x86_64: find, record, and reserve the memory location of the bsp

This commit is contained in:
2026-02-08 11:52:33 +00:00
parent 129e782e99
commit da611ab070

View File

@@ -3,6 +3,7 @@
#include <arch/serial.h>
#include <arch/vgacon.h>
#include <mango/arg.h>
#include <mango/bsp.h>
#include <mango/clock.h>
#include <mango/console.h>
#include <mango/cpu.h>
@@ -30,7 +31,7 @@ static void bootstrap_cpu_init(void)
ml_cpu_block_use(&g_bootstrap_cpu);
}
static void early_vm_init(void)
static void early_vm_init(uintptr_t reserve_end)
{
uintptr_t alloc_start = VM_KERNEL_VOFFSET;
/* boot code mapped 2 GiB of memory from
@@ -42,10 +43,10 @@ static void early_vm_init(void)
alloc_start,
alloc_end);
memblock_reserve(0x00, (uintptr_t)__pend);
memblock_reserve(0x00, reserve_end);
printk("memblock: reserved bios+kernel at [0x%016llx-0x%016llx]",
0,
(uintptr_t)__pend);
reserve_end);
}
void early_console_init(void)
@@ -70,6 +71,23 @@ static void use_uniprocessor_topology(void)
cpu_set_online(0);
}
static void find_bsp(multiboot_info_t *mb, struct boot_module *out)
{
memset(out, 0x0, sizeof *out);
printk("modules=%u: %llx", mb->mods_count, mb->mods_addr);
multiboot_module_t *mods = PTR32(mb->mods_addr);
size_t nr_mods = mb->mods_count;
if (nr_mods < 1) {
return;
}
out->mod_base = mods[0].mod_start;
out->mod_size = mods[0].mod_end - mods[0].mod_start;
}
int ml_init(uintptr_t arg)
{
multiboot_info_t *mb = (multiboot_info_t *)arg;
@@ -83,7 +101,16 @@ int ml_init(uintptr_t arg)
print_kernel_banner();
early_vm_init();
struct boot_module bsp;
find_bsp(mb, &bsp);
bsp_set_location(&bsp);
uintptr_t reserve_end = (uintptr_t)__pend;
if (bsp.mod_base + bsp.mod_size > reserve_end) {
reserve_end = bsp.mod_base + bsp.mod_size;
}
early_vm_init(reserve_end);
e820_scan(PTR32(mb->mmap_addr), mb->mmap_length);