github.com/ebiten/purego@v0.0.0-20220525025155-0f6873f42222/sys_darwin_arm64.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  	SUB  $16, RSP   // push structure pointer
    29  	MOVD R0, 8(RSP)
    30  
    31  	MOVD 0(R0), R12 // fn
    32  	MOVD 16(R0), R1 // a2
    33  	MOVD 24(R0), R2 // a3
    34  	MOVD 32(R0), R3 // a4
    35  	MOVD 40(R0), R4 // a5
    36  	MOVD 48(R0), R5 // a6
    37  	MOVD 56(R0), R6 // a7
    38  	MOVD 64(R0), R7 // a8
    39  	MOVD 72(R0), R8 // a9
    40  	MOVD 8(R0), R0  // a1
    41  
    42  	// these may be float arguments
    43  	// so we put them also where C expects floats
    44  	FMOVD R0, F0 // a1
    45  	FMOVD R1, F1 // a2
    46  	FMOVD R2, F2 // a3
    47  	FMOVD R3, F3 // a4
    48  	FMOVD R4, F4 // a5
    49  	FMOVD R5, F5 // a6
    50  	FMOVD R6, F6 // a7
    51  	FMOVD R7, F7 // a8
    52  
    53  	MOVD R8, (RSP) // push a9 onto stack
    54  
    55  	BL (R12)
    56  
    57  	MOVD 8(RSP), R2     // pop structure pointer
    58  	ADD  $16, RSP
    59  	MOVD R0, 80(R2)     // save r1
    60  	MOVD R1, 88(R2)     // save r2
    61  	CMP  $-1, R0
    62  	BNE  ok
    63  	SUB  $16, RSP       // push structure pointer
    64  	MOVD R2, (RSP)
    65  	BL   libc_error(SB)
    66  	MOVW (R0), R0
    67  	MOVD (RSP), R2      // pop structure pointer
    68  	ADD  $16, RSP
    69  	MOVD R0, 96(R2)     // save err
    70  
    71  ok:
    72  	RET