| 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 |  | 
 | 16 | struct bug_entry { | 
 | 17 | 	unsigned long	bug_addr; | 
| Paul Mackerras | 89003eb | 2005-11-01 21:54:38 +1100 | [diff] [blame] | 18 | 	long		line; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | 	const char	*file; | 
 | 20 | 	const char	*function; | 
 | 21 | }; | 
 | 22 |  | 
 | 23 | struct bug_entry *find_bug(unsigned long bugaddr); | 
 | 24 |  | 
 | 25 | /* | 
 | 26 |  * If this bit is set in the line number it means that the trap | 
 | 27 |  * is for WARN_ON rather than BUG or BUG_ON. | 
 | 28 |  */ | 
 | 29 | #define BUG_WARNING_TRAP	0x1000000 | 
 | 30 |  | 
| Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_BUG | 
 | 32 |  | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 33 | /* | 
 | 34 |  * BUG_ON() and WARN_ON() do their best to cooperate with compile-time | 
 | 35 |  * optimisations. However depending on the complexity of the condition | 
 | 36 |  * some compiler versions may not produce optimal results. | 
 | 37 |  */ | 
 | 38 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define BUG() do {							 \ | 
 | 40 | 	__asm__ __volatile__(						 \ | 
 | 41 | 		"1:	twi 31,0,0\n"					 \ | 
| Paul Mackerras | 104dd65 | 2005-11-02 15:19:47 +1100 | [diff] [blame] | 42 | 		".section __bug_table,\"a\"\n"				 \ | 
| Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 43 | 		"\t"PPC_LONG"	1b,%0,%1,%2\n"				 \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | 		".previous"						 \ | 
 | 45 | 		: : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \ | 
 | 46 | } while (0) | 
 | 47 |  | 
 | 48 | #define BUG_ON(x) do {						\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 49 | 	if (__builtin_constant_p(x)) {				\ | 
 | 50 | 		if (x)						\ | 
 | 51 | 			BUG();					\ | 
 | 52 | 	} else {						\ | 
 | 53 | 		__asm__ __volatile__(				\ | 
| David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 54 | 		"1:	"PPC_TLNEI"	%0,0\n"			\ | 
| Paul Mackerras | 104dd65 | 2005-11-02 15:19:47 +1100 | [diff] [blame] | 55 | 		".section __bug_table,\"a\"\n"			\ | 
| Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 56 | 		"\t"PPC_LONG"	1b,%1,%2,%3\n"			\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | 		".previous"					\ | 
| Al Viro | f2cad7a | 2005-11-02 03:10:43 +0000 | [diff] [blame] | 58 | 		: : "r" ((long)(x)), "i" (__LINE__),		\ | 
| Anton Blanchard | 32818c2 | 2005-08-26 18:34:07 -0700 | [diff] [blame] | 59 | 		    "i" (__FILE__), "i" (__FUNCTION__));	\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 60 | 	}							\ | 
 | 61 | } while (0) | 
 | 62 |  | 
| Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 63 | #define __WARN() do {						\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 64 | 	__asm__ __volatile__(					\ | 
 | 65 | 		"1:	twi 31,0,0\n"				\ | 
 | 66 | 		".section __bug_table,\"a\"\n"			\ | 
 | 67 | 		"\t"PPC_LONG"	1b,%0,%1,%2\n"			\ | 
 | 68 | 		".previous"					\ | 
 | 69 | 		: : "i" (__LINE__ + BUG_WARNING_TRAP),		\ | 
 | 70 | 		    "i" (__FILE__), "i" (__FUNCTION__));	\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } while (0) | 
 | 72 |  | 
 | 73 | #define WARN_ON(x) do {						\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 74 | 	if (__builtin_constant_p(x)) {				\ | 
 | 75 | 		if (x)						\ | 
| Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 76 | 			__WARN();				\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 77 | 	} else {						\ | 
 | 78 | 		__asm__ __volatile__(				\ | 
| David Gibson | 3ddfbcf | 2005-11-10 12:56:55 +1100 | [diff] [blame] | 79 | 		"1:	"PPC_TLNEI"	%0,0\n"			\ | 
| Paul Mackerras | 104dd65 | 2005-11-02 15:19:47 +1100 | [diff] [blame] | 80 | 		".section __bug_table,\"a\"\n"			\ | 
| Andrew Morton | 872345b | 2006-03-27 23:42:49 -0800 | [diff] [blame] | 81 | 		"\t"PPC_LONG"	1b,%1,%2,%3\n"			\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | 		".previous"					\ | 
| Al Viro | f2cad7a | 2005-11-02 03:10:43 +0000 | [diff] [blame] | 83 | 		: : "r" ((long)(x)),				\ | 
| Anton Blanchard | 32818c2 | 2005-08-26 18:34:07 -0700 | [diff] [blame] | 84 | 		    "i" (__LINE__ + BUG_WARNING_TRAP),		\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 		    "i" (__FILE__), "i" (__FUNCTION__));	\ | 
| Michael Ellerman | e3f94b8 | 2006-03-23 23:32:24 +1100 | [diff] [blame] | 86 | 	}							\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } while (0) | 
 | 88 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define HAVE_ARCH_BUG | 
 | 90 | #define HAVE_ARCH_BUG_ON | 
 | 91 | #define HAVE_ARCH_WARN_ON | 
| Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 92 | #endif /* CONFIG_BUG */ | 
 | 93 | #endif /* __ASSEMBLY __ */ | 
| Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 94 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #include <asm-generic/bug.h> | 
 | 96 |  | 
| Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 97 | #endif /* __KERNEL__ */ | 
| Becky Bruce | 25433b1 | 2005-09-19 17:01:54 -0500 | [diff] [blame] | 98 | #endif /* _ASM_POWERPC_BUG_H */ |