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