You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
736 B
C

/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
#include <gay/kprintf.h>
#include <gay/ktrace.h>
#include <gay/linker.h>
__naked void ktrace_print(void)
{
__asm__ volatile(
" movq %rbp, %rdi \n"
" jmp ktrace_print_from \n"
);
}
void ktrace_print_from(void *frame)
{
void **rbp = (void **)frame;
kprintf("Stack trace:\n");
/* XXX Rather than spitting out raw addresses, parse the kernel image's
* ELF sections to figure out what the address actually belongs to */
while (rbp >= (void **)image_start && rbp < (void **)image_end) {
/* caller return address is immediately above the stack frame */
kprintf(" %p\n", rbp[1]);
if (rbp[1] >= isr_start && rbp[1] < isr_end)
break;
rbp = *rbp;
}
}