From d509054e139f3a48676eb0e7cada4a1c71e09b28 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 1 Nov 2021 17:07:59 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E8=B0=83?= =?utf8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/exec.c | 3 ++- kernel/syscall.S | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) 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 -- 2.44.0