18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASMARM_BUG_H
38c2ecf20Sopenharmony_ci#define _ASMARM_BUG_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/linkage.h>
68c2ecf20Sopenharmony_ci#include <linux/types.h>
78c2ecf20Sopenharmony_ci#include <asm/opcodes.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * Use a suitable undefined instruction to use for ARM/Thumb2 bug handling.
118c2ecf20Sopenharmony_ci * We need to be careful not to conflict with those used by other modules and
128c2ecf20Sopenharmony_ci * the register_undef_hook() system.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#ifdef CONFIG_THUMB2_KERNEL
158c2ecf20Sopenharmony_ci#define BUG_INSTR_VALUE 0xde02
168c2ecf20Sopenharmony_ci#define BUG_INSTR(__value) __inst_thumb16(__value)
178c2ecf20Sopenharmony_ci#else
188c2ecf20Sopenharmony_ci#define BUG_INSTR_VALUE 0xe7f001f2
198c2ecf20Sopenharmony_ci#define BUG_INSTR(__value) __inst_arm(__value)
208c2ecf20Sopenharmony_ci#endif
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE)
248c2ecf20Sopenharmony_ci#define _BUG(file, line, value) __BUG(file, line, value)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_BUGVERBOSE
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * The extra indirection is to ensure that the __FILE__ string comes through
308c2ecf20Sopenharmony_ci * OK. Many version of gcc do not support the asm %c parameter which would be
318c2ecf20Sopenharmony_ci * preferable to this unpleasantness. We use mergeable string sections to
328c2ecf20Sopenharmony_ci * avoid multiple copies of the string appearing in the kernel image.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define __BUG(__file, __line, __value)				\
368c2ecf20Sopenharmony_cido {								\
378c2ecf20Sopenharmony_ci	asm volatile("1:\t" BUG_INSTR(__value) "\n"  \
388c2ecf20Sopenharmony_ci		".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
398c2ecf20Sopenharmony_ci		"2:\t.asciz " #__file "\n" 			\
408c2ecf20Sopenharmony_ci		".popsection\n" 				\
418c2ecf20Sopenharmony_ci		".pushsection __bug_table,\"aw\"\n"		\
428c2ecf20Sopenharmony_ci		".align 2\n"					\
438c2ecf20Sopenharmony_ci		"3:\t.word 1b, 2b\n"				\
448c2ecf20Sopenharmony_ci		"\t.hword " #__line ", 0\n"			\
458c2ecf20Sopenharmony_ci		".popsection");					\
468c2ecf20Sopenharmony_ci	unreachable();						\
478c2ecf20Sopenharmony_ci} while (0)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#else
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define __BUG(__file, __line, __value)				\
528c2ecf20Sopenharmony_cido {								\
538c2ecf20Sopenharmony_ci	asm volatile(BUG_INSTR(__value) "\n");			\
548c2ecf20Sopenharmony_ci	unreachable();						\
558c2ecf20Sopenharmony_ci} while (0)
568c2ecf20Sopenharmony_ci#endif  /* CONFIG_DEBUG_BUGVERBOSE */
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define HAVE_ARCH_BUG
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#include <asm-generic/bug.h>
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct pt_regs;
638c2ecf20Sopenharmony_civoid die(const char *msg, struct pt_regs *regs, int err);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_civoid arm_notify_die(const char *str, struct pt_regs *regs,
668c2ecf20Sopenharmony_ci		int signo, int si_code, void __user *addr,
678c2ecf20Sopenharmony_ci		unsigned long err, unsigned long trap);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_LPAE
708c2ecf20Sopenharmony_ci#define FAULT_CODE_ALIGNMENT	33
718c2ecf20Sopenharmony_ci#define FAULT_CODE_DEBUG	34
728c2ecf20Sopenharmony_ci#else
738c2ecf20Sopenharmony_ci#define FAULT_CODE_ALIGNMENT	1
748c2ecf20Sopenharmony_ci#define FAULT_CODE_DEBUG	2
758c2ecf20Sopenharmony_ci#endif
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_civoid hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
788c2ecf20Sopenharmony_ci				       struct pt_regs *),
798c2ecf20Sopenharmony_ci		     int sig, int code, const char *name);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_civoid hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
828c2ecf20Sopenharmony_ci				       struct pt_regs *),
838c2ecf20Sopenharmony_ci		     int sig, int code, const char *name);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciextern asmlinkage void c_backtrace(unsigned long fp, int pmode,
868c2ecf20Sopenharmony_ci				   const char *loglvl);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct mm_struct;
898c2ecf20Sopenharmony_civoid show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr);
908c2ecf20Sopenharmony_ciextern void __show_regs(struct pt_regs *);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#endif
93