extable.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * linux/arch/sparc64/mm/extable.c
  3. */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <asm/uaccess.h>
  7. extern const struct exception_table_entry __start___ex_table[];
  8. extern const struct exception_table_entry __stop___ex_table[];
  9. void sort_extable(struct exception_table_entry *start,
  10. struct exception_table_entry *finish)
  11. {
  12. }
  13. /* Caller knows they are in a range if ret->fixup == 0 */
  14. const struct exception_table_entry *
  15. search_extable(const struct exception_table_entry *start,
  16. const struct exception_table_entry *last,
  17. unsigned long value)
  18. {
  19. const struct exception_table_entry *walk;
  20. /* Single insn entries are encoded as:
  21. * word 1: insn address
  22. * word 2: fixup code address
  23. *
  24. * Range entries are encoded as:
  25. * word 1: first insn address
  26. * word 2: 0
  27. * word 3: last insn address + 4 bytes
  28. * word 4: fixup code address
  29. *
  30. * See asm/uaccess.h for more details.
  31. */
  32. /* 1. Try to find an exact match. */
  33. for (walk = start; walk <= last; walk++) {
  34. if (walk->fixup == 0) {
  35. /* A range entry, skip both parts. */
  36. walk++;
  37. continue;
  38. }
  39. if (walk->insn == value)
  40. return walk;
  41. }
  42. /* 2. Try to find a range match. */
  43. for (walk = start; walk <= (last - 1); walk++) {
  44. if (walk->fixup)
  45. continue;
  46. if (walk[0].insn <= value && walk[1].insn > value)
  47. return walk;
  48. walk++;
  49. }
  50. return NULL;
  51. }
  52. /* Special extable search, which handles ranges. Returns fixup */
  53. unsigned long search_extables_range(unsigned long addr, unsigned long *g2)
  54. {
  55. const struct exception_table_entry *entry;
  56. entry = search_exception_tables(addr);
  57. if (!entry)
  58. return 0;
  59. /* Inside range? Fix g2 and return correct fixup */
  60. if (!entry->fixup) {
  61. *g2 = (addr - entry->insn) / 4;
  62. return (entry + 1)->fixup;
  63. }
  64. return entry->fixup;
  65. }