18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_BUG_H
38c2ecf20Sopenharmony_ci#define __ASM_BUG_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm/break.h>
68c2ecf20Sopenharmony_ci#include <linux/stringify.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef CONFIG_DEBUG_BUGVERBOSE
98c2ecf20Sopenharmony_ci#define _BUGVERBOSE_LOCATION(file, line)
108c2ecf20Sopenharmony_ci#else
118c2ecf20Sopenharmony_ci#define __BUGVERBOSE_LOCATION(file, line)			\
128c2ecf20Sopenharmony_ci		.pushsection .rodata.str, "aMS", @progbits, 1;	\
138c2ecf20Sopenharmony_ci	10002:	.string file;					\
148c2ecf20Sopenharmony_ci		.popsection;					\
158c2ecf20Sopenharmony_ci								\
168c2ecf20Sopenharmony_ci		.long 10002b - 10000b;				\
178c2ecf20Sopenharmony_ci		.short line;
188c2ecf20Sopenharmony_ci#define _BUGVERBOSE_LOCATION(file, line) __BUGVERBOSE_LOCATION(file, line)
198c2ecf20Sopenharmony_ci#endif
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifndef CONFIG_GENERIC_BUG
228c2ecf20Sopenharmony_ci#define __BUG_ENTRY(flags)
238c2ecf20Sopenharmony_ci#else
248c2ecf20Sopenharmony_ci#define __BUG_ENTRY(flags) 					\
258c2ecf20Sopenharmony_ci		.pushsection __bug_table, "aw";			\
268c2ecf20Sopenharmony_ci		.align 2;					\
278c2ecf20Sopenharmony_ci	10000:	.long 10001f - 10000b;				\
288c2ecf20Sopenharmony_ci		_BUGVERBOSE_LOCATION(__FILE__, __LINE__)	\
298c2ecf20Sopenharmony_ci		.short flags; 					\
308c2ecf20Sopenharmony_ci		.popsection;					\
318c2ecf20Sopenharmony_ci	10001:
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define ASM_BUG_FLAGS(flags)					\
358c2ecf20Sopenharmony_ci	__BUG_ENTRY(flags)					\
368c2ecf20Sopenharmony_ci	break		BRK_BUG
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define ASM_BUG()	ASM_BUG_FLAGS(0)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define __BUG_FLAGS(flags)					\
418c2ecf20Sopenharmony_ci	asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags)));
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define __WARN_FLAGS(flags)					\
448c2ecf20Sopenharmony_cido {								\
458c2ecf20Sopenharmony_ci	instrumentation_begin();				\
468c2ecf20Sopenharmony_ci	__BUG_FLAGS(BUGFLAG_WARNING|(flags));			\
478c2ecf20Sopenharmony_ci	annotate_reachable();					\
488c2ecf20Sopenharmony_ci	instrumentation_end();					\
498c2ecf20Sopenharmony_ci} while (0)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define BUG()							\
528c2ecf20Sopenharmony_cido {								\
538c2ecf20Sopenharmony_ci	instrumentation_begin();				\
548c2ecf20Sopenharmony_ci	__BUG_FLAGS(0);						\
558c2ecf20Sopenharmony_ci	unreachable();						\
568c2ecf20Sopenharmony_ci} while (0)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define HAVE_ARCH_BUG
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#include <asm-generic/bug.h>
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#endif /* __ASM_BUG_H */
63