/* * @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" #include "io/term/flanterm.h" #include "io/term/flanterm_backends/fb.h" // Limine version used __attribute__((used, section(".limine_requests"))) volatile LIMINE_BASE_REVISION(3); /* * hcf - Halt and catch fire * * This function is called only in the case of an unrecoverable * error. It halts interrupts, and stops execution. The machine * will stay in an infinite loop state. */ void hcf() { CLEAR_INTERRUPTS; for (;;)asm("hlt"); } /* * idle - Make the machine idle * * When there is nothing else to do, this function * gets called. It can be interrupted, so it allows * the scheduler, timer, and keyboard to work. */ void idle() {SET_INTERRUPTS; for(;;)asm("hlt");} struct flanterm_context *ft_ctx; struct boot_context boot_ctx; struct init_status init = {0}; 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; struct process_t* idle_proc; bool iran = false; // Never gets executed although pedicel is scheduled? void pedicel_main(void* arg) { //panic(NULL, "test"); bool iran = true; // FROM THE NEXT LINE ONWARDS, CANNOT WRITE TO FRAMEBUFFER WITHOUT PAGE FAULT! //printf("\n\nWelcome to PepperOS! Pedicel speaking.\nNothing left to do, halting the system!"); } void idle_main(void* arg) { for (;;) { asm("hlt"); } } extern uintptr_t kheap_start; /* * kmain - Kernel entry point * * This is where execution begins at handoff from Limine. * The function fetches all needed information from the * bootloader, initializes all kernel modules and structures, * and then goes in an idle state. */ void kmain() { CLEAR_INTERRUPTS; if (!LIMINE_BASE_REVISION_SUPPORTED) hcf(); serial_init(); timer_init(); // 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; boot_mem_display(); pmm_init(boot_ctx); // Remap kernel , HHDM and framebuffer paging_init(boot_ctx); kheap_init(); keyboard_init(FR); term_init(); gdt_init(); idt_init(); process_init(); idle_proc = process_create("idle", (void*)idle_main, 0); struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0); process_display_list(processes_list); scheduler_init(); kputs(PEPPEROS_SPLASH); idle(); }