bug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef _ASM_POWERPC_BUG_H
  2. #define _ASM_POWERPC_BUG_H
  3. #ifdef __KERNEL__
  4. #include <asm/asm-compat.h>
  5. /*
  6. * Define an illegal instr to trap on the bug.
  7. * We don't use 0 because that marks the end of a function
  8. * in the ELF ABI. That's "Boo Boo" in case you wonder...
  9. */
  10. #define BUG_OPCODE .long 0x00b00b00 /* For asm */
  11. #define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */
  12. #ifdef CONFIG_BUG
  13. #ifdef __ASSEMBLY__
  14. #ifdef CONFIG_DEBUG_BUGVERBOSE
  15. .macro EMIT_BUG_ENTRY addr,file,line,flags
  16. .section __bug_table,"a"
  17. 5001: PPC_LONG \addr, 5002f
  18. .short \line, \flags
  19. .org 5001b+BUG_ENTRY_SIZE
  20. .previous
  21. .section .rodata,"a"
  22. 5002: .asciz "\file"
  23. .previous
  24. .endm
  25. #else
  26. .macro EMIT_BUG_ENTRY addr,file,line,flags
  27. .section __bug_table,"a"
  28. 5001: PPC_LONG \addr
  29. .short \flags
  30. .org 5001b+BUG_ENTRY_SIZE
  31. .previous
  32. .endm
  33. #endif /* verbose */
  34. #else /* !__ASSEMBLY__ */
  35. /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
  36. sizeof(struct bug_entry), respectively */
  37. #ifdef CONFIG_DEBUG_BUGVERBOSE
  38. #define _EMIT_BUG_ENTRY \
  39. ".section __bug_table,\"a\"\n" \
  40. "2:\t" PPC_LONG "1b, %0\n" \
  41. "\t.short %1, %2\n" \
  42. ".org 2b+%3\n" \
  43. ".previous\n"
  44. #else
  45. #define _EMIT_BUG_ENTRY \
  46. ".section __bug_table,\"a\"\n" \
  47. "2:\t" PPC_LONG "1b\n" \
  48. "\t.short %2\n" \
  49. ".org 2b+%3\n" \
  50. ".previous\n"
  51. #endif
  52. /*
  53. * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
  54. * optimisations. However depending on the complexity of the condition
  55. * some compiler versions may not produce optimal results.
  56. */
  57. #define BUG() do { \
  58. __asm__ __volatile__( \
  59. "1: twi 31,0,0\n" \
  60. _EMIT_BUG_ENTRY \
  61. : : "i" (__FILE__), "i" (__LINE__), \
  62. "i" (0), "i" (sizeof(struct bug_entry))); \
  63. for(;;) ; \
  64. } while (0)
  65. #define BUG_ON(x) do { \
  66. if (__builtin_constant_p(x)) { \
  67. if (x) \
  68. BUG(); \
  69. } else { \
  70. __asm__ __volatile__( \
  71. "1: "PPC_TLNEI" %4,0\n" \
  72. _EMIT_BUG_ENTRY \
  73. : : "i" (__FILE__), "i" (__LINE__), "i" (0), \
  74. "i" (sizeof(struct bug_entry)), \
  75. "r" ((__force long)(x))); \
  76. } \
  77. } while (0)
  78. #define __WARN() do { \
  79. __asm__ __volatile__( \
  80. "1: twi 31,0,0\n" \
  81. _EMIT_BUG_ENTRY \
  82. : : "i" (__FILE__), "i" (__LINE__), \
  83. "i" (BUGFLAG_WARNING), \
  84. "i" (sizeof(struct bug_entry))); \
  85. } while (0)
  86. #define WARN_ON(x) ({ \
  87. int __ret_warn_on = !!(x); \
  88. if (__builtin_constant_p(__ret_warn_on)) { \
  89. if (__ret_warn_on) \
  90. __WARN(); \
  91. } else { \
  92. __asm__ __volatile__( \
  93. "1: "PPC_TLNEI" %4,0\n" \
  94. _EMIT_BUG_ENTRY \
  95. : : "i" (__FILE__), "i" (__LINE__), \
  96. "i" (BUGFLAG_WARNING), \
  97. "i" (sizeof(struct bug_entry)), \
  98. "r" (__ret_warn_on)); \
  99. } \
  100. unlikely(__ret_warn_on); \
  101. })
  102. #define HAVE_ARCH_BUG
  103. #define HAVE_ARCH_BUG_ON
  104. #define HAVE_ARCH_WARN_ON
  105. #endif /* __ASSEMBLY __ */
  106. #endif /* CONFIG_BUG */
  107. #include <asm-generic/bug.h>
  108. #endif /* __KERNEL__ */
  109. #endif /* _ASM_POWERPC_BUG_H */