2 * Kernel exception handling table support. Derived from arch/alpha/mm/extable.c.
4 * Copyright (C) 1998, 1999, 2001-2002, 2004 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
8 #include <linux/config.h>
10 #include <asm/uaccess.h>
11 #include <asm/module.h>
14 compare_entries (struct exception_table_entry *l, struct exception_table_entry *r)
16 u64 lip = (u64) &l->addr + l->addr;
17 u64 rip = (u64) &r->addr + r->addr;
28 swap_entries (struct exception_table_entry *l, struct exception_table_entry *r)
30 u64 delta = (u64) r - (u64) l;
31 struct exception_table_entry tmp;
34 l->addr = r->addr + delta;
35 l->cont = r->cont + delta;
36 r->addr = tmp.addr - delta;
37 r->cont = tmp.cont - delta;
41 * Sort the exception table. It's usually already sorted, but there may be unordered
42 * entries due to multiple text sections (such as the .init text section). Note that the
43 * exception-table-entries contain location-relative addresses, which requires a bit of
44 * care during sorting to avoid overflows in the offset members (e.g., it would not be
45 * safe to make a temporary copy of an exception-table entry on the stack, because the
46 * stack may be more than 2GB away from the exception-table).
49 sort_extable (struct exception_table_entry *start, struct exception_table_entry *finish)
51 struct exception_table_entry *p, *q;
54 for (p = start + 1; p < finish; ++p)
55 /* start .. p-1 is sorted; push p down to it's proper place */
56 for (q = p; q > start && compare_entries(&q[0], &q[-1]) < 0; --q)
57 swap_entries(&q[0], &q[-1]);
60 const struct exception_table_entry *
61 search_extable (const struct exception_table_entry *first,
62 const struct exception_table_entry *last,
65 const struct exception_table_entry *mid;
69 while (first <= last) {
70 mid = &first[(last - first)/2];
71 mid_ip = (u64) &mid->addr + mid->addr;
84 ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e)
86 long fix = (u64) &e->cont + e->cont;
91 regs->cr_iip = fix & ~0xf;
92 ia64_psr(regs)->ri = fix & 0x3; /* set continuation slot number */