hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/arch/riscv/include/asm/bug.h
....@@ -1,14 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2012 Regents of the University of California
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation, version 2.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
124 */
135
146 #ifndef _ASM_RISCV_BUG_H
....@@ -20,10 +12,21 @@
2012
2113 #include <asm/asm.h>
2214
23
-#ifdef CONFIG_GENERIC_BUG
24
-#define __BUG_INSN _AC(0x00100073, UL) /* ebreak */
15
+#define __INSN_LENGTH_MASK _UL(0x3)
16
+#define __INSN_LENGTH_32 _UL(0x3)
17
+#define __COMPRESSED_INSN_MASK _UL(0xffff)
2518
26
-#ifndef __ASSEMBLY__
19
+#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
20
+#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
21
+
22
+#define GET_INSN_LENGTH(insn) \
23
+({ \
24
+ unsigned long __len; \
25
+ __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
26
+ 4UL : 2UL; \
27
+ __len; \
28
+})
29
+
2730 typedef u32 bug_insn_t;
2831
2932 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
....@@ -38,51 +41,51 @@
3841 #define __BUG_ENTRY \
3942 __BUG_ENTRY_ADDR "\n\t" \
4043 __BUG_ENTRY_FILE "\n\t" \
41
- RISCV_SHORT " %1"
44
+ RISCV_SHORT " %1\n\t" \
45
+ RISCV_SHORT " %2"
4246 #else
4347 #define __BUG_ENTRY \
44
- __BUG_ENTRY_ADDR
48
+ __BUG_ENTRY_ADDR "\n\t" \
49
+ RISCV_SHORT " %2"
4550 #endif
4651
47
-#define BUG() \
52
+#ifdef CONFIG_GENERIC_BUG
53
+#define __BUG_FLAGS(flags) \
4854 do { \
4955 __asm__ __volatile__ ( \
5056 "1:\n\t" \
5157 "ebreak\n" \
52
- ".pushsection __bug_table,\"a\"\n\t" \
58
+ ".pushsection __bug_table,\"aw\"\n\t" \
5359 "2:\n\t" \
5460 __BUG_ENTRY "\n\t" \
55
- ".org 2b + %2\n\t" \
61
+ ".org 2b + %3\n\t" \
5662 ".popsection" \
5763 : \
5864 : "i" (__FILE__), "i" (__LINE__), \
59
- "i" (sizeof(struct bug_entry))); \
60
- unreachable(); \
65
+ "i" (flags), \
66
+ "i" (sizeof(struct bug_entry))); \
6167 } while (0)
62
-#endif /* !__ASSEMBLY__ */
6368 #else /* CONFIG_GENERIC_BUG */
64
-#ifndef __ASSEMBLY__
65
-#define BUG() \
66
-do { \
69
+#define __BUG_FLAGS(flags) do { \
6770 __asm__ __volatile__ ("ebreak\n"); \
71
+} while (0)
72
+#endif /* CONFIG_GENERIC_BUG */
73
+
74
+#define BUG() do { \
75
+ __BUG_FLAGS(0); \
6876 unreachable(); \
6977 } while (0)
70
-#endif /* !__ASSEMBLY__ */
71
-#endif /* CONFIG_GENERIC_BUG */
78
+
79
+#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
7280
7381 #define HAVE_ARCH_BUG
7482
7583 #include <asm-generic/bug.h>
7684
77
-#ifndef __ASSEMBLY__
78
-
7985 struct pt_regs;
8086 struct task_struct;
8187
82
-extern void die(struct pt_regs *regs, const char *str);
83
-extern void do_trap(struct pt_regs *regs, int signo, int code,
84
- unsigned long addr, struct task_struct *tsk);
85
-
86
-#endif /* !__ASSEMBLY__ */
88
+void die(struct pt_regs *regs, const char *str);
89
+void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr);
8790
8891 #endif /* _ASM_RISCV_BUG_H */