driver: add dev_name inline
[barebox-mini2440.git] / common / kallsyms.c
blob4069f4b701b7cc7631083528e835e732051a5337
1 #include <common.h>
2 #include <init.h>
3 #include <kallsyms.h>
5 /* These will be re-linked against their real values during the second link stage */
6 extern const unsigned long kallsyms_addresses[] __attribute__((weak));
7 extern const unsigned long kallsyms_num_syms __attribute__((weak));
8 extern const u8 kallsyms_names[] __attribute__((weak));
10 extern const u8 kallsyms_token_table[] __attribute__((weak));
11 extern const u16 kallsyms_token_index[] __attribute__((weak));
13 extern const unsigned long kallsyms_markers[] __attribute__((weak));
15 /* expand a compressed symbol data into the resulting uncompressed string,
16 given the offset to where the symbol is in the compressed stream */
17 static unsigned int kallsyms_expand_symbol(unsigned int off, char *result)
19 int len, skipped_first = 0;
20 const u8 *tptr, *data;
22 /* get the compressed symbol length from the first symbol byte */
23 data = &kallsyms_names[off];
24 len = *data;
25 data++;
27 /* update the offset to return the offset for the next symbol on
28 * the compressed stream */
29 off += len + 1;
31 /* for every byte on the compressed symbol data, copy the table
32 entry for that byte */
33 while(len) {
34 tptr = &kallsyms_token_table[ kallsyms_token_index[*data] ];
35 data++;
36 len--;
38 while (*tptr) {
39 if(skipped_first) {
40 *result = *tptr;
41 result++;
42 } else
43 skipped_first = 1;
44 tptr++;
48 *result = '\0';
50 /* return to offset to the next symbol */
51 return off;
54 /* Lookup the address for this symbol. Returns 0 if not found. */
55 unsigned long kallsyms_lookup_name(const char *name)
57 char namebuf[KSYM_NAME_LEN];
58 unsigned long i;
59 unsigned int off;
61 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
62 off = kallsyms_expand_symbol(off, namebuf);
64 if (strcmp(namebuf, name) == 0)
65 return kallsyms_addresses[i];
67 // return module_kallsyms_lookup_name(name);
68 return 0;