76 lines
1.6 KiB
ArmAsm
76 lines
1.6 KiB
ArmAsm
/* opencoreC - Fast Syscall Entry Trampoline (x86_64) */
|
|
.global syscall_entry
|
|
.extern kernel_syscall_dispatcher
|
|
|
|
/* Per-CPU scratch: user RSP saved here on syscall entry */
|
|
.section .bss
|
|
.align 8
|
|
.global cpu0_scratch_user_rsp
|
|
cpu0_scratch_user_rsp: .quad 0
|
|
|
|
.section .text
|
|
/*
|
|
* syscall_entry:
|
|
* On entry (SYSCALL from Ring 3):
|
|
* RCX = user RIP
|
|
* R11 = user RFLAGS
|
|
* RAX = syscall number
|
|
* RDI,RSI,RDX,R10,R8,R9 = args
|
|
* RSP = user RSP
|
|
*
|
|
* Strategy:
|
|
* 1. Save user RSP into scratch area
|
|
* 2. Load kernel RSP from TSS.RSP0 via gdt.rs TSS symbol
|
|
* 3. Build SyscallRegisters on kernel stack
|
|
* 4. Dispatch to Rust handler
|
|
* 5. Restore & sysretq
|
|
*/
|
|
syscall_entry:
|
|
/* Save user RSP */
|
|
mov [rip + cpu0_scratch_user_rsp], rsp
|
|
|
|
/* Load kernel stack from TSS.rsp0.
|
|
* TSS is exported as 'TSS' from gdt.rs.
|
|
* Layout: _reserved1(u32=4 bytes), rsp0(u64=8 bytes)
|
|
* So TSS.rsp0 is at offset 4 from TSS start.
|
|
*/
|
|
lea rsp, [rip + TSS]
|
|
mov rsp, [rsp + 4]
|
|
|
|
/* Push user RSP onto thread kernel stack */
|
|
push qword ptr [rip + cpu0_scratch_user_rsp]
|
|
|
|
/* Push user RIP and RFLAGS */
|
|
push rcx
|
|
push r11
|
|
|
|
/* Push syscall arguments as SyscallRegisters */
|
|
push rax
|
|
push rdi
|
|
push rsi
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
|
|
mov rdi, rsp
|
|
call kernel_syscall_dispatcher
|
|
|
|
/* Restore args */
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rsi
|
|
pop rdi
|
|
pop rax
|
|
|
|
/* Restore user context */
|
|
pop r11
|
|
pop rcx
|
|
|
|
/* Restore thread-specific user RSP directly from kernel stack */
|
|
pop rsp
|
|
|
|
sysretq
|