Text file
src/runtime/cgo/gcc_aix_ppc64.S
1 // Copyright 2019 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 .file "gcc_aix_ppc64.S"
6
7 /*
8 * void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g)
9 *
10 * Calling into the gc tool chain, where all registers are caller save.
11 * Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
12 * callee-save, so they must be saved explicitly.
13 * AIX has a special assembly syntax and keywords that can be mixed with
14 * Linux assembly.
15 * ABI: r3=fn, r4=setg_gcc, r5=g
16 */
17 .toc
18 .csect .text[PR]
19 .globl crosscall1
20 .globl .crosscall1
21 .csect crosscall1[DS]
22 crosscall1:
23 .llong .crosscall1, TOC[tc0], 0
24 .csect .text[PR]
25 .crosscall1:
26 // Start with standard C stack frame layout and linkage
27 mflr 0
28 std 0, 16(1) // Save LR in caller's frame
29 std 2, 40(1) // Save TOC in caller's frame
30 bl saveregs
31 stdu 1, -296(1)
32
33 // Set up Go ABI constant registers
34 // Must match _cgo_reginit in runtime package.
35 xor 0, 0, 0
36
37 // Save fn in r14 (callee-save) so we can reuse r3 for setg_gcc call
38 mr 14, 3
39 // Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
40 mr 30, 5
41
42 // Call setg_gcc(g)
43 // Function pointers are function descriptors.
44 // Dereference setg_gcc to get the entry point and TOC.
45 mr 3, 5 // arg g
46 ld 12, 0(4) // load entry point from function descriptor
47 ld 2, 8(4) // load TOC from function descriptor
48 mtctr 12
49 bctrl
50
51 // Call fn
52 mr 12, 14
53 mtctr 12
54 bctrl
55
56 addi 1, 1, 296
57 bl restoreregs
58 ld 2, 40(1)
59 ld 0, 16(1)
60 mtlr 0
61 blr
62
63 saveregs:
64 // Save callee-save registers
65 // O=-288; for R in {14..31}; do echo "\tstd\t$R, $O(1)"; ((O+=8)); done; for F in f{14..31}; do echo "\tstfd\t$F, $O(1)"; ((O+=8)); done
66 std 14, -288(1)
67 std 15, -280(1)
68 std 16, -272(1)
69 std 17, -264(1)
70 std 18, -256(1)
71 std 19, -248(1)
72 std 20, -240(1)
73 std 21, -232(1)
74 std 22, -224(1)
75 std 23, -216(1)
76 std 24, -208(1)
77 std 25, -200(1)
78 std 26, -192(1)
79 std 27, -184(1)
80 std 28, -176(1)
81 std 29, -168(1)
82 std 30, -160(1)
83 std 31, -152(1)
84 stfd 14, -144(1)
85 stfd 15, -136(1)
86 stfd 16, -128(1)
87 stfd 17, -120(1)
88 stfd 18, -112(1)
89 stfd 19, -104(1)
90 stfd 20, -96(1)
91 stfd 21, -88(1)
92 stfd 22, -80(1)
93 stfd 23, -72(1)
94 stfd 24, -64(1)
95 stfd 25, -56(1)
96 stfd 26, -48(1)
97 stfd 27, -40(1)
98 stfd 28, -32(1)
99 stfd 29, -24(1)
100 stfd 30, -16(1)
101 stfd 31, -8(1)
102
103 blr
104
105 restoreregs:
106 // O=-288; for R in {14..31}; do echo "\tld\t$R, $O(1)"; ((O+=8)); done; for F in {14..31}; do echo "\tlfd\t$F, $O(1)"; ((O+=8)); done
107 ld 14, -288(1)
108 ld 15, -280(1)
109 ld 16, -272(1)
110 ld 17, -264(1)
111 ld 18, -256(1)
112 ld 19, -248(1)
113 ld 20, -240(1)
114 ld 21, -232(1)
115 ld 22, -224(1)
116 ld 23, -216(1)
117 ld 24, -208(1)
118 ld 25, -200(1)
119 ld 26, -192(1)
120 ld 27, -184(1)
121 ld 28, -176(1)
122 ld 29, -168(1)
123 ld 30, -160(1)
124 ld 31, -152(1)
125 lfd 14, -144(1)
126 lfd 15, -136(1)
127 lfd 16, -128(1)
128 lfd 17, -120(1)
129 lfd 18, -112(1)
130 lfd 19, -104(1)
131 lfd 20, -96(1)
132 lfd 21, -88(1)
133 lfd 22, -80(1)
134 lfd 23, -72(1)
135 lfd 24, -64(1)
136 lfd 25, -56(1)
137 lfd 26, -48(1)
138 lfd 27, -40(1)
139 lfd 28, -32(1)
140 lfd 29, -24(1)
141 lfd 30, -16(1)
142 lfd 31, -8(1)
143
144 blr
145
View as plain text