diff --git a/amd64/arch/entry.S b/amd64/arch/entry.S index 4bc994d..2ced28d 100644 --- a/amd64/arch/entry.S +++ b/amd64/arch/entry.S @@ -88,11 +88,9 @@ irq_common: swapgs 1: push_all /* pushes 15 registers */ - mov gs:[28], rsp /* save RSP after push_all for scheduler */ mov rdi, [rsp + 120] /* irq no */ call irq_handler -irq_epilogue: pop_all test qword ptr [rsp + 24], 3 /* from userspace? */ jz 2f @@ -101,10 +99,17 @@ irq_epilogue: add rsp, 8 iretq +.global sched_save_state +sched_save_state: + push_all + mov [rdi + 8], rsp /* save RSP to thread->kstack_ptr */ + ret + .global sched_restore_state sched_restore_state: - mov rsp, [rdi + 8] /* load from thread->kstack_ptr */ - jmp irq_epilogue + mov rsp, [rdi + 8] /* load RSP from thread->kstack_ptr */ + pop_all + ret .global _syscall_enter _syscall_enter: diff --git a/amd64/kernel/proc.c b/amd64/kernel/proc.c index 03ef7dd..3b0cdba 100644 --- a/amd64/kernel/proc.c +++ b/amd64/kernel/proc.c @@ -35,10 +35,7 @@ u32 cpu_id() return tls_get()->cpu_id; } -void sched_save_state(struct thread *t) -{ - t->kstack_ptr = tls_get()->irq_rsp; -} +void fork_trampoline(); /* the thread that calls this will be lost, so it should only be called * on the initial process, and while doing an exec diff --git a/usr.bin/init/init b/usr.bin/init/init new file mode 100755 index 0000000..32b5c06 Binary files /dev/null and b/usr.bin/init/init differ