Boot framework rework (#45)
[lunaix-os.git] / lunaix-os / arch / x86 / boot / boot_helper.c
1 #include <lunaix/boot_generic.h>
2 #include <lunaix/mm/pagetable.h>
3 #include <lunaix/mm/pmm.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/sections.h>
6 #include <lunaix/generic/bootmem.h>
7
8 #include <sys/mm/mm_defs.h>
9 #include <sys/boot/bstage.h>
10
11 #ifdef CONFIG_ARCH_X86_64
12
13 void
14 boot_begin_arch_reserve(struct boot_handoff* bhctx)
15 {
16     return;
17 }
18
19
20 void
21 boot_clean_arch_reserve(struct boot_handoff* bhctx)
22 {
23     pfn_t start;
24
25     start = leaf_count(__ptr(__kboot_start));
26     pmm_unhold_range(start, leaf_count(__ptr(__kboot_end)) - start);
27 }
28
29 #else
30
31 #include <lunaix/mm/vmm.h>
32
33 void
34 boot_begin_arch_reserve(struct boot_handoff* bhctx)
35 {
36     // Identity-map the first 3GiB address spaces
37     pte_t* ptep  = mkl0tep(mkptep_va(VMS_SELF, 0));
38     pte_t pte    = mkpte_prot(KERNEL_DATA);
39     size_t count = page_count(KERNEL_RESIDENT, L0T_SIZE);
40
41     vmm_set_ptes_contig(ptep, pte_mkhuge(pte), L0T_SIZE, count);
42 }
43
44
45 void
46 boot_clean_arch_reserve(struct boot_handoff* bhctx)
47 {
48     pte_t* ptep  = mkl0tep(mkptep_va(VMS_SELF, 0));
49     size_t count = page_count(KERNEL_RESIDENT, L0T_SIZE);
50     vmm_unset_ptes(ptep, count);
51 }
52
53 #endif
54
55 extern void
56 mb_parse(struct boot_handoff* bhctx);
57
58 struct boot_handoff*
59 prepare_boot_handover()
60 {
61     struct boot_handoff* handoff;
62
63     handoff = bootmem_alloc(sizeof(*handoff));
64
65     mb_parse(handoff);
66
67     return handoff;
68 }