xref: /openbmc/linux/arch/arm/include/asm/bug.h (revision eb3fcf00)
1 #ifndef _ASMARM_BUG_H
2 #define _ASMARM_BUG_H
3 
4 #include <linux/linkage.h>
5 #include <linux/types.h>
6 #include <asm/opcodes.h>
7 
8 #ifdef CONFIG_BUG
9 
10 /*
11  * Use a suitable undefined instruction to use for ARM/Thumb2 bug handling.
12  * We need to be careful not to conflict with those used by other modules and
13  * the register_undef_hook() system.
14  */
15 #ifdef CONFIG_THUMB2_KERNEL
16 #define BUG_INSTR_VALUE 0xde02
17 #define BUG_INSTR(__value) __inst_thumb16(__value)
18 #else
19 #define BUG_INSTR_VALUE 0xe7f001f2
20 #define BUG_INSTR(__value) __inst_arm(__value)
21 #endif
22 
23 
24 #define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE)
25 #define _BUG(file, line, value) __BUG(file, line, value)
26 
27 #ifdef CONFIG_DEBUG_BUGVERBOSE
28 
29 /*
30  * The extra indirection is to ensure that the __FILE__ string comes through
31  * OK. Many version of gcc do not support the asm %c parameter which would be
32  * preferable to this unpleasantness. We use mergeable string sections to
33  * avoid multiple copies of the string appearing in the kernel image.
34  */
35 
36 #define __BUG(__file, __line, __value)				\
37 do {								\
38 	asm volatile("1:\t" BUG_INSTR(__value) "\n"  \
39 		".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
40 		"2:\t.asciz " #__file "\n" 			\
41 		".popsection\n" 				\
42 		".pushsection __bug_table,\"a\"\n"		\
43 		".align 2\n"					\
44 		"3:\t.word 1b, 2b\n"				\
45 		"\t.hword " #__line ", 0\n"			\
46 		".popsection");					\
47 	unreachable();						\
48 } while (0)
49 
50 #else  /* not CONFIG_DEBUG_BUGVERBOSE */
51 
52 #define __BUG(__file, __line, __value)				\
53 do {								\
54 	asm volatile(BUG_INSTR(__value) "\n");			\
55 	unreachable();						\
56 } while (0)
57 #endif  /* CONFIG_DEBUG_BUGVERBOSE */
58 
59 #define HAVE_ARCH_BUG
60 #endif  /* CONFIG_BUG */
61 
62 #include <asm-generic/bug.h>
63 
64 struct pt_regs;
65 void die(const char *msg, struct pt_regs *regs, int err);
66 
67 struct siginfo;
68 void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
69 		unsigned long err, unsigned long trap);
70 
71 #ifdef CONFIG_ARM_LPAE
72 #define FAULT_CODE_ALIGNMENT	33
73 #define FAULT_CODE_DEBUG	34
74 #else
75 #define FAULT_CODE_ALIGNMENT	1
76 #define FAULT_CODE_DEBUG	2
77 #endif
78 
79 void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
80 				       struct pt_regs *),
81 		     int sig, int code, const char *name);
82 
83 void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
84 				       struct pt_regs *),
85 		     int sig, int code, const char *name);
86 
87 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
88 
89 struct mm_struct;
90 extern void show_pte(struct mm_struct *mm, unsigned long addr);
91 extern void __show_regs(struct pt_regs *);
92 
93 #endif
94