10 #include "../common/plat.h"
13 int plat_is_dir(const char *path)
16 if ((dir = opendir(path))) {
23 int plat_get_root_dir(char *dst, int len)
28 strncpy(dst, g_argv[0], len);
32 for (j = strlen(dst); j > 0; j--)
33 if (dst[j] == '/') { dst[j+1] = 0; break; }
39 /* Wiz has a borked gettimeofday().. */
40 #define plat_get_ticks_ms plat_get_ticks_ms_good
41 #define plat_get_ticks_us plat_get_ticks_us_good
44 unsigned int plat_get_ticks_ms(void)
49 gettimeofday(&tv, NULL);
51 ret = (unsigned)tv.tv_sec * 1000;
52 /* approximate /= 1000 */
53 ret += ((unsigned)tv.tv_usec * 4195) >> 22;
58 unsigned int plat_get_ticks_us(void)
63 gettimeofday(&tv, NULL);
65 ret = (unsigned)tv.tv_sec * 1000000;
66 ret += (unsigned)tv.tv_usec;
71 void plat_sleep_ms(int ms)
76 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
78 struct timeval tv, *timeout = NULL;
79 int i, ret, fdmax = -1;
82 if (timeout_ms >= 0) {
83 tv.tv_sec = timeout_ms / 1000;
84 tv.tv_usec = (timeout_ms % 1000) * 1000;
89 for (i = 0; i < count; i++) {
90 if (fds_hnds[i] > fdmax) fdmax = fds_hnds[i];
91 FD_SET(fds_hnds[i], &fdset);
94 ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
97 perror("plat_wait_event: select failed");
103 return -1; /* timeout */
106 for (i = 0; i < count; i++)
107 if (FD_ISSET(fds_hnds[i], &fdset))
113 void *plat_mmap(unsigned long addr, size_t size)
118 ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
119 if (ret == MAP_FAILED)
122 printf("warning: mmaped to %p, requested %p\n", ret, req);
127 void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
131 ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
132 if (ret == MAP_FAILED)
135 printf("warning: mremap moved: %p -> %p\n", ptr, ret);
140 void plat_munmap(void *ptr, size_t size)