Path: blob/main/stand/kboot/libkboot/arch/amd64/host_syscall.S
34889 views
#include <machine/asm.h>12/*3* Emulate the Linux system call interface. The system call number is set in4* %rax, and %rdi, %rsi, %rdx, %r10, %r8, %r9 have the 6 system call5* arguments. errno is returned as a negative value, but we use it more as a6* flag something went wrong rather than using its value.7*8* Note: For system calls, we use %r10 instead of %rcx for the 4th argument.9* See section A.2.1 for the Linux calling conventions of the ABI spec10* https://web.archive.org/web/20160801075146/http://www.x86-64.org/documentation/abi.pdf11* In addition to the below, %r11 and %rcx are destroyed, negative12* values are ERRNO for %rax between -1 and -4095 otherwise the system13* call is successful. Unlike other Unix systems, carry isn't used to14* signal an error in the system call. We expose the raw system call15* result, rather than do the POSIX converion to -1 and setting errno.16*/17ENTRY(host_syscall)18movq %rdi, %rax /* SYS_ number in %rax */19movq %rsi, %rdi /* arg2 -> 1 */20movq %rdx, %rsi /* arg3 -> 2 */21movq %rcx, %rdx /* arg4 -> 3 */22movq %r8, %r10 /* arg5 -> 4 */23movq %r9, %r8 /* arg6 -> 5 */24movq 8(%rsp),%r9 /* arg7 -> 6 from stack. */25syscall26ret27/* Note: We're exposing the raw return value to the caller */28END(host_syscall)2930.section .note.GNU-stack,"",%progbits313233