From f17eb5b624877f75293200eefb0123584f4e9e03 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 18 Jul 2017 12:40:47 -0500 Subject: [PATCH] define handlers as weak aliases of DEFAULT_HANDLER cc japaric/cortex-m#19 --- CHANGELOG.md | 6 +++ src/lib.rs | 124 ++++++++++++--------------------------------------- 2 files changed, 35 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a87d506b..abdced2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). improves the output of `objdump`; before, the output showed "Address 0x20000004 is out of bounds". + +### Fixed + +- Remove duplication of default exception handlers. This saves 32 bytes of Flash + memory (.text). + ## [v0.3.3] - 2017-07-14 ### Changed diff --git a/src/lib.rs b/src/lib.rs index 9543fbf6..29682522 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,6 +284,7 @@ #![deny(warnings)] #![feature(asm)] #![feature(compiler_builtins_lib)] +#![feature(global_asm)] #![feature(lang_items)] #![feature(linkage)] #![feature(naked_functions)] @@ -371,108 +372,41 @@ unsafe extern "C" fn reset_handler() -> ! { } } -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn NMI() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +global_asm!(r#" +.weak NMI +NMI = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn HARD_FAULT() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak HARD_FAULT +HARD_FAULT = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn MEM_MANAGE() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak MEM_MANAGE +MEM_MANAGE = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn BUS_FAULT() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak BUS_FAULT +BUS_FAULT = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn USAGE_FAULT() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak USAGE_FAULT +USAGE_FAULT = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn SVCALL() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak SVCALL +SVCALL = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn PENDSV() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } -} +.weak PENDSV +PENDSV = DEFAULT_HANDLER -#[allow(non_snake_case)] -#[allow(private_no_mangle_fns)] -#[cfg(target_arch = "arm")] -#[linkage = "weak"] -#[naked] -#[no_mangle] -extern "C" fn SYS_TICK() { - unsafe { - asm!("b DEFAULT_HANDLER" :::: "volatile"); - intrinsics::unreachable(); - } +.weak SYS_TICK +SYS_TICK = DEFAULT_HANDLER +"#); + +extern "C" { + fn NMI(); + fn HARD_FAULT(); + fn MEM_MANAGE(); + fn BUS_FAULT(); + fn USAGE_FAULT(); + fn SVCALL(); + fn PENDSV(); + fn SYS_TICK(); } #[cfg(target_arch = "arm")]