Skip to content

Commit 12c1679

Browse files
committed
main: Get address_space_gib from linker
We can just get the address_space_gib symbol from the linker, which lets us avoid the need for a separate ADDRESS_SPACE_GIB constant. Signed-off-by: Joe Richey <joerichey@google.com>
1 parent a0f8c87 commit 12c1679

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,24 @@ fn panic(info: &PanicInfo) -> ! {
5353

5454
/// Setup page tables to provide an identity mapping over the full 4GiB range
5555
fn setup_pagetables() {
56-
const ADDRESS_SPACE_GIB: u64 = 4;
5756
type PageTable = [u64; 512];
5857

5958
extern "C" {
6059
static pml3t: PageTable;
61-
static pml2t: [PageTable; ADDRESS_SPACE_GIB as usize];
60+
static pml2t: PageTable;
61+
static address_space_gib: u8;
6262
}
63+
let num_gib = unsafe { &address_space_gib } as *const _ as usize as u64;
64+
log!("Setting up {} GiB identity mapping", num_gib);
6365

64-
let pte = mem::MemoryRegion::from_slice(unsafe { &pml2t });
65-
for i in 0..(512 * ADDRESS_SPACE_GIB) {
66+
let pml2t_addr = unsafe { pml2t.as_ptr() } as usize as u64;
67+
let pte = mem::MemoryRegion::new(pml2t_addr, num_gib * 4096);
68+
for i in 0..(512 * num_gib) {
6669
pte.io_write_u64(i * 8, (i << 21) + 0x83u64)
6770
}
6871

69-
let pml2t_addr = unsafe { pml2t.as_ptr() } as usize as u64;
7072
let pde = mem::MemoryRegion::from_slice(unsafe { &pml3t });
71-
for i in 0..ADDRESS_SPACE_GIB {
73+
for i in 0..num_gib {
7274
pde.io_write_u64(i * 8, (pml2t_addr + (0x1000u64 * i)) | 0x03);
7375
}
7476

0 commit comments

Comments
 (0)