Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust

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>

authored by

FUJITA Tomonori and committed by
Miguel Ojeda
8ad470d4 8c8efa93

+21 -14
+21 -14
arch/riscv/include/asm/bug.h
··· 31 31 32 32 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS 33 33 #define __BUG_ENTRY_ADDR RISCV_INT " 1b - ." 34 - #define __BUG_ENTRY_FILE RISCV_INT " %0 - ." 34 + #define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ." 35 35 #else 36 36 #define __BUG_ENTRY_ADDR RISCV_PTR " 1b" 37 - #define __BUG_ENTRY_FILE RISCV_PTR " %0" 37 + #define __BUG_ENTRY_FILE(file) RISCV_PTR " " file 38 38 #endif 39 39 40 40 #ifdef CONFIG_DEBUG_BUGVERBOSE 41 - #define __BUG_ENTRY \ 41 + #define __BUG_ENTRY(file, line, flags) \ 42 42 __BUG_ENTRY_ADDR "\n\t" \ 43 - __BUG_ENTRY_FILE "\n\t" \ 44 - RISCV_SHORT " %1\n\t" \ 45 - RISCV_SHORT " %2" 43 + __BUG_ENTRY_FILE(file) "\n\t" \ 44 + RISCV_SHORT " " line "\n\t" \ 45 + RISCV_SHORT " " flags 46 46 #else 47 - #define __BUG_ENTRY \ 48 - __BUG_ENTRY_ADDR "\n\t" \ 49 - RISCV_SHORT " %2" 47 + #define __BUG_ENTRY(file, line, flags) \ 48 + __BUG_ENTRY_ADDR "\n\t" \ 49 + RISCV_SHORT " " flags 50 50 #endif 51 51 52 52 #ifdef CONFIG_GENERIC_BUG 53 - #define __BUG_FLAGS(flags) \ 54 - do { \ 55 - __asm__ __volatile__ ( \ 53 + 54 + #define ARCH_WARN_ASM(file, line, flags, size) \ 56 55 "1:\n\t" \ 57 56 "ebreak\n" \ 58 57 ".pushsection __bug_table,\"aw\"\n\t" \ 59 58 "2:\n\t" \ 60 - __BUG_ENTRY "\n\t" \ 61 - ".org 2b + %3\n\t" \ 59 + __BUG_ENTRY(file, line, flags) "\n\t" \ 60 + ".org 2b + " size "\n\t" \ 62 61 ".popsection" \ 62 + 63 + #define __BUG_FLAGS(flags) \ 64 + do { \ 65 + __asm__ __volatile__ ( \ 66 + ARCH_WARN_ASM("%0", "%1", "%2", "%3") \ 63 67 : \ 64 68 : "i" (__FILE__), "i" (__LINE__), \ 65 69 "i" (flags), \ 66 70 "i" (sizeof(struct bug_entry))); \ 67 71 } while (0) 72 + 68 73 #else /* CONFIG_GENERIC_BUG */ 69 74 #define __BUG_FLAGS(flags) do { \ 70 75 __asm__ __volatile__ ("ebreak\n"); \ ··· 82 77 } while (0) 83 78 84 79 #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags)) 80 + 81 + #define ARCH_WARN_REACHABLE 85 82 86 83 #define HAVE_ARCH_BUG 87 84