tail_core 0.1.0

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


use core::arch::asm;

pub fn spin_msec(n: u32) {
    let mut f: u64;
    let mut t: u64;
    let mut r: u64;

    unsafe {
        // Get the current counter frequency
        asm!("mrs {0}, cntfrq_el0", out(reg) f);

        // Read the current counter
        asm!("mrs {0}, cntpct_el0", out(reg) t);

        // Calculate the expiration value for the counter
        t += (f / 1000) * (n as u64);

        // Spin until the counter reaches the target value
        loop {
            asm!("mrs {0}, cntpct_el0", out(reg) r);
            if r >= t {
                break;
            }
        }
    }
}