From a9f7f478246388f91e27324a2c2b67a257b530b0 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 | 5 +++ src/lib.rs | 124 ++++++++++++--------------------------------------- 2 files changed, 34 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 653c55e3..b210b23b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed + +- Remove duplication of default exception handlers. This saves 32 bytes of Flash + memory (.text). + ## [v0.3.4] - 2017-07-19 ### 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")]