1// Copyright 2012 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 MOVW _crosscall2_ptr(SB), R1
13 MOVW $crosscall2_trampoline<>(SB), R2
14 MOVW 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 SUB $(8*9), R13 // Reserve space for the floating point registers.
26 // The C arguments arrive in R0, R1, R2, and R3. We want to
27 // pass R0, R1, and R3 to Go, so we push those on the stack.
28 // Also, save C callee-save registers R4-R12.
29 MOVM.WP [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12], (R13)
30 // Finally, save the link register R14. This also puts the
31 // arguments we pushed for cgocallback where they need to be,
32 // starting at 4(R13).
33 MOVW.W R14, -4(R13)
34
35 // Skip floating point registers if goarmsoftfp!=0.
36 MOVB runtime·goarmsoftfp(SB), R11
37 CMP $0, R11
38 BNE skipfpsave
39 MOVD F8, (13*4+8*1)(R13)
40 MOVD F9, (13*4+8*2)(R13)
41 MOVD F10, (13*4+8*3)(R13)
42 MOVD F11, (13*4+8*4)(R13)
43 MOVD F12, (13*4+8*5)(R13)
44 MOVD F13, (13*4+8*6)(R13)
45 MOVD F14, (13*4+8*7)(R13)
46 MOVD F15, (13*4+8*8)(R13)
47
48skipfpsave:
49 BL runtime·load_g(SB)
50 // We set up the arguments to cgocallback when saving registers above.
51 BL runtime·cgocallback(SB)
52
53 MOVB runtime·goarmsoftfp(SB), R11
54 CMP $0, R11
55 BNE skipfprest
56 MOVD (13*4+8*1)(R13), F8
57 MOVD (13*4+8*2)(R13), F9
58 MOVD (13*4+8*3)(R13), F10
59 MOVD (13*4+8*4)(R13), F11
60 MOVD (13*4+8*5)(R13), F12
61 MOVD (13*4+8*6)(R13), F13
62 MOVD (13*4+8*7)(R13), F14
63 MOVD (13*4+8*8)(R13), F15
64
65skipfprest:
66 MOVW.P 4(R13), R14
67 MOVM.IAW (R13), [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12]
68 ADD $(8*9), R13
69 MOVW R14, R15
View as plain text