add kernel highmem remap for aarch64 and some clean-ups
[lunaix-os.git] / lunaix-os / arch / aarch64 / boot / kremap.c
1 #include <lunaix/sections.h>
2 #include <asm-generic/init_pagetable.h>
3 #include <asm/boot_stage.h>
4
5 #include "init.h"
6
7 static pte_t kpt[LEVEL_SIZE][32];
8
9 ptr_t
10 kremap()
11 {
12     struct pt_alloc alloc;
13     struct ptw_state ptw;
14     pte_t pte;
15     unsigned long nr;
16
17     init_pt_alloc(&alloc, to_kphysical(&kpt), sizeof(kpt));
18     init_ptw_state(&ptw, &alloc, kpt_alloc_table(&alloc));
19
20     pte = mkpte(boot_start, KERNEL_DATA);
21     pte = pte_mkexec(pte);
22     nr  = leaf_count(boot_end - boot_start);
23     kpt_set_ptes(&ptw, boot_start, pte, LFT_SIZE, nr);
24
25     kpt_mktable_at(&ptw, VMAP, L0T_SIZE);
26     kpt_mktable_at(&ptw, PMAP, L2T_SIZE);
27     kpt_mktable_at(&ptw, KMAP, LFT_SIZE);
28
29     kpt_migrate_highmem(&ptw);
30
31     pte = mkpte(__ptr(ptw.root), KERNEL_PGTAB);
32     kpt_set_ptes(&ptw, VMS_SELF, pte, L0T_SIZE, 1);
33
34     return __ptr(ptw.root);
35 }