|
7 | 7 | #include "tls_arm64.h"
|
8 | 8 | #include "funcdata.h"
|
9 | 9 | #include "textflag.h"
|
| 10 | +#include "cgo/abi_arm64.h" |
| 11 | + |
| 12 | +// _rt0_arm64 is common startup code for most arm64 systems when using |
| 13 | +// internal linking. This is the entry point for the program from the |
| 14 | +// kernel for an ordinary -buildmode=exe program. The stack holds the |
| 15 | +// number of arguments and the C-style argv. |
| 16 | +TEXT _rt0_arm64(SB),NOSPLIT,$0 |
| 17 | + MOVD 0(RSP), R0 // argc |
| 18 | + ADD $8, RSP, R1 // argv |
| 19 | + JMP runtime·rt0_go(SB) |
| 20 | + |
| 21 | +// main is common startup code for most amd64 systems when using |
| 22 | +// external linking. The C startup code will call the symbol "main" |
| 23 | +// passing argc and argv in the usual C ABI registers R0 and R1. |
| 24 | +TEXT main(SB),NOSPLIT,$0 |
| 25 | + JMP runtime·rt0_go(SB) |
| 26 | + |
| 27 | +// _rt0_arm64_lib is common startup code for most arm64 systems when |
| 28 | +// using -buildmode=c-archive or -buildmode=c-shared. The linker will |
| 29 | +// arrange to invoke this function as a global constructor (for |
| 30 | +// c-archive) or when the shared library is loaded (for c-shared). |
| 31 | +// We expect argc and argv to be passed in the usual C ABI registers |
| 32 | +// R0 and R1. |
| 33 | +TEXT _rt0_arm64_lib(SB),NOSPLIT,$184 |
| 34 | + // Preserve callee-save registers. |
| 35 | + SAVE_R19_TO_R28(24) |
| 36 | + SAVE_F8_TO_F15(104) |
| 37 | + |
| 38 | + // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go |
| 39 | + MOVD ZR, g |
| 40 | + |
| 41 | + MOVD R0, _rt0_arm64_lib_argc<>(SB) |
| 42 | + MOVD R1, _rt0_arm64_lib_argv<>(SB) |
| 43 | + |
| 44 | + // Synchronous initialization. |
| 45 | + MOVD $runtime·libpreinit(SB), R4 |
| 46 | + BL (R4) |
| 47 | + |
| 48 | + // Create a new thread to do the runtime initialization and return. |
| 49 | + MOVD _cgo_sys_thread_create(SB), R4 |
| 50 | + CBZ R4, nocgo |
| 51 | + MOVD $_rt0_arm64_lib_go(SB), R0 |
| 52 | + MOVD $0, R1 |
| 53 | + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. |
| 54 | + BL (R4) |
| 55 | + ADD $16, RSP |
| 56 | + B restore |
| 57 | + |
| 58 | +nocgo: |
| 59 | + MOVD $0x800000, R0 // stacksize = 8192KB |
| 60 | + MOVD $_rt0_arm64_lib_go(SB), R1 |
| 61 | + MOVD R0, 8(RSP) |
| 62 | + MOVD R1, 16(RSP) |
| 63 | + MOVD $runtime·newosproc0(SB),R4 |
| 64 | + BL (R4) |
| 65 | + |
| 66 | +restore: |
| 67 | + // Restore callee-save registers. |
| 68 | + RESTORE_R19_TO_R28(24) |
| 69 | + RESTORE_F8_TO_F15(104) |
| 70 | + RET |
| 71 | + |
| 72 | +TEXT _rt0_arm64_lib_go(SB),NOSPLIT,$0 |
| 73 | + MOVD _rt0_arm64_lib_argc<>(SB), R0 |
| 74 | + MOVD _rt0_arm64_lib_argv<>(SB), R1 |
| 75 | + MOVD $runtime·rt0_go(SB),R4 |
| 76 | + B (R4) |
| 77 | + |
| 78 | +DATA _rt0_arm64_lib_argc<>(SB)/8, $0 |
| 79 | +GLOBL _rt0_arm64_lib_argc<>(SB),NOPTR, $8 |
| 80 | +DATA _rt0_arm64_lib_argv<>(SB)/8, $0 |
| 81 | +GLOBL _rt0_arm64_lib_argv<>(SB),NOPTR, $8 |
10 | 82 |
|
11 | 83 | #ifdef GOARM64_LSE
|
12 | 84 | DATA no_lse_msg<>+0x00(SB)/64, $"This program can only run on ARM64 processors with LSE support.\n"
|
|
0 commit comments