wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
roy zang | c2db5cf | 2006-12-04 17:56:59 +0800 | [diff] [blame] | 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 42 | struct exception_table_entry |
| 43 | { |
| 44 | unsigned long insn, fixup; |
| 45 | }; |
| 46 | |
| 47 | extern const struct exception_table_entry __start___ex_table[]; |
| 48 | extern const struct exception_table_entry __stop___ex_table[]; |
| 49 | |
| 50 | static inline unsigned long |
| 51 | search_one_table(const struct exception_table_entry *first, |
| 52 | const struct exception_table_entry *last, |
| 53 | unsigned long value) |
| 54 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | while (first <= last) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 56 | const struct exception_table_entry *mid; |
| 57 | long diff; |
| 58 | |
| 59 | mid = (last - first) / 2 + first; |
Wolfgang Denk | 34128aa | 2007-04-20 17:43:28 +0200 | [diff] [blame] | 60 | if ((ulong) mid > CFG_MONITOR_BASE) { |
| 61 | /* exception occurs in FLASH, before u-boot relocation. |
| 62 | * No relocation offset is needed. |
| 63 | */ |
roy zang | 373baf4 | 2006-12-01 19:01:25 +0800 | [diff] [blame] | 64 | diff = mid->insn - value; |
| 65 | if (diff == 0) |
| 66 | return mid->fixup; |
| 67 | } else { |
Wolfgang Denk | 34128aa | 2007-04-20 17:43:28 +0200 | [diff] [blame] | 68 | /* exception occurs in RAM, after u-boot relocation. |
| 69 | * A relocation offset should be added. |
| 70 | */ |
roy zang | 373baf4 | 2006-12-01 19:01:25 +0800 | [diff] [blame] | 71 | diff = (mid->insn + gd->reloc_off) - value; |
| 72 | if (diff == 0) |
| 73 | return (mid->fixup + gd->reloc_off); |
| 74 | } |
| 75 | if (diff < 0) |
Wolfgang Denk | 34128aa | 2007-04-20 17:43:28 +0200 | [diff] [blame] | 76 | first = mid + 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | else |
Wolfgang Denk | 34128aa | 2007-04-20 17:43:28 +0200 | [diff] [blame] | 78 | last = mid - 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | } |
| 80 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | int ex_tab_message = 1; |
| 84 | |
| 85 | unsigned long |
| 86 | search_exception_table(unsigned long addr) |
| 87 | { |
| 88 | unsigned long ret; |
| 89 | |
| 90 | /* There is only the kernel to search. */ |
| 91 | ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr); |
roy zang | 373baf4 | 2006-12-01 19:01:25 +0800 | [diff] [blame] | 92 | /* if the serial port does not hang in exception, printf can be used */ |
roy zang | d136d66 | 2006-11-02 18:49:51 +0800 | [diff] [blame] | 93 | #if !defined(CFG_SERIAL_HANG_IN_EXCEPTION) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 94 | if (ex_tab_message) |
| 95 | printf("Bus Fault @ 0x%08lx, fixup 0x%08lx\n", addr, ret); |
roy zang | d136d66 | 2006-11-02 18:49:51 +0800 | [diff] [blame] | 96 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 97 | if (ret) return ret; |
| 98 | |
| 99 | return 0; |
| 100 | } |