Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
define handlers as weak aliases of DEFAULT_HANDLER
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Jul 18, 2017
1 parent 2b08758 commit f17eb5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 95 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
124 changes: 29 additions & 95 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
#![deny(warnings)]
#![feature(asm)]
#![feature(compiler_builtins_lib)]
#![feature(global_asm)]
#![feature(lang_items)]
#![feature(linkage)]
#![feature(naked_functions)]
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit f17eb5b

Please sign in to comment.