00001
00002
00003
00004
00005
00006
00007
00008 #ifndef SYS_H
00009 #define SYS_H
00010
00011 #include <types.h>
00012
00013
00014 #define SYS_exit 0
00015
00016 #define SYS_getchar 1
00017
00018 #define SYS_putchar 2
00019
00020 #define SYS_malloc 3
00021
00022 #define SYS_free 4
00023
00024
00025 #define _syscall0(type, name) \
00026 type name(void) \
00027 { \
00028 register long __ret; \
00029 __asm__ __volatile__ ( \
00030 "pushl %%ebp\n" \
00031 "movl %%esp, %%ebp\n" \
00032 "int $0x80\n" \
00033 "popl %%ebp" \
00034 : "=a"(__ret) : "0"(SYS_##name)); \
00035 return((type)__ret); \
00036 }
00037
00038
00039 #define _syscall1(type, name, type1, arg1) \
00040 type name(type1 arg1) \
00041 { \
00042 register long __ret; \
00043 __asm__ __volatile__ ( \
00044 "pushl %%ebp\n" \
00045 "pushl %2\n" \
00046 "movl %%esp, %%ebp\n" \
00047 "int $0x80\n" \
00048 "add $4, %%esp\n" \
00049 "popl %%ebp" \
00050 : "=a"(__ret) : "0"(SYS_##name), \
00051 "r"((long)(arg1))); \
00052 return((type)__ret); \
00053 }
00054
00055
00056 #define _syscall2(type, name, type1, arg1, type2, arg2) \
00057 type name(type1 arg1, type2 arg2) \
00058 { \
00059 register long __ret; \
00060 __asm__ __volatile__ ( \
00061 "pushl %%ebp\n" \
00062 "pushl %2\n" \
00063 "pushl %3\n" \
00064 "movl %%esp, %%ebp\n" \
00065 "int $0x80\n" \
00066 "add $8, %%esp\n" \
00067 "popl %%ebp" \
00068 : "=a"(__ret) : "0"(SYS_##name), \
00069 "r"((long)(arg1)), "r"((long)(arg2))); \
00070 return((type)__ret); \
00071 }
00072
00073
00074 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
00075 type name(type1 arg1, type2 arg2, type3 arg3) \
00076 { \
00077 register long __ret; \
00078 __asm__ __volatile__ ( \
00079 "pushl %%ebp\n" \
00080 "pushl %2\n" \
00081 "pushl %3\n" \
00082 "pushl %4\n" \
00083 "movl %%esp, %%ebp\n" \
00084 "int $0x80\n" \
00085 "add $12, %%esp\n" \
00086 "popl %%ebp" \
00087 : "=a"(__ret) : "0"(SYS_##name), \
00088 "r"((long)(arg1)), "r"((long)(arg2)), "r"((long)(arg3))); \
00089 return((type)__ret); \
00090 }
00091
00092
00093 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
00094 type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
00095 { \
00096 register long __ret; \
00097 __asm__ __volatile__ ( \
00098 "pushl %%ebp\n" \
00099 "pushl %2\n" \
00100 "pushl %3\n" \
00101 "pushl %4\n" \
00102 "pushl %5\n" \
00103 "movl %%esp, %%ebp\n" \
00104 "int $0x80\n" \
00105 "add $16, %%esp\n" \
00106 "popl %%ebp" \
00107 : "=a"(__ret) : "0"(SYS_##name), \
00108 "r"((long)(arg1)), "r"((long)(arg2)), "r"((long)(arg3)), "r"((long)(arg4))); \
00109 return((type)__ret); \
00110 }
00111
00112
00113
00114 static __inline__ _syscall1(int, exit, int, exitcode);
00115 static __inline__ _syscall0(int, getchar);
00116 static __inline__ _syscall1(void, putchar, int, c);
00117 static __inline__ _syscall1(void *, malloc, size_t, size);
00118 static __inline__ _syscall1(void, free, void *, ptr);
00119
00120 #endif