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