target-i386: Move CPUID fields to X86CPU
cover target-i386: Move CPUID fields to X86CPU
This patch depends on the X86CPU conversion patches I have sent earlier today. The full series can be seen on the git branch at:
git://github.com/ehabkost/qemu-hacks.git work/x86-cpu-move-cpuid-fields
Eduardo Habkost (3):
target-i386: Coding style fix on x86_cpuid_set_vendor()
target-i386: Add a marker to the end of region zeroed on reset
target-i386: Move CPUID fields to X86CPU
hw/i386/kvm/clock.c | 4 +- hw/i386/pc.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu-qom.h | 11 +++ target-i386/cpu.c | 216 +++++++++++++++++++++------------------------- target-i386/cpu.h | 12 +-- target-i386/helper.c | 6 +- target-i386/kvm.c | 10 +-- target-i386/misc_helper.c | 16 ++-- target-i386/translate.c | 14 +-- 11 files changed, 142 insertions(+), 155 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/3 target-i386: Coding style fix on x86_cpuid_set_vendor()
checkpatch.pl doesn't like the extra spaces inside the square brackets, but the alignment makes the code easier to read. Add a "+ 0" to keep alignment while making checkpatch.pl happy.
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -1640,7 +1640,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value, env->cpuid_vendor2 =0 ; env->cpuid_vendor3 =0 ;for (i =0 ; i <4 ; i++) { - env->cpuid_vendor1 |= ((uint8_t )value[i ]) << (8 * i); + env->cpuid_vendor1 |= ((uint8_t )value[i +0 ]) << (8 * i); env->cpuid_vendor2 |= ((uint8_t )value[i +4 ]) << (8 * i); env->cpuid_vendor3 |= ((uint8_t )value[i +8 ]) << (8 * i); }
Signature · 1 line
2.1.0
PATCH 2/3 target-i386: Add a marker to the end of region zeroed on reset
In reply to Eduardo HabkostInstead of using the next field in the struct (that's a moving target because we are gradually moving fields to X86CPU), add an empty struct as a marker (like we already did with {start,end}_init_save).
--- target-i386/cpu.c | 2 +- target-i386/cpu.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -2595,7 +2595,7 @@ static void x86_cpu_reset(CPUState *s) xcc->parent_reset (s); -memset (env,0 , offsetof(CPUX86State , cpuid_level)); +memset (env,0 , offsetof(CPUX86State , end_reset_fields));tlb_flush (s,1 );
target-i386/cpu.h +1 -0
@@ -931,6 +931,7 @@ typedef struct CPUX86State {CPU_COMMON /* Fields from here on are preserved across CPU reset. */ + struct {} end_reset_fields;/* processor features (e.g. for CPUID insn) */ uint32_t cpuid_level;
Signature · 1 line
2.1.0
PATCH 3/3 target-i386: Move CPUID fields to X86CPU
In reply to Eduardo Habkost--- hw/i386/kvm/clock.c | 4 +- hw/i386/pc.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu-qom.h | 11 +++ target-i386/cpu.c | 214 +++++++++++++++++++++------------------------- target-i386/cpu.h | 11 --- target-i386/helper.c | 6 +- target-i386/kvm.c | 10 +-- target-i386/misc_helper.c | 16 ++-- target-i386/translate.c | 14 +-- 11 files changed, 140 insertions(+), 154 deletions(-)
hw/i386/kvm/clock.c +2 -2
@@ -195,8 +195,8 @@ void kvmclock_create(void)X86CPU *cpu =X86_CPU (first_cpu);if (kvm_enabled () && - cpu->env.features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | - (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) { + cpu->features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | + (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) {sysbus_create_simple (TYPE_KVM_CLOCK ,-1 ,NULL ); } }
hw/i386/pc.c +1 -1
@@ -1096,7 +1096,7 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge) }/* tell smbios about cpuid version and features */ -smbios_set_cpuid (cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX ]); +smbios_set_cpuid (cpu->cpuid_version, cpu->features[FEAT_1_EDX ]); }/* pci-info ROM file. Little endian format */
linux-user/elfload.c +1 -1
@@ -140,7 +140,7 @@ static uint32_t get_elf_hwcap(void) {X86CPU *cpu =X86_CPU (thread_cpu); -return cpu->env.features[FEAT_1_EDX ]; +return cpu->features[FEAT_1_EDX ]; }#ifdef TARGET_X86_64
linux-user/main.c +2 -2
@@ -4086,13 +4086,13 @@ int main(int argc, char **argv, char **envp)#if defined(TARGET_I386 ) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; env->hflags |=HF_PE_MASK |HF_CPL_MASK ; -if (env->features[FEAT_1_EDX ] &CPUID_SSE ) { +if (X86_CPU (cpu)->features[FEAT_1_EDX ] &CPUID_SSE ) { env->cr[4 ] |=CR4_OSFXSR_MASK ; env->hflags |=HF_OSFXSR_MASK ; }#ifndef TARGET_ABI32 /* enable 64 bit mode if possible */ -if (!(env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM )) { +if (!(X86_CPU (cpu)->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM )) {fprintf (stderr,"The selected x86 CPU does not support 64 bit mode\n" );exit (1 ); }
target-i386/cpu-qom.h +11 -0
@@ -95,6 +95,17 @@ typedef struct X86CPU {bool host_features;int64_t apic_id; +/* processor features (e.g. for CPUID insn) */ +uint32_t cpuid_level; +uint32_t cpuid_xlevel; +uint32_t cpuid_xlevel2; +uint32_t cpuid_vendor1; +uint32_t cpuid_vendor2; +uint32_t cpuid_vendor3; +uint32_t cpuid_version; +FeatureWordArray features; +uint32_t cpuid_model[12 ]; +/* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough;
target-i386/cpu.c +99 -115
566 lines not on this page · raw message
target-i386/cpu.h +0 -11
@@ -933,17 +933,6 @@ typedef struct CPUX86State {/* Fields from here on are preserved across CPU reset. */ struct {} end_reset_fields; -/* processor features (e.g. for CPUID insn) */ -uint32_t cpuid_level; -uint32_t cpuid_xlevel; -uint32_t cpuid_xlevel2; -uint32_t cpuid_vendor1; -uint32_t cpuid_vendor2; -uint32_t cpuid_vendor3; -uint32_t cpuid_version; -FeatureWordArray features; -uint32_t cpuid_model[12 ]; -/* MTRRs */ uint64_t mtrr_fixed[11 ];uint64_t mtrr_deftype;
target-i386/helper.c +3 -3
@@ -27,7 +27,7 @@static void cpu_x86_version (X86CPU *cpu,int *family,int *model) { -int cpuver = cpu->env.cpuid_version; +int cpuver = cpu->cpuid_version;if (family ==NULL || model ==NULL ) {return ;
@@ -465,7 +465,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)tlb_flush (CPU (cpu),1 ); }/* SSE handling */ -if (!(env->features[FEAT_1_EDX ] &CPUID_SSE )) { +if (!(cpu->features[FEAT_1_EDX ] &CPUID_SSE )) { new_cr4 &= ~CR4_OSFXSR_MASK ; } env->hflags &= ~HF_OSFXSR_MASK ;
@@ -473,7 +473,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4) env->hflags |=HF_OSFXSR_MASK ; } -if (!(env->features[FEAT_7_0_EBX ] &CPUID_7_0_EBX_SMAP )) { +if (!(cpu->features[FEAT_7_0_EBX ] &CPUID_7_0_EBX_SMAP )) { new_cr4 &= ~CR4_SMAP_MASK ; } env->hflags &= ~HF_SMAP_MASK ;
target-i386/kvm.c +5 -5
@@ -544,7 +544,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; c->function =KVM_CPUID_FEATURES | kvm_base; - c->eax = env->features[FEAT_KVM ]; + c->eax = cpu->features[FEAT_KVM ]; has_msr_async_pf_en = c->eax & (1 <<KVM_FEATURE_ASYNC_PF );
@@ -656,7 +656,7 @@ int kvm_arch_init_vcpu(CPUState *cs) }/* Call Centaur's CPUID instructions they are supported. */ -if (env->cpuid_xlevel2 >0 ) { +if (cpu->cpuid_xlevel2 >0 ) {cpu_x86_cpuid (cpu,0xC0000000 ,0 , &limit, &unused, &unused, &unused);for (i =0xC0000000 ; i <= limit; i++) {
@@ -674,8 +674,8 @@ int kvm_arch_init_vcpu(CPUState *cs) cpuid_data.cpuid.nent = cpuid_i; -if (((env->cpuid_version >>8 )&0xF ) >=6 - && (env->features[FEAT_1_EDX ] & (CPUID_MCE |CPUID_MCA )) == +if (((cpu->cpuid_version >>8 )&0xF ) >=6 + && (cpu->features[FEAT_1_EDX ] & (CPUID_MCE |CPUID_MCA )) == (CPUID_MCE |CPUID_MCA ) &&kvm_check_extension (cs->kvm_state,KVM_CAP_MCE ) >0 ) {uint64_t mcg_cap;
@@ -740,7 +740,7 @@ int kvm_arch_init_vcpu(CPUState *cs) env->kvm_xsave_buf =qemu_memalign (4096 ,sizeof (struct kvm_xsave )); } -if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) { +if (cpu->features[FEAT_1_EDX ] &CPUID_MTRR ) { has_msr_mtrr = true; }
target-i386/misc_helper.c +9 -7
@@ -226,6 +226,7 @@ void helper_rdmsr(CPUX86State *env)#else void helper_wrmsr (CPUX86State *env) { +X86CPU *cpu =x86_env_get_cpu (env);uint64_t val;cpu_svm_check_intercept_param (env,SVM_EXIT_MSR ,1 );
@@ -251,22 +252,22 @@ void helper_wrmsr(CPUX86State *env)uint64_t update_mask; update_mask =0 ; -if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_SYSCALL ) { +if (cpu->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_SYSCALL ) { update_mask |=MSR_EFER_SCE ; } -if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM ) { +if (cpu->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM ) { update_mask |=MSR_EFER_LME ; } -if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { +if (cpu->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } -if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_NX ) { +if (cpu->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_NX ) { update_mask |=MSR_EFER_NXE ; } -if (env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_SVM ) { +if (cpu->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_SVM ) { update_mask |=MSR_EFER_SVME ; } -if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { +if (cpu->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } cpu_load_efer(env, (env->efer & ~update_mask) |
@@ -380,6 +381,7 @@ void helper_wrmsr(CPUX86State *env)void helper_rdmsr (CPUX86State *env) { +X86CPU *cpu =x86_env_get_cpu (env);uint64_t val;cpu_svm_check_intercept_param (env,SVM_EXIT_MSR ,0 );
@@ -483,7 +485,7 @@ void helper_rdmsr(CPUX86State *env) val = env->mtrr_deftype;break ;case MSR_MTRRcap: -if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) { +if (cpu->features[FEAT_1_EDX ] &CPUID_MTRR ) { val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT | MSR_MTRRcap_WC_SUPPORTED; }else {
target-i386/translate.c +7 -7
@@ -7090,7 +7090,7 @@ static target_ulong disas_insn(X86CPU *cpu, DisasContext *s,break ;case 0x134 :/* sysenter */ /* For Intel SYSENTER is valid on 64-bit */ -if (CODE64 (s) && env->cpuid_vendor1 !=CPUID_VENDOR_INTEL_1 ) +if (CODE64 (s) && cpu->cpuid_vendor1 !=CPUID_VENDOR_INTEL_1 ) goto illegal_op;if (!s->pe) {gen_exception (s,EXCP0D_GPF , pc_start - s->cs_base);
@@ -7103,7 +7103,7 @@ static target_ulong disas_insn(X86CPU *cpu, DisasContext *s,break ;case 0x135 :/* sysexit */ /* For Intel SYSEXIT is valid on 64-bit */ -if (CODE64 (s) && env->cpuid_vendor1 !=CPUID_VENDOR_INTEL_1 ) +if (CODE64 (s) && cpu->cpuid_vendor1 !=CPUID_VENDOR_INTEL_1 ) goto illegal_op;if (!s->pe) {gen_exception (s,EXCP0D_GPF , pc_start - s->cs_base);
@@ -7946,11 +7946,11 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu,if (flags &HF_SOFTMMU_MASK ) { dc->mem_index =cpu_mmu_index (env); } - dc->cpuid_features = env->features[FEAT_1_EDX ]; - dc->cpuid_ext_features = env->features[FEAT_1_ECX ]; - dc->cpuid_ext2_features = env->features[FEAT_8000_0001_EDX ]; - dc->cpuid_ext3_features = env->features[FEAT_8000_0001_ECX ]; - dc->cpuid_7_0_ebx_features = env->features[FEAT_7_0_EBX ]; + dc->cpuid_features = cpu->features[FEAT_1_EDX ]; + dc->cpuid_ext_features = cpu->features[FEAT_1_ECX ]; + dc->cpuid_ext2_features = cpu->features[FEAT_8000_0001_EDX ]; + dc->cpuid_ext3_features = cpu->features[FEAT_8000_0001_ECX ]; + dc->cpuid_7_0_ebx_features = cpu->features[FEAT_7_0_EBX ];#ifdef TARGET_X86_64 dc->lma = (flags >>HF_LMA_SHIFT ) &1 ; dc->code64 = (flags >>HF_CS64_SHIFT ) &1 ;
Signature · 1 line
2.1.0