blob: 237aa52d87339fd65e551bd65ec11bfd2fcc0792 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _ASMARM_BUG_H
3#define _ASMARM_BUG_H
4
David Howells9f97da72012-03-28 18:30:01 +01005#include <linux/linkage.h>
Ben Dooks63328072013-07-25 14:38:03 +01006#include <linux/types.h>
7#include <asm/opcodes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Simon Glass87e040b2011-08-16 23:44:26 +01009/*
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 Dooks63328072013-07-25 14:38:03 +010016#define BUG_INSTR(__value) __inst_thumb16(__value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#else
Simon Glass87e040b2011-08-16 23:44:26 +010018#define BUG_INSTR_VALUE 0xe7f001f2
Ben Dooks63328072013-07-25 14:38:03 +010019#define BUG_INSTR(__value) __inst_arm(__value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#endif
21
Simon Glass87e040b2011-08-16 23:44:26 +010022
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) \
36do { \
Ben Dooks63328072013-07-25 14:38:03 +010037 asm volatile("1:\t" BUG_INSTR(__value) "\n" \
Simon Glass87e040b2011-08-16 23:44:26 +010038 ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
39 "2:\t.asciz " #__file "\n" \
40 ".popsection\n" \
Josh Poimboeuf325cdac2017-07-15 00:10:58 -050041 ".pushsection __bug_table,\"aw\"\n" \
Robert Jarzmika4a5a732015-09-11 17:12:27 +010042 ".align 2\n" \
Simon Glass87e040b2011-08-16 23:44:26 +010043 "3:\t.word 1b, 2b\n" \
44 "\t.hword " #__line ", 0\n" \
45 ".popsection"); \
46 unreachable(); \
47} while (0)
48
Arnd Bergmanne9c38ce2015-11-19 13:22:42 +010049#else
Simon Glass87e040b2011-08-16 23:44:26 +010050
51#define __BUG(__file, __line, __value) \
52do { \
Ben Dooks63328072013-07-25 14:38:03 +010053 asm volatile(BUG_INSTR(__value) "\n"); \
Simon Glass87e040b2011-08-16 23:44:26 +010054 unreachable(); \
55} while (0)
56#endif /* CONFIG_DEBUG_BUGVERBOSE */
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define HAVE_ARCH_BUG
Matt Mackallc8538a72005-05-01 08:59:01 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm-generic/bug.h>
61
David Howells9f97da72012-03-28 18:30:01 +010062struct pt_regs;
63void die(const char *msg, struct pt_regs *regs, int err);
64
65struct siginfo;
66void 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
77void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
78 struct pt_regs *),
79 int sig, int code, const char *name);
80
81void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
82 struct pt_regs *),
83 int sig, int code, const char *name);
84
85extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
86
87struct mm_struct;
88extern void show_pte(struct mm_struct *mm, unsigned long addr);
89extern void __show_regs(struct pt_regs *);
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif