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