blob: 42473d8b722c32f8c934c62fec053cfb4776619b [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASMARM_BUG_H
3#define _ASMARM_BUG_H
4
5#include <linux/linkage.h>
6#include <linux/types.h>
7#include <asm/opcodes.h>
8
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
16#define BUG_INSTR(__value) __inst_thumb16(__value)
17#else
18#define BUG_INSTR_VALUE 0xe7f001f2
19#define BUG_INSTR(__value) __inst_arm(__value)
20#endif
21
22
23//old: #define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE)
24
25#define BUG() do { \
26 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
27 barrier_before_unreachable(); \
28 _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE); \
29} while (0)
30
31#define _BUG(file, line, value) __BUG(file, line, value)
32
33#ifdef CONFIG_DEBUG_BUGVERBOSE
34
35/*
36 * The extra indirection is to ensure that the __FILE__ string comes through
37 * OK. Many version of gcc do not support the asm %c parameter which would be
38 * preferable to this unpleasantness. We use mergeable string sections to
39 * avoid multiple copies of the string appearing in the kernel image.
40 */
41
42#define __BUG(__file, __line, __value) \
43do { \
44 asm volatile("1:\t" BUG_INSTR(__value) "\n" \
45 ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
46 "2:\t.asciz " #__file "\n" \
47 ".popsection\n" \
48 ".pushsection __bug_table,\"aw\"\n" \
49 ".align 2\n" \
50 "3:\t.word 1b, 2b\n" \
51 "\t.hword " #__line ", 0\n" \
52 ".popsection"); \
53 unreachable(); \
54} while (0)
55
56#else
57
58#define __BUG(__file, __line, __value) \
59do { \
60 asm volatile(BUG_INSTR(__value) "\n"); \
61 unreachable(); \
62} while (0)
63#endif /* CONFIG_DEBUG_BUGVERBOSE */
64
65#define HAVE_ARCH_BUG
66
67#include <asm-generic/bug.h>
68
69struct pt_regs;
70void die(const char *msg, struct pt_regs *regs, int err);
71
72void arm_notify_die(const char *str, struct pt_regs *regs,
73 int signo, int si_code, void __user *addr,
74 unsigned long err, unsigned long trap);
75
76#ifdef CONFIG_ARM_LPAE
77#define FAULT_CODE_ALIGNMENT 33
78#define FAULT_CODE_DEBUG 34
79#else
80#define FAULT_CODE_ALIGNMENT 1
81#define FAULT_CODE_DEBUG 2
82#endif
83
84void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
85 struct pt_regs *),
86 int sig, int code, const char *name);
87
88void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
89 struct pt_regs *),
90 int sig, int code, const char *name);
91
92extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
93
94struct mm_struct;
95void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr);
96extern void __show_regs(struct pt_regs *);
97
98#endif