Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / includes / lunaix / hart_state.h
diff --git a/lunaix-os/includes/lunaix/hart_state.h b/lunaix-os/includes/lunaix/hart_state.h
new file mode 100644 (file)
index 0000000..a9172bd
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef __LUNAIX_CONTEXT_H
+#define __LUNAIX_CONTEXT_H
+
+struct exec_param;
+struct regcontext;
+struct hart_state;
+
+#include <lunaix/compiler.h>
+#include <sys/hart.h>
+
+struct hart_transition 
+{
+    ptr_t inject;
+    struct {
+        struct hart_state state;
+        struct exec_param eret;
+    } compact transfer;
+};
+
+bool
+install_hart_transition(ptr_t vm_mnt, struct hart_transition* tctx);
+
+void
+hart_prepare_transition(struct hart_transition* tctx, 
+                      ptr_t kstack_tp, ptr_t ustack_pt, 
+                      ptr_t entry, bool to_user);
+
+static inline void
+hart_user_transfer(struct hart_transition* tctx, 
+                            ptr_t kstack_tp, ptr_t ustack_pt, 
+                            ptr_t entry) 
+{
+    hart_prepare_transition(tctx, kstack_tp, ustack_pt, entry, true);
+}
+
+static inline void
+hart_kernel_transfer(struct hart_transition* tctx, 
+                            ptr_t kstack_tp,  ptr_t entry) 
+{
+    hart_prepare_transition(tctx, kstack_tp, 0, entry, false);
+}
+
+#endif /* __LUNAIX_CONTEXT_H */