extable.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PARISC_EXTABLE_H
  3. #define __PARISC_EXTABLE_H
  4. #include <asm/ptrace.h>
  5. #include <linux/compiler.h>
  6. /*
  7. * The exception table consists of three addresses:
  8. *
  9. * - A relative address to the instruction that is allowed to fault.
  10. * - A relative address at which the program should continue (fixup routine)
  11. * - An asm statement which specifies which CPU register will
  12. * receive -EFAULT when an exception happens if the lowest bit in
  13. * the fixup address is set.
  14. *
  15. * Note: The register specified in the err_opcode instruction will be
  16. * modified at runtime if a fault happens. Register %r0 will be ignored.
  17. *
  18. * Since relative addresses are used, 32bit values are sufficient even on
  19. * 64bit kernel.
  20. */
  21. struct pt_regs;
  22. int fixup_exception(struct pt_regs *regs);
  23. #define ARCH_HAS_RELATIVE_EXTABLE
  24. struct exception_table_entry {
  25. int insn; /* relative address of insn that is allowed to fault. */
  26. int fixup; /* relative address of fixup routine */
  27. int err_opcode; /* sample opcode with register which holds error code */
  28. };
  29. #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr, opcode )\
  30. ".section __ex_table,\"aw\"\n" \
  31. ".align 4\n" \
  32. ".word (" #fault_addr " - .), (" #except_addr " - .)\n" \
  33. opcode "\n" \
  34. ".previous\n"
  35. /*
  36. * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry
  37. * (with lowest bit set) for which the fault handler in fixup_exception() will
  38. * load -EFAULT on fault into the register specified by the err_opcode instruction,
  39. * and zeroes the target register in case of a read fault in get_user().
  40. */
  41. #define ASM_EXCEPTIONTABLE_VAR(__err_var) \
  42. int __err_var = 0
  43. #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr, register )\
  44. ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1, "or %%r0,%%r0," register)
  45. static inline void swap_ex_entry_fixup(struct exception_table_entry *a,
  46. struct exception_table_entry *b,
  47. struct exception_table_entry tmp,
  48. int delta)
  49. {
  50. a->fixup = b->fixup + delta;
  51. b->fixup = tmp.fixup - delta;
  52. a->err_opcode = b->err_opcode;
  53. b->err_opcode = tmp.err_opcode;
  54. }
  55. #define swap_ex_entry_fixup swap_ex_entry_fixup
  56. #endif