authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-16 17:09:30+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-18 00:36:52+02:00
logba9ab3fb6720ff5894ac07741eccaaca44122eb0
treeb2dd557ed57b265647849588f32e22bc1167623d
parenteb36a45ed9fbdf5ab92c3cdb650375a13eaaa648
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: add CPU context and DWARF mappings for m68k


3 files changed, 49 insertions(+), 3 deletions(-)

lib/std/debug/Dwarf.zig+3
......@@ -1435,6 +1435,7 @@ pub fn ipRegNum(arch: std.Target.Cpu.Arch) ?u16 {
14351435 .hexagon => 76,
14361436 .lanai => 2,
14371437 .loongarch32, .loongarch64 => 64,
1438 .m68k => 26,
14381439 .mips, .mipsel, .mips64, .mips64el => 66,
14391440 .or1k => 35,
14401441 .powerpc, .powerpcle, .powerpc64, .powerpc64le => 67,
......@@ -1456,6 +1457,7 @@ pub fn fpRegNum(arch: std.Target.Cpu.Arch) u16 {
14561457 .hexagon => 30,
14571458 .lanai => 5,
14581459 .loongarch32, .loongarch64 => 22,
1460 .m68k => 14,
14591461 .mips, .mipsel, .mips64, .mips64el => 30,
14601462 .or1k => 2,
14611463 .powerpc, .powerpcle, .powerpc64, .powerpc64le => 1,
......@@ -1477,6 +1479,7 @@ pub fn spRegNum(arch: std.Target.Cpu.Arch) u16 {
14771479 .hexagon => 29,
14781480 .lanai => 4,
14791481 .loongarch32, .loongarch64 => 3,
1482 .m68k => 15,
14801483 .mips, .mipsel, .mips64, .mips64el => 29,
14811484 .or1k => 1,
14821485 .powerpc, .powerpcle, .powerpc64, .powerpc64le => 1,
lib/std/debug/SelfInfo/Elf.zig+6-3
......@@ -94,19 +94,21 @@ pub const can_unwind: bool = s: {
9494 // Notably, we are yet to support unwinding on ARM. There, unwinding is not done through
9595 // `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format.
9696 const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) {
97 // Not supported yet: arm, m68k
97 // Not supported yet: arm
9898 .haiku => &.{
9999 .aarch64,
100 .m68k,
100101 .riscv64,
101102 .x86,
102103 .x86_64,
103104 },
104 // Not supported yet: arc, arm/armeb/thumb/thumbeb, m68k, xtensa
105 // Not supported yet: arc, arm/armeb/thumb/thumbeb, xtensa
105106 .linux => &.{
106107 .aarch64,
107108 .aarch64_be,
108109 .csky,
109110 .loongarch64,
111 .m68k,
110112 .mips,
111113 .mipsel,
112114 .mips64,
......@@ -133,10 +135,11 @@ pub const can_unwind: bool = s: {
133135 .riscv64,
134136 .x86_64,
135137 },
136 // Not supported yet: arm/armeb, m68k, mips64/mips64el
138 // Not supported yet: arm/armeb, mips64/mips64el
137139 .netbsd => &.{
138140 .aarch64,
139141 .aarch64_be,
142 .m68k,
140143 .mips,
141144 .mipsel,
142145 .x86,
lib/std/debug/cpu_context.zig+40
......@@ -10,6 +10,7 @@ else switch (native_arch) {
1010 .hexagon => Hexagon,
1111 .lanai => Lanai,
1212 .loongarch32, .loongarch64 => LoongArch,
13 .m68k => M68k,
1314 .mips, .mipsel, .mips64, .mips64el => Mips,
1415 .or1k => Or1k,
1516 .powerpc, .powerpcle, .powerpc64, .powerpc64le => Powerpc,
......@@ -87,6 +88,11 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
8788 .r = uc.mcontext.r,
8889 .pc = uc.mcontext.pc,
8990 },
91 .m68k => .{
92 .d = uc.mcontext.d,
93 .a = uc.mcontext.a,
94 .pc = uc.mcontext.pc,
95 },
9096 .powerpc, .powerpcle, .powerpc64, .powerpc64le => .{
9197 .r = uc.mcontext.r,
9298 .pc = uc.mcontext.pc,
......@@ -697,6 +703,40 @@ const LoongArch = extern struct {
697703 }
698704};
699705
706/// This is an `extern struct` so that inline assembly in `current` can use field offsets.
707const M68k = extern struct {
708 /// The numbered data registers d0 - d7.
709 d: [8]u32,
710 /// The numbered address registers a0 - a7.
711 a: [8]u32,
712 pc: u32,
713
714 pub inline fn current() M68k {
715 var ctx: M68k = undefined;
716 asm volatile (
717 \\ movem.l %%d0 - %%a7, (%%a0)
718 \\ lea.l (%%pc), %%a1
719 \\ move.l %%a1, (%%a0, 64)
720 :
721 : [ctx] "{a0}" (&ctx),
722 : .{ .a1 = true, .memory = true });
723 return ctx;
724 }
725
726 pub fn dwarfRegisterBytes(ctx: *M68k, register_num: u16) DwarfRegisterError![]u8 {
727 switch (register_num) {
728 0...7 => return @ptrCast(&ctx.d[register_num]),
729 8...15 => return @ptrCast(&ctx.a[register_num - 8]),
730 26 => return @ptrCast(&ctx.pc),
731
732 16...23 => return error.UnsupportedRegister, // fp0 - fp7
733 24...25 => return error.UnsupportedRegister, // Return columns in GCC...?
734
735 else => return error.InvalidRegister,
736 }
737 }
738};
739
700740/// This is an `extern struct` so that inline assembly in `current` can use field offsets.
701741const Mips = extern struct {
702742 /// The numbered general-purpose registers r0 - r31. r0 must be zero.