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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | /* |
| 7 | * Define an illegal instr to trap on the bug. |
| 8 | * We don't use 0 because that marks the end of a function |
| 9 | * in the ELF ABI. That's "Boo Boo" in case you wonder... |
| 10 | */ |
| 11 | #define BUG_OPCODE .long 0x00b00b00 /* For asm */ |
| 12 | #define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */ |
| 13 | |
| 14 | #ifndef __ASSEMBLY__ |
| 15 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_BUG |
| 17 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame^] | 18 | /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and |
| 19 | sizeof(struct bug_entry), respectively */ |
| 20 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 21 | #define _EMIT_BUG_ENTRY \ |
| 22 | ".section __bug_table,\"a\"\n" \ |
| 23 | "2:\t" PPC_LONG "1b, %0\n" \ |
| 24 | "\t.short %1, %2\n" \ |
| 25 | ".org 2b+%3\n" \ |
| 26 | ".previous\n" |
| 27 | #else |
| 28 | #define _EMIT_BUG_ENTRY \ |
| 29 | ".section __bug_table,\"a\"\n" \ |
| 30 | "2:\t" PPC_LONG "1b\n" \ |
| 31 | "\t.short %2\n" \ |
| 32 | ".org 2b+%3\n" \ |
| 33 | ".previous\n" |
| 34 | #endif |
| 35 | |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 36 | /* |
| 37 | * BUG_ON() and WARN_ON() do their best to cooperate with compile-time |
| 38 | * optimisations. However depending on the complexity of the condition |
| 39 | * some compiler versions may not produce optimal results. |
| 40 | */ |
| 41 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame^] | 42 | #define BUG() do { \ |
| 43 | __asm__ __volatile__( \ |
| 44 | "1: twi 31,0,0\n" \ |
| 45 | _EMIT_BUG_ENTRY \ |
| 46 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 47 | "i" (0), "i" (sizeof(struct bug_entry))); \ |
| 48 | for(;;) ; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } while (0) |
| 50 | |
| 51 | #define BUG_ON(x) do { \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 52 | if (__builtin_constant_p(x)) { \ |
| 53 | if (x) \ |
| 54 | BUG(); \ |
| 55 | } else { \ |
| 56 | __asm__ __volatile__( \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame^] | 57 | "1: "PPC_TLNEI" %4,0\n" \ |
| 58 | _EMIT_BUG_ENTRY \ |
| 59 | : : "i" (__FILE__), "i" (__LINE__), "i" (0), \ |
| 60 | "i" (sizeof(struct bug_entry)), \ |
| 61 | "r" ((long)(x))); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 62 | } \ |
| 63 | } while (0) |
| 64 | |
Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 65 | #define __WARN() do { \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 66 | __asm__ __volatile__( \ |
| 67 | "1: twi 31,0,0\n" \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame^] | 68 | _EMIT_BUG_ENTRY \ |
| 69 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 70 | "i" (BUGFLAG_WARNING), \ |
| 71 | "i" (sizeof(struct bug_entry))); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } while (0) |
| 73 | |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 74 | #define WARN_ON(x) ({ \ |
| 75 | typeof(x) __ret_warn_on = (x); \ |
| 76 | if (__builtin_constant_p(__ret_warn_on)) { \ |
| 77 | if (__ret_warn_on) \ |
Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 78 | __WARN(); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 79 | } else { \ |
| 80 | __asm__ __volatile__( \ |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame^] | 81 | "1: "PPC_TLNEI" %4,0\n" \ |
| 82 | _EMIT_BUG_ENTRY \ |
| 83 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 84 | "i" (BUGFLAG_WARNING), \ |
| 85 | "i" (sizeof(struct bug_entry)), \ |
| 86 | "r" (__ret_warn_on)); \ |
Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 87 | } \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 88 | unlikely(__ret_warn_on); \ |
| 89 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #define HAVE_ARCH_BUG |
| 92 | #define HAVE_ARCH_BUG_ON |
| 93 | #define HAVE_ARCH_WARN_ON |
Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 94 | #endif /* CONFIG_BUG */ |
| 95 | #endif /* __ASSEMBLY __ */ |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #include <asm-generic/bug.h> |
| 98 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 99 | #endif /* __KERNEL__ */ |
Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 100 | #endif /* _ASM_POWERPC_BUG_H */ |