9 #include "../common/plat.h"
12 int plat_is_dir(const char *path)
15 if ((dir = opendir(path))) {
22 int plat_get_root_dir(char *dst, int len)
27 strncpy(dst, g_argv[0], len);
31 for (j = strlen(dst); j > 0; j--)
32 if (dst[j] == '/') { dst[j+1] = 0; break; }
38 /* Wiz has a borked gettimeofday().. */
39 #define plat_get_ticks_ms plat_get_ticks_ms_good
40 #define plat_get_ticks_us plat_get_ticks_us_good
43 unsigned int plat_get_ticks_ms(void)
48 gettimeofday(&tv, NULL);
50 ret = (unsigned)tv.tv_sec * 1000;
51 /* approximate /= 1000 */
52 ret += ((unsigned)tv.tv_usec * 4195) >> 22;
57 unsigned int plat_get_ticks_us(void)
62 gettimeofday(&tv, NULL);
64 ret = (unsigned)tv.tv_sec * 1000000;
65 ret += (unsigned)tv.tv_usec;
70 void plat_sleep_ms(int ms)
75 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
77 struct timeval tv, *timeout = NULL;
78 int i, ret, fdmax = -1;
81 if (timeout_ms >= 0) {
82 tv.tv_sec = timeout_ms / 1000;
83 tv.tv_usec = (timeout_ms % 1000) * 1000;
88 for (i = 0; i < count; i++) {
89 if (fds_hnds[i] > fdmax) fdmax = fds_hnds[i];
90 FD_SET(fds_hnds[i], &fdset);
93 ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
96 perror("plat_wait_event: select failed");
102 return -1; /* timeout */
105 for (i = 0; i < count; i++)
106 if (FD_ISSET(fds_hnds[i], &fdset))
112 void *plat_mmap(unsigned long addr, size_t size)
116 ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
117 if (ret == MAP_FAILED)
120 printf("warning: mmaped to %p, requested %p\n", ret, req);
125 void plat_munmap(void *ptr, size_t size)