.globl syscall_64bit_handler
syscall_64bit_handler:
- push %rax
+ mov %rax, rax_save
movq current_pid, %rax
shl $17, %rax # * 0x1000 * 32 (i.e. the size of a process)
addq process_struct_table, %rax
# %rax now contains the address of the current process struct.
movq %rcx, 0x10(%rax) # %rip
movq %rbx, 0x18(%rax)
- movq %rsp, 0x20(%rax) # original %rsp
- addq $8, 0x20(%rax) # here as well
+ movq %rsp, 0x20(%rax)
movq %rbp, 0x28(%rax)
movq %r12, 0x30(%rax)
movq %r13, 0x38(%rax)
movq %r14, 0x40(%rax)
movq %r15, 0x48(%rax)
fstcw 0x58(%rax)
- # Current process registers have now all been updated.
- pop %rax
+ # Current process registers have now all been saved.
+ mov rax_save, %rax
mov %r10, %rcx
cmp $syscall_n, %rax
+ mov $stack_top, %rsp # Setup stack
jae incorrect_syscall
callq *syscalls_call_table(, %rax, 8)
syscall_end:
- movq %rax, %rbp
+ mov %rax, rax_save
movq current_pid, %rax
shl $17, %rax # * 0x1000 * 32 (i.e. the size of a process)
addq process_struct_table, %rax
movq 0x10(%rax), %rcx # %rip
movq 0x18(%rax), %rbx
movq 0x20(%rax), %rsp
- push %rbp # %rax
movq 0x28(%rax), %rbp
movq 0x30(%rax), %r12
movq 0x38(%rax), %r13
movq 0x40(%rax), %r14
movq 0x48(%rax), %r15
fldcw 0x58(%rax)
- # Current process registers have now all been updated.
- pop %rax
+ # Current process registers have now all been loaded.
+ mov rax_save, %rax
sysretq
incorrect_syscall:
call syscall_rax_error_handler
.quad syscall_print_low_mmap
.set syscall_n, 3
process_struct_table: .quad 0xFFFFC00000000000
+
+.section .data
+rax_save: .quad 1