diff --git a/docs/STYLE.md b/docs/STYLE.md index c7db749..7055ccc 100644 --- a/docs/STYLE.md +++ b/docs/STYLE.md @@ -78,6 +78,10 @@ Comments should describe what a function does and why, not how it does it. */ ``` +## Kernel messages + +When printing kernel messages with the `DEBUG` macro, they should start with a capital letter. + ### Resources Some of the elements here are inspired by the [Linux kernel coding style](https://www.kernel.org/doc/html/v4.10/process/coding-style.html). \ No newline at end of file diff --git a/src/debug/misc.c b/src/debug/misc.c index 5cba142..eb7392e 100644 --- a/src/debug/misc.c +++ b/src/debug/misc.c @@ -43,7 +43,7 @@ void memmap_display(struct limine_memmap_response* response) strcpy(type, "UNKNOWN"); break; } - DEBUG("entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type); + DEBUG("Entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type); } } @@ -57,5 +57,5 @@ void boot_mem_display() { 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); + DEBUG("Kernel is at phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base); } \ No newline at end of file diff --git a/src/debug/panic.c b/src/debug/panic.c index fce9bbe..f770ac7 100644 --- a/src/debug/panic.c +++ b/src/debug/panic.c @@ -20,13 +20,13 @@ void panic(struct cpu_status_t* ctx, const char* str) if (init.terminal) { - printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)"); - printf("\r\n%s\r\n\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m", str); + printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[48;5;232m Something went horribly wrong! (no cpu ctx)"); + printf("\r\n%s\r\n\x1b[38;5;231mend Kernel panic - halting...\x1b[0m", str); } hcf(); } - DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) 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\rHalting...", + DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) 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\rHalting...\x1b[0m", ctx->iret_rip, str, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, @@ -34,7 +34,7 @@ void panic(struct cpu_status_t* ctx, const char* str) if (init.terminal) { - printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) 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\rHalting...", + printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[48;5;232mat rip=%p\r\nSomething went horribly wrong! (%s) 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\rHalting...\x1b[0m", ctx->iret_rip, str, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, diff --git a/src/idt/idt.c b/src/idt/idt.c index 5b9504b..9203c54 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -126,72 +126,70 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) switch(context->vector_number) { case 0: - DEBUG("Divide Error!"); + panic(context, "Divide Error"); break; case 1: - DEBUG("Debug Exception!"); + panic(context, "Debug Exception"); break; case 2: - DEBUG("NMI Interrupt!"); + panic(context, "NMI Interrupt"); break; case 3: - DEBUG("Breakpoint Interrupt!"); + panic(context, "Breakpoint Interrupt"); break; case 4: - DEBUG("Overflow Trap!"); + panic(context, "Overflow Trap"); break; case 5: - DEBUG("BOUND Range Exceeded!"); + panic(context, "BOUND Range Exceeded"); break; case 6: - DEBUG("Invalid Opcode!"); - panic(context, "Invalid Opcode!"); + panic(context, "Invalid Opcode"); break; case 7: - DEBUG("Device Not Available!"); + panic(context, "Device Not Available"); break; case 8: - DEBUG("Double Fault!"); + panic(context, "Double Fault"); break; case 9: - DEBUG("Coprocessor Segment Overrun!"); + panic(context, "Coprocessor Segment Overrun"); break; case 10: - DEBUG("Invalid TSS!"); + panic(context, "Invalid TSS"); break; case 11: - DEBUG("Segment Not Present!"); + panic(context, "Segment Not Present"); break; case 12: - DEBUG("Stack-Segment Fault!"); + panic(context, "Stack-Segment Fault"); break; case 13: gp_fault_handler(context); break; case 14: - // Better debugging for page faults... page_fault_handler(context); break; case 15: - DEBUG("Intel Reserved Interrupt! (Achievement unlocked: How Did We Get Here?)"); + panic(context, "Intel Reserved Interrupt (Achievement unlocked: How Did We Get Here?)"); break; case 16: - DEBUG("x87 Floating-Point Error!"); + panic(context, "x87 Floating-Point Error"); break; case 17: - DEBUG("Alignment Check Fault!"); + panic(context, "Alignment Check Fault"); break; case 18: - DEBUG("Machine Check!"); + panic(context, "Machine Check"); break; case 19: - DEBUG("SIMD Floating-Point Exception!"); + panic(context, "SIMD Floating-Point Exception"); break; case 20: - DEBUG("Virtualization Exception!"); + panic(context, "Virtualization Exception"); break; case 21: - DEBUG("Control Protection Exception!"); + panic(context, "Control Protection Exception"); break; case 32: // Timer Interrupt @@ -213,7 +211,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) break; default: - DEBUG("Unexpected interrupt"); + DEBUG("Unexpected Interrupt"); break; } diff --git a/src/mem/paging/paging.c b/src/mem/paging/paging.c index 4128b14..ba61b55 100644 --- a/src/mem/paging/paging.c +++ b/src/mem/paging/paging.c @@ -141,7 +141,6 @@ void paging_init() { max_phys = top; } - //DEBUG("max_phys=0x%p", max_phys); } // 4GB @@ -187,15 +186,7 @@ void paging_init() } DEBUG("Mapped %u pages for framebuffer", page_count); - // test for flanterm - // When 10 pages are mapped, SOMETIMES (1 out of 50 times) it prints everything without problem! - // Other times it prints garbage (almost full cursors) and/or panics. -/* for (uint64_t i=0; i<10; i++) - { - paging_map_page(kernel_pml4, 0, kernel_phys_base+KERNEL_SIZE+i*PAGE_SIZE, PTE_WRITABLE); - } */ - // Finally, we load the physical address of our PML4 (root table) into cr3 load_cr3(VIRT_TO_PHYS(kernel_pml4)); - DEBUG("cr3 loaded, we're still alive"); + DEBUG("Loaded kernel PML4 into CR3"); } \ No newline at end of file diff --git a/src/mem/paging/pmm.c b/src/mem/paging/pmm.c index 2b45699..472ccfa 100644 --- a/src/mem/paging/pmm.c +++ b/src/mem/paging/pmm.c @@ -102,8 +102,7 @@ void pmm_init(struct limine_memmap_response* memmap, struct limine_hhdm_response { hhdm_off = hhdm->offset; pmm_find_biggest_usable_region(memmap, hhdm); - //pmm_allocate_bitmap(hhdm); too complicated for my small brain - + // Now we have biggest USABLE region, // so to populate the free list we just iterate through it pmm_init_freelist(); diff --git a/src/sched/scheduler.c b/src/sched/scheduler.c index 14a3fe0..528e769 100644 --- a/src/sched/scheduler.c +++ b/src/sched/scheduler.c @@ -61,7 +61,7 @@ struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context) DEBUG("current_process={pid=%u, name='%s', root_page_table[virt]=%p}", current_process->pid, current_process->name, current_process->root_page_table); load_cr3(VIRT_TO_PHYS((uint64_t)current_process->root_page_table)); - DEBUG("loaded process pml4 into cr3"); + DEBUG("Loaded process PML4 into CR3"); return current_process->context; } \ No newline at end of file