Text file
src/runtime/rt0_aix_ppc64.s
1 // Copyright 2018 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 // _rt0_ppc64_aix is a function descriptor of the entrypoint function
8 // __start. This name is needed by cmd/link.
9 DATA _rt0_ppc64_aix+0(SB)/8, $__start<>(SB)
10 DATA _rt0_ppc64_aix+8(SB)/8, $TOC(SB)
11 GLOBL _rt0_ppc64_aix(SB), NOPTR, $16
12
13
14 // The starting function must return in the loader to
15 // initialise some librairies, especially libthread which
16 // creates the main thread and adds the TLS in R13
17 // R19 contains a function descriptor to the loader function
18 // which needs to be called.
19 // This code is similar to the __start function in C
20 TEXT __start<>(SB),NOSPLIT,$-8
21 XOR R0, R0
22 MOVD $libc___n_pthreads(SB), R4
23 MOVD 0(R4), R4
24 MOVD $libc___mod_init(SB), R5
25 MOVD 0(R5), R5
26 MOVD 0(R19), R0
27 MOVD R2, 40(R1)
28 MOVD 8(R19), R2
29 MOVD R18, R3
30 MOVD R0, CTR
31 BL (CTR) // Return to AIX loader
32
33 // Launch rt0_go
34 MOVD 40(R1), R2
35 MOVD R14, R3 // argc
36 MOVD R15, R4 // argv
37 BL _main(SB)
38
39
40 DATA main+0(SB)/8, $_main(SB)
41 DATA main+8(SB)/8, $TOC(SB)
42 DATA main+16(SB)/8, $0
43 GLOBL main(SB), NOPTR, $24
44
45 TEXT _main(SB),NOSPLIT,$-8
46 MOVD $runtime·rt0_go(SB), R12
47 MOVD R12, CTR
48 BR (CTR)
49
50
51 TEXT _rt0_ppc64_aix_lib(SB),NOSPLIT,$-8
52 // Start with standard C stack frame layout and linkage.
53 MOVD LR, R0
54 MOVD R0, 16(R1) // Save LR in caller's frame.
55 MOVW CR, R0 // Save CR in caller's frame
56 MOVD R0, 8(R1)
57
58 MOVDU R1, -344(R1) // Allocate frame.
59
60 // Preserve callee-save registers.
61 MOVD R14, 48(R1)
62 MOVD R15, 56(R1)
63 MOVD R16, 64(R1)
64 MOVD R17, 72(R1)
65 MOVD R18, 80(R1)
66 MOVD R19, 88(R1)
67 MOVD R20, 96(R1)
68 MOVD R21,104(R1)
69 MOVD R22, 112(R1)
70 MOVD R23, 120(R1)
71 MOVD R24, 128(R1)
72 MOVD R25, 136(R1)
73 MOVD R26, 144(R1)
74 MOVD R27, 152(R1)
75 MOVD R28, 160(R1)
76 MOVD R29, 168(R1)
77 MOVD g, 176(R1) // R30
78 MOVD R31, 184(R1)
79 FMOVD F14, 192(R1)
80 FMOVD F15, 200(R1)
81 FMOVD F16, 208(R1)
82 FMOVD F17, 216(R1)
83 FMOVD F18, 224(R1)
84 FMOVD F19, 232(R1)
85 FMOVD F20, 240(R1)
86 FMOVD F21, 248(R1)
87 FMOVD F22, 256(R1)
88 FMOVD F23, 264(R1)
89 FMOVD F24, 272(R1)
90 FMOVD F25, 280(R1)
91 FMOVD F26, 288(R1)
92 FMOVD F27, 296(R1)
93 FMOVD F28, 304(R1)
94 FMOVD F29, 312(R1)
95 FMOVD F30, 320(R1)
96 FMOVD F31, 328(R1)
97
98 // Synchronous initialization.
99 MOVD $runtime·reginit(SB), R12
100 MOVD R12, CTR
101 BL (CTR)
102
103 MOVBZ runtime·isarchive(SB), R3 // Check buildmode = c-archive
104 CMP $0, R3
105 BEQ done
106
107 MOVD R14, _rt0_ppc64_aix_lib_argc<>(SB)
108 MOVD R15, _rt0_ppc64_aix_lib_argv<>(SB)
109
110 MOVD $runtime·libpreinit(SB), R12
111 MOVD R12, CTR
112 BL (CTR)
113
114 // Create a new thread to do the runtime initialization and return.
115 MOVD _cgo_sys_thread_create(SB), R12
116 CMP $0, R12
117 BEQ nocgo
118 MOVD $_rt0_ppc64_aix_lib_go(SB), R3
119 MOVD $0, R4
120 MOVD R2, 40(R1)
121 MOVD 8(R12), R2
122 MOVD (R12), R12
123 MOVD R12, CTR
124 BL (CTR)
125 MOVD 40(R1), R2
126 BR done
127
128 nocgo:
129 MOVD $0x800000, R12 // stacksize = 8192KB
130 MOVD R12, 8(R1)
131 MOVD $_rt0_ppc64_aix_lib_go(SB), R12
132 MOVD R12, 16(R1)
133 MOVD $runtime·newosproc0(SB),R12
134 MOVD R12, CTR
135 BL (CTR)
136
137 done:
138 // Restore saved registers.
139 MOVD 48(R1), R14
140 MOVD 56(R1), R15
141 MOVD 64(R1), R16
142 MOVD 72(R1), R17
143 MOVD 80(R1), R18
144 MOVD 88(R1), R19
145 MOVD 96(R1), R20
146 MOVD 104(R1), R21
147 MOVD 112(R1), R22
148 MOVD 120(R1), R23
149 MOVD 128(R1), R24
150 MOVD 136(R1), R25
151 MOVD 144(R1), R26
152 MOVD 152(R1), R27
153 MOVD 160(R1), R28
154 MOVD 168(R1), R29
155 MOVD 176(R1), g // R30
156 MOVD 184(R1), R31
157 FMOVD 196(R1), F14
158 FMOVD 200(R1), F15
159 FMOVD 208(R1), F16
160 FMOVD 216(R1), F17
161 FMOVD 224(R1), F18
162 FMOVD 232(R1), F19
163 FMOVD 240(R1), F20
164 FMOVD 248(R1), F21
165 FMOVD 256(R1), F22
166 FMOVD 264(R1), F23
167 FMOVD 272(R1), F24
168 FMOVD 280(R1), F25
169 FMOVD 288(R1), F26
170 FMOVD 296(R1), F27
171 FMOVD 304(R1), F28
172 FMOVD 312(R1), F29
173 FMOVD 320(R1), F30
174 FMOVD 328(R1), F31
175
176 ADD $344, R1
177
178 MOVD 8(R1), R0
179 MOVFL R0, $0xff
180 MOVD 16(R1), R0
181 MOVD R0, LR
182 RET
183
184 DATA _rt0_ppc64_aix_lib_go+0(SB)/8, $__rt0_ppc64_aix_lib_go(SB)
185 DATA _rt0_ppc64_aix_lib_go+8(SB)/8, $TOC(SB)
186 DATA _rt0_ppc64_aix_lib_go+16(SB)/8, $0
187 GLOBL _rt0_ppc64_aix_lib_go(SB), NOPTR, $24
188
189 TEXT __rt0_ppc64_aix_lib_go(SB),NOSPLIT,$0
190 MOVD _rt0_ppc64_aix_lib_argc<>(SB), R3
191 MOVD _rt0_ppc64_aix_lib_argv<>(SB), R4
192 MOVD $runtime·rt0_go(SB), R12
193 MOVD R12, CTR
194 BR (CTR)
195
196 DATA _rt0_ppc64_aix_lib_argc<>(SB)/8, $0
197 GLOBL _rt0_ppc64_aix_lib_argc<>(SB),NOPTR, $8
198 DATA _rt0_ppc64_aix_lib_argv<>(SB)/8, $0
199 GLOBL _rt0_ppc64_aix_lib_argv<>(SB),NOPTR, $8
200
View as plain text