qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] fw_cfg: fix endianness in fw_cfg_data_mem_read(


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] fw_cfg: fix endianness in fw_cfg_data_mem_read() / _write()
Date: Wed, 31 Dec 2014 14:20:41 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0


On 31/12/2014 12:21, Laszlo Ersek wrote:
> Because register emulation in QEMU is integer-preserving, not
> string-preserving (see (2)), we have to jump through a few hoops.
> 
> (3a) We defined the memory mapped fw_cfg data register as
> DEVICE_BIG_ENDIAN.
> 
> The particular choice is not really relevant -- we picked BE only for
> consistency with the control register, which *does* transfer integers --
> but our choice affects how we must host-encode values from fw_cfg strings.
> 
> (3b) Since we want the fw_cfg string "XY" to appear as the [0x58, 0x59]
> array on the data register, *and* we picked DEVICE_BIG_ENDIAN, we must
> compose the host (== C language) value 0x5859 in the read accessor
> function.

I'm not sure this is right.

DEVICE_BIG_ENDIAN means that if we return 0xaabb and the guest is little
endian, it will return 0xbbaa.  But the value returned by the accessor
is always in host endianness.

And it makes sense to swap in the guest if the register is big endian
but the guest is little endian.

So IMHO your old code is right.  Either you are overthinking it, or I'm
underthinking it...  Knowing our respective personalities, either
possibility is just as likely... ;)

Paolo



reply via email to

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