bug.h 2.7 KB

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