Skip to content

Commit

Permalink
[crt0] use crt0 trap handler for destructor exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Jul 5, 2024
1 parent 7a2cdcc commit e3e4eb7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sw/common/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,23 @@ __crt0_call_constructors_loop_end:
__crt0_main_entry:
addi x10, zero, 0 // x10 = a0 = argc = 0
addi x11, zero, 0 // x11 = a1 = argv = 0
jal x1, main // call actual app's main function
jal x1, main // call actual main function

__crt0_main_exit: // main's "return" and "exit" will arrive here
csrw mie, zero // disable all interrupt sources
csrw mscratch, a0 // backup main's return code to mscratch (for debugger)
csrw mscratch, a0 // backup main's return code to mscratch (for debugger or destructors)



// ************************************************************************************************
// Call destructors
// ************************************************************************************************
#ifndef MAKE_BOOTLOADER // destructors are not supported for bootloader
__crt0_call_destructors:
la x8, __fini_array_start
la x9, __fini_array_end
la x8, __crt0_trap_handler // use the crt0 trap handler if there are exceptions in the destructors
csrw mtvec, x8
la x8, __fini_array_start
la x9, __fini_array_end

__crt0_call_destructors_loop:
bge x8, x9, __crt0_call_destructors_loop_end
Expand Down

0 comments on commit e3e4eb7

Please sign in to comment.