MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / error_to_trap_cause

Function error_to_trap_cause

crates/virtual-machine/src/cpu/traps.rs:128–139  ·  view source on GitHub ↗

Map a `VmError` to a trap cause/tval pair. Returns `Some((cause, tval))` if the error should trigger a trap, or `None` if it is a fatal error that cannot be trapped.

(e: &VmError)

Source from the content-addressed store, hash-verified

126 let prev_priv = match mpp {
127 0 => PrivilegeMode::User,
128 1 => PrivilegeMode::Supervisor,
129 3 => PrivilegeMode::Machine,
130 _ => PrivilegeMode::Machine, // reserved value; treat as Machine
131 };
132 regs.priv_mode = prev_priv;
133 csrs.mstatus &= !(0x3u64 << 11); // MPP = User
134
135 // Clear MPRV if returning below M-mode.
136 if prev_priv != PrivilegeMode::Machine {
137 csrs.mstatus &= !(1u64 << 17);
138 }
139
140 csrs.mepc
141}
142

Callers 3

flush_and_trapMethod · 0.85
handle_sretMethod · 0.85
test_error_to_trap_causeFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_error_to_trap_causeFunction · 0.68