sparreal_kernel/hal_al/
mod.rs

1pub use rdrive::{DeviceId, IrqId, register::DriverRegisterSlice};
2
3pub use crate::irq::IrqParam;
4use crate::mem::mmu::BootRegion;
5
6pub mod mmu;
7pub mod run;
8
9#[repr(C)]
10#[derive(Debug, Clone, Copy)]
11pub enum CacheOp {
12    /// Write back to memory
13    Clean,
14    /// Invalidate cache
15    Invalidate,
16    /// Clean and invalidate
17    CleanAndInvalidate,
18}
19
20#[trait_ffi::def_extern_trait(mod_path = "hal_al")]
21pub trait Hal: mmu::Mmu {
22    fn kstack_size() -> usize;
23    fn cpu_id() -> usize;
24    fn cpu_context_size() -> usize;
25
26    fn boot_region_by_index(index: usize) -> Option<BootRegion>;
27
28    /// # Safety
29    ///
30    ///
31    unsafe fn get_current_tcb_addr() -> *mut u8;
32
33    /// # Safety
34    ///
35    ///
36    unsafe fn set_current_tcb_addr(addr: *mut u8);
37
38    /// # Safety
39    ///
40    /// `ctx_ptr` 是有效的上下文指针
41    unsafe fn cpu_context_sp(ctx_ptr: *const u8) -> usize;
42
43    /// # Safety
44    ///
45    /// `ctx_ptr` 是有效的上下文指针
46    unsafe fn cpu_context_set_sp(ctx_ptr: *const u8, sp: usize);
47
48    /// # Safety
49    ///
50    /// `ctx_ptr` 是有效的上下文指针
51    unsafe fn cpu_context_set_pc(ctx_ptr: *const u8, pc: usize);
52
53    /// # Safety
54    ///
55    ///
56    unsafe fn cpu_context_switch(prev_tcb: *mut u8, next_tcb: *mut u8);
57
58    fn wait_for_interrupt();
59
60    fn irq_init_current_cpu(id: DeviceId);
61
62    fn irq_ack() -> IrqId;
63    fn irq_eoi(irq: IrqId);
64
65    fn irq_all_enable();
66    fn irq_all_disable();
67    fn irq_all_is_enabled() -> bool;
68
69    fn irq_enable(config: IrqParam);
70    fn irq_disable(id: DeviceId, irq: IrqId);
71
72    fn shutdown() -> !;
73    fn debug_put(b: u8);
74
75    fn dcache_range(op: CacheOp, addr: usize, size: usize);
76
77    fn driver_registers() -> DriverRegisterSlice;
78}