DEBUG with Capital Letters

This commit is contained in:
2026-03-11 15:24:45 +01:00
parent 1dd4e728d4
commit 9d409317e2
7 changed files with 34 additions and 42 deletions

View File

@@ -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).

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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");
}

View File

@@ -102,7 +102,6 @@ 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

View File

@@ -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;
}