Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / lib / i386 / backtrace.c
blob7a7796a12ecbe7641d0537056af21089be71a6cb
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/misc.h>
20 #include <grub/command.h>
21 #include <grub/err.h>
22 #include <grub/dl.h>
23 #include <grub/mm.h>
24 #include <grub/term.h>
25 #include <grub/backtrace.h>
27 #define MAX_STACK_FRAME 102400
29 void
30 grub_backtrace_pointer (void *ebp)
32 void *ptr, *nptr;
33 unsigned i;
35 ptr = ebp;
36 while (1)
38 grub_printf ("%p: ", ptr);
39 grub_backtrace_print_address (((void **) ptr)[1]);
40 grub_printf (" (");
41 for (i = 0; i < 2; i++)
42 grub_printf ("%p,", ((void **)ptr) [i + 2]);
43 grub_printf ("%p)\n", ((void **)ptr) [i + 2]);
44 nptr = *(void **)ptr;
45 if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME
46 || nptr == ptr)
48 grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr);
49 break;
51 ptr = nptr;
55 void
56 grub_backtrace (void)
58 #ifdef __x86_64__
59 asm volatile ("movq %rbp, %rdi\n"
60 "call " EXT_C("grub_backtrace_pointer"));
61 #else
62 asm volatile ("movl %ebp, %eax\n"
63 "call " EXT_C("grub_backtrace_pointer"));
64 #endif