7 // NOTE: This must match up with the Syscalls interface in MIPSInterpreter.java
8 // (in my tree the Syscalls interface is autogenerated from a syscalls.h. We should
24 static inline int syscall4(int n, int a, int b, int c, int d) {
26 __asm__ __volatile__ (
37 : "0"(n),"r"(a),"r"(b),"r"(c),"r"(d)
38 : "$2","$4","$5","$6","$7","memory"
42 static inline int syscall0(int n) { return syscall4(n,0,0,0,0); }
43 static inline int syscall1(int n, int a) { return syscall4(n,a,0,0,0); }
44 static inline int syscall2(int n, int a, int b) { return syscall4(n,a,b,0,0); }
45 static inline int syscall3(int n, int a, int b, int c) { return syscall4(n,a,b,c,0); }
47 static inline int errnoize(struct _reent *ptr,int n) {
55 /* These return errno values and must be reentrant */
56 caddr_t _sbrk_r(struct _reent *ptr,int incr) {
57 int n = syscall1(SYS_sbrk,incr);
58 if(n == -ENOMEM) { ptr->_errno = ENOMEM; return (caddr_t)-1; }
62 int _write_r(struct _reent *ptr,int fd, char *p, int len) { return errnoize(ptr,syscall3(SYS_write,fd,(int)p,len)); }
63 int _read_r(struct _reent *ptr,int fd, char *p, int len) { return errnoize(ptr,syscall3(SYS_read,fd,(int)p,len)); }
64 int _close_r(struct _reent *ptr,int fd) { return errnoize(ptr,syscall1(SYS_close,fd)); }
65 int _fstat_r(struct _reent *ptr,int fd, struct stat *st) { return errnoize(ptr,syscall2(SYS_fstat,fd,(int)st)); }
66 int _lseek_r(struct _reent *ptr,int fd, int off, int whence) { return errnoize(ptr,syscall3(SYS_seek,fd,off,whence)); }
67 int _open_r(struct _reent *ptr,char *name, int flags, int mode) { return errnoize(ptr,syscall3(SYS_open,(int)name,flags,mode)); }
68 int _kill_r(struct _reent *ptr,pid_t pid, int sig) { return errnoize(ptr,syscall2(SYS_kill,(int)pid,sig)); }
69 int _getpid_r(struct _reent *ptr) { return errnoize(ptr,syscall0(SYS_getpid)); }
72 void _exit(int status) {
73 syscall1(SYS_exit,status);
74 for(;;); /* shut up gcc */
76 int isatty(int fd) { return syscall1(SYS_isatty,fd); }
78 void emu_pause() { syscall0(SYS_pause); }