diff --git a/src/hal/cortex_common/irq.rs b/src/hal/cortex_common/irq.rs index ac9083c9..5a4e5560 100644 --- a/src/hal/cortex_common/irq.rs +++ b/src/hal/cortex_common/irq.rs @@ -16,7 +16,7 @@ //! Disabling and enabling interrupts use core::ops::Drop; -#[cfg(not(test))] +#[cfg(target_os = "none")] use core::intrinsics::abort; /// Phantom type to indicate that interrupts are disabled. @@ -43,25 +43,25 @@ impl Drop for NoInterrupts { } } -#[cfg(not(test))] +#[cfg(target_os = "none")] static mut irq_level : usize = 0; /// Disables all interrupts except Reset, HardFault, and NMI. /// Note that this is reference counted: if `disable_irqs` is called /// twice then interrupts will only be re-enabled upon the second call /// to `enable_irqs`. -#[cfg(not(test))] +#[cfg(target_os = "none")] #[inline(always)] unsafe fn disable_irqs() { asm!("cpsid i" :::: "volatile"); irq_level += 1; } -#[cfg(test)] +#[cfg(not(target_os = "none"))] unsafe fn disable_irqs() { unimplemented!() } /// Enables all interrupts except Reset, HardFault, and NMI. -#[cfg(not(test))] +#[cfg(target_os = "none")] #[inline(always)] unsafe fn enable_irqs() { if irq_level == 0 { @@ -75,5 +75,5 @@ unsafe fn enable_irqs() { } } -#[cfg(test)] +#[cfg(not(target_os = "none"))] unsafe fn enable_irqs() { unimplemented!() } diff --git a/src/hal/cortex_m3/isr.rs b/src/hal/cortex_m3/isr.rs index c653b733..a7cac1a5 100644 --- a/src/hal/cortex_m3/isr.rs +++ b/src/hal/cortex_m3/isr.rs @@ -34,7 +34,6 @@ extern { fn isr_reserved_1(); } -#[cfg(not(test))] #[no_mangle] pub unsafe extern fn isr_handler_wrapper() { asm!(".weak isr_nmi, isr_hardfault, isr_mmfault, isr_busfault diff --git a/src/hal/cortex_m3/lock.rs b/src/hal/cortex_m3/lock.rs index 84a4cafc..e7fd6e62 100644 --- a/src/hal/cortex_m3/lock.rs +++ b/src/hal/cortex_m3/lock.rs @@ -29,7 +29,7 @@ pub struct Guard<'a>(&'a Lock); pub static STATIC_LOCK: Lock = Lock { locked: Unsafe { value: 0, marker1: InvariantType } }; -#[cfg(not(test))] +#[cfg(target_arch = "arm")] #[inline(always)] unsafe fn exclusive_load(addr: *const u32) -> u32 { let mut value: u32; @@ -42,10 +42,10 @@ unsafe fn exclusive_load(addr: *const u32) -> u32 { value } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] unsafe fn exclusive_load(addr: *const u32) -> u32 { unimplemented!() } -#[cfg(not(test))] +#[cfg(target_arch = "arm")] #[inline(always)] unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool { let mut success: u32; @@ -58,7 +58,7 @@ unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool { success == 0 } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool { unimplemented!() } diff --git a/src/hal/cortex_m3/sched.rs b/src/hal/cortex_m3/sched.rs index 531be10c..de62b4a8 100644 --- a/src/hal/cortex_m3/sched.rs +++ b/src/hal/cortex_m3/sched.rs @@ -28,17 +28,17 @@ pub fn switch_context() { } /// Sets task stack pointer (PSP). -#[cfg(not(test))] +#[cfg(target_arch = "arm")] #[inline(always)] pub fn set_task_stack_pointer(val: u32) { unsafe { asm!("msr psp, $0" :: "r"(val) :: "volatile") }; } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] pub fn set_task_stack_pointer(val: u32) { unimplemented!() } /// Returns task stack pointer (PSP). -#[cfg(not(test))] +#[cfg(target_arch = "arm")] #[inline(always)] pub fn get_task_stack_pointer() -> u32 { let mut val: u32; @@ -46,11 +46,11 @@ pub fn get_task_stack_pointer() -> u32 { val } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] pub fn get_task_stack_pointer() -> u32 { unimplemented!() } /// Returns current stack pointer (SP, which may be PSP or MSP). -#[cfg(not(test))] +#[cfg(target_arch = "arm")] #[inline(always)] pub fn get_current_stack_pointer() -> u32 { let mut val: u32; @@ -58,7 +58,7 @@ pub fn get_current_stack_pointer() -> u32 { val } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] pub fn get_current_stack_pointer() -> u32 { unimplemented!() } /// State, that's saved by hardware upon entering an ISR. @@ -92,11 +92,11 @@ impl SavedState { // TODO(farcaller): this should actually kill the task. // TODO(bgamari): It should also unlock anything the task holds /// Default handler for task that tries to return. -#[cfg(not(test))] +#[cfg(target_os = "none")] unsafe fn task_finished() { - asm!("bkpt" :::: "volatile"); + core::intrinsics::breakpoint(); } -#[cfg(test)] +#[cfg(not(target_os = "none"))] unsafe fn task_finished() { unimplemented!() } diff --git a/src/hal/isr.rs b/src/hal/isr.rs index 21ab6abb..722439fd 100644 --- a/src/hal/isr.rs +++ b/src/hal/isr.rs @@ -21,7 +21,6 @@ #[cfg(feature = "cpu_cortex-m3")] #[path="cortex_m3/isr.rs"] pub mod isr_cortex_m3; -// TODO(mcoffin): create cortex-m4 isr module #[cfg(feature = "cpu_cortex-m4")] #[path="cortex_m3/isr.rs"] pub mod isr_cortex_m4; diff --git a/src/hal/mod.rs b/src/hal/mod.rs index af07aa04..49d7917c 100644 --- a/src/hal/mod.rs +++ b/src/hal/mod.rs @@ -48,5 +48,5 @@ pub mod stack; pub mod timer; pub mod uart; -#[cfg(not(test))] +#[cfg(target_os = "none")] pub mod isr; diff --git a/src/lib.rs b/src/lib.rs index f1bf914d..896462b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,8 @@ STM32F403/407). #![feature(no_std)] #[macro_use] extern crate core; -#[cfg(not(test))] extern crate rlibc; +#[cfg(target_os = "none")] +extern crate rlibc; #[macro_use] #[no_link] extern crate ioreg; extern crate volatile_cell; @@ -66,7 +67,7 @@ pub mod os; /// for some items in the `std` namespace. /// /// TODO(farcaller): clean up when fixed. -#[cfg(not(test))] +#[cfg(target_os = "none")] pub mod std { pub use core::cmp; // used for #[derive(Eq)] until fixed in rust. pub use core::option; diff --git a/src/util/shared.rs b/src/util/shared.rs index ccc60d28..7e47bbd1 100644 --- a/src/util/shared.rs +++ b/src/util/shared.rs @@ -34,7 +34,7 @@ mod dummy_irq { impl NoInterrupts { pub fn new() -> NoInterrupts { - NoInterrupts; + NoInterrupts } } } diff --git a/src/util/support.rs b/src/util/support.rs index 25814664..327f4451 100644 --- a/src/util/support.rs +++ b/src/util/support.rs @@ -15,25 +15,15 @@ //! Support functions currently required by the linker for bare-metal targets. -#[doc(hidden)] -#[cfg(test)] -#[no_stack_check] -#[no_mangle] -pub extern fn breakpoint() { unimplemented!() } - -/// Call the debugger. -#[cfg(all(not(test), target_arch = "arm"))] -#[no_stack_check] -#[no_mangle] -pub extern fn breakpoint() { - unsafe { asm!("bkpt") } -} +pub use core::intrinsics::breakpoint; /// Call the debugger and halts execution. #[no_stack_check] #[no_mangle] pub extern fn abort() -> ! { - breakpoint(); + unsafe { + breakpoint(); + } loop {} } @@ -49,26 +39,26 @@ pub extern fn __aeabi_memset(dest: *mut u8, size: usize, value: u32) { } } -#[cfg(all(not(test), target_arch = "arm"))] +#[cfg(target_arch = "arm")] #[inline(always)] /// NOP instruction pub fn nop() { unsafe { asm!("nop" :::: "volatile"); } } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] /// NOP instruction (mock) pub fn nop() { } -#[cfg(all(not(test), target_arch = "arm"))] +#[cfg(target_arch = "arm")] #[inline(always)] /// WFI instruction pub fn wfi() { unsafe { asm!("wfi" :::: "volatile"); } } -#[cfg(test)] +#[cfg(not(target_arch = "arm"))] /// WFI instruction (mock) pub fn wfi() { }