@@ -273,6 +273,12 @@ static void qtest_irq_handler(void *opaque, int n, int level)
}
}
+/* Default address space for MMIO accesses */
+static AddressSpace *qtest_mem_as(void)
+{
+ return first_cpu->as;
+}
+
static void qtest_process_command(CharBackend *chr, gchar **words)
{
const gchar *command;
@@ -434,22 +440,22 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
if (words[0][5] == 'b') {
uint8_t data = value;
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 1);
} else if (words[0][5] == 'w') {
uint16_t data = value;
tswap16s(&data);
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 2);
} else if (words[0][5] == 'l') {
uint32_t data = value;
tswap32s(&data);
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 4);
} else if (words[0][5] == 'q') {
uint64_t data = value;
tswap64s(&data);
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 8);
}
qtest_send_prefix(chr);
@@ -468,21 +474,21 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
if (words[0][4] == 'b') {
uint8_t data;
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 1);
value = data;
} else if (words[0][4] == 'w') {
uint16_t data;
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 2);
value = tswap16(data);
} else if (words[0][4] == 'l') {
uint32_t data;
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&data, 4);
value = tswap32(data);
} else if (words[0][4] == 'q') {
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
&value, 8);
tswap64s(&value);
}
@@ -503,7 +509,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
g_assert(len);
data = g_malloc(len);
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED, data,
len);
enc = g_malloc(2 * len + 1);
@@ -529,7 +535,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
g_assert(ret == 0);
data = g_malloc(len);
- address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
+ address_space_read(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED, data,
len);
b64_data = g_base64_encode(data, len);
qtest_send_prefix(chr);
@@ -564,7 +570,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
data[i] = 0;
}
}
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED, data,
len);
g_free(data);
@@ -587,7 +593,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
if (len) {
data = g_malloc(len);
memset(data, pattern, len);
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED,
data, len);
g_free(data);
}
@@ -621,7 +627,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
out_len = MIN(out_len, len);
}
- address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
+ address_space_write(qtest_mem_as(), addr, MEMTXATTRS_UNSPECIFIED, data,
len);
qtest_send_prefix(chr);
Refactor the access to the default address space introducing the qtest_mem_as() getter. This will help us to use another address space in the next commit. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- softmmu/qtest.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)