From 4bc10176c9f47063d8eddf8703832304b8151f5d Mon Sep 17 00:00:00 2001 From: Lunaixsky Date: Tue, 1 Oct 2024 23:13:31 +0100 Subject: [PATCH] add kernel highmem remap for aarch64 and some clean-ups --- lunaix-os/arch/aarch64/boot/init.h | 5 +-- lunaix-os/arch/aarch64/boot/kremap.c | 35 +++++++++++++++++++ lunaix-os/arch/aarch64/boot/mem.c | 32 ----------------- lunaix-os/arch/aarch64/boot/start.S | 4 +-- .../arch/aarch64/includes/asm/boot_stage.h | 6 ++++ 5 files changed, 44 insertions(+), 38 deletions(-) delete mode 100644 lunaix-os/arch/aarch64/boot/mem.c create mode 100644 lunaix-os/arch/aarch64/includes/asm/boot_stage.h diff --git a/lunaix-os/arch/aarch64/boot/init.h b/lunaix-os/arch/aarch64/boot/init.h index 4593759..5357779 100644 --- a/lunaix-os/arch/aarch64/boot/init.h +++ b/lunaix-os/arch/aarch64/boot/init.h @@ -3,10 +3,7 @@ #include #include - -#define boot_text __attribute__((section(".boot.text"))) -#define boot_data __attribute__((section(".boot.data"))) -#define boot_bss __attribute__((section(".boot.bss"))) +#include ptr_t kremap(); diff --git a/lunaix-os/arch/aarch64/boot/kremap.c b/lunaix-os/arch/aarch64/boot/kremap.c index e69de29..a230ece 100644 --- a/lunaix-os/arch/aarch64/boot/kremap.c +++ b/lunaix-os/arch/aarch64/boot/kremap.c @@ -0,0 +1,35 @@ +#include +#include +#include + +#include "init.h" + +static pte_t kpt[LEVEL_SIZE][32]; + +ptr_t +kremap() +{ + struct pt_alloc alloc; + struct ptw_state ptw; + pte_t pte; + unsigned long nr; + + init_pt_alloc(&alloc, to_kphysical(&kpt), sizeof(kpt)); + init_ptw_state(&ptw, &alloc, kpt_alloc_table(&alloc)); + + pte = mkpte(boot_start, KERNEL_DATA); + pte = pte_mkexec(pte); + nr = leaf_count(boot_end - boot_start); + kpt_set_ptes(&ptw, boot_start, pte, LFT_SIZE, nr); + + kpt_mktable_at(&ptw, VMAP, L0T_SIZE); + kpt_mktable_at(&ptw, PMAP, L2T_SIZE); + kpt_mktable_at(&ptw, KMAP, LFT_SIZE); + + kpt_migrate_highmem(&ptw); + + pte = mkpte(__ptr(ptw.root), KERNEL_PGTAB); + kpt_set_ptes(&ptw, VMS_SELF, pte, L0T_SIZE, 1); + + return __ptr(ptw.root); +} \ No newline at end of file diff --git a/lunaix-os/arch/aarch64/boot/mem.c b/lunaix-os/arch/aarch64/boot/mem.c deleted file mode 100644 index 1803e2a..0000000 --- a/lunaix-os/arch/aarch64/boot/mem.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "init.h" -#include -#include - -#define BOOTMEM_SIZE (4 * 4096) - -static reclaimable char bootmem_pool[BOOTMEM_SIZE]; -static unsigned int pos; - -void* -bootmem_alloc(unsigned int size) -{ - ptr_t res; - - res = __ptr(bootmem_pool) + pos; - - size = ROUNDUP(size, 4); - pos += size; - - if (pos >= BOOTMEM_SIZE) { - spin(); - } - - return (void*)res; -} - -void -bootmem_free(void* ptr) -{ - // not need to support, as they are all one-shot - return; -} \ No newline at end of file diff --git a/lunaix-os/arch/aarch64/boot/start.S b/lunaix-os/arch/aarch64/boot/start.S index ed11af9..f2aa88a 100644 --- a/lunaix-os/arch/aarch64/boot/start.S +++ b/lunaix-os/arch/aarch64/boot/start.S @@ -19,8 +19,8 @@ mov fp, xzr ldr x4, =aarch64_init - blx x4 + bl x4 // x0: ptr to boot_handoff ldr x4, =kernel_bootstrap - blx x4 \ No newline at end of file + bl x4 \ No newline at end of file diff --git a/lunaix-os/arch/aarch64/includes/asm/boot_stage.h b/lunaix-os/arch/aarch64/includes/asm/boot_stage.h new file mode 100644 index 0000000..46bcec2 --- /dev/null +++ b/lunaix-os/arch/aarch64/includes/asm/boot_stage.h @@ -0,0 +1,6 @@ +#ifndef __LUNAIX_ARCH_BOOT_STAGE_H +#define __LUNAIX_ARCH_BOOT_STAGE_H + +#include + +#endif /* __LUNAIX_BOOT_STAGE_H */ -- 2.27.0