Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

sys.h

Go to the documentation of this file.
00001 /*!     \file include/sys/sys.h
00002  *      \brief Generic minirighi syscall library.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-11-15
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef SYS_H
00009 #define SYS_H
00010 
00011 #include <types.h>
00012 
00013 //! Go back to the system.
00014 #define SYS_exit        0
00015 //! Get a char from stdin.
00016 #define SYS_getchar     1
00017 //! Put a character on stdout.
00018 #define SYS_putchar     2
00019 //! Allocate a memory area.
00020 #define SYS_malloc      3
00021 //! Free a memory area.
00022 #define SYS_free        4
00023 
00024 //! The core of a system call with no argument.
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 //! The core of a system call with 1 argument.
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 //! The core of a system call with 2 argument.
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 //! The core of a system call with 3 argument.
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 //! The core of a system call with 4 argument.
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 // --- Prototypes ----------------------------------------------------- //
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

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18