bug.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef __ASSEMBLY__
  13. #ifdef CONFIG_BUG
  14. /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
  15. sizeof(struct bug_entry), respectively */
  16. #ifdef CONFIG_DEBUG_BUGVERBOSE
  17. #define _EMIT_BUG_ENTRY \
  18. ".section __bug_table,\"a\"\n" \
  19. "2:\t" PPC_LONG "1b, %0\n" \
  20. "\t.short %1, %2\n" \
  21. ".org 2b+%3\n" \
  22. ".previous\n"
  23. #else
  24. #define _EMIT_BUG_ENTRY \
  25. ".section __bug_table,\"a\"\n" \
  26. "2:\t" PPC_LONG "1b\n" \
  27. "\t.short %2\n" \
  28. ".org 2b+%3\n" \
  29. ".previous\n"
  30. #endif
  31. /*
  32. * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
  33. * optimisations. However depending on the complexity of the condition
  34. * some compiler versions may not produce optimal results.
  35. */
  36. #define BUG() do { \
  37. __asm__ __volatile__( \
  38. "1: twi 31,0,0\n" \
  39. _EMIT_BUG_ENTRY \
  40. : : "i" (__FILE__), "i" (__LINE__), \
  41. "i" (0), "i" (sizeof(struct bug_entry))); \
  42. for(;;) ; \
  43. } while (0)
  44. #define BUG_ON(x) do { \
  45. if (__builtin_constant_p(x)) { \
  46. if (x) \
  47. BUG(); \
  48. } else { \
  49. __asm__ __volatile__( \
  50. "1: "PPC_TLNEI" %4,0\n" \
  51. _EMIT_BUG_ENTRY \
  52. : : "i" (__FILE__), "i" (__LINE__), "i" (0), \
  53. "i" (sizeof(struct bug_entry)), \
  54. "r" ((long)(x))); \
  55. } \
  56. } while (0)
  57. #define __WARN() do { \
  58. __asm__ __volatile__( \
  59. "1: twi 31,0,0\n" \
  60. _EMIT_BUG_ENTRY \
  61. : : "i" (__FILE__), "i" (__LINE__), \
  62. "i" (BUGFLAG_WARNING), \
  63. "i" (sizeof(struct bug_entry))); \
  64. } while (0)
  65. #define WARN_ON(x) ({ \
  66. typeof(x) __ret_warn_on = (x); \
  67. if (__builtin_constant_p(__ret_warn_on)) { \
  68. if (__ret_warn_on) \
  69. __WARN(); \
  70. } else { \
  71. __asm__ __volatile__( \
  72. "1: "PPC_TLNEI" %4,0\n" \
  73. _EMIT_BUG_ENTRY \
  74. : : "i" (__FILE__), "i" (__LINE__), \
  75. "i" (BUGFLAG_WARNING), \
  76. "i" (sizeof(struct bug_entry)), \
  77. "r" (__ret_warn_on)); \
  78. } \
  79. unlikely(__ret_warn_on); \
  80. })
  81. #define HAVE_ARCH_BUG
  82. #define HAVE_ARCH_BUG_ON
  83. #define HAVE_ARCH_WARN_ON
  84. #endif /* CONFIG_BUG */
  85. #endif /* __ASSEMBLY __ */
  86. #include <asm-generic/bug.h>
  87. #endif /* __KERNEL__ */
  88. #endif /* _ASM_POWERPC_BUG_H */