extable.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * The exception table consists of pairs of addresses: the first is the
  28. * address of an instruction that is allowed to fault, and the second is
  29. * the address at which the program should continue. No registers are
  30. * modified, so it is entirely up to the continuation code to figure out
  31. * what to do.
  32. *
  33. * All the routines below use bits of fixup code that are out of line
  34. * with the main instruction path. This means when everything is well,
  35. * we don't even have to jump over them. Further, they do not intrude
  36. * on our cache or tlb entries.
  37. */
  38. DECLARE_GLOBAL_DATA_PTR;
  39. struct exception_table_entry
  40. {
  41. unsigned long insn, fixup;
  42. };
  43. extern const struct exception_table_entry __start___ex_table[];
  44. extern const struct exception_table_entry __stop___ex_table[];
  45. static inline unsigned long
  46. search_one_table(const struct exception_table_entry *first,
  47. const struct exception_table_entry *last,
  48. unsigned long value)
  49. {
  50. long diff;
  51. while (first <= last) {
  52. diff = first->insn - value;
  53. if (diff == 0)
  54. return first->fixup;
  55. first++;
  56. }
  57. return 0;
  58. }
  59. int ex_tab_message = 1;
  60. unsigned long
  61. search_exception_table(unsigned long addr)
  62. {
  63. unsigned long ret;
  64. /* There is only the kernel to search. */
  65. ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
  66. /* if the serial port does not hang in exception, printf can be used */
  67. #if !defined(CONFIG_SYS_SERIAL_HANG_IN_EXCEPTION)
  68. if (ex_tab_message)
  69. debug("Bus Fault @ 0x%08lx, fixup 0x%08lx\n", addr, ret);
  70. #endif
  71. if (ret) return ret;
  72. return 0;
  73. }