Proposed patch to kernel.h

From: Paul Mackerras (paulus@samba.org)
Date: Tue May 27 2003 - 17:56:59 EST


Linus,

PowerPC has a conditional trap instruction that I would like to use
for BUG_ON. I would like to make BUG_ON for ppc look like this:

#define BUG_ON(x) do { \
__asm__ __volatile__( \
"1: twnei %0,0\n" \
".section __bug_table,\"a\"\n" \
" .long 1b,%1,%2\n" \
".previous" \
: : "r" (x), "i" (__LINE__), "i" (__FILE__)); \
} while (0)

This avoids a conditional branch and is nice and compact. (The twnei
instruction takes an exception if the register operand is not equal
to the immediate operand - trap word not equal immediate.)

However, at the moment BUG_ON is unconditionally defined in kernel.h.
The patch below is the simplest way I can see to make it possible for
architectures to supply their own BUG_ON. Please apply.

Thanks,
Paul.

diff -urN linux-2.5/include/linux/kernel.h pmac-2.5/include/linux/kernel.h
--- linux-2.5/include/linux/kernel.h 2003-05-21 08:27:25.000000000 +1000
+++ pmac-2.5/include/linux/kernel.h 2003-05-26 22:01:54.000000000 +1000
@@ -228,7 +228,9 @@
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};

+#ifndef BUG_ON
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
+#endif
#define WARN_ON(condition) do { \
if (unlikely((condition)!=0)) { \
printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/