#![allow(missing_docs)]

use abi::error::Error;

pub fn get_thread_pointer() -> usize {
    let tp: usize;
    unsafe {
        core::arch::asm!("mrs {0}, tpidr_el0", out(reg) tp);
    }
    tp
}

/// Writes `value` into `tpidr_el0` register.
///
/// # Safety
///
/// Usual pointer rules apply.
pub unsafe fn set_thread_pointer(value: usize) -> Result<(), Error> {
    unsafe {
        core::arch::asm!("msr tpidr_el0, {0}", in(reg) value);
    }
    Ok(())
}
