diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asm.rs | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -164,3 +164,44 @@ pub fn ttat(addr: *mut u32) -> u32 { pub unsafe fn bx_ns(addr: u32) { call_asm!(__bxns(addr: u32)); } + +/// Semihosing syscall. +/// +/// This method is used by cortex-m-semihosting to provide semihosting syscalls. +#[inline] +pub unsafe fn sh_syscall(nr: u32, arg: u32) -> u32 { + call_asm!(__sh_syscall(nr: u32, arg: u32) -> u32) +} + +/// Bootstrap. +/// +/// Sets the active stack to the main stack, updates the main stack pointer to `msp`, +/// then jumps execution to the address in `rv`. +/// Writes `msp` to the MSP special register, then jumps to the address in `rv`. +#[inline] +pub unsafe fn bootstrap(msp: *const u32, rv: *const u32) -> ! { + let msp = msp as u32; + let rv = rv as u32; + call_asm!(__bootstrap(msp: u32, rv: u32)); + core::hint::unreachable_unchecked(); +} + +/// Bootload. +/// +/// Reads the initial stack pointer value and reset vector from +/// the provided vector table address, sets the active stack to +/// the main stack, sets the main stack pointer to the new initial +/// stack pointer view, then jumps to the reset vector. +/// +/// # Safety +/// +/// The provided `vector_table` must point to a valid vector +/// table, with a valid stack pointer as the first word and +/// a valid reset vector (in thumb mode, with the least significant +/// bit cleared) as the second word. +#[inline] +pub unsafe fn bootload(vector_table: *const u32) -> ! { + let msp = core::ptr::read_volatile(vector_table); + let rv = core::ptr::read_volatile(vector_table.offset(1)); + bootstrap(msp as *const u32, rv as *const u32); +} |