Browse Source

Add hook to initialize custom interrupt controllers.

Karol Harasim 4 years ago
parent
commit
ff86cd05a5

+ 7 - 6
riscv-rt/asm.S

@@ -113,15 +113,10 @@ _abs_start:
     // Set frame pointer
     add s0, sp, zero
 
-    // Set trap handler
-    la t0, _start_trap
-    csrw mtvec, t0
-
     jal zero, _start_rust
 
     .cfi_endproc
 
-
 /*
     Trap entry point (_start_trap)
 
@@ -130,6 +125,7 @@ _abs_start:
 */
 .section .trap, "ax"
 .global _start_trap
+.weak _start_trap
 
 _start_trap:
     addi sp, sp, -16*REGBYTES
@@ -174,9 +170,14 @@ _start_trap:
     addi sp, sp, 16*REGBYTES
     mret
 
+.section .text
+default_setup_interrupts:
+    // Set trap handler
+    la t0, _start_trap
+    csrw mtvec, t0
+    ret
 
 /* Make sure there is an abort when linking */
-.section .text
 .globl abort
 abort:
     j abort

BIN
riscv-rt/bin/riscv32i-unknown-none-elf.a


BIN
riscv-rt/bin/riscv32ic-unknown-none-elf.a


BIN
riscv-rt/bin/riscv32im-unknown-none-elf.a


BIN
riscv-rt/bin/riscv32imc-unknown-none-elf.a


BIN
riscv-rt/bin/riscv64i-unknown-none-elf.a


BIN
riscv-rt/bin/riscv64ic-unknown-none-elf.a


BIN
riscv-rt/bin/riscv64im-unknown-none-elf.a


BIN
riscv-rt/bin/riscv64imc-unknown-none-elf.a


+ 4 - 2
riscv-rt/link.x

@@ -22,6 +22,8 @@ PROVIDE(ExceptionHandler = DefaultExceptionHandler);
    then the function this points to will be called before the RAM is initialized. */
 PROVIDE(__pre_init = default_pre_init);
 
+PROVIDE(_setup_interrupts = default_setup_interrupts);
+
 /* # Multi-processing hook function
    fn _mp_hook() -> bool;
 
@@ -46,8 +48,8 @@ SECTIONS
     KEEP(*(.init));
     KEEP(*(.init.rust));
     . = ALIGN(4);
-    KEEP(*(.trap));
-    KEEP(*(.trap.rust));
+    (*(.trap));
+    (*(.trap.rust));
 
     *(.text .text.*);
   } > REGION_TEXT

+ 4 - 0
riscv-rt/src/lib.rs

@@ -370,6 +370,8 @@ pub unsafe extern "C" fn start_rust() -> ! {
         // This symbol will be provided by the user via `#[pre_init]`
         fn __pre_init();
 
+        fn _setup_interrupts();
+
         fn _mp_hook() -> bool;
     }
 
@@ -382,6 +384,8 @@ pub unsafe extern "C" fn start_rust() -> ! {
 
     // TODO: Enable FPU when available
 
+    _setup_interrupts();
+
     main();
 }