switcher: avoid a 2nd read of mtdc on error path When in .Lskip_compartment_call, t0 is spare, in that it will be overwritten by one of... - us, in a few instructions (the zeroAllRegistersExcept), or - zeroAllRegistersExcept in .Ltherad_exit, via .Lset_mcause_and_exit_thread, or - the exception path (.Lforce_unwind via .Lhandle_error_in_switcher) bringing us back here, one TrustedFrame further up. We can use it instead of tp for a temporary value, avoiding the need to reload mtdc.
diff --git a/sdk/core/switcher/entry.S b/sdk/core/switcher/entry.S index 09f2e25..3fe407e 100644 --- a/sdk/core/switcher/entry.S +++ b/sdk/core/switcher/entry.S
@@ -349,15 +349,14 @@ clear_hazard_slots ctp, ct2 // make sure there is a frame left in the trusted stack clhu t2, TrustedStack_offset_frameoffset(ctp) - li tp, TrustedStack_offset_frames + li t0, TrustedStack_offset_frames // Move to the previous trusted stack frame. addi t2, t2, -TrustedStackFrame_size // If this is the first trusted stack frame, then the csp that we would be // loading is the csp on entry, which does not have a spilled area. In // this case, we would fault when loading, so would exit the thread, but we // should instead gracefully exit the thread. - bgeu tp, t2, .Lcommon_defer_irqs_and_thread_exit - cspecialr ctp, mtdc + bgeu t0, t2, .Lcommon_defer_irqs_and_thread_exit cincoffset ct1, ctp, t2 // Restore the stack pointer. All other spilled values are spilled there. clc csp, TrustedStackFrame_offset_csp(ct1)