fix: virt: lowlevel: test_device should translate address

This commit is contained in:
Paul Pan 2024-04-12 23:42:30 +08:00
parent 32759ef037
commit 3b02a14aeb
2 changed files with 19 additions and 3 deletions

View File

@ -1,16 +1,26 @@
use super::super::lowlevel::{ArchLL, ArchLLOps};
use super::TEST_DEVICE;
use crate::arch::layout::mmap_phys_to_virt;
use crate::arch::vspace::is_kernel_pagetable_installed;
unsafe fn get_qemu_test_device() -> *mut u32 {
if is_kernel_pagetable_installed() {
return mmap_phys_to_virt(TEST_DEVICE.into()).into();
} else {
return TEST_DEVICE;
}
}
impl ArchLLOps for ArchLL {
fn board_shutdown(failure: bool) {
if failure {
unsafe { TEST_DEVICE.write_volatile(0x0001_3333) }
unsafe { get_qemu_test_device().write_volatile(0x0001_3333) }
} else {
unsafe { TEST_DEVICE.write_volatile(0x0000_5555) }
unsafe { get_qemu_test_device().write_volatile(0x0000_5555) }
}
}
fn board_reset(_failure: bool) {
unsafe { TEST_DEVICE.write_volatile(0x0042_7777) }
unsafe { get_qemu_test_device().write_volatile(0x0042_7777) }
}
}

View File

@ -130,8 +130,14 @@ pub unsafe fn map(from: VirtAddr, to: PhysAddr, size: usize, attr: MapAttr) {
map_range(pt, from, to, size, attr).expect("Failed to map memory");
}
#[inline]
pub fn is_kernel_pagetable_installed() -> bool {
KERNEL_PAGETABLE.lock().is_some()
}
pub unsafe fn setup_kernel_paging() {
info!("Setting up kernel paging");
assert!(!is_kernel_pagetable_installed(), "Kernel pagetable already installed");
let root_pt = alloc_page();
let kernel_pt = Table::new(root_pt.as_usize().into());