/* * @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"))) volatile LIMINE_BASE_REVISION(3); // Halt and catch fire (makes machine stall) void hcf() { CLEAR_INTERRUPTS; for (;;)asm("hlt"); } // Doing nothing (can be interrupted) void idle() {for(;;)asm("hlt");} void panic(struct cpu_status_t* ctx, const char* str) { CLEAR_INTERRUPTS; if (ctx == NULL) { DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)"); DIE_DEBUG(str); skputc('\n'); DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m"); hcf(); } 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(); } struct boot_context boot_ctx; extern volatile struct limine_framebuffer_request framebuffer_request; extern volatile struct limine_memmap_request memmap_request; extern volatile struct limine_hhdm_request hhdm_request; extern volatile struct limine_kernel_address_request kerneladdr_request; extern struct process_t* processes_list; extern struct process_t* current_process; void pedicel_main(void* arg) { panic(NULL, "we did it!"); } 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(PEPPEROS_SPLASH); idle(); }