File: /usr/src/linux/arch/ia64/mm/extable.c
1 /*
2 * Kernel exception handling table support. Derived from arch/alpha/mm/extable.c.
3 *
4 * Copyright (C) 1998, 1999, 2001 Hewlett-Packard Co
5 * Copyright (C) 1998, 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
6 */
7
8 #include <linux/config.h>
9
10 #include <asm/uaccess.h>
11 #include <asm/module.h>
12
13 extern const struct exception_table_entry __start___ex_table[];
14 extern const struct exception_table_entry __stop___ex_table[];
15
16 static inline const struct exception_table_entry *
17 search_one_table (const struct exception_table_entry *first,
18 const struct exception_table_entry *last,
19 unsigned long ip, unsigned long gp)
20 {
21 while (first <= last) {
22 const struct exception_table_entry *mid;
23 long diff;
24
25 mid = &first[(last - first)/2];
26 diff = (mid->addr + gp) - ip;
27 if (diff == 0)
28 return mid;
29 else if (diff < 0)
30 first = mid + 1;
31 else
32 last = mid - 1;
33 }
34 return 0;
35 }
36
37 #ifndef CONFIG_MODULES
38 register unsigned long main_gp __asm__("gp");
39 #endif
40
41 struct exception_fixup
42 search_exception_table (unsigned long addr)
43 {
44 const struct exception_table_entry *entry;
45 struct exception_fixup fix = { 0 };
46
47 #ifndef CONFIG_MODULES
48 /* There is only the kernel to search. */
49 entry = search_one_table(__start___ex_table, __stop___ex_table - 1, addr, main_gp);
50 if (entry)
51 fix.cont = entry->cont + main_gp;
52 return fix;
53 #else
54 struct archdata *archdata;
55 struct module *mp;
56
57 /* The kernel is the last "module" -- no need to treat it special. */
58 for (mp = module_list; mp ; mp = mp->next) {
59 if (!mp->ex_table_start)
60 continue;
61 archdata = (struct archdata *) mp->archdata_start;
62 entry = search_one_table(mp->ex_table_start, mp->ex_table_end - 1,
63 addr, (unsigned long) archdata->gp);
64 if (entry) {
65 fix.cont = entry->cont + (unsigned long) archdata->gp;
66 return fix;
67 }
68 }
69 #endif
70 return fix;
71 }
72
73 void
74 handle_exception (struct pt_regs *regs, struct exception_fixup fix)
75 {
76 regs->r8 = -EFAULT;
77 if (fix.cont & 4)
78 regs->r9 = 0;
79 regs->cr_iip = (long) fix.cont & ~0xf;
80 ia64_psr(regs)->ri = fix.cont & 0x3; /* set continuation slot number */
81 }
82