use core::arch::asm;

use eh_info::ELF;
use spin::{Lazy, Mutex};
use unwinder::{RegisterSet, Unwinder};

pub mod eh_info;
pub mod panic;
pub mod unwinder;

/// We should initialise on program start.
pub static UNWINDER: Lazy<Mutex<Unwinder>> = Lazy::new(|| {
    // Setup stack traces and proper panic handler. TODO: Handle panics
    // differently if not initialised.
    let eh_frame_ptr = ELF
        .get_section_addr(".eh_frame_hdr")
        .expect("Could not get `.eh_frame_hdr` address.");

    let eh_info = unsafe { eh_info::EhInfo::from_hdr_ptr(eh_frame_ptr) };
    let mut registers = RegisterSet::default();

    Mutex::new(Unwinder::new(eh_info, registers))
});
