...
1// Copyright 2016 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.
11TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
12 MOVD _crosscall2_ptr(SB), R1
13 MOVD $crosscall2_trampoline<>(SB), R2
14 MOVD R2, (R1)
15 RET
16
17TEXT 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.
24TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
25 // Start with standard C stack frame layout and linkage.
26
27 // Save R6-R15 in the register save area of the calling function.
28 STMG R6, R15, 48(R15)
29
30 // Allocate 96 bytes on the stack.
31 MOVD $-96(R15), R15
32
33 // Save F8-F15 in our stack frame.
34 FMOVD F8, 32(R15)
35 FMOVD F9, 40(R15)
36 FMOVD F10, 48(R15)
37 FMOVD F11, 56(R15)
38 FMOVD F12, 64(R15)
39 FMOVD F13, 72(R15)
40 FMOVD F14, 80(R15)
41 FMOVD F15, 88(R15)
42
43 // Initialize Go ABI environment.
44 BL runtime·load_g(SB)
45
46 MOVD R2, 8(R15) // fn unsafe.Pointer
47 MOVD R3, 16(R15) // a unsafe.Pointer
48 // Skip R4 = n uint32
49 MOVD R5, 24(R15) // ctxt uintptr
50 BL runtime·cgocallback(SB)
51
52 FMOVD 32(R15), F8
53 FMOVD 40(R15), F9
54 FMOVD 48(R15), F10
55 FMOVD 56(R15), F11
56 FMOVD 64(R15), F12
57 FMOVD 72(R15), F13
58 FMOVD 80(R15), F14
59 FMOVD 88(R15), F15
60
61 // De-allocate stack frame.
62 MOVD $96(R15), R15
63
64 // Restore R6-R15.
65 LMG 48(R15), R6, R15
66
67 RET
68
View as plain text