#![no_std]
#![no_main]

use core::{arch::asm, panic::PanicInfo, ptr};
use mik32_runtime::entry;

static mut INITIALIZED: u32 = 0x4D49_4B32;
static mut ZEROED: u32 = 0;

#[entry]
fn main() -> ! {
    // Touch both sections so the example verifies startup's .data/.bss setup.
    unsafe {
        let value = ptr::read_volatile(&raw const INITIALIZED);
        ptr::write_volatile(&raw mut ZEROED, value);
    }

    idle()
}

#[unsafe(link_section = ".ram_text")]
#[inline(never)]
fn idle() -> ! {
    loop {
        unsafe { asm!("wfi", options(nomem, nostack)) };
    }
}

#[panic_handler]
fn panic(_info: &PanicInfo<'_>) -> ! {
    loop {
        unsafe { asm!("wfi", options(nomem, nostack)) };
    }
}

#[unsafe(export_name = "trap_handler")]
fn trap() {
    // Add EPIC/source acknowledgement here before returning with `mret`.
}
