2026-02-19 18:54:48 +00:00
|
|
|
#include <kernel/arg.h>
|
|
|
|
|
#include <kernel/bsp.h>
|
|
|
|
|
#include <kernel/channel.h>
|
|
|
|
|
#include <kernel/clock.h>
|
|
|
|
|
#include <kernel/cpu.h>
|
|
|
|
|
#include <kernel/handle.h>
|
|
|
|
|
#include <kernel/init.h>
|
|
|
|
|
#include <kernel/input.h>
|
|
|
|
|
#include <kernel/libc/stdio.h>
|
|
|
|
|
#include <kernel/machine/init.h>
|
|
|
|
|
#include <kernel/object.h>
|
|
|
|
|
#include <kernel/panic.h>
|
|
|
|
|
#include <kernel/port.h>
|
|
|
|
|
#include <kernel/printk.h>
|
|
|
|
|
#include <kernel/sched.h>
|
|
|
|
|
#include <kernel/test.h>
|
|
|
|
|
#include <kernel/vm-object.h>
|
2024-09-17 17:47:50 +01:00
|
|
|
#include <stdint.h>
|
2023-02-04 19:03:45 +00:00
|
|
|
|
|
|
|
|
extern unsigned long get_rflags(void);
|
2022-12-21 08:29:33 +00:00
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
extern char __pstart[], __pend[];
|
|
|
|
|
|
2023-02-04 19:19:48 +00:00
|
|
|
void print_kernel_banner(void)
|
|
|
|
|
{
|
2024-11-02 11:31:51 +00:00
|
|
|
printk("Mango kernel version " BUILD_ID);
|
2023-02-04 19:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
static void hang(void)
|
|
|
|
|
{
|
2026-02-08 13:12:48 +00:00
|
|
|
// struct task *self = current_task();
|
|
|
|
|
// struct thread *thread = current_thread();
|
2024-09-17 17:49:34 +01:00
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
while (1) {
|
2026-02-08 13:12:48 +00:00
|
|
|
#if 0
|
2024-09-17 17:49:34 +01:00
|
|
|
printk("[cpu %u, task %u, thread %u]: tick",
|
|
|
|
|
this_cpu(),
|
|
|
|
|
self->t_id,
|
|
|
|
|
thread->tr_id);
|
2026-02-08 13:12:48 +00:00
|
|
|
#endif
|
2023-05-10 20:34:53 +01:00
|
|
|
milli_sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 21:43:18 +01:00
|
|
|
void background_thread(void)
|
|
|
|
|
{
|
2024-09-17 17:49:34 +01:00
|
|
|
struct task *self = current_task();
|
|
|
|
|
struct thread *thread = current_thread();
|
2023-05-04 21:43:18 +01:00
|
|
|
printk("background_thread() running on processor %u", this_cpu());
|
2023-12-30 09:09:18 +00:00
|
|
|
milli_sleep(1000);
|
2023-05-07 12:38:06 +01:00
|
|
|
|
2023-05-04 21:43:18 +01:00
|
|
|
while (1) {
|
2024-09-17 17:49:34 +01:00
|
|
|
printk("[cpu %u, task %u, thread %u]: tock",
|
|
|
|
|
this_cpu(),
|
|
|
|
|
self->t_id,
|
|
|
|
|
thread->tr_id);
|
2023-05-10 20:34:53 +01:00
|
|
|
milli_sleep(2000);
|
2023-05-04 21:43:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
static void putchar(char c)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
struct queue *consoles = get_consoles(&flags);
|
2024-09-17 17:47:50 +01:00
|
|
|
queue_foreach(struct console, con, consoles, c_list)
|
|
|
|
|
{
|
2023-05-10 20:34:53 +01:00
|
|
|
console_write(con, &c, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
put_consoles(consoles, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 08:29:33 +00:00
|
|
|
void kernel_init(uintptr_t arg)
|
|
|
|
|
{
|
2023-02-03 20:24:27 +00:00
|
|
|
ml_init(arg);
|
2023-02-26 10:05:39 +00:00
|
|
|
|
2026-02-08 13:12:48 +00:00
|
|
|
struct boot_module bsp_image = {0};
|
|
|
|
|
bsp_get_location(&bsp_image);
|
|
|
|
|
|
|
|
|
|
tracek("kernel_init() running on processor %u", this_cpu());
|
|
|
|
|
|
|
|
|
|
if (!bsp_image.mod_base) {
|
|
|
|
|
printk("FATAL: no bsp image specified");
|
|
|
|
|
hang();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tracek("bsp image at [0x%llx-0x%llx]",
|
|
|
|
|
bsp_image.mod_base,
|
|
|
|
|
bsp_image.mod_base + bsp_image.mod_size);
|
|
|
|
|
|
|
|
|
|
struct bsp bsp;
|
|
|
|
|
kern_status_t status = bsp_load(&bsp, &bsp_image);
|
|
|
|
|
if (status != KERN_OK) {
|
|
|
|
|
printk("FATAL: bsp image is corrupt/invalid");
|
|
|
|
|
hang();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tracek("bsp image loaded. text=[%06llx-%06llx], data=[%06llx-%06llx], "
|
|
|
|
|
"entry=%06llx, vmo=%p",
|
|
|
|
|
bsp.bsp_trailer.bsp_text_vaddr,
|
|
|
|
|
bsp.bsp_trailer.bsp_text_size + bsp.bsp_trailer.bsp_text_vaddr,
|
|
|
|
|
bsp.bsp_trailer.bsp_data_vaddr,
|
|
|
|
|
bsp.bsp_trailer.bsp_data_size + bsp.bsp_trailer.bsp_data_vaddr,
|
|
|
|
|
bsp.bsp_trailer.bsp_exec_entry,
|
|
|
|
|
bsp.bsp_vmo);
|
|
|
|
|
|
|
|
|
|
struct task *bootstrap_task = task_create(kernel_task(), "bootstrap");
|
|
|
|
|
tracek("created bootstrap task (pid=%u)", bootstrap_task->t_id);
|
2023-03-18 19:35:00 +00:00
|
|
|
|
2026-02-08 13:12:48 +00:00
|
|
|
bsp_launch_async(&bsp, bootstrap_task);
|
2023-05-04 21:43:18 +01:00
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
hang();
|
2022-12-21 08:29:33 +00:00
|
|
|
}
|