Skip to contentSkip to conversation

hw/sh4/r2d: Replace tswap32() by stl_endian_p()

PATCH In review Philippe Mathieu-Daudé 2 participants 2 messages Sep 30, 2024 – Oct 1, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/sh4/r2d: Replace tswap32() by stl_endian_p()

Replace the target-specific tswap32() calls by stl_endian_p() which does the same but takes the endianness as argument, thus is target-agnostic.

---
Based-on: <[email protected]>
"qemu/bswap: Introduce ld/st_endian_p() API"

---
 hw/sh4/r2d.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/sh4/r2d.c +5 -3
index e5ac6751bd..6739ac435a 100644
@@ -353,9 +353,11 @@ static void r2d_init(MachineState *machine)
         }
 
         /* initialization which should be done by firmware */
-        boot_params.loader_type = tswap32(1);
-        boot_params.initrd_start = tswap32(INITRD_LOAD_OFFSET);
-        boot_params.initrd_size = tswap32(initrd_size);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.loader_type, 1);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.initrd_start,
+                     INITRD_LOAD_OFFSET);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.initrd_size,
+                     initrd_size);
     }
 
     if (kernel_cmdline) {
Signature · 1 line
2.45.2
#1 lore raw
Quoted 19 lines · Philippe Mathieu-Daudé

Replace the target-specific tswap32() calls by stl_endian_p() which does the same but takes the endianness as argument, thus is target-agnostic.

---
Based-on: <[email protected]>
"qemu/bswap: Introduce ld/st_endian_p() API"

---
  hw/sh4/r2d.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
hw/sh4/r2d.c +0 -0
index e5ac6751bd..6739ac435a 100644
@@ -353,9 +353,11 @@ static void r2d_init(MachineState *machine)
          }
 

hw/sh4/r2d.c static void r2d_init(MachineState *machine) · line 361

Quoted 10 lines
hw/sh4/r2d.c +5 -3
          /* initialization which should be done by firmware */
-        boot_params.loader_type = tswap32(1);
-        boot_params.initrd_start = tswap32(INITRD_LOAD_OFFSET);
-        boot_params.initrd_size = tswap32(initrd_size);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.loader_type, 1);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.initrd_start,
+                     INITRD_LOAD_OFFSET);
+        stl_endian_p(TARGET_BIG_ENDIAN, &boot_params.initrd_size,
+                     initrd_size);
      }

I still don't quite get it - the tswap functions already use target_words_bigendian() when being used in common code, so what do you really gain by these changes?

Thomas