cpu: avoid illegal instruction on netbsd/arm64

On NetBSD, this package tries to read a privileged register,
which results in a SIGILL. Use the same workaround as Android and
iOS. In the future, we could use sysctl(3) instead.

Update golang/go#30824

Change-Id: Ifd9aa2a2cf4dac43341d013602d1ccb4b8d6eb6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/235097
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/cpu/cpu_arm64.go b/cpu/cpu_arm64.go
index 9c87677..7bcb36c 100644
--- a/cpu/cpu_arm64.go
+++ b/cpu/cpu_arm64.go
@@ -10,8 +10,14 @@
 func init() {
 	switch runtime.GOOS {
-	case "android", "darwin":
+	case "android", "darwin", "netbsd":
 		// Android and iOS don't seem to allow reading these registers.
+		//
+		// NetBSD:
+		// ID_AA64ISAR0_EL1 is a privileged register and cannot be read from EL0.
+		// It can be read via sysctl(3). Example for future implementers:
+		// https://nxr.netbsd.org/xref/src/usr.sbin/cpuctl/arch/aarch64.c
+		//
 		// Fake the minimal features expected by
 		// TestARM64minimalFeatures.
 		ARM64.HasASIMD = true