xref: /openbmc/linux/arch/arm/include/asm/bug.h (revision e9c38ceb)
14baa9922SRussell King #ifndef _ASMARM_BUG_H
24baa9922SRussell King #define _ASMARM_BUG_H
34baa9922SRussell King 
49f97da78SDavid Howells #include <linux/linkage.h>
563328070SBen Dooks #include <linux/types.h>
663328070SBen Dooks #include <asm/opcodes.h>
74baa9922SRussell King 
887e040b6SSimon Glass /*
987e040b6SSimon Glass  * Use a suitable undefined instruction to use for ARM/Thumb2 bug handling.
1087e040b6SSimon Glass  * We need to be careful not to conflict with those used by other modules and
1187e040b6SSimon Glass  * the register_undef_hook() system.
1287e040b6SSimon Glass  */
1387e040b6SSimon Glass #ifdef CONFIG_THUMB2_KERNEL
1487e040b6SSimon Glass #define BUG_INSTR_VALUE 0xde02
1563328070SBen Dooks #define BUG_INSTR(__value) __inst_thumb16(__value)
164baa9922SRussell King #else
1787e040b6SSimon Glass #define BUG_INSTR_VALUE 0xe7f001f2
1863328070SBen Dooks #define BUG_INSTR(__value) __inst_arm(__value)
194baa9922SRussell King #endif
204baa9922SRussell King 
2187e040b6SSimon Glass 
2287e040b6SSimon Glass #define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE)
2387e040b6SSimon Glass #define _BUG(file, line, value) __BUG(file, line, value)
2487e040b6SSimon Glass 
2587e040b6SSimon Glass #ifdef CONFIG_DEBUG_BUGVERBOSE
2687e040b6SSimon Glass 
2787e040b6SSimon Glass /*
2887e040b6SSimon Glass  * The extra indirection is to ensure that the __FILE__ string comes through
2987e040b6SSimon Glass  * OK. Many version of gcc do not support the asm %c parameter which would be
3087e040b6SSimon Glass  * preferable to this unpleasantness. We use mergeable string sections to
3187e040b6SSimon Glass  * avoid multiple copies of the string appearing in the kernel image.
3287e040b6SSimon Glass  */
3387e040b6SSimon Glass 
3487e040b6SSimon Glass #define __BUG(__file, __line, __value)				\
3587e040b6SSimon Glass do {								\
3663328070SBen Dooks 	asm volatile("1:\t" BUG_INSTR(__value) "\n"  \
3787e040b6SSimon Glass 		".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
3887e040b6SSimon Glass 		"2:\t.asciz " #__file "\n" 			\
3987e040b6SSimon Glass 		".popsection\n" 				\
4087e040b6SSimon Glass 		".pushsection __bug_table,\"a\"\n"		\
41a4a5a737SRobert Jarzmik 		".align 2\n"					\
4287e040b6SSimon Glass 		"3:\t.word 1b, 2b\n"				\
4387e040b6SSimon Glass 		"\t.hword " #__line ", 0\n"			\
4487e040b6SSimon Glass 		".popsection");					\
4587e040b6SSimon Glass 	unreachable();						\
4687e040b6SSimon Glass } while (0)
4787e040b6SSimon Glass 
48e9c38cebSArnd Bergmann #else
4987e040b6SSimon Glass 
5087e040b6SSimon Glass #define __BUG(__file, __line, __value)				\
5187e040b6SSimon Glass do {								\
5263328070SBen Dooks 	asm volatile(BUG_INSTR(__value) "\n");			\
5387e040b6SSimon Glass 	unreachable();						\
5487e040b6SSimon Glass } while (0)
5587e040b6SSimon Glass #endif  /* CONFIG_DEBUG_BUGVERBOSE */
5687e040b6SSimon Glass 
574baa9922SRussell King #define HAVE_ARCH_BUG
584baa9922SRussell King 
594baa9922SRussell King #include <asm-generic/bug.h>
604baa9922SRussell King 
619f97da78SDavid Howells struct pt_regs;
629f97da78SDavid Howells void die(const char *msg, struct pt_regs *regs, int err);
639f97da78SDavid Howells 
649f97da78SDavid Howells struct siginfo;
659f97da78SDavid Howells void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
669f97da78SDavid Howells 		unsigned long err, unsigned long trap);
679f97da78SDavid Howells 
689f97da78SDavid Howells #ifdef CONFIG_ARM_LPAE
699f97da78SDavid Howells #define FAULT_CODE_ALIGNMENT	33
709f97da78SDavid Howells #define FAULT_CODE_DEBUG	34
719f97da78SDavid Howells #else
729f97da78SDavid Howells #define FAULT_CODE_ALIGNMENT	1
739f97da78SDavid Howells #define FAULT_CODE_DEBUG	2
749f97da78SDavid Howells #endif
759f97da78SDavid Howells 
769f97da78SDavid Howells void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
779f97da78SDavid Howells 				       struct pt_regs *),
789f97da78SDavid Howells 		     int sig, int code, const char *name);
799f97da78SDavid Howells 
809f97da78SDavid Howells void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
819f97da78SDavid Howells 				       struct pt_regs *),
829f97da78SDavid Howells 		     int sig, int code, const char *name);
839f97da78SDavid Howells 
849f97da78SDavid Howells extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
859f97da78SDavid Howells 
869f97da78SDavid Howells struct mm_struct;
879f97da78SDavid Howells extern void show_pte(struct mm_struct *mm, unsigned long addr);
889f97da78SDavid Howells extern void __show_regs(struct pt_regs *);
899f97da78SDavid Howells 
904baa9922SRussell King #endif
91