#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")]
#![allow(asm_sub_register)]
#![feature(asm_experimental_arch)]
#![no_std]
use core::arch::asm;
pub mod interrupt;
pub mod timer;
#[macro_use]
mod macros;
const DCR_ENABLEOCD: u32 = 0x01;
const XDM_OCD_DCR_SET: u32 = 0x10200C;
#[inline(always)]
pub unsafe fn set_vecbase(base: *const u32) {
unsafe {
asm!("wsr.vecbase {0}", in(reg) base, options(nostack));
}
}
#[inline(always)]
pub fn get_stack_pointer() -> *const u32 {
let x: *const u32;
unsafe { asm!("mov {0}, sp", out(reg) x, options(nostack)) };
x
}
#[inline(always)]
pub unsafe fn set_stack_pointer(stack: *mut u32) {
unsafe {
asm!(
"movi a0, 0", "mov sp, {0}", in(reg) stack, options(nostack)
);
}
}
#[inline(always)]
pub fn get_program_counter() -> *const u32 {
let x: *const u32;
unsafe {
asm!("
mov {1}, {2}
call0 2f
.align 4
2:
mov {0}, {2}
mov {2}, {1}
", out(reg) x, out(reg) _, out(reg) _, options(nostack))
};
x
}
#[inline(always)]
pub fn get_processor_id() -> u32 {
let mut x: u32;
unsafe { asm!("rsr.prid {0}", out(reg) x, options(nostack)) };
x
}
#[inline(always)]
pub fn is_debugger_attached() -> bool {
let mut x: u32;
unsafe { asm!("rer {0}, {1}", out(reg) x, in(reg) XDM_OCD_DCR_SET, options(nostack)) };
(x & DCR_ENABLEOCD) != 0
}
#[inline(always)]
pub fn debug_break() {
unsafe { asm!("break 1, 15", options(nostack)) };
}
#[doc(hidden)]
pub mod _export {
pub use critical_section;
}