Text file
src/runtime/cgo/gcc_linux_ppc64x.S
1 // Copyright 2014 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 linux && (ppc64 || ppc64le)
6
7 .file "gcc_linux_ppc64x.S"
8
9 // Define a frame which has no argument space, but is compatible with
10 // a call into a Go ABI. We allocate 32B to match FIXED_FRAME with
11 // similar semantics, except we store the backchain pointer, not the
12 // LR at offset 0. R2 is stored in the Go TOC save slot (offset 24).
13 .set GPR_OFFSET, 32
14 .set FPR_OFFSET, GPR_OFFSET + 18*8
15 .set VR_OFFSET, FPR_OFFSET + 18*8
16 .set FRAME_SIZE, VR_OFFSET + 12*16
17
18 .macro FOR_EACH_GPR opcode r=14
19 .ifge 31 - \r
20 \opcode \r, GPR_OFFSET + 8*(\r-14)(1)
21 FOR_EACH_GPR \opcode "(\r+1)"
22 .endif
23 .endm
24
25 .macro FOR_EACH_FPR opcode fr=14
26 .ifge 31 - \fr
27 \opcode \fr, FPR_OFFSET + 8*(\fr-14)(1)
28 FOR_EACH_FPR \opcode "(\fr+1)"
29 .endif
30 .endm
31
32 .macro FOR_EACH_VR opcode vr=20
33 .ifge 31 - \vr
34 li 0, VR_OFFSET + 16*(\vr-20)
35 \opcode \vr, 1, 0
36 FOR_EACH_VR \opcode "(\vr+1)"
37 .endif
38 .endm
39
40 /*
41 * void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g)
42 *
43 * Calling into the gc tool chain, where all registers are caller save.
44 * Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
45 * callee-save, so they must be saved explicitly.
46 * ABI: r3=fn, r4=setg_gcc, r5=g on entry.
47 */
48 .globl crosscall1
49 crosscall1:
50 // Start with standard C stack frame layout and linkage
51 mflr %r0
52 std %r0, 16(%r1) // Save LR in caller's frame
53 mfcr %r0
54 std %r0, 8(%r1) // Save CR in caller's frame
55 stdu %r1, -FRAME_SIZE(%r1)
56 std %r2, 24(%r1)
57
58 FOR_EACH_GPR std
59 FOR_EACH_FPR stfd
60 FOR_EACH_VR stvx
61
62 // Set up Go ABI constant registers
63 li %r0, 0
64
65 // Save fn in r14 (callee-save) while we call setg_gcc
66 mr %r14, %r3
67 // Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
68 mr %r30, %r5
69
70 // Call setg_gcc(g)
71 mr %r3, %r5 /* arg: g */
72 mr %r12, %r4 /* setg_gcc */
73 mtctr %r12
74 bctrl
75
76 // Call fn()
77 mr %r12, %r14
78 mtctr %r12
79 bctrl
80
81 FOR_EACH_GPR ld
82 FOR_EACH_FPR lfd
83 FOR_EACH_VR lvx
84
85 ld %r2, 24(%r1)
86 addi %r1, %r1, FRAME_SIZE
87 ld %r0, 16(%r1)
88 mtlr %r0
89 ld %r0, 8(%r1)
90 mtcr %r0
91 blr
92
93 #ifdef __ELF__
94 .section .note.GNU-stack,"",%progbits
95 #endif
96
View as plain text