bug.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include <asm/asm-offsets.h>
  15. #ifdef CONFIG_DEBUG_BUGVERBOSE
  16. .macro EMIT_BUG_ENTRY addr,file,line,flags
  17. .section __bug_table,"a"
  18. 5001: PPC_LONG \addr, 5002f
  19. .short \line, \flags
  20. .org 5001b+BUG_ENTRY_SIZE
  21. .previous
  22. .section .rodata,"a"
  23. 5002: .asciz "\file"
  24. .previous
  25. .endm
  26. #else
  27. .macro EMIT_BUG_ENTRY addr,file,line,flags
  28. .section __bug_table,"a"
  29. 5001: PPC_LONG \addr
  30. .short \flags
  31. .org 5001b+BUG_ENTRY_SIZE
  32. .previous
  33. .endm
  34. #endif /* verbose */
  35. #else /* !__ASSEMBLY__ */
  36. /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
  37. sizeof(struct bug_entry), respectively */
  38. #ifdef CONFIG_DEBUG_BUGVERBOSE
  39. #define _EMIT_BUG_ENTRY \
  40. ".section __bug_table,\"a\"\n" \
  41. "2:\t" PPC_LONG "1b, %0\n" \
  42. "\t.short %1, %2\n" \
  43. ".org 2b+%3\n" \
  44. ".previous\n"
  45. #else
  46. #define _EMIT_BUG_ENTRY \
  47. ".section __bug_table,\"a\"\n" \
  48. "2:\t" PPC_LONG "1b\n" \
  49. "\t.short %2\n" \
  50. ".org 2b+%3\n" \
  51. ".previous\n"
  52. #endif
  53. /*
  54. * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
  55. * optimisations. However depending on the complexity of the condition
  56. * some compiler versions may not produce optimal results.
  57. */
  58. #define BUG() do { \
  59. __asm__ __volatile__( \
  60. "1: twi 31,0,0\n" \
  61. _EMIT_BUG_ENTRY \
  62. : : "i" (__FILE__), "i" (__LINE__), \
  63. "i" (0), "i" (sizeof(struct bug_entry))); \
  64. unreachable(); \
  65. } while (0)
  66. #define BUG_ON(x) do { \
  67. if (__builtin_constant_p(x)) { \
  68. if (x) \
  69. BUG(); \
  70. } else { \
  71. __asm__ __volatile__( \
  72. "1: "PPC_TLNEI" %4,0\n" \
  73. _EMIT_BUG_ENTRY \
  74. : : "i" (__FILE__), "i" (__LINE__), "i" (0), \
  75. "i" (sizeof(struct bug_entry)), \
  76. "r" ((__force long)(x))); \
  77. } \
  78. } while (0)
  79. #define __WARN_TAINT(taint) do { \
  80. __asm__ __volatile__( \
  81. "1: twi 31,0,0\n" \
  82. _EMIT_BUG_ENTRY \
  83. : : "i" (__FILE__), "i" (__LINE__), \
  84. "i" (BUGFLAG_TAINT(taint)), \
  85. "i" (sizeof(struct bug_entry))); \
  86. } while (0)
  87. #define WARN_ON(x) ({ \
  88. int __ret_warn_on = !!(x); \
  89. if (__builtin_constant_p(__ret_warn_on)) { \
  90. if (__ret_warn_on) \
  91. __WARN(); \
  92. } else { \
  93. __asm__ __volatile__( \
  94. "1: "PPC_TLNEI" %4,0\n" \
  95. _EMIT_BUG_ENTRY \
  96. : : "i" (__FILE__), "i" (__LINE__), \
  97. "i" (BUGFLAG_TAINT(TAINT_WARN)), \
  98. "i" (sizeof(struct bug_entry)), \
  99. "r" (__ret_warn_on)); \
  100. } \
  101. unlikely(__ret_warn_on); \
  102. })
  103. #define HAVE_ARCH_BUG
  104. #define HAVE_ARCH_BUG_ON
  105. #define HAVE_ARCH_WARN_ON
  106. #endif /* __ASSEMBLY __ */
  107. #else
  108. #ifdef __ASSEMBLY__
  109. .macro EMIT_BUG_ENTRY addr,file,line,flags
  110. .endm
  111. #else /* !__ASSEMBLY__ */
  112. #define _EMIT_BUG_ENTRY
  113. #endif
  114. #endif /* CONFIG_BUG */
  115. #include <asm-generic/bug.h>
  116. #ifndef __ASSEMBLY__
  117. struct pt_regs;
  118. extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
  119. extern void bad_page_fault(struct pt_regs *, unsigned long, int);
  120. extern void _exception(int, struct pt_regs *, int, unsigned long);
  121. extern void die(const char *, struct pt_regs *, long);
  122. #endif /* !__ASSEMBLY__ */
  123. #endif /* __KERNEL__ */
  124. #endif /* _ASM_POWERPC_BUG_H */