From 079bf6f0f93d01c8be3429d9a8a867ef84501557 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Thu, 10 Jul 2025 00:29:29 +0100 Subject: [PATCH] firmware: Replace sole uses of REGBYTES with __SIZEOF_LONG__ This code has nothing to do with the ISA's registers, it's about the format of ELF relocations. As such, __SIZEOF_LONG__, being a language / ABI-level property, is a more appropriate constant to use. This also makes it easier to support CHERI, where general-purpose registers are extended to be capabilities, not just integers, and so the register size is not the same as the machine word size. This also happens to make it more correct for RV64ILP32, where the registers are 64-bit integers but the ABI is 32-bit (both for long and for the ELF format), though properly supporting that ABI is not part of the motivation here, just a consequence of improving the code for CHERI. Signed-off-by: Jessica Clarke Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20250709232932.37622-2-jrtc27@jrtc27.com Signed-off-by: Anup Patel --- firmware/fw_base.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 9e2c017c..5300ecf2 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -80,17 +80,17 @@ _sc_fail: lla t1, __rela_dyn_end beq t0, t1, _relocate_done 2: - REG_L t5, REGBYTES(t0) /* t5 <-- relocation info:type */ + REG_L t5, __SIZEOF_LONG__(t0) /* t5 <-- relocation info:type */ li t3, R_RISCV_RELATIVE /* reloc type R_RISCV_RELATIVE */ bne t5, t3, 3f REG_L t3, 0(t0) - REG_L t5, (REGBYTES * 2)(t0) /* t5 <-- addend */ + REG_L t5, (__SIZEOF_LONG__ * 2)(t0) /* t5 <-- addend */ add t5, t5, t2 add t3, t3, t2 REG_S t5, 0(t3) /* store runtime address to the GOT entry */ 3: - addi t0, t0, (REGBYTES * 3) + addi t0, t0, (__SIZEOF_LONG__ * 3) blt t0, t1, 2b _relocate_done: /* At this point we are running from link address */