#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" // 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\nrax=%p rbx=%p rcx=%p rdx=%p\nrsi=%p rdi=%p r8=%p r9=%p\nr10=%p r11=%p r12=%p r13=%p\nr14=%p r15=%p\n\nflags=%p\nstack at rbp=%p\nHalting...", 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; // 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(); void* ptr = kmalloc(10); DEBUG("(KMALLOC TEST) Allocated 10 bytes at 0x%p", ptr); void* ptr2 = kmalloc(200); DEBUG("(KMALLOC TEST) Allocated 200 bytes at 0x%p", ptr2); kfree(ptr); void* ptr3 = kmalloc(5); DEBUG("(KMALLOC TEST) Allocated 5 bytes at 0x%p", ptr3); vmm_init(); struct process_t* pedicel = process_create(); struct process_t* two = process_create(); struct process_t* three = process_create(); process_add(&processes_list, pedicel); process_add(&processes_list, two); process_add(&processes_list, three); process_display_list(processes_list); scheduler_init(); SET_INTERRUPTS; keyboard_init(FR); term_init(); kputs(splash); hcf(); }