From 9ae0bcefc961fd1d6d67aba17fbaf835580e45ed Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 2 Nov 2022 15:28:07 +0100 Subject: [PATCH] Revert "smp/x86: Free up trampoline memory after use" This reverts commit ae771dd8a19aeb3f8ba5b310dc454b668b94403a. --- common/sys/smp.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/common/sys/smp.c b/common/sys/smp.c index 2d9f9604..5d709a03 100644 --- a/common/sys/smp.c +++ b/common/sys/smp.c @@ -64,8 +64,6 @@ struct madt_gicc { uint16_t spe_overflow_gsiv; } __attribute__((packed)); -static void *trampoline = NULL; - #if defined (__x86_64__) || defined (__i386__) struct trampoline_passed_info { @@ -81,6 +79,14 @@ static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr, struct limine_smp_info *info_struct, bool longmode, bool lv5, uint32_t pagemap, bool x2apic, bool nx, uint64_t hhdm, bool wp) { + // Prepare the trampoline + static void *trampoline = NULL; + if (trampoline == NULL) { + trampoline = conv_mem_alloc(smp_trampoline_size); + + memcpy(trampoline, smp_trampoline_start, smp_trampoline_size); + } + static struct trampoline_passed_info *passed_info = NULL; if (passed_info == NULL) { passed_info = (void *)(((uintptr_t)trampoline + smp_trampoline_size) @@ -211,14 +217,6 @@ struct limine_smp_info *init_smp(size_t *cpu_count, *cpu_count = 0; // Try to start all APs - - // Prepare the trampoline - if (trampoline == NULL) { - trampoline = conv_mem_alloc(smp_trampoline_size); - - memcpy(trampoline, smp_trampoline_start, smp_trampoline_size); - } - for (uint8_t *madt_ptr = (uint8_t *)madt->madt_entries_begin; (uintptr_t)madt_ptr < (uintptr_t)madt + madt->header.length; madt_ptr += *(madt_ptr + 1)) { @@ -297,10 +295,6 @@ struct limine_smp_info *init_smp(size_t *cpu_count, } } - if (trampoline != NULL) { - pmm_free(trampoline, smp_trampoline_size); - } - return ret; } @@ -332,6 +326,14 @@ static bool try_start_ap(int boot_method, uint64_t method_ptr, struct limine_smp_info *info_struct, uint64_t ttbr0, uint64_t ttbr1, uint64_t mair, uint64_t tcr, uint64_t sctlr) { + // Prepare the trampoline + static void *trampoline = NULL; + if (trampoline == NULL) { + trampoline = ext_mem_alloc(0x1000); + + memcpy(trampoline, smp_trampoline_start, smp_trampoline_size); + } + static struct trampoline_passed_info *passed_info = NULL; if (passed_info == NULL) { passed_info = (void *)(((uintptr_t)trampoline + 0x1000) @@ -486,14 +488,6 @@ static struct limine_smp_info *try_acpi_smp(size_t *cpu_count, *cpu_count = 0; // Try to start all APs - - // Prepare the trampoline - if (trampoline == NULL) { - trampoline = ext_mem_alloc(0x1000); - - memcpy(trampoline, smp_trampoline_start, smp_trampoline_size); - } - for (uint8_t *madt_ptr = (uint8_t *)madt->madt_entries_begin; (uintptr_t)madt_ptr < (uintptr_t)madt + madt->header.length; madt_ptr += *(madt_ptr + 1)) {