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.
39 lines
850 B
C
39 lines
850 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(
|
|
" pushl %ebp \n"
|
|
" call ktrace_print_from \n"
|
|
" ret \n"
|
|
);
|
|
}
|
|
|
|
void ktrace_print_from(void *frame)
|
|
{
|
|
void **ebp = (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 (ebp >= (void **)image_start && ebp < (void **)image_end) {
|
|
/* caller return address is immediately above the stack frame */
|
|
kprintf(" %p\n", ebp[1]);
|
|
if (rbp[1] >= isr_start && rbp[1] < isr_end)
|
|
break;
|
|
rbp = *rbp;
|
|
}
|
|
}
|
|
|
|
__naked void *ktrace_return_addr(void)
|
|
{
|
|
__asm__ volatile(
|
|
" movl 4(%ebp), %eax \n"
|
|
" ret \n"
|
|
);
|
|
}
|