bug.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_BUG_H
  3. #define _ASM_X86_BUG_H
  4. #include <linux/stringify.h>
  5. #ifndef __ASSEMBLY__
  6. /*
  7. * Despite that some emulators terminate on UD2, we use it for WARN().
  8. *
  9. * Since various instruction decoders/specs disagree on the encoding of
  10. * UD0/UD1.
  11. */
  12. #define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
  13. #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
  14. #define ASM_UD2 ".byte 0x0f, 0x0b"
  15. #define INSN_UD0 0xff0f
  16. #define INSN_UD2 0x0b0f
  17. #define LEN_UD2 2
  18. #define _BUG_FLAGS(ins, flags) \
  19. do { \
  20. asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 " \
  21. "flags=%c2 size=%c3" \
  22. : : "i" (__FILE__), "i" (__LINE__), \
  23. "i" (flags), \
  24. "i" (sizeof(struct bug_entry))); \
  25. } while (0)
  26. #define HAVE_ARCH_BUG
  27. #define BUG() \
  28. do { \
  29. _BUG_FLAGS(ASM_UD2, 0); \
  30. unreachable(); \
  31. } while (0)
  32. #define __WARN_FLAGS(flags) \
  33. do { \
  34. _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
  35. annotate_reachable(); \
  36. } while (0)
  37. #include <asm-generic/bug.h>
  38. #else /* __ASSEMBLY__ */
  39. #ifdef CONFIG_GENERIC_BUG
  40. #ifdef CONFIG_X86_32
  41. .macro __BUG_REL val:req
  42. .long \val
  43. .endm
  44. #else
  45. .macro __BUG_REL val:req
  46. .long \val - 2b
  47. .endm
  48. #endif
  49. #ifdef CONFIG_DEBUG_BUGVERBOSE
  50. .macro ASM_BUG ins:req file:req line:req flags:req size:req
  51. 1: \ins
  52. .pushsection __bug_table,"aw"
  53. 2: __BUG_REL val=1b # bug_entry::bug_addr
  54. __BUG_REL val=\file # bug_entry::file
  55. .word \line # bug_entry::line
  56. .word \flags # bug_entry::flags
  57. .org 2b+\size
  58. .popsection
  59. .endm
  60. #else /* !CONFIG_DEBUG_BUGVERBOSE */
  61. .macro ASM_BUG ins:req file:req line:req flags:req size:req
  62. 1: \ins
  63. .pushsection __bug_table,"aw"
  64. 2: __BUG_REL val=1b # bug_entry::bug_addr
  65. .word \flags # bug_entry::flags
  66. .org 2b+\size
  67. .popsection
  68. .endm
  69. #endif /* CONFIG_DEBUG_BUGVERBOSE */
  70. #else /* CONFIG_GENERIC_BUG */
  71. .macro ASM_BUG ins:req file:req line:req flags:req size:req
  72. \ins
  73. .endm
  74. #endif /* CONFIG_GENERIC_BUG */
  75. #endif /* __ASSEMBLY__ */
  76. #endif /* _ASM_X86_BUG_H */