Code-base clean-up and refactoring (#47)
[lunaix-os.git] / lunaix-os / arch / x86 / mm / fault.c
index 62f9d8088ed2c60f1afbf877541ff72ffc914f2f..899fe2f8ff17689d805b2f672a629fe5d7c3f159 100644 (file)
@@ -1,10 +1,6 @@
 #include <lunaix/mm/fault.h>
-#include <lunaix/mm/region.h>
-#include <lunaix/process.h>
 #include <lunaix/hart_state.h>
 
-#include <sys/mm/mm_defs.h>
-
 bool
 __arch_prepare_fault_context(struct fault_context* fault)
 {
@@ -21,4 +17,30 @@ __arch_prepare_fault_context(struct fault_context* fault)
     fault->fault_va    = ptr;
 
     return true;
+}
+
+
+void
+intr_routine_page_fault(const struct hart_state* hstate)
+{
+    if (hstate->depth > 10) {
+        // Too many nested fault! we must messed up something
+        // XXX should we failed silently?
+        spin();
+    }
+
+    struct fault_context fault = { .hstate = hstate };
+
+    if (!__arch_prepare_fault_context(&fault)) {
+        goto failed;
+    }
+
+    if (!handle_page_fault(&fault)) {
+        goto failed;
+    }
+
+    return;
+
+failed:
+    fault_resolving_failed(&fault);
 }
\ No newline at end of file