blob: e4d028e8702042d3573117b53241dfda23f48fab [file] [log] [blame]
Becky Bruce25433b12005-09-19 17:01:54 -05001#ifndef _ASM_POWERPC_BUG_H
2#define _ASM_POWERPC_BUG_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/*
5 * Define an illegal instr to trap on the bug.
6 * We don't use 0 because that marks the end of a function
7 * in the ELF ABI. That's "Boo Boo" in case you wonder...
8 */
9#define BUG_OPCODE .long 0x00b00b00 /* For asm */
10#define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */
11
12#ifndef __ASSEMBLY__
13
Becky Bruce25433b12005-09-19 17:01:54 -050014#ifdef __powerpc64__
15#define BUG_TABLE_ENTRY(label, line, file, func) \
16 ".llong " #label "\n .long " #line "\n .llong " #file ", " #func "\n"
17#define TRAP_OP(ra, rb) "1: tdnei " #ra ", " #rb "\n"
18#define DATA_TYPE long long
19#else
20#define BUG_TABLE_ENTRY(label, line, file, func) \
21 ".long " #label ", " #line ", " #file ", " #func "\n"
22#define TRAP_OP(ra, rb) "1: twnei " #ra ", " #rb "\n"
23#define DATA_TYPE int
24#endif /* __powerpc64__ */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct bug_entry {
27 unsigned long bug_addr;
Becky Bruce25433b12005-09-19 17:01:54 -050028 int line;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 const char *file;
30 const char *function;
31};
32
33struct bug_entry *find_bug(unsigned long bugaddr);
34
35/*
36 * If this bit is set in the line number it means that the trap
37 * is for WARN_ON rather than BUG or BUG_ON.
38 */
39#define BUG_WARNING_TRAP 0x1000000
40
Matt Mackallc8538a72005-05-01 08:59:01 -070041#ifdef CONFIG_BUG
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define BUG() do { \
44 __asm__ __volatile__( \
45 "1: twi 31,0,0\n" \
46 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050047 BUG_TABLE_ENTRY(1b,%0,%1,%2) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 ".previous" \
49 : : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \
50} while (0)
51
52#define BUG_ON(x) do { \
53 __asm__ __volatile__( \
Becky Bruce25433b12005-09-19 17:01:54 -050054 TRAP_OP(%0,0) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050056 BUG_TABLE_ENTRY(1b,%1,%2,%3) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 ".previous" \
Becky Bruce25433b12005-09-19 17:01:54 -050058 : : "r" ((DATA_TYPE)(x)), "i" (__LINE__), \
Anton Blanchard32818c22005-08-26 18:34:07 -070059 "i" (__FILE__), "i" (__FUNCTION__)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070060} while (0)
61
62#define WARN_ON(x) do { \
63 __asm__ __volatile__( \
Becky Bruce25433b12005-09-19 17:01:54 -050064 TRAP_OP(%0,0) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050066 BUG_TABLE_ENTRY(1b,%1,%2,%3) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 ".previous" \
Becky Bruce25433b12005-09-19 17:01:54 -050068 : : "r" ((DATA_TYPE)(x)), \
Anton Blanchard32818c22005-08-26 18:34:07 -070069 "i" (__LINE__ + BUG_WARNING_TRAP), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 "i" (__FILE__), "i" (__FUNCTION__)); \
71} while (0)
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define HAVE_ARCH_BUG
74#define HAVE_ARCH_BUG_ON
75#define HAVE_ARCH_WARN_ON
Becky Bruce25433b12005-09-19 17:01:54 -050076#endif /* CONFIG_BUG */
77#endif /* __ASSEMBLY __ */
Matt Mackallc8538a72005-05-01 08:59:01 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm-generic/bug.h>
80
Becky Bruce25433b12005-09-19 17:01:54 -050081#endif /* _ASM_POWERPC_BUG_H */