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//go:build mips || mipsle
6
7#include "textflag.h"
8
9// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
10// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
11// Use a local trampoline, to avoid taking the address of a dynamically exported
12// function.
13TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
14 MOVW _crosscall2_ptr(SB), R5
15 MOVW $crosscall2_trampoline<>(SB), R6
16 MOVW R6, (R5)
17 RET
18
19TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
20 JMP crosscall2(SB)
21
22// Called by C code generated by cmd/cgo.
23// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
24// Saves C callee-saved registers and calls cgocallback with three arguments.
25// fn is the PC of a func(a unsafe.Pointer) function.
26TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
27 /*
28 * We still need to save all callee save register as before, and then
29 * push 3 args for fn (R4, R5, R7), skipping R6.
30 * Also note that at procedure entry in gc world, 4(R29) will be the
31 * first arg.
32 */
33
34 // Space for 9 caller-saved GPR + LR + 6 caller-saved FPR.
35 // O32 ABI allows us to smash 16 bytes argument area of caller frame.
36#ifndef GOMIPS_softfloat
37 SUBU $(4*14+8*6-16), R29
38#else
39 SUBU $(4*14-16), R29 // For soft-float, no FPR.
40#endif
41 MOVW R4, (4*1)(R29) // fn unsafe.Pointer
42 MOVW R5, (4*2)(R29) // a unsafe.Pointer
43 MOVW R7, (4*3)(R29) // ctxt uintptr
44 MOVW R16, (4*4)(R29)
45 MOVW R17, (4*5)(R29)
46 MOVW R18, (4*6)(R29)
47 MOVW R19, (4*7)(R29)
48 MOVW R20, (4*8)(R29)
49 MOVW R21, (4*9)(R29)
50 MOVW R22, (4*10)(R29)
51 MOVW R23, (4*11)(R29)
52 MOVW g, (4*12)(R29)
53 MOVW R31, (4*13)(R29)
54#ifndef GOMIPS_softfloat
55 MOVD F20, (4*14)(R29)
56 MOVD F22, (4*14+8*1)(R29)
57 MOVD F24, (4*14+8*2)(R29)
58 MOVD F26, (4*14+8*3)(R29)
59 MOVD F28, (4*14+8*4)(R29)
60 MOVD F30, (4*14+8*5)(R29)
61#endif
62 JAL runtime·load_g(SB)
63
64 JAL runtime·cgocallback(SB)
65
66 MOVW (4*4)(R29), R16
67 MOVW (4*5)(R29), R17
68 MOVW (4*6)(R29), R18
69 MOVW (4*7)(R29), R19
70 MOVW (4*8)(R29), R20
71 MOVW (4*9)(R29), R21
72 MOVW (4*10)(R29), R22
73 MOVW (4*11)(R29), R23
74 MOVW (4*12)(R29), g
75 MOVW (4*13)(R29), R31
76#ifndef GOMIPS_softfloat
77 MOVD (4*14)(R29), F20
78 MOVD (4*14+8*1)(R29), F22
79 MOVD (4*14+8*2)(R29), F24
80 MOVD (4*14+8*3)(R29), F26
81 MOVD (4*14+8*4)(R29), F28
82 MOVD (4*14+8*5)(R29), F30
83
84 ADDU $(4*14+8*6-16), R29
85#else
86 ADDU $(4*14-16), R29
87#endif
88 RET
View as plain text