-
-
Save catap/a20b8b1f46b0ba79b9f7297e73df0563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#elif defined(VGP_amd64_darwin) | |
/* Incoming args (syscall number + up to 8 args) come in registers and stack | |
The kernel's syscall calling convention is: | |
* the syscall number goes in rax | |
* the args are passed to the syscall in registers and the stack | |
* the call instruction is 'syscall' | |
Return value: | |
* MACH,MDEP: the return value comes back in rax | |
* UNIX: the return value comes back in rdx:rax (hi64:lo64) | |
Error: | |
* MACH,MDEP: no error is returned | |
* UNIX: the carry flag indicates success or failure | |
nb here, sizeof(UWord) == sizeof(ULong) | |
*/ | |
__private_extern__ UWord | |
do_syscall_unix_WRK ( UWord a1, UWord a2, UWord a3, /* rdi, rsi, rdx */ | |
UWord a4, UWord a5, UWord a6, /* rcx, r8, r9 */ | |
UWord a7, UWord a8, /* 8(rsp), 16(rsp) */ | |
UWord syscall_no, /* 24(rsp) */ | |
/*OUT*/ULong* errflag, /* 32(rsp) */ | |
/*OUT*/ULong* res2 ); /* 40(rsp) */ | |
// Unix syscall: 128-bit return in rax:rdx, with LSB in rax | |
// error indicated by carry flag: clear=good, set=bad | |
asm(".private_extern _do_syscall_unix_WRK\n" | |
"_do_syscall_unix_WRK:\n" | |
" movq %rcx, %r10 \n" /* pass rcx in r10 instead */ | |
" movq 32(%rsp), %rax \n" /* assume syscall success */ | |
" movq $0, (%rax) \n" | |
" movq 24(%rsp), %rax \n" /* load syscall_no */ | |
" syscall \n" | |
" jnc 1f \n" /* jump if success */ | |
" movq 32(%rsp), %rcx \n" /* syscall failed - set *errflag */ | |
" movq $1, (%rcx) \n" | |
" 1: movq 40(%rsp), %rcx \n" /* save 2nd result word */ | |
" movq %rdx, (%rcx) \n" | |
" retq \n" /* return 1st result word */ | |
); | |
__private_extern__ UWord | |
do_syscall_mach_WRK ( UWord a1, UWord a2, UWord a3, /* rdi, rsi, rdx */ | |
UWord a4, UWord a5, UWord a6, /* rcx, r8, r9 */ | |
UWord a7, UWord a8, /* 8(rsp), 16(rsp) */ | |
UWord syscall_no ); /* 24(rsp) */ | |
// Mach trap: 64-bit result, no error flag | |
asm(".private_extern _do_syscall_mach_WRK\n" | |
"_do_syscall_mach_WRK:\n" | |
" movq %rcx, %r10 \n" /* pass rcx in r10 instead */ | |
" movq 24(%rsp), %rax \n" /* load syscall_no */ | |
" syscall \n" | |
" retq \n" | |
); | |
#elif defined(VGP_s390x_linux) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment