bug.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef _ASM_X86_BUG_H
  2. #define _ASM_X86_BUG_H
  3. #include <linux/stringify.h>
  4. /*
  5. * Since some emulators terminate on UD2, we cannot use it for WARN.
  6. * Since various instruction decoders disagree on the length of UD1,
  7. * we cannot use it either. So use UD0 for WARN.
  8. *
  9. * (binutils knows about "ud1" but {en,de}codes it as 2 bytes, whereas
  10. * our kernel decoder thinks it takes a ModRM byte, which seems consistent
  11. * with various things like the Intel SDM instruction encoding rules)
  12. */
  13. #define ASM_UD0 ".byte 0x0f, 0xff"
  14. #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
  15. #define ASM_UD2 ".byte 0x0f, 0x0b"
  16. #define INSN_UD0 0xff0f
  17. #define INSN_UD2 0x0b0f
  18. #define LEN_UD0 2
  19. #ifdef CONFIG_GENERIC_BUG
  20. #ifdef CONFIG_X86_32
  21. # define __BUG_REL(val) ".long " __stringify(val)
  22. #else
  23. # define __BUG_REL(val) ".long " __stringify(val) " - 2b"
  24. #endif
  25. #ifdef CONFIG_DEBUG_BUGVERBOSE
  26. #define _BUG_FLAGS(ins, flags) \
  27. do { \
  28. asm volatile("1:\t" ins "\n" \
  29. ".pushsection __bug_table,\"aw\"\n" \
  30. "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
  31. "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
  32. "\t.word %c1" "\t# bug_entry::line\n" \
  33. "\t.word %c2" "\t# bug_entry::flags\n" \
  34. "\t.org 2b+%c3\n" \
  35. ".popsection" \
  36. : : "i" (__FILE__), "i" (__LINE__), \
  37. "i" (flags), \
  38. "i" (sizeof(struct bug_entry))); \
  39. } while (0)
  40. #else /* !CONFIG_DEBUG_BUGVERBOSE */
  41. #define _BUG_FLAGS(ins, flags) \
  42. do { \
  43. asm volatile("1:\t" ins "\n" \
  44. ".pushsection __bug_table,\"aw\"\n" \
  45. "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
  46. "\t.word %c0" "\t# bug_entry::flags\n" \
  47. "\t.org 2b+%c1\n" \
  48. ".popsection" \
  49. : : "i" (flags), \
  50. "i" (sizeof(struct bug_entry))); \
  51. } while (0)
  52. #endif /* CONFIG_DEBUG_BUGVERBOSE */
  53. #else
  54. #define _BUG_FLAGS(ins, flags) asm volatile(ins)
  55. #endif /* CONFIG_GENERIC_BUG */
  56. #define HAVE_ARCH_BUG
  57. #define BUG() \
  58. do { \
  59. _BUG_FLAGS(ASM_UD2, 0); \
  60. unreachable(); \
  61. } while (0)
  62. #define __WARN_FLAGS(flags) _BUG_FLAGS(ASM_UD0, BUGFLAG_WARNING|(flags))
  63. #include <asm-generic/bug.h>
  64. #endif /* _ASM_X86_BUG_H */