extable.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. *
  5. * (C) Copyright 2000
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. */
  8. #include <common.h>
  9. /*
  10. * The exception table consists of pairs of addresses: the first is the
  11. * address of an instruction that is allowed to fault, and the second is
  12. * the address at which the program should continue. No registers are
  13. * modified, so it is entirely up to the continuation code to figure out
  14. * what to do.
  15. *
  16. * All the routines below use bits of fixup code that are out of line
  17. * with the main instruction path. This means when everything is well,
  18. * we don't even have to jump over them. Further, they do not intrude
  19. * on our cache or tlb entries.
  20. */
  21. struct exception_table_entry
  22. {
  23. unsigned long insn, fixup;
  24. };
  25. extern const struct exception_table_entry __start___ex_table[];
  26. extern const struct exception_table_entry __stop___ex_table[];
  27. static inline unsigned long
  28. search_one_table(const struct exception_table_entry *first,
  29. const struct exception_table_entry *last,
  30. unsigned long value)
  31. {
  32. long diff;
  33. while (first <= last) {
  34. diff = first->insn - value;
  35. if (diff == 0)
  36. return first->fixup;
  37. first++;
  38. }
  39. return 0;
  40. }
  41. unsigned long
  42. search_exception_table(unsigned long addr)
  43. {
  44. unsigned long ret;
  45. /* There is only the kernel to search. */
  46. ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
  47. /* if the serial port does not hang in exception, printf can be used */
  48. #if !defined(CONFIG_SYS_SERIAL_HANG_IN_EXCEPTION)
  49. debug("Bus Fault @ 0x%08lx, fixup 0x%08lx\n", addr, ret);
  50. #endif
  51. if (ret) return ret;
  52. return 0;
  53. }