tail_core 0.1.1

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.


#[cfg(not(test))]
use core::intrinsics::volatile_load;
#[cfg(not(test))]
use core::intrinsics::volatile_store;

pub fn write_mmap_device(address: u32, value: u32)
{
    unsafe {
        volatile_store(address as *mut u32, value);
    }
}

pub fn read_mmap_device(address: u32) -> u32
{
    unsafe {
        return volatile_load(address as *mut u32);
    }
}

// mocked function
#[cfg(test)]
pub unsafe fn volatile_load(address: *mut u32) -> u32 {
    return 0x12345678;
}

// mocked function
#[cfg(test)]
pub unsafe fn volatile_store(address: *mut u32, value: u32)
{
    assert_eq!(value, 0x12345678);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_mmap_device() {
        let address = 0x1000;
        let value = 0x12345678;
        write_mmap_device(address, value);
        assert_eq!(read_mmap_device(address), value);
    }
}