aboutsummaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-11-20 16:22:55 +0200
committerAvi Kivity <avi@redhat.com>2012-01-04 13:34:49 +0200
commitbe675c972088eba210e18dc125613e9f205a6bfb (patch)
tree8b980da41377565172d1ec921d7e1b303ac53dcb /memory.c
parent7638e0d220df9dd150492ec59ac9683015e3c8ba (diff)
memory: move endianness compensation to memory core
Instead of doing device endianness compensation in cpu_register_io_memory(), do it in the memory core. Signed-off-by: Avi Kivity <avi@redhat.com> Reviewed-by: Richard Henderson <rth@twiddle.net>
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/memory.c b/memory.c
index 868ffd0bc5..6f9fea15ad 100644
--- a/memory.c
+++ b/memory.c
@@ -857,6 +857,15 @@ static void memory_region_destructor_rom_device(MemoryRegion *mr)
cpu_unregister_io_memory(mr->ram_addr & ~(TARGET_PAGE_MASK | IO_MEM_ROMD));
}
+static bool memory_region_wrong_endianness(MemoryRegion *mr)
+{
+#ifdef TARGET_BIG_ENDIAN
+ return mr->ops->endianness == DEVICE_LITTLE_ENDIAN;
+#else
+ return mr->ops->endianness == DEVICE_BIG_ENDIAN;
+#endif
+}
+
void memory_region_init(MemoryRegion *mr,
const char *name,
uint64_t size)
@@ -967,12 +976,24 @@ static uint32_t memory_region_read_thunk_b(void *mr, target_phys_addr_t addr)
static uint32_t memory_region_read_thunk_w(void *mr, target_phys_addr_t addr)
{
- return memory_region_read_thunk_n(mr, addr, 2);
+ uint32_t data;
+
+ data = memory_region_read_thunk_n(mr, addr, 2);
+ if (memory_region_wrong_endianness(mr)) {
+ data = bswap16(data);
+ }
+ return data;
}
static uint32_t memory_region_read_thunk_l(void *mr, target_phys_addr_t addr)
{
- return memory_region_read_thunk_n(mr, addr, 4);
+ uint32_t data;
+
+ data = memory_region_read_thunk_n(mr, addr, 4);
+ if (memory_region_wrong_endianness(mr)) {
+ data = bswap32(data);
+ }
+ return data;
}
static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,
@@ -984,12 +1005,18 @@ static void memory_region_write_thunk_b(void *mr, target_phys_addr_t addr,
static void memory_region_write_thunk_w(void *mr, target_phys_addr_t addr,
uint32_t data)
{
+ if (memory_region_wrong_endianness(mr)) {
+ data = bswap16(data);
+ }
memory_region_write_thunk_n(mr, addr, 2, data);
}
static void memory_region_write_thunk_l(void *mr, target_phys_addr_t addr,
uint32_t data)
{
+ if (memory_region_wrong_endianness(mr)) {
+ data = bswap32(data);
+ }
memory_region_write_thunk_n(mr, addr, 4, data);
}
@@ -1014,8 +1041,7 @@ static void memory_region_prepare_ram_addr(MemoryRegion *mr)
mr->destructor = memory_region_destructor_iomem;
mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk,
memory_region_write_thunk,
- mr,
- mr->ops->endianness);
+ mr);
mr->backend_registered = true;
}
@@ -1082,8 +1108,7 @@ void memory_region_init_rom_device(MemoryRegion *mr,
mr->ram_addr = qemu_ram_alloc(size, mr);
mr->ram_addr |= cpu_register_io_memory(memory_region_read_thunk,
memory_region_write_thunk,
- mr,
- mr->ops->endianness);
+ mr);
mr->ram_addr |= IO_MEM_ROMD;
mr->backend_registered = true;
}