memory: Access MemoryRegion with endianness
Preparation for collapsing the two byte swaps adjust_endianness and
handle_bswap into the former.
Call memory_region_dispatch_{read|write} with endianness encoded into
the "MemOp op" operand.
This patch does not change any behaviour as
memory_region_dispatch_{read|write} is yet to handle the endianness.
Once it does handle endianness, callers with byte swaps can collapse
them into adjust_endianness.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Tony Nguyen <tony.nguyen@bt.com>
Message-Id: <8066ab3eb037c0388dfadfe53c5118429dd1de3a.1566466906.git.tony.nguyen@bt.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
diff --git a/memory.c b/memory.c
index 3d87908..d72143a 100644
--- a/memory.c
+++ b/memory.c
@@ -3285,3 +3285,21 @@
}
type_init(memory_register_types)
+
+MemOp devend_memop(enum device_endian end)
+{
+ static MemOp conv[] = {
+ [DEVICE_LITTLE_ENDIAN] = MO_LE,
+ [DEVICE_BIG_ENDIAN] = MO_BE,
+ [DEVICE_NATIVE_ENDIAN] = MO_TE,
+ [DEVICE_HOST_ENDIAN] = 0,
+ };
+ switch (end) {
+ case DEVICE_LITTLE_ENDIAN:
+ case DEVICE_BIG_ENDIAN:
+ case DEVICE_NATIVE_ENDIAN:
+ return conv[end];
+ default:
+ g_assert_not_reached();
+ }
+}