| // SPDX-License-Identifier: GPL-2.0-only |
| #include <libcflat.h> |
| #include <stack.h> |
| |
| #ifdef CONFIG_RELOC |
| extern char ImageBase, _text, _etext; |
| |
| bool arch_base_address(const void *rebased_addr, unsigned long *addr) |
| { |
| unsigned long ra = (unsigned long)rebased_addr; |
| unsigned long base = (unsigned long)&ImageBase; |
| unsigned long start = (unsigned long)&_text; |
| unsigned long end = (unsigned long)&_etext; |
| |
| if (ra < start || ra >= end) |
| return false; |
| |
| *addr = ra - base; |
| return true; |
| } |
| #endif |
| |
| int arch_backtrace_frame(const void *frame, const void **return_addrs, |
| int max_depth, bool current_frame) |
| { |
| static bool walking; |
| const unsigned long *fp = (unsigned long *)frame; |
| int depth; |
| |
| if (current_frame) |
| fp = __builtin_frame_address(0); |
| |
| if (walking) { |
| printf("RECURSIVE STACK WALK!!!\n"); |
| return 0; |
| } |
| walking = true; |
| |
| for (depth = 0; fp && depth < max_depth; ++depth) { |
| return_addrs[depth] = (void *)fp[-1]; |
| if (return_addrs[depth] == 0) |
| break; |
| fp = (unsigned long *)fp[-2]; |
| } |
| |
| walking = false; |
| return depth; |
| } |