Liviu Dudau a0de077600 std.zig.system.linux: Use arm.zig detection for AArch64 CPU features
When building zig natively from source on an RK3588 SoC board, the
generated stage3 compiler will use unsupported 'sha256h.4s' instructions
due to mis-identified CPU features. This happens when trying to
compile a new project generated with "zig init"

$ ~/devel/zig/build/stage3/bin/zig build
thread 919 panic: Illegal instruction at address 0x1fdc0c4
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:223:29: 0x1fdc0c4 in round (zig)
                            asm volatile (
                            ^
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:168:20: 0x1fdca87 in final (zig)
            d.round(&d.buf);
                   ^
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:180:20: 0x1c8bb33 in finalResult (zig)
            d.final(&result);
                   ^
/mnt/home/dliviu/devel/zig/src/Package/Fetch.zig:754:49: 0x1a3a8eb in relativePathDigest (zig)
    return Manifest.hexDigest(hasher.finalResult());
                                                ^
/mnt/home/dliviu/devel/zig/src/main.zig:5128:53: 0x1a37413 in cmdBuild (zig)
                    Package.Fetch.relativePathDigest(build_mod.root, global_cache_directory),
                                                    ^
???:?:?: 0xff09ffffffffffff in ??? (???)
Unwind information for `???:0xff09ffffffffffff` was not available, trace may be incomplete

???:?:?: 0x3f7f137 in ??? (???)
Aborted (core dumped)

system/linux.zig parses "/proc/cpuinfo" to determine the CPU features, but it
seems to generate the wrong set of features from:

$ cat /proc/cpuinfo
processor	: 0
BogoMIPS	: 48.00
Features	: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x2
CPU part	: 0xd05
CPU revision	: 0
.....
processor	: 4
BogoMIPS	: 48.00
Features	: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x4
CPU part	: 0xd0b
CPU revision	: 0
.....

To fix this, use the Linux kernel way of reading the feature registers as documented
here: https://www.kernel.org/doc/html/latest/arch/arm64/cpu-feature-registers.html

arm.zig already has the code to parse the feature register values, we just need to
collect them in an array and pass them for identification.

Signed-off-by: Liviu Dudau <liviu@dudau.co.uk>
2024-04-17 15:06:48 -07:00
..
2024-04-08 13:20:14 -04:00
2024-03-19 11:45:09 -07:00
2024-03-29 22:15:17 -07:00
2024-03-20 21:05:35 -07:00
2024-03-21 14:11:46 -07:00
2024-02-23 02:37:11 -07:00
2024-03-31 23:57:16 +02:00
2024-04-13 01:35:20 -04:00
2024-03-19 11:45:09 -07:00
2024-04-14 15:33:46 -04:00
2024-03-21 14:11:46 -07:00
2024-03-21 14:11:46 -07:00
2024-03-15 02:28:50 -04:00
2024-03-10 18:13:30 -07:00
2024-03-21 14:11:46 -07:00
2024-03-19 11:45:09 -07:00
2024-03-23 18:11:32 +01:00
2024-03-10 18:13:30 -07:00
2024-04-11 23:33:38 -07:00
2024-03-19 11:45:09 -07:00
2024-03-10 18:13:30 -07:00
2024-03-21 14:11:46 -07:00
2024-03-19 16:18:18 -07:00
2024-02-05 11:55:14 +03:30
2024-03-19 11:45:09 -07:00
2024-04-10 02:11:54 -07:00
2023-10-25 04:28:30 -04:00
2024-02-09 14:02:57 -08:00
2024-03-29 09:33:57 +00:00
2024-04-17 13:41:25 +01:00
2024-04-15 15:24:30 -07:00
2024-03-19 16:18:18 -07:00
2024-03-19 11:45:09 -07:00
2024-03-23 18:11:32 +01:00
2024-02-08 15:39:28 +01:00
2024-03-10 18:13:30 -07:00
2024-03-21 14:11:46 -07:00
2024-03-30 20:50:48 -04:00
2024-03-19 11:45:09 -07:00
2024-03-21 14:11:46 -07:00
2024-03-21 14:11:46 -07:00
2023-10-21 21:24:55 +00:00