1f15cbe6fSPaul Mundt #ifndef __ASM_SH_BUG_H 2f15cbe6fSPaul Mundt #define __ASM_SH_BUG_H 3f15cbe6fSPaul Mundt 4f15cbe6fSPaul Mundt #define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */ 5f15cbe6fSPaul Mundt 6f15cbe6fSPaul Mundt #ifdef CONFIG_GENERIC_BUG 7f15cbe6fSPaul Mundt #define HAVE_ARCH_BUG 8f15cbe6fSPaul Mundt #define HAVE_ARCH_WARN_ON 9f15cbe6fSPaul Mundt 10f15cbe6fSPaul Mundt /** 11f15cbe6fSPaul Mundt * _EMIT_BUG_ENTRY 12f15cbe6fSPaul Mundt * %1 - __FILE__ 13f15cbe6fSPaul Mundt * %2 - __LINE__ 14f15cbe6fSPaul Mundt * %3 - trap type 15f15cbe6fSPaul Mundt * %4 - sizeof(struct bug_entry) 16f15cbe6fSPaul Mundt * 17f15cbe6fSPaul Mundt * The trapa opcode itself sits in %0. 18f15cbe6fSPaul Mundt * The %O notation is used to avoid # generation. 19f15cbe6fSPaul Mundt * 20f15cbe6fSPaul Mundt * The offending file and line are encoded in the __bug_table section. 21f15cbe6fSPaul Mundt */ 22f15cbe6fSPaul Mundt #ifdef CONFIG_DEBUG_BUGVERBOSE 23f15cbe6fSPaul Mundt #define _EMIT_BUG_ENTRY \ 24f15cbe6fSPaul Mundt "\t.pushsection __bug_table,\"a\"\n" \ 25f15cbe6fSPaul Mundt "2:\t.long 1b, %O1\n" \ 26f15cbe6fSPaul Mundt "\t.short %O2, %O3\n" \ 27f15cbe6fSPaul Mundt "\t.org 2b+%O4\n" \ 28f15cbe6fSPaul Mundt "\t.popsection\n" 29f15cbe6fSPaul Mundt #else 30f15cbe6fSPaul Mundt #define _EMIT_BUG_ENTRY \ 31f15cbe6fSPaul Mundt "\t.pushsection __bug_table,\"a\"\n" \ 32f15cbe6fSPaul Mundt "2:\t.long 1b\n" \ 33f15cbe6fSPaul Mundt "\t.short %O3\n" \ 34f15cbe6fSPaul Mundt "\t.org 2b+%O4\n" \ 35f15cbe6fSPaul Mundt "\t.popsection\n" 36f15cbe6fSPaul Mundt #endif 37f15cbe6fSPaul Mundt 38f15cbe6fSPaul Mundt #define BUG() \ 39f15cbe6fSPaul Mundt do { \ 40f15cbe6fSPaul Mundt __asm__ __volatile__ ( \ 41f15cbe6fSPaul Mundt "1:\t.short %O0\n" \ 42f15cbe6fSPaul Mundt _EMIT_BUG_ENTRY \ 43f15cbe6fSPaul Mundt : \ 44f15cbe6fSPaul Mundt : "n" (TRAPA_BUG_OPCODE), \ 45f15cbe6fSPaul Mundt "i" (__FILE__), \ 46f15cbe6fSPaul Mundt "i" (__LINE__), "i" (0), \ 47f15cbe6fSPaul Mundt "i" (sizeof(struct bug_entry))); \ 48f15cbe6fSPaul Mundt } while (0) 49f15cbe6fSPaul Mundt 50f15cbe6fSPaul Mundt #define __WARN() \ 51f15cbe6fSPaul Mundt do { \ 52f15cbe6fSPaul Mundt __asm__ __volatile__ ( \ 53f15cbe6fSPaul Mundt "1:\t.short %O0\n" \ 54f15cbe6fSPaul Mundt _EMIT_BUG_ENTRY \ 55f15cbe6fSPaul Mundt : \ 56f15cbe6fSPaul Mundt : "n" (TRAPA_BUG_OPCODE), \ 57f15cbe6fSPaul Mundt "i" (__FILE__), \ 58f15cbe6fSPaul Mundt "i" (__LINE__), \ 59f15cbe6fSPaul Mundt "i" (BUGFLAG_WARNING), \ 60f15cbe6fSPaul Mundt "i" (sizeof(struct bug_entry))); \ 61f15cbe6fSPaul Mundt } while (0) 62f15cbe6fSPaul Mundt 63f15cbe6fSPaul Mundt #define WARN_ON(x) ({ \ 64f15cbe6fSPaul Mundt int __ret_warn_on = !!(x); \ 65f15cbe6fSPaul Mundt if (__builtin_constant_p(__ret_warn_on)) { \ 66f15cbe6fSPaul Mundt if (__ret_warn_on) \ 67f15cbe6fSPaul Mundt __WARN(); \ 68f15cbe6fSPaul Mundt } else { \ 69f15cbe6fSPaul Mundt if (unlikely(__ret_warn_on)) \ 70f15cbe6fSPaul Mundt __WARN(); \ 71f15cbe6fSPaul Mundt } \ 72f15cbe6fSPaul Mundt unlikely(__ret_warn_on); \ 73f15cbe6fSPaul Mundt }) 74f15cbe6fSPaul Mundt 75f15cbe6fSPaul Mundt #endif /* CONFIG_GENERIC_BUG */ 76f15cbe6fSPaul Mundt 77f15cbe6fSPaul Mundt #include <asm-generic/bug.h> 78f15cbe6fSPaul Mundt 79f15cbe6fSPaul Mundt #endif /* __ASM_SH_BUG_H */ 80