1 // Copyright 2015 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 #include "abi_arm64.h"
7
8 // Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
9 // It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
10 // Use a local trampoline, to avoid taking the address of a dynamically exported
11 // function.
12 TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
13 MOVD _crosscall2_ptr(SB), R1
14 MOVD $crosscall2_trampoline<>(SB), R2
15 MOVD R2, (R1)
16 RET
17
18 TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
19 JMP crosscall2(SB)
20
21 // Called by C code generated by cmd/cgo.
22 // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
23 // Saves C callee-saved registers and calls cgocallback with three arguments.
24 // fn is the PC of a func(a unsafe.Pointer) function.
25 TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
26 /*
27 * We still need to save all callee save register as before, and then
28 * push 3 args for fn (R0, R1, R3), skipping R2.
29 * Also note that at procedure entry in gc world, 8(RSP) will be the
30 * first arg.
31 */
32 SUB $(8*24), RSP
33 STP (R0, R1), (8*1)(RSP)
34 MOVD R3, (8*3)(RSP)
35
36 SAVE_R19_TO_R28(8*4)
37 SAVE_F8_TO_F15(8*14)
38 STP (R29, R30), (8*22)(RSP)
39
40
41 // Initialize Go ABI environment
42 BL runtime·load_g(SB)
43 BL runtime·cgocallback(SB)
44
45 RESTORE_R19_TO_R28(8*4)
46 RESTORE_F8_TO_F15(8*14)
47 LDP (8*22)(RSP), (R29, R30)
48
49 ADD $(8*24), RSP
50 RET
51
View as plain text