github.com/jwijenbergh/purego@v0.0.0-20240126093400-70ff3a61df13/sys_arm64.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
     3  
     4  //go:build darwin || freebsd || linux || windows
     5  
     6  #include "textflag.h"
     7  #include "go_asm.h"
     8  #include "funcdata.h"
     9  
    10  #define STACK_SIZE 64
    11  #define PTR_ADDRESS (STACK_SIZE - 8)
    12  
    13  // syscall15X calls a function in libc on behalf of the syscall package.
    14  // syscall15X takes a pointer to a struct like:
    15  // struct {
    16  //	fn    uintptr
    17  //	a1    uintptr
    18  //	a2    uintptr
    19  //	a3    uintptr
    20  //	a4    uintptr
    21  //	a5    uintptr
    22  //	a6    uintptr
    23  //	a7    uintptr
    24  //	a8    uintptr
    25  //	a9    uintptr
    26  //	a10    uintptr
    27  //	a11    uintptr
    28  //	a12    uintptr
    29  //	a13    uintptr
    30  //	a14    uintptr
    31  //	a15    uintptr
    32  //	r1    uintptr
    33  //	r2    uintptr
    34  //	err   uintptr
    35  // }
    36  // syscall15X must be called on the g0 stack with the
    37  // C calling convention (use libcCall).
    38  GLOBL ·syscall15XABI0(SB), NOPTR|RODATA, $8
    39  DATA ·syscall15XABI0(SB)/8, $syscall15X(SB)
    40  TEXT syscall15X(SB), NOSPLIT, $0
    41  	SUB  $STACK_SIZE, RSP     // push structure pointer
    42  	MOVD R0, PTR_ADDRESS(RSP)
    43  	MOVD R0, R9
    44  
    45  	FMOVD syscall15Args_f1(R9), F0 // f1
    46  	FMOVD syscall15Args_f2(R9), F1 // f2
    47  	FMOVD syscall15Args_f3(R9), F2 // f3
    48  	FMOVD syscall15Args_f4(R9), F3 // f4
    49  	FMOVD syscall15Args_f5(R9), F4 // f5
    50  	FMOVD syscall15Args_f6(R9), F5 // f6
    51  	FMOVD syscall15Args_f7(R9), F6 // f7
    52  	FMOVD syscall15Args_f8(R9), F7 // f8
    53  
    54  	MOVD syscall15Args_a1(R9), R0 // a1
    55  	MOVD syscall15Args_a2(R9), R1 // a2
    56  	MOVD syscall15Args_a3(R9), R2 // a3
    57  	MOVD syscall15Args_a4(R9), R3 // a4
    58  	MOVD syscall15Args_a5(R9), R4 // a5
    59  	MOVD syscall15Args_a6(R9), R5 // a6
    60  	MOVD syscall15Args_a7(R9), R6 // a7
    61  	MOVD syscall15Args_a8(R9), R7 // a8
    62  
    63  	MOVD syscall15Args_a9(R9), R10
    64  	MOVD R10, 0(RSP)                // push a9 onto stack
    65  	MOVD syscall15Args_a10(R9), R10
    66  	MOVD R10, 8(RSP)                // push a10 onto stack
    67  	MOVD syscall15Args_a11(R9), R10
    68  	MOVD R10, 16(RSP)               // push a11 onto stack
    69  	MOVD syscall15Args_a12(R9), R10
    70  	MOVD R10, 24(RSP)               // push a12 onto stack
    71  	MOVD syscall15Args_a13(R9), R10
    72  	MOVD R10, 32(RSP)               // push a13 onto stack
    73  	MOVD syscall15Args_a14(R9), R10
    74  	MOVD R10, 40(RSP)               // push a14 onto stack
    75  	MOVD syscall15Args_a15(R9), R10
    76  	MOVD R10, 48(RSP)               // push a15 onto stack
    77  
    78  	MOVD syscall15Args_fn(R9), R10 // fn
    79  	BL   (R10)
    80  
    81  	MOVD  PTR_ADDRESS(RSP), R2     // pop structure pointer
    82  	ADD   $STACK_SIZE, RSP
    83  	MOVD  R0, syscall15Args_r1(R2) // save r1
    84  	FMOVD F0, syscall15Args_r2(R2) // save r2
    85  	RET