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 #include "cgo/abi_arm64.h"
7
8 // See comment in runtime/sys_openbsd_arm64.s re this construction.
9 #define INVOKE_SYSCALL \
10 SVC; \
11 NOOP; \
12 NOOP
13
14 TEXT _rt0_arm64_openbsd(SB),NOSPLIT|NOFRAME,$0
15 MOVD 0(RSP), R0 // argc
16 ADD $8, RSP, R1 // argv
17 BL main(SB)
18
19 // When building with -buildmode=c-shared, this symbol is called when the shared
20 // library is loaded.
21 TEXT _rt0_arm64_openbsd_lib(SB),NOSPLIT,$184
22 // Preserve callee-save registers.
23 SAVE_R19_TO_R28(24)
24 SAVE_F8_TO_F15(104)
25
26 // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
27 MOVD ZR, g
28
29 MOVD R0, _rt0_arm64_openbsd_lib_argc<>(SB)
30 MOVD R1, _rt0_arm64_openbsd_lib_argv<>(SB)
31
32 // Synchronous initialization.
33 MOVD $runtime·libpreinit(SB), R4
34 BL (R4)
35
36 // Create a new thread to do the runtime initialization and return.
37 MOVD _cgo_sys_thread_create(SB), R4
38 CBZ R4, nocgo
39 MOVD $_rt0_arm64_openbsd_lib_go(SB), R0
40 MOVD $0, R1
41 SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved.
42 BL (R4)
43 ADD $16, RSP
44 B restore
45
46 nocgo:
47 MOVD $0x800000, R0 // stacksize = 8192KB
48 MOVD $_rt0_arm64_openbsd_lib_go(SB), R1
49 MOVD R0, 8(RSP)
50 MOVD R1, 16(RSP)
51 MOVD $runtime·newosproc0(SB),R4
52 BL (R4)
53
54 restore:
55 // Restore callee-save registers.
56 RESTORE_R19_TO_R28(24)
57 RESTORE_F8_TO_F15(104)
58 RET
59
60 TEXT _rt0_arm64_openbsd_lib_go(SB),NOSPLIT,$0
61 MOVD _rt0_arm64_openbsd_lib_argc<>(SB), R0
62 MOVD _rt0_arm64_openbsd_lib_argv<>(SB), R1
63 MOVD $runtime·rt0_go(SB),R4
64 B (R4)
65
66 DATA _rt0_arm64_openbsd_lib_argc<>(SB)/8, $0
67 GLOBL _rt0_arm64_openbsd_lib_argc<>(SB),NOPTR, $8
68 DATA _rt0_arm64_openbsd_lib_argv<>(SB)/8, $0
69 GLOBL _rt0_arm64_openbsd_lib_argv<>(SB),NOPTR, $8
70
71
72 TEXT main(SB),NOSPLIT|NOFRAME,$0
73 MOVD $runtime·rt0_go(SB), R2
74 BL (R2)
75 exit:
76 MOVD $0, R0
77 MOVD $1, R8 // sys_exit
78 INVOKE_SYSCALL
79 B exit
80
View as plain text