1f15cbe6fSPaul Mundt #ifndef __ASM_SH_BUG_H 2f15cbe6fSPaul Mundt #define __ASM_SH_BUG_H 3f15cbe6fSPaul Mundt 4e839ca52SDavid Howells #include <linux/linkage.h> 5e839ca52SDavid Howells 6f15cbe6fSPaul Mundt #define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */ 7e115f2c1SPaul Mundt #define BUGFLAG_UNWINDER (1 << 1) 8f15cbe6fSPaul Mundt 9f15cbe6fSPaul Mundt #ifdef CONFIG_GENERIC_BUG 10f15cbe6fSPaul Mundt #define HAVE_ARCH_BUG 11f15cbe6fSPaul Mundt #define HAVE_ARCH_WARN_ON 12f15cbe6fSPaul Mundt 13f15cbe6fSPaul Mundt /** 14f15cbe6fSPaul Mundt * _EMIT_BUG_ENTRY 15f15cbe6fSPaul Mundt * %1 - __FILE__ 16f15cbe6fSPaul Mundt * %2 - __LINE__ 17f15cbe6fSPaul Mundt * %3 - trap type 18f15cbe6fSPaul Mundt * %4 - sizeof(struct bug_entry) 19f15cbe6fSPaul Mundt * 20f15cbe6fSPaul Mundt * The trapa opcode itself sits in %0. 21f15cbe6fSPaul Mundt * The %O notation is used to avoid # generation. 22f15cbe6fSPaul Mundt * 23f15cbe6fSPaul Mundt * The offending file and line are encoded in the __bug_table section. 24f15cbe6fSPaul Mundt */ 25f15cbe6fSPaul Mundt #ifdef CONFIG_DEBUG_BUGVERBOSE 26f15cbe6fSPaul Mundt #define _EMIT_BUG_ENTRY \ 27f15cbe6fSPaul Mundt "\t.pushsection __bug_table,\"a\"\n" \ 28f15cbe6fSPaul Mundt "2:\t.long 1b, %O1\n" \ 29f15cbe6fSPaul Mundt "\t.short %O2, %O3\n" \ 30f15cbe6fSPaul Mundt "\t.org 2b+%O4\n" \ 31f15cbe6fSPaul Mundt "\t.popsection\n" 32f15cbe6fSPaul Mundt #else 33f15cbe6fSPaul Mundt #define _EMIT_BUG_ENTRY \ 34f15cbe6fSPaul Mundt "\t.pushsection __bug_table,\"a\"\n" \ 35f15cbe6fSPaul Mundt "2:\t.long 1b\n" \ 36f15cbe6fSPaul Mundt "\t.short %O3\n" \ 37f15cbe6fSPaul Mundt "\t.org 2b+%O4\n" \ 38f15cbe6fSPaul Mundt "\t.popsection\n" 39f15cbe6fSPaul Mundt #endif 40f15cbe6fSPaul Mundt 41f15cbe6fSPaul Mundt #define BUG() \ 42f15cbe6fSPaul Mundt do { \ 43f15cbe6fSPaul Mundt __asm__ __volatile__ ( \ 44f15cbe6fSPaul Mundt "1:\t.short %O0\n" \ 45f15cbe6fSPaul Mundt _EMIT_BUG_ENTRY \ 46f15cbe6fSPaul Mundt : \ 47f15cbe6fSPaul Mundt : "n" (TRAPA_BUG_OPCODE), \ 48f15cbe6fSPaul Mundt "i" (__FILE__), \ 49f15cbe6fSPaul Mundt "i" (__LINE__), "i" (0), \ 50f15cbe6fSPaul Mundt "i" (sizeof(struct bug_entry))); \ 51f15cbe6fSPaul Mundt } while (0) 52f15cbe6fSPaul Mundt 5319d43626SPeter Zijlstra #define __WARN_FLAGS(flags) \ 54f15cbe6fSPaul Mundt do { \ 55f15cbe6fSPaul Mundt __asm__ __volatile__ ( \ 56f15cbe6fSPaul Mundt "1:\t.short %O0\n" \ 57f15cbe6fSPaul Mundt _EMIT_BUG_ENTRY \ 58f15cbe6fSPaul Mundt : \ 59f15cbe6fSPaul Mundt : "n" (TRAPA_BUG_OPCODE), \ 60f15cbe6fSPaul Mundt "i" (__FILE__), \ 61f15cbe6fSPaul Mundt "i" (__LINE__), \ 6219d43626SPeter Zijlstra "i" (BUGFLAG_WARNING|(flags)), \ 63f15cbe6fSPaul Mundt "i" (sizeof(struct bug_entry))); \ 64f15cbe6fSPaul Mundt } while (0) 65f15cbe6fSPaul Mundt 66f15cbe6fSPaul Mundt #define WARN_ON(x) ({ \ 67f15cbe6fSPaul Mundt int __ret_warn_on = !!(x); \ 68f15cbe6fSPaul Mundt if (__builtin_constant_p(__ret_warn_on)) { \ 69f15cbe6fSPaul Mundt if (__ret_warn_on) \ 70f15cbe6fSPaul Mundt __WARN(); \ 71f15cbe6fSPaul Mundt } else { \ 72f15cbe6fSPaul Mundt if (unlikely(__ret_warn_on)) \ 73f15cbe6fSPaul Mundt __WARN(); \ 74f15cbe6fSPaul Mundt } \ 75f15cbe6fSPaul Mundt unlikely(__ret_warn_on); \ 76f15cbe6fSPaul Mundt }) 77f15cbe6fSPaul Mundt 78b344e24aSMatt Fleming #define UNWINDER_BUG() \ 79b344e24aSMatt Fleming do { \ 80b344e24aSMatt Fleming __asm__ __volatile__ ( \ 81b344e24aSMatt Fleming "1:\t.short %O0\n" \ 82b344e24aSMatt Fleming _EMIT_BUG_ENTRY \ 83b344e24aSMatt Fleming : \ 84e115f2c1SPaul Mundt : "n" (TRAPA_BUG_OPCODE), \ 85b344e24aSMatt Fleming "i" (__FILE__), \ 86e115f2c1SPaul Mundt "i" (__LINE__), \ 87e115f2c1SPaul Mundt "i" (BUGFLAG_UNWINDER), \ 88b344e24aSMatt Fleming "i" (sizeof(struct bug_entry))); \ 89b344e24aSMatt Fleming } while (0) 90b344e24aSMatt Fleming 91b344e24aSMatt Fleming #define UNWINDER_BUG_ON(x) ({ \ 92b344e24aSMatt Fleming int __ret_unwinder_on = !!(x); \ 93b344e24aSMatt Fleming if (__builtin_constant_p(__ret_unwinder_on)) { \ 94b344e24aSMatt Fleming if (__ret_unwinder_on) \ 95b344e24aSMatt Fleming UNWINDER_BUG(); \ 96b344e24aSMatt Fleming } else { \ 97b344e24aSMatt Fleming if (unlikely(__ret_unwinder_on)) \ 98b344e24aSMatt Fleming UNWINDER_BUG(); \ 99b344e24aSMatt Fleming } \ 100b344e24aSMatt Fleming unlikely(__ret_unwinder_on); \ 101b344e24aSMatt Fleming }) 102b344e24aSMatt Fleming 10374db2479SPaul Mundt #else 10474db2479SPaul Mundt 10574db2479SPaul Mundt #define UNWINDER_BUG BUG 10674db2479SPaul Mundt #define UNWINDER_BUG_ON BUG_ON 10774db2479SPaul Mundt 108f15cbe6fSPaul Mundt #endif /* CONFIG_GENERIC_BUG */ 109f15cbe6fSPaul Mundt 110f15cbe6fSPaul Mundt #include <asm-generic/bug.h> 111f15cbe6fSPaul Mundt 112e839ca52SDavid Howells struct pt_regs; 1135f857bceSPaul Mundt 1145f857bceSPaul Mundt /* arch/sh/kernel/traps.c */ 115e839ca52SDavid Howells extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn)); 1165f857bceSPaul Mundt extern void die_if_kernel(const char *str, struct pt_regs *regs, long err); 1175f857bceSPaul Mundt extern void die_if_no_fixup(const char *str, struct pt_regs *regs, long err); 118e839ca52SDavid Howells 119f15cbe6fSPaul Mundt #endif /* __ASM_SH_BUG_H */ 120