Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Change zinc to support tests #49

Merged
merged 1 commit into from
May 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/hal/cortex_m3/isr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern {
fn isr_systick();
}

#[cfg(not(test))]
#[no_mangle]
#[no_split_stack]
pub extern fn isr_default_fault() {
Expand All @@ -42,6 +43,9 @@ pub extern fn isr_default_fault() {
}
}

#[cfg(test)]
pub extern fn isr_default_fault() { unimplemented!() }

static ISRCount: uint = 16;

#[link_section=".isr_vector"]
Expand Down
10 changes: 10 additions & 0 deletions src/hal/cortex_m3/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Guard<'a>(&'a Lock);

pub static STATIC_LOCK: Lock = Lock { locked: Unsafe { value: 0, marker1: InvariantType } };

#[cfg(not(test))]
#[inline(always)]
unsafe fn exclusive_load(addr: *u32) -> u32 {
let mut value: u32;
Expand All @@ -41,6 +42,10 @@ unsafe fn exclusive_load(addr: *u32) -> u32 {
value
}

#[cfg(test)]
unsafe fn exclusive_load(addr: *u32) -> u32 { unimplemented!() }

#[cfg(not(test))]
#[inline(always)]
unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool {
let mut success: u32;
Expand All @@ -53,6 +58,11 @@ unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool {
success == 0
}

#[cfg(test)]
unsafe fn exclusive_store(addr: *mut u32, value: u32) -> bool {
unimplemented!()
}

impl Lock {
pub fn new() -> Lock {
Lock { locked: Unsafe::new(0) }
Expand Down
24 changes: 24 additions & 0 deletions src/hal/cortex_m3/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,39 @@ pub fn switch_context() {
}

/// Sets task stack pointer (PSP).
#[cfg(not(test))]
#[inline(always)]
pub fn set_task_stack_pointer(val: u32) {
unsafe { asm!("msr psp, $0" :: "r"(val)) };
}

#[cfg(test)]
pub fn set_task_stack_pointer(val: u32) { unimplemented!() }

/// Returns task stack pointer (PSP).
#[cfg(not(test))]
#[inline(always)]
pub fn get_task_stack_pointer() -> u32 {
let mut val: u32;
unsafe { asm!("mrs $0, psp" : "=r"(val)) };
val
}

#[cfg(test)]
pub fn get_task_stack_pointer() -> u32 { unimplemented!() }

/// Returns current stack pointer (SP, which may be PSP or MSP).
#[cfg(not(test))]
#[inline(always)]
pub fn get_current_stack_pointer() -> u32 {
let mut val: u32;
unsafe { asm!("mov $0, sp" : "=r"(val)) };
val
}

#[cfg(test)]
pub fn get_current_stack_pointer() -> u32 { unimplemented!() }

/// State, that's saved by hardware upon entering an ISR.
pub struct SavedState {
pub r0: u32,
Expand Down Expand Up @@ -80,10 +92,14 @@ 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))]
unsafe fn task_finished() {
asm!("bkpt" :::: "volatile");
}

#[cfg(test)]
unsafe fn task_finished() { unimplemented!() }

/// Phantom type to indicate that interrupts are disabled
pub struct NoInterrupts {
contents: ()
Expand Down Expand Up @@ -112,6 +128,7 @@ static mut irq_level : uint = 0;
/// 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))]
#[inline(always)]
unsafe fn disable_irqs() {
if irq_level == 0 {
Expand All @@ -120,7 +137,11 @@ unsafe fn disable_irqs() {
irq_level += 1;
}

#[cfg(test)]
unsafe fn disable_irqs() { unimplemented!() }

/// Enables all interrupts except Reset, HardFault, and NMI.
#[cfg(not(test))]
#[inline(always)]
unsafe fn enable_irqs() {
if irq_level == 0 {
Expand All @@ -131,3 +152,6 @@ unsafe fn enable_irqs() {
asm!("cpsie i" :::: "volatile");
}
}

#[cfg(test)]
unsafe fn enable_irqs() { unimplemented!() }
5 changes: 5 additions & 0 deletions src/lib/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(not(test))]
#[lang="stack_exhausted"]
#[no_split_stack]
extern fn stack_exhausted() {}

#[cfg(not(test))]
#[lang="eh_personality"]
#[no_split_stack]
extern fn eh_personality() {}

#[cfg(not(test))]
#[lang="begin_unwind"]
#[no_split_stack]
extern fn begin_unwind() {}
8 changes: 7 additions & 1 deletion src/lib/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub extern "C" fn __aeabi_memset(s: *mut u8, n: int, c: c_int) {
memset(s, c, n);
}

#[cfg(test)]
#[no_split_stack]
#[no_mangle]
pub fn breakpoint() { unimplemented!() }

#[cfg(not(test))]
#[no_split_stack]
#[no_mangle]
pub fn breakpoint() {
Expand All @@ -71,7 +77,7 @@ pub fn breakpoint() {
#[no_split_stack]
#[no_mangle]
pub fn abort() -> ! {
unsafe { asm!("bkpt") }
breakpoint();
loop {}
}

Expand Down
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(globs, macro_rules, asm)]
#![feature(globs, macro_rules, asm, phase)]
#![crate_id="zinc"]
#![crate_type="rlib"]
#![allow(ctypes)]
Expand Down Expand Up @@ -45,13 +45,21 @@ STM32F403/407).

extern crate core;

#[cfg(test)] #[phase(syntax,link)] extern crate std;
#[cfg(test)] extern crate native;

pub mod boards;
pub mod drivers;
pub mod hal;
pub mod lib;
pub mod os;

// TODO(farcaller): clean up when fixed.
#[cfg(not(test))]
mod std {
pub use core::cmp; // used for #[deriving(Eq)] until fixed in rust.
}

#[test]
fn dummy_test() {
}