Skip to content

Commit

Permalink
adjust kernel stack since syscall doesn't do it for us
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Dec 21, 2021
1 parent 9e3bdb3 commit d6a2159
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/kernel/syscall/syscall.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

; Include useful functions, constants and macros
%include "../../../include/boot/global/macro.asm"
%include "../../../include/boot/global/const.asm"
%include "../../../include/boot/global/mem.asm"


; Export references to C
global syscall_entry
Expand All @@ -9,12 +14,12 @@ extern syscall_handler
section .text

syscall_entry:
;TODO: Test (while I figure out how to disable interrupts via SFMASK)
; the idea is to not have to deal with preemptable stuff that can cause
; a syscall to be stopped half-way to server an interrupt and then come back.
; While this seems pretty cool to figure out, it will for certain take a
; little longer as debugging becomes really hard.
cli
; TODO: read from TSS
; Ideally we should point this to the kernel stack in the TSS.rsp0. For some reason I'm having trouble accessing it correctly
; Right now we are not dealing with preemtable kernel so pointing it to the original
; kernel stack will work.
push rsp
mov rsp, Kernel.New.Start.VirtualAddress

; preserve all values so we can access them from C
; and know where to go back to (RCX, r11)
Expand All @@ -40,6 +45,8 @@ syscall_entry:
pop rbx
add rsp, 8 ; ditch rax value it's used for the return value

pop rsp

; go back to where we came from
o64 sysret

0 comments on commit d6a2159

Please sign in to comment.