Skip to content

Commit 5137b0a

Browse files
bors[bot]MabezDev
andauthored
Merge #81
81: Trap handler override improvments r=almindor a=MabezDev * Add ability to override trap handling mechanism * Previously, `_start_trap` was marked as weak, which when compiled into a static archive, that information is ignored. * Now by default we `PROVIDE` the default trap handler, if another one has not been specified from another crate. * Mark the fields of `Vector` public, for use outside of `riscv-rt` Co-authored-by: Scott Mabin <[email protected]>
2 parents 629737e + daeaf18 commit 5137b0a

27 files changed

+11
-6
lines changed

riscv-rt/asm.S

+2-4
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ _abs_start:
124124
restores caller saved registers and then returns.
125125
*/
126126
.section .trap, "ax"
127-
.global _start_trap
128-
/* Make it .weak so PAC/HAL can provide their own if needed. */
129-
.weak _start_trap
127+
.global default_start_trap
130128

131-
_start_trap:
129+
default_start_trap:
132130
addi sp, sp, -16*REGBYTES
133131

134132
STORE ra, 0*REGBYTES(sp)
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.

riscv-rt/link.x

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ PROVIDE(_setup_interrupts = default_setup_interrupts);
3434
*/
3535
PROVIDE(_mp_hook = default_mp_hook);
3636

37+
/* # Start trap function override
38+
By default uses the riscv crates default trap handler
39+
but by providing the `_start_trap` symbol external crates can override.
40+
*/
41+
PROVIDE(_start_trap = default_start_trap);
42+
3743
SECTIONS
3844
{
3945
.text.dummy (NOLOAD) :

riscv-rt/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ pub unsafe extern "C" fn start_rust() -> ! {
392392
/// Registers saved in trap handler
393393
#[allow(missing_docs)]
394394
#[repr(C)]
395+
#[derive(Debug)]
395396
pub struct TrapFrame {
396397
pub ra: usize,
397398
pub t0: usize,
@@ -496,8 +497,8 @@ extern "C" {
496497

497498
#[doc(hidden)]
498499
pub union Vector {
499-
handler: unsafe extern "C" fn(),
500-
reserved: usize,
500+
pub handler: unsafe extern "C" fn(),
501+
pub reserved: usize,
501502
}
502503

503504
#[doc(hidden)]

0 commit comments

Comments
 (0)