sparreal_kernel/platform/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use alloc::string::String;
use page_table_generic::PTEGeneric;
use sparreal_macros::api_trait;

pub enum PageAttribute {
    Read,
    Write,
    Device,
    Execute,
    NonCache,
}

pub enum PageError {
    NoMemory,
    Other,
}

pub fn app_main() {
    extern "C" {
        fn __sparreal_rt_main();
    }

    unsafe { __sparreal_rt_main() }
}

#[api_trait]
pub trait Platform {
    unsafe fn shutdown();
    unsafe fn wait_for_interrupt();
    unsafe fn current_ticks() -> u64;
    unsafe fn tick_hz() -> u64;
    unsafe fn debug_write_char(ch: u8);

    fn print_system_info();

    fn irqs_enable();
    fn irqs_disable();
    fn cpu_id() -> u64;
    fn cpu_id_display() -> String;
}

#[cfg(feature = "mmu")]
#[api_trait]
pub trait PlatformPageTable {
    fn set_kernel_table(addr: usize);
    fn get_kernel_table() -> usize;
    fn set_user_table(addr: usize);
    fn get_user_table() -> usize;
    fn flush_tlb(addr: Option<*const u8>);
    fn page_size() -> usize;
    fn table_level() -> usize;
    fn new_pte(config: PTEGeneric) -> usize;
    fn read_pte(pte: usize) -> PTEGeneric;
}