* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / arch / sparc64 / mm / extable.c
blobb2df0e169ac0763a96e4be2010eacab967cf644a
1 /*
2 * linux/arch/sparc64/mm/extable.c
3 */
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <asm/uaccess.h>
9 extern const struct exception_table_entry __start___ex_table[];
10 extern const struct exception_table_entry __stop___ex_table[];
12 static unsigned long
13 search_one_table(const struct exception_table_entry *start,
14 const struct exception_table_entry *last,
15 unsigned long value, unsigned long *g2)
17 const struct exception_table_entry *first = start;
18 const struct exception_table_entry *mid;
19 long diff = 0;
20 while (first <= last) {
21 mid = (last - first) / 2 + first;
22 diff = mid->insn - value;
23 if (diff == 0) {
24 if (!mid->fixup) {
25 *g2 = 0;
26 return (mid + 1)->fixup;
27 } else
28 return mid->fixup;
29 } else if (diff < 0)
30 first = mid+1;
31 else
32 last = mid-1;
34 if (last->insn < value && !last->fixup && last[1].insn > value) {
35 *g2 = (value - last->insn)/4;
36 return last[1].fixup;
38 if (first > start && first[-1].insn < value
39 && !first[-1].fixup && first->insn < value) {
40 *g2 = (value - first[-1].insn)/4;
41 return first->fixup;
43 return 0;
46 unsigned long
47 search_exception_table(unsigned long addr, unsigned long *g2)
49 unsigned long ret;
51 #ifndef CONFIG_MODULES
52 /* There is only the kernel to search. */
53 ret = search_one_table(__start___ex_table,
54 __stop___ex_table-1, addr, g2);
55 if (ret) return ret;
56 #else
57 /* The kernel is the last "module" -- no need to treat it special. */
58 struct module *mp;
59 for (mp = module_list; mp != NULL; mp = mp->next) {
60 if (mp->ex_table_start == NULL)
61 continue;
62 ret = search_one_table(mp->ex_table_start,
63 mp->ex_table_end-1, addr, g2);
64 if (ret) return ret;
66 #endif
68 return 0;