bug.h 3.7 KB

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