diff mbox series

[18/20] hw/core/generic-loader: Use cpu_datapath_is_big_endian()

Message ID 20241204202602.58083-19-philmd@linaro.org
State New
Headers show
Series target: Implement CPUClass::datapath_is_big_endian() handlers | expand

Commit Message

Philippe Mathieu-Daudé Dec. 4, 2024, 8:26 p.m. UTC
Rather that using the binary endianness, use the vCPU one.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/generic-loader.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Richard Henderson Dec. 5, 2024, 12:05 a.m. UTC | #1
On 12/4/24 14:26, Philippe Mathieu-Daudé wrote:
> Rather that using the binary endianness, use the vCPU one.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/core/generic-loader.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
> index abdd4c08a38..7b3b5f06565 100644
> --- a/hw/core/generic-loader.c
> +++ b/hw/core/generic-loader.c
> @@ -31,7 +31,6 @@
>    */
>   
>   #include "qemu/osdep.h"
> -#include "exec/tswap.h"
>   #include "sysemu/dma.h"
>   #include "sysemu/reset.h"
>   #include "hw/boards.h"
> @@ -66,7 +65,6 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
>   {
>       GenericLoaderState *s = GENERIC_LOADER(dev);
>       hwaddr entry;
> -    int big_endian;
>       ssize_t size = 0;
>   
>       s->set_pc = false;
> @@ -134,14 +132,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
>           s->cpu = first_cpu;
>       }
>   
> -    big_endian = qemu_binary_is_bigendian();
> -
>       if (s->file) {
>           AddressSpace *as = s->cpu ? s->cpu->as :  NULL;
>   
>           if (!s->force_raw) {
>               size = load_elf_as(s->file, NULL, NULL, NULL, &entry, NULL, NULL,
> -                               NULL, big_endian, 0, 0, 0, as);
> +                               NULL, cpu_datapath_is_big_endian(s->cpu),
> +                               0, 0, 0, as);
>   
>               if (size < 0) {
>                   size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,

Given that we're not verifying ehdr.e_machine from the file via the generic-loader, I see 
no point in verifying ehdr.e_ident[EI_DATA] either.

I suggest changing load_elf* big_endian parameter to elf_data, then use ELFCLASSNONE to 
skip the EI_DATA test.  This more or less mirrors the elf_machine parameter -- we use 
EM_NONE (0) to skip the e_machine test.


r~
diff mbox series

Patch

diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index abdd4c08a38..7b3b5f06565 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -31,7 +31,6 @@ 
  */
 
 #include "qemu/osdep.h"
-#include "exec/tswap.h"
 #include "sysemu/dma.h"
 #include "sysemu/reset.h"
 #include "hw/boards.h"
@@ -66,7 +65,6 @@  static void generic_loader_realize(DeviceState *dev, Error **errp)
 {
     GenericLoaderState *s = GENERIC_LOADER(dev);
     hwaddr entry;
-    int big_endian;
     ssize_t size = 0;
 
     s->set_pc = false;
@@ -134,14 +132,13 @@  static void generic_loader_realize(DeviceState *dev, Error **errp)
         s->cpu = first_cpu;
     }
 
-    big_endian = qemu_binary_is_bigendian();
-
     if (s->file) {
         AddressSpace *as = s->cpu ? s->cpu->as :  NULL;
 
         if (!s->force_raw) {
             size = load_elf_as(s->file, NULL, NULL, NULL, &entry, NULL, NULL,
-                               NULL, big_endian, 0, 0, 0, as);
+                               NULL, cpu_datapath_is_big_endian(s->cpu),
+                               0, 0, 0, as);
 
             if (size < 0) {
                 size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,