On Fri, Aug 29, 2014 at 12:40:43PM +0200, Marc Marí wrote:
> +static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)
> +{
> + QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
> + int i;
> + union {
> + uint8_t bytes[8];
> + uint64_t u64;
> + } quad;
> +
> + if (qtest_big_endian()) {
> + for (i = 0; i < 8; ++i) {
> + quad.bytes[7-i] = qpci_io_readb(dev->pdev, addr + i);
> + }
> + } else {
> + for (i = 0; i < 8; ++i) {
> + quad.bytes[i] = qpci_io_readb(dev->pdev, addr + i);
> + }
> + }
> +
> + return quad.u64;
> +}
This assumes that the host is little-endian. The host could be
big-endian!
qvirtio_pci_config_readq() needs to return a 64-bit value in host CPU
endianness. So the logic should be:
for (i = 0; i < 8; ++i) {
quad.bytes[i] = qpci_io_readb(dev->pdev, addr + i);
}
if (qtest_big_endian() != qtest_host_endian()) {
quad.u64 = bswap64(quad.u64);
}
return quard.u64;
Stefan
pgpwVZryR2sdx.pgp
Description: PGP signature
