1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3
4//go:build darwin || (!cgo && linux) || windows
5
6#include "textflag.h"
7#include "go_asm.h"
8#include "funcdata.h"
9#include "internal/abi/abi_arm64.h"
10
11// syscall9X calls a function in libc on behalf of the syscall package.
12// syscall9X takes a pointer to a struct like:
13// struct {
14// fn uintptr
15// a1 uintptr
16// a2 uintptr
17// a3 uintptr
18// a4 uintptr
19// a5 uintptr
20// a6 uintptr
21// a7 uintptr
22// a8 uintptr
23// a9 uintptr
24// r1 uintptr
25// r2 uintptr
26// err uintptr
27// }
28// syscall9X must be called on the g0 stack with the
29// C calling convention (use libcCall).
30GLOBL ·syscall9XABI0(SB), NOPTR|RODATA, $8
31DATA ·syscall9XABI0(SB)/8, $syscall9X(SB)
32TEXT syscall9X(SB), NOSPLIT, $0
33 SUB $16, RSP // push structure pointer
34 MOVD R0, 8(RSP)
35
36 FMOVD syscall9Args_f1(R0), F0 // f1
37 FMOVD syscall9Args_f2(R0), F1 // f2
38 FMOVD syscall9Args_f3(R0), F2 // f3
39 FMOVD syscall9Args_f4(R0), F3 // f4
40 FMOVD syscall9Args_f5(R0), F4 // f5
41 FMOVD syscall9Args_f6(R0), F5 // f6
42 FMOVD syscall9Args_f7(R0), F6 // f7
43 FMOVD syscall9Args_f8(R0), F7 // f8
44
45 MOVD syscall9Args_fn(R0), R12 // fn
46 MOVD syscall9Args_a2(R0), R1 // a2
47 MOVD syscall9Args_a3(R0), R2 // a3
48 MOVD syscall9Args_a4(R0), R3 // a4
49 MOVD syscall9Args_a5(R0), R4 // a5
50 MOVD syscall9Args_a6(R0), R5 // a6
51 MOVD syscall9Args_a7(R0), R6 // a7
52 MOVD syscall9Args_a8(R0), R7 // a8
53 MOVD syscall9Args_a9(R0), R8 // a9
54 MOVD syscall9Args_a1(R0), R0 // a1
55
56 MOVD R8, (RSP) // push a9 onto stack
57
58 BL (R12)
59
60 MOVD 8(RSP), R2 // pop structure pointer
61 ADD $16, RSP
62 MOVD R0, syscall9Args_r1(R2) // save r1
63 FMOVD F0, syscall9Args_r2(R2) // save r2
64 RET