From 7fd8d36281de9c2d6e8012b60c35d4d3ac4654d0 Mon Sep 17 00:00:00 2001 From: Ry Date: Mon, 15 Aug 2022 19:43:28 -0700 Subject: [PATCH] Actually implement paging properly, bump version to 0.3.1 I was mixing up the virtual and physical addresses, oops --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/memory.rs | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d40624..e6a24ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -865,7 +865,7 @@ dependencies = [ [[package]] name = "fox32" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "image", diff --git a/Cargo.toml b/Cargo.toml index dae7269..452ed07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fox32" -version = "0.3.0" +version = "0.3.1" authors = ["ry"] edition = "2021" build = "build.rs" diff --git a/src/memory.rs b/src/memory.rs index ba6fc75..023b4ba 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,5 +1,7 @@ // memory.rs +const DEBUG: bool = false; + use crate::error; use crate::cpu::Exception; @@ -115,17 +117,18 @@ impl Memory { let table_rw = table & 0b10 != 0; let table_address = table & 0xFFFFF000; - let tlb_entry = MemoryPage { - //physical_address: (((directory_index + 1) * (table_index + 1) * 4096) - 4096), - physical_address: (directory_index << 22) | (table_index << 12), - present: table_present, - rw: table_rw, - }; - self.tlb().entry(table_address).or_insert(tlb_entry); + if table_present { + let tlb_entry = MemoryPage { + physical_address: table_address, + present: table_present, + rw: table_rw, + }; + self.tlb().entry((directory_index << 22) | (table_index << 12)).or_insert(tlb_entry); + } } } } - println!("{:#X?}", self.tlb()); + if DEBUG { println!("{:#X?}", self.tlb()); } } pub fn virtual_to_physical(&self, virtual_address: u32) -> Option<(u32, bool)> {