18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_SH_BUG_H
38c2ecf20Sopenharmony_ci#define __ASM_SH_BUG_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/linkage.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define TRAPA_BUG_OPCODE	0xc33e	/* trapa #0x3e */
88c2ecf20Sopenharmony_ci#define BUGFLAG_UNWINDER	(1 << 1)
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifdef CONFIG_GENERIC_BUG
118c2ecf20Sopenharmony_ci#define HAVE_ARCH_BUG
128c2ecf20Sopenharmony_ci#define HAVE_ARCH_WARN_ON
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/**
158c2ecf20Sopenharmony_ci * _EMIT_BUG_ENTRY
168c2ecf20Sopenharmony_ci * %1 - __FILE__
178c2ecf20Sopenharmony_ci * %2 - __LINE__
188c2ecf20Sopenharmony_ci * %3 - trap type
198c2ecf20Sopenharmony_ci * %4 - sizeof(struct bug_entry)
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * The trapa opcode itself sits in %0.
228c2ecf20Sopenharmony_ci * The %O notation is used to avoid # generation.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * The offending file and line are encoded in the __bug_table section.
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_BUGVERBOSE
278c2ecf20Sopenharmony_ci#define _EMIT_BUG_ENTRY				\
288c2ecf20Sopenharmony_ci	"\t.pushsection __bug_table,\"aw\"\n"	\
298c2ecf20Sopenharmony_ci	"2:\t.long 1b, %O1\n"			\
308c2ecf20Sopenharmony_ci	"\t.short %O2, %O3\n"			\
318c2ecf20Sopenharmony_ci	"\t.org 2b+%O4\n"			\
328c2ecf20Sopenharmony_ci	"\t.popsection\n"
338c2ecf20Sopenharmony_ci#else
348c2ecf20Sopenharmony_ci#define _EMIT_BUG_ENTRY				\
358c2ecf20Sopenharmony_ci	"\t.pushsection __bug_table,\"aw\"\n"	\
368c2ecf20Sopenharmony_ci	"2:\t.long 1b\n"			\
378c2ecf20Sopenharmony_ci	"\t.short %O3\n"			\
388c2ecf20Sopenharmony_ci	"\t.org 2b+%O4\n"			\
398c2ecf20Sopenharmony_ci	"\t.popsection\n"
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define BUG()						\
438c2ecf20Sopenharmony_cido {							\
448c2ecf20Sopenharmony_ci	__asm__ __volatile__ (				\
458c2ecf20Sopenharmony_ci		"1:\t.short %O0\n"			\
468c2ecf20Sopenharmony_ci		_EMIT_BUG_ENTRY				\
478c2ecf20Sopenharmony_ci		 :					\
488c2ecf20Sopenharmony_ci		 : "n" (TRAPA_BUG_OPCODE),		\
498c2ecf20Sopenharmony_ci		   "i" (__FILE__),			\
508c2ecf20Sopenharmony_ci		   "i" (__LINE__), "i" (0),		\
518c2ecf20Sopenharmony_ci		   "i" (sizeof(struct bug_entry)));	\
528c2ecf20Sopenharmony_ci	unreachable();					\
538c2ecf20Sopenharmony_ci} while (0)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define __WARN_FLAGS(flags)				\
568c2ecf20Sopenharmony_cido {							\
578c2ecf20Sopenharmony_ci	__asm__ __volatile__ (				\
588c2ecf20Sopenharmony_ci		"1:\t.short %O0\n"			\
598c2ecf20Sopenharmony_ci		 _EMIT_BUG_ENTRY			\
608c2ecf20Sopenharmony_ci		 :					\
618c2ecf20Sopenharmony_ci		 : "n" (TRAPA_BUG_OPCODE),		\
628c2ecf20Sopenharmony_ci		   "i" (__FILE__),			\
638c2ecf20Sopenharmony_ci		   "i" (__LINE__),			\
648c2ecf20Sopenharmony_ci		   "i" (BUGFLAG_WARNING|(flags)),	\
658c2ecf20Sopenharmony_ci		   "i" (sizeof(struct bug_entry)));	\
668c2ecf20Sopenharmony_ci} while (0)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define WARN_ON(x) ({						\
698c2ecf20Sopenharmony_ci	int __ret_warn_on = !!(x);				\
708c2ecf20Sopenharmony_ci	if (__builtin_constant_p(__ret_warn_on)) {		\
718c2ecf20Sopenharmony_ci		if (__ret_warn_on)				\
728c2ecf20Sopenharmony_ci			__WARN();				\
738c2ecf20Sopenharmony_ci	} else {						\
748c2ecf20Sopenharmony_ci		if (unlikely(__ret_warn_on))			\
758c2ecf20Sopenharmony_ci			__WARN();				\
768c2ecf20Sopenharmony_ci	}							\
778c2ecf20Sopenharmony_ci	unlikely(__ret_warn_on);				\
788c2ecf20Sopenharmony_ci})
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define UNWINDER_BUG()					\
818c2ecf20Sopenharmony_cido {							\
828c2ecf20Sopenharmony_ci	__asm__ __volatile__ (				\
838c2ecf20Sopenharmony_ci		"1:\t.short %O0\n"			\
848c2ecf20Sopenharmony_ci		_EMIT_BUG_ENTRY				\
858c2ecf20Sopenharmony_ci		 :					\
868c2ecf20Sopenharmony_ci		 : "n" (TRAPA_BUG_OPCODE),		\
878c2ecf20Sopenharmony_ci		   "i" (__FILE__),			\
888c2ecf20Sopenharmony_ci		   "i" (__LINE__),			\
898c2ecf20Sopenharmony_ci		   "i" (BUGFLAG_UNWINDER),		\
908c2ecf20Sopenharmony_ci		   "i" (sizeof(struct bug_entry)));	\
918c2ecf20Sopenharmony_ci} while (0)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define UNWINDER_BUG_ON(x) ({					\
948c2ecf20Sopenharmony_ci	int __ret_unwinder_on = !!(x);				\
958c2ecf20Sopenharmony_ci	if (__builtin_constant_p(__ret_unwinder_on)) {		\
968c2ecf20Sopenharmony_ci		if (__ret_unwinder_on)				\
978c2ecf20Sopenharmony_ci			UNWINDER_BUG();				\
988c2ecf20Sopenharmony_ci	} else {						\
998c2ecf20Sopenharmony_ci		if (unlikely(__ret_unwinder_on))		\
1008c2ecf20Sopenharmony_ci			UNWINDER_BUG();				\
1018c2ecf20Sopenharmony_ci	}							\
1028c2ecf20Sopenharmony_ci	unlikely(__ret_unwinder_on);				\
1038c2ecf20Sopenharmony_ci})
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#else
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define UNWINDER_BUG	BUG
1088c2ecf20Sopenharmony_ci#define UNWINDER_BUG_ON	BUG_ON
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#endif /* CONFIG_GENERIC_BUG */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#include <asm-generic/bug.h>
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct pt_regs;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* arch/sh/kernel/traps.c */
1178c2ecf20Sopenharmony_ciextern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
1188c2ecf20Sopenharmony_ciextern void die_if_kernel(const char *str, struct pt_regs *regs, long err);
1198c2ecf20Sopenharmony_ciextern void die_if_no_fixup(const char *str, struct pt_regs *regs, long err);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#endif /* __ASM_SH_BUG_H */
122