DEBUG with Capital Letters
This commit is contained in:
@@ -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
|
### 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).
|
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).
|
||||||
@@ -43,7 +43,7 @@ void memmap_display(struct limine_memmap_response* response)
|
|||||||
strcpy(type, "UNKNOWN");
|
strcpy(type, "UNKNOWN");
|
||||||
break;
|
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);
|
memmap_display(boot_ctx.mmap);
|
||||||
hhdm_display(boot_ctx.hhdm);
|
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);
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,13 @@ void panic(struct cpu_status_t* ctx, const char* str)
|
|||||||
|
|
||||||
if (init.terminal)
|
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\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;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m", str);
|
printf("\r\n%s\r\n\x1b[38;5;231mend Kernel panic - halting...\x1b[0m", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
hcf();
|
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,
|
ctx->iret_rip,
|
||||||
str,
|
str,
|
||||||
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
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)
|
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,
|
ctx->iret_rip,
|
||||||
str,
|
str,
|
||||||
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
||||||
|
|||||||
@@ -126,72 +126,70 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
|||||||
switch(context->vector_number)
|
switch(context->vector_number)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
DEBUG("Divide Error!");
|
panic(context, "Divide Error");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
DEBUG("Debug Exception!");
|
panic(context, "Debug Exception");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
DEBUG("NMI Interrupt!");
|
panic(context, "NMI Interrupt");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
DEBUG("Breakpoint Interrupt!");
|
panic(context, "Breakpoint Interrupt");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
DEBUG("Overflow Trap!");
|
panic(context, "Overflow Trap");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
DEBUG("BOUND Range Exceeded!");
|
panic(context, "BOUND Range Exceeded");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
DEBUG("Invalid Opcode!");
|
panic(context, "Invalid Opcode");
|
||||||
panic(context, "Invalid Opcode!");
|
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
DEBUG("Device Not Available!");
|
panic(context, "Device Not Available");
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
DEBUG("Double Fault!");
|
panic(context, "Double Fault");
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
DEBUG("Coprocessor Segment Overrun!");
|
panic(context, "Coprocessor Segment Overrun");
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
DEBUG("Invalid TSS!");
|
panic(context, "Invalid TSS");
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
DEBUG("Segment Not Present!");
|
panic(context, "Segment Not Present");
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
DEBUG("Stack-Segment Fault!");
|
panic(context, "Stack-Segment Fault");
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
gp_fault_handler(context);
|
gp_fault_handler(context);
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
// Better debugging for page faults...
|
|
||||||
page_fault_handler(context);
|
page_fault_handler(context);
|
||||||
break;
|
break;
|
||||||
case 15:
|
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;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
DEBUG("x87 Floating-Point Error!");
|
panic(context, "x87 Floating-Point Error");
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
DEBUG("Alignment Check Fault!");
|
panic(context, "Alignment Check Fault");
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
DEBUG("Machine Check!");
|
panic(context, "Machine Check");
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
DEBUG("SIMD Floating-Point Exception!");
|
panic(context, "SIMD Floating-Point Exception");
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
DEBUG("Virtualization Exception!");
|
panic(context, "Virtualization Exception");
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
DEBUG("Control Protection Exception!");
|
panic(context, "Control Protection Exception");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32: // Timer Interrupt
|
case 32: // Timer Interrupt
|
||||||
@@ -213,7 +211,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUG("Unexpected interrupt");
|
DEBUG("Unexpected Interrupt");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ void paging_init()
|
|||||||
{
|
{
|
||||||
max_phys = top;
|
max_phys = top;
|
||||||
}
|
}
|
||||||
//DEBUG("max_phys=0x%p", max_phys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4GB
|
// 4GB
|
||||||
@@ -187,15 +186,7 @@ void paging_init()
|
|||||||
}
|
}
|
||||||
DEBUG("Mapped %u pages for framebuffer", page_count);
|
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
|
// Finally, we load the physical address of our PML4 (root table) into cr3
|
||||||
load_cr3(VIRT_TO_PHYS(kernel_pml4));
|
load_cr3(VIRT_TO_PHYS(kernel_pml4));
|
||||||
DEBUG("cr3 loaded, we're still alive");
|
DEBUG("Loaded kernel PML4 into CR3");
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,6 @@ void pmm_init(struct limine_memmap_response* memmap, struct limine_hhdm_response
|
|||||||
{
|
{
|
||||||
hhdm_off = hhdm->offset;
|
hhdm_off = hhdm->offset;
|
||||||
pmm_find_biggest_usable_region(memmap, hhdm);
|
pmm_find_biggest_usable_region(memmap, hhdm);
|
||||||
//pmm_allocate_bitmap(hhdm); too complicated for my small brain
|
|
||||||
|
|
||||||
// Now we have biggest USABLE region,
|
// Now we have biggest USABLE region,
|
||||||
// so to populate the free list we just iterate through it
|
// so to populate the free list we just iterate through it
|
||||||
|
|||||||
@@ -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);
|
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));
|
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;
|
return current_process->context;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user