summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/sys/init.c
blob: 06fbe488cddecd5bb0defde027bbc873b0e3379d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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);
}