Skip to content

Commit 5ab6585

Browse files
committed
cpu: add HPDS, LOR, PAN detection for arm64
This CL gets ID_AA64MMFR1_EL1, Memory Model Feature Register 1, and grabs HPDS, LOR, PAN features from its bits. Fixes golang/go#75472.
1 parent b06ce05 commit 5ab6585

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

cpu/cpu.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ var ARM64 struct {
9292
HasSHA2 bool // SHA2 hardware implementation
9393
HasCRC32 bool // CRC32 hardware implementation
9494
HasATOMICS bool // Atomic memory operation instruction set
95+
HasHPDS bool // Hierarchical permission disables in translations tables
96+
HasLOR bool // Limited ordering regions
97+
HasPAN bool // Privileged access never
9598
HasFPHP bool // Half precision floating-point instruction set
9699
HasASIMDHP bool // Advanced SIMD half precision instruction set
97100
HasCPUID bool // CPUID identification scheme registers

cpu/cpu_arm64.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ func setMinimalFeatures() {
6565
func readARM64Registers() {
6666
Initialized = true
6767

68-
parseARM64SystemRegisters(getisar0(), getisar1(), getpfr0())
68+
parseARM64SystemRegisters(getisar0(), getisar1(), getmmfr1(), getpfr0())
6969
}
7070

71-
func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) {
71+
func parseARM64SystemRegisters(isar0, isar1, mmfr1, pfr0 uint64) {
7272
// ID_AA64ISAR0_EL1
7373
switch extractBits(isar0, 4, 7) {
7474
case 1:
@@ -152,6 +152,22 @@ func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) {
152152
ARM64.HasI8MM = true
153153
}
154154

155+
// ID_AA64MMFR1_EL1
156+
switch extractBits(mmfr1, 12, 15) {
157+
case 1:
158+
ARM64.HasHPDS = true
159+
}
160+
161+
switch extractBits(mmfr1, 16, 19) {
162+
case 1:
163+
ARM64.HasLOR = true
164+
}
165+
166+
switch extractBits(mmfr1, 20, 23) {
167+
case 1:
168+
ARM64.HasPAN = true
169+
}
170+
155171
// ID_AA64PFR0_EL1
156172
switch extractBits(pfr0, 16, 19) {
157173
case 0:

cpu/cpu_arm64.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ TEXT ·getpfr0(SB),NOSPLIT,$0-8
3030
MOVD R0, ret+0(FP)
3131
RET
3232

33+
// func getmmfr1() uint64
34+
TEXT ·getmmfr1(SB),NOSPLIT,$0-8
35+
// get SVE Feature Register 0 into x0
36+
// mrs x0, ID_AA64MMFR1_EL1 = d5380720
37+
WORD $0xd5380720
38+
MOVD R0, ret+0(FP)
39+
RET
40+
3341
// func getzfr0() uint64
3442
TEXT ·getzfr0(SB),NOSPLIT,$0-8
3543
// get SVE Feature Register 0 into x0

cpu/cpu_gc_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ package cpu
99
func getisar0() uint64
1010
func getisar1() uint64
1111
func getpfr0() uint64
12+
func getmmfr1() uint64
1213
func getzfr0() uint64

cpu/cpu_gccgo_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ package cpu
88

99
func getisar0() uint64 { return 0 }
1010
func getisar1() uint64 { return 0 }
11+
func getmmfr1() uint64 { return 0 }
1112
func getpfr0() uint64 { return 0 }

0 commit comments

Comments
 (0)