Skip to content

Commit

Permalink
physmem: allow cpu_memory_rw_debug to write to MMIO devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Zabka committed Dec 18, 2024
1 parent 06bf8fa commit 609ff8c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions system/physmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3572,6 +3572,7 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
hwaddr phys_addr;
vaddr l, page;
uint8_t *buf = ptr;
bool is_memcpy_access;

cpu_synchronize_state(cpu);
while (len > 0) {
Expand All @@ -3590,11 +3591,24 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
l = len;
phys_addr += (addr & ~TARGET_PAGE_MASK);
if (is_write) {
res = address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr,
attrs, buf, l);
/* if ram/rom region we access the memory
via memcpy instead of via the cpu */
hwaddr mr_len, addr1;
AddressSpace *as = cpu->cpu_ases[asidx].as;
MemoryRegion *mr = address_space_translate(as, phys_addr, &addr1, &mr_len, is_write, attrs);

is_memcpy_access = memory_region_is_ram(mr) || memory_region_is_romd(mr);
if(!is_memcpy_access) {
l = memory_access_size(mr, l, addr1);
}
} else {
is_memcpy_access = false;
}

if (is_write && is_memcpy_access) {
res = address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr, attrs, buf, l);
} else {
res = address_space_read(cpu->cpu_ases[asidx].as, phys_addr,
attrs, buf, l);
res = address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, attrs, buf, l, is_write);
}
if (res != MEMTX_OK) {
return -1;
Expand Down

0 comments on commit 609ff8c

Please sign in to comment.