00001 #include <syscall.h>
00002 #include "../syscall-nr.h"
00003
00004
00005
00006 #define syscall0(NUMBER) \
00007 ({ \
00008 int retval; \
00009 asm volatile \
00010 ("pushl %[number]; int $0x30; addl $4, %%esp" \
00011 : "=a" (retval) \
00012 : [number] "i" (NUMBER) \
00013 : "memory"); \
00014 retval; \
00015 })
00016
00017
00018
00019 #define syscall1(NUMBER, ARG0) \
00020 ({ \
00021 int retval; \
00022 asm volatile \
00023 ("pushl %[arg0]; pushl %[number]; int $0x30; addl $8, %%esp" \
00024 : "=a" (retval) \
00025 : [number] "i" (NUMBER), \
00026 [arg0] "g" (ARG0) \
00027 : "memory"); \
00028 retval; \
00029 })
00030
00031
00032
00033 #define syscall2(NUMBER, ARG0, ARG1) \
00034 ({ \
00035 int retval; \
00036 asm volatile \
00037 ("pushl %[arg1]; pushl %[arg0]; " \
00038 "pushl %[number]; int $0x30; addl $12, %%esp" \
00039 : "=a" (retval) \
00040 : [number] "i" (NUMBER), \
00041 [arg0] "g" (ARG0), \
00042 [arg1] "g" (ARG1) \
00043 : "memory"); \
00044 retval; \
00045 })
00046
00047
00048
00049 #define syscall3(NUMBER, ARG0, ARG1, ARG2) \
00050 ({ \
00051 int retval; \
00052 asm volatile \
00053 ("pushl %[arg2]; pushl %[arg1]; pushl %[arg0]; " \
00054 "pushl %[number]; int $0x30; addl $16, %%esp" \
00055 : "=a" (retval) \
00056 : [number] "i" (NUMBER), \
00057 [arg0] "g" (ARG0), \
00058 [arg1] "g" (ARG1), \
00059 [arg2] "g" (ARG2) \
00060 : "memory"); \
00061 retval; \
00062 })
00063
00064 void
00065 halt (void)
00066 {
00067 syscall0 (SYS_HALT);
00068 NOT_REACHED ();
00069 }
00070
00071 void
00072 exit (int status)
00073 {
00074 syscall1 (SYS_EXIT, status);
00075 NOT_REACHED ();
00076 }
00077
00078 pid_t
00079 exec (const char *file)
00080 {
00081 return (pid_t) syscall1 (SYS_EXEC, file);
00082 }
00083
00084 int
00085 wait (pid_t pid)
00086 {
00087 return syscall1 (SYS_WAIT, pid);
00088 }
00089
00090 bool
00091 create (const char *file, unsigned initial_size)
00092 {
00093 return syscall2 (SYS_CREATE, file, initial_size);
00094 }
00095
00096 bool
00097 remove (const char *file)
00098 {
00099 return syscall1 (SYS_REMOVE, file);
00100 }
00101
00102 int
00103 open (const char *file)
00104 {
00105 return syscall1 (SYS_OPEN, file);
00106 }
00107
00108 int
00109 filesize (int fd)
00110 {
00111 return syscall1 (SYS_FILESIZE, fd);
00112 }
00113
00114 int
00115 read (int fd, void *buffer, unsigned size)
00116 {
00117 return syscall3 (SYS_READ, fd, buffer, size);
00118 }
00119
00120 int
00121 write (int fd, const void *buffer, unsigned size)
00122 {
00123 return syscall3 (SYS_WRITE, fd, buffer, size);
00124 }
00125
00126 void
00127 seek (int fd, unsigned position)
00128 {
00129 syscall2 (SYS_SEEK, fd, position);
00130 }
00131
00132 unsigned
00133 tell (int fd)
00134 {
00135 return syscall1 (SYS_TELL, fd);
00136 }
00137
00138 void
00139 close (int fd)
00140 {
00141 syscall1 (SYS_CLOSE, fd);
00142 }
00143
00144 mapid_t
00145 mmap (int fd, void *addr)
00146 {
00147 return syscall2 (SYS_MMAP, fd, addr);
00148 }
00149
00150 void
00151 munmap (mapid_t mapid)
00152 {
00153 syscall1 (SYS_MUNMAP, mapid);
00154 }
00155
00156 bool
00157 chdir (const char *dir)
00158 {
00159 return syscall1 (SYS_CHDIR, dir);
00160 }
00161
00162 bool
00163 mkdir (const char *dir)
00164 {
00165 return syscall1 (SYS_MKDIR, dir);
00166 }
00167
00168 bool
00169 readdir (int fd, char name[READDIR_MAX_LEN + 1])
00170 {
00171 return syscall2 (SYS_READDIR, fd, name);
00172 }
00173
00174 bool
00175 isdir (int fd)
00176 {
00177 return syscall1 (SYS_ISDIR, fd);
00178 }
00179
00180 int
00181 inumber (int fd)
00182 {
00183 return syscall1 (SYS_INUMBER, fd);
00184 }