authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-07 02:20:57+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-07 16:47:57+02:00
log7fdd5704edfe960ec3fafc82e5a724b8882207eb
treec2ab3676f61e4ab9c4e313e1d5a81cd719088030
parentde3b22db4db5e95d3a4a30333784e8d6c2cc3818
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug.cpu_context: map a bunch of known registers as unsupported instead of invalid


1 files changed, 81 insertions(+), 8 deletions(-)

lib/std/debug/cpu_context.zig+81-8
......@@ -341,7 +341,7 @@ pub const X86 = struct {
341341 // x86-macos is a deprecated target which is not supported by the Zig Standard Library.
342342 0...8 => return @ptrCast(&ctx.gprs.values[register_num]),
343343
344 9 => return error.UnsupportedRegister, // rflags
344 9 => return error.UnsupportedRegister, // eflags
345345 11...18 => return error.UnsupportedRegister, // st0 - st7
346346 21...28 => return error.UnsupportedRegister, // xmm0 - xmm7
347347 29...36 => return error.UnsupportedRegister, // mm0 - mm7
......@@ -349,7 +349,7 @@ pub const X86 = struct {
349349 40...45 => return error.UnsupportedRegister, // es, cs, ss, ds, fs, gs
350350 48 => return error.UnsupportedRegister, // tr
351351 49 => return error.UnsupportedRegister, // ldtr
352 93...94 => return error.UnsupportedRegister, // fs.base, gs.base
352 93...100 => return error.UnsupportedRegister, // k0 - k7 (AVX-512)
353353
354354 else => return error.InvalidRegister,
355355 }
......@@ -417,6 +417,9 @@ pub const X86_64 = struct {
417417 64 => return error.UnsupportedRegister, // mxcsr
418418 65 => return error.UnsupportedRegister, // fcw
419419 66 => return error.UnsupportedRegister, // fsw
420 67...82 => return error.UnsupportedRegister, // xmm16 - xmm31 (AVX-512)
421 118...125 => return error.UnsupportedRegister, // k0 - k7 (AVX-512)
422 130...145 => return error.UnsupportedRegister, // r16 - r31 (APX)
420423
421424 else => return error.InvalidRegister,
422425 }
......@@ -520,13 +523,13 @@ pub const Aarch64 = extern struct {
520523 31 => return @ptrCast(&ctx.sp),
521524 32 => return @ptrCast(&ctx.pc),
522525
523 33 => return error.UnsupportedRegister, // ELF_mode
526 33 => return error.UnsupportedRegister, // ELR_mode
524527 34 => return error.UnsupportedRegister, // RA_SIGN_STATE
525528 35 => return error.UnsupportedRegister, // TPIDRRO_ELO
526 36 => return error.UnsupportedRegister, // RPIDR_ELO
527 37 => return error.UnsupportedRegister, // RPIDR_EL1
528 38 => return error.UnsupportedRegister, // RPIDR_EL2
529 39 => return error.UnsupportedRegister, // RPIDR_EL3
529 36 => return error.UnsupportedRegister, // TPIDR_ELO
530 37 => return error.UnsupportedRegister, // TPIDR_EL1
531 38 => return error.UnsupportedRegister, // TPIDR_EL2
532 39 => return error.UnsupportedRegister, // TPIDR_EL3
530533 46 => return error.UnsupportedRegister, // VG
531534 47 => return error.UnsupportedRegister, // FFR
532535 48...63 => return error.UnsupportedRegister, // P0 - P15
......@@ -701,6 +704,8 @@ pub const LoongArch = extern struct {
701704 0...31 => return @ptrCast(&ctx.r[register_num]),
702705 64 => return @ptrCast(&ctx.pc),
703706
707 32...63 => return error.UnsupportedRegister, // f0 - f31
708
704709 else => return error.InvalidRegister,
705710 }
706711 }
......@@ -811,6 +816,18 @@ pub const Mips = extern struct {
811816 0...31 => return @ptrCast(&ctx.r[register_num]),
812817 66 => return @ptrCast(&ctx.pc),
813818
819 // Who the hell knows what numbers exist for this architecture? What's an ABI
820 // specification anyway? We don't need that nonsense.
821 32...63 => return error.UnsupportedRegister, // f0 - f31, w0 - w31
822 64 => return error.UnsupportedRegister, // hi0 (ac0)
823 65 => return error.UnsupportedRegister, // lo0 (ac0)
824 176 => return error.UnsupportedRegister, // hi1 (ac1)
825 177 => return error.UnsupportedRegister, // lo1 (ac1)
826 178 => return error.UnsupportedRegister, // hi2 (ac2)
827 179 => return error.UnsupportedRegister, // lo2 (ac2)
828 180 => return error.UnsupportedRegister, // hi3 (ac3)
829 181 => return error.UnsupportedRegister, // lo3 (ac3)
830
814831 else => return error.InvalidRegister,
815832 }
816833 }
......@@ -914,11 +931,59 @@ pub const Powerpc = extern struct {
914931 }
915932
916933 pub fn dwarfRegisterBytes(ctx: *Powerpc, register_num: u16) DwarfRegisterError![]u8 {
934 // References:
935 //
936 // * System V Application Binary Interface - PowerPC Processor Supplement §3-46
937 // * Power Architecture 32-bit Application Binary Interface Supplement 1.0 - Linux & Embedded §3.4
938 // * 64-bit ELF V2 ABI Specification - Power Architecture Revision 1.5 §2.4
939 // * ??? AIX?
940 //
941 // Are we having fun yet?
942
943 if (Gpr == u64) switch (register_num) {
944 65 => return @ptrCast(&ctx.lr), // lr
945
946 66 => return error.UnsupportedRegister, // ctr
947 68...75 => return error.UnsupportedRegister, // cr0 - cr7
948 76 => return error.UnsupportedRegister, // xer
949 77...108 => return error.UnsupportedRegister, // vr0 - vr31
950 109 => return error.UnsupportedRegister, // vrsave (LLVM)
951 110 => return error.UnsupportedRegister, // vscr
952 114 => return error.UnsupportedRegister, // tfhar
953 115 => return error.UnsupportedRegister, // tfiar
954 116 => return error.UnsupportedRegister, // texasr
955
956 else => {},
957 } else switch (register_num) {
958 65 => return @ptrCast(&ctx.lr), // fpscr (SVR4 / EABI), or lr if you ask LLVM
959 108 => return @ptrCast(&ctx.lr),
960
961 64 => return error.UnsupportedRegister, // cr
962 66 => return error.UnsupportedRegister, // msr (SVR4 / EABI), or ctr if you ask LLVM
963 68...75 => return error.UnsupportedRegister, // cr0 - cr7 if you ask LLVM
964 76 => return error.UnsupportedRegister, // xer if you ask LLVM
965 99 => return error.UnsupportedRegister, // acc
966 100 => return error.UnsupportedRegister, // mq
967 101 => return error.UnsupportedRegister, // xer
968 102...107 => return error.UnsupportedRegister, // SPRs
969 109 => return error.UnsupportedRegister, // ctr
970 110...111 => return error.UnsupportedRegister, // SPRs
971 112 => return error.UnsupportedRegister, // spefscr
972 113...1123 => return error.UnsupportedRegister, // SPRs
973 1124...1155 => return error.UnsupportedRegister, // SPE v0 - v31
974 1200...1231 => return error.UnsupportedRegister, // SPE upper r0 - r31
975 3072...4095 => return error.UnsupportedRegister, // DCRs
976 4096...5120 => return error.UnsupportedRegister, // PMRs
977
978 else => {},
979 }
980
917981 switch (register_num) {
918982 0...31 => return @ptrCast(&ctx.r[register_num]),
919 65 => return @ptrCast(&ctx.lr),
920983 67 => return @ptrCast(&ctx.pc),
921984
985 32...63 => return error.UnsupportedRegister, // f0 - f31
986
922987 else => return error.InvalidRegister,
923988 }
924989 }
......@@ -1019,6 +1084,12 @@ pub const Riscv = extern struct {
10191084 0...31 => return @ptrCast(&ctx.r[register_num]),
10201085 65 => return @ptrCast(&ctx.pc),
10211086
1087 32...63 => return error.UnsupportedRegister, // f0 - f31
1088 64 => return error.UnsupportedRegister, // Alternate Frame Return Column
1089 96...127 => return error.UnsupportedRegister, // v0 - v31
1090 3072...4095 => return error.UnsupportedRegister, // Custom extensions
1091 4096...8191 => return error.UnsupportedRegister, // CSRs
1092
10221093 else => return error.InvalidRegister,
10231094 }
10241095 }
......@@ -1057,7 +1128,9 @@ pub const S390x = extern struct {
10571128 65 => return @ptrCast(&ctx.psw.addr),
10581129
10591130 16...31 => return error.UnsupportedRegister, // f0 - f15
1131 32...47 => return error.UnsupportedRegister, // cr0 - cr15
10601132 48...63 => return error.UnsupportedRegister, // a0 - a15
1133 66...67 => return error.UnsupportedRegister, // z/OS stuff???
10611134 68...83 => return error.UnsupportedRegister, // v16 - v31
10621135
10631136 else => return error.InvalidRegister,