blob: f49f46271ba6c83e0146ab32209acf39255c2c09 [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) \
Paul Mackerras89003eb2005-11-01 21:54:38 +110016 ".llong " #label ", " #line ", " #file ", " #func "\n"
Becky Bruce25433b12005-09-19 17:01:54 -050017#define TRAP_OP(ra, rb) "1: tdnei " #ra ", " #rb "\n"
Becky Bruce25433b12005-09-19 17:01:54 -050018#else
19#define BUG_TABLE_ENTRY(label, line, file, func) \
20 ".long " #label ", " #line ", " #file ", " #func "\n"
21#define TRAP_OP(ra, rb) "1: twnei " #ra ", " #rb "\n"
Becky Bruce25433b12005-09-19 17:01:54 -050022#endif /* __powerpc64__ */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct bug_entry {
25 unsigned long bug_addr;
Paul Mackerras89003eb2005-11-01 21:54:38 +110026 long line;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 const char *file;
28 const char *function;
29};
30
31struct bug_entry *find_bug(unsigned long bugaddr);
32
33/*
34 * If this bit is set in the line number it means that the trap
35 * is for WARN_ON rather than BUG or BUG_ON.
36 */
37#define BUG_WARNING_TRAP 0x1000000
38
Matt Mackallc8538a72005-05-01 08:59:01 -070039#ifdef CONFIG_BUG
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define BUG() do { \
42 __asm__ __volatile__( \
43 "1: twi 31,0,0\n" \
44 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050045 BUG_TABLE_ENTRY(1b,%0,%1,%2) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 ".previous" \
47 : : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \
48} while (0)
49
50#define BUG_ON(x) do { \
51 __asm__ __volatile__( \
Becky Bruce25433b12005-09-19 17:01:54 -050052 TRAP_OP(%0,0) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050054 BUG_TABLE_ENTRY(1b,%1,%2,%3) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 ".previous" \
Al Virof2cad7a2005-11-02 03:10:43 +000056 : : "r" ((long)(x)), "i" (__LINE__), \
Anton Blanchard32818c22005-08-26 18:34:07 -070057 "i" (__FILE__), "i" (__FUNCTION__)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070058} while (0)
59
60#define WARN_ON(x) do { \
61 __asm__ __volatile__( \
Becky Bruce25433b12005-09-19 17:01:54 -050062 TRAP_OP(%0,0) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 ".section __bug_table,\"a\"\n\t" \
Becky Bruce25433b12005-09-19 17:01:54 -050064 BUG_TABLE_ENTRY(1b,%1,%2,%3) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 ".previous" \
Al Virof2cad7a2005-11-02 03:10:43 +000066 : : "r" ((long)(x)), \
Anton Blanchard32818c22005-08-26 18:34:07 -070067 "i" (__LINE__ + BUG_WARNING_TRAP), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 "i" (__FILE__), "i" (__FUNCTION__)); \
69} while (0)
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#define HAVE_ARCH_BUG
72#define HAVE_ARCH_BUG_ON
73#define HAVE_ARCH_WARN_ON
Becky Bruce25433b12005-09-19 17:01:54 -050074#endif /* CONFIG_BUG */
75#endif /* __ASSEMBLY __ */
Matt Mackallc8538a72005-05-01 08:59:01 -070076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include <asm-generic/bug.h>
78
Becky Bruce25433b12005-09-19 17:01:54 -050079#endif /* _ASM_POWERPC_BUG_H */