summaryrefslogtreecommitdiff
path: root/include/mercury/kernel/application.hpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-01-13 16:43:49 -0500
committerBenji Dial <benji@benjidial.net>2024-01-13 16:43:49 -0500
commit4130562b1555cabe441efe9420cebe12e7ed8d39 (patch)
treebeaf0012373aab2c3a13fe0147a5cda4af28ef78 /include/mercury/kernel/application.hpp
parent882e74b2191c059a9226cbd8bcb51c97da36247c (diff)
downloadhilbert-os-4130562b1555cabe441efe9420cebe12e7ed8d39.tar.gz
application loading
Diffstat (limited to 'include/mercury/kernel/application.hpp')
-rw-r--r--include/mercury/kernel/application.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/include/mercury/kernel/application.hpp b/include/mercury/kernel/application.hpp
new file mode 100644
index 0000000..bc4a763
--- /dev/null
+++ b/include/mercury/kernel/application.hpp
@@ -0,0 +1,72 @@
+#ifndef MERCURY_KERNEL_APPLICATION_HPP
+#define MERCURY_KERNEL_APPLICATION_HPP
+
+#include <mercury/kernel/vfile.hpp>
+#include <cstdint>
+
+namespace mercury::kernel::application {
+
+ enum class app_state {
+ running,
+ paused,
+ zombie
+ };
+
+ struct app_instance {
+
+ app_state state;
+
+ uint64_t *p4;
+ uint64_t *p3;
+ uint64_t *p2;
+
+ bool *p2es_to_free_on_exit;
+
+ uint64_t p4_paddr;
+
+ //set to 0 if none
+ uint64_t framebuffer_vaddr;
+
+ //only valid if state is zombie
+ int exit_code;
+
+ //only valid if state is paused
+ struct {
+ uint64_t rip;
+ uint64_t rsp;
+ //TODO: etc.
+ } saved_regs;
+
+ app_instance();
+ ~app_instance();
+
+ //2MiB page. vaddr and paddr must be aligned, and vaddr in valid range.
+ void map_page(uint64_t vaddr, uint64_t paddr,
+ bool write, bool execute, bool free_pram_on_exit);
+
+ //2MiB pages. returns start of first page.
+ uint64_t get_free_vaddr_pages(uint64_t count);
+
+ void create_stack();
+
+ void set_instruction_pointer(uint64_t vaddr);
+
+ //2MiB pages; only lower half.
+ uint64_t count_mapped_vram_pages();
+
+ };
+
+ extern app_instance *running_app;
+
+ enum class create_app_result {
+ success,
+ device_error,
+ app_corrupt,
+ fs_corrupt
+ };
+
+ create_app_result create_app(const vfile::vfile &file, app_instance *&out);
+
+}
+
+#endif