1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 #include "textflag.h"
6
7 // Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
8 // It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
9 // Use a local trampoline, to avoid taking the address of a dynamically exported
10 // function.
11 TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
12 MOV _crosscall2_ptr(SB), X7
13 MOV $crosscall2_trampoline<>(SB), X8
14 MOV X8, (X7)
15 RET
16
17 TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
18 JMP crosscall2(SB)
19
20 // Called by C code generated by cmd/cgo.
21 // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
22 // Saves C callee-saved registers and calls cgocallback with three arguments.
23 // fn is the PC of a func(a unsafe.Pointer) function.
24 TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
25 /*
26 * Push arguments for fn (X10, X11, X13), along with all callee-save
27 * registers. Note that at procedure entry the first argument is at
28 * 8(X2).
29 */
30 ADD $(-8*29), X2
31 MOV X10, (8*1)(X2) // fn unsafe.Pointer
32 MOV X11, (8*2)(X2) // a unsafe.Pointer
33 MOV X13, (8*3)(X2) // ctxt uintptr
34 MOV X8, (8*4)(X2)
35 MOV X9, (8*5)(X2)
36 MOV X18, (8*6)(X2)
37 MOV X19, (8*7)(X2)
38 MOV X20, (8*8)(X2)
39 MOV X21, (8*9)(X2)
40 MOV X22, (8*10)(X2)
41 MOV X23, (8*11)(X2)
42 MOV X24, (8*12)(X2)
43 MOV X25, (8*13)(X2)
44 MOV X26, (8*14)(X2)
45 MOV g, (8*15)(X2)
46 MOV X1, (8*16)(X2)
47 MOVD F8, (8*17)(X2)
48 MOVD F9, (8*18)(X2)
49 MOVD F18, (8*19)(X2)
50 MOVD F19, (8*20)(X2)
51 MOVD F20, (8*21)(X2)
52 MOVD F21, (8*22)(X2)
53 MOVD F22, (8*23)(X2)
54 MOVD F23, (8*24)(X2)
55 MOVD F24, (8*25)(X2)
56 MOVD F25, (8*26)(X2)
57 MOVD F26, (8*27)(X2)
58 MOVD F27, (8*28)(X2)
59
60 // Initialize Go ABI environment
61 CALL runtime·load_g(SB)
62 CALL runtime·cgocallback(SB)
63
64 MOV (8*4)(X2), X8
65 MOV (8*5)(X2), X9
66 MOV (8*6)(X2), X18
67 MOV (8*7)(X2), X19
68 MOV (8*8)(X2), X20
69 MOV (8*9)(X2), X21
70 MOV (8*10)(X2), X22
71 MOV (8*11)(X2), X23
72 MOV (8*12)(X2), X24
73 MOV (8*13)(X2), X25
74 MOV (8*14)(X2), X26
75 MOV (8*15)(X2), g
76 MOV (8*16)(X2), X1
77 MOVD (8*17)(X2), F8
78 MOVD (8*18)(X2), F9
79 MOVD (8*19)(X2), F18
80 MOVD (8*20)(X2), F19
81 MOVD (8*21)(X2), F20
82 MOVD (8*22)(X2), F21
83 MOVD (8*23)(X2), F22
84 MOVD (8*24)(X2), F23
85 MOVD (8*25)(X2), F24
86 MOVD (8*26)(X2), F25
87 MOVD (8*27)(X2), F26
88 MOVD (8*28)(X2), F27
89 ADD $(8*29), X2
90
91 RET
92
View as plain text