Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion port/wch/ch32v/src/cpus/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ pub const startup_logic = struct {
},
}

// Enable interrupts.
// Set mtvec.base to (vector_table_address - 4) >> 2 so that interrupt N
// jumps to the correct handler regardless of any padding between _reset_vector
// and vector_table.
Expand All @@ -263,10 +262,17 @@ pub const startup_logic = struct {
.mode1 = 1, // Use absolute addresses
.base = @intCast((vtable_addr - 4) >> 2),
});

// mstatus.mpp determines the privilege level restored by mret.
// Set to 0x3 (Machine) so mret returns to Machine mode, allowing the
// firmware to manage interrupts and change privilege as needed.
// To change execution to User mode set mpp to 0x0 and execute mret.
// Enable machine-level interrupts (mie) and set floating-point status (fs) if applicable.
csr.mstatus.write(.{
.mie = 1,
.mpie = 1,
.fs = if (cpu_name == .@"qingkev4-rv32imafc") .dirty else .off,
.mpp = 0x3,
});

// Initialize the system.
Expand Down
Loading