authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-20 21:26:14+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-23 09:27:17+02:00
logaf1d777b27641e2dedb70d19e3e4f5b04fa62a6e
treeec307648b1243d20ae40334fe2b0a3a9ef7da32c
parent4fa453ce20ceaee254a7d127a4a99be2260ec605
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.builtin: add CallingConvention.sh_interrupt

Only supported in CBE.

8 files changed, 48 insertions(+), 0 deletions(-)

lib/std/Target.zig+1
...@@ -1923,6 +1923,7 @@ pub const Cpu = struct {...@@ -1923,6 +1923,7 @@ pub const Cpu = struct {
19231923
1924 .sh_gnu,1924 .sh_gnu,
1925 .sh_renesas,1925 .sh_renesas,
1926 .sh_interrupt,
1926 => &.{ .sh, .sheb },1927 => &.{ .sh, .sheb },
19271928
1928 .ve_sysv,1929 .ve_sysv,
lib/std/builtin.zig+20
...@@ -342,6 +342,7 @@ pub const CallingConvention = union(enum(u8)) {...@@ -342,6 +342,7 @@ pub const CallingConvention = union(enum(u8)) {
342 // Calling conventions for the `sh`/`sheb` architecture.342 // Calling conventions for the `sh`/`sheb` architecture.
343 sh_gnu: CommonOptions,343 sh_gnu: CommonOptions,
344 sh_renesas: CommonOptions,344 sh_renesas: CommonOptions,
345 sh_interrupt: ShInterruptOptions,
345346
346 /// The standard `ve` calling convention.347 /// The standard `ve` calling convention.
347 ve_sysv: CommonOptions,348 ve_sysv: CommonOptions,
...@@ -476,6 +477,25 @@ pub const CallingConvention = union(enum(u8)) {...@@ -476,6 +477,25 @@ pub const CallingConvention = union(enum(u8)) {
476 };477 };
477 };478 };
478479
480 /// Options for the `sh_interrupt` calling convention.
481 pub const ShInterruptOptions = struct {
482 /// The boundary the stack is aligned to when the function is called.
483 /// `null` means the default for this calling convention.
484 incoming_stack_alignment: ?u64 = null,
485 save: SaveBehavior = .full,
486
487 pub const SaveBehavior = enum(u3) {
488 /// Save only fpscr (if applicable).
489 fpscr,
490 /// Save only high-numbered registers, i.e. r0 through r7 are *not* saved.
491 high,
492 /// Save all registers normally.
493 full,
494 /// Save all registers using the CPU's fast register bank.
495 bank,
496 };
497 };
498
479 /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.499 /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
480 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.500 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
481 pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {501 pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
src/InternPool.zig+9
...@@ -12975,6 +12975,11 @@ const PackedCallingConvention = packed struct(u18) {...@@ -12975,6 +12975,11 @@ const PackedCallingConvention = packed struct(u18) {
12975 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),12975 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12976 .extra = @intFromEnum(pl.mode),12976 .extra = @intFromEnum(pl.mode),
12977 },12977 },
12978 std.builtin.CallingConvention.ShInterruptOptions => .{
12979 .tag = tag,
12980 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12981 .extra = @intFromEnum(pl.save),
12982 },
12978 else => comptime unreachable,12983 else => comptime unreachable,
12979 },12984 },
12980 };12985 };
...@@ -13014,6 +13019,10 @@ const PackedCallingConvention = packed struct(u18) {...@@ -13014,6 +13019,10 @@ const PackedCallingConvention = packed struct(u18) {
13014 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),13019 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
13015 .mode = @enumFromInt(cc.extra),13020 .mode = @enumFromInt(cc.extra),
13016 },13021 },
13022 std.builtin.CallingConvention.ShInterruptOptions => .{
13023 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
13024 .save = @enumFromInt(cc.extra),
13025 },
13017 else => comptime unreachable,13026 else => comptime unreachable,
13018 },13027 },
13019 ),13028 ),
src/Sema.zig+6
...@@ -9141,6 +9141,7 @@ fn callConvIsCallable(cc: std.builtin.CallingConvention.Tag) bool {...@@ -9141,6 +9141,7 @@ fn callConvIsCallable(cc: std.builtin.CallingConvention.Tag) bool {
9141 .msp430_interrupt,9141 .msp430_interrupt,
9142 .riscv32_interrupt,9142 .riscv32_interrupt,
9143 .riscv64_interrupt,9143 .riscv64_interrupt,
9144 .sh_interrupt,
9144 .x86_interrupt,9145 .x86_interrupt,
9145 .x86_64_interrupt,9146 .x86_64_interrupt,
91469147
...@@ -9301,6 +9302,7 @@ fn funcCommon(...@@ -9301,6 +9302,7 @@ fn funcCommon(
9301 .mips_interrupt,9302 .mips_interrupt,
9302 .riscv64_interrupt,9303 .riscv64_interrupt,
9303 .riscv32_interrupt,9304 .riscv32_interrupt,
9305 .sh_interrupt,
9304 .avr_interrupt,9306 .avr_interrupt,
9305 .csky_interrupt,9307 .csky_interrupt,
9306 .m68k_interrupt,9308 .m68k_interrupt,
...@@ -9528,6 +9530,7 @@ fn finishFunc(...@@ -9528,6 +9530,7 @@ fn finishFunc(
9528 .mips_interrupt,9530 .mips_interrupt,
9529 .riscv64_interrupt,9531 .riscv64_interrupt,
9530 .riscv32_interrupt,9532 .riscv32_interrupt,
9533 .sh_interrupt,
9531 .arc_interrupt,9534 .arc_interrupt,
9532 .avr_interrupt,9535 .avr_interrupt,
9533 .csky_interrupt,9536 .csky_interrupt,
...@@ -30069,6 +30072,9 @@ fn callconvCoerceAllowed(...@@ -30069,6 +30072,9 @@ fn callconvCoerceAllowed(
30069 std.builtin.CallingConvention.RiscvInterruptOptions => {30072 std.builtin.CallingConvention.RiscvInterruptOptions => {
30070 if (src_data.mode != dest_data.mode) return false;30073 if (src_data.mode != dest_data.mode) return false;
30071 },30074 },
30075 std.builtin.CallingConvention.ShInterruptOptions => {
30076 if (src_data.save != dest_data.save) return false;
30077 },
30072 else => comptime unreachable,30078 else => comptime unreachable,
30073 }30079 }
30074 },30080 },
src/Zcu.zig+3
...@@ -4449,6 +4449,9 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu...@@ -4449,6 +4449,9 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
4449 .riscv64_interrupt,4449 .riscv64_interrupt,
4450 => |opts| opts.incoming_stack_alignment == null,4450 => |opts| opts.incoming_stack_alignment == null,
44514451
4452 .sh_interrupt,
4453 => |opts| opts.incoming_stack_alignment == null,
4454
4452 .x86_sysv,4455 .x86_sysv,
4453 .x86_win,4456 .x86_win,
4454 .x86_stdcall,4457 .x86_stdcall,
src/codegen/c.zig+6
...@@ -8114,6 +8114,12 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8...@@ -8114,6 +8114,12 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
8114 },8114 },
81158115
8116 .sh_renesas => "renesas",8116 .sh_renesas => "renesas",
8117 .sh_interrupt => |opts| switch (opts.save) {
8118 .fpscr => "trapa_handler", // Implies `interrupt_handler`.
8119 .high => "interrupt_handler, nosave_low_regs",
8120 .full => "interrupt_handler",
8121 .bank => "interrupt_handler, resbank",
8122 },
81178123
8118 .m68k_rtd => "m68k_rtd",8124 .m68k_rtd => "m68k_rtd",
81198125
src/codegen/llvm.zig+2
...@@ -11837,6 +11837,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: *const std.Targ...@@ -11837,6 +11837,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: *const std.Targ
11837 std.builtin.CallingConvention.ArcInterruptOptions,11837 std.builtin.CallingConvention.ArcInterruptOptions,
11838 std.builtin.CallingConvention.ArmInterruptOptions,11838 std.builtin.CallingConvention.ArmInterruptOptions,
11839 std.builtin.CallingConvention.RiscvInterruptOptions,11839 std.builtin.CallingConvention.RiscvInterruptOptions,
11840 std.builtin.CallingConvention.ShInterruptOptions,
11840 std.builtin.CallingConvention.MicroblazeInterruptOptions,11841 std.builtin.CallingConvention.MicroblazeInterruptOptions,
11841 std.builtin.CallingConvention.MipsInterruptOptions,11842 std.builtin.CallingConvention.MipsInterruptOptions,
11842 std.builtin.CallingConvention.CommonOptions,11843 std.builtin.CallingConvention.CommonOptions,
...@@ -11964,6 +11965,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s...@@ -11964,6 +11965,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
11964 .s390x_sysv_vx,11965 .s390x_sysv_vx,
11965 .sh_gnu,11966 .sh_gnu,
11966 .sh_renesas,11967 .sh_renesas,
11968 .sh_interrupt,
11967 .ve_sysv,11969 .ve_sysv,
11968 .xcore_xs1,11970 .xcore_xs1,
11969 .xcore_xs2,11971 .xcore_xs2,
src/link/Dwarf.zig+1
...@@ -3919,6 +3919,7 @@ fn updateLazyType(...@@ -3919,6 +3919,7 @@ fn updateLazyType(
3919 .mips_interrupt,3919 .mips_interrupt,
3920 .riscv64_interrupt,3920 .riscv64_interrupt,
3921 .riscv32_interrupt,3921 .riscv32_interrupt,
3922 .sh_interrupt,
3922 .arc_interrupt,3923 .arc_interrupt,
3923 .avr_builtin,3924 .avr_builtin,
3924 .avr_signal,3925 .avr_signal,