From 8dc751d9e184d348078766c393bd26b27d66ac38 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Sat, 24 Jan 2026 16:24:21 -0500 Subject: [PATCH 1/2] ch32v: Fix: Add clobbers to bss/data loops --- port/wch/ch32v/src/cpus/main.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/port/wch/ch32v/src/cpus/main.zig b/port/wch/ch32v/src/cpus/main.zig index cde786de7..54138c2f4 100644 --- a/port/wch/ch32v/src/cpus/main.zig +++ b/port/wch/ch32v/src/cpus/main.zig @@ -309,7 +309,7 @@ pub const startup_logic = struct { \\ addi a1, a1, 4 \\ blt a1, a2, clear_bss_loop \\clear_bss_done: - ); + ::: .{ .x10 = true, .x11 = true, .x12 = true }); // Copy .data from FLASH to RAM. asm volatile ( @@ -324,7 +324,7 @@ pub const startup_logic = struct { \\ addi a1, a1, 4 \\ bne a1, a2, copy_data_loop \\copy_done: - ); + ::: .{ .x10 = true, .x11 = true, .x12 = true, .x13 = true }); } fn _system_init() callconv(.c) void { From 7f38c1e2adddf1828f0bb80cd4374eb8b910c7e4 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Sat, 24 Jan 2026 21:58:49 -0500 Subject: [PATCH 2/2] Fix more clobbers --- port/wch/ch32v/src/cpus/main.zig | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/port/wch/ch32v/src/cpus/main.zig b/port/wch/ch32v/src/cpus/main.zig index 54138c2f4..a477503d6 100644 --- a/port/wch/ch32v/src/cpus/main.zig +++ b/port/wch/ch32v/src/cpus/main.zig @@ -282,7 +282,26 @@ pub const startup_logic = struct { @export(&startup_logic._system_init, .{ .name = "_system_init" }); asm volatile ( \\jal _system_init - ); + // We have clobber all caller-saved registers + ::: .{ + .x1 = true, + .x5 = true, + .x6 = true, + .x7 = true, + .x10 = true, + .x11 = true, + .x12 = true, + .x13 = true, + .x14 = true, + .x15 = true, + .x16 = true, + .x17 = true, + .x28 = true, + .x29 = true, + .x30 = true, + .x31 = true, + .memory = true, + }); // Load the address of the `microzig_main` function into the `mepc` register // and transfer control to it using the `mret` instruction.