1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 24baa9922SRussell King #ifndef _ASMARM_BUG_H 34baa9922SRussell King #define _ASMARM_BUG_H 44baa9922SRussell King 59f97da78SDavid Howells #include <linux/linkage.h> 663328070SBen Dooks #include <linux/types.h> 763328070SBen Dooks #include <asm/opcodes.h> 84baa9922SRussell King 987e040b6SSimon Glass /* 1087e040b6SSimon Glass * Use a suitable undefined instruction to use for ARM/Thumb2 bug handling. 1187e040b6SSimon Glass * We need to be careful not to conflict with those used by other modules and 1287e040b6SSimon Glass * the register_undef_hook() system. 1387e040b6SSimon Glass */ 1487e040b6SSimon Glass #ifdef CONFIG_THUMB2_KERNEL 1587e040b6SSimon Glass #define BUG_INSTR_VALUE 0xde02 1663328070SBen Dooks #define BUG_INSTR(__value) __inst_thumb16(__value) 174baa9922SRussell King #else 1887e040b6SSimon Glass #define BUG_INSTR_VALUE 0xe7f001f2 1963328070SBen Dooks #define BUG_INSTR(__value) __inst_arm(__value) 204baa9922SRussell King #endif 214baa9922SRussell King 2287e040b6SSimon Glass 2387e040b6SSimon Glass #define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE) 2487e040b6SSimon Glass #define _BUG(file, line, value) __BUG(file, line, value) 2587e040b6SSimon Glass 2687e040b6SSimon Glass #ifdef CONFIG_DEBUG_BUGVERBOSE 2787e040b6SSimon Glass 2887e040b6SSimon Glass /* 2987e040b6SSimon Glass * The extra indirection is to ensure that the __FILE__ string comes through 3087e040b6SSimon Glass * OK. Many version of gcc do not support the asm %c parameter which would be 3187e040b6SSimon Glass * preferable to this unpleasantness. We use mergeable string sections to 3287e040b6SSimon Glass * avoid multiple copies of the string appearing in the kernel image. 3387e040b6SSimon Glass */ 3487e040b6SSimon Glass 3587e040b6SSimon Glass #define __BUG(__file, __line, __value) \ 3687e040b6SSimon Glass do { \ 3763328070SBen Dooks asm volatile("1:\t" BUG_INSTR(__value) "\n" \ 3887e040b6SSimon Glass ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ 3987e040b6SSimon Glass "2:\t.asciz " #__file "\n" \ 4087e040b6SSimon Glass ".popsection\n" \ 41325cdacdSJosh Poimboeuf ".pushsection __bug_table,\"aw\"\n" \ 42a4a5a737SRobert Jarzmik ".align 2\n" \ 4387e040b6SSimon Glass "3:\t.word 1b, 2b\n" \ 4487e040b6SSimon Glass "\t.hword " #__line ", 0\n" \ 4587e040b6SSimon Glass ".popsection"); \ 4687e040b6SSimon Glass unreachable(); \ 4787e040b6SSimon Glass } while (0) 4887e040b6SSimon Glass 49e9c38cebSArnd Bergmann #else 5087e040b6SSimon Glass 5187e040b6SSimon Glass #define __BUG(__file, __line, __value) \ 5287e040b6SSimon Glass do { \ 5363328070SBen Dooks asm volatile(BUG_INSTR(__value) "\n"); \ 5487e040b6SSimon Glass unreachable(); \ 5587e040b6SSimon Glass } while (0) 5687e040b6SSimon Glass #endif /* CONFIG_DEBUG_BUGVERBOSE */ 5787e040b6SSimon Glass 584baa9922SRussell King #define HAVE_ARCH_BUG 594baa9922SRussell King 604baa9922SRussell King #include <asm-generic/bug.h> 614baa9922SRussell King 629f97da78SDavid Howells struct pt_regs; 639f97da78SDavid Howells void die(const char *msg, struct pt_regs *regs, int err); 649f97da78SDavid Howells 6505e792e3SEric W. Biederman void arm_notify_die(const char *str, struct pt_regs *regs, 6605e792e3SEric W. Biederman int signo, int si_code, void __user *addr, 679f97da78SDavid Howells unsigned long err, unsigned long trap); 689f97da78SDavid Howells 699f97da78SDavid Howells #ifdef CONFIG_ARM_LPAE 709f97da78SDavid Howells #define FAULT_CODE_ALIGNMENT 33 719f97da78SDavid Howells #define FAULT_CODE_DEBUG 34 729f97da78SDavid Howells #else 739f97da78SDavid Howells #define FAULT_CODE_ALIGNMENT 1 749f97da78SDavid Howells #define FAULT_CODE_DEBUG 2 759f97da78SDavid Howells #endif 769f97da78SDavid Howells 779f97da78SDavid Howells void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, 789f97da78SDavid Howells struct pt_regs *), 799f97da78SDavid Howells int sig, int code, const char *name); 809f97da78SDavid Howells 819f97da78SDavid Howells void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, 829f97da78SDavid Howells struct pt_regs *), 839f97da78SDavid Howells int sig, int code, const char *name); 849f97da78SDavid Howells 855489ab50SDmitry Safonov extern asmlinkage void c_backtrace(unsigned long fp, int pmode, 865489ab50SDmitry Safonov const char *loglvl); 879f97da78SDavid Howells 889f97da78SDavid Howells struct mm_struct; 8949b38c34SRussell King void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr); 909f97da78SDavid Howells extern void __show_regs(struct pt_regs *); 91*5aa6b70eSManinder Singh extern void __show_regs_alloc_free(struct pt_regs *regs); 929f97da78SDavid Howells 934baa9922SRussell King #endif 94