#include "fs/cpio.h" #include "fs/elf.h" #include #include #include #define SERIAL_PORT 0x70000000 #define DRAM_DEVICE 0 #define UART_DEVICE 1 #define DRAM_RESERVED_INITRD 10 #define DRAM_RESERVED_OTHER 11 extern void set_root(struct mempage_t *incoming_root); void serial_write(char value) { *(char *)SERIAL_PORT = value; } void kernel_main(int hart, struct boot_args *args) { if (hart != 0) { return; } register_console_callback(serial_write); printk("webkernel version %s (Compiler %s, Linker %s) on %s\n", VERSION, COMPILER_NAME, LINKER_NAME, ARCH_NAME); printk("Command line: %s\n", args->cmd_line); printk("BIOS provided device map:\n"); struct device *root = args->devices; struct mempage_t *mem_root; void *initrd_base; size_t initrd_size; while (root != NULL) { printk("....Device at 0x%x to 0x%x is ", (uintptr_t)root->start, (uintptr_t)root->start + root->size ); switch(root->device_type) { case DRAM_DEVICE: printk("generic DRAM device, usable\n"); mem_root = (struct mempage_t *)root->start; mem_root->next = NULL; mem_root->size = root->size; break; case UART_DEVICE: printk("Web OS UART character device, not ns16550a compatible, MMIO device\n"); break; case DRAM_RESERVED_INITRD: printk("generic DRAM device, not usable, reserved, initial ramdisk\n"); initrd_base = (void *)root->start; initrd_size = root->size; break; case DRAM_RESERVED_OTHER: printk("generic DRAM device, not usable, reserved, other (likely kernel or firmware)\n"); break; default: printk("unknown\n"); } root = root->next; } set_root(mem_root); printk("Using initramfs mounted at 0x%x, size %d\n", (uintptr_t)initrd_base, initrd_size); printk("Skipping initramfs mount, invoking /sbin/init\n"); void *file = cpio_get_file(initrd_base, initrd_size, "sbin/init"); elf_exec(file); } void panic(char *cause) { printk("PANIC: %s\n", cause); } void handle_syscall() { panic("syscall handler unimplemented"); }