2024-09-17 17:48:26 +01:00
|
|
|
#include "arch/serial.h"
|
|
|
|
|
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <arch/e820.h>
|
2024-09-17 17:48:26 +01:00
|
|
|
#include <arch/pit.h>
|
2023-12-27 17:34:59 +00:00
|
|
|
#include <socks/arg.h>
|
2023-04-28 20:51:51 +01:00
|
|
|
#include <socks/clock.h>
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <socks/console.h>
|
2023-03-18 19:35:00 +00:00
|
|
|
#include <socks/cpu.h>
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <socks/init.h>
|
|
|
|
|
#include <socks/libc/stdio.h>
|
|
|
|
|
#include <socks/machine/cpu.h>
|
2023-02-05 10:50:13 +00:00
|
|
|
#include <socks/memblock.h>
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <socks/object.h>
|
|
|
|
|
#include <socks/percpu.h>
|
|
|
|
|
#include <socks/pmap.h>
|
2023-02-05 10:50:13 +00:00
|
|
|
#include <socks/printk.h>
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <socks/types.h>
|
|
|
|
|
#include <socks/vm.h>
|
2023-12-30 09:09:18 +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);
|
2024-09-17 17:47:50 +01:00
|
|
|
printk("memblock: allocating from [0x%llx-0x%llx]",
|
|
|
|
|
alloc_start,
|
|
|
|
|
alloc_end);
|
2023-02-05 10:50:13 +00:00
|
|
|
|
|
|
|
|
memblock_reserve(0x00, (uintptr_t)__pend);
|
2024-09-17 17:47:50 +01:00
|
|
|
printk("memblock: reserved bios+kernel at [0x%016llx-0x%016llx]",
|
|
|
|
|
0,
|
|
|
|
|
(uintptr_t)__pend);
|
2023-02-05 10:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 09:09:18 +00:00
|
|
|
void early_console_init(void)
|
|
|
|
|
{
|
|
|
|
|
const char *dest = arg_value("kernel.early-console");
|
|
|
|
|
if (!dest) {
|
2024-09-17 17:48:26 +01:00
|
|
|
dest = "ttyS0";
|
2023-12-30 09:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 17:48:26 +01:00
|
|
|
if (!strcmp(dest, "tty0")) {
|
|
|
|
|
/* show log messages on VGA */
|
|
|
|
|
} else if (!strcmp(dest, "ttyS0")) {
|
|
|
|
|
/* write log messages to serial port */
|
|
|
|
|
early_serialcon_init(115200);
|
|
|
|
|
}
|
2023-06-08 20:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 19:31:30 +01:00
|
|
|
static void use_uniprocessor_topology(void)
|
|
|
|
|
{
|
|
|
|
|
cpu_set_available(0);
|
|
|
|
|
cpu_set_online(0);
|
|
|
|
|
}
|
|
|
|
|
|
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-07 16:00:45 +00:00
|
|
|
|
2023-12-27 17:34:59 +00:00
|
|
|
parse_cmdline(PTR32(mb->cmdline));
|
|
|
|
|
|
2024-09-17 17:48:26 +01:00
|
|
|
early_console_init();
|
2023-06-08 20:46:43 +01:00
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
bootstrap_cpu_init();
|
2023-04-28 20:51:51 +01:00
|
|
|
clock_calibrate(500);
|
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-06 20:50:28 +00:00
|
|
|
pmap_bootstrap();
|
|
|
|
|
|
2023-06-09 19:31:30 +01:00
|
|
|
use_uniprocessor_topology();
|
|
|
|
|
|
2023-03-18 19:35:00 +00:00
|
|
|
init_per_cpu_areas();
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct cpu_data *this_cpu = get_this_cpu();
|
2023-05-07 21:40:12 +01:00
|
|
|
memset(this_cpu, 0x0, sizeof *this_cpu);
|
|
|
|
|
|
2023-03-18 19:35:00 +00:00
|
|
|
this_cpu->c_flags = CPU_ONLINE;
|
|
|
|
|
this_cpu->c_id = this_cpu();
|
2023-03-28 21:38:47 +01:00
|
|
|
g_bootstrap_cpu.c_data = this_cpu;
|
2023-03-18 19:35:00 +00:00
|
|
|
put_cpu(this_cpu);
|
2023-02-09 19:09:07 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct vm_zone_descriptor vm_zones[] = {
|
2024-09-17 17:47:50 +01:00
|
|
|
{.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},
|
2023-02-07 16:00:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
vm_bootstrap(vm_zones, sizeof vm_zones / sizeof vm_zones[0]);
|
|
|
|
|
|
2023-03-19 20:36:36 +00:00
|
|
|
object_bootstrap();
|
2023-06-02 19:35:07 +01:00
|
|
|
|
2023-03-19 20:36:36 +00:00
|
|
|
sched_init();
|
|
|
|
|
|
2024-09-17 17:48:26 +01:00
|
|
|
pit_start(500);
|
2023-03-24 14:21:02 +00:00
|
|
|
ml_int_enable();
|
2023-03-19 20:36:36 +00:00
|
|
|
|
2023-02-03 20:24:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|