diff options
author | Anton Kling <anton@kling.gg> | 2023-10-22 19:50:38 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-22 19:50:38 +0200 |
commit | 4e09bca9e34c226b6d7e34b4fa11248405fd988e (patch) | |
tree | 80f156b7940d9d19971395f335530170c69516c7 /log.c |
Move everything into a new repo.
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -0,0 +1,40 @@ +#include "log.h" +#include <sched/scheduler.h> + +struct stackframe { + struct stackframe *ebp; + uint32_t eip; +}; + +void dump_backtrace(uint32_t max_frames) { + struct stackframe *stk; + asm("mov %%ebp,%0" : "=r"(stk)::); + kprintf("Stack trace:\n"); + for (uint32_t frame = 0; stk && frame < max_frames; ++frame) { + kprintf(" 0x%x\n", stk->eip); + stk = stk->ebp; + } + if (get_current_task()) { + kprintf(" PID: %x\n", get_current_task()->pid); + } +} + +void klog(char *str, int code) { + switch (code) { + case LOG_NOTE: + kprintf("[NOTE] "); + break; + case LOG_WARN: + kprintf("[WARN] "); + break; + case LOG_ERROR: + kprintf("[ERROR] "); + break; + default: + case LOG_SUCCESS: + kprintf("[SUCCESS] "); + break; + } + + puts(str); +} |