Text file
src/runtime/rt0_linux_ppc64x.s
1 // Copyright 2016 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 (ppc64 || ppc64le) && linux
6
7 #include "go_asm.h"
8 #include "textflag.h"
9 #include "asm_ppc64x.h"
10
11 #ifdef GOARCH_ppc64
12 #define ENTRYPOINT _rt0_ppc64_linux
13 #define ENTRYPOINT_LIB _rt0_ppc64_linux_lib
14 #else
15 #define ENTRYPOINT _rt0_ppc64le_linux
16 #define ENTRYPOINT_LIB _rt0_ppc64le_linux_lib
17 #endif
18
19 TEXT ENTRYPOINT(SB),NOSPLIT,$0
20 XOR R0, R0 // Make sure R0 is zero before _main
21 BR _main<>(SB)
22
23 TEXT ENTRYPOINT_LIB(SB),NOSPLIT|NOFRAME,$0
24 JMP _rt0_ppc64x_lib(SB)
25
26 TEXT _main<>(SB),NOSPLIT,$-8
27 // In a statically linked binary, the stack contains argc,
28 // argv as argc string pointers followed by a NULL, envv as a
29 // sequence of string pointers followed by a NULL, and auxv.
30 // The TLS pointer should be initialized to 0.
31 //
32 // In an ELFv2 compliant dynamically linked binary, R3 contains argc,
33 // R4 contains argv, R5 contains envp, R6 contains auxv, and R13
34 // contains the TLS pointer.
35 //
36 // When loading via glibc, the first doubleword on the stack points
37 // to NULL a value. (that is *(uintptr)(R1) == 0). This is used to
38 // differentiate static vs dynamically linked binaries.
39 //
40 // If loading with the musl loader, it doesn't follow the ELFv2 ABI. It
41 // passes argc/argv similar to the linux kernel, R13 (TLS) is
42 // initialized, and R3/R4 are undefined.
43 MOVD (R1), R12
44 CMP R12, $0
45 BEQ tls_and_argcv_in_reg
46
47 // Arguments are passed via the stack (musl loader or a static binary)
48 MOVD 0(R1), R3 // argc
49 ADD $8, R1, R4 // argv
50
51 // Did the TLS pointer get set? If so, don't change it (e.g musl).
52 CMP R13, $0
53 BNE tls_and_argcv_in_reg
54
55 MOVD $runtimeĀ·m0+m_tls(SB), R13 // TLS
56 ADD $0x7000, R13
57
58 tls_and_argcv_in_reg:
59 BR main(SB)
60
61 TEXT main(SB),NOSPLIT,$-8
62 MOVD $runtimeĀ·rt0_go(SB), R12
63 MOVD R12, CTR
64 BR (CTR)
65
View as plain text