bug.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. struct bug_entry {
  14. unsigned long bug_addr;
  15. long line;
  16. const char *file;
  17. const char *function;
  18. };
  19. struct bug_entry *find_bug(unsigned long bugaddr);
  20. /*
  21. * If this bit is set in the line number it means that the trap
  22. * is for WARN_ON rather than BUG or BUG_ON.
  23. */
  24. #define BUG_WARNING_TRAP 0x1000000
  25. #ifdef CONFIG_BUG
  26. /*
  27. * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
  28. * optimisations. However depending on the complexity of the condition
  29. * some compiler versions may not produce optimal results.
  30. */
  31. #define BUG() do { \
  32. __asm__ __volatile__( \
  33. "1: twi 31,0,0\n" \
  34. ".section __bug_table,\"a\"\n" \
  35. "\t"PPC_LONG" 1b,%0,%1,%2\n" \
  36. ".previous" \
  37. : : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \
  38. } while (0)
  39. #define BUG_ON(x) do { \
  40. if (__builtin_constant_p(x)) { \
  41. if (x) \
  42. BUG(); \
  43. } else { \
  44. __asm__ __volatile__( \
  45. "1: "PPC_TLNEI" %0,0\n" \
  46. ".section __bug_table,\"a\"\n" \
  47. "\t"PPC_LONG" 1b,%1,%2,%3\n" \
  48. ".previous" \
  49. : : "r" ((long)(x)), "i" (__LINE__), \
  50. "i" (__FILE__), "i" (__FUNCTION__)); \
  51. } \
  52. } while (0)
  53. #define __WARN() do { \
  54. __asm__ __volatile__( \
  55. "1: twi 31,0,0\n" \
  56. ".section __bug_table,\"a\"\n" \
  57. "\t"PPC_LONG" 1b,%0,%1,%2\n" \
  58. ".previous" \
  59. : : "i" (__LINE__ + BUG_WARNING_TRAP), \
  60. "i" (__FILE__), "i" (__FUNCTION__)); \
  61. } while (0)
  62. #define WARN_ON(x) do { \
  63. if (__builtin_constant_p(x)) { \
  64. if (x) \
  65. __WARN(); \
  66. } else { \
  67. __asm__ __volatile__( \
  68. "1: "PPC_TLNEI" %0,0\n" \
  69. ".section __bug_table,\"a\"\n" \
  70. "\t"PPC_LONG" 1b,%1,%2,%3\n" \
  71. ".previous" \
  72. : : "r" ((long)(x)), \
  73. "i" (__LINE__ + BUG_WARNING_TRAP), \
  74. "i" (__FILE__), "i" (__FUNCTION__)); \
  75. } \
  76. } while (0)
  77. #define HAVE_ARCH_BUG
  78. #define HAVE_ARCH_BUG_ON
  79. #define HAVE_ARCH_WARN_ON
  80. #endif /* CONFIG_BUG */
  81. #endif /* __ASSEMBLY __ */
  82. #include <asm-generic/bug.h>
  83. #endif /* __KERNEL__ */
  84. #endif /* _ASM_POWERPC_BUG_H */