xref: /freebsd/stand/kboot/libkboot/arch/amd64/host_syscall.S (revision 58c99df2196c5564a6922dcfe4d03387cebdd10c)
109933581SWarner Losh#include <machine/asm.h>
209933581SWarner Losh
309933581SWarner Losh/*
409933581SWarner Losh * Emulate the Linux system call interface. The system call number is set in
509933581SWarner Losh * %rax, and %rdi, %rsi, %rdx, %r10, %r8, %r9 have the 6 system call
609933581SWarner Losh * arguments. errno is returned as a negative value, but we use it more as a
709933581SWarner Losh * flag something went wrong rather than using its value.
809933581SWarner Losh *
909933581SWarner Losh * Note: For system calls, we use %r10 instead of %rcx for the 4th argument.
1009933581SWarner Losh * See section A.2.1 for the Linux calling conventions of the ABI spec
1109933581SWarner Losh * https://web.archive.org/web/20160801075146/http://www.x86-64.org/documentation/abi.pdf
1209933581SWarner Losh * In addition to the below, %r11 and %rcx are destroyed, negative
1309933581SWarner Losh * values are ERRNO for %rax between -1 and -4095 otherwise the system
1409933581SWarner Losh * call is successful. Unlike other Unix systems, carry isn't used to
1509933581SWarner Losh * signal an error in the system call. We expose the raw system call
1609933581SWarner Losh * result, rather than do the POSIX converion to -1 and setting errno.
1709933581SWarner Losh */
1809933581SWarner LoshENTRY(host_syscall)
1909933581SWarner Losh	movq %rdi, %rax		/* SYS_ number in %rax */
2009933581SWarner Losh	movq %rsi, %rdi		/* arg2 -> 1 */
2109933581SWarner Losh	movq %rdx, %rsi		/* arg3 -> 2 */
2209933581SWarner Losh	movq %rcx, %rdx		/* arg4 -> 3 */
2309933581SWarner Losh	movq %r8, %r10		/* arg5 -> 4 */
2409933581SWarner Losh	movq %r9, %r8		/* arg6 -> 5 */
2509933581SWarner Losh        movq 8(%rsp),%r9        /* arg7 -> 6 from stack.  */
2609933581SWarner Losh        syscall
2709933581SWarner Losh	ret
2809933581SWarner Losh/* Note: We're exposing the raw return value to the caller */
2909933581SWarner LoshEND(host_syscall)
30*58c99df2SWarner Losh
31*58c99df2SWarner Losh	.section .note.GNU-stack,"",%progbits
32