This patch moves the definition of BUG_ON from include/linux/kernel.h
into include/asm-*/bug.h so that I can use a conditional-trap
instruction to implement BUG_ON on PowerPC.
Architecture maintainers, this should be completely benign. An ack
would still be appreciated, though. If this will let you improve your
BUG_ON too, please let me know.
Thanks,
Paul.
diff -urN linux-2.5/include/asm-alpha/bug.h pmac-2.5/include/asm-alpha/bug.h
--- linux-2.5/include/asm-alpha/bug.h 2002-02-25 03:51:44.000000000 +1100
+++ pmac-2.5/include/asm-alpha/bug.h 2003-05-28 18:33:23.000000000 +1000
@@ -9,6 +9,8 @@
__asm__ __volatile__("call_pal %0 # bugchk\n\t"".long %1\n\t.8byte %2" \
: : "i" (PAL_bugchk), "i"(__LINE__), "i"(__FILE__))
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
#define PAGE_BUG(page) BUG()
#endif
diff -urN linux-2.5/include/asm-arm/bug.h pmac-2.5/include/asm-arm/bug.h
--- linux-2.5/include/asm-arm/bug.h 2003-02-02 04:15:11.000000000 +1100
+++ pmac-2.5/include/asm-arm/bug.h 2003-05-28 18:33:35.000000000 +1000
@@ -18,4 +18,6 @@
#endif
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
#endif
diff -urN linux-2.5/include/asm-cris/bug.h pmac-2.5/include/asm-cris/bug.h
--- linux-2.5/include/asm-cris/bug.h 2002-01-06 22:46:09.000000000 +1100
+++ pmac-2.5/include/asm-cris/bug.h 2003-05-28 18:33:44.000000000 +1000
@@ -9,4 +9,6 @@
BUG(); \
} while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
#endif
diff -urN linux-2.5/include/asm-h8300/bug.h pmac-2.5/include/asm-h8300/bug.h
--- linux-2.5/include/asm-h8300/bug.h 2003-04-18 05:31:21.000000000 +1000
+++ pmac-2.5/include/asm-h8300/bug.h 2003-05-28 18:34:07.000000000 +1000
@@ -9,4 +9,6 @@
BUG(); \
} while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
#endif
diff -urN linux-2.5/include/asm-i386/bug.h pmac-2.5/include/asm-i386/bug.h
--- linux-2.5/include/asm-i386/bug.h 2003-02-17 10:52:20.000000000 +1100
+++ pmac-2.5/include/asm-i386/bug.h 2003-05-28 18:34:35.000000000 +1000
@@ -19,6 +19,8 @@
#define BUG() __asm__ __volatile__("ud2\n")
#endif
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+
#define PAGE_BUG(page) do { \
BUG(); \
} while (0)
diff -urN linux-2.5/include/asm-ia64/bug.h pmac-2.5/include/asm-ia64/bug.h
--- linux-2.5/include/asm-ia64/bug.h 2002-01-06 22:57:28.000000000 +1100
+++ pmac-2.5/include/asm-ia64/bug.h 2003-05-28 18:34:51.000000000 +1000
@@ -7,6 +7,7 @@
# define ia64_abort() (*(volatile int *) 0 = 0)
#endif
#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); ia64_abort(); } while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
#define PAGE_BUG(page) do { BUG(); } while (0)
#endif
diff -urN linux-2.5/include/asm-m68k/bug.h pmac-2.5/include/asm-m68k/bug.h
--- linux-2.5/include/asm-m68k/bug.h 2002-07-26 06:17:16.000000000 +1000
+++ pmac-2.5/include/asm-m68k/bug.h 2003-05-28 18:35:34.000000000 +1000
@@ -21,6 +21,11 @@
} while (0)
#endif
+#define BUG_ON(condition) do { \
+ if (unlikely((condition)!=0)) \
+ BUG(); \
+} while(0)
+
#define PAGE_BUG(page) do { \
BUG(); \
} while (0)
diff -urN linux-2.5/include/asm-m68knommu/bug.h pmac-2.5/include/asm-m68knommu/bug.h
--- linux-2.5/include/asm-m68knommu/bug.h 2003-01-15 22:04:34.000000000 +1100
+++ pmac-2.5/include/asm-m68knommu/bug.h 2003-05-28 18:35:54.000000000 +1000
@@ -5,6 +5,11 @@
printk("%s(%d): kernel BUG!\n", __FILE__, __LINE__); \
} while (0)
+#define BUG_ON(condition) do { \
+ if (unlikely((condition)!=0)) \
+ BUG(); \
+} while(0)
+
#define PAGE_BUG(page) do { \
BUG(); \
} while (0)
diff -urN linux-2.5/include/asm-mips/bug.h pmac-2.5/include/asm-mips/bug.h
--- linux-2.5/include/asm-mips/bug.h 2002-01-06 22:57:49.000000000 +1100
+++ pmac-2.5/include/asm-mips/bug.h 2003-05-28 18:36:16.000000000 +1000
@@ -3,6 +3,7 @@
#define __ASM_BUG_H
#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); *(int *)0=0; } while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
#define PAGE_BUG(page) do { BUG(); } while (0)
#endif
diff -urN linux-2.5/include/asm-mips64/bug.h pmac-2.5/include/asm-mips64/bug.h
--- linux-2.5/include/asm-mips64/bug.h 2002-01-06 22:51:12.000000000 +1100
+++ pmac-2.5/include/asm-mips64/bug.h 2003-05-28 18:36:23.000000000 +1000
@@ -2,6 +2,7 @@
#define _ASM_BUG_H
#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); *(int *)0=0; } while (0)
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
#define PAGE_BUG(page) do { BUG(); } while (0)
#endif
diff -urN linux-2.5/include/asm-parisc/bug.h pmac-2.5/include/asm-parisc/bug.h
--- linux-2.5/include/asm-parisc/bug.h 2003-03-18 04:58:50.000000000 +1100
+++ pmac-2.5/include/asm-parisc/bug.h 2003-05-28 18:36:42.000000000 +1000
@@ -10,6 +10,11 @@
dump_stack(); \
} while (0)
+#define BUG_ON(condition) do { \
+ if (unlikely((condition)!=0)) \
+ BUG(); \
+} while(0)
+
#define PAGE_BUG(page) do { \
BUG(); \
} while (0)
diff -urN linux-2.5/include/asm-ppc/bug.h pmac-2.5/include/asm-ppc/bug.h
--- linux-2.5/include/asm-ppc/bug.h 2003-05-26 22:18:59.000000000 +1000
+++ pmac-2.5/include/asm-ppc/bug.h 2003-05-27 11:24:03.000000000 +1000
@@ -1,9 +1,28 @@
#ifndef _PPC_BUG_H
#define _PPC_BUG_H
-#define BUG() do { \
- printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
- __asm__ __volatile__(".long 0x0"); \
+struct bug_entry {
+ unsigned long bug_addr;
+ int line;
+ const char *file;
+};
+
+#define BUG() do { \
+ __asm__ __volatile__( \
+ "1: twi 31,0,0\n" \
+ ".section __bug_table,\"a\"\n\t" \
+ " .long 1b,%0,%1\n" \
+ ".previous" \
+ : : "i" (__LINE__), "i" (__FILE__)); \
+} while (0)
+
+#define BUG_ON(x) do { \
+ __asm__ __volatile__( \
+ "1: twnei %0,0\n" \
+ ".section __bug_table,\"a\"\n\t" \
+ " .long 1b,%1,%2\n" \
+ ".previous" \
+ : : "r" (x), "i" (__LINE__), "i" (__FILE__))