Skip to content

Commit f64a022

Browse files
committed
bios: Fix EPC handling for break and syscall in exception handler
1 parent 70aea8b commit f64a022

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

examples/bios/src/exceptions.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ extern "C" fn call_handlers(
161161
let cs = &mut cs;
162162
let new_tcb = match cause.excode() {
163163
Excode::Interrupt => call_irq_handlers(tcb, cs),
164-
Excode::Syscall | Excode::Breakpoint => {
165-
if cause.branch_delay_slot() {
166-
unsafe {
167-
asm!("addiu $k1, 4");
168-
}
164+
Excode::Breakpoint => {
165+
// SAFETY: Return to EPC+4 to avoid reexecuting the break instruction
166+
unsafe {
167+
asm!("addiu $k1, 4");
169168
}
170-
if cause.excode() == Excode::Syscall {
171-
syscall_handler(cs, r4, r5)
172-
} else {
173-
println!("{:#x?}", tcb);
174-
ptr::null_mut()
169+
// SAFETY: tcb passed in by exception handler comes from CURRENT_THREAD which is
170+
// always safe to dereference
171+
unsafe {
172+
println!("{:#x?}", *tcb);
175173
}
174+
ptr::null_mut()
176175
},
176+
Excode::Syscall => syscall_handler(cs, r4, r5),
177177
_ => unreachable!(""),
178178
};
179179
new_tcb

0 commit comments

Comments
 (0)