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 // +build ppc64 ppc64le
6 // +build linux
7
8 /*
9 * Apple still insists on underscore prefixes for C function names.
10 */
11 #if defined(__APPLE__)
12 #define EXT(s) _##s
13 #else
14 #define EXT(s) s
15 #endif
16
17 /*
18 * void crosscall_ppc64(void (*fn)(void), void *g)
19 *
20 * Calling into the gc tool chain, where all registers are caller save.
21 * Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
22 * callee-save, so they must be saved explicitly.
23 */
24 .globl EXT(crosscall_ppc64)
25 EXT(crosscall_ppc64):
26 // Start with standard C stack frame layout and linkage
27 mflr %r0
28 std %r0, 16(%r1) // Save LR in caller's frame
29 std %r2, 24(%r1) // Save TOC in caller's frame
30 bl saveregs
31 stdu %r1, -296(%r1)
32
33 // Set up Go ABI constant registers
34 bl _cgo_reginit
35 nop
36
37 // Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
38 mr %r30, %r4
39
40 // Call fn
41 mr %r12, %r3
42 mtctr %r3
43 bctrl
44
45 addi %r1, %r1, 296
46 bl restoreregs
47 ld %r2, 24(%r1)
48 ld %r0, 16(%r1)
49 mtlr %r0
50 blr
51
52 saveregs:
53 // Save callee-save registers
54 // O=-288; for R in %r{14..31}; do echo "\tstd\t$R, $O(%r1)"; ((O+=8)); done; for F in f{14..31}; do echo "\tstfd\t$F, $O(%r1)"; ((O+=8)); done
55 std %r14, -288(%r1)
56 std %r15, -280(%r1)
57 std %r16, -272(%r1)
58 std %r17, -264(%r1)
59 std %r18, -256(%r1)
60 std %r19, -248(%r1)
61 std %r20, -240(%r1)
62 std %r21, -232(%r1)
63 std %r22, -224(%r1)
64 std %r23, -216(%r1)
65 std %r24, -208(%r1)
66 std %r25, -200(%r1)
67 std %r26, -192(%r1)
68 std %r27, -184(%r1)
69 std %r28, -176(%r1)
70 std %r29, -168(%r1)
71 std %r30, -160(%r1)
72 std %r31, -152(%r1)
73 stfd %f14, -144(%r1)
74 stfd %f15, -136(%r1)
75 stfd %f16, -128(%r1)
76 stfd %f17, -120(%r1)
77 stfd %f18, -112(%r1)
78 stfd %f19, -104(%r1)
79 stfd %f20, -96(%r1)
80 stfd %f21, -88(%r1)
81 stfd %f22, -80(%r1)
82 stfd %f23, -72(%r1)
83 stfd %f24, -64(%r1)
84 stfd %f25, -56(%r1)
85 stfd %f26, -48(%r1)
86 stfd %f27, -40(%r1)
87 stfd %f28, -32(%r1)
88 stfd %f29, -24(%r1)
89 stfd %f30, -16(%r1)
90 stfd %f31, -8(%r1)
91
92 blr
93
94 restoreregs:
95 // O=-288; for R in %r{14..31}; do echo "\tld\t$R, $O(%r1)"; ((O+=8)); done; for F in %f{14..31}; do echo "\tlfd\t$F, $O(%r1)"; ((O+=8)); done
96 ld %r14, -288(%r1)
97 ld %r15, -280(%r1)
98 ld %r16, -272(%r1)
99 ld %r17, -264(%r1)
100 ld %r18, -256(%r1)
101 ld %r19, -248(%r1)
102 ld %r20, -240(%r1)
103 ld %r21, -232(%r1)
104 ld %r22, -224(%r1)
105 ld %r23, -216(%r1)
106 ld %r24, -208(%r1)
107 ld %r25, -200(%r1)
108 ld %r26, -192(%r1)
109 ld %r27, -184(%r1)
110 ld %r28, -176(%r1)
111 ld %r29, -168(%r1)
112 ld %r30, -160(%r1)
113 ld %r31, -152(%r1)
114 lfd %f14, -144(%r1)
115 lfd %f15, -136(%r1)
116 lfd %f16, -128(%r1)
117 lfd %f17, -120(%r1)
118 lfd %f18, -112(%r1)
119 lfd %f19, -104(%r1)
120 lfd %f20, -96(%r1)
121 lfd %f21, -88(%r1)
122 lfd %f22, -80(%r1)
123 lfd %f23, -72(%r1)
124 lfd %f24, -64(%r1)
125 lfd %f25, -56(%r1)
126 lfd %f26, -48(%r1)
127 lfd %f27, -40(%r1)
128 lfd %f28, -32(%r1)
129 lfd %f29, -24(%r1)
130 lfd %f30, -16(%r1)
131 lfd %f31, -8(%r1)
132
133 blr
134
135
136 #ifdef __ELF__
137 .section .note.GNU-stack,"",%progbits
138 #endif
139
View as plain text