X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/28c176b668c841a3b7fb093faccf0efa39257603..9daf4fcdae88f72af60aeb0c7722841af02233d4:/lunaix-os/arch/x86/mm/pmm.c diff --git a/lunaix-os/arch/x86/mm/pmm.c b/lunaix-os/arch/x86/mm/pmm.c index aa35b86..73f9fb1 100644 --- a/lunaix-os/arch/x86/mm/pmm.c +++ b/lunaix-os/arch/x86/mm/pmm.c @@ -1,7 +1,6 @@ #include #include - -extern unsigned int __kexec_end[]; +#include void pmm_arch_init_pool(struct pmem* memory) @@ -12,13 +11,15 @@ pmm_arch_init_pool(struct pmem* memory) ptr_t pmm_arch_init_remap(struct pmem* memory, struct boot_handoff* bctx) { - size_t ppfn_total = pfn(bctx->mem.size) + 1; + size_t ppfn_total = pfn(bctx->mem.size); size_t pool_size = ppfn_total * sizeof(struct ppage); size_t i = 0; struct boot_mmapent* ent; - for (; i < bctx->mem.mmap_len; i++) { - ent = &bctx->mem.mmap[i]; + +restart:; + while (i < bctx->mem.mmap_len) { + ent = &bctx->mem.mmap[i++]; if (free_memregion(ent) && ent->size > pool_size) { goto found; } @@ -28,7 +29,7 @@ pmm_arch_init_remap(struct pmem* memory, struct boot_handoff* bctx) return 0; found:; - ptr_t kexec_end = to_kphysical(__kexec_end); + ptr_t kexec_end = to_kphysical(kernel_start); ptr_t aligned_pplist = MAX(ent->start, kexec_end); #ifdef CONFIG_ARCH_X86_64 @@ -38,7 +39,7 @@ found:; #endif if (aligned_pplist + pool_size > ent->start + ent->size) { - return 0; + goto restart; } // for x86_32, the upper bound of memory requirement for pplist