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:
@@ -1,51 +1,73 @@
|
||||
struc REGS
|
||||
.r15 resq 1 ; 0x00
|
||||
.r14 resq 1 ; 0x08
|
||||
.r13 resq 1 ; 0x10
|
||||
.r12 resq 1 ; 0x18
|
||||
.r11 resq 1 ; 0x20
|
||||
.r10 resq 1 ; 0x28
|
||||
.r9 resq 1 ; 0x30
|
||||
.r8 resq 1 ; 0x38
|
||||
|
||||
.rdi resq 1 ; 0x40
|
||||
.rsi resq 1 ; 0x48
|
||||
.rbp resq 1 ; 0x50
|
||||
.rbx resq 1 ; 0x58
|
||||
.rdx resq 1 ; 0x60
|
||||
.rcx resq 1 ; 0x68
|
||||
.rax resq 1 ; 0x70
|
||||
|
||||
.int resq 1 ; 0x78
|
||||
.err resq 1 ; 0x80
|
||||
.rip resq 1 ; 0x88
|
||||
.cs3 resq 1 ; 0x90
|
||||
.rflags resq 1 ; 0x98
|
||||
.rsp3 resq 1 ; 0xa0
|
||||
.ss3 resq 1 ; 0xa8
|
||||
endstruc
|
||||
|
||||
regs_total_size equ 0xb0
|
||||
regs_extra_size equ 0x78
|
||||
|
||||
%macro push_all 0
|
||||
sub rsp, 0x78
|
||||
sub rsp, regs_extra_size
|
||||
|
||||
; ss3 rsp + 0xa8
|
||||
; rsp3 rsp + 0xa0
|
||||
; flags3 rsp + 0x98
|
||||
; cs3 rsp + 0x90
|
||||
; rip3 rsp + 0x88
|
||||
; error rsp + 0x80
|
||||
; vector rsp + 0x78
|
||||
mov [rsp + REGS.rax], rax
|
||||
mov [rsp + REGS.rcx], rcx
|
||||
mov [rsp + REGS.rdx], rdx
|
||||
mov [rsp + REGS.rbx], rbx
|
||||
mov [rsp + REGS.rbp], rbp
|
||||
mov [rsp + REGS.rsi], rsi
|
||||
mov [rsp + REGS.rdi], rdi
|
||||
|
||||
mov [rsp + 0x70], rax
|
||||
mov [rsp + 0x68], rcx
|
||||
mov [rsp + 0x60], rdx
|
||||
mov [rsp + 0x58], rbx
|
||||
mov [rsp + 0x50], rbp
|
||||
mov [rsp + 0x48], rsi
|
||||
mov [rsp + 0x40], rdi
|
||||
|
||||
mov [rsp + 0x38], r8
|
||||
mov [rsp + 0x30], r9
|
||||
mov [rsp + 0x28], r10
|
||||
mov [rsp + 0x20], r11
|
||||
mov [rsp + 0x18], r12
|
||||
mov [rsp + 0x10], r13
|
||||
mov [rsp + 0x08], r14
|
||||
mov [rsp + 0x00], r15
|
||||
mov [rsp + REGS.r8 ], r8
|
||||
mov [rsp + REGS.r9 ], r9
|
||||
mov [rsp + REGS.r10], r10
|
||||
mov [rsp + REGS.r11], r11
|
||||
mov [rsp + REGS.r12], r12
|
||||
mov [rsp + REGS.r13], r13
|
||||
mov [rsp + REGS.r14], r14
|
||||
mov [rsp + REGS.r15], r15
|
||||
%endmacro
|
||||
|
||||
%macro pop_all 0
|
||||
mov rax, [rsp + 0x70]
|
||||
mov rcx, [rsp + 0x68]
|
||||
mov rdx, [rsp + 0x60]
|
||||
mov rbx, [rsp + 0x58]
|
||||
mov rbp, [rsp + 0x50]
|
||||
mov rsi, [rsp + 0x48]
|
||||
mov rdi, [rsp + 0x40]
|
||||
mov rax, [rsp + REGS.rax]
|
||||
mov rcx, [rsp + REGS.rcx]
|
||||
mov rdx, [rsp + REGS.rdx]
|
||||
mov rbx, [rsp + REGS.rbx]
|
||||
mov rbp, [rsp + REGS.rbp]
|
||||
mov rsi, [rsp + REGS.rsi]
|
||||
mov rdi, [rsp + REGS.rdi]
|
||||
|
||||
mov r8, [rsp + 0x38]
|
||||
mov r9, [rsp + 0x30]
|
||||
mov r10, [rsp + 0x28]
|
||||
mov r11, [rsp + 0x20]
|
||||
mov r12, [rsp + 0x18]
|
||||
mov r13, [rsp + 0x10]
|
||||
mov r14, [rsp + 0x08]
|
||||
mov r15, [rsp + 0x00]
|
||||
mov r8, [rsp + REGS.r8 ]
|
||||
mov r9, [rsp + REGS.r9 ]
|
||||
mov r10, [rsp + REGS.r10]
|
||||
mov r11, [rsp + REGS.r11]
|
||||
mov r12, [rsp + REGS.r12]
|
||||
mov r13, [rsp + REGS.r13]
|
||||
mov r14, [rsp + REGS.r14]
|
||||
mov r15, [rsp + REGS.r15]
|
||||
|
||||
add rsp, 0x78
|
||||
add rsp, regs_extra_size
|
||||
%endmacro
|
||||
|
||||
%macro check_swap_gs 0
|
||||
|
||||
Reference in New Issue
Block a user