* [PATCH] load_aout: replace bswap_needed with big_endian
@ 2025-03-20 12:43 Paolo Bonzini
2025-03-20 12:49 ` Philippe Mathieu-Daudé
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Bonzini @ 2025-03-20 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland
Targets know whether they are big-endian more than they know if
the endianness is different from the host: the former is mostly
a constant, at least in machine creation code, while the latter
has to be computed with TARGET_BIG_ENDIAN != HOST_BIG_ENDIAN or
something like that.
load_aout, however, takes a "bswap_needed" argument. Replace
it with a "big_endian" argument; even though all users are
big-endian, it is cheap enough to keep the optional swapping
functionality even for little-endian boards.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/hw/loader.h | 2 +-
hw/core/loader.c | 4 ++--
hw/ppc/mac_newworld.c | 7 +------
hw/ppc/mac_oldworld.c | 7 +------
hw/sparc/sun4m.c | 9 +--------
hw/sparc64/sun4u.c | 9 +--------
6 files changed, 7 insertions(+), 31 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 784a93d6c17..d280dc33e96 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -190,7 +190,7 @@ ssize_t load_elf(const char *filename,
void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
- int bswap_needed, hwaddr target_page_size);
+ bool big_endian, hwaddr target_page_size);
#define LOAD_UIMAGE_LOADADDR_INVALID (-1)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index ce6ff1b52e3..2e35f0aa905 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -226,7 +226,7 @@ static void bswap_ahdr(struct exec *e)
ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
- int bswap_needed, hwaddr target_page_size)
+ bool big_endian, hwaddr target_page_size)
{
int fd;
ssize_t size, ret;
@@ -241,7 +241,7 @@ ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
if (size < 0)
goto fail;
- if (bswap_needed) {
+ if (big_endian != HOST_BIG_ENDIAN) {
bswap_ahdr(&e);
}
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index cb3dc3ab482..2d5309d6f55 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -197,11 +197,6 @@ static void ppc_core99_init(MachineState *machine)
}
if (machine->kernel_filename) {
- int bswap_needed = 0;
-
-#ifdef BSWAP_NEEDED
- bswap_needed = 1;
-#endif
kernel_base = KERNEL_LOAD_ADDR;
kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
@@ -209,7 +204,7 @@ static void ppc_core99_init(MachineState *machine)
if (kernel_size < 0) {
kernel_size = load_aout(machine->kernel_filename, kernel_base,
machine->ram_size - kernel_base,
- bswap_needed, TARGET_PAGE_SIZE);
+ true, TARGET_PAGE_SIZE);
}
if (kernel_size < 0) {
kernel_size = load_image_targphys(machine->kernel_filename,
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 0dbcea035c3..b5814690f5a 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -153,11 +153,6 @@ static void ppc_heathrow_init(MachineState *machine)
}
if (machine->kernel_filename) {
- int bswap_needed = 0;
-
-#ifdef BSWAP_NEEDED
- bswap_needed = 1;
-#endif
kernel_base = KERNEL_LOAD_ADDR;
kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
@@ -165,7 +160,7 @@ static void ppc_heathrow_init(MachineState *machine)
if (kernel_size < 0) {
kernel_size = load_aout(machine->kernel_filename, kernel_base,
machine->ram_size - kernel_base,
- bswap_needed, TARGET_PAGE_SIZE);
+ true, TARGET_PAGE_SIZE);
}
if (kernel_size < 0) {
kernel_size = load_image_targphys(machine->kernel_filename,
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index a48d3622c5a..5aaafb40dac 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -233,20 +233,13 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
kernel_size = 0;
if (linux_boot) {
- int bswap_needed;
-
-#ifdef BSWAP_NEEDED
- bswap_needed = 1;
-#else
- bswap_needed = 0;
-#endif
kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, NULL,
NULL, NULL, NULL, NULL,
ELFDATA2MSB, EM_SPARC, 0, 0);
if (kernel_size < 0)
kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
- RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
+ RAM_size - KERNEL_LOAD_ADDR, true,
TARGET_PAGE_SIZE);
if (kernel_size < 0)
kernel_size = load_image_targphys(kernel_filename,
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 8ab5cf0461f..d3cb7270ff5 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -168,13 +168,6 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
kernel_size = 0;
if (linux_boot) {
- int bswap_needed;
-
-#ifdef BSWAP_NEEDED
- bswap_needed = 1;
-#else
- bswap_needed = 0;
-#endif
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, kernel_entry,
kernel_addr, &kernel_top, NULL,
ELFDATA2MSB, EM_SPARCV9, 0, 0);
@@ -182,7 +175,7 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
*kernel_addr = KERNEL_LOAD_ADDR;
*kernel_entry = KERNEL_LOAD_ADDR;
kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
- RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
+ RAM_size - KERNEL_LOAD_ADDR, true,
TARGET_PAGE_SIZE);
}
if (kernel_size < 0) {
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] load_aout: replace bswap_needed with big_endian
2025-03-20 12:43 [PATCH] load_aout: replace bswap_needed with big_endian Paolo Bonzini
@ 2025-03-20 12:49 ` Philippe Mathieu-Daudé
2025-03-20 22:33 ` Pierrick Bouvier
2025-03-23 22:32 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-03-20 12:49 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: mark.cave-ayland
On 20/3/25 13:43, Paolo Bonzini wrote:
> Targets know whether they are big-endian more than they know if
> the endianness is different from the host: the former is mostly
> a constant, at least in machine creation code, while the latter
> has to be computed with TARGET_BIG_ENDIAN != HOST_BIG_ENDIAN or
> something like that.
>
> load_aout, however, takes a "bswap_needed" argument. Replace
> it with a "big_endian" argument; even though all users are
> big-endian, it is cheap enough to keep the optional swapping
> functionality even for little-endian boards.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/hw/loader.h | 2 +-
> hw/core/loader.c | 4 ++--
> hw/ppc/mac_newworld.c | 7 +------
> hw/ppc/mac_oldworld.c | 7 +------
> hw/sparc/sun4m.c | 9 +--------
> hw/sparc64/sun4u.c | 9 +--------
> 6 files changed, 7 insertions(+), 31 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] load_aout: replace bswap_needed with big_endian
2025-03-20 12:43 [PATCH] load_aout: replace bswap_needed with big_endian Paolo Bonzini
2025-03-20 12:49 ` Philippe Mathieu-Daudé
@ 2025-03-20 22:33 ` Pierrick Bouvier
2025-03-23 22:32 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Pierrick Bouvier @ 2025-03-20 22:33 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: mark.cave-ayland
On 3/20/25 05:43, Paolo Bonzini wrote:
> Targets know whether they are big-endian more than they know if
> the endianness is different from the host: the former is mostly
> a constant, at least in machine creation code, while the latter
> has to be computed with TARGET_BIG_ENDIAN != HOST_BIG_ENDIAN or
> something like that.
>
> load_aout, however, takes a "bswap_needed" argument. Replace
> it with a "big_endian" argument; even though all users are
> big-endian, it is cheap enough to keep the optional swapping
> functionality even for little-endian boards.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/hw/loader.h | 2 +-
> hw/core/loader.c | 4 ++--
> hw/ppc/mac_newworld.c | 7 +------
> hw/ppc/mac_oldworld.c | 7 +------
> hw/sparc/sun4m.c | 9 +--------
> hw/sparc64/sun4u.c | 9 +--------
> 6 files changed, 7 insertions(+), 31 deletions(-)
>
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index 784a93d6c17..d280dc33e96 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -190,7 +190,7 @@ ssize_t load_elf(const char *filename,
> void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
>
> ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
> - int bswap_needed, hwaddr target_page_size);
> + bool big_endian, hwaddr target_page_size);
>
> #define LOAD_UIMAGE_LOADADDR_INVALID (-1)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index ce6ff1b52e3..2e35f0aa905 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -226,7 +226,7 @@ static void bswap_ahdr(struct exec *e)
>
>
> ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
> - int bswap_needed, hwaddr target_page_size)
> + bool big_endian, hwaddr target_page_size)
> {
> int fd;
> ssize_t size, ret;
> @@ -241,7 +241,7 @@ ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
> if (size < 0)
> goto fail;
>
> - if (bswap_needed) {
> + if (big_endian != HOST_BIG_ENDIAN) {
> bswap_ahdr(&e);
> }
>
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index cb3dc3ab482..2d5309d6f55 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -197,11 +197,6 @@ static void ppc_core99_init(MachineState *machine)
> }
>
> if (machine->kernel_filename) {
> - int bswap_needed = 0;
> -
> -#ifdef BSWAP_NEEDED
> - bswap_needed = 1;
> -#endif
> kernel_base = KERNEL_LOAD_ADDR;
> kernel_size = load_elf(machine->kernel_filename, NULL,
> translate_kernel_address, NULL, NULL, NULL,
> @@ -209,7 +204,7 @@ static void ppc_core99_init(MachineState *machine)
> if (kernel_size < 0) {
> kernel_size = load_aout(machine->kernel_filename, kernel_base,
> machine->ram_size - kernel_base,
> - bswap_needed, TARGET_PAGE_SIZE);
> + true, TARGET_PAGE_SIZE);
> }
> if (kernel_size < 0) {
> kernel_size = load_image_targphys(machine->kernel_filename,
> diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
> index 0dbcea035c3..b5814690f5a 100644
> --- a/hw/ppc/mac_oldworld.c
> +++ b/hw/ppc/mac_oldworld.c
> @@ -153,11 +153,6 @@ static void ppc_heathrow_init(MachineState *machine)
> }
>
> if (machine->kernel_filename) {
> - int bswap_needed = 0;
> -
> -#ifdef BSWAP_NEEDED
> - bswap_needed = 1;
> -#endif
> kernel_base = KERNEL_LOAD_ADDR;
> kernel_size = load_elf(machine->kernel_filename, NULL,
> translate_kernel_address, NULL, NULL, NULL,
> @@ -165,7 +160,7 @@ static void ppc_heathrow_init(MachineState *machine)
> if (kernel_size < 0) {
> kernel_size = load_aout(machine->kernel_filename, kernel_base,
> machine->ram_size - kernel_base,
> - bswap_needed, TARGET_PAGE_SIZE);
> + true, TARGET_PAGE_SIZE);
> }
> if (kernel_size < 0) {
> kernel_size = load_image_targphys(machine->kernel_filename,
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index a48d3622c5a..5aaafb40dac 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -233,20 +233,13 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
>
> kernel_size = 0;
> if (linux_boot) {
> - int bswap_needed;
> -
> -#ifdef BSWAP_NEEDED
> - bswap_needed = 1;
> -#else
> - bswap_needed = 0;
> -#endif
> kernel_size = load_elf(kernel_filename, NULL,
> translate_kernel_address, NULL,
> NULL, NULL, NULL, NULL,
> ELFDATA2MSB, EM_SPARC, 0, 0);
> if (kernel_size < 0)
> kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
> - RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
> + RAM_size - KERNEL_LOAD_ADDR, true,
> TARGET_PAGE_SIZE);
> if (kernel_size < 0)
> kernel_size = load_image_targphys(kernel_filename,
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index 8ab5cf0461f..d3cb7270ff5 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -168,13 +168,6 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
>
> kernel_size = 0;
> if (linux_boot) {
> - int bswap_needed;
> -
> -#ifdef BSWAP_NEEDED
> - bswap_needed = 1;
> -#else
> - bswap_needed = 0;
> -#endif
> kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, kernel_entry,
> kernel_addr, &kernel_top, NULL,
> ELFDATA2MSB, EM_SPARCV9, 0, 0);
> @@ -182,7 +175,7 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
> *kernel_addr = KERNEL_LOAD_ADDR;
> *kernel_entry = KERNEL_LOAD_ADDR;
> kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
> - RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
> + RAM_size - KERNEL_LOAD_ADDR, true,
> TARGET_PAGE_SIZE);
> }
> if (kernel_size < 0) {
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
The rest of BSWAP_NEEDED removal was done here:
https://lore.kernel.org/qemu-devel/20250320223002.2915728-2-pierrick.bouvier@linaro.org
Feel free to combine it with this patch.
Regards,
Pierrick
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] load_aout: replace bswap_needed with big_endian
2025-03-20 12:43 [PATCH] load_aout: replace bswap_needed with big_endian Paolo Bonzini
2025-03-20 12:49 ` Philippe Mathieu-Daudé
2025-03-20 22:33 ` Pierrick Bouvier
@ 2025-03-23 22:32 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2025-03-23 22:32 UTC (permalink / raw)
To: qemu-devel
On 3/20/25 05:43, Paolo Bonzini wrote:
> Targets know whether they are big-endian more than they know if
> the endianness is different from the host: the former is mostly
> a constant, at least in machine creation code, while the latter
> has to be computed with TARGET_BIG_ENDIAN != HOST_BIG_ENDIAN or
> something like that.
>
> load_aout, however, takes a "bswap_needed" argument. Replace
> it with a "big_endian" argument; even though all users are
> big-endian, it is cheap enough to keep the optional swapping
> functionality even for little-endian boards.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Thanks, queued to tcg-next for 10.1.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-23 22:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 12:43 [PATCH] load_aout: replace bswap_needed with big_endian Paolo Bonzini
2025-03-20 12:49 ` Philippe Mathieu-Daudé
2025-03-20 22:33 ` Pierrick Bouvier
2025-03-23 22:32 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).