Fix braces + init_paging args

This commit is contained in:
2026-03-11 19:58:00 +01:00
parent 9d409317e2
commit 8e2a612d88
29 changed files with 147 additions and 229 deletions

View File

@@ -1,3 +1,9 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Miscellaneous debug features
* @license GPL-3.0-only
*/
#include <kernel.h>
#include "limine.h"
#include "string/string.h"
@@ -9,12 +15,10 @@ void memmap_display(struct limine_memmap_response* response)
{
DEBUG("Got memory map from Limine: revision %u, %u entries", response->revision, response->entry_count);
for (size_t i=0; i<response->entry_count; i++)
{
for (size_t i=0; i<response->entry_count; i++) {
struct limine_memmap_entry* entry = response->entries[i];
char type[32] = {0};
switch(entry->type)
{
switch(entry->type) {
case LIMINE_MEMMAP_USABLE:
strcpy(type, "USABLE");
break;

View File

@@ -1,3 +1,9 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Kernel panic
* @license GPL-3.0-only
*/
#include <stddef.h>
#include "idt/idt.h"
#include "io/serial/serial.h"
@@ -8,8 +14,7 @@ extern struct init_status init;
void panic(struct cpu_status_t* ctx, const char* str)
{
CLEAR_INTERRUPTS;
if (ctx == NULL)
{
if (ctx == NULL) {
DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)");
fctprintf((void*)&skputc, 0, "\x1b[38;5;231m\x1b[48;5;27m");
DIE_DEBUG(str);
@@ -18,8 +23,7 @@ void panic(struct cpu_status_t* ctx, const char* str)
skputc('\n');
DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m");
if (init.terminal)
{
if (init.terminal) {
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);
}
@@ -32,8 +36,7 @@ void panic(struct cpu_status_t* ctx, const char* str)
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);
if (init.terminal)
{
if (init.terminal) {
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,

View File

@@ -1,3 +1,9 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Stack trace tools
* @license GPL-3.0-only
*/
#include <stdint.h>
#include "kernel.h"
@@ -6,45 +12,39 @@ extern struct init_status init;
void debug_stack_trace(unsigned int max_frames)
{
DEBUG("*** begin stack trace ***");
if (init.terminal)
{
if (init.terminal) {
printf("\r\n*** begin stack trace ***\r\n");
}
// Thanks GCC :)
uintptr_t* rbp = (uintptr_t*)__builtin_frame_address(0);
for (unsigned int frame=0; frame<max_frames && rbp != NULL; frame++)
{
for (unsigned int frame=0; frame<max_frames && rbp != NULL; frame++) {
// Return address, 1 word above saved rbp
uintptr_t rip = rbp[1];
uintptr_t offset = 0;
const char* name = debug_find_symbol(rip, &offset);
DEBUG("[%u] <0x%p> (%s+0x%x)", frame, (void*)rip, name, offset);
if (init.terminal)
{
if (init.terminal) {
printf("[%u] <0x%p> (%s+0x%x)\r\n", frame, (void*)rip, name, offset);
}
uintptr_t* next_rbp = (uintptr_t*)rbp[0];
// invalid rbp or we're at the end
if (next_rbp <= rbp || next_rbp == NULL)
{
// Invalid rbp or we're at the end
if (next_rbp <= rbp || next_rbp == NULL) {
break;
}
rbp = next_rbp;
}
if (init.terminal)
{
if (init.terminal) {
printf("*** end stack trace ***");
}
DEBUG("*** end stack trace ***");
}
typedef struct
{
typedef struct {
uint64_t addr;
const char *name;
} __attribute__((packed)) kernel_symbol_t;
@@ -55,8 +55,7 @@ __attribute__((weak)) extern uint64_t symbol_count;
// binary search
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
{
if (!symbol_table || symbol_count == 0)
{
if (!symbol_table || symbol_count == 0) {
if (offset) *offset = 0;
return "???";
}
@@ -64,11 +63,9 @@ const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
int low = 0, high = (int)symbol_count - 1;
int best = -1;
while (low <= high)
{
while (low <= high) {
int mid = (low + high) / 2;
if (symbol_table[mid].addr <= rip)
{
if (symbol_table[mid].addr <= rip) {
best = mid;
low = mid + 1;
} else {
@@ -76,15 +73,15 @@ const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
}
}
if (best != -1)
{
if (offset)
{
if (best != -1) {
if (offset) {
*offset = rip - symbol_table[best].addr;
}
return symbol_table[best].name;
}
if (offset) *offset = 0;
if (offset) {
*offset = 0;
}
return "unknown";
}