mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
firmware: Simplify FDT header endianness conversion
Reduce the code size by using single-byte loads instead of bit manipulation. This method also does the right thing on (hypothetical) big-endian systems. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
7179e36ce7
commit
7c40909159
@@ -242,30 +242,14 @@ _scratch_init:
|
|||||||
beq t1, a1, _fdt_reloc_done
|
beq t1, a1, _fdt_reloc_done
|
||||||
/* t0 = source FDT start address */
|
/* t0 = source FDT start address */
|
||||||
add t0, a1, zero
|
add t0, a1, zero
|
||||||
/* t2 = source FDT size in big-endian */
|
/* t2 = source FDT size (convert from big-endian) */
|
||||||
#if __riscv_xlen > 32
|
lbu t2, 7(t0)
|
||||||
lwu t2, 4(t0)
|
lbu t3, 6(t0)
|
||||||
#else
|
lbu t4, 5(t0)
|
||||||
lw t2, 4(t0)
|
lbu t5, 4(t0)
|
||||||
#endif
|
|
||||||
/* t3 = bit[15:8] of FDT size */
|
|
||||||
add t3, t2, zero
|
|
||||||
srli t3, t3, 16
|
|
||||||
and t3, t3, a4
|
|
||||||
slli t3, t3, 8
|
slli t3, t3, 8
|
||||||
/* t4 = bit[23:16] of FDT size */
|
|
||||||
add t4, t2, zero
|
|
||||||
srli t4, t4, 8
|
|
||||||
and t4, t4, a4
|
|
||||||
slli t4, t4, 16
|
slli t4, t4, 16
|
||||||
/* t5 = bit[31:24] of FDT size */
|
|
||||||
add t5, t2, zero
|
|
||||||
and t5, t5, a4
|
|
||||||
slli t5, t5, 24
|
slli t5, t5, 24
|
||||||
/* t2 = bit[7:0] of FDT size */
|
|
||||||
srli t2, t2, 24
|
|
||||||
and t2, t2, a4
|
|
||||||
/* t2 = FDT size in little-endian */
|
|
||||||
or t2, t2, t3
|
or t2, t2, t3
|
||||||
or t2, t2, t4
|
or t2, t2, t4
|
||||||
or t2, t2, t5
|
or t2, t2, t5
|
||||||
|
Reference in New Issue
Block a user