Skip to content

Commit f6aedfa

Browse files
committed
Fix duplicated exception handlers.
1 parent 6eb79e4 commit f6aedfa

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/generate.rs

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ pub fn device(
3535

3636
if *target != Target::None {
3737
items.push(quote! {
38-
#![cfg_attr(feature = "rt", feature(asm))]
39-
#![cfg_attr(feature = "rt", feature(core_intrinsics))]
38+
#![cfg_attr(feature = "rt", feature(global_asm))]
4039
#![cfg_attr(feature = "rt", feature(linkage))]
4140
#![cfg_attr(feature = "rt", feature(macro_reexport))]
42-
#![cfg_attr(feature = "rt", feature(naked_functions))]
4341
#![cfg_attr(feature = "rt", feature(used))]
4442
});
4543
}
@@ -234,52 +232,45 @@ pub fn interrupt(
234232
names.push(name_uc);
235233
}
236234

235+
let aliases = names.iter()
236+
.map(|n| format!("
237+
.weak {0}
238+
{0} = DEFAULT_HANDLER", n))
239+
.collect::<Vec<_>>()
240+
.concat();
241+
237242
let n = util::unsuffixed(u64(pos));
238243
match *target {
239244
Target::CortexM => {
240245
mod_items.push(quote! {
241-
#(
242-
#[allow(non_snake_case)]
243-
#[allow(private_no_mangle_fns)]
244-
#[cfg(feature = "rt")]
245-
#[linkage = "weak"]
246-
#[naked]
247-
#[no_mangle]
248-
extern "C" fn #names() {
249-
unsafe {
250-
asm!("b DEFAULT_HANDLER" :::: "volatile");
251-
::core::intrinsics::unreachable()
252-
}
253-
}
254-
)*
246+
#[cfg(feature = "rt")]
247+
global_asm!(#aliases);
248+
249+
#[cfg(feature = "rt")]
250+
extern "C" {
251+
#(fn #names();)*
252+
}
255253

256254
#[allow(private_no_mangle_statics)]
257255
#[cfg(feature = "rt")]
258256
#[doc(hidden)]
259257
#[link_section = ".vector_table.interrupts"]
260258
#[no_mangle]
261259
#[used]
262-
pub static INTERRUPTS: [Option<extern "C" fn()>; #n] = [
260+
pub static INTERRUPTS: [Option<unsafe extern "C" fn()>; #n] = [
263261
#(#elements,)*
264262
];
265263
});
266264
}
267265
Target::Msp430 => {
268266
mod_items.push(quote! {
269-
#(
270-
#[allow(non_snake_case)]
271-
#[allow(private_no_mangle_fns)]
272-
#[cfg(feature = "rt")]
273-
#[linkage = "weak"]
274-
#[naked]
275-
#[no_mangle]
276-
extern "msp430-interrupt" fn #names() {
277-
unsafe {
278-
asm!("jmp DEFAULT_HANDLER" :::: "volatile");
279-
::core::intrinsics::unreachable()
280-
}
281-
}
282-
)*
267+
#[cfg(feature = "rt")]
268+
global_asm!(#aliases);
269+
270+
#[cfg(feature = "rt")]
271+
extern "msp430-interrupt" {
272+
#(fn #names();)*
273+
}
283274

284275
#[allow(private_no_mangle_statics)]
285276
#[cfg(feature = "rt")]
@@ -288,7 +279,7 @@ pub fn interrupt(
288279
#[no_mangle]
289280
#[used]
290281
pub static INTERRUPTS:
291-
[Option<extern "msp430-interrupt" fn()>; #n] = [
282+
[Option<unsafe extern "msp430-interrupt" fn()>; #n] = [
292283
#(#elements,)*
293284
];
294285
});

0 commit comments

Comments
 (0)