Skip to content

Commit

Permalink
switcher: symbolic names of switcher mcause values
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Norton <robert.norton@microsoft.com>
  • Loading branch information
nwf and ronorton committed Nov 8, 2024
1 parent a9b70d4 commit 9a0f2c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sdk/core/switcher/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ exception_entry_asm:
// If we hit one of the exception conditions that we should let
// compartments handle then deliver it to the compartment.
// CHERI exception code.
li a0, 0x1c
li a0, MCAUSE_CHERI
beq a0, t1, .Lhandle_error
// Misaligned instruction, instruction access, illegal instruction,
// breakpoint, misaligned load, load fault, misaligned store, and store
Expand Down Expand Up @@ -549,11 +549,11 @@ exception_entry_asm:
// mret, so reentrancy is no longer a concern.
cspecialw mtdc, csp

// If mcause is 25, then we will jump into the error handler: another
// thread has signalled that this thread should be interrupted. 25 is a
// reserved exception number that we repurpose to indicate explicit
// interruption.
li t1, 25
// If mcause is MCAUSE_THREAD_INTERRUPT, then we will jump into the error
// handler: another thread has signalled that this thread should be
// interrupted. MCAUSE_THREAD_INTERRUPT is a reserved exception number that
// we repurpose to indicate explicit interruption.
li t1, MCAUSE_THREAD_INTERRUPT
beq t0, t1, .Lhandle_injected_error

// Environment call from M-mode is exception code 11.
Expand Down Expand Up @@ -859,7 +859,7 @@ exception_entry_asm:

// Value 24 is reserved for custom use.
.Lset_mcause_and_exit_thread:
csrw mcause, 24
csrw mcause, MCAUSE_THREAD_EXIT
// The thread exit code expects the trusted stack pointer to be in csp and
// the stack pointer to be in mtdc. After thread exit, we don't need the
// stack pointer so just put zero there.
Expand Down Expand Up @@ -1011,7 +1011,7 @@ __Z25switcher_interrupt_threadPv:

// Mark the thread as interrupted.
// Store a magic value in mcause
li a2, 25
li a2, MCAUSE_THREAD_INTERRUPT
csw a2, TrustedStack_offset_mcause(ca1)
// Return success
li a0, 1
Expand Down
8 changes: 8 additions & 0 deletions sdk/core/switcher/misc-assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ EXPORT_ASSEMBLY_EXPRESSION(COMPARTMENT_STACK_PERMISSIONS,
* This *must* be a multiple of 16, which is the stack alignment.
*/
#define STACK_ENTRY_RESERVED_SPACE 16

#ifdef __cplusplus
using namespace priv;
#endif

EXPORT_ASSEMBLY_NAME(MCAUSE_THREAD_EXIT, 24)
EXPORT_ASSEMBLY_NAME(MCAUSE_THREAD_INTERRUPT, 25)
EXPORT_ASSEMBLY_NAME(MCAUSE_CHERI, 28)
1 change: 1 addition & 0 deletions sdk/include/priv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace priv
constexpr size_t MCAUSE_LOAD_PAGE_FAULT = 13;
constexpr size_t MCAUSE_STORE_PAGE_FAULT = 15;
constexpr size_t MCAUSE_THREAD_EXIT = 24;
constexpr size_t MCAUSE_THREAD_INTERRUPT = 25;
constexpr size_t MCAUSE_CHERI = 28;

constexpr size_t MSTATUS_UIE = (1 << 0);
Expand Down

0 comments on commit 9a0f2c0

Please sign in to comment.