aa64: finalise context switch, page fault handler and syscall
[lunaix-os.git] / lunaix-os / arch / aarch64 / fault.c
index e551d683d2d91c5f0d403549ce5d178ef37bc0a8..29f8e97195486260fa226cbdf0ee0087820c0e91 100644 (file)
@@ -1,9 +1,36 @@
 #include <lunaix/mm/fault.h>
 #include <asm/aa64_exception.h>
+#include <asm/aa64_msrs.h>
 #include <asm/hart.h>
 
+bool
+__arch_prepare_fault_context(struct fault_context* fault)
+{
+    struct hart_state* hs = fault->hstate;
+
+    ptr_t ptr = read_sysreg(FAR_EL1);
+    if (!ptr) {
+        return false;
+    }
+
+    fault->fault_ptep  = mkptep_va(VMS_SELF, ptr);
+    fault->fault_data  = esr_ec(hs->execp.syndrome);
+    fault->fault_instn = hart_pc(hs);
+    fault->fault_va    = ptr;
+
+    return true;
+}
+
 void 
 handle_mm_abort(struct hart_state* state)
 {
-    // TODO
+    struct fault_context fault;
+
+    __arch_prepare_fault_context(&fault);
+
+    if (!handle_page_fault(&fault)) {
+        fault_resolving_failed(&fault);
+    }
+
+    return;
 }
\ No newline at end of file