Text file
src/runtime/rt0_freebsd_arm64.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 #include "textflag.h"
6
7 // On FreeBSD argc/argv are passed in R0, not RSP
8 TEXT _rt0_arm64_freebsd(SB),NOSPLIT|NOFRAME,$0
9 ADD $8, R0, R1 // argv
10 MOVD 0(R0), R0 // argc
11 BL main(SB)
12
13 // When building with -buildmode=c-shared, this symbol is called when the shared
14 // library is loaded.
15 TEXT _rt0_arm64_freebsd_lib(SB),NOSPLIT,$184
16 // Preserve callee-save registers.
17 MOVD R19, 24(RSP)
18 MOVD R20, 32(RSP)
19 MOVD R21, 40(RSP)
20 MOVD R22, 48(RSP)
21 MOVD R23, 56(RSP)
22 MOVD R24, 64(RSP)
23 MOVD R25, 72(RSP)
24 MOVD R26, 80(RSP)
25 MOVD R27, 88(RSP)
26 FMOVD F8, 96(RSP)
27 FMOVD F9, 104(RSP)
28 FMOVD F10, 112(RSP)
29 FMOVD F11, 120(RSP)
30 FMOVD F12, 128(RSP)
31 FMOVD F13, 136(RSP)
32 FMOVD F14, 144(RSP)
33 FMOVD F15, 152(RSP)
34 MOVD g, 160(RSP)
35
36 // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
37 MOVD ZR, g
38
39 MOVD R0, _rt0_arm64_freebsd_lib_argc<>(SB)
40 MOVD R1, _rt0_arm64_freebsd_lib_argv<>(SB)
41
42 // Synchronous initialization.
43 MOVD $runtime·libpreinit(SB), R4
44 BL (R4)
45
46 // Create a new thread to do the runtime initialization and return.
47 MOVD _cgo_sys_thread_create(SB), R4
48 CBZ R4, nocgo
49 MOVD $_rt0_arm64_freebsd_lib_go(SB), R0
50 MOVD $0, R1
51 SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved.
52 BL (R4)
53 ADD $16, RSP
54 B restore
55
56 nocgo:
57 MOVD $0x800000, R0 // stacksize = 8192KB
58 MOVD $_rt0_arm64_freebsd_lib_go(SB), R1
59 MOVD R0, 8(RSP)
60 MOVD R1, 16(RSP)
61 MOVD $runtime·newosproc0(SB),R4
62 BL (R4)
63
64 restore:
65 // Restore callee-save registers.
66 MOVD 24(RSP), R19
67 MOVD 32(RSP), R20
68 MOVD 40(RSP), R21
69 MOVD 48(RSP), R22
70 MOVD 56(RSP), R23
71 MOVD 64(RSP), R24
72 MOVD 72(RSP), R25
73 MOVD 80(RSP), R26
74 MOVD 88(RSP), R27
75 FMOVD 96(RSP), F8
76 FMOVD 104(RSP), F9
77 FMOVD 112(RSP), F10
78 FMOVD 120(RSP), F11
79 FMOVD 128(RSP), F12
80 FMOVD 136(RSP), F13
81 FMOVD 144(RSP), F14
82 FMOVD 152(RSP), F15
83 MOVD 160(RSP), g
84 RET
85
86 TEXT _rt0_arm64_freebsd_lib_go(SB),NOSPLIT,$0
87 MOVD _rt0_arm64_freebsd_lib_argc<>(SB), R0
88 MOVD _rt0_arm64_freebsd_lib_argv<>(SB), R1
89 MOVD $runtime·rt0_go(SB),R4
90 B (R4)
91
92 DATA _rt0_arm64_freebsd_lib_argc<>(SB)/8, $0
93 GLOBL _rt0_arm64_freebsd_lib_argc<>(SB),NOPTR, $8
94 DATA _rt0_arm64_freebsd_lib_argv<>(SB)/8, $0
95 GLOBL _rt0_arm64_freebsd_lib_argv<>(SB),NOPTR, $8
96
97
98 TEXT main(SB),NOSPLIT|NOFRAME,$0
99 MOVD $runtime·rt0_go(SB), R2
100 BL (R2)
101 exit:
102 MOVD $0, R0
103 MOVD $1, R8 // SYS_exit
104 SVC
105 B exit
106
View as plain text