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