mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-22 19:15:36 +00:00
exec.c: Don't set cpu->as until cpu_address_space_init
Rather than setting cpu->as unconditionally in cpu_exec_init (and then having target-i386 override this later), don't set it until the first call to cpu_address_space_init. This requires us to initialise the address space for both TCG and KVM (KVM doesn't need the AS listener but it does require cpu->as to be set). For target CPUs which don't set up any address spaces (currently everything except i386), add the default address_space_memory in qemu_init_vcpu(). Backports commit 56943e8cc14b7eeeab67d1942fa5d8bcafe3e53f from qemu
This commit is contained in:
parent
51aeab661f
commit
f1b237236c
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_aarch64
|
||||
#define tcg_exec_init tcg_exec_init_aarch64
|
||||
#define memory_register_types memory_register_types_aarch64
|
||||
#define cpu_address_space_init cpu_address_space_init_aarch64
|
||||
#define cpu_exec_init_all cpu_exec_init_all_aarch64
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_aarch64
|
||||
#define vm_start vm_start_aarch64
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_aarch64
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_aarch64
|
||||
#define tcg_context_init tcg_context_init_aarch64
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_aarch64
|
||||
#define tcg_cpu_exec tcg_cpu_exec_aarch64
|
||||
#define tcg_current_code_size tcg_current_code_size_aarch64
|
||||
#define tcg_dump_info tcg_dump_info_aarch64
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_aarch64eb
|
||||
#define tcg_exec_init tcg_exec_init_aarch64eb
|
||||
#define memory_register_types memory_register_types_aarch64eb
|
||||
#define cpu_address_space_init cpu_address_space_init_aarch64eb
|
||||
#define cpu_exec_init_all cpu_exec_init_all_aarch64eb
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_aarch64eb
|
||||
#define vm_start vm_start_aarch64eb
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_aarch64eb
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_aarch64eb
|
||||
#define tcg_context_init tcg_context_init_aarch64eb
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_aarch64eb
|
||||
#define tcg_cpu_exec tcg_cpu_exec_aarch64eb
|
||||
#define tcg_current_code_size tcg_current_code_size_aarch64eb
|
||||
#define tcg_dump_info tcg_dump_info_aarch64eb
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_arm
|
||||
#define tcg_exec_init tcg_exec_init_arm
|
||||
#define memory_register_types memory_register_types_arm
|
||||
#define cpu_address_space_init cpu_address_space_init_arm
|
||||
#define cpu_exec_init_all cpu_exec_init_all_arm
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_arm
|
||||
#define vm_start vm_start_arm
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_arm
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_arm
|
||||
#define tcg_context_init tcg_context_init_arm
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_arm
|
||||
#define tcg_cpu_exec tcg_cpu_exec_arm
|
||||
#define tcg_current_code_size tcg_current_code_size_arm
|
||||
#define tcg_dump_info tcg_dump_info_arm
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_armeb
|
||||
#define tcg_exec_init tcg_exec_init_armeb
|
||||
#define memory_register_types memory_register_types_armeb
|
||||
#define cpu_address_space_init cpu_address_space_init_armeb
|
||||
#define cpu_exec_init_all cpu_exec_init_all_armeb
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_armeb
|
||||
#define vm_start vm_start_armeb
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_armeb
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_armeb
|
||||
#define tcg_context_init tcg_context_init_armeb
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_armeb
|
||||
#define tcg_cpu_exec tcg_cpu_exec_armeb
|
||||
#define tcg_current_code_size tcg_current_code_size_armeb
|
||||
#define tcg_dump_info tcg_dump_info_armeb
|
||||
|
|
|
@ -110,7 +110,12 @@ static void *qemu_tcg_cpu_loop(struct uc_struct *uc)
|
|||
|
||||
static int qemu_tcg_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
tcg_cpu_address_space_init(cpu, cpu->as);
|
||||
if (!cpu->as) {
|
||||
/* If the target cpu hasn't set up any address spaces itself,
|
||||
* give it the default one.
|
||||
*/
|
||||
cpu_address_space_init(cpu, &cpu->uc->as, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
29
qemu/exec.c
29
qemu/exec.c
|
@ -383,18 +383,28 @@ CPUState *qemu_get_cpu(struct uc_struct *uc, int index)
|
|||
}
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
|
||||
void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx)
|
||||
{
|
||||
if (asidx == 0) {
|
||||
/* address space 0 gets the convenience alias */
|
||||
cpu->as = as;
|
||||
}
|
||||
|
||||
/* We only support one address space per cpu at the moment. */
|
||||
assert(cpu->as == as);
|
||||
|
||||
if (cpu->tcg_as_listener) {
|
||||
memory_listener_unregister(as->uc, cpu->tcg_as_listener);
|
||||
} else {
|
||||
cpu->tcg_as_listener = g_new0(MemoryListener, 1);
|
||||
if (cpu->cpu_ases) {
|
||||
/* We've already registered the listener for our only AS */
|
||||
return;
|
||||
}
|
||||
|
||||
cpu->cpu_ases = g_new0(CPUAddressSpace, 1);
|
||||
cpu->cpu_ases[0].cpu = cpu;
|
||||
cpu->cpu_ases[0].as = as;
|
||||
if (tcg_enabled(as->uc)) {
|
||||
cpu->cpu_ases[0].tcg_as_listener.commit = tcg_commit;
|
||||
memory_listener_register(as->uc, &cpu->cpu_ases[0].tcg_as_listener, as);
|
||||
}
|
||||
cpu->tcg_as_listener->commit = tcg_commit;
|
||||
memory_listener_register(as->uc, cpu->tcg_as_listener, as);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -403,12 +413,11 @@ void cpu_exec_init(CPUState *cpu, void *opaque)
|
|||
struct uc_struct *uc = opaque;
|
||||
CPUArchState *env = cpu->env_ptr;
|
||||
|
||||
cpu->cpu_index = 0;
|
||||
cpu->as = NULL;
|
||||
cpu->uc = uc;
|
||||
env->uc = uc;
|
||||
|
||||
cpu->cpu_index = 0;
|
||||
cpu->as = &uc->as;
|
||||
|
||||
// TODO: assert uc does not already have a cpu?
|
||||
uc->cpu = cpu;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ symbols = (
|
|||
'tcg_enabled',
|
||||
'tcg_exec_init',
|
||||
'memory_register_types',
|
||||
'cpu_address_space_init',
|
||||
'cpu_exec_init_all',
|
||||
'cpu_reload_memory_map',
|
||||
'vm_start',
|
||||
|
@ -2739,7 +2740,6 @@ symbols = (
|
|||
'tcg_const_local_i32',
|
||||
'tcg_const_local_i64',
|
||||
'tcg_context_init',
|
||||
'tcg_cpu_address_space_init',
|
||||
'tcg_cpu_exec',
|
||||
'tcg_current_code_size',
|
||||
'tcg_dump_info',
|
||||
|
|
|
@ -83,7 +83,21 @@ void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
|
|||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
void cpu_reload_memory_map(CPUState *cpu);
|
||||
void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as);
|
||||
/**
|
||||
* cpu_address_space_init:
|
||||
* @cpu: CPU to add this address space to
|
||||
* @as: address space to add
|
||||
* @asidx: integer index of this 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
|
||||
* convenience pointer cpu->as.
|
||||
* The target-specific code which registers ASes is responsible
|
||||
* for defining what semantics address space 0, 1, 2, etc have.
|
||||
*
|
||||
* Note that with KVM only one address space is supported.
|
||||
*/
|
||||
void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx);
|
||||
/* cputlb.c */
|
||||
/**
|
||||
* tlb_flush_page:
|
||||
|
|
|
@ -15,6 +15,7 @@ typedef struct BusClass BusClass;
|
|||
typedef struct BusState BusState;
|
||||
typedef struct CharDriverState CharDriverState;
|
||||
typedef struct CompatProperty CompatProperty;
|
||||
typedef struct CPUAddressSpace CPUAddressSpace;
|
||||
typedef struct DeviceState DeviceState;
|
||||
typedef struct DisplayChangeListener DisplayChangeListener;
|
||||
typedef struct DisplayState DisplayState;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <setjmp.h>
|
||||
#include "hw/qdev-core.h"
|
||||
#include "exec/hwaddr.h"
|
||||
#include "exec/memory.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/thread.h"
|
||||
#include "qemu/typedefs.h"
|
||||
|
@ -171,6 +172,21 @@ struct kvm_run;
|
|||
#define TB_JMP_CACHE_BITS 12
|
||||
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
|
||||
|
||||
// Unicorn: Moved CPUAddressSpace here from exec.c
|
||||
/**
|
||||
* CPUAddressSpace: all the information a CPU needs about an AddressSpace
|
||||
* @cpu: the CPU whose AddressSpace this is
|
||||
* @as: the AddressSpace itself
|
||||
* @memory_dispatch: its dispatch pointer (cached, RCU protected)
|
||||
* @tcg_as_listener: listener for tracking changes to the AddressSpace
|
||||
*/
|
||||
struct CPUAddressSpace {
|
||||
CPUState *cpu;
|
||||
AddressSpace *as;
|
||||
struct AddressSpaceDispatch *memory_dispatch;
|
||||
MemoryListener tcg_as_listener;
|
||||
};
|
||||
|
||||
/**
|
||||
* CPUState:
|
||||
* @cpu_index: CPU index (informative).
|
||||
|
@ -231,9 +247,10 @@ struct CPUState {
|
|||
int64_t icount_extra;
|
||||
sigjmp_buf jmp_env;
|
||||
|
||||
CPUAddressSpace *cpu_ases;
|
||||
int num_ases;
|
||||
AddressSpace *as;
|
||||
struct AddressSpaceDispatch *memory_dispatch;
|
||||
MemoryListener *tcg_as_listener;
|
||||
|
||||
void *env_ptr; /* CPUArchState */
|
||||
struct TranslationBlock *current_tb;
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_m68k
|
||||
#define tcg_exec_init tcg_exec_init_m68k
|
||||
#define memory_register_types memory_register_types_m68k
|
||||
#define cpu_address_space_init cpu_address_space_init_m68k
|
||||
#define cpu_exec_init_all cpu_exec_init_all_m68k
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_m68k
|
||||
#define vm_start vm_start_m68k
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_m68k
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_m68k
|
||||
#define tcg_context_init tcg_context_init_m68k
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_m68k
|
||||
#define tcg_cpu_exec tcg_cpu_exec_m68k
|
||||
#define tcg_current_code_size tcg_current_code_size_m68k
|
||||
#define tcg_dump_info tcg_dump_info_m68k
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_mips
|
||||
#define tcg_exec_init tcg_exec_init_mips
|
||||
#define memory_register_types memory_register_types_mips
|
||||
#define cpu_address_space_init cpu_address_space_init_mips
|
||||
#define cpu_exec_init_all cpu_exec_init_all_mips
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_mips
|
||||
#define vm_start vm_start_mips
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_mips
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_mips
|
||||
#define tcg_context_init tcg_context_init_mips
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_mips
|
||||
#define tcg_cpu_exec tcg_cpu_exec_mips
|
||||
#define tcg_current_code_size tcg_current_code_size_mips
|
||||
#define tcg_dump_info tcg_dump_info_mips
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_mips64
|
||||
#define tcg_exec_init tcg_exec_init_mips64
|
||||
#define memory_register_types memory_register_types_mips64
|
||||
#define cpu_address_space_init cpu_address_space_init_mips64
|
||||
#define cpu_exec_init_all cpu_exec_init_all_mips64
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_mips64
|
||||
#define vm_start vm_start_mips64
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_mips64
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_mips64
|
||||
#define tcg_context_init tcg_context_init_mips64
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_mips64
|
||||
#define tcg_cpu_exec tcg_cpu_exec_mips64
|
||||
#define tcg_current_code_size tcg_current_code_size_mips64
|
||||
#define tcg_dump_info tcg_dump_info_mips64
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_mips64el
|
||||
#define tcg_exec_init tcg_exec_init_mips64el
|
||||
#define memory_register_types memory_register_types_mips64el
|
||||
#define cpu_address_space_init cpu_address_space_init_mips64el
|
||||
#define cpu_exec_init_all cpu_exec_init_all_mips64el
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_mips64el
|
||||
#define vm_start vm_start_mips64el
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_mips64el
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_mips64el
|
||||
#define tcg_context_init tcg_context_init_mips64el
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_mips64el
|
||||
#define tcg_cpu_exec tcg_cpu_exec_mips64el
|
||||
#define tcg_current_code_size tcg_current_code_size_mips64el
|
||||
#define tcg_dump_info tcg_dump_info_mips64el
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_mipsel
|
||||
#define tcg_exec_init tcg_exec_init_mipsel
|
||||
#define memory_register_types memory_register_types_mipsel
|
||||
#define cpu_address_space_init cpu_address_space_init_mipsel
|
||||
#define cpu_exec_init_all cpu_exec_init_all_mipsel
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_mipsel
|
||||
#define vm_start vm_start_mipsel
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_mipsel
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_mipsel
|
||||
#define tcg_context_init tcg_context_init_mipsel
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_mipsel
|
||||
#define tcg_cpu_exec tcg_cpu_exec_mipsel
|
||||
#define tcg_current_code_size tcg_current_code_size_mipsel
|
||||
#define tcg_dump_info tcg_dump_info_mipsel
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_powerpc
|
||||
#define tcg_exec_init tcg_exec_init_powerpc
|
||||
#define memory_register_types memory_register_types_powerpc
|
||||
#define cpu_address_space_init cpu_address_space_init_powerpc
|
||||
#define cpu_exec_init_all cpu_exec_init_all_powerpc
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_powerpc
|
||||
#define vm_start vm_start_powerpc
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_powerpc
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_powerpc
|
||||
#define tcg_context_init tcg_context_init_powerpc
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_powerpc
|
||||
#define tcg_cpu_exec tcg_cpu_exec_powerpc
|
||||
#define tcg_current_code_size tcg_current_code_size_powerpc
|
||||
#define tcg_dump_info tcg_dump_info_powerpc
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_sparc
|
||||
#define tcg_exec_init tcg_exec_init_sparc
|
||||
#define memory_register_types memory_register_types_sparc
|
||||
#define cpu_address_space_init cpu_address_space_init_sparc
|
||||
#define cpu_exec_init_all cpu_exec_init_all_sparc
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_sparc
|
||||
#define vm_start vm_start_sparc
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_sparc
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_sparc
|
||||
#define tcg_context_init tcg_context_init_sparc
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_sparc
|
||||
#define tcg_cpu_exec tcg_cpu_exec_sparc
|
||||
#define tcg_current_code_size tcg_current_code_size_sparc
|
||||
#define tcg_dump_info tcg_dump_info_sparc
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_sparc64
|
||||
#define tcg_exec_init tcg_exec_init_sparc64
|
||||
#define memory_register_types memory_register_types_sparc64
|
||||
#define cpu_address_space_init cpu_address_space_init_sparc64
|
||||
#define cpu_exec_init_all cpu_exec_init_all_sparc64
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_sparc64
|
||||
#define vm_start vm_start_sparc64
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_sparc64
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_sparc64
|
||||
#define tcg_context_init tcg_context_init_sparc64
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_sparc64
|
||||
#define tcg_cpu_exec tcg_cpu_exec_sparc64
|
||||
#define tcg_current_code_size tcg_current_code_size_sparc64
|
||||
#define tcg_dump_info tcg_dump_info_sparc64
|
||||
|
|
|
@ -2601,12 +2601,14 @@ static int x86_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **err
|
|||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
if (tcg_enabled(uc)) {
|
||||
AddressSpace *newas = g_new(AddressSpace, 1);
|
||||
|
||||
cpu->cpu_as_root = g_new(MemoryRegion, 1);
|
||||
cs->as = g_new(AddressSpace, 1);
|
||||
memory_region_init_alias(uc, cpu->cpu_as_root, OBJECT(cpu), "memory",
|
||||
get_system_memory(uc), 0, ~0ull);
|
||||
memory_region_set_enabled(cpu->cpu_as_root, true);
|
||||
address_space_init(uc, cs->as, cpu->cpu_as_root, "CPU");
|
||||
address_space_init(uc, newas, cpu->cpu_as_root, "CPU");
|
||||
cpu_address_space_init(cs, newas, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#define tcg_enabled tcg_enabled_x86_64
|
||||
#define tcg_exec_init tcg_exec_init_x86_64
|
||||
#define memory_register_types memory_register_types_x86_64
|
||||
#define cpu_address_space_init cpu_address_space_init_x86_64
|
||||
#define cpu_exec_init_all cpu_exec_init_all_x86_64
|
||||
#define cpu_reload_memory_map cpu_reload_memory_map_x86_64
|
||||
#define vm_start vm_start_x86_64
|
||||
|
@ -2733,7 +2734,6 @@
|
|||
#define tcg_const_local_i32 tcg_const_local_i32_x86_64
|
||||
#define tcg_const_local_i64 tcg_const_local_i64_x86_64
|
||||
#define tcg_context_init tcg_context_init_x86_64
|
||||
#define tcg_cpu_address_space_init tcg_cpu_address_space_init_x86_64
|
||||
#define tcg_cpu_exec tcg_cpu_exec_x86_64
|
||||
#define tcg_current_code_size tcg_current_code_size_x86_64
|
||||
#define tcg_dump_info tcg_dump_info_x86_64
|
||||
|
|
Loading…
Reference in a new issue