mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-01 23:21:08 +00:00
cpu: refactor cpu_address_space_init()
Normally we create an address space for that CPU and pass that address space into the function. Let's just do it inside to unify address space creations. It'll simplify my next patch to rename those address spaces. Backports commit 80ceb07a83375e3a0091591f96bd47bce2f640ce from qemu
This commit is contained in:
parent
55b19c099e
commit
1bb34aadf9
|
@ -104,11 +104,8 @@ 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, as, 0);
|
||||
cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
|
||||
}
|
||||
|
||||
if (tcg_enabled(cpu->uc)) {
|
||||
|
|
|
@ -533,9 +533,14 @@ CPUState *qemu_get_cpu(struct uc_struct *uc, int index)
|
|||
}
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx)
|
||||
void cpu_address_space_init(CPUState *cpu, int asidx,
|
||||
const char *prefix, MemoryRegion *mr)
|
||||
{
|
||||
CPUAddressSpace *newas;
|
||||
AddressSpace *as = g_new0(AddressSpace, 1);
|
||||
|
||||
assert(mr);
|
||||
address_space_init(cpu->uc, as, mr, prefix);
|
||||
|
||||
/* Target code should have set num_ases before calling us */
|
||||
assert(asidx < cpu->num_ases);
|
||||
|
|
|
@ -73,8 +73,9 @@ void QEMU_NORETURN cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
|
|||
/**
|
||||
* cpu_address_space_init:
|
||||
* @cpu: CPU to add this address space to
|
||||
* @as: address space to add
|
||||
* @asidx: integer index of this address space
|
||||
* @prefix: prefix to be used as name of address space
|
||||
* @mr: the root memory region of address space
|
||||
*
|
||||
* Add the specified address space to the CPU's cpu_ases list.
|
||||
* The address space added with @asidx 0 is the one used for the
|
||||
|
@ -88,7 +89,8 @@ void QEMU_NORETURN cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
|
|||
*
|
||||
* Note that with KVM only one address space is supported.
|
||||
*/
|
||||
void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx);
|
||||
void cpu_address_space_init(CPUState *cpu, int asidx,
|
||||
const char *prefix, MemoryRegion *mr);
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
|
||||
|
|
|
@ -686,25 +686,17 @@ static int arm_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **err
|
|||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
if (cpu->has_el3 || arm_feature(env, ARM_FEATURE_M_SECURITY)) {
|
||||
AddressSpace *as;
|
||||
|
||||
cs->num_ases = 2;
|
||||
|
||||
if (!cpu->secure_memory) {
|
||||
cpu->secure_memory = cs->memory;
|
||||
}
|
||||
as = address_space_init_shareable(uc,
|
||||
cpu->secure_memory,
|
||||
"cpu-secure-memory");
|
||||
cpu_address_space_init(cs, as, ARMASIdx_S);
|
||||
cpu_address_space_init(cs, ARMASIdx_S, "cpu-secure-memory",
|
||||
cpu->secure_memory);
|
||||
} else {
|
||||
cs->num_ases = 1;
|
||||
}
|
||||
cpu_address_space_init(cs,
|
||||
address_space_init_shareable(uc,
|
||||
cs->memory,
|
||||
"cpu-memory"),
|
||||
ARMASIdx_NS);
|
||||
cpu_address_space_init(cs, ARMASIdx_NS, "cpu-memory", cs->memory);
|
||||
#endif
|
||||
|
||||
init_cpreg_list(cpu);
|
||||
|
|
|
@ -4108,10 +4108,6 @@ static int x86_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **err
|
|||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
if (tcg_enabled(uc)) {
|
||||
AddressSpace *as_normal = address_space_init_shareable(uc, cs->memory,
|
||||
"cpu-memory");
|
||||
AddressSpace *as_smm = g_new(AddressSpace, 1);
|
||||
|
||||
cpu->cpu_as_mem = g_new(MemoryRegion, 1);
|
||||
cpu->cpu_as_root = g_new(MemoryRegion, 1);
|
||||
|
||||
|
@ -4126,11 +4122,10 @@ static int x86_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **err
|
|||
get_system_memory(uc), 0, ~0ull);
|
||||
memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_as_mem, 0);
|
||||
memory_region_set_enabled(cpu->cpu_as_mem, true);
|
||||
address_space_init(uc, as_smm, cpu->cpu_as_root, "CPU");
|
||||
|
||||
cs->num_ases = 2;
|
||||
cpu_address_space_init(cs, as_normal, 0);
|
||||
cpu_address_space_init(cs, as_smm, 1);
|
||||
cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
|
||||
cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue