diff --git a/Cargo.toml b/Cargo.toml index c9ef3e94..b09500de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ r0 = "0.2.1" [dependencies.cortex-m] optional = true -version = "0.2.0" +version = "0.2.2" [dependencies.cortex-m-semihosting] optional = true @@ -19,6 +19,9 @@ features = ["mem"] git = "https://github.com/rust-lang-nursery/compiler-builtins" [features] +default = ["exceptions"] +# handle exceptions using the default handler +exceptions = ["cortex-m"] linker-script = [] panic-over-itm = ["cortex-m"] panic-over-semihosting = ["cortex-m-semihosting"] \ No newline at end of file diff --git a/link.x b/link.x index f9f7e2ed..491c9e51 100644 --- a/link.x +++ b/link.x @@ -9,10 +9,10 @@ SECTIONS LONG(ORIGIN(RAM) + LENGTH(RAM)); KEEP(*(.rodata.reset_handler)); - KEEP(*(.rodata._EXCEPTIONS)); + KEEP(*(.rodata.exceptions)); __exceptions = .; - KEEP(*(.rodata._INTERRUPTS)); + KEEP(*(.rodata.interrupts)); __interrupts = .; *(.text.*); diff --git a/src/lib.rs b/src/lib.rs index 1ef90ae4..299617dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,8 +34,8 @@ #![feature(used)] #![no_std] -#[cfg(feature = "panic-over-itm")] -#[macro_use] +#[cfg(any(feature = "panic-over-itm", feature = "exceptions"))] +#[cfg_attr(feature = "panic-over-itm", macro_use)] extern crate cortex_m; extern crate compiler_builtins; #[cfg(feature = "panic-over-semihosting")] @@ -45,6 +45,9 @@ extern crate r0; mod lang_items; +#[cfg(feature = "exceptions")] +use cortex_m::exception; + /// The reset handler /// /// This is the entry point of all programs @@ -57,14 +60,10 @@ unsafe extern "C" fn reset_handler() -> ! { static mut _sdata: u32; static _sidata: u32; - - static _init_array_start: extern "C" fn(); - static _init_array_end: extern "C" fn(); } ::r0::zero_bss(&mut _sbss, &mut _ebss); ::r0::init_data(&mut _sdata, &mut _edata, &_sidata); - ::r0::run_init_array(&_init_array_start, &_init_array_end); // NOTE `rustc` forces this signature on us. See `src/lang_items.rs` extern "C" { @@ -86,3 +85,11 @@ unsafe extern "C" fn reset_handler() -> ! { #[used] #[link_section = ".rodata.reset_handler"] static RESET_HANDLER: unsafe extern "C" fn() -> ! = reset_handler; + +#[allow(dead_code)] +#[cfg(feature = "exceptions")] +#[link_section = ".rodata.exceptions"] +#[used] +static EXCEPTIONS: exception::Handlers = exception::Handlers { + ..exception::DEFAULT_HANDLERS +};