11 #include "../common/plat.h"
14 int plat_is_dir(const char *path)
17 if ((dir = opendir(path))) {
24 int plat_get_root_dir(char *dst, int len)
28 ret = readlink("/proc/self/exe", dst, len - 1);
35 for (j = strlen(dst); j > 0; j--)
45 /* Wiz has a borked gettimeofday().. */
46 #define plat_get_ticks_ms plat_get_ticks_ms_good
47 #define plat_get_ticks_us plat_get_ticks_us_good
50 unsigned int plat_get_ticks_ms(void)
55 gettimeofday(&tv, NULL);
57 ret = (unsigned)tv.tv_sec * 1000;
58 /* approximate /= 1000 */
59 ret += ((unsigned)tv.tv_usec * 4195) >> 22;
64 unsigned int plat_get_ticks_us(void)
69 gettimeofday(&tv, NULL);
71 ret = (unsigned)tv.tv_sec * 1000000;
72 ret += (unsigned)tv.tv_usec;
77 void plat_sleep_ms(int ms)
82 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
84 struct timeval tv, *timeout = NULL;
85 int i, ret, fdmax = -1;
88 if (timeout_ms >= 0) {
89 tv.tv_sec = timeout_ms / 1000;
90 tv.tv_usec = (timeout_ms % 1000) * 1000;
95 for (i = 0; i < count; i++) {
96 if (fds_hnds[i] > fdmax) fdmax = fds_hnds[i];
97 FD_SET(fds_hnds[i], &fdset);
100 ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
103 perror("plat_wait_event: select failed");
109 return -1; /* timeout */
112 for (i = 0; i < count; i++)
113 if (FD_ISSET(fds_hnds[i], &fdset))
119 void *plat_mmap(unsigned long addr, size_t size)
124 ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
125 if (ret == MAP_FAILED)
128 printf("warning: mmaped to %p, requested %p\n", ret, req);
133 void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
137 ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
138 if (ret == MAP_FAILED)
141 printf("warning: mremap moved: %p -> %p\n", ptr, ret);
146 void plat_munmap(void *ptr, size_t size)
152 void lprintf(const char *fmt, ...)