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