From: Paolo Bonzini Date: Fri, 24 May 2013 15:58:37 +0000 (+0200) Subject: memory: correctly handle endian-swapped 64-bit accesses X-Git-Tag: qemu-xen-4.4.0-rc1~6^2~343^2~3 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=968a5627c80ff2b9fd1ed40f9400897088bd661a;p=qemu-upstream-4.5-testing.git memory: correctly handle endian-swapped 64-bit accesses Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- diff --git a/exec.c b/exec.c index 1c4c46683..453946e1b 100644 --- a/exec.c +++ b/exec.c @@ -2263,15 +2263,21 @@ static inline uint64_t ldq_phys_internal(hwaddr addr, false); if (l < 8 || !memory_access_is_direct(section->mr, false)) { /* I/O case */ - - /* XXX This is broken when device endian != cpu endian. - Fix and add "endian" variable check */ #ifdef TARGET_WORDS_BIGENDIAN val = io_mem_read(section->mr, addr1, 4) << 32; val |= io_mem_read(section->mr, addr1 + 4, 4); #else val = io_mem_read(section->mr, addr1, 4); val |= io_mem_read(section->mr, addr1 + 4, 4) << 32; +#endif +#if defined(TARGET_WORDS_BIGENDIAN) + if (endian == DEVICE_LITTLE_ENDIAN) { + val = bswap64(val); + } +#else + if (endian == DEVICE_BIG_ENDIAN) { + val = bswap64(val); + } #endif } else { /* RAM case */ diff --git a/memory.c b/memory.c index ca2710214..f84fc53d4 100644 --- a/memory.c +++ b/memory.c @@ -957,6 +957,9 @@ static void adjust_endianness(MemoryRegion *mr, uint64_t *data, unsigned size) case 4: *data = bswap32(*data); break; + case 8: + *data = bswap64(*data); + break; default: abort(); }