Skip to content

Commit 4e70258

Browse files
andreybokhankocherrymui
authored andcommitted
runtime: Check LSE support on ARM64 at runtime init
Check presence of LSE support on ARM64 chip if we targeted it at compile time. Related to #69124 Update #60905 Change-Id: I6fe244decbb4982548982e1f88376847721a33c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/610195 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Shu-Chun Weng <[email protected]>
1 parent 38f8596 commit 4e70258

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/runtime/asm_arm64.s

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#include "funcdata.h"
99
#include "textflag.h"
1010

11+
#ifdef GOARM64_LSE
12+
DATA no_lse_msg<>+0x00(SB)/64, $"This program can only run on ARM64 processors with LSE support.\n"
13+
GLOBL no_lse_msg<>(SB), RODATA, $64
14+
#endif
15+
1116
TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
1217
// SP = stack; R0 = argc; R1 = argv
1318

@@ -77,6 +82,21 @@ nocgo:
7782
BL runtime·wintls(SB)
7883
#endif
7984

85+
// Check that CPU we use for execution supports instructions targeted during compile-time.
86+
#ifdef GOARM64_LSE
87+
#ifndef GOOS_openbsd
88+
// Read the ID_AA64ISAR0_EL1 register
89+
MRS ID_AA64ISAR0_EL1, R0
90+
91+
// Extract the LSE field (bits [23:20])
92+
LSR $20, R0, R0
93+
AND $0xf, R0, R0
94+
95+
// LSE support is indicated by a non-zero value
96+
CBZ R0, no_lse
97+
#endif
98+
#endif
99+
80100
MOVW 8(RSP), R0 // copy argc
81101
MOVW R0, -8(RSP)
82102
MOVD 16(RSP), R0 // copy argv
@@ -95,6 +115,23 @@ nocgo:
95115

96116
// start this M
97117
BL runtime·mstart(SB)
118+
RET
119+
120+
#ifdef GOARM64_LSE
121+
#ifndef GOOS_openbsd
122+
no_lse:
123+
MOVD $1, R0 // stderr
124+
MOVD R0, 8(RSP)
125+
MOVD $no_lse_msg<>(SB), R1 // message address
126+
MOVD R1, 16(RSP)
127+
MOVD $64, R2 // message length
128+
MOVD R2, 24(RSP)
129+
CALL runtime·write(SB)
130+
CALL runtime·exit(SB)
131+
CALL runtime·abort(SB)
132+
RET
133+
#endif
134+
#endif
98135

99136
// Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
100137
// intended to be called by debuggers.

0 commit comments

Comments
 (0)