Skip to content

Commit

Permalink
cpu: Add CPUArchState pointer to CPUState
Browse files Browse the repository at this point in the history
The target-specific ENV_GET_CPU() macros have allowed us to navigate
from CPUArchState to CPUState. The reverse direction was not supported.
Avoid introducing CPU_GET_ENV() macros by initializing an untyped
pointer that is initialized in derived instance_init functions.

The field may not be called "env" due to it being poisoned.

Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
afaerber committed Feb 1, 2013
1 parent a66fdbc commit 2f1c556
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/qom/cpu.h
Expand Up @@ -71,6 +71,7 @@ struct kvm_run;
* @created: Indicates whether the CPU thread has been successfully created.
* @stop: Indicates a pending stop request.
* @stopped: Indicates the CPU has been artificially stopped.
* @env_ptr: Pointer to subclass-specific CPUArchState field.
* @current_tb: Currently executing TB.
* @kvm_fd: vCPU file descriptor for KVM.
*
Expand Down Expand Up @@ -100,6 +101,7 @@ struct CPUState {
bool stopped;
volatile sig_atomic_t exit_request;

void *env_ptr; /* CPUArchState */
struct TranslationBlock *current_tb;

int kvm_fd;
Expand Down
2 changes: 2 additions & 0 deletions target-alpha/cpu.c
Expand Up @@ -233,9 +233,11 @@ static const TypeInfo ev68_cpu_type_info = {

static void alpha_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
AlphaCPU *cpu = ALPHA_CPU(obj);
CPUAlphaState *env = &cpu->env;

cs->env_ptr = env;
cpu_exec_init(env);
tlb_flush(env, 1);

Expand Down
2 changes: 2 additions & 0 deletions target-arm/cpu.c
Expand Up @@ -134,9 +134,11 @@ static inline void set_feature(CPUARMState *env, int feature)

static void arm_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
ARMCPU *cpu = ARM_CPU(obj);
static bool inited;

cs->env_ptr = &cpu->env;
cpu_exec_init(&cpu->env);
cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
g_free, g_free);
Expand Down
2 changes: 2 additions & 0 deletions target-cris/cpu.c
Expand Up @@ -68,10 +68,12 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp)

static void cris_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
CRISCPU *cpu = CRIS_CPU(obj);
CPUCRISState *env = &cpu->env;
static bool tcg_initialized;

cs->env_ptr = env;
cpu_exec_init(env);

if (tcg_enabled() && !tcg_initialized) {
Expand Down
1 change: 1 addition & 0 deletions target-i386/cpu.c
Expand Up @@ -2164,6 +2164,7 @@ static void x86_cpu_initfn(Object *obj)
CPUX86State *env = &cpu->env;
static int inited;

cs->env_ptr = env;
cpu_exec_init(env);

object_property_add(obj, "family", "int",
Expand Down
2 changes: 2 additions & 0 deletions target-lm32/cpu.c
Expand Up @@ -56,10 +56,12 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error **errp)

static void lm32_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
LM32CPU *cpu = LM32_CPU(obj);
CPULM32State *env = &cpu->env;
static bool tcg_initialized;

cs->env_ptr = env;
cpu_exec_init(env);

env->flags = 0;
Expand Down
2 changes: 2 additions & 0 deletions target-m68k/cpu.c
Expand Up @@ -154,10 +154,12 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)

static void m68k_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
M68kCPU *cpu = M68K_CPU(obj);
CPUM68KState *env = &cpu->env;
static bool inited;

cs->env_ptr = env;
cpu_exec_init(env);

if (tcg_enabled() && !inited) {
Expand Down
2 changes: 2 additions & 0 deletions target-microblaze/cpu.c
Expand Up @@ -98,10 +98,12 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)

static void mb_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
MicroBlazeCPU *cpu = MICROBLAZE_CPU(obj);
CPUMBState *env = &cpu->env;
static bool tcg_initialized;

cs->env_ptr = env;
cpu_exec_init(env);

set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
Expand Down
2 changes: 2 additions & 0 deletions target-mips/cpu.c
Expand Up @@ -55,9 +55,11 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)

static void mips_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
MIPSCPU *cpu = MIPS_CPU(obj);
CPUMIPSState *env = &cpu->env;

cs->env_ptr = env;
cpu_exec_init(env);

if (tcg_enabled()) {
Expand Down
2 changes: 2 additions & 0 deletions target-openrisc/cpu.c
Expand Up @@ -75,9 +75,11 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)

static void openrisc_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
OpenRISCCPU *cpu = OPENRISC_CPU(obj);
static int inited;

cs->env_ptr = &cpu->env;
cpu_exec_init(&cpu->env);

#ifndef CONFIG_USER_ONLY
Expand Down
2 changes: 2 additions & 0 deletions target-ppc/translate_init.c
Expand Up @@ -10529,11 +10529,13 @@ static void ppc_cpu_reset(CPUState *s)

static void ppc_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
PowerPCCPU *cpu = POWERPC_CPU(obj);
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
CPUPPCState *env = &cpu->env;
ppc_def_t *def = pcc->info;

cs->env_ptr = env;
cpu_exec_init(env);

env->msr_mask = def->msr_mask;
Expand Down
2 changes: 2 additions & 0 deletions target-s390x/cpu.c
Expand Up @@ -110,6 +110,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)

static void s390_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
S390CPU *cpu = S390_CPU(obj);
CPUS390XState *env = &cpu->env;
static bool inited;
Expand All @@ -118,6 +119,7 @@ static void s390_cpu_initfn(Object *obj)
struct tm tm;
#endif

cs->env_ptr = env;
cpu_exec_init(env);
#if !defined(CONFIG_USER_ONLY)
qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
Expand Down
2 changes: 2 additions & 0 deletions target-sh4/cpu.c
Expand Up @@ -67,9 +67,11 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp)

static void superh_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
SuperHCPU *cpu = SUPERH_CPU(obj);
CPUSH4State *env = &cpu->env;

cs->env_ptr = env;
cpu_exec_init(env);

env->movcal_backup_tail = &(env->movcal_backup);
Expand Down
2 changes: 2 additions & 0 deletions target-sparc/cpu.c
Expand Up @@ -860,9 +860,11 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)

static void sparc_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
SPARCCPU *cpu = SPARC_CPU(obj);
CPUSPARCState *env = &cpu->env;

cs->env_ptr = env;
cpu_exec_init(env);

if (tcg_enabled()) {
Expand Down
2 changes: 2 additions & 0 deletions target-unicore32/cpu.c
Expand Up @@ -93,10 +93,12 @@ static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)

static void uc32_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
UniCore32CPU *cpu = UNICORE32_CPU(obj);
CPUUniCore32State *env = &cpu->env;
static bool inited;

cs->env_ptr = env;
cpu_exec_init(env);

#ifdef CONFIG_USER_ONLY
Expand Down
2 changes: 2 additions & 0 deletions target-xtensa/cpu.c
Expand Up @@ -69,10 +69,12 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)

static void xtensa_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
XtensaCPU *cpu = XTENSA_CPU(obj);
CPUXtensaState *env = &cpu->env;
static bool tcg_inited;

cs->env_ptr = env;
cpu_exec_init(env);

if (tcg_enabled() && !tcg_inited) {
Expand Down

0 comments on commit 2f1c556

Please sign in to comment.