Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e70109b)
raw | patch | inline | side by side (parent: e70109b)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Mon, 1 Nov 2021 09:07:59 +0000 (17:07 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:46 +0000 (10:45 +0800) |
| kernel/exec.c | patch | blob | history | |
| kernel/syscall.S | patch | blob | history |
diff --git a/kernel/exec.c b/kernel/exec.c
--- a/kernel/exec.c
+++ b/kernel/exec.c
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
--- a/kernel/syscall.S
+++ b/kernel/syscall.S
#define ASM
#include <system.h>
#include <syscall.h>
+#include <task.h>
.code32
.text
.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
.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