blob: a78d482e8b2f378969fc86b907f8a1625b83b1bd [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
Matt Mackallc8538a72005-05-01 08:59:01 -07006#ifdef CONFIG_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 Mundtfa691512007-03-08 19:41:21 +090075struct pt_regs;
76
77/* arch/sh/kernel/traps.c */
78void handle_BUG(struct pt_regs *);
Paul Mundtdc34d312006-12-08 17:41:43 +090079
80#endif /* CONFIG_BUG */
Matt Mackallc8538a72005-05-01 08:59:01 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include <asm-generic/bug.h>
83
Paul Mundtdc34d312006-12-08 17:41:43 +090084#endif /* __ASM_SH_BUG_H */