bug.h 1.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef __ASM_SH_BUG_H
#define __ASM_SH_BUG_H

P
Paul Mundt 已提交
4 5
#define TRAPA_BUG_OPCODE	0xc33e	/* trapa #0x3e */

M
Matt Mackall 已提交
6
#ifdef CONFIG_BUG
P
Paul Mundt 已提交
7 8
#define HAVE_ARCH_BUG
#define HAVE_ARCH_WARN_ON
9

P
Paul Mundt 已提交
10 11 12 13 14 15 16 17 18 19 20 21
/**
 * _EMIT_BUG_ENTRY
 * %1 - __FILE__
 * %2 - __LINE__
 * %3 - trap type
 * %4 - sizeof(struct bug_entry)
 *
 * The trapa opcode itself sits in %0.
 * The %O notation is used to avoid # generation.
 *
 * The offending file and line are encoded in the __bug_table section.
 */
22
#ifdef CONFIG_DEBUG_BUGVERBOSE
P
Paul Mundt 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
#define _EMIT_BUG_ENTRY				\
	"\t.pushsection __bug_table,\"a\"\n"	\
	"2:\t.long 1b, %O1\n"			\
	"\t.short %O2, %O3\n"			\
	"\t.org 2b+%O4\n"			\
	"\t.popsection\n"
#else
#define _EMIT_BUG_ENTRY				\
	"\t.pushsection __bug_table,\"a\"\n"	\
	"2:\t.long 1b\n"			\
	"\t.short %O3\n"			\
	"\t.org 2b+%O4\n"			\
	"\t.popsection\n"
#endif
37 38 39 40

#define BUG()						\
do {							\
	__asm__ __volatile__ (				\
P
Paul Mundt 已提交
41 42 43 44 45 46 47
		"1:\t.short %O0\n"			\
		_EMIT_BUG_ENTRY				\
		 :					\
		 : "n" (TRAPA_BUG_OPCODE),		\
		   "i" (__FILE__),			\
		   "i" (__LINE__), "i" (0),		\
		   "i" (sizeof(struct bug_entry)));	\
48 49
} while (0)

P
Paul Mundt 已提交
50 51 52 53 54 55 56 57 58 59 60
#define __WARN()					\
do {							\
	__asm__ __volatile__ (				\
		"1:\t.short %O0\n"			\
		 _EMIT_BUG_ENTRY			\
		 :					\
		 : "n" (TRAPA_BUG_OPCODE),		\
		   "i" (__FILE__),			\
		   "i" (__LINE__),			\
		   "i" (BUGFLAG_WARNING),		\
		   "i" (sizeof(struct bug_entry)));	\
L
Linus Torvalds 已提交
61 62
} while (0)

P
Paul Mundt 已提交
63 64 65 66 67 68 69 70 71 72 73
#define WARN_ON(x) ({						\
	typeof(x) __ret_warn_on = (x);				\
	if (__builtin_constant_p(__ret_warn_on)) {		\
		if (__ret_warn_on)				\
			__WARN();				\
	} else {						\
		if (unlikely(__ret_warn_on))			\
			__WARN();				\
	}							\
	unlikely(__ret_warn_on);				\
})
74

P
Paul Mundt 已提交
75 76 77 78
struct pt_regs;

/* arch/sh/kernel/traps.c */
void handle_BUG(struct pt_regs *);
79 80

#endif /* CONFIG_BUG */
M
Matt Mackall 已提交
81

L
Linus Torvalds 已提交
82 83
#include <asm-generic/bug.h>

84
#endif /* __ASM_SH_BUG_H */