.globl syscall_64bit_handler
syscall_64bit_handler:
- push %rcx
+ push %rax
+ 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 %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
+
mov %r10, %rcx
cmp $syscall_n, %rax
jae incorrect_syscall
callq *syscalls_call_table(, %rax, 8)
- pop %rcx
+syscall_end:
+ movq %rax, %rbp
+ 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 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
sysretq
incorrect_syscall:
call syscall_rax_error_handler
- pop %rcx
- sysretq
+ jmp syscall_end
.section .rodata
syscalls_call_table:
.quad syscall_println
.quad syscall_print_low_mmap
.set syscall_n, 3
+process_struct_table: .quad 0xFFFFC00000000000
std::uint64_t r13;
std::uint64_t r14;
std::uint64_t r15;
- std::uint64_t mxcsr;
+ std::uint64_t mxcsr; // UNUSED for now.
std::uint64_t x87cw;
port ports[4093];
};
return port < 4093 && process_exists(pid) && get_process(pid).ports[port].exists;
}
-extern std::uint64_t current_pid;
+extern "C" std::uint64_t current_pid;
} // namespace os