use loongArch64::register::{crmd, stlbps, tlbidx, tlbrehi, tlbrentry};
use memory_addr::PhysAddr;
use page_table_multiarch::loongarch64::LA64MetaData;
pub fn init_mmu(root_paddr: PhysAddr, phys_virt_offset: usize) {
unsafe extern "C" {
fn handle_tlb_refill();
}
const PS_4K: usize = 0x0c; let tlbrentry_paddr = pa!(handle_tlb_refill as *const () as usize - phys_virt_offset);
tlbidx::set_ps(PS_4K);
stlbps::set_ps(PS_4K);
tlbrehi::set_ps(PS_4K);
tlbrentry::set_tlbrentry(tlbrentry_paddr.as_usize());
unsafe {
crate::asm::write_pwc(LA64MetaData::PWCL_VALUE, LA64MetaData::PWCH_VALUE);
crate::asm::write_kernel_page_table(root_paddr);
crate::asm::write_user_page_table(pa!(0));
}
crate::asm::flush_tlb(None);
crmd::set_pg(true);
}
pub fn init_trap() {
unsafe extern "C" {
fn exception_entry_base();
}
unsafe {
crate::asm::write_exception_entry_base(exception_entry_base as *const () as usize);
}
}