Improve syscalls for new task switching

There are a lot of under the hood changes here:
- Move syscalls to be a dispatch table, defined by syscalls.inc
- Don't need a full process state (push_all) in syscalls now
- In push_all, define REGS instead of using offsets
- Save TWO stack pointers as well as current saved stack pointer in TCB:
  - rsp0 is the base of the kernel stack for interrupts
  - rsp3 is the saved user stack from cpu_data
- Update syscall numbers in nulldrv
- Some asm-debugging enhancements to the gdb script
- fork() still not working
This commit is contained in:
Justin C. Miller
2019-04-02 00:25:36 -07:00
parent ca2362f858
commit 11a53e792f
17 changed files with 284 additions and 215 deletions

View File

@@ -1,53 +1,52 @@
%include "push_all.inc"
%include "tasking.inc"
%define SYSCALL(name, nargs) resb 1
struc SYSCALLS
%include "syscalls.inc"
.count:
endstruc
extern __counter_syscall_enter
extern __counter_syscall_sysret
extern syscall_handler
extern isr_handler_return
extern syscall_registry
extern syscall_invalid
global syscall_handler_prelude
syscall_handler_prelude:
swapgs
mov [gs:0x08], rsp
mov rsp, [gs:0x00]
mov [gs:CPU_DATA.rsp3], rsp
mov rsp, [gs:CPU_DATA.rsp0]
push 0x23 ; ss
push 0x00 ; rsp - to be filled
push r11 ; rflags
push 0x2b ; cs
push rcx ; user rip
push 0 ; bogus error
push 0 ; bogus vector
push_all
push rcx
push rbp
mov rbp, rsp
push r11
inc qword [rel __counter_syscall_enter]
mov rax, [gs:0x08]
mov [rsp + 0xa0], rax
mov rax, [rsp + 0x70]
cmp rax, SYSCALLS.count
jl .ok_syscall
mov rdi, rsp
call syscall_handler
mov rdi, rax
call syscall_invalid
mov rax, [rsp + 0x90]
and rax, 0x3
cmp rax, 0x3
jne isr_handler_return
.ok_syscall:
lea r11, [rel syscall_registry]
mov r11, [r11 + rax * 8]
call r11
inc qword [rel __counter_syscall_sysret]
mov rax, [rsp + 0xa0]
mov [gs:0x08], rax
pop r11
pop rbp
pop rcx
pop_all
add rsp, 16 ; ignore bogus interrupt / error
pop rcx ; user rip
add rsp, 8 ; ignore cs
pop r11 ; flags
add rsp, 16 ; rsp, ss
mov [gs:0x00], rsp
mov rsp, [gs:0x08]
mov [gs:CPU_DATA.rsp0], rsp
mov rsp, [gs:CPU_DATA.rsp3]
swapgs
o64 sysret