[PATCH 01/11] ARM: BUG: Move the assembly out of __BUG() macro

Sebastian Andrzej Siewior sebastian at breakpoint.cc
Fri Oct 9 15:21:08 PDT 2026


Move the assembly line from within the __BUG() macro into its own
define. The quotation marks and the string escape can be removed and
instead the resulting __BUG__LINE() macro can be wrapped into
__stringify() to achieve the same.
The BUG_INSTR() expects a string context. This can be replaced with
___asm_opcode_to_mem_arm()/_thumb16() macro. Wrap this into
BUG_ENCODING() macro.

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
 arch/arm/include/asm/bug.h | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index ba8d9d7d242bd..24f46d4f6e733 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -14,9 +14,11 @@
 #ifdef CONFIG_THUMB2_KERNEL
 #define BUG_INSTR_VALUE 0xde02
 #define BUG_INSTR(__value) __inst_thumb16(__value)
+#define BUG_ENCODING() .short ___asm_opcode_to_mem_thumb16(BUG_INSTR_VALUE)
 #else
 #define BUG_INSTR_VALUE 0xe7f001f2
 #define BUG_INSTR(__value) __inst_arm(__value)
+#define BUG_ENCODING() .long ___asm_opcode_to_mem_arm(BUG_INSTR_VALUE)
 #endif
 
 
@@ -25,24 +27,27 @@
 
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 
+#define __BUG__LINE(__file, __line, __value)			\
+	1: ;							\
+	BUG_ENCODING();						\
+	.pushsection .rodata.str, "aMS", %progbits, 1;		\
+	2: .asciz  __file;					\
+	.popsection;						\
+	.pushsection __bug_table,"aw";				\
+	.align 2;						\
+	3: .word 1b, 2b;					\
+	.hword __line , 0;					\
+	.popsection;
+
 /*
  * The extra indirection is to ensure that the __FILE__ string comes through
  * OK. Many version of gcc do not support the asm %c parameter which would be
  * preferable to this unpleasantness. We use mergeable string sections to
  * avoid multiple copies of the string appearing in the kernel image.
  */
-
 #define __BUG(__file, __line, __value)				\
 do {								\
-	asm volatile("1:\t" BUG_INSTR(__value) "\n"  \
-		".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
-		"2:\t.asciz " #__file "\n" 			\
-		".popsection\n" 				\
-		".pushsection __bug_table,\"aw\"\n"		\
-		".align 2\n"					\
-		"3:\t.word 1b, 2b\n"				\
-		"\t.hword " #__line ", 0\n"			\
-		".popsection");					\
+	asm volatile(__stringify(__BUG__LINE(__file, __line, __value))); \
 	unreachable();						\
 } while (0)
 

-- 
2.55.0




More information about the linux-arm-kernel mailing list