Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_BUG_H |
| 2 | #define __ASM_SH_BUG_H |
| 3 | |
David Howells | e839ca5 | 2012-03-28 18:30:03 +0100 | [diff] [blame] | 4 | #include <linux/linkage.h> |
| 5 | |
Paul Mundt | 44530c6 | 2007-05-08 12:14:54 +0900 | [diff] [blame] | 6 | #define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */ |
Paul Mundt | e115f2c | 2009-08-22 05:28:25 +0900 | [diff] [blame] | 7 | #define BUGFLAG_UNWINDER (1 << 1) |
Paul Mundt | 44530c6 | 2007-05-08 12:14:54 +0900 | [diff] [blame] | 8 | |
Paul Mundt | e1cd93e | 2007-11-08 18:58:00 +0900 | [diff] [blame] | 9 | #ifdef CONFIG_GENERIC_BUG |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 10 | #define HAVE_ARCH_BUG |
| 11 | #define HAVE_ARCH_WARN_ON |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 12 | |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 13 | /** |
| 14 | * _EMIT_BUG_ENTRY |
| 15 | * %1 - __FILE__ |
| 16 | * %2 - __LINE__ |
| 17 | * %3 - trap type |
| 18 | * %4 - sizeof(struct bug_entry) |
| 19 | * |
| 20 | * The trapa opcode itself sits in %0. |
| 21 | * The %O notation is used to avoid # generation. |
| 22 | * |
| 23 | * The offending file and line are encoded in the __bug_table section. |
| 24 | */ |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 25 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 26 | #define _EMIT_BUG_ENTRY \ |
| 27 | "\t.pushsection __bug_table,\"a\"\n" \ |
| 28 | "2:\t.long 1b, %O1\n" \ |
| 29 | "\t.short %O2, %O3\n" \ |
| 30 | "\t.org 2b+%O4\n" \ |
| 31 | "\t.popsection\n" |
| 32 | #else |
| 33 | #define _EMIT_BUG_ENTRY \ |
| 34 | "\t.pushsection __bug_table,\"a\"\n" \ |
| 35 | "2:\t.long 1b\n" \ |
| 36 | "\t.short %O3\n" \ |
| 37 | "\t.org 2b+%O4\n" \ |
| 38 | "\t.popsection\n" |
| 39 | #endif |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 40 | |
| 41 | #define BUG() \ |
| 42 | do { \ |
| 43 | __asm__ __volatile__ ( \ |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 44 | "1:\t.short %O0\n" \ |
| 45 | _EMIT_BUG_ENTRY \ |
| 46 | : \ |
| 47 | : "n" (TRAPA_BUG_OPCODE), \ |
| 48 | "i" (__FILE__), \ |
| 49 | "i" (__LINE__), "i" (0), \ |
| 50 | "i" (sizeof(struct bug_entry))); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } while (0) |
| 52 | |
Ben Hutchings | b2be052 | 2010-04-03 19:34:56 +0100 | [diff] [blame] | 53 | #define __WARN_TAINT(taint) \ |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 54 | do { \ |
| 55 | __asm__ __volatile__ ( \ |
| 56 | "1:\t.short %O0\n" \ |
| 57 | _EMIT_BUG_ENTRY \ |
| 58 | : \ |
| 59 | : "n" (TRAPA_BUG_OPCODE), \ |
| 60 | "i" (__FILE__), \ |
| 61 | "i" (__LINE__), \ |
Ben Hutchings | b2be052 | 2010-04-03 19:34:56 +0100 | [diff] [blame] | 62 | "i" (BUGFLAG_TAINT(taint)), \ |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 63 | "i" (sizeof(struct bug_entry))); \ |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 64 | } while (0) |
| 65 | |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 66 | #define WARN_ON(x) ({ \ |
Heiko Carstens | fd0cbdd | 2007-08-02 00:18:38 +0200 | [diff] [blame] | 67 | int __ret_warn_on = !!(x); \ |
Paul Mundt | fa69151 | 2007-03-08 19:41:21 +0900 | [diff] [blame] | 68 | if (__builtin_constant_p(__ret_warn_on)) { \ |
| 69 | if (__ret_warn_on) \ |
| 70 | __WARN(); \ |
| 71 | } else { \ |
| 72 | if (unlikely(__ret_warn_on)) \ |
| 73 | __WARN(); \ |
| 74 | } \ |
| 75 | unlikely(__ret_warn_on); \ |
| 76 | }) |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 77 | |
Paul Mundt | e115f2c | 2009-08-22 05:28:25 +0900 | [diff] [blame] | 78 | #define UNWINDER_BUG() \ |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 79 | do { \ |
| 80 | __asm__ __volatile__ ( \ |
| 81 | "1:\t.short %O0\n" \ |
Paul Mundt | e115f2c | 2009-08-22 05:28:25 +0900 | [diff] [blame] | 82 | _EMIT_BUG_ENTRY \ |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 83 | : \ |
Paul Mundt | e115f2c | 2009-08-22 05:28:25 +0900 | [diff] [blame] | 84 | : "n" (TRAPA_BUG_OPCODE), \ |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 85 | "i" (__FILE__), \ |
Paul Mundt | e115f2c | 2009-08-22 05:28:25 +0900 | [diff] [blame] | 86 | "i" (__LINE__), \ |
| 87 | "i" (BUGFLAG_UNWINDER), \ |
Matt Fleming | b344e24a | 2009-08-16 21:54:48 +0100 | [diff] [blame] | 88 | "i" (sizeof(struct bug_entry))); \ |
| 89 | } while (0) |
| 90 | |
| 91 | #define UNWINDER_BUG_ON(x) ({ \ |
| 92 | int __ret_unwinder_on = !!(x); \ |
| 93 | if (__builtin_constant_p(__ret_unwinder_on)) { \ |
| 94 | if (__ret_unwinder_on) \ |
| 95 | UNWINDER_BUG(); \ |
| 96 | } else { \ |
| 97 | if (unlikely(__ret_unwinder_on)) \ |
| 98 | UNWINDER_BUG(); \ |
| 99 | } \ |
| 100 | unlikely(__ret_unwinder_on); \ |
| 101 | }) |
| 102 | |
Paul Mundt | 74db247 | 2009-08-22 05:31:45 +0900 | [diff] [blame] | 103 | #else |
| 104 | |
| 105 | #define UNWINDER_BUG BUG |
| 106 | #define UNWINDER_BUG_ON BUG_ON |
| 107 | |
Paul Mundt | e1cd93e | 2007-11-08 18:58:00 +0900 | [diff] [blame] | 108 | #endif /* CONFIG_GENERIC_BUG */ |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #include <asm-generic/bug.h> |
| 111 | |
David Howells | e839ca5 | 2012-03-28 18:30:03 +0100 | [diff] [blame] | 112 | struct pt_regs; |
| 113 | extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn)); |
| 114 | |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 115 | #endif /* __ASM_SH_BUG_H */ |