bug.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef __ASM_SH_BUG_H
  2. #define __ASM_SH_BUG_H
  3. #define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */
  4. #define BUGFLAG_UNWINDER (1 << 1)
  5. #ifdef CONFIG_GENERIC_BUG
  6. #define HAVE_ARCH_BUG
  7. #define HAVE_ARCH_WARN_ON
  8. /**
  9. * _EMIT_BUG_ENTRY
  10. * %1 - __FILE__
  11. * %2 - __LINE__
  12. * %3 - trap type
  13. * %4 - sizeof(struct bug_entry)
  14. *
  15. * The trapa opcode itself sits in %0.
  16. * The %O notation is used to avoid # generation.
  17. *
  18. * The offending file and line are encoded in the __bug_table section.
  19. */
  20. #ifdef CONFIG_DEBUG_BUGVERBOSE
  21. #define _EMIT_BUG_ENTRY \
  22. "\t.pushsection __bug_table,\"a\"\n" \
  23. "2:\t.long 1b, %O1\n" \
  24. "\t.short %O2, %O3\n" \
  25. "\t.org 2b+%O4\n" \
  26. "\t.popsection\n"
  27. #else
  28. #define _EMIT_BUG_ENTRY \
  29. "\t.pushsection __bug_table,\"a\"\n" \
  30. "2:\t.long 1b\n" \
  31. "\t.short %O3\n" \
  32. "\t.org 2b+%O4\n" \
  33. "\t.popsection\n"
  34. #endif
  35. #define BUG() \
  36. do { \
  37. __asm__ __volatile__ ( \
  38. "1:\t.short %O0\n" \
  39. _EMIT_BUG_ENTRY \
  40. : \
  41. : "n" (TRAPA_BUG_OPCODE), \
  42. "i" (__FILE__), \
  43. "i" (__LINE__), "i" (0), \
  44. "i" (sizeof(struct bug_entry))); \
  45. } while (0)
  46. #define __WARN_TAINT(taint) \
  47. do { \
  48. __asm__ __volatile__ ( \
  49. "1:\t.short %O0\n" \
  50. _EMIT_BUG_ENTRY \
  51. : \
  52. : "n" (TRAPA_BUG_OPCODE), \
  53. "i" (__FILE__), \
  54. "i" (__LINE__), \
  55. "i" (BUGFLAG_TAINT(taint)), \
  56. "i" (sizeof(struct bug_entry))); \
  57. } while (0)
  58. #define WARN_ON(x) ({ \
  59. int __ret_warn_on = !!(x); \
  60. if (__builtin_constant_p(__ret_warn_on)) { \
  61. if (__ret_warn_on) \
  62. __WARN(); \
  63. } else { \
  64. if (unlikely(__ret_warn_on)) \
  65. __WARN(); \
  66. } \
  67. unlikely(__ret_warn_on); \
  68. })
  69. #define UNWINDER_BUG() \
  70. do { \
  71. __asm__ __volatile__ ( \
  72. "1:\t.short %O0\n" \
  73. _EMIT_BUG_ENTRY \
  74. : \
  75. : "n" (TRAPA_BUG_OPCODE), \
  76. "i" (__FILE__), \
  77. "i" (__LINE__), \
  78. "i" (BUGFLAG_UNWINDER), \
  79. "i" (sizeof(struct bug_entry))); \
  80. } while (0)
  81. #define UNWINDER_BUG_ON(x) ({ \
  82. int __ret_unwinder_on = !!(x); \
  83. if (__builtin_constant_p(__ret_unwinder_on)) { \
  84. if (__ret_unwinder_on) \
  85. UNWINDER_BUG(); \
  86. } else { \
  87. if (unlikely(__ret_unwinder_on)) \
  88. UNWINDER_BUG(); \
  89. } \
  90. unlikely(__ret_unwinder_on); \
  91. })
  92. #else
  93. #define UNWINDER_BUG BUG
  94. #define UNWINDER_BUG_ON BUG_ON
  95. #endif /* CONFIG_GENERIC_BUG */
  96. #include <asm-generic/bug.h>
  97. #endif /* __ASM_SH_BUG_H */