blob: 49b3897078ae9490295784b1cf625fc847e9722c [file] [log] [blame]
Mike Frysingera46fbba2009-05-20 04:35:14 -04001/*
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 Frysingera46fbba2009-05-20 04:35:14 -04008
9/* We need the weak marking as this symbol is provided specially */
10extern const char system_map[] __attribute__((weak));
11
12/* Given an address, return a pointer to the symbol name and store
13 * the base address in caddr. So if the symbol map had an entry:
14 * 03fb9b7c_spi_cs_deactivate
15 * Then the following call:
16 * unsigned long base;
17 * const char *sym = symbol_lookup(0x03fb9b80, &base);
18 * Would end up setting the variables like so:
19 * base = 0x03fb9b7c;
20 * sym = "_spi_cs_deactivate";
21 */
22const char *symbol_lookup(unsigned long addr, unsigned long *caddr)
23{
24 const char *sym, *csym;
25 char *esym;
26 unsigned long sym_addr;
27
28 sym = system_map;
29 csym = NULL;
30 *caddr = 0;
31
32 while (*sym) {
Simon Glass3ff49ec2021-07-24 09:03:29 -060033 sym_addr = hextoul(sym, &esym);
Mike Frysingera46fbba2009-05-20 04:35:14 -040034 sym = esym;
35 if (sym_addr > addr)
36 break;
37 *caddr = sym_addr;
38 csym = sym;
39 sym += strlen(sym) + 1;
40 }
41
42 return csym;
43}