Only use offset mapping
This commit is contained in:
+3
-7
@@ -32,17 +32,13 @@ impl Arch for EmulateArch {
|
||||
const PHYS_OFFSET: usize = X8664Arch::PHYS_OFFSET;
|
||||
|
||||
unsafe fn init() -> &'static [MemoryArea] {
|
||||
// Create machine with PAGE_ENTRIES pages identity mapped (2 MiB on x86_64)
|
||||
// Pages over 1 MiB will be mapped writable
|
||||
// Create machine with PAGE_ENTRIES pages offset mapped (2 MiB on x86_64)
|
||||
let mut machine = Machine::new(MEMORY_SIZE);
|
||||
|
||||
// PML4 link to PDP
|
||||
// PML4 index 256 (PHYS_OFFSET) link to PDP
|
||||
let pml4 = 0;
|
||||
let pdp = pml4 + Self::PAGE_SIZE;
|
||||
let flags = Self::ENTRY_FLAG_WRITABLE | Self::ENTRY_FLAG_PRESENT;
|
||||
machine.write_phys::<usize>(PhysicalAddress::new(pml4), pdp | flags);
|
||||
|
||||
// PML4 index 256, set to PDP again for PHYS_OFFSET mapping
|
||||
machine.write_phys::<usize>(PhysicalAddress::new(pml4 + 256 * Self::PAGE_ENTRY_SIZE), pdp | flags);
|
||||
|
||||
// PDP link to PD
|
||||
@@ -102,7 +98,7 @@ const MEGABYTE: usize = 1024 * 1024;
|
||||
const MEMORY_SIZE: usize = 64 * MEGABYTE;
|
||||
static MEMORY_AREAS: [MemoryArea; 1] = [
|
||||
MemoryArea {
|
||||
base: PhysicalAddress::new(MEGABYTE),
|
||||
base: PhysicalAddress::new(EmulateArch::PAGE_SIZE * 4), // Initial PML4, PDP, PD, and PT wasted
|
||||
size: MEMORY_SIZE,
|
||||
}
|
||||
];
|
||||
|
||||
+11
-1
@@ -1,7 +1,9 @@
|
||||
use rmm::{
|
||||
Arch,
|
||||
EmulateArch,
|
||||
MemoryArea,
|
||||
PageTable,
|
||||
PhysicalAddress,
|
||||
VirtualAddress,
|
||||
};
|
||||
|
||||
@@ -23,13 +25,21 @@ unsafe fn dump_tables<A: Arch>(table: PageTable<A>) {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn new_tables<A: Arch>(areas: &[MemoryArea]) {
|
||||
|
||||
}
|
||||
|
||||
unsafe fn inner<A: Arch>() {
|
||||
let areas = A::init();
|
||||
|
||||
// Debug table
|
||||
dump_tables(PageTable::<A>::top());
|
||||
|
||||
let megabyte = VirtualAddress::new(0x100000);
|
||||
new_tables::<A>(areas);
|
||||
|
||||
dump_tables(PageTable::<A>::top());
|
||||
|
||||
let megabyte = A::phys_to_virt(PhysicalAddress::new(0x100000));
|
||||
|
||||
// Test read
|
||||
println!("0x{:X} = 0x{:X}", megabyte.data(), A::read::<u8>(megabyte));
|
||||
|
||||
Reference in New Issue
Block a user