127 lines
2.6 KiB
C
127 lines
2.6 KiB
C
#include "arch/serial.h"
|
|
|
|
#include <arch/e820.h>
|
|
#include <arch/pit.h>
|
|
#include <mango/arg.h>
|
|
#include <mango/clock.h>
|
|
#include <mango/console.h>
|
|
#include <mango/cpu.h>
|
|
#include <mango/init.h>
|
|
#include <mango/libc/stdio.h>
|
|
#include <mango/machine/cpu.h>
|
|
#include <mango/memblock.h>
|
|
#include <mango/object.h>
|
|
#include <mango/percpu.h>
|
|
#include <mango/pmap.h>
|
|
#include <mango/printk.h>
|
|
#include <mango/types.h>
|
|
#include <mango/vm.h>
|
|
|
|
#define PTR32(x) ((void *)((uintptr_t)(x)))
|
|
|
|
static ml_cpu_block g_bootstrap_cpu = {0};
|
|
|
|
/* start and end of kernel image (physical addresses) */
|
|
extern char __pstart[], __pend[];
|
|
|
|
static void bootstrap_cpu_init(void)
|
|
{
|
|
ml_cpu_block_init(&g_bootstrap_cpu);
|
|
ml_cpu_block_use(&g_bootstrap_cpu);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void early_console_init(void)
|
|
{
|
|
const char *dest = arg_value("kernel.early-console");
|
|
if (!dest) {
|
|
dest = "ttyS0";
|
|
}
|
|
|
|
if (!strcmp(dest, "tty0")) {
|
|
/* show log messages on VGA */
|
|
} else if (!strcmp(dest, "ttyS0")) {
|
|
/* write log messages to serial port */
|
|
early_serialcon_init(115200);
|
|
}
|
|
}
|
|
|
|
static void use_uniprocessor_topology(void)
|
|
{
|
|
cpu_set_available(0);
|
|
cpu_set_online(0);
|
|
}
|
|
|
|
int ml_init(uintptr_t arg)
|
|
{
|
|
multiboot_info_t *mb = (multiboot_info_t *)arg;
|
|
|
|
parse_cmdline(PTR32(mb->cmdline));
|
|
|
|
early_console_init();
|
|
|
|
bootstrap_cpu_init();
|
|
clock_calibrate(500);
|
|
|
|
print_kernel_banner();
|
|
|
|
early_vm_init();
|
|
|
|
e820_scan(PTR32(mb->mmap_addr), mb->mmap_length);
|
|
|
|
pmap_bootstrap();
|
|
|
|
use_uniprocessor_topology();
|
|
|
|
init_per_cpu_areas();
|
|
|
|
struct cpu_data *this_cpu = get_this_cpu();
|
|
memset(this_cpu, 0x0, sizeof *this_cpu);
|
|
|
|
this_cpu->c_flags = CPU_ONLINE;
|
|
this_cpu->c_id = this_cpu();
|
|
g_bootstrap_cpu.c_data = this_cpu;
|
|
put_cpu(this_cpu);
|
|
|
|
struct vm_zone_descriptor vm_zones[] = {
|
|
{.zd_id = VM_ZONE_DMA,
|
|
.zd_node = 0,
|
|
.zd_name = "dma",
|
|
.zd_base = 0x00,
|
|
.zd_limit = 0xffffff},
|
|
{.zd_id = VM_ZONE_NORMAL,
|
|
.zd_node = 0,
|
|
.zd_name = "normal",
|
|
.zd_base = 0x1000000,
|
|
.zd_limit = UINTPTR_MAX},
|
|
};
|
|
|
|
vm_bootstrap(vm_zones, sizeof vm_zones / sizeof vm_zones[0]);
|
|
|
|
object_bootstrap();
|
|
|
|
sched_init();
|
|
|
|
pit_start(500);
|
|
ml_int_enable();
|
|
|
|
return 0;
|
|
}
|