1 #include <lunaix/mm/pagetable.h>
2 #include <lunaix/sections.h>
4 #include <asm/boot_stage.h>
5 #include <asm/mm_defs.h>
6 #include <asm-generic/init_pagetable.h>
9 kpt_alloc_table(struct pt_alloc* alloc)
11 if (alloc->index >= alloc->total) {
17 next = alloc->base + alloc->index * PAGE_SIZE;
24 __walk(struct ptw_state* state, ptr_t addr,
25 unsigned long level_size, bool create)
36 lsize = lnt_page_size(level);
37 pt_index = va_level_index(addr, lsize);
40 if (!pte_isnull(pte)) {
41 next_level = pte_paddr(pte);
45 if (pt_last_level(level) || lsize == level_size) {
53 next_level = kpt_alloc_table(state->alloc);
59 pte = mkpte(next_level, KERNEL_PGTAB);
63 pt = (pte_t*) next_level;
66 while (lsize > level_size);
70 state->tab_index = pt_index;
79 unsigned int boot_text
80 kpt_set_ptes_flatten(struct ptw_state* state, ptr_t addr,
81 pte_t pte, unsigned long lsize, unsigned int nr)
83 unsigned int tab_i, _n;
87 addr = addr & ~(lsize - 1);
90 if (!__walk(state, addr, lsize, true)) {
95 tab_i = state->tab_index;
96 while (_n < nr && tab_i < LEVEL_SIZE) {
98 pte = pte_advance(pte, lsize);
109 #define ksection_maps autogen_name(ksecmap)
113 extern_autogen(ksecmap);
115 bridge_farsym(__kexec_text_start);
116 bridge_farsym(ksection_maps);
119 kpt_migrate_highmem(struct ptw_state* state)
122 struct ksecmap* maps;
123 struct ksection* section;
126 maps = (struct ksecmap*)to_kphysical(__far(ksection_maps));
128 for (unsigned int i = 0; i < maps->num; i++)
130 section = &maps->secs[i];
132 if (section->va < KERNEL_RESIDENT) {
136 pte = mkpte(section->pa, KERNEL_RDONLY);
137 if ((section->flags & PF_X)) {
138 pte = pte_mkexec(pte);
140 if ((section->flags & PF_W)) {
141 pte = pte_mkwritable(pte);
144 pgs = leaf_count(section->size);
145 kpt_set_ptes(state, section->va, pte, LFT_SIZE, pgs);