qemu-stable
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] hw/mips/malta: Fix the malta machine on big endian hosts


From: Thomas Huth
Subject: Re: [PATCH] hw/mips/malta: Fix the malta machine on big endian hosts
Date: Thu, 30 Mar 2023 17:42:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

On 30/03/2023 17.33, Peter Maydell wrote:
On Thu, 30 Mar 2023 at 16:27, Thomas Huth <thuth@redhat.com> wrote:

Booting a Linux kernel with the malta machine is currently broken
on big endian hosts. The cpu_to_gt32 macro wants to byteswap a value
for little endian targets only, but uses the wrong way to do this:
cpu_to_[lb]e32 works the other way round on big endian hosts! Fix
it by using the same ways on both, big and little endian hosts.

Fixes: 0c8427baf0 ("hw/mips/malta: Use bootloader helper to set BAR registers")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
  I've checked that both, the kernel from
  https://landley.net/toybox/downloads/binaries/mkroot/0.8.9/mipsel.tgz
  and the kernel from
  https://landley.net/toybox/downloads/binaries/mkroot/0.8.9/mips.tgz
  now boot fine on both, a little endian (x86) and a big endian (s390x) host.

  hw/mips/malta.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index af9021316d..b26ed1fc9a 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -629,9 +629,9 @@ static void bl_setup_gt64120_jump_kernel(void **p, uint64_t 
run_addr,

      /* Bus endianess is always reversed */
  #if TARGET_BIG_ENDIAN
-#define cpu_to_gt32 cpu_to_le32
+#define cpu_to_gt32(x) (x)
  #else
-#define cpu_to_gt32 cpu_to_be32
+#define cpu_to_gt32(x) bswap32(x)
  #endif

So if we:
  * do nothing to the value on a BE host
  * swap the value on an LE host

isn't that the same as cpu_to_be32() in both cases?

No, it's about the *target*, not the host:

* do nothing to the value for a BE *target*
* swap the value for LE *targets*

It's quite weird and it also took me a while to understand this, but this seems to be the way it's working right with all combinations.

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]