bug.h 1.7 KB

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