bug.h 2.8 KB

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