Browse Source

Do not use #[linkage = "weak"]

Vadim Kaushan 6 năm trước cách đây
mục cha
commit
7740a5c87d
2 tập tin đã thay đổi với 12 bổ sung7 xóa
  1. 2 0
      riscv-rt/link.x
  2. 10 7
      riscv-rt/src/lib.rs

+ 2 - 0
riscv-rt/link.x

@@ -3,6 +3,8 @@ INCLUDE memory.x
 
 PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
 
+PROVIDE(trap_handler = default_trap_handler);
+
 SECTIONS
 {
   PROVIDE(_stext = ORIGIN(FLASH));

+ 10 - 7
riscv-rt/src/lib.rs

@@ -166,12 +166,11 @@
 #![deny(warnings)]
 #![feature(compiler_builtins_lib)]
 #![feature(const_fn)]
-#![feature(linkage)]
 
 extern crate riscv;
 extern crate r0;
 
-use riscv::register::{mcause, mstatus, mtvec};
+use riscv::register::{mstatus, mtvec};
 
 extern "C" {
     // Boundaries of the .bss section
@@ -252,10 +251,15 @@ macro_rules! entry {
 #[link_section = ".trap.rust"]
 #[export_name = "_start_trap_rust"]
 pub extern "C" fn start_trap_rust() {
-    // dispatch trap to handler
-    trap_handler(mcause::read().cause());
-    // mstatus, remain in M-mode after mret
+    extern "C" {
+        fn trap_handler();
+    }
+
     unsafe {
+        // dispatch trap to handler
+        trap_handler();
+
+        // mstatus, remain in M-mode after mret
         mstatus::set_mpp(mstatus::MPP::Machine);
     }
 }
@@ -263,5 +267,4 @@ pub extern "C" fn start_trap_rust() {
 
 /// Default Trap Handler
 #[no_mangle]
-#[linkage = "weak"]
-pub fn trap_handler(_: mcause::Trap) {}
+pub fn default_trap_handler() {}