Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_BUG_H |
| 2 | #define _ASM_POWERPC_BUG_H |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 3 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 5 | #include <asm/asm-compat.h> |
Benjamin Herrenschmidt | a58f053 | 2008-12-14 19:44:13 +0000 | [diff] [blame] | 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | /* |
| 8 | * Define an illegal instr to trap on the bug. |
| 9 | * We don't use 0 because that marks the end of a function |
| 10 | * in the ELF ABI. That's "Boo Boo" in case you wonder... |
| 11 | */ |
| 12 | #define BUG_OPCODE .long 0x00b00b00 /* For asm */ |
| 13 | #define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */ |
| 14 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_BUG |
| 16 | |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 17 | #ifdef __ASSEMBLY__ |
Benjamin Herrenschmidt | a58f053 | 2008-12-14 19:44:13 +0000 | [diff] [blame] | 18 | #include <asm/asm-offsets.h> |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 19 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 20 | .macro EMIT_BUG_ENTRY addr,file,line,flags |
| 21 | .section __bug_table,"a" |
| 22 | 5001: PPC_LONG \addr, 5002f |
| 23 | .short \line, \flags |
| 24 | .org 5001b+BUG_ENTRY_SIZE |
| 25 | .previous |
| 26 | .section .rodata,"a" |
| 27 | 5002: .asciz "\file" |
| 28 | .previous |
| 29 | .endm |
| 30 | #else |
Benjamin Herrenschmidt | a58f053 | 2008-12-14 19:44:13 +0000 | [diff] [blame] | 31 | .macro EMIT_BUG_ENTRY addr,file,line,flags |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 32 | .section __bug_table,"a" |
| 33 | 5001: PPC_LONG \addr |
| 34 | .short \flags |
| 35 | .org 5001b+BUG_ENTRY_SIZE |
| 36 | .previous |
| 37 | .endm |
| 38 | #endif /* verbose */ |
| 39 | |
| 40 | #else /* !__ASSEMBLY__ */ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 41 | /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and |
| 42 | sizeof(struct bug_entry), respectively */ |
| 43 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 44 | #define _EMIT_BUG_ENTRY \ |
| 45 | ".section __bug_table,\"a\"\n" \ |
| 46 | "2:\t" PPC_LONG "1b, %0\n" \ |
| 47 | "\t.short %1, %2\n" \ |
| 48 | ".org 2b+%3\n" \ |
| 49 | ".previous\n" |
| 50 | #else |
| 51 | #define _EMIT_BUG_ENTRY \ |
| 52 | ".section __bug_table,\"a\"\n" \ |
| 53 | "2:\t" PPC_LONG "1b\n" \ |
| 54 | "\t.short %2\n" \ |
| 55 | ".org 2b+%3\n" \ |
| 56 | ".previous\n" |
| 57 | #endif |
| 58 | |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 59 | /* |
| 60 | * BUG_ON() and WARN_ON() do their best to cooperate with compile-time |
| 61 | * optimisations. However depending on the complexity of the condition |
| 62 | * some compiler versions may not produce optimal results. |
| 63 | */ |
| 64 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 65 | #define BUG() do { \ |
| 66 | __asm__ __volatile__( \ |
| 67 | "1: twi 31,0,0\n" \ |
| 68 | _EMIT_BUG_ENTRY \ |
| 69 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 70 | "i" (0), "i" (sizeof(struct bug_entry))); \ |
| 71 | for(;;) ; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } while (0) |
| 73 | |
| 74 | #define BUG_ON(x) do { \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 75 | if (__builtin_constant_p(x)) { \ |
| 76 | if (x) \ |
| 77 | BUG(); \ |
| 78 | } else { \ |
| 79 | __asm__ __volatile__( \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 80 | "1: "PPC_TLNEI" %4,0\n" \ |
| 81 | _EMIT_BUG_ENTRY \ |
| 82 | : : "i" (__FILE__), "i" (__LINE__), "i" (0), \ |
| 83 | "i" (sizeof(struct bug_entry)), \ |
Al Viro | 97f1e7f | 2007-07-26 17:35:49 +0100 | [diff] [blame] | 84 | "r" ((__force long)(x))); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 85 | } \ |
| 86 | } while (0) |
| 87 | |
Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 88 | #define __WARN() do { \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 89 | __asm__ __volatile__( \ |
| 90 | "1: twi 31,0,0\n" \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 91 | _EMIT_BUG_ENTRY \ |
| 92 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 93 | "i" (BUGFLAG_WARNING), \ |
| 94 | "i" (sizeof(struct bug_entry))); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } while (0) |
| 96 | |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 97 | #define WARN_ON(x) ({ \ |
Linus Torvalds | 8d4fbcf | 2007-07-31 21:12:07 -0700 | [diff] [blame] | 98 | int __ret_warn_on = !!(x); \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 99 | if (__builtin_constant_p(__ret_warn_on)) { \ |
| 100 | if (__ret_warn_on) \ |
Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 101 | __WARN(); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 102 | } else { \ |
| 103 | __asm__ __volatile__( \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 104 | "1: "PPC_TLNEI" %4,0\n" \ |
| 105 | _EMIT_BUG_ENTRY \ |
| 106 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 107 | "i" (BUGFLAG_WARNING), \ |
| 108 | "i" (sizeof(struct bug_entry)), \ |
| 109 | "r" (__ret_warn_on)); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 110 | } \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 111 | unlikely(__ret_warn_on); \ |
| 112 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #define HAVE_ARCH_BUG |
| 115 | #define HAVE_ARCH_BUG_ON |
| 116 | #define HAVE_ARCH_WARN_ON |
Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 117 | #endif /* __ASSEMBLY __ */ |
Benjamin Herrenschmidt | a58f053 | 2008-12-14 19:44:13 +0000 | [diff] [blame] | 118 | #else |
| 119 | #ifdef __ASSEMBLY__ |
| 120 | .macro EMIT_BUG_ENTRY addr,file,line,flags |
| 121 | .endm |
| 122 | #else /* !__ASSEMBLY__ */ |
| 123 | #define _EMIT_BUG_ENTRY |
| 124 | #endif |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 125 | #endif /* CONFIG_BUG */ |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #include <asm-generic/bug.h> |
| 128 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 129 | #endif /* __KERNEL__ */ |
Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 130 | #endif /* _ASM_POWERPC_BUG_H */ |