diff --git a/kaleid/kernel/ke/isr.asm b/kaleid/kernel/ke/isr.asm index 88f9723..57ada84 100644 --- a/kaleid/kernel/ke/isr.asm +++ b/kaleid/kernel/ke/isr.asm @@ -27,10 +27,9 @@ %include "kaleid/kernel/ke/cpuf.inc" global KeLoadIDT - extern _KeIdtPtr extern _KeHandleISR -extern _KeSyscallHandler +extern syscallPreHandler ;; ;; Loads the IDT @@ -78,73 +77,6 @@ Die: hlt jmp Die -;; -;; System call pre-handler -;; -syscallPreHandler: - push r15 - push r14 - push r13 - push r12 - push r11 - push r10 - push r9 - push r8 - push rbp - push 0 - push rsi - push rdx - push rcx - push rbx - push rax - mov rax, cr8 - push rax - mov rax, cr4 - push rax - mov rax, cr3 - push rax - mov rax, cr2 - push rax - mov rax, cr0 - push rax - mov rcx, 0xC0000080 - rdmsr - push rax - - ; Call the C routine to dispatch interrupts - cld ; DF must be cleared by the caller - mov rsi, rsp ; First argument points to the processor state - mov rbp, 0 ; Terminate stack traces here - - call _KeSyscallHandler - - ; pop the control registers - add rsp, 48 - ; pop registers except return value - pop rbx - pop rbx ; 2x rbx to discard rax - pop rcx - pop rdx - pop rsi - pop rdi - pop rbp - pop r8 - pop r9 - pop r10 - pop r11 - pop r12 - pop r13 - pop r14 - pop r15 - ; pop the error code and interrupt id - add rsp, 16 - - iretq - -Die2: - hlt - jmp Die - ;; Divide Error Fault IsrWithoutErrCode 0 diff --git a/kaleid/kernel/ke/syscall.asm b/kaleid/kernel/ke/syscall.asm index 533834d..c9cca05 100644 --- a/kaleid/kernel/ke/syscall.asm +++ b/kaleid/kernel/ke/syscall.asm @@ -28,7 +28,72 @@ global KeJumpToUserspace global KeSyscall -extern KernLog +global syscallPreHandler +extern _KeSyscallHandler + + +;; +;; System call pre-handler +;; +syscallPreHandler: + push r15 + push r14 + push r13 + push r12 + push r11 + push 0 + push r9 + push r8 + push rbp + push 0 + push 0 + push 0 + push rcx + push rbx + push rax + mov rax, cr8 + push rax + mov rax, cr4 + push rax + mov rax, cr3 + push rax + mov rax, cr2 + push rax + mov rax, cr0 + push rax + mov rcx, 0xC0000080 + rdmsr + push rax + + ; Call the C routine to dispatch interrupts + cld ; DF must be cleared by the caller + mov rsi, rsp ; First argument points to the processor state + mov rbp, 0 ; Terminate stack traces here + + call _KeSyscallHandler + + ; pop the control registers + add rsp, 48 + ; pop registers except return value + pop rbx + pop rbx ; 2x rbx to discard rax + pop rcx + pop rdx + pop rsi + pop rdi + pop rbp + pop r8 + pop r9 + pop r10 + pop r11 + pop r12 + pop r13 + pop r14 + pop r15 + ; pop the error code and interrupt id + add rsp, 16 + + iretq ;; ;; To get ring3 code running