github.com/ebiten/purego@v0.0.0-20220525025155-0f6873f42222/sys_darwin_amd64.s (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2022 The Ebiten Authors 3 4 #include "textflag.h" 5 6 // syscall9X calls a function in libc on behalf of the syscall package. 7 // syscall9X takes a pointer to a struct like: 8 // struct { 9 // fn uintptr 10 // a1 uintptr 11 // a2 uintptr 12 // a3 uintptr 13 // a4 uintptr 14 // a5 uintptr 15 // a6 uintptr 16 // a7 uintptr 17 // a8 uintptr 18 // a9 uintptr 19 // r1 uintptr 20 // r2 uintptr 21 // err uintptr 22 // } 23 // syscall9X must be called on the g0 stack with the 24 // C calling convention (use libcCall). 25 GLOBL ·syscall9XABI0(SB), NOPTR|RODATA, $8 26 DATA ·syscall9XABI0(SB)/8, $·syscall9X(SB) 27 TEXT ·syscall9X(SB), NOSPLIT, $0 28 PUSHQ BP 29 MOVQ SP, BP 30 SUBQ $32, SP 31 MOVQ DI, -8(BP) // save the pointer 32 MOVQ (0*8)(DI), R10 // fn 33 MOVQ (2*8)(DI), SI // a2 34 MOVQ (3*8)(DI), DX // a3 35 MOVQ (4*8)(DI), CX // a4 36 MOVQ (5*8)(DI), R8 // a5 37 MOVQ (6*8)(DI), R9 // a6 38 MOVQ (7*8)(DI), R11 // a7 39 MOVQ (8*8)(DI), R12 // a8 40 MOVQ (9*8)(DI), R13 // a9 41 MOVQ (1*8)(DI), DI // a1 42 43 // these may be float arguments 44 // so we put them also where C expects floats 45 MOVQ DI, X0 // a1 46 MOVQ SI, X1 // a2 47 MOVQ DX, X2 // a3 48 MOVQ CX, X3 // a4 49 MOVQ R8, X4 // a5 50 MOVQ R9, X5 // a6 51 MOVQ R11, X6 // a7 52 MOVQ R12, X7 // a8 53 54 // push the remaining paramters onto the stack 55 MOVQ R11, 0(SP) // push a7 56 MOVQ R12, 8(SP) // push a8 57 MOVQ R13, 16(SP) // push a9 58 XORL AX, AX // vararg: say "no float args" 59 60 CALL R10 61 62 MOVQ -8(BP), DI // get the pointer back 63 MOVQ AX, (10*8)(DI) // r1 64 MOVQ DX, (11*8)(DI) // r2 65 66 // Standard libc functions return -1 on error 67 // and set errno. 68 CMPQ AX, $-1 69 JNE ok 70 71 // Get error code from libc. 72 CALL libc_error(SB) 73 MOVLQSX (AX), AX 74 MOVQ (SP), DI 75 MOVQ AX, (12*8)(DI) // err 76 77 ok: 78 XORL AX, AX // no error (it's ignored anyway) 79 ADDQ $32, SP 80 MOVQ BP, SP 81 POPQ BP 82 RET