blob: c9828f785ca0bce1f3e49a73def335bfc67eafc7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_BUG_H
2#define __ASM_SH_BUG_H
3
David Howellse839ca52012-03-28 18:30:03 +01004#include <linux/linkage.h>
5
Paul Mundt44530c62007-05-08 12:14:54 +09006#define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */
Paul Mundte115f2c2009-08-22 05:28:25 +09007#define BUGFLAG_UNWINDER (1 << 1)
Paul Mundt44530c62007-05-08 12:14:54 +09008
Paul Mundte1cd93e2007-11-08 18:58:00 +09009#ifdef CONFIG_GENERIC_BUG
Paul Mundtfa691512007-03-08 19:41:21 +090010#define HAVE_ARCH_BUG
11#define HAVE_ARCH_WARN_ON
Paul Mundtdc34d312006-12-08 17:41:43 +090012
Paul Mundtfa691512007-03-08 19:41:21 +090013/**
14 * _EMIT_BUG_ENTRY
15 * %1 - __FILE__
16 * %2 - __LINE__
17 * %3 - trap type
18 * %4 - sizeof(struct bug_entry)
19 *
20 * The trapa opcode itself sits in %0.
21 * The %O notation is used to avoid # generation.
22 *
23 * The offending file and line are encoded in the __bug_table section.
24 */
Paul Mundtdc34d312006-12-08 17:41:43 +090025#ifdef CONFIG_DEBUG_BUGVERBOSE
Paul Mundtfa691512007-03-08 19:41:21 +090026#define _EMIT_BUG_ENTRY \
27 "\t.pushsection __bug_table,\"a\"\n" \
28 "2:\t.long 1b, %O1\n" \
29 "\t.short %O2, %O3\n" \
30 "\t.org 2b+%O4\n" \
31 "\t.popsection\n"
32#else
33#define _EMIT_BUG_ENTRY \
34 "\t.pushsection __bug_table,\"a\"\n" \
35 "2:\t.long 1b\n" \
36 "\t.short %O3\n" \
37 "\t.org 2b+%O4\n" \
38 "\t.popsection\n"
39#endif
Paul Mundtdc34d312006-12-08 17:41:43 +090040
41#define BUG() \
42do { \
43 __asm__ __volatile__ ( \
Paul Mundtfa691512007-03-08 19:41:21 +090044 "1:\t.short %O0\n" \
45 _EMIT_BUG_ENTRY \
46 : \
47 : "n" (TRAPA_BUG_OPCODE), \
48 "i" (__FILE__), \
49 "i" (__LINE__), "i" (0), \
50 "i" (sizeof(struct bug_entry))); \
Kees Cook579e1452017-07-12 14:36:13 -070051 unreachable(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070052} while (0)
53
Peter Zijlstra19d43622017-02-25 08:56:53 +010054#define __WARN_FLAGS(flags) \
Paul Mundtfa691512007-03-08 19:41:21 +090055do { \
56 __asm__ __volatile__ ( \
57 "1:\t.short %O0\n" \
58 _EMIT_BUG_ENTRY \
59 : \
60 : "n" (TRAPA_BUG_OPCODE), \
61 "i" (__FILE__), \
62 "i" (__LINE__), \
Peter Zijlstra19d43622017-02-25 08:56:53 +010063 "i" (BUGFLAG_WARNING|(flags)), \
Paul Mundtfa691512007-03-08 19:41:21 +090064 "i" (sizeof(struct bug_entry))); \
Paul Mundtdc34d312006-12-08 17:41:43 +090065} while (0)
66
Paul Mundtfa691512007-03-08 19:41:21 +090067#define WARN_ON(x) ({ \
Heiko Carstensfd0cbdd2007-08-02 00:18:38 +020068 int __ret_warn_on = !!(x); \
Paul Mundtfa691512007-03-08 19:41:21 +090069 if (__builtin_constant_p(__ret_warn_on)) { \
70 if (__ret_warn_on) \
71 __WARN(); \
72 } else { \
73 if (unlikely(__ret_warn_on)) \
74 __WARN(); \
75 } \
76 unlikely(__ret_warn_on); \
77})
Paul Mundtdc34d312006-12-08 17:41:43 +090078
Paul Mundte115f2c2009-08-22 05:28:25 +090079#define UNWINDER_BUG() \
Matt Flemingb344e24a2009-08-16 21:54:48 +010080do { \
81 __asm__ __volatile__ ( \
82 "1:\t.short %O0\n" \
Paul Mundte115f2c2009-08-22 05:28:25 +090083 _EMIT_BUG_ENTRY \
Matt Flemingb344e24a2009-08-16 21:54:48 +010084 : \
Paul Mundte115f2c2009-08-22 05:28:25 +090085 : "n" (TRAPA_BUG_OPCODE), \
Matt Flemingb344e24a2009-08-16 21:54:48 +010086 "i" (__FILE__), \
Paul Mundte115f2c2009-08-22 05:28:25 +090087 "i" (__LINE__), \
88 "i" (BUGFLAG_UNWINDER), \
Matt Flemingb344e24a2009-08-16 21:54:48 +010089 "i" (sizeof(struct bug_entry))); \
90} while (0)
91
92#define UNWINDER_BUG_ON(x) ({ \
93 int __ret_unwinder_on = !!(x); \
94 if (__builtin_constant_p(__ret_unwinder_on)) { \
95 if (__ret_unwinder_on) \
96 UNWINDER_BUG(); \
97 } else { \
98 if (unlikely(__ret_unwinder_on)) \
99 UNWINDER_BUG(); \
100 } \
101 unlikely(__ret_unwinder_on); \
102})
103
Paul Mundt74db2472009-08-22 05:31:45 +0900104#else
105
106#define UNWINDER_BUG BUG
107#define UNWINDER_BUG_ON BUG_ON
108
Paul Mundte1cd93e2007-11-08 18:58:00 +0900109#endif /* CONFIG_GENERIC_BUG */
Matt Mackallc8538a72005-05-01 08:59:01 -0700110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#include <asm-generic/bug.h>
112
David Howellse839ca52012-03-28 18:30:03 +0100113struct pt_regs;
Paul Mundt5f857bc2012-06-14 14:18:51 +0900114
115/* arch/sh/kernel/traps.c */
David Howellse839ca52012-03-28 18:30:03 +0100116extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
Paul Mundt5f857bc2012-06-14 14:18:51 +0900117extern void die_if_kernel(const char *str, struct pt_regs *regs, long err);
118extern void die_if_no_fixup(const char *str, struct pt_regs *regs, long err);
David Howellse839ca52012-03-28 18:30:03 +0100119
Paul Mundtdc34d312006-12-08 17:41:43 +0900120#endif /* __ASM_SH_BUG_H */