@samitouri / QOSamiQemu / commits / c64fbc1219

hw/riscv/boot: Replace cpu_to_le32() -> const_le32()

Rather than adapting the array endianness when it it filled, directly initialize the CODE words with the correct endianness. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Message-ID: <20260527201348.29511-9-philmd@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Philippe Mathieu-Daudé committed May 27, 2026 at 22:13 UTC c64fbc121996005f422ade58e3c53d0dc36f4f75
1 file changed +13 -17
hw/riscv/boot.c
+13 -17
@@ -454,40 +454,36 @@ void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts
454 uint64_t kernel_entry,
455 uint64_t fdt_load_addr)
456 {
457 - int i;
457 const bool rv32 = riscv_is_32bit(harts);
458 uint32_t reset_vec[CODE_WORDS + DATA_WORDS];
459
461 - /* .text */
462 - reset_vec[0] = 0x00000297; /* 1: auipc t0, %pcrel_hi(fw_dyn) */
463 - reset_vec[1] = 0x02828613; /* addi a2, t0, %pcrel_lo(1b) */
460 + /* .text (RISC-V instructions are always little-endian) */
461 + reset_vec[0] = const_le32(0x00000297); /* 1: auipc t0, %pcrel_hi(fw_dyn) */
462 + reset_vec[1] = const_le32(0x02828613); /* addi a2, t0, %pcrel_lo(1b) */
463 + reset_vec[2] = const_le32(0xf1402573); /* csrr a0, mhartid */
464 if (harts->harts[0].cfg.ext_zicsr) {
465 - reset_vec[2] = 0xf1402573; /* csrr a0, mhartid */
465 + reset_vec[2] = const_le32(0xf1402573); /* csrr a0, mhartid */
466 } else {
467 /*
468 * The Zicsr extension has been disabled, so let's ensure we don't
469 * run the CSR instruction. Let's fill the address with a non
470 * compressed nop.
471 */
472 - reset_vec[2] = 0x00000013; /* addi x0, x0, 0 */
472 + reset_vec[2] = const_le32(0x00000013); /* addi x0, x0, 0 */
473 }
474 if (rv32) {
475 - reset_vec[3] = 0x0202a583; /* lw a1, 32(t0) */
476 - reset_vec[4] = 0x0182a283; /* lw t0, 24(t0) */
475 + reset_vec[3] = const_le32(0x0202a583); /* lw a1, 32(t0) */
476 + reset_vec[4] = const_le32(0x0182a283); /* lw t0, 24(t0) */
477 } else {
478 - reset_vec[3] = 0x0202b583; /* ld a1, 32(t0) */
479 - reset_vec[4] = 0x0182b283; /* ld t0, 24(t0) */
478 + reset_vec[3] = const_le32(0x0202b583); /* ld a1, 32(t0) */
479 + reset_vec[4] = const_le32(0x0182b283); /* ld t0, 24(t0) */
480 }
481 - reset_vec[5] = 0x00028067; /* jr t0 */
481 + reset_vec[5] = const_le32(0x00028067); /* jr t0 */
482
483 /* .data */
484 - stq_p(&reset_vec[6], start_addr); /* start: .dword */
485 - stq_p(&reset_vec[8], fdt_load_addr); /* fdt_laddr: .dword */
484 + stq_le_p(&reset_vec[6], start_addr); /* start: .dword */
485 + stq_le_p(&reset_vec[8], fdt_load_addr); /* fdt_laddr: .dword */
486
487 - /* copy in the reset vector in little_endian byte order */
488 - for (i = 0; i < ARRAY_SIZE(reset_vec); i++) {
489 - reset_vec[i] = cpu_to_le32(reset_vec[i]);
490 - }
487 rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec),
488 rom_base, &address_space_memory);
489 riscv_rom_copy_firmware_info(machine, harts,