From 1457044de10f55924882a5a8b933a190c1479050 Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Fri, 16 Feb 2024 20:45:15 -0500 Subject: [PATCH 1/6] Added write monitor command --- hmp-commands.hx | 14 ++++++++++++++ include/exec/memory.h | 2 ++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 10 ++++++++++ softmmu/memory.c | 16 ++++++++++++++++ 5 files changed, 43 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 673e39a6979..a83ffde8cd9 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -47,7 +47,21 @@ ERST .cmd = hmp_quit, .flags = "p", }, + +SRST +``write`` or ``w`` + Quit the emulator. +ERST + { + .name = "write|w", + .args_type = "addr:l,size:i,data:i", + .params = "addr size data", + .help = "write to ram", + .cmd = hmp_write, + .flags = "p", + }, + SRST ``quit`` or ``q`` Quit the emulator. diff --git a/include/exec/memory.h b/include/exec/memory.h index ddb9b9e10b7..ac602343919 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2721,6 +2721,8 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, hwaddr len, bool is_write); +void ram_write(hwaddr addr, void *ptr, hwaddr len); + /** * address_space_cache_invalidate: complete a write to a #MemoryRegionCache * diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index dfbc0c9a2fa..8dedfd9dcf9 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -20,6 +20,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); +void hmp_write(Monitor* mon, const QDict* qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 01b789a79e6..a7bb619c793 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -59,6 +59,8 @@ #include "hw/intc/intc.h" #include "migration/snapshot.h" #include "migration/misc.h" +#include "exec/memory.h" +#include "exec/memory.h" #ifdef CONFIG_SPICE #include @@ -123,6 +125,14 @@ void hmp_info_version(Monitor *mon, const QDict *qdict) qapi_free_VersionInfo(info); } +void hmp_write(Monitor *mon, const QDict *qdict) +{ + uint32_t addr = qdict_get_int(qdict, "addr"); + int data = qdict_get_int(qdict, "data"); + int size = qdict_get_int(qdict, "size"); + ram_write(addr, &data, size); +} + void hmp_info_kvm(Monitor *mon, const QDict *qdict) { KvmInfo *info; diff --git a/softmmu/memory.c b/softmmu/memory.c index 7eefde99147..6f5855a3955 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3595,6 +3595,22 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } } + +void ram_write(hwaddr addr, void* ptr, hwaddr len) +{ + MemoryRegion* sm = get_system_memory(); + MemoryRegion* mr; + const uint8_t* buf = ptr; + QTAILQ_FOREACH(mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) + { + uint8_t* ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); + memcpy(ram_ptr, buf, len); + break; + } + } +} + void memory_region_init_ram(MemoryRegion *mr, Object *owner, const char *name, From f13bfe3489e79897b86194c7c9eee7daacdeaa15 Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Fri, 16 Feb 2024 21:07:24 -0500 Subject: [PATCH 2/6] Sdd support of write monitor command --- hmp-commands.hx | 4 ++-- include/monitor/hmp.h | 2 +- monitor/hmp-cmds.c | 41 ++++++++++++++++++++--------------------- softmmu/memory.c | 17 ++++++++--------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index a83ffde8cd9..c129be42fa1 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -50,14 +50,14 @@ ERST SRST ``write`` or ``w`` - Quit the emulator. + Write to physical memory. ERST { .name = "write|w", .args_type = "addr:l,size:i,data:i", .params = "addr size data", - .help = "write to ram", + .help = "write to physical memory", .cmd = hmp_write, .flags = "p", }, diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 8dedfd9dcf9..13af0412f1b 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -20,7 +20,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); -void hmp_write(Monitor* mon, const QDict* qdict); +void hmp_write(Monitor *mon, const QDict *qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index a7bb619c793..3ac0d03fa6a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -14,20 +14,18 @@ */ #include "qemu/osdep.h" -#include "monitor/hmp.h" -#include "net/net.h" -#include "net/eth.h" #include "chardev/char.h" -#include "sysemu/block-backend.h" -#include "sysemu/runstate.h" -#include "qemu/config-file.h" -#include "qemu/option.h" -#include "qemu/timer.h" -#include "qemu/sockets.h" -#include "qemu/help_option.h" +#include "exec/memory.h" +#include "hw/core/cpu.h" +#include "hw/intc/intc.h" +#include "migration/misc.h" +#include "migration/snapshot.h" +#include "monitor/hmp.h" #include "monitor/monitor-internal.h" -#include "qapi/error.h" +#include "net/eth.h" +#include "net/net.h" #include "qapi/clone-visitor.h" +#include "qapi/error.h" #include "qapi/opts-visitor.h" #include "qapi/qapi-builtin-visit.h" #include "qapi/qapi-commands-block.h" @@ -44,23 +42,24 @@ #include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qapi-commands-virtio.h" -#include "qapi/qapi-visit-virtio.h" -#include "qapi/qapi-visit-net.h" #include "qapi/qapi-visit-migration.h" +#include "qapi/qapi-visit-net.h" +#include "qapi/qapi-visit-virtio.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" -#include "qom/object_interfaces.h" -#include "ui/console.h" +#include "qemu/config-file.h" #include "qemu/cutils.h" #include "qemu/error-report.h" -#include "hw/core/cpu.h" -#include "hw/intc/intc.h" -#include "migration/snapshot.h" -#include "migration/misc.h" -#include "exec/memory.h" -#include "exec/memory.h" +#include "qemu/help_option.h" +#include "qemu/option.h" +#include "qemu/sockets.h" +#include "qemu/timer.h" +#include "qom/object_interfaces.h" +#include "sysemu/block-backend.h" +#include "sysemu/runstate.h" +#include "ui/console.h" #ifdef CONFIG_SPICE #include diff --git a/softmmu/memory.c b/softmmu/memory.c index 6f5855a3955..79fac681a2d 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3596,15 +3596,14 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } -void ram_write(hwaddr addr, void* ptr, hwaddr len) -{ - MemoryRegion* sm = get_system_memory(); - MemoryRegion* mr; - const uint8_t* buf = ptr; - QTAILQ_FOREACH(mr, &sm->subregions, subregions_link) { - if (strcmp(memory_region_name(mr), "xbox.ram") == 0) - { - uint8_t* ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); +void ram_write(hwaddr addr, void *ptr, hwaddr len) +{ + MemoryRegion *sm = get_system_memory(); + MemoryRegion *mr; + const uint8_t *buf = ptr; + QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { + uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); memcpy(ram_ptr, buf, len); break; } From 206596b53bc39482b686c3ce740ffd0bf0d6e0ef Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Tue, 20 Feb 2024 04:20:43 -0500 Subject: [PATCH 3/6] Added support for virtual memory vs physical memory --- hmp-commands.hx | 20 +++++++++++++++++--- include/exec/memory.h | 2 +- include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 10 +++++++++- softmmu/memory.c | 30 +++++++++++++++++++----------- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index c129be42fa1..cd8480580a6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -49,16 +49,30 @@ ERST }, SRST -``write`` or ``w`` +``w`` + Write to virtual memory. +ERST + + { + .name = "w", + .args_type = "addr:l,size:i,data:i", + .params = "addr size data", + .help = "write to virtual memory", + .cmd = hmp_write, + .flags = "p", + }, + +SRST +``wp`` Write to physical memory. ERST { - .name = "write|w", + .name = "wp", .args_type = "addr:l,size:i,data:i", .params = "addr size data", .help = "write to physical memory", - .cmd = hmp_write, + .cmd = hmp_write_physical, .flags = "p", }, diff --git a/include/exec/memory.h b/include/exec/memory.h index ac602343919..a520ef6875c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2721,7 +2721,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, hwaddr len, bool is_write); -void ram_write(hwaddr addr, void *ptr, hwaddr len); +void ram_write(hwaddr addr, void *ptr, hwaddr len, int is_physcial); /** * address_space_cache_invalidate: complete a write to a #MemoryRegionCache diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 13af0412f1b..2b358b5a0ac 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -21,6 +21,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); void hmp_write(Monitor *mon, const QDict *qdict); +void hmp_write_physical(Monitor *mon, const QDict *qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 3ac0d03fa6a..8e6b6164260 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -129,7 +129,15 @@ void hmp_write(Monitor *mon, const QDict *qdict) uint32_t addr = qdict_get_int(qdict, "addr"); int data = qdict_get_int(qdict, "data"); int size = qdict_get_int(qdict, "size"); - ram_write(addr, &data, size); + ram_write(addr, &data, size, 0); +} + +void hmp_write_physical(Monitor *mon, const QDict *qdict) +{ + uint32_t addr = qdict_get_int(qdict, "addr"); + int data = qdict_get_int(qdict, "data"); + int size = qdict_get_int(qdict, "size"); + ram_write(addr, &data, size, 1); } void hmp_info_kvm(Monitor *mon, const QDict *qdict) diff --git a/softmmu/memory.c b/softmmu/memory.c index 79fac681a2d..4159f076fe6 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -25,15 +25,16 @@ #include "qom/object.h" #include "trace.h" +#include "exec/address-spaces.h" #include "exec/memory-internal.h" #include "exec/ram_addr.h" +#include "hw/boards.h" +#include "hw/core/cpu.h" +#include "migration/vmstate.h" +#include "qemu/accel.h" #include "sysemu/kvm.h" #include "sysemu/runstate.h" #include "sysemu/tcg.h" -#include "qemu/accel.h" -#include "hw/boards.h" -#include "migration/vmstate.h" -#include "exec/address-spaces.h" //#define DEBUG_UNASSIGNED @@ -3596,16 +3597,23 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } -void ram_write(hwaddr addr, void *ptr, hwaddr len) +void ram_write(hwaddr addr, void *ptr, hwaddr len, int is_physical) { MemoryRegion *sm = get_system_memory(); MemoryRegion *mr; - const uint8_t *buf = ptr; - QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { - if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { - uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); - memcpy(ram_ptr, buf, len); - break; + uint8_t *buf = ptr; + CPUState *cs = qemu_get_cpu(0); + if (is_physical) { + QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { + uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); + memcpy(ram_ptr, buf, len); + break; + } + } + } else { + if (cpu_memory_rw_debug(cs, addr, buf, len, 1) < 0) { + qemu_printf("Cannot access memory\n"); } } } From 7a22caccb0d3800718279190d028d9b38e36c83d Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Fri, 16 Feb 2024 20:45:15 -0500 Subject: [PATCH 4/6] Added write monitor command --- hmp-commands.hx | 14 ++++++++++++++ include/exec/memory.h | 2 ++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 10 ++++++++++ softmmu/memory.c | 16 ++++++++++++++++ 5 files changed, 43 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 673e39a6979..a83ffde8cd9 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -47,7 +47,21 @@ ERST .cmd = hmp_quit, .flags = "p", }, + +SRST +``write`` or ``w`` + Quit the emulator. +ERST + { + .name = "write|w", + .args_type = "addr:l,size:i,data:i", + .params = "addr size data", + .help = "write to ram", + .cmd = hmp_write, + .flags = "p", + }, + SRST ``quit`` or ``q`` Quit the emulator. diff --git a/include/exec/memory.h b/include/exec/memory.h index ddb9b9e10b7..ac602343919 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2721,6 +2721,8 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, hwaddr len, bool is_write); +void ram_write(hwaddr addr, void *ptr, hwaddr len); + /** * address_space_cache_invalidate: complete a write to a #MemoryRegionCache * diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index dfbc0c9a2fa..8dedfd9dcf9 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -20,6 +20,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); +void hmp_write(Monitor* mon, const QDict* qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 01b789a79e6..a7bb619c793 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -59,6 +59,8 @@ #include "hw/intc/intc.h" #include "migration/snapshot.h" #include "migration/misc.h" +#include "exec/memory.h" +#include "exec/memory.h" #ifdef CONFIG_SPICE #include @@ -123,6 +125,14 @@ void hmp_info_version(Monitor *mon, const QDict *qdict) qapi_free_VersionInfo(info); } +void hmp_write(Monitor *mon, const QDict *qdict) +{ + uint32_t addr = qdict_get_int(qdict, "addr"); + int data = qdict_get_int(qdict, "data"); + int size = qdict_get_int(qdict, "size"); + ram_write(addr, &data, size); +} + void hmp_info_kvm(Monitor *mon, const QDict *qdict) { KvmInfo *info; diff --git a/softmmu/memory.c b/softmmu/memory.c index 7eefde99147..6f5855a3955 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3595,6 +3595,22 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } } + +void ram_write(hwaddr addr, void* ptr, hwaddr len) +{ + MemoryRegion* sm = get_system_memory(); + MemoryRegion* mr; + const uint8_t* buf = ptr; + QTAILQ_FOREACH(mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) + { + uint8_t* ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); + memcpy(ram_ptr, buf, len); + break; + } + } +} + void memory_region_init_ram(MemoryRegion *mr, Object *owner, const char *name, From 5533e8891f1283259b0eb49fe747767a85d6c628 Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Fri, 16 Feb 2024 21:07:24 -0500 Subject: [PATCH 5/6] Sdd support of write monitor command --- hmp-commands.hx | 4 ++-- include/monitor/hmp.h | 2 +- monitor/hmp-cmds.c | 41 ++++++++++++++++++++--------------------- softmmu/memory.c | 17 ++++++++--------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index a83ffde8cd9..c129be42fa1 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -50,14 +50,14 @@ ERST SRST ``write`` or ``w`` - Quit the emulator. + Write to physical memory. ERST { .name = "write|w", .args_type = "addr:l,size:i,data:i", .params = "addr size data", - .help = "write to ram", + .help = "write to physical memory", .cmd = hmp_write, .flags = "p", }, diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 8dedfd9dcf9..13af0412f1b 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -20,7 +20,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); -void hmp_write(Monitor* mon, const QDict* qdict); +void hmp_write(Monitor *mon, const QDict *qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index a7bb619c793..3ac0d03fa6a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -14,20 +14,18 @@ */ #include "qemu/osdep.h" -#include "monitor/hmp.h" -#include "net/net.h" -#include "net/eth.h" #include "chardev/char.h" -#include "sysemu/block-backend.h" -#include "sysemu/runstate.h" -#include "qemu/config-file.h" -#include "qemu/option.h" -#include "qemu/timer.h" -#include "qemu/sockets.h" -#include "qemu/help_option.h" +#include "exec/memory.h" +#include "hw/core/cpu.h" +#include "hw/intc/intc.h" +#include "migration/misc.h" +#include "migration/snapshot.h" +#include "monitor/hmp.h" #include "monitor/monitor-internal.h" -#include "qapi/error.h" +#include "net/eth.h" +#include "net/net.h" #include "qapi/clone-visitor.h" +#include "qapi/error.h" #include "qapi/opts-visitor.h" #include "qapi/qapi-builtin-visit.h" #include "qapi/qapi-commands-block.h" @@ -44,23 +42,24 @@ #include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qapi-commands-virtio.h" -#include "qapi/qapi-visit-virtio.h" -#include "qapi/qapi-visit-net.h" #include "qapi/qapi-visit-migration.h" +#include "qapi/qapi-visit-net.h" +#include "qapi/qapi-visit-virtio.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" -#include "qom/object_interfaces.h" -#include "ui/console.h" +#include "qemu/config-file.h" #include "qemu/cutils.h" #include "qemu/error-report.h" -#include "hw/core/cpu.h" -#include "hw/intc/intc.h" -#include "migration/snapshot.h" -#include "migration/misc.h" -#include "exec/memory.h" -#include "exec/memory.h" +#include "qemu/help_option.h" +#include "qemu/option.h" +#include "qemu/sockets.h" +#include "qemu/timer.h" +#include "qom/object_interfaces.h" +#include "sysemu/block-backend.h" +#include "sysemu/runstate.h" +#include "ui/console.h" #ifdef CONFIG_SPICE #include diff --git a/softmmu/memory.c b/softmmu/memory.c index 6f5855a3955..79fac681a2d 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3596,15 +3596,14 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } -void ram_write(hwaddr addr, void* ptr, hwaddr len) -{ - MemoryRegion* sm = get_system_memory(); - MemoryRegion* mr; - const uint8_t* buf = ptr; - QTAILQ_FOREACH(mr, &sm->subregions, subregions_link) { - if (strcmp(memory_region_name(mr), "xbox.ram") == 0) - { - uint8_t* ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); +void ram_write(hwaddr addr, void *ptr, hwaddr len) +{ + MemoryRegion *sm = get_system_memory(); + MemoryRegion *mr; + const uint8_t *buf = ptr; + QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { + uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); memcpy(ram_ptr, buf, len); break; } From 199445f2fa2e4a0952e3d1d5d90965ecce8c43e5 Mon Sep 17 00:00:00 2001 From: jamesbrq Date: Tue, 20 Feb 2024 04:20:43 -0500 Subject: [PATCH 6/6] Added support for virtual memory vs physical memory --- hmp-commands.hx | 20 +++++++++++++++++--- include/exec/memory.h | 2 +- include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 10 +++++++++- softmmu/memory.c | 30 +++++++++++++++++++----------- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index c129be42fa1..cd8480580a6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -49,16 +49,30 @@ ERST }, SRST -``write`` or ``w`` +``w`` + Write to virtual memory. +ERST + + { + .name = "w", + .args_type = "addr:l,size:i,data:i", + .params = "addr size data", + .help = "write to virtual memory", + .cmd = hmp_write, + .flags = "p", + }, + +SRST +``wp`` Write to physical memory. ERST { - .name = "write|w", + .name = "wp", .args_type = "addr:l,size:i,data:i", .params = "addr size data", .help = "write to physical memory", - .cmd = hmp_write, + .cmd = hmp_write_physical, .flags = "p", }, diff --git a/include/exec/memory.h b/include/exec/memory.h index ac602343919..a520ef6875c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2721,7 +2721,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, hwaddr len, bool is_write); -void ram_write(hwaddr addr, void *ptr, hwaddr len); +void ram_write(hwaddr addr, void *ptr, hwaddr len, int is_physcial); /** * address_space_cache_invalidate: complete a write to a #MemoryRegionCache diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 13af0412f1b..2b358b5a0ac 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -21,6 +21,7 @@ bool hmp_handle_error(Monitor *mon, Error *err); void hmp_write(Monitor *mon, const QDict *qdict); +void hmp_write_physical(Monitor *mon, const QDict *qdict); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 3ac0d03fa6a..8e6b6164260 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -129,7 +129,15 @@ void hmp_write(Monitor *mon, const QDict *qdict) uint32_t addr = qdict_get_int(qdict, "addr"); int data = qdict_get_int(qdict, "data"); int size = qdict_get_int(qdict, "size"); - ram_write(addr, &data, size); + ram_write(addr, &data, size, 0); +} + +void hmp_write_physical(Monitor *mon, const QDict *qdict) +{ + uint32_t addr = qdict_get_int(qdict, "addr"); + int data = qdict_get_int(qdict, "data"); + int size = qdict_get_int(qdict, "size"); + ram_write(addr, &data, size, 1); } void hmp_info_kvm(Monitor *mon, const QDict *qdict) diff --git a/softmmu/memory.c b/softmmu/memory.c index 79fac681a2d..4159f076fe6 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -25,15 +25,16 @@ #include "qom/object.h" #include "trace.h" +#include "exec/address-spaces.h" #include "exec/memory-internal.h" #include "exec/ram_addr.h" +#include "hw/boards.h" +#include "hw/core/cpu.h" +#include "migration/vmstate.h" +#include "qemu/accel.h" #include "sysemu/kvm.h" #include "sysemu/runstate.h" #include "sysemu/tcg.h" -#include "qemu/accel.h" -#include "hw/boards.h" -#include "migration/vmstate.h" -#include "exec/address-spaces.h" //#define DEBUG_UNASSIGNED @@ -3596,16 +3597,23 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } -void ram_write(hwaddr addr, void *ptr, hwaddr len) +void ram_write(hwaddr addr, void *ptr, hwaddr len, int is_physical) { MemoryRegion *sm = get_system_memory(); MemoryRegion *mr; - const uint8_t *buf = ptr; - QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { - if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { - uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); - memcpy(ram_ptr, buf, len); - break; + uint8_t *buf = ptr; + CPUState *cs = qemu_get_cpu(0); + if (is_physical) { + QTAILQ_FOREACH (mr, &sm->subregions, subregions_link) { + if (strcmp(memory_region_name(mr), "xbox.ram") == 0) { + uint8_t *ram_ptr = qemu_map_ram_ptr(mr->ram_block, addr); + memcpy(ram_ptr, buf, len); + break; + } + } + } else { + if (cpu_memory_rw_debug(cs, addr, buf, len, 1) < 0) { + qemu_printf("Cannot access memory\n"); } } }