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