/* * @author xamidev * @brief PepperOS kernel entry point * @license GPL-3.0-only */ #include #include #include #include "io/term/term.h" #include "io/term/printf.h" #include "io/serial/serial.h" #include "mem/gdt/gdt.h" #include "mem/misc/utils.h" #include "idt/idt.h" #include "kernel.h" #include "time/timer.h" #include "io/kbd/ps2.h" #include "mem/paging/pmm.h" #include "mem/paging/paging.h" #include "mem/paging/vmm.h" #include "mem/heap/kheap.h" #include "sched/process.h" #include "sched/scheduler.h" #include "config.h" // Limine version used __attribute__((used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3); // Framebuffer request __attribute__((used, section(".limine_requests"))) static volatile struct limine_framebuffer_request framebuffer_request = { .id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0 }; // Memory map request __attribute__((used, section(".limine_requests"))) static volatile struct limine_memmap_request memmap_request = { .id = LIMINE_MEMMAP_REQUEST, .revision = 0 }; // Higher Half Direct Map __attribute__((used, section(".limine_requests"))) static volatile struct limine_hhdm_request hhdm_request = { .id = LIMINE_HHDM_REQUEST, .revision = 0 }; // Executable Address/Kernel Address (find base phys/virt address of kernel) __attribute__((used, section(".limine_requests"))) static volatile struct limine_kernel_address_request kerneladdr_request = { .id = LIMINE_KERNEL_ADDRESS_REQUEST, .revision = 0 }; __attribute__((used, section(".limine_requests_start"))) static volatile LIMINE_REQUESTS_START_MARKER; __attribute__((used, section(".limine_requests_end"))) static volatile LIMINE_REQUESTS_END_MARKER; // Panic (should dump registers etc. in the future) void hcf() { //CLEAR_INTERRUPTS; for (;;) { asm("hlt"); } } void panic(struct cpu_status_t* ctx) { DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\nSomething went horribly wrong! vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rstack at rbp=%p\n\rHalting...", ctx->iret_rip, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags, ctx->rbp); hcf(); } const char* splash = "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\n"; struct boot_context boot_ctx; extern struct process_t* processes_list; extern struct process_t* current_process; void pedicel_main(void* arg) { } void two_main(void* arg) { } void three_main(void* arg) { } // This is our entry point void kmain() { if (!LIMINE_BASE_REVISION_SUPPORTED) hcf(); // Populate boot context boot_ctx.fb = framebuffer_request.response ? framebuffer_request.response->framebuffers[0] : NULL; boot_ctx.mmap = memmap_request.response ? memmap_request.response : NULL; boot_ctx.hhdm = hhdm_request.response ? hhdm_request.response : NULL; boot_ctx.kaddr = kerneladdr_request.response ? kerneladdr_request.response : NULL; serial_init(); memmap_display(boot_ctx.mmap); hhdm_display(boot_ctx.hhdm); DEBUG("kernel: phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base); CLEAR_INTERRUPTS; gdt_init(); idt_init(); timer_init(); pmm_init(boot_ctx.mmap, boot_ctx.hhdm); // Remap kernel , HHDM and framebuffer paging_init(boot_ctx.kaddr, boot_ctx.fb); kheap_init(); vmm_init(); struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0); struct process_t* two = process_create("two", (void*)two_main, 0); struct process_t* three = process_create("three", (void*)three_main, 0); process_display_list(processes_list); scheduler_init(); SET_INTERRUPTS; keyboard_init(FR); term_init(); kputs(splash); hcf(); }