clock_t clock(void) { uint64_t retval; (void)cpu_syscall(&retval,NULL,NULL,NULL,SYS_CLOCK); return retval; }
int pipe(int pipefd[2]) { register int retval; retval = (int)cpu_syscall((void*)pipefd, NULL,NULL, NULL, SYS_PIPE); return retval; }
int madvise(void *start, size_t length, int advice) { if((start == NULL) || (advice < 0) || (advice > MADV_MIGRATE)) return EINVAL; return (int) cpu_syscall(start, (void*)length, (void*)advice, NULL, SYS_MADVISE); }
unsigned int __attribute__ ((noinline)) sleep (unsigned int nb_sec) { unsigned int val; val = (unsigned int)cpu_syscall((void*)nb_sec,NULL,NULL,NULL,SYS_ALARM); return val; }
int mkfifo(const char *pathname, mode_t mode) { register int retval; retval = (int)cpu_syscall((void*)pathname, (void*)mode, NULL, NULL, SYS_MKFIFO); return retval; }
ssize_t write(int fd, const void *buf, size_t count) { register ssize_t size; size = (ssize_t) cpu_syscall((void*)fd, (void*)buf, (void*)count, NULL, SYS_WRITE); return size; }
ssize_t read (int fd, void *buf, size_t count) { register ssize_t size; size = (ssize_t) cpu_syscall((void*)fd, buf, (void*)count, NULL, SYS_READ); return size; }
void *mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) { mmap_attr_t mattr; mattr.addr = addr; mattr.length = len; mattr.prot = prot; mattr.flags = flags; mattr.fd = fd; mattr.offset = offset; return cpu_syscall(&mattr, NULL, NULL, NULL,SYS_MMAP); }
int ftime(struct timeb *tp) { int retval; if(tp == NULL) return -1; retval = (int) cpu_syscall((void*)tp, NULL, NULL, NULL, SYS_FTIME); if(retval != 0) return -1; return 0; }
pid_t fork(void) { pid_t pid; struct __pthread_tls_s *tls; tls = cpu_get_tls(); pid = (pid_t) cpu_syscall((void*)__pthread_tls_get(tls,__PT_TLS_FORK_FLAGS), (void*)__pthread_tls_get(tls,__PT_TLS_FORK_CPUID), NULL,NULL,SYS_FORK); if(pid == 0) __pthread_tls_init(tls); return pid; }
int cpu_start(Cpu *cpu){ cpu->run = 1; int ret_val = 0; while ((NPC < cpu->prog_len) && cpu->run){ switch (cpu->firmware[NPC]){ case push_num: cpu_push_num(cpu, cpu->firmware[NPC + 1]); NPC_INC(2); break; case pop: cpu_pop(cpu, cpu->firmware[NPC + 1]); if (p_errno){ break; } NPC_INC(2); break; case push_reg: cpu_push_reg(cpu, cpu->firmware[NPC + 1]); NPC_INC(2); break; case add: cpu_add(cpu); if (p_errno){ break; } NPC_INC(1); break; case mul: cpu_mul(cpu); if (p_errno){ break; } NPC_INC(1); break; case sub: cpu_sub(cpu); if (p_errno){ break; } NPC_INC(1); break; case divide: cpu_div(cpu); if (p_errno){ break; } NPC_INC(1); break; case tr: cpu_tr(cpu, cpu->firmware[NPC + 1]); break; case trip: cpu_trip(cpu, cpu->firmware[NPC + 1]); break; case trin: cpu_trin(cpu, cpu->firmware[NPC + 1]); break; case triz: cpu_triz(cpu, cpu->firmware[NPC + 1]); break; case gsp: cpu_gsp(cpu, cpu->firmware[NPC + 1]); NPC_INC(2); break; case ssp: cpu_ssp(cpu, cpu->firmware[NPC + 1]); NPC_INC(2); break; case syscall: cpu_syscall(cpu, &ret_val); NPC_INC(1); break; case out: cpu_out(cpu); NPC_INC(1); break; default: NPC_INC(1); } if (p_errno){ printf("\nError at %d", NPC); return 1; } } cpu->run = 0; return ret_val; }
void *dma_memcpy (void *src, void *dst, unsigned int size) { void *value = cpu_syscall(src,dst,(void*)size,NULL,SYS_DMA_MEMCPY); return (value == NULL) ? dst : NULL; }
int mcntl(int op, void *vaddr, size_t len, minfo_t *info) { return (int)cpu_syscall((void*)op, vaddr, (void*)len, info, SYS_MCNTL); }