Skip to content

Commit

Permalink
Added support for virtual memory vs physical memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbrq committed Feb 20, 2024
1 parent f13bfe3 commit 206596b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
20 changes: 17 additions & 3 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

Expand Down
2 changes: 1 addition & 1 deletion include/exec/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/monitor/hmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion monitor/hmp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 19 additions & 11 deletions softmmu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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");
}
}
}
Expand Down

0 comments on commit 206596b

Please sign in to comment.