summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/sys/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/sys/init.c')
-rw-r--r--arch/x86_64/sys/init.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/arch/x86_64/sys/init.c b/arch/x86_64/sys/init.c
new file mode 100644
index 0000000..06fbe48
--- /dev/null
+++ b/arch/x86_64/sys/init.c
@@ -0,0 +1,53 @@
+#include "init.h"
+#include "config.h"
+#include "jove.h"
+#include "hal/obj.h"
+#include "lib/string.h"
+#include "lib/panic.h"
+#include "arch/x86_64/hal/paging.h"
+#include "boot/cmdline.h"
+#include "boot/initrd.h"
+
+#define INIT_PROGRAM_HUGEPAGES_MAX ((INIT_PROGRAM_PAGES_MAX + 511) / 512)
+#define INIT_STACK_HUGEPAGES_MAX ((INIT_STACK_PAGES_MAX + 511) / 512)
+
+PAGEALIGN static page_t s_init_program_pml3[512];
+PAGEALIGN static page_t s_init_program_pml2[512];
+PAGEALIGN static page_t s_init_program_pml1[INIT_PROGRAM_HUGEPAGES_MAX][512];
+
+PAGEALIGN static page_t s_init_stack_pml3[512];
+PAGEALIGN static page_t s_init_stack_pml2[512];
+PAGEALIGN static page_t s_init_stack_pml1[INIT_STACK_HUGEPAGES_MAX][512];
+
+void
+init_setup(void)
+{
+ memset(s_init_program_pml3, 0, 0x1000);
+ memset(s_init_program_pml2, 0, 0x1000);
+ memset(s_init_program_pml1, 0, 0x1000 * INIT_PROGRAM_HUGEPAGES_MAX);
+
+ memset(s_init_stack_pml3, 0, 0x1000);
+ memset(s_init_stack_pml2, 0, 0x1000);
+ memset(s_init_stack_pml1, 0, 0x1000 * INIT_STACK_HUGEPAGES_MAX);
+
+ uintptr_t init_program_pml3_pptr = KPTR_TOPHYS(s_init_program_pml3);
+ uintptr_t init_program_pml2_pptr = KPTR_TOPHYS(s_init_program_pml2);
+ uintptr_t init_program_pml1_pptr = KPTR_TOPHYS(s_init_program_pml1);
+
+ uintptr_t init_stack_pml3_pptr = KPTR_TOPHYS(s_init_stack_pml3);
+ uintptr_t init_stack_pml2_pptr = KPTR_TOPHYS(s_init_stack_pml2);
+ uintptr_t init_stack_pml1_pptr = KPTR_TOPHYS(s_init_stack_pml1);
+
+ //Get the init file data from the initrd.
+ const char *init_path = cmdline_getarg("init");
+ if(init_path == NULL) {
+ kpanic("Kernel commandline is missing 'init' arg.\n");
+ }
+
+ jove_owned_obj_t *initrd_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_INITRD_I));
+ jove_owned_obj_t *initfile_obj = initrd_seek(initrd_obj, init_path);
+ if(initfile_obj == NULL) {
+ kpanic("init: Cannot find file '%s' in initrd.\n", init_path);
+ }
+ obj_release(initrd_obj);
+}