]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust
authorFUJITA Tomonori <fujita.tomonori@gmail.com>
Fri, 2 May 2025 09:45:34 +0000 (18:45 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 22 Jul 2025 22:04:53 +0000 (00:04 +0200)
Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with
Rust to avoid the duplication.

No functional changes.

Acked-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Link: https://lore.kernel.org/r/20250502094537.231725-3-fujita.tomonori@gmail.com
[ Remove ending newline in `ARCH_WARN_ASM` content to be closer to the
  original. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
arch/riscv/include/asm/bug.h

index 1aaea81fb1413eeb87dc23cbd9346055fb6f6ef8..4c03e20ad11f2d422f4648ecfb9c6089d0e76a79 100644 (file)
@@ -31,40 +31,45 @@ typedef u32 bug_insn_t;
 
 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
 #define __BUG_ENTRY_ADDR       RISCV_INT " 1b - ."
-#define __BUG_ENTRY_FILE       RISCV_INT " %0 - ."
+#define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ."
 #else
 #define __BUG_ENTRY_ADDR       RISCV_PTR " 1b"
-#define __BUG_ENTRY_FILE       RISCV_PTR " %0"
+#define __BUG_ENTRY_FILE(file) RISCV_PTR " " file
 #endif
 
 #ifdef CONFIG_DEBUG_BUGVERBOSE
-#define __BUG_ENTRY                    \
+#define __BUG_ENTRY(file, line, flags) \
        __BUG_ENTRY_ADDR "\n\t"         \
-       __BUG_ENTRY_FILE "\n\t"         \
-       RISCV_SHORT " %1\n\t"           \
-       RISCV_SHORT " %2"
+       __BUG_ENTRY_FILE(file) "\n\t"   \
+       RISCV_SHORT " " line "\n\t"     \
+       RISCV_SHORT " " flags
 #else
-#define __BUG_ENTRY                    \
-       __BUG_ENTRY_ADDR "\n\t"         \
-       RISCV_SHORT " %2"
+#define __BUG_ENTRY(file, line, flags)         \
+       __BUG_ENTRY_ADDR "\n\t"                 \
+       RISCV_SHORT " " flags
 #endif
 
 #ifdef CONFIG_GENERIC_BUG
-#define __BUG_FLAGS(flags)                                     \
-do {                                                           \
-       __asm__ __volatile__ (                                  \
+
+#define ARCH_WARN_ASM(file, line, flags, size)                 \
                "1:\n\t"                                        \
                        "ebreak\n"                              \
                        ".pushsection __bug_table,\"aw\"\n\t"   \
                "2:\n\t"                                        \
-                       __BUG_ENTRY "\n\t"                      \
-                       ".org 2b + %3\n\t"                      \
+               __BUG_ENTRY(file, line, flags) "\n\t"           \
+                       ".org 2b + " size "\n\t"                \
                        ".popsection"                           \
+
+#define __BUG_FLAGS(flags)                                     \
+do {                                                           \
+       __asm__ __volatile__ (                                  \
+               ARCH_WARN_ASM("%0", "%1", "%2", "%3")           \
                :                                               \
                : "i" (__FILE__), "i" (__LINE__),               \
                  "i" (flags),                                  \
                  "i" (sizeof(struct bug_entry)));              \
 } while (0)
+
 #else /* CONFIG_GENERIC_BUG */
 #define __BUG_FLAGS(flags) do {                                        \
        __asm__ __volatile__ ("ebreak\n");                      \
@@ -78,6 +83,8 @@ do {                                                          \
 
 #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
 
+#define ARCH_WARN_REACHABLE
+
 #define HAVE_ARCH_BUG
 
 #include <asm-generic/bug.h>