From: acevest Date: Fri, 20 Jun 2014 14:59:57 +0000 (+0800) Subject: move use syscall code to libc X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=c949876b9178267551360249dd2117da6955a4c8;p=kernel.git move use syscall code to libc --- diff --git a/bin/Makefile b/bin/Makefile index 66e2586..a64df42 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -3,7 +3,7 @@ CFLAGS = -c -I../include -fno-builtin LDOBJS = ../lib/errno.c.o ../lib/fork.c.o ../lib/lib.c.o ../lib/open.c.o \ ../lib/stat.c.o ../lib/string.c.o ../lib/write.c.o ../lib/exec.c.o \ ../lib/vsprintf.c.o ../lib/read.c.o \ - ../lib/keyboard.c.o ../lib/exit.c.o + ../lib/keyboard.c.o ../lib/exit.c.o ../lib/syscall.c.o all: gcc -c shell.S -o shell.S.c.o gcc $(CFLAGS) shell.c -o shell.c.o diff --git a/kernel/syscall.c b/kernel/syscall.c index eb4be16..52ba90e 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -84,87 +84,3 @@ int sysc_bad_syscnr() return 0; } - - -#define SYSENTER_ASM \ - "pushl $1f;" \ - "pushl %%ecx;" \ - "pushl %%edx;" \ - "pushl %%ebp;" \ - "movl %%esp,%%ebp;" \ - "sysenter;" \ - "1:" - -static int __syscall0(int nr) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr)); - return __sysc_ret__; -} - -static int __syscall1(int nr, unsigned long a) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a)); - return __sysc_ret__; -} - -static int __syscall2(int nr, unsigned long a, unsigned long b) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b)); - return __sysc_ret__; -} - -static int __syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c)); - return __sysc_ret__; -} - -static int __syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c), "S"(d)); - return __sysc_ret__; -} - -static int __syscall5(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d, unsigned long e) -{ - int __sysc_ret__ = 0; - asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c), "S"(d), "D"(e)); - return __sysc_ret__; -} - - - -int _syscall0(int nr) -{ - return __syscall0(nr); -} - -int _syscall1(int nr, unsigned long a) -{ - return __syscall1(nr, a); -} - -int _syscall2(int nr, unsigned long a, unsigned long b) -{ - return __syscall2(nr, a, b); -} - -int _syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) -{ - return __syscall3(nr, a, b, c); -} - -int _syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) -{ - return __syscall4(nr, a, b, c, d); -} - -int _syscall5(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d, unsigned long e) -{ - return __syscall5(nr, a, b, c, d, e); -} diff --git a/lib/syscall.c b/lib/syscall.c new file mode 100644 index 0000000..d781aa9 --- /dev/null +++ b/lib/syscall.c @@ -0,0 +1,92 @@ +/* + * ------------------------------------------------------------------------ + * File Name: syscall.c + * Author: Zhao Yanbai + * Fri Jun 20 22:57:17 2014 + * Description: none + * ------------------------------------------------------------------------ + */ + + +#define SYSENTER_ASM \ + "pushl $1f;" \ + "pushl %%ecx;" \ + "pushl %%edx;" \ + "pushl %%ebp;" \ + "movl %%esp,%%ebp;" \ + "sysenter;" \ + "1:" + +static int __syscall0(int nr) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr)); + return __sysc_ret__; +} + +static int __syscall1(int nr, unsigned long a) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a)); + return __sysc_ret__; +} + +static int __syscall2(int nr, unsigned long a, unsigned long b) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b)); + return __sysc_ret__; +} + +static int __syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c)); + return __sysc_ret__; +} + +static int __syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c), "S"(d)); + return __sysc_ret__; +} + +static int __syscall5(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d, unsigned long e) +{ + int __sysc_ret__ = 0; + asm(SYSENTER_ASM:"=a"(__sysc_ret__):"a"(nr), "b"(a), "c"(b), "d"(c), "S"(d), "D"(e)); + return __sysc_ret__; +} + + + +int _syscall0(int nr) +{ + return __syscall0(nr); +} + +int _syscall1(int nr, unsigned long a) +{ + return __syscall1(nr, a); +} + +int _syscall2(int nr, unsigned long a, unsigned long b) +{ + return __syscall2(nr, a, b); +} + +int _syscall3(int nr, unsigned long a, unsigned long b, unsigned long c) +{ + return __syscall3(nr, a, b, c); +} + +int _syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d) +{ + return __syscall4(nr, a, b, c, d); +} + +int _syscall5(int nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d, unsigned long e) +{ + return __syscall5(nr, a, b, c, d, e); +}