Pārlūkot izejas kodu

Use proc-macro `entry`

Vadim Kaushan 6 gadi atpakaļ
vecāks
revīzija
f981ee60ef
2 mainītis faili ar 9 papildinājumiem un 30 dzēšanām
  1. 1 0
      riscv-rt/Cargo.toml
  2. 8 30
      riscv-rt/src/lib.rs

+ 1 - 0
riscv-rt/Cargo.toml

@@ -11,6 +11,7 @@ license = "ISC"
 [dependencies]
 r0 = "0.2.2"
 riscv = "0.5.0"
+riscv-rt-macros = { path = "macros", version = "0.1.5" }
 
 [features]
 inline-asm = ["riscv/inline-asm"]

+ 8 - 30
riscv-rt/src/lib.rs

@@ -8,7 +8,7 @@
 //!
 //! - Before main initialization of the FPU (for targets that have a FPU).
 //!
-//! - An `entry!` macro to declare the entry point of the program.
+//! - `#[entry]` to declare the entry point of the program
 //!
 //! - A linker script that encodes the memory layout of a generic RISC-V
 //!   microcontroller. This linker script is missing some information that must
@@ -46,8 +46,8 @@
 //! use riscv_rt::entry;
 //!
 //! // use `main` as the entry point of this application
-//! entry!(main);
-//!
+//! // `main` is not allowed to return
+//! #[entry]
 //! fn main() -> ! {
 //!     // do something here
 //!     loop { }
@@ -187,8 +187,11 @@
 #![deny(warnings)]
 
 extern crate riscv;
+extern crate riscv_rt_macros as macros;
 extern crate r0;
 
+pub use macros::entry;
+
 use riscv::register::{mstatus, mtvec};
 
 extern "C" {
@@ -215,8 +218,8 @@ extern "C" {
 #[link_section = ".init.rust"]
 #[export_name = "_start_rust"]
 pub extern "C" fn start_rust() -> ! {
-    extern "C" {
-        // This symbol will be provided by the user via the `entry!` macro
+    extern "Rust" {
+        // This symbol will be provided by the user via `#[entry]`
         fn main() -> !;
     }
 
@@ -236,31 +239,6 @@ pub extern "C" fn start_rust() -> ! {
 }
 
 
-/// Macro to define the entry point of the program
-///
-/// **NOTE** This macro must be invoked once and must be invoked from an accessible module, ideally
-/// from the root of the crate.
-///
-/// Usage: `entry!(path::to::entry::point)`
-///
-/// The specified function will be called by the reset handler *after* RAM has been initialized.
-///
-/// The signature of the specified function must be `fn() -> !` (never ending function).
-#[macro_export]
-macro_rules! entry {
-    ($path:expr) => {
-        #[inline(never)]
-        #[export_name = "main"]
-        pub extern "C" fn __impl_main() -> ! {
-            // validate the signature of the program entry point
-            let f: fn() -> ! = $path;
-
-            f()
-        }
-    };
-}
-
-
 /// Trap entry point rust (_start_trap_rust)
 ///
 /// mcause is read to determine the cause of the trap. XLEN-1 bit indicates