qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	qemu-stable@nongnu.org, "Aurelien Jarno" <aurelien@aurel32.net>,
	"Rob Landley" <rob@landley.net>
Subject: Re: [PATCH] hw/mips/malta: Fix the malta machine on big endian hosts
Date: Thu, 30 Mar 2023 17:42:41 +0200	[thread overview]
Message-ID: <2b237e97-5490-9ca0-a540-707ca0fc2669@redhat.com> (raw)
In-Reply-To: <CAFEAcA_2H9rMG6uu8JY8VDY96UjmvPuXBYzoQmy8adM+sqUF+Q@mail.gmail.com>

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	other threads:[~2023-03-30 15:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 15:26 [PATCH] hw/mips/malta: Fix the malta machine on big endian hosts Thomas Huth
2023-03-30 15:33 ` Peter Maydell
2023-03-30 15:42   ` Thomas Huth [this message]
2023-04-13 16:07 ` Michael Tokarev
2023-04-13 16:26   ` Peter Maydell
2023-05-09 18:44     ` Peter Maydell
2023-05-31  7:13       ` Thomas Huth
2023-06-05  6:20         ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b237e97-5490-9ca0-a540-707ca0fc2669@redhat.com \
    --to=thuth@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=jiaxun.yang@flygoat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=rob@landley.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).