aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/paging/fault.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86_64/paging/fault.rs')
-rw-r--r--src/arch/x86_64/paging/fault.rs33
1 files changed, 33 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;
+}