2023-02-05 10:50:13 +00:00
|
|
|
#include "socks/types.h"
|
|
|
|
|
#include <arch/e820.h>
|
2023-02-04 19:19:48 +00:00
|
|
|
#include <socks/init.h>
|
2023-02-05 10:50:13 +00:00
|
|
|
#include <socks/memblock.h>
|
|
|
|
|
#include <socks/vm.h>
|
|
|
|
|
#include <socks/printk.h>
|
2023-02-03 20:24:27 +00:00
|
|
|
#include <socks/machine/cpu.h>
|
2023-02-05 09:45:17 +00:00
|
|
|
#include <arch/vgacon.h>
|
2023-02-03 20:24:27 +00:00
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
#define PTR32(x) ((void *)((uintptr_t)(x)))
|
|
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
static ml_cpu_block g_bootstrap_cpu = {0};
|
|
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
/* start and end of kernel image (physical addresses) */
|
|
|
|
|
extern char __pstart[], __pend[];
|
|
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
static void bootstrap_cpu_init(void)
|
|
|
|
|
{
|
|
|
|
|
ml_cpu_block_init(&g_bootstrap_cpu);
|
|
|
|
|
ml_cpu_block_use(&g_bootstrap_cpu);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
static void early_vm_init(void)
|
|
|
|
|
{
|
|
|
|
|
uintptr_t alloc_start = VM_KERNEL_VOFFSET;
|
|
|
|
|
/* boot code mapped 2 GiB of memory from
|
|
|
|
|
VM_KERNEL_VOFFSET */
|
|
|
|
|
uintptr_t alloc_end = VM_KERNEL_VOFFSET + 0x7fffffff;
|
|
|
|
|
|
|
|
|
|
memblock_init(alloc_start, alloc_end, VM_KERNEL_VOFFSET);
|
|
|
|
|
printk("memblock: allocating from [0x%llx-0x%llx]", alloc_start, alloc_end);
|
|
|
|
|
|
|
|
|
|
memblock_reserve(0x00, (uintptr_t)__pend);
|
|
|
|
|
printk("memblock: reserved bios+kernel at [0x%016llx-0x%016llx]", 0, (uintptr_t)__pend);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
int ml_init(uintptr_t arg)
|
|
|
|
|
{
|
2023-02-05 10:50:13 +00:00
|
|
|
multiboot_info_t *mb = (multiboot_info_t *)arg;
|
|
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
bootstrap_cpu_init();
|
2023-02-04 19:03:45 +00:00
|
|
|
vgacon_init();
|
2023-02-04 19:19:48 +00:00
|
|
|
|
|
|
|
|
print_kernel_banner();
|
|
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
early_vm_init();
|
|
|
|
|
|
|
|
|
|
e820_scan(PTR32(mb->mmap_addr), mb->mmap_length);
|
|
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|