2 * linux/arch/ppc64/mm/extable.c
4 * from linux/arch/i386/mm/extable.c
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/spinlock.h>
15 #include <asm/uaccess.h>
17 extern struct exception_table_entry __start___ex_table[];
18 extern struct exception_table_entry __stop___ex_table[];
21 * The exception table needs to be sorted because we use the macros
22 * which put things into the exception table in a variety of segments
23 * as well as the init segment and the main kernel text segment.
26 sort_ex_table(struct exception_table_entry *start,
27 struct exception_table_entry *finish)
29 struct exception_table_entry el, *p, *q;
32 for (p = start + 1; p < finish; ++p) {
33 /* start .. p-1 is sorted */
34 if (p[0].insn < p[-1].insn) {
35 /* move element p down to its right place */
39 /* el comes before q[-1], move q[-1] up one */
42 } while (q > start && el.insn < q[-1].insn);
49 sort_exception_table(void)
51 sort_ex_table(__start___ex_table, __stop___ex_table);
54 static inline unsigned long
55 search_one_table(const struct exception_table_entry *first,
56 const struct exception_table_entry *last,
59 while (first <= last) {
60 const struct exception_table_entry *mid;
63 mid = (last - first) / 2 + first;
64 diff = mid->insn - value;
75 extern spinlock_t modlist_lock;
78 search_exception_table(unsigned long addr)
80 unsigned long ret = 0;
82 #ifndef CONFIG_MODULES
83 /* There is only the kernel to search. */
84 ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
88 /* The kernel is the last "module" -- no need to treat it special. */
91 spin_lock_irqsave(&modlist_lock, flags);
92 for (mp = module_list; mp != NULL; mp = mp->next) {
93 if (mp->ex_table_start == NULL || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
95 ret = search_one_table(mp->ex_table_start,
96 mp->ex_table_end - 1, addr);
100 spin_unlock_irqrestore(&modlist_lock, flags);