Kernel debugging helpers
[akaros.git] / kern / arch / sparc / kdebug.c
1 #include <arch/sparc.h>
2 #include <arch/arch.h>
3 #include <arch/mmu.h>
4 #include <stdio.h>
5 #include <assert.h>
6 #include <smp.h>
7 #include <umem.h>
8 #include <pmap.h>
9 #include <kdebug.h>
10
11 int debuginfo_eip(uintptr_t eip, struct eipdebuginfo *info)
12 {
13         static bool once = TRUE;
14         if (once) {
15                 warn("Not implemented for sparc");
16                 once = FALSE;
17         }
18         return 0;
19 }
20
21 void backtrace(void)
22 {
23         int i = 0, j;
24
25         flush_windows();
26
27         cprintf("Backtrace:\n");
28
29         // hack: assumes (correctly) we aren't a leaf routine
30         void *sp, *pc, *newsp;
31         __asm__ __volatile__ ("mov %%sp,%0" : "=r"(sp));
32
33         assert(sp >= (void*)KERNBASE);
34
35         newsp = *((void**)sp+14);
36         pc = *((void**)sp+15);
37
38         cprintf("initial sp = %x, newsp = %x, pc = %x\n",sp,newsp,pc);
39         assert(newsp >= (void*)KERNBASE);
40
41         while(newsp)
42         {
43                 cprintf("#%02d [<%x>]:\n",++i,pc);
44                 cprintf("    %%sp: %x   Args:",newsp);
45                 for(j = 8; j < 14; j++)
46                         cprintf(" %x",*((void**)sp+j));
47                 cprintf("\n");
48
49                 sp = newsp;
50
51                 if(sp >= (void*)KERNBASE && (void**)sp+16 > ((void**)0+16))
52                 {
53                         newsp = *((void**)sp+14);
54                         pc = *((void**)sp+15);
55                 }
56                 else if(current)
57                 {
58                         error_t ret;
59                         ret  = memcpy_from_user(current,&newsp,(void**)sp+14,sizeof(void*));
60                         ret |= memcpy_from_user(current,&pc,(void**)sp+15,sizeof(void*));
61                         if(ret)
62                         {
63                                 warn("Backtrace would have caused access exception;"
64                                      "corrupt user stack?");
65                                 break;
66                         }
67                 }
68                 else
69                         break;
70         }
71 }