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 {
19231923
19241924 .sh_gnu,
19251925 .sh_renesas,
1926 .sh_interrupt,
19261927 => &.{ .sh, .sheb },
19271928
19281929 .ve_sysv,
lib/std/builtin.zig+20
......@@ -342,6 +342,7 @@ pub const CallingConvention = union(enum(u8)) {
342342 // Calling conventions for the `sh`/`sheb` architecture.
343343 sh_gnu: CommonOptions,
344344 sh_renesas: CommonOptions,
345 sh_interrupt: ShInterruptOptions,
345346
346347 /// The standard `ve` calling convention.
347348 ve_sysv: CommonOptions,
......@@ -476,6 +477,25 @@ pub const CallingConvention = union(enum(u8)) {
476477 };
477478 };
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
479499 /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
480500 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
481501 pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
src/InternPool.zig+9
......@@ -12975,6 +12975,11 @@ const PackedCallingConvention = packed struct(u18) {
1297512975 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1297612976 .extra = @intFromEnum(pl.mode),
1297712977 },
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 },
1297812983 else => comptime unreachable,
1297912984 },
1298012985 };
......@@ -13014,6 +13019,10 @@ const PackedCallingConvention = packed struct(u18) {
1301413019 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1301513020 .mode = @enumFromInt(cc.extra),
1301613021 },
13022 std.builtin.CallingConvention.ShInterruptOptions => .{
13023 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
13024 .save = @enumFromInt(cc.extra),
13025 },
1301713026 else => comptime unreachable,
1301813027 },
1301913028 ),
src/Sema.zig+6
......@@ -9141,6 +9141,7 @@ fn callConvIsCallable(cc: std.builtin.CallingConvention.Tag) bool {
91419141 .msp430_interrupt,
91429142 .riscv32_interrupt,
91439143 .riscv64_interrupt,
9144 .sh_interrupt,
91449145 .x86_interrupt,
91459146 .x86_64_interrupt,
91469147
......@@ -9301,6 +9302,7 @@ fn funcCommon(
93019302 .mips_interrupt,
93029303 .riscv64_interrupt,
93039304 .riscv32_interrupt,
9305 .sh_interrupt,
93049306 .avr_interrupt,
93059307 .csky_interrupt,
93069308 .m68k_interrupt,
......@@ -9528,6 +9530,7 @@ fn finishFunc(
95289530 .mips_interrupt,
95299531 .riscv64_interrupt,
95309532 .riscv32_interrupt,
9533 .sh_interrupt,
95319534 .arc_interrupt,
95329535 .avr_interrupt,
95339536 .csky_interrupt,
......@@ -30069,6 +30072,9 @@ fn callconvCoerceAllowed(
3006930072 std.builtin.CallingConvention.RiscvInterruptOptions => {
3007030073 if (src_data.mode != dest_data.mode) return false;
3007130074 },
30075 std.builtin.CallingConvention.ShInterruptOptions => {
30076 if (src_data.save != dest_data.save) return false;
30077 },
3007230078 else => comptime unreachable,
3007330079 }
3007430080 },
src/Zcu.zig+3
......@@ -4449,6 +4449,9 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
44494449 .riscv64_interrupt,
44504450 => |opts| opts.incoming_stack_alignment == null,
44514451
4452 .sh_interrupt,
4453 => |opts| opts.incoming_stack_alignment == null,
4454
44524455 .x86_sysv,
44534456 .x86_win,
44544457 .x86_stdcall,
src/codegen/c.zig+6
......@@ -8114,6 +8114,12 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
81148114 },
81158115
81168116 .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
81188124 .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
1183711837 std.builtin.CallingConvention.ArcInterruptOptions,
1183811838 std.builtin.CallingConvention.ArmInterruptOptions,
1183911839 std.builtin.CallingConvention.RiscvInterruptOptions,
11840 std.builtin.CallingConvention.ShInterruptOptions,
1184011841 std.builtin.CallingConvention.MicroblazeInterruptOptions,
1184111842 std.builtin.CallingConvention.MipsInterruptOptions,
1184211843 std.builtin.CallingConvention.CommonOptions,
......@@ -11964,6 +11965,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
1196411965 .s390x_sysv_vx,
1196511966 .sh_gnu,
1196611967 .sh_renesas,
11968 .sh_interrupt,
1196711969 .ve_sysv,
1196811970 .xcore_xs1,
1196911971 .xcore_xs2,
src/link/Dwarf.zig+1
......@@ -3919,6 +3919,7 @@ fn updateLazyType(
39193919 .mips_interrupt,
39203920 .riscv64_interrupt,
39213921 .riscv32_interrupt,
3922 .sh_interrupt,
39223923 .arc_interrupt,
39233924 .avr_builtin,
39243925 .avr_signal,