summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2021-07-23 13:50:00 +0200
committerdzwdz2021-07-23 13:50:00 +0200
commit8a29c78d34f1924c4e39a3a951b36c4512ffe9c1 (patch)
tree624319a6dd15593be381c48d03ef5c8b568020a0 /src
parent91c637d847744ba410cbf0e20c62c485e1f6153d (diff)
update the process' EIP/ESP when it syscalls
Diffstat (limited to 'src')
-rw-r--r--src/kernel/arch/generic.h2
-rw-r--r--src/kernel/arch/i386/sysenter.s8
-rw-r--r--src/kernel/syscalls.c5
3 files changed, 10 insertions, 5 deletions
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h
index 6200320..8db079c 100644
--- a/src/kernel/arch/generic.h
+++ b/src/kernel/arch/generic.h
@@ -17,7 +17,7 @@ void halt_cpu();
// src/arch/i386/sysenter.s
void sysexit(void (*fun)(), void *stack_top);
void sysenter_setup();
-int syscall_handler(int, int, int, int);
+int syscall_handler(int, int, int, int, void *stack, void *eip);
// all of those can allocate memory
struct pagedir *pagedir_new();
diff --git a/src/kernel/arch/i386/sysenter.s b/src/kernel/arch/i386/sysenter.s
index 7375e06..64b7d01 100644
--- a/src/kernel/arch/i386/sysenter.s
+++ b/src/kernel/arch/i386/sysenter.s
@@ -49,6 +49,8 @@ sysenter_setup:
sysenter_handler:
pushal
+ push %edx
+ push %ecx
push %edi
push %esi
push %ebx
@@ -61,13 +63,13 @@ sysenter_handler:
call syscall_handler
// save the return value
- mov %eax, 44(%esp) // 16 [top of eflags] + 7*4 [skip until EAX]
- mov %edx, 32(%esp) // 16 + 4*4 [skip until EBX]
+ mov %eax, 52(%esp) // 24 [top of eflags] + 7*4 [skip until EAX]
+ mov %edx, 40(%esp) // 24 + 4*4 [skip until EBX]
mov %cr0, %eax
or $0x80000000, %eax // enable paging
mov %eax, %cr0
- add $16, %esp
+ add $24, %esp
popal
sysexit
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 2af8cf9..24706d3 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -18,7 +18,10 @@ int sc_debuglog(const char *msg, size_t len) {
return len;
}
-int syscall_handler(int num, int a, int b, int c) {
+int syscall_handler(int num, int a, int b, int c, void *stack, void *eip) {
+ process_current->esp = stack;
+ process_current->eip = eip;
+
switch (num) {
case SC_DEBUGLOG:
return sc_debuglog((void*)a, b);