add basic exception model and context switching for aarch64
[lunaix-os.git] / lunaix-os / arch / aarch64 / exception / handler.c
diff --git a/lunaix-os/arch/aarch64/exception/handler.c b/lunaix-os/arch/aarch64/exception/handler.c
new file mode 100644 (file)
index 0000000..ab2b806
--- /dev/null
@@ -0,0 +1,27 @@
+#include <lunaix/process.h>
+#include <asm/hart.h>
+
+static inline void
+update_thread_context(struct hart_state* state)
+{
+    if (!current_thread) {
+        return;
+    }
+
+    struct hart_state* parent = current_thread->hstate;
+    hart_push_state(parent, state);
+    current_thread->hstate = state;
+
+    if (parent) {
+        state->depth = parent->depth + 1;
+    }
+}
+
+
+struct hart_state*
+handle_exception(struct hart_state* hstate)
+{
+    update_thread_context(hstate);
+
+    return hstate;
+}
\ No newline at end of file