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