Skip to content

Commit 1180e81

Browse files
authored
ch32v: Fix _reset_vector in non-small release modes. (#863)
1 parent 6fef482 commit 1180e81

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

port/wch/ch32v/src/cpus/main.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,15 @@ pub const startup_logic = struct {
254254
}
255255

256256
// Enable interrupts.
257-
csr.mtvec.write(.{ .mode0 = 1, .mode1 = 1, .base = 0 });
257+
// Set mtvec.base to (vector_table_address - 4) >> 2 so that interrupt N
258+
// jumps to the correct handler regardless of any padding between _reset_vector
259+
// and vector_table.
260+
const vtable_addr = @intFromPtr(&vector_table);
261+
csr.mtvec.write(.{
262+
.mode0 = 1, // Interrupt entry for each interrupt
263+
.mode1 = 1, // Use absolute addresses
264+
.base = @intCast((vtable_addr - 4) >> 2),
265+
});
258266
csr.mstatus.write(.{
259267
.mie = 1,
260268
.mpie = 1,

0 commit comments

Comments
 (0)