aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/paging
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86_64/paging')
-rw-r--r--src/arch/x86_64/paging/fault.rs33
-rw-r--r--src/arch/x86_64/paging/mod.rs6
2 files changed, 39 insertions, 0 deletions
diff --git a/src/arch/x86_64/paging/fault.rs b/src/arch/x86_64/paging/fault.rs
new file mode 100644
index 0000000..7b27649
--- /dev/null
+++ b/src/arch/x86_64/paging/fault.rs
@@ -0,0 +1,33 @@
+use crate::arch::x86_64::arch_regs::TrapFrame;
+use crate::io::*;
+use core::arch::asm;
+
+/// handle page fault: for now we only check if the faulting addr is within
+/// kernel heap range.
+/// TODO: improve this later
+pub fn page_fault_handler(frame: &mut TrapFrame, fault_addr: u64) {
+ let err_code = frame.err_code;
+ println!("pagefault @ {:#X}, err {:#X?}", fault_addr, err_code);
+ unsafe { asm!("hlt") };
+}
+
+/// for x86_64, return the CR3 register.
+/// TODO: use page root in task struct instead of raw cr3
+#[inline]
+pub fn get_root() -> u64 {
+ let cr3: u64;
+ unsafe {
+ asm!("mov {}, cr3", out(reg) cr3);
+ }
+ return cr3;
+}
+
+/// for x86_64, return the CR3 register.
+#[inline]
+pub fn get_fault_addr() -> u64 {
+ let cr2: u64;
+ unsafe {
+ asm!("mov {}, cr2", out(reg) cr2);
+ }
+ return cr2;
+}
diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs
index ab93938..257b7b3 100644
--- a/src/arch/x86_64/paging/mod.rs
+++ b/src/arch/x86_64/paging/mod.rs
@@ -1,6 +1,7 @@
// code derived from the x86_64 crate
// https://docs.rs/x86_64/latest/src/x86_64/addr.rs.html
// see ATTRIBUTIONS
+pub mod fault;
use crate::defs::*;
use bitflags::bitflags;
#[repr(align(4096))]
@@ -98,6 +99,11 @@ impl Pagetable {
pub fn is_empty(&self) -> bool {
self.iter().all(|entry| entry.is_unused())
}
+
+ /// walk the page table, create missing tables, return mapped physical frame
+ pub fn map_page(&self, _va: VAddr) {
+ todo!()
+ }
}
impl VAddr {