Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Helper functions for working with the builtin symbol table |
| 3 | * |
| 4 | * Copyright (c) 2008-2009 Analog Devices Inc. |
| 5 | * Licensed under the GPL-2 or later. |
| 6 | */ |
| 7 | |
Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 8 | /* We need the weak marking as this symbol is provided specially */ |
| 9 | extern const char system_map[] __attribute__((weak)); |
| 10 | |
| 11 | /* Given an address, return a pointer to the symbol name and store |
| 12 | * the base address in caddr. So if the symbol map had an entry: |
| 13 | * 03fb9b7c_spi_cs_deactivate |
| 14 | * Then the following call: |
| 15 | * unsigned long base; |
| 16 | * const char *sym = symbol_lookup(0x03fb9b80, &base); |
| 17 | * Would end up setting the variables like so: |
| 18 | * base = 0x03fb9b7c; |
| 19 | * sym = "_spi_cs_deactivate"; |
| 20 | */ |
| 21 | const char *symbol_lookup(unsigned long addr, unsigned long *caddr) |
| 22 | { |
| 23 | const char *sym, *csym; |
| 24 | char *esym; |
| 25 | unsigned long sym_addr; |
| 26 | |
| 27 | sym = system_map; |
| 28 | csym = NULL; |
| 29 | *caddr = 0; |
| 30 | |
| 31 | while (*sym) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 32 | sym_addr = hextoul(sym, &esym); |
Mike Frysinger | a46fbba | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 33 | sym = esym; |
| 34 | if (sym_addr > addr) |
| 35 | break; |
| 36 | *caddr = sym_addr; |
| 37 | csym = sym; |
| 38 | sym += strlen(sym) + 1; |
| 39 | } |
| 40 | |
| 41 | return csym; |
| 42 | } |