Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _ASMARM_BUG_H |
| 3 | #define _ASMARM_BUG_H |
| 4 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 5 | #include <linux/linkage.h> |
Ben Dooks | 6332807 | 2013-07-25 14:38:03 +0100 | [diff] [blame] | 6 | #include <linux/types.h> |
| 7 | #include <asm/opcodes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 9 | /* |
| 10 | * Use a suitable undefined instruction to use for ARM/Thumb2 bug handling. |
| 11 | * We need to be careful not to conflict with those used by other modules and |
| 12 | * the register_undef_hook() system. |
| 13 | */ |
| 14 | #ifdef CONFIG_THUMB2_KERNEL |
| 15 | #define BUG_INSTR_VALUE 0xde02 |
Ben Dooks | 6332807 | 2013-07-25 14:38:03 +0100 | [diff] [blame] | 16 | #define BUG_INSTR(__value) __inst_thumb16(__value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #else |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 18 | #define BUG_INSTR_VALUE 0xe7f001f2 |
Ben Dooks | 6332807 | 2013-07-25 14:38:03 +0100 | [diff] [blame] | 19 | #define BUG_INSTR(__value) __inst_arm(__value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #endif |
| 21 | |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 22 | |
| 23 | #define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE) |
| 24 | #define _BUG(file, line, value) __BUG(file, line, value) |
| 25 | |
| 26 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 27 | |
| 28 | /* |
| 29 | * The extra indirection is to ensure that the __FILE__ string comes through |
| 30 | * OK. Many version of gcc do not support the asm %c parameter which would be |
| 31 | * preferable to this unpleasantness. We use mergeable string sections to |
| 32 | * avoid multiple copies of the string appearing in the kernel image. |
| 33 | */ |
| 34 | |
| 35 | #define __BUG(__file, __line, __value) \ |
| 36 | do { \ |
Ben Dooks | 6332807 | 2013-07-25 14:38:03 +0100 | [diff] [blame] | 37 | asm volatile("1:\t" BUG_INSTR(__value) "\n" \ |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 38 | ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ |
| 39 | "2:\t.asciz " #__file "\n" \ |
| 40 | ".popsection\n" \ |
Josh Poimboeuf | 325cdac | 2017-07-15 00:10:58 -0500 | [diff] [blame] | 41 | ".pushsection __bug_table,\"aw\"\n" \ |
Robert Jarzmik | a4a5a73 | 2015-09-11 17:12:27 +0100 | [diff] [blame] | 42 | ".align 2\n" \ |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 43 | "3:\t.word 1b, 2b\n" \ |
| 44 | "\t.hword " #__line ", 0\n" \ |
| 45 | ".popsection"); \ |
| 46 | unreachable(); \ |
| 47 | } while (0) |
| 48 | |
Arnd Bergmann | e9c38ce | 2015-11-19 13:22:42 +0100 | [diff] [blame] | 49 | #else |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 50 | |
| 51 | #define __BUG(__file, __line, __value) \ |
| 52 | do { \ |
Ben Dooks | 6332807 | 2013-07-25 14:38:03 +0100 | [diff] [blame] | 53 | asm volatile(BUG_INSTR(__value) "\n"); \ |
Simon Glass | 87e040b | 2011-08-16 23:44:26 +0100 | [diff] [blame] | 54 | unreachable(); \ |
| 55 | } while (0) |
| 56 | #endif /* CONFIG_DEBUG_BUGVERBOSE */ |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define HAVE_ARCH_BUG |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <asm-generic/bug.h> |
| 61 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 62 | struct pt_regs; |
| 63 | void die(const char *msg, struct pt_regs *regs, int err); |
| 64 | |
| 65 | struct siginfo; |
| 66 | void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info, |
| 67 | unsigned long err, unsigned long trap); |
| 68 | |
| 69 | #ifdef CONFIG_ARM_LPAE |
| 70 | #define FAULT_CODE_ALIGNMENT 33 |
| 71 | #define FAULT_CODE_DEBUG 34 |
| 72 | #else |
| 73 | #define FAULT_CODE_ALIGNMENT 1 |
| 74 | #define FAULT_CODE_DEBUG 2 |
| 75 | #endif |
| 76 | |
| 77 | void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, |
| 78 | struct pt_regs *), |
| 79 | int sig, int code, const char *name); |
| 80 | |
| 81 | void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, |
| 82 | struct pt_regs *), |
| 83 | int sig, int code, const char *name); |
| 84 | |
| 85 | extern asmlinkage void c_backtrace(unsigned long fp, int pmode); |
| 86 | |
| 87 | struct mm_struct; |
| 88 | extern void show_pte(struct mm_struct *mm, unsigned long addr); |
| 89 | extern void __show_regs(struct pt_regs *); |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #endif |