From 571bb2b2a6e7bfda194319675e618e34f9986990 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 3 Nov 2005 14:36:46 +0000 Subject: [PATCH] Simplified the x86 syscall interface a bit. We no longer pass a pointer to the parameters nor the number of parameters; the kernel is able to get both without problems. The syscall functions in libroot (_kern_*()) are now self-contained (they don't "jmp" to separate code anymore), which at least theoretically allows gdb to print a stack trace with the syscall function on the top when a thread is currently performing a syscall. Practically it doesn't work yet, though, since those functions are frameless (i.e. create no stack frame) which needs special support I haven't implemented yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14661 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/arch/x86/arch_int.c | 14 +- src/system/libroot/os/arch/x86/syscalls.inc | 266 ++------------------ 2 files changed, 30 insertions(+), 250 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_int.c b/src/system/kernel/arch/x86/arch_int.c index e7b0855482..f7c635d01c 100644 --- a/src/system/kernel/arch/x86/arch_int.c +++ b/src/system/kernel/arch/x86/arch_int.c @@ -479,18 +479,18 @@ i386_handle_trap(struct iframe frame) #endif /* syscall interface works as such: * %eax has syscall # - * %ecx has number of args (0-16) - * %edx has pointer to buffer containing args from first to last - * each is verified to make sure someone doesn't try to clobber it + * %esp + 4 points to the syscall parameters */ - if (frame.ecx <= MAX_ARGS) { - if (IS_KERNEL_ADDRESS(frame.edx) - || user_memcpy(args, (void *)frame.edx, frame.ecx * sizeof(unsigned int)) < B_OK) { + if (frame.eax >= 0 && frame.eax < kSyscallCount) { + void *params = (void*)(frame.user_esp + 4); + int paramSize = kSyscallInfos[frame.eax].parameter_size; + if (IS_KERNEL_ADDRESS((addr_t)params) + || user_memcpy(args, params, paramSize) < B_OK) { retcode = B_BAD_ADDRESS; } else ret = syscall_dispatcher(frame.eax, (void *)args, &retcode); } else { - // want to pass too many args into the system + // invalid syscall number retcode = EINVAL; } frame.eax = retcode & 0xffffffff; diff --git a/src/system/libroot/os/arch/x86/syscalls.inc b/src/system/libroot/os/arch/x86/syscalls.inc index bd513a5887..87154ec695 100644 --- a/src/system/libroot/os/arch/x86/syscalls.inc +++ b/src/system/libroot/os/arch/x86/syscalls.inc @@ -4,254 +4,34 @@ */ /* -** syscall interface works as such: -** eax has syscall # -** ecx has number of args (0-16) -** edx has pointer to buffer containing args from first to last -** each is verified to make sure someone doesnt try to clobber it -*/ + * syscall interface works as such: + * eax has syscall # + * esp + 4 points to the syscall parameters + */ -#define SYSCALL0(name, n) \ +#define _SYSCALL(name, n) \ .globl name; \ .type name,@function; \ .align 8; \ name: \ movl $n,%eax; \ - jmp syscall0 - -#define SYSCALL1(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall1 - -#define SYSCALL2(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall2 - -#define SYSCALL3(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall3 - -#define SYSCALL4(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall4 - -#define SYSCALL5(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall5 - -#define SYSCALL6(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall6 - - -#define SYSCALL7(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall7 - -#define SYSCALL8(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall8 - -#define SYSCALL9(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall9 - -#define SYSCALL10(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall10 - -#define SYSCALL11(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall11 - -#define SYSCALL12(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall12 - -#define SYSCALL13(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall13 - -#define SYSCALL14(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall14 - -#define SYSCALL15(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall15 - -#define SYSCALL16(name, n) \ -.globl name; \ -.type name,@function; \ -.align 8; \ -name: \ - movl $n,%eax; \ - jmp syscall16 - - - -/* we will optimize by just passing a ptr to the place where the caller -** would have dumped the args */ - -syscall0: - movl $0, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall1: - movl $1, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall2: - movl $2, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall3: - movl $3, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall4: - movl $4, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall5: - movl $5, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall6: - movl $6, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall7: - movl $7, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall8: - movl $8, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall9: - movl $9, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall10: - movl $10, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall11: - movl $11, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall12: - movl $12, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall13: - movl $13, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall14: - movl $14, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall15: - movl $15, %ecx - lea 4(%esp), %edx - int $99 - ret - -syscall16: - movl $16, %ecx - lea 4(%esp), %edx - int $99 + int $99; \ ret +#define SYSCALL0(name, n) _SYSCALL(name, n) +#define SYSCALL1(name, n) _SYSCALL(name, n) +#define SYSCALL2(name, n) _SYSCALL(name, n) +#define SYSCALL3(name, n) _SYSCALL(name, n) +#define SYSCALL4(name, n) _SYSCALL(name, n) +#define SYSCALL5(name, n) _SYSCALL(name, n) +#define SYSCALL6(name, n) _SYSCALL(name, n) +#define SYSCALL7(name, n) _SYSCALL(name, n) +#define SYSCALL8(name, n) _SYSCALL(name, n) +#define SYSCALL9(name, n) _SYSCALL(name, n) +#define SYSCALL10(name, n) _SYSCALL(name, n) +#define SYSCALL11(name, n) _SYSCALL(name, n) +#define SYSCALL12(name, n) _SYSCALL(name, n) +#define SYSCALL13(name, n) _SYSCALL(name, n) +#define SYSCALL14(name, n) _SYSCALL(name, n) +#define SYSCALL15(name, n) _SYSCALL(name, n) +#define SYSCALL16(name, n) _SYSCALL(name, n)