blob: c01718040166e2141fe68357e57fe637e9f20edf [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 */
5
Paul Mundte1cd93e2007-11-08 18:58:00 +09006#ifdef CONFIG_GENERIC_BUG
Paul Mundtfa691512007-03-08 19:41:21 +09007#define HAVE_ARCH_BUG
8#define HAVE_ARCH_WARN_ON
Paul Mundtdc34d312006-12-08 17:41:43 +09009
Paul Mundtfa691512007-03-08 19:41:21 +090010/**
11 * _EMIT_BUG_ENTRY
12 * %1 - __FILE__
13 * %2 - __LINE__
14 * %3 - trap type
15 * %4 - sizeof(struct bug_entry)
16 *
17 * The trapa opcode itself sits in %0.
18 * The %O notation is used to avoid # generation.
19 *
20 * The offending file and line are encoded in the __bug_table section.
21 */
Paul Mundtdc34d312006-12-08 17:41:43 +090022#ifdef CONFIG_DEBUG_BUGVERBOSE
Paul Mundtfa691512007-03-08 19:41:21 +090023#define _EMIT_BUG_ENTRY \
24 "\t.pushsection __bug_table,\"a\"\n" \
25 "2:\t.long 1b, %O1\n" \
26 "\t.short %O2, %O3\n" \
27 "\t.org 2b+%O4\n" \
28 "\t.popsection\n"
29#else
30#define _EMIT_BUG_ENTRY \
31 "\t.pushsection __bug_table,\"a\"\n" \
32 "2:\t.long 1b\n" \
33 "\t.short %O3\n" \
34 "\t.org 2b+%O4\n" \
35 "\t.popsection\n"
36#endif
Paul Mundtdc34d312006-12-08 17:41:43 +090037
38#define BUG() \
39do { \
40 __asm__ __volatile__ ( \
Paul Mundtfa691512007-03-08 19:41:21 +090041 "1:\t.short %O0\n" \
42 _EMIT_BUG_ENTRY \
43 : \
44 : "n" (TRAPA_BUG_OPCODE), \
45 "i" (__FILE__), \
46 "i" (__LINE__), "i" (0), \
47 "i" (sizeof(struct bug_entry))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070048} while (0)
49
Paul Mundtfa691512007-03-08 19:41:21 +090050#define __WARN() \
51do { \
52 __asm__ __volatile__ ( \
53 "1:\t.short %O0\n" \
54 _EMIT_BUG_ENTRY \
55 : \
56 : "n" (TRAPA_BUG_OPCODE), \
57 "i" (__FILE__), \
58 "i" (__LINE__), \
59 "i" (BUGFLAG_WARNING), \
60 "i" (sizeof(struct bug_entry))); \
Paul Mundtdc34d312006-12-08 17:41:43 +090061} while (0)
62
Paul Mundtfa691512007-03-08 19:41:21 +090063#define WARN_ON(x) ({ \
Heiko Carstensfd0cbdd2007-08-02 00:18:38 +020064 int __ret_warn_on = !!(x); \
Paul Mundtfa691512007-03-08 19:41:21 +090065 if (__builtin_constant_p(__ret_warn_on)) { \
66 if (__ret_warn_on) \
67 __WARN(); \
68 } else { \
69 if (unlikely(__ret_warn_on)) \
70 __WARN(); \
71 } \
72 unlikely(__ret_warn_on); \
73})
Paul Mundtdc34d312006-12-08 17:41:43 +090074
Paul Mundte1cd93e2007-11-08 18:58:00 +090075#endif /* CONFIG_GENERIC_BUG */
Matt Mackallc8538a72005-05-01 08:59:01 -070076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include <asm-generic/bug.h>
78
Paul Mundtdc34d312006-12-08 17:41:43 +090079#endif /* __ASM_SH_BUG_H */