2024-02-05 13:44:21 +02:00
|
|
|
#![no_std]
|
2024-02-06 12:27:02 +02:00
|
|
|
#![feature(effects, strict_provenance)]
|
2024-02-05 13:44:21 +02:00
|
|
|
|
|
|
|
use kernel_arch_interface::Architecture;
|
|
|
|
|
2024-02-06 12:27:02 +02:00
|
|
|
pub mod mem;
|
|
|
|
pub mod registers;
|
|
|
|
|
|
|
|
pub use mem::KernelTableManagerImpl;
|
|
|
|
|
2024-02-05 13:44:21 +02:00
|
|
|
pub struct ArchitectureImpl;
|
|
|
|
|
2024-02-06 12:27:02 +02:00
|
|
|
pub const KERNEL_VIRT_OFFSET: usize = 0xFFFFFF8000000000;
|
|
|
|
|
2024-02-05 13:44:21 +02:00
|
|
|
impl Architecture for ArchitectureImpl {
|
|
|
|
fn interrupt_mask() -> bool {
|
|
|
|
let mut flags: u64;
|
|
|
|
unsafe {
|
|
|
|
core::arch::asm!("pushfq; pop {0}", out(reg) flags, options(att_syntax));
|
|
|
|
}
|
|
|
|
// If IF is zero, interrupts are disabled (masked)
|
|
|
|
flags & (1 << 9) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn set_interrupt_mask(mask: bool) -> bool {
|
|
|
|
let old = Self::interrupt_mask();
|
|
|
|
if mask {
|
|
|
|
core::arch::asm!("cli");
|
|
|
|
} else {
|
|
|
|
core::arch::asm!("sti");
|
|
|
|
}
|
|
|
|
old
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn wait_for_interrupt() {
|
|
|
|
unsafe {
|
|
|
|
core::arch::asm!("hlt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|