diff options
author | Avi Kivity <avi@redhat.com> | 2012-02-08 16:54:16 +0200 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2012-02-29 13:44:42 +0200 |
commit | 9363274709af23c499b6db3eb402b6f9aa46c40b (patch) | |
tree | 5db489178fce25d9af97354b916cee3cd5e3be10 /exec.c | |
parent | d7ec83e6b57f48cf07f663e232e4aa2b32bc33c7 (diff) |
memory: use a MemoryListener for core memory map updates too
This transforms memory.c into a library which can then be unit tested
easily, by feeding it inputs and listening to its outputs.
Signed-off-by: Avi Kivity <avi@redhat.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Diffstat (limited to 'exec.c')
-rw-r--r-- | exec.c | 75 |
1 files changed, 75 insertions, 0 deletions
@@ -3488,6 +3488,79 @@ static void io_mem_init(void) "watch", UINT64_MAX); } +static void core_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + if (section->address_space == get_system_memory()) { + cpu_register_physical_memory_log(section, section->readonly); + } else { + iorange_init(§ion->mr->iorange, &memory_region_iorange_ops, + section->offset_within_address_space, section->size); + ioport_register(§ion->mr->iorange); + } +} + +static void core_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + if (section->address_space == get_system_memory()) { + cpu_register_physical_memory_log(section, false); + } else { + isa_unassign_ioport(section->offset_within_address_space, + section->size); + } +} + +static void core_log_start(MemoryListener *listener, + MemoryRegionSection *section) +{ +} + +static void core_log_stop(MemoryListener *listener, + MemoryRegionSection *section) +{ +} + +static void core_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ +} + +static void core_log_global_start(MemoryListener *listener) +{ + cpu_physical_memory_set_dirty_tracking(1); +} + +static void core_log_global_stop(MemoryListener *listener) +{ + cpu_physical_memory_set_dirty_tracking(0); +} + +static void core_eventfd_add(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, int fd) +{ +} + +static void core_eventfd_del(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, int fd) +{ +} + +static MemoryListener core_memory_listener = { + .region_add = core_region_add, + .region_del = core_region_del, + .log_start = core_log_start, + .log_stop = core_log_stop, + .log_sync = core_log_sync, + .log_global_start = core_log_global_start, + .log_global_stop = core_log_global_stop, + .eventfd_add = core_eventfd_add, + .eventfd_del = core_eventfd_del, + .priority = 0, +}; + static void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); @@ -3497,6 +3570,8 @@ static void memory_map_init(void) system_io = g_malloc(sizeof(*system_io)); memory_region_init(system_io, "io", 65536); set_system_io_map(system_io); + + memory_listener_register(&core_memory_listener); } MemoryRegion *get_system_memory(void) |