Skip to content

Commit cd9e192

Browse files
Marc Zyngierctmarinas
authored andcommitted
arm64: Work around broken .inst when defective gas is detected
.inst being largely broken with older binutils, it'd be better not to emit it altogether when detecting such configuration (as it leads to all kind of horrors when using alternatives). Generalize the __emit_inst macro and use it extensively in asm/sysreg.h, and make it generate a .long when a broken gas is detected. The disassembly will be crap, but at least we can write semi-sane code. Acked-by: Will Deacon <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent bbb56c2 commit cd9e192

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

arch/arm64/include/asm/sysreg.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,33 @@
3535
#define sys_reg(op0, op1, crn, crm, op2) \
3636
((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5))
3737

38+
#ifndef CONFIG_BROKEN_GAS_INST
39+
3840
#ifdef __ASSEMBLY__
3941
#define __emit_inst(x) .inst (x)
4042
#else
4143
#define __emit_inst(x) ".inst " __stringify((x)) "\n\t"
4244
#endif
4345

46+
#else /* CONFIG_BROKEN_GAS_INST */
47+
48+
#ifndef CONFIG_CPU_BIG_ENDIAN
49+
#define __INSTR_BSWAP(x) (x)
50+
#else /* CONFIG_CPU_BIG_ENDIAN */
51+
#define __INSTR_BSWAP(x) ((((x) << 24) & 0xff000000) | \
52+
(((x) << 8) & 0x00ff0000) | \
53+
(((x) >> 8) & 0x0000ff00) | \
54+
(((x) >> 24) & 0x000000ff))
55+
#endif /* CONFIG_CPU_BIG_ENDIAN */
56+
57+
#ifdef __ASSEMBLY__
58+
#define __emit_inst(x) .long __INSTR_BSWAP(x)
59+
#else /* __ASSEMBLY__ */
60+
#define __emit_inst(x) ".long " __stringify(__INSTR_BSWAP(x)) "\n\t"
61+
#endif /* __ASSEMBLY__ */
62+
63+
#endif /* CONFIG_BROKEN_GAS_INST */
64+
4465
#define SYS_MIDR_EL1 sys_reg(3, 0, 0, 0, 0)
4566
#define SYS_MPIDR_EL1 sys_reg(3, 0, 0, 0, 5)
4667
#define SYS_REVIDR_EL1 sys_reg(3, 0, 0, 0, 6)
@@ -232,11 +253,11 @@
232253
.equ .L__reg_num_xzr, 31
233254

234255
.macro mrs_s, rt, sreg
235-
.inst 0xd5200000|(\sreg)|(.L__reg_num_\rt)
256+
__emit_inst(0xd5200000|(\sreg)|(.L__reg_num_\rt))
236257
.endm
237258

238259
.macro msr_s, sreg, rt
239-
.inst 0xd5000000|(\sreg)|(.L__reg_num_\rt)
260+
__emit_inst(0xd5000000|(\sreg)|(.L__reg_num_\rt))
240261
.endm
241262

242263
#else
@@ -250,11 +271,11 @@ asm(
250271
" .equ .L__reg_num_xzr, 31\n"
251272
"\n"
252273
" .macro mrs_s, rt, sreg\n"
253-
" .inst 0xd5200000|(\\sreg)|(.L__reg_num_\\rt)\n"
274+
__emit_inst(0xd5200000|(\\sreg)|(.L__reg_num_\\rt))
254275
" .endm\n"
255276
"\n"
256277
" .macro msr_s, sreg, rt\n"
257-
" .inst 0xd5000000|(\\sreg)|(.L__reg_num_\\rt)\n"
278+
__emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt))
258279
" .endm\n"
259280
);
260281

0 commit comments

Comments
 (0)