blob: d02c01b3e6b9fd899e2d09a5518f12beefa44c76 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_BUG_H
2#define __ASM_SH_BUG_H
3
Paul Mundt44530c62007-05-08 12:14:54 +09004#define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */
Paul Mundte115f2c2009-08-22 05:28:25 +09005#define BUGFLAG_UNWINDER (1 << 1)
Paul Mundt44530c62007-05-08 12:14:54 +09006
Paul Mundte1cd93e2007-11-08 18:58:00 +09007#ifdef CONFIG_GENERIC_BUG
Paul Mundtfa691512007-03-08 19:41:21 +09008#define HAVE_ARCH_BUG
9#define HAVE_ARCH_WARN_ON
Paul Mundtdc34d312006-12-08 17:41:43 +090010
Paul Mundtfa691512007-03-08 19:41:21 +090011/**
12 * _EMIT_BUG_ENTRY
13 * %1 - __FILE__
14 * %2 - __LINE__
15 * %3 - trap type
16 * %4 - sizeof(struct bug_entry)
17 *
18 * The trapa opcode itself sits in %0.
19 * The %O notation is used to avoid # generation.
20 *
21 * The offending file and line are encoded in the __bug_table section.
22 */
Paul Mundtdc34d312006-12-08 17:41:43 +090023#ifdef CONFIG_DEBUG_BUGVERBOSE
Paul Mundtfa691512007-03-08 19:41:21 +090024#define _EMIT_BUG_ENTRY \
25 "\t.pushsection __bug_table,\"a\"\n" \
26 "2:\t.long 1b, %O1\n" \
27 "\t.short %O2, %O3\n" \
28 "\t.org 2b+%O4\n" \
29 "\t.popsection\n"
30#else
31#define _EMIT_BUG_ENTRY \
32 "\t.pushsection __bug_table,\"a\"\n" \
33 "2:\t.long 1b\n" \
34 "\t.short %O3\n" \
35 "\t.org 2b+%O4\n" \
36 "\t.popsection\n"
37#endif
Paul Mundtdc34d312006-12-08 17:41:43 +090038
39#define BUG() \
40do { \
41 __asm__ __volatile__ ( \
Paul Mundtfa691512007-03-08 19:41:21 +090042 "1:\t.short %O0\n" \
43 _EMIT_BUG_ENTRY \
44 : \
45 : "n" (TRAPA_BUG_OPCODE), \
46 "i" (__FILE__), \
47 "i" (__LINE__), "i" (0), \
48 "i" (sizeof(struct bug_entry))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070049} while (0)
50
Paul Mundtfa691512007-03-08 19:41:21 +090051#define __WARN() \
52do { \
53 __asm__ __volatile__ ( \
54 "1:\t.short %O0\n" \
55 _EMIT_BUG_ENTRY \
56 : \
57 : "n" (TRAPA_BUG_OPCODE), \
58 "i" (__FILE__), \
59 "i" (__LINE__), \
60 "i" (BUGFLAG_WARNING), \
61 "i" (sizeof(struct bug_entry))); \
Paul Mundtdc34d312006-12-08 17:41:43 +090062} while (0)
63
Paul Mundtfa691512007-03-08 19:41:21 +090064#define WARN_ON(x) ({ \
Heiko Carstensfd0cbdd2007-08-02 00:18:38 +020065 int __ret_warn_on = !!(x); \
Paul Mundtfa691512007-03-08 19:41:21 +090066 if (__builtin_constant_p(__ret_warn_on)) { \
67 if (__ret_warn_on) \
68 __WARN(); \
69 } else { \
70 if (unlikely(__ret_warn_on)) \
71 __WARN(); \
72 } \
73 unlikely(__ret_warn_on); \
74})
Paul Mundtdc34d312006-12-08 17:41:43 +090075
Paul Mundte115f2c2009-08-22 05:28:25 +090076#define UNWINDER_BUG() \
Matt Flemingb344e242009-08-16 21:54:48 +010077do { \
78 __asm__ __volatile__ ( \
79 "1:\t.short %O0\n" \
Paul Mundte115f2c2009-08-22 05:28:25 +090080 _EMIT_BUG_ENTRY \
Matt Flemingb344e242009-08-16 21:54:48 +010081 : \
Paul Mundte115f2c2009-08-22 05:28:25 +090082 : "n" (TRAPA_BUG_OPCODE), \
Matt Flemingb344e242009-08-16 21:54:48 +010083 "i" (__FILE__), \
Paul Mundte115f2c2009-08-22 05:28:25 +090084 "i" (__LINE__), \
85 "i" (BUGFLAG_UNWINDER), \
Matt Flemingb344e242009-08-16 21:54:48 +010086 "i" (sizeof(struct bug_entry))); \
87} while (0)
88
89#define UNWINDER_BUG_ON(x) ({ \
90 int __ret_unwinder_on = !!(x); \
91 if (__builtin_constant_p(__ret_unwinder_on)) { \
92 if (__ret_unwinder_on) \
93 UNWINDER_BUG(); \
94 } else { \
95 if (unlikely(__ret_unwinder_on)) \
96 UNWINDER_BUG(); \
97 } \
98 unlikely(__ret_unwinder_on); \
99})
100
Paul Mundt74db2472009-08-22 05:31:45 +0900101#else
102
103#define UNWINDER_BUG BUG
104#define UNWINDER_BUG_ON BUG_ON
105
Paul Mundte1cd93e2007-11-08 18:58:00 +0900106#endif /* CONFIG_GENERIC_BUG */
Matt Mackallc8538a72005-05-01 08:59:01 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#include <asm-generic/bug.h>
109
Paul Mundtdc34d312006-12-08 17:41:43 +0900110#endif /* __ASM_SH_BUG_H */