| 1 |
// Copyright 2022 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_loong64.h" |
| 7 |
|
| 8 |
TEXT _rt0_loong64_linux(SB),NOSPLIT|NOFRAME,$0 |
| 9 |
// In a statically linked binary, the stack contains argc, |
| 10 |
// argv as argc string pointers followed by a NULL, envv as a |
| 11 |
// sequence of string pointers followed by a NULL, and auxv. |
| 12 |
// There is no TLS base pointer. |
| 13 |
MOVW 0(R3), R4 // argc |
| 14 |
ADDV $8, R3, R5 // argv |
| 15 |
JMP main(SB) |
| 16 |
|
| 17 |
// When building with -buildmode=c-shared, this symbol is called when the shared |
| 18 |
// library is loaded. |
| 19 |
TEXT _rt0_loong64_linux_lib(SB),NOSPLIT,$168 |
| 20 |
// Preserve callee-save registers. |
| 21 |
SAVE_R22_TO_R31(3*8) |
| 22 |
SAVE_F24_TO_F31(13*8) |
| 23 |
|
| 24 |
// Initialize g as nil in case of using g later e.g. sigaction in cgo_sigaction.go |
| 25 |
MOVV R0, g |
| 26 |
|
| 27 |
MOVV R4, _rt0_loong64_linux_lib_argc<>(SB) |
| 28 |
MOVV R5, _rt0_loong64_linux_lib_argv<>(SB) |
| 29 |
|
| 30 |
// Synchronous initialization. |
| 31 |
MOVV $runtime·libpreinit(SB), R19 |
| 32 |
JAL (R19) |
| 33 |
|
| 34 |
// Create a new thread to do the runtime initialization and return. |
| 35 |
MOVV _cgo_sys_thread_create(SB), R19 |
| 36 |
BEQ R19, nocgo |
| 37 |
MOVV $_rt0_loong64_linux_lib_go(SB), R4 |
| 38 |
MOVV $0, R5 |
| 39 |
JAL (R19) |
| 40 |
JMP restore |
| 41 |
|
| 42 |
nocgo: |
| 43 |
MOVV $0x800000, R4 // stacksize = 8192KB |
| 44 |
MOVV $_rt0_loong64_linux_lib_go(SB), R5 |
| 45 |
MOVV R4, 8(R3) |
| 46 |
MOVV R5, 16(R3) |
| 47 |
MOVV $runtime·newosproc0(SB), R19 |
| 48 |
JAL (R19) |
| 49 |
|
| 50 |
restore: |
| 51 |
// Restore callee-save registers. |
| 52 |
RESTORE_R22_TO_R31(3*8) |
| 53 |
RESTORE_F24_TO_F31(13*8) |
| 54 |
RET |
| 55 |
|
| 56 |
TEXT _rt0_loong64_linux_lib_go(SB),NOSPLIT,$0 |
| 57 |
MOVV _rt0_loong64_linux_lib_argc<>(SB), R4 |
| 58 |
MOVV _rt0_loong64_linux_lib_argv<>(SB), R5 |
| 59 |
MOVV $runtime·rt0_go(SB),R19 |
| 60 |
JMP (R19) |
| 61 |
|
| 62 |
DATA _rt0_loong64_linux_lib_argc<>(SB)/8, $0 |
| 63 |
GLOBL _rt0_loong64_linux_lib_argc<>(SB),NOPTR, $8 |
| 64 |
DATA _rt0_loong64_linux_lib_argv<>(SB)/8, $0 |
| 65 |
GLOBL _rt0_loong64_linux_lib_argv<>(SB),NOPTR, $8 |
| 66 |
|
| 67 |
TEXT main(SB),NOSPLIT|NOFRAME,$0 |
| 68 |
// in external linking, glibc jumps to main with argc in R4 |
| 69 |
// and argv in R5 |
| 70 |
|
| 71 |
MOVV $runtime·rt0_go(SB), R19 |
| 72 |
JMP (R19) |