switches to tohost based exit code, reducing complexity in deciding failure / pass

This commit is contained in:
2026-03-23 16:58:56 +01:00
parent 4e87ae718b
commit e02a58e25f
4 changed files with 13 additions and 109 deletions

View File

@@ -37,6 +37,7 @@ EXTERN_C function_t __init_array_start;
EXTERN_C function_t __init_array_end;
EXTERN_C function_t __fini_array_start;
EXTERN_C function_t __fini_array_end;
EXTERN_C volatile uintptr_t tohost;
// This function will be placed by the linker script according to the section
// Raw function 'called' by the CPU with no runtime.
@@ -119,9 +120,11 @@ void _initialize(void) {
_exit(rc);
}
// This should never be called. Busy loop with the CPU in idle state.
// This should never be called. Report the exit code through HTIF and idle the CPU.
void _exit(int exit_code) {
(void)exit_code;
uintptr_t htif_exit_code = (((uintptr_t)(unsigned int)exit_code) << 1) | 1u;
tohost = htif_exit_code;
csr_clr_bits_mie(MIE_MTI_BIT_MASK);
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
while (1) {