From ca2485429c19d3e5cdecbb39a5f3383b40477d94 Mon Sep 17 00:00:00 2001 From: Lunaixsky Date: Sun, 26 Jan 2025 03:18:11 +0000 Subject: [PATCH 1/1] physical page list mapping --- lunaix-os/arch/aarch64/vmutils.c | 60 +++++++++++++++++++++++----- lunaix-os/includes/lunaix/sections.h | 3 +- lunaix-os/kernel/boot_helper.c | 2 +- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/lunaix-os/arch/aarch64/vmutils.c b/lunaix-os/arch/aarch64/vmutils.c index aef8c4c..405a32b 100644 --- a/lunaix-os/arch/aarch64/vmutils.c +++ b/lunaix-os/arch/aarch64/vmutils.c @@ -1,18 +1,19 @@ #include #include +#include -struct leaflet* -dup_leaflet(struct leaflet* leaflet) +struct leaflet * +dup_leaflet(struct leaflet *leaflet) { ptr_t dest_va, src_va; - struct leaflet* new_leaflet; - + struct leaflet *new_leaflet; + new_leaflet = alloc_leaflet(leaflet_order(leaflet)); src_va = leaflet_mount(leaflet); dest_va = vmap(new_leaflet, KERNEL_DATA); - memcpy((void*)dest_va, (void*)src_va, PAGE_SIZE); + memcpy((void *)dest_va, (void *)src_va, PAGE_SIZE); leaflet_unmount(leaflet); vunmap(dest_va, new_leaflet); @@ -20,14 +21,51 @@ dup_leaflet(struct leaflet* leaflet) return new_leaflet; } -ptr_t -pmm_arch_init_remap(struct pmem* memory, struct boot_handoff* bctx) +static inline struct ppage* +__setup_pmem_map(ptr_t start, size_t plist_size) { - unsigned long plist_len; + pte_t pte, *ptep; + unsigned int nr_pages; + + pte = mkpte(start, KERNEL_DATA); + ptep = mkl2tep_va(VMS_SELF, PMAP); + nr_pages = page_count(plist_size, L2T_SIZE); + + vmm_set_ptes_contig(ptep, pte, L2T_SIZE, nr_pages); - plist_len = leaf_count(bctx->mem.size) * sizeof(struct ppage); + return (struct ppage*)PMAP; +} + +ptr_t +pmm_arch_init_remap(struct pmem *memory, struct boot_handoff *bctx) +{ + unsigned long plist_len, plist_size, nr_huges; + struct boot_mmapent *ment; - for (int i = 0; i < bctx->mem.mmap_len; i++) { - + plist_len = leaf_count(bctx->mem.size); + plist_size = plist_len * sizeof(struct ppage); + nr_huges = page_count(plist_size, lnt_page_size(2)); + + ptr_t pkernel_end = to_kphysical(kernel_end); + pkernel_end = napot_upaligned(pkernel_end, L2T_SIZE); + pkernel_end += plist_size; + + for (int i = 0; i < bctx->mem.mmap_len; i++) + { + ment = &bctx->mem.mmap[i]; + if (ment->type != BOOT_MMAP_FREE) { + continue; + } + + if (pkernel_end >= ment->start + ment->size) { + continue; + } + + memory->pplist = __setup_pmem_map(pkernel_end, plist_size);; + memory->list_len = plist_len; + return pkernel_end; } + + fail("no_mem, unable to map plist"); + return NULL; } diff --git a/lunaix-os/includes/lunaix/sections.h b/lunaix-os/includes/lunaix/sections.h index 9290178..72f5855 100644 --- a/lunaix-os/includes/lunaix/sections.h +++ b/lunaix-os/includes/lunaix/sections.h @@ -31,7 +31,8 @@ #define bootsec_end __section_mark(kboot, end) #define kernel_start __section_mark(kexec, start) -#define kernel_load_end __section_mark(kexec, end) +#define kernel_load_start __section_mark(kload, start) +#define kernel_load_end __section_mark(kload, end) #define kernel_end __section_mark(kimg, end) #ifdef CONFIG_USE_DEVICETREE diff --git a/lunaix-os/kernel/boot_helper.c b/lunaix-os/kernel/boot_helper.c index 37e6bb4..99977bc 100644 --- a/lunaix-os/kernel/boot_helper.c +++ b/lunaix-os/kernel/boot_helper.c @@ -20,7 +20,7 @@ boot_begin(struct boot_handoff* bhctx) boot_begin_arch_reserve(bhctx); // 将内核占据的页,包括前1MB,hhk_init 设为已占用 - size_t pg_count = leaf_count(to_kphysical(kernel_load_end)); + size_t pg_count = leaf_count(to_kphysical(kernel_end)); pmm_onhold_range(0, pg_count); size_t i; -- 2.27.0