Skip to content

Commit eb1c7f6

Browse files
committed
runtime: move loong64 library entry point to os-agnostic file
The library entry point for loong64 is agnostic to the OS, so move it to asm_loong64.s. This is similar to what we do for other architectures. Cq-Include-Trybots: luci.golang.try:gotip-linux-loong64 Change-Id: I6915eb76d3ea72a779e05e78d85f24793169c61f Reviewed-on: https://go-review.googlesource.com/c/go/+/706416 Reviewed-by: abner chenc <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c925715 commit eb1c7f6

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

src/runtime/asm_loong64.s

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,57 @@
66
#include "go_tls.h"
77
#include "funcdata.h"
88
#include "textflag.h"
9+
#include "cgo/abi_loong64.h"
10+
11+
// When building with -buildmode=c-shared, this symbol is called when the shared
12+
// library is loaded.
13+
TEXT _rt0_loong64_lib(SB),NOSPLIT,$168
14+
// Preserve callee-save registers.
15+
SAVE_R22_TO_R31(3*8)
16+
SAVE_F24_TO_F31(13*8)
17+
18+
// Initialize g as nil in case of using g later e.g. sigaction in cgo_sigaction.go
19+
MOVV R0, g
20+
21+
MOVV R4, _rt0_loong64_lib_argc<>(SB)
22+
MOVV R5, _rt0_loong64_lib_argv<>(SB)
23+
24+
// Synchronous initialization.
25+
MOVV $runtime·libpreinit(SB), R19
26+
JAL (R19)
27+
28+
// Create a new thread to do the runtime initialization and return.
29+
MOVV _cgo_sys_thread_create(SB), R19
30+
BEQ R19, nocgo
31+
MOVV $_rt0_loong64_lib_go(SB), R4
32+
MOVV $0, R5
33+
JAL (R19)
34+
JMP restore
35+
36+
nocgo:
37+
MOVV $0x800000, R4 // stacksize = 8192KB
38+
MOVV $_rt0_loong64_lib_go(SB), R5
39+
MOVV R4, 8(R3)
40+
MOVV R5, 16(R3)
41+
MOVV $runtime·newosproc0(SB), R19
42+
JAL (R19)
43+
44+
restore:
45+
// Restore callee-save registers.
46+
RESTORE_R22_TO_R31(3*8)
47+
RESTORE_F24_TO_F31(13*8)
48+
RET
49+
50+
TEXT _rt0_loong64_lib_go(SB),NOSPLIT,$0
51+
MOVV _rt0_loong64_lib_argc<>(SB), R4
52+
MOVV _rt0_loong64_lib_argv<>(SB), R5
53+
MOVV $runtime·rt0_go(SB),R19
54+
JMP (R19)
55+
56+
DATA _rt0_loong64_lib_argc<>(SB)/8, $0
57+
GLOBL _rt0_loong64_lib_argc<>(SB),NOPTR, $8
58+
DATA _rt0_loong64_lib_argv<>(SB)/8, $0
59+
GLOBL _rt0_loong64_lib_argv<>(SB),NOPTR, $8
960

1061
#define REGCTXT R29
1162

src/runtime/rt0_linux_loong64.s

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
#include "textflag.h"
6-
#include "cgo/abi_loong64.h"
76

87
TEXT _rt0_loong64_linux(SB),NOSPLIT|NOFRAME,$0
98
// In a statically linked binary, the stack contains argc,
@@ -16,53 +15,8 @@ TEXT _rt0_loong64_linux(SB),NOSPLIT|NOFRAME,$0
1615

1716
// When building with -buildmode=c-shared, this symbol is called when the shared
1817
// 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
18+
TEXT _rt0_loong64_linux_lib(SB),NOSPLIT,$0
19+
JMP _rt0_loong64_lib(SB)
6620

6721
TEXT main(SB),NOSPLIT|NOFRAME,$0
6822
// in external linking, glibc jumps to main with argc in R4

0 commit comments

Comments
 (0)