qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 19/22] memory: correctly handle endian-swapped 64-bi


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 19/22] memory: correctly handle endian-swapped 64-bit accesses
Date: Thu, 30 May 2013 23:03:53 +0200

Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
 exec.c   |   12 +++++++++---
 memory.c |    3 +++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index 1c4c466..453946e 100644
--- a/exec.c
+++ b/exec.c
@@ -2263,9 +2263,6 @@ 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);
@@ -2273,6 +2270,15 @@ static inline uint64_t ldq_phys_internal(hwaddr addr,
         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 */
         ptr = qemu_get_ram_ptr((memory_region_get_ram_addr(section->mr)
diff --git a/memory.c b/memory.c
index ca27102..f84fc53 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();
         }
-- 
1.7.4.1





reply via email to

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