blob: d92f14270ef189fc80fa02f8b0ce2443478c116f [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
3 *
4 * (C) Copyright 2000
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25#include <common.h>
26
27/*
28 * The exception table consists of pairs of addresses: the first is the
29 * address of an instruction that is allowed to fault, and the second is
30 * the address at which the program should continue. No registers are
31 * modified, so it is entirely up to the continuation code to figure out
32 * what to do.
33 *
34 * All the routines below use bits of fixup code that are out of line
35 * with the main instruction path. This means when everything is well,
36 * we don't even have to jump over them. Further, they do not intrude
37 * on our cache or tlb entries.
38 */
39
40struct exception_table_entry
41{
42 unsigned long insn, fixup;
43};
44
45extern const struct exception_table_entry __start___ex_table[];
46extern const struct exception_table_entry __stop___ex_table[];
47
48static inline unsigned long
49search_one_table(const struct exception_table_entry *first,
50 const struct exception_table_entry *last,
51 unsigned long value)
52{
wdenk57b2d802003-06-27 21:31:46 +000053 while (first <= last) {
wdenkfe8c2802002-11-03 00:38:21 +000054 const struct exception_table_entry *mid;
55 long diff;
56
57 mid = (last - first) / 2 + first;
58 diff = mid->insn - value;
wdenk57b2d802003-06-27 21:31:46 +000059 if (diff == 0)
60 return mid->fixup;
61 else if (diff < 0)
62 first = mid+1;
63 else
64 last = mid-1;
65 }
66 return 0;
wdenkfe8c2802002-11-03 00:38:21 +000067}
68
69int ex_tab_message = 1;
70
71unsigned long
72search_exception_table(unsigned long addr)
73{
74 unsigned long ret;
75
76 /* There is only the kernel to search. */
77 ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
78 if (ex_tab_message)
79 printf("Bus Fault @ 0x%08lx, fixup 0x%08lx\n", addr, ret);
80 if (ret) return ret;
81
82 return 0;
83}