ia64/xen-unstable

view xen/common/symbols.c @ 12390:e28beea6d228

[IA64] Fix time services of EFI emulation

This patch serializes the execution of following efi.runtimes.
- GetTime
- SetTime
- GetWakeTime
- SetWakeTime

Linux/ia64 uses similar spinlocks in the EFI RTC driver.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author awilliam@xenbuild.aw
date Fri Nov 10 12:03:19 2006 -0700 (2006-11-10)
parents 34452b288046
children 60f91c9f1a24
line source
1 /*
2 * symbols.c: in-kernel printing of symbolic oopses and stack traces.
3 *
4 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
5 *
6 * ChangeLog:
7 *
8 * (25/Aug/2004) Paulo Marques <pmarques@grupopie.com>
9 * Changed the compression method from stem compression to "table lookup"
10 * compression (see tools/symbols.c for a more complete description)
11 */
13 #include <xen/config.h>
14 #include <xen/symbols.h>
15 #include <xen/init.h>
16 #include <xen/lib.h>
17 #include <xen/string.h>
19 extern unsigned long symbols_addresses[];
20 extern unsigned long symbols_num_syms;
21 extern u8 symbols_names[];
23 extern u8 symbols_token_table[];
24 extern u16 symbols_token_index[];
26 extern unsigned long symbols_markers[];
28 /* expand a compressed symbol data into the resulting uncompressed string,
29 given the offset to where the symbol is in the compressed stream */
30 static unsigned int symbols_expand_symbol(unsigned int off, char *result)
31 {
32 int len, skipped_first = 0;
33 u8 *tptr, *data;
35 /* get the compressed symbol length from the first symbol byte */
36 data = &symbols_names[off];
37 len = *data;
38 data++;
40 /* update the offset to return the offset for the next symbol on
41 * the compressed stream */
42 off += len + 1;
44 /* for every byte on the compressed symbol data, copy the table
45 entry for that byte */
46 while(len) {
47 tptr = &symbols_token_table[ symbols_token_index[*data] ];
48 data++;
49 len--;
51 while (*tptr) {
52 if(skipped_first) {
53 *result = *tptr;
54 result++;
55 } else
56 skipped_first = 1;
57 tptr++;
58 }
59 }
61 *result = '\0';
63 /* return to offset to the next symbol */
64 return off;
65 }
67 /* find the offset on the compressed stream given and index in the
68 * symbols array */
69 static unsigned int get_symbol_offset(unsigned long pos)
70 {
71 u8 *name;
72 int i;
74 /* use the closest marker we have. We have markers every 256 positions,
75 * so that should be close enough */
76 name = &symbols_names[ symbols_markers[pos>>8] ];
78 /* sequentially scan all the symbols up to the point we're searching for.
79 * Every symbol is stored in a [<len>][<len> bytes of data] format, so we
80 * just need to add the len to the current pointer for every symbol we
81 * wish to skip */
82 for(i = 0; i < (pos&0xFF); i++)
83 name = name + (*name) + 1;
85 return name - symbols_names;
86 }
88 const char *symbols_lookup(unsigned long addr,
89 unsigned long *symbolsize,
90 unsigned long *offset,
91 char *namebuf)
92 {
93 unsigned long i, low, high, mid;
94 unsigned long symbol_end = 0;
96 /* This kernel should never had been booted. */
97 BUG_ON(!symbols_addresses);
99 namebuf[KSYM_NAME_LEN] = 0;
100 namebuf[0] = 0;
102 if (!is_kernel_text(addr))
103 return NULL;
105 /* do a binary search on the sorted symbols_addresses array */
106 low = 0;
107 high = symbols_num_syms;
109 while (high-low > 1) {
110 mid = (low + high) / 2;
111 if (symbols_addresses[mid] <= addr) low = mid;
112 else high = mid;
113 }
115 /* search for the first aliased symbol. Aliased symbols are
116 symbols with the same address */
117 while (low && symbols_addresses[low - 1] == symbols_addresses[low])
118 --low;
120 /* Grab name */
121 symbols_expand_symbol(get_symbol_offset(low), namebuf);
123 /* Search for next non-aliased symbol */
124 for (i = low + 1; i < symbols_num_syms; i++) {
125 if (symbols_addresses[i] > symbols_addresses[low]) {
126 symbol_end = symbols_addresses[i];
127 break;
128 }
129 }
131 /* if we found no next symbol, we use the end of the section */
132 if (!symbol_end)
133 symbol_end = kernel_text_end();
135 *symbolsize = symbol_end - symbols_addresses[low];
136 *offset = addr - symbols_addresses[low];
137 return namebuf;
138 }
140 /* Replace "%s" in format with address, or returns -errno. */
141 void __print_symbol(const char *fmt, unsigned long address)
142 {
143 const char *name;
144 unsigned long offset, size;
145 char namebuf[KSYM_NAME_LEN+1];
146 char buffer[sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN +
147 2*(BITS_PER_LONG*3/10) + 1];
149 name = symbols_lookup(address, &size, &offset, namebuf);
151 if (!name)
152 sprintf(buffer, "???");
153 else
154 sprintf(buffer, "%s+%#lx/%#lx", name, offset, size);
156 printk(fmt, buffer);
157 }