From: acevest Date: Mon, 1 Nov 2021 09:07:59 +0000 (+0800) Subject: 优化系统调用 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-settime.html?a=commitdiff_plain;h=d509054e139f3a48676eb0e7cada4a1c71e09b28;p=kernel.git 优化系统调用 --- diff --git a/kernel/exec.c b/kernel/exec.c index 1e1d437..3f1ead9 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -129,7 +129,8 @@ int sysc_exec(const char *path, char *const argv[]) free_pages((unsigned long)ehdr); - asm("movl $0, %%eax; movl %%ebx,%%ebp; movl %%ebp,%%esp;jmp syscall_exit;" ::"b"((unsigned long)(regs))); + // TODO FIXME + //asm("movl $0, %%eax; movl %%ebx,%%ebp; movl %%ebp,%%esp;jmp syscall_exit;" ::"b"((unsigned long)(regs))); return 0; } diff --git a/kernel/syscall.S b/kernel/syscall.S index 89996b8..ff8617e 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -20,6 +20,7 @@ #define ASM #include #include +#include .code32 .text @@ -27,9 +28,11 @@ .global ret_from_fork_user .global ret_from_fork_krnl .global sysexit -.global syscall_exit +//.global syscall_exit syscall_entry: + // 这段代码纯是为了pt_regs_t准备的 + // 后续看看直接优化掉 pushl $(SELECTOR_USER_SS) pushl %ebp pushfl @@ -54,24 +57,32 @@ syscall_entry: .normal_syscall: call *sysc_handler_table(,%eax,4) -normal_syscall_exit: - leal sysexit, %edx - movl %edx, PT_REGS_EDX(%esp) - movl PT_REGS_EBP(%esp), %edx - movl %edx, PT_REGS_ECX(%esp) +// normal_syscall_exit: +// leal sysexit, %edx +// movl %edx, PT_REGS_EDX(%esp) +// movl PT_REGS_EBP(%esp), %edx +// movl %edx, PT_REGS_ECX(%esp) + +//syscall_exit: -syscall_exit: + // 保存返回值 movl %eax, PT_REGS_EAX(%esp) +ret_from_fork_user: + RESTORE_REGS + // 返回用户态的eip + // sysexit指令从edx中恢复用户态eip + leal sysexit, %edx + + // 在系统调用前,用户态的esp保存在ebp中 + // sysexit指令从ecx中恢复用户态esp + movl %ebp, %ecx + sti /* sysenter have cleared IF, and sysexit will not set IF. */ sysexit -ret_from_fork_user: - xorl %eax, %eax - jmp normal_syscall_exit - ret_from_fork_krnl: movl PT_REGS_EDX(%esp), %edx sti