#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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("bootstrap", 9); tracek("created bootstrap task (pid=%u)", bootstrap_task->t_id); bsp_launch_async(&bsp, bootstrap_task); hang(); }