mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-17 04:32:27 +00:00
Refactor and reorganize project structure
This commit is contained in:
17
src/aarch64/mmu.rs
Normal file
17
src/aarch64/mmu.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use core::arch::asm;
|
||||
|
||||
pub fn init_mmu() {
|
||||
let ips = 0b000 << 32;
|
||||
|
||||
// 4KB granularity
|
||||
let tg0 = 0b00 << 14;
|
||||
let tg1 = 0b00 << 30;
|
||||
|
||||
//64-25 = 29 bits of VA
|
||||
// FFFF_FF80_0000_0000 start address
|
||||
let t0sz = 25;
|
||||
|
||||
let tcr_el1: u64 = ips | tg0 | tg1 | t0sz;
|
||||
|
||||
unsafe { asm!("msr TCR_EL1, {0:x}", in(reg) tcr_el1) };
|
||||
}
|
||||
2
src/aarch64/mod.rs
Normal file
2
src/aarch64/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod mmu;
|
||||
pub mod registers;
|
||||
57
src/aarch64/registers.rs
Normal file
57
src/aarch64/registers.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use core::arch::asm;
|
||||
|
||||
pub mod daif {
|
||||
use core::arch::asm;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn mask_all() {
|
||||
unsafe { asm!("msr DAIFSet, #0xf", options(nomem, nostack)) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unmask_all() {
|
||||
unsafe { asm!("msr DAIFClr, #0xf", options(nomem, nostack)) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn mask_irq() {
|
||||
unsafe { asm!("msr DAIFSet, #0x2", options(nomem, nostack)) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unmask_irq() {
|
||||
unsafe { asm!("msr DAIFClr, #0x2", options(nomem, nostack)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! psr {
|
||||
($name:ident, $t:tt) => {
|
||||
paste::item! {
|
||||
pub fn [<read_ $name:lower>]() -> $t {
|
||||
let buf: $t;
|
||||
unsafe {
|
||||
asm!(
|
||||
concat!("mrs {0:x}, ", stringify!($name)),
|
||||
out(reg) buf
|
||||
);
|
||||
}
|
||||
buf
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
psr!(TCR_EL1, u64);
|
||||
|
||||
psr!(ID_AA64MMFR0_EL1, u64);
|
||||
|
||||
psr!(ESR_EL1, u32);
|
||||
|
||||
psr!(SPSR_EL1, u32);
|
||||
|
||||
psr!(ELR_EL1, u32);
|
||||
|
||||
pub fn read_exception_source_el() -> u32 {
|
||||
read_spsr_el1() & 0b1111
|
||||
}
|
||||
Reference in New Issue
Block a user