all kernel headers have been moved from include/mango to include/kernel and include definitions that are only relevant to kernel-space. any definitions that are relevant to both kernel- and user-space (i.e. type definitions, syscall IDs) have been moved to include/mango within libmango.
114 lines
2.6 KiB
C
114 lines
2.6 KiB
C
#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>
|
|
#include <stdint.h>
|
|
|
|
extern unsigned long get_rflags(void);
|
|
|
|
extern char __pstart[], __pend[];
|
|
|
|
void print_kernel_banner(void)
|
|
{
|
|
printk("Mango kernel version " BUILD_ID);
|
|
}
|
|
|
|
static void hang(void)
|
|
{
|
|
// struct task *self = current_task();
|
|
// struct thread *thread = current_thread();
|
|
|
|
while (1) {
|
|
#if 0
|
|
printk("[cpu %u, task %u, thread %u]: tick",
|
|
this_cpu(),
|
|
self->t_id,
|
|
thread->tr_id);
|
|
#endif
|
|
milli_sleep(2000);
|
|
}
|
|
}
|
|
|
|
void background_thread(void)
|
|
{
|
|
struct task *self = current_task();
|
|
struct thread *thread = current_thread();
|
|
printk("background_thread() running on processor %u", this_cpu());
|
|
milli_sleep(1000);
|
|
|
|
while (1) {
|
|
printk("[cpu %u, task %u, thread %u]: tock",
|
|
this_cpu(),
|
|
self->t_id,
|
|
thread->tr_id);
|
|
milli_sleep(2000);
|
|
}
|
|
}
|
|
|
|
static void putchar(char c)
|
|
{
|
|
unsigned long flags;
|
|
struct queue *consoles = get_consoles(&flags);
|
|
queue_foreach(struct console, con, consoles, c_list)
|
|
{
|
|
console_write(con, &c, 1);
|
|
}
|
|
|
|
put_consoles(consoles, flags);
|
|
}
|
|
|
|
void kernel_init(uintptr_t arg)
|
|
{
|
|
ml_init(arg);
|
|
|
|
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);
|
|
|
|
bsp_launch_async(&bsp, bootstrap_task);
|
|
|
|
hang();
|
|
}
|