qom/cpu: Add MemoryRegion property

Add a MemoryRegion property, which if set is used to construct
the CPU's initial (default) AddressSpace.

Backports commit 6731d864f80938e404dc3e5eb7f6b76b891e3e43 from qemu
This commit is contained in:
Peter Crosthwaite 2018-02-18 21:40:52 -05:00 committed by Lioncash
parent 6d5f465449
commit ce997e1caf
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
4 changed files with 26 additions and 1 deletions

View file

@ -88,8 +88,11 @@ int qemu_init_vcpu(CPUState *cpu)
/* If the target cpu hasn't set up any address spaces itself,
* give it the default one.
*/
AddressSpace *as = address_space_init_shareable(cpu->uc,
cpu->memory,
"cpu-memory");
cpu->num_ases = 1;
cpu_address_space_init(cpu, &cpu->uc->as, 0);
cpu_address_space_init(cpu, as, 0);
}
if (tcg_enabled(cpu->uc)) {

View file

@ -451,6 +451,25 @@ void cpu_exec_init(CPUState *cpu, void *opaque)
// TODO: assert uc does not already have a cpu?
uc->cpu = cpu;
#ifndef CONFIG_USER_ONLY
// Unicorn: commented out
/* This is a softmmu CPU object, so create a property for it
* so users can wire up its memory. (This can't go in qom/cpu.c
* because that file is compiled only once for both user-mode
* and system builds.) The default if no link is set up is to use
* the system address space.
*/
/*object_property_add_link(OBJECT(cpu), "memory", TYPE_MEMORY_REGION,
(Object **)&cpu->memory,
qdev_prop_allow_set_link_before_realize,
OBJ_PROP_LINK_UNREF_ON_RELEASE,
&error_abort);*/
cpu->memory = uc->system_memory;
// Unicorn: commented out
/*object_ref(OBJECT(cpu->memory)); */
#endif
}
#if defined(CONFIG_USER_ONLY)

View file

@ -264,6 +264,7 @@ struct CPUState {
CPUAddressSpace *cpu_ases;
int num_ases;
AddressSpace *as;
MemoryRegion *memory;
void *env_ptr; /* CPUArchState */
struct TranslationBlock *current_tb;

View file

@ -44,6 +44,8 @@ static void release_common(void *t)
// TODO(danghvu): these function is not available outside qemu
// so we keep them here instead of outside uc_close.
phys_mem_clean(&s->uc->as);
address_space_destroy(&s->uc->as);
for (i = 0; i < s->uc->cpu->num_ases; i++) {
AddressSpace *as = s->uc->cpu->cpu_ases[i].as;
phys_mem_clean(as);