replace cpuid_*features fields with a featue word array
cover replace cpuid_*features fields with a featue word array
I was planning to implement this only after we finished the rest of the work, the changes are a bit intrusive. But now it looks like the CPUID feature bits are getting into our way (e.g. the feature word array will allow us to simplify the -cpu host and -cpu check/enforce code a lot, making it easier to convert that code to use CPU subclasses), so I decided to submit it now.
Eduardo Habkost (2):
target-i386: add EXT2_PPRO_FEATURES #define
target-i386: replace cpuid_*features fields with a feature word array
hw/kvm/clock.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu.c | 548 +++++++++++++++++++++++----------------------- target-i386/cpu.h | 27 ++- target-i386/helper.c | 4 +- target-i386/kvm.c | 5 +- target-i386/misc_helper.c | 14 +- target-i386/translate.c | 10 +- 9 files changed, 317 insertions(+), 299 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/2 target-i386: add EXT2_PPRO_FEATURES #define
Instead of repeating the (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) expression everywhere, use EXT2_PPRO_FEATURES.
---
I have done this only to help me keep my sanity while redoing the 80-column line-wrap in the next patch.
--- target-i386/cpu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
target-i386/cpu.c +7 -6
@@ -303,6 +303,7 @@ typedef struct x86_def_t { CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \ CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \ CPUID_PAE | CPUID_SEP | CPUID_APIC) +#define EXT2_PPRO_FEATURES (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES)#define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \ CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
@@ -350,7 +351,7 @@ static x86_def_t builtin_x86_defs[] = {CPUID_MTRR |CPUID_CLFLUSH |CPUID_MCA | CPUID_PSE36, .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT, - .ext2_features = (PPRO_FEATURES &CPUID_EXT2_AMD_ALIASES ) | + .ext2_features =EXT2_PPRO_FEATURES | CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX, .ext3_features =CPUID_EXT3_LAHF_LM |CPUID_EXT3_SVM | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
@@ -370,7 +371,7 @@ static x86_def_t builtin_x86_defs[] = { CPUID_PSE36 | CPUID_VME | CPUID_HT, .ext_features =CPUID_EXT_SSE3 |CPUID_EXT_MONITOR |CPUID_EXT_CX16 | CPUID_EXT_POPCNT, - .ext2_features = (PPRO_FEATURES &CPUID_EXT2_AMD_ALIASES ) | + .ext2_features =EXT2_PPRO_FEATURES |CPUID_EXT2_LM |CPUID_EXT2_SYSCALL |CPUID_EXT2_NX |CPUID_EXT2_3DNOW |CPUID_EXT2_3DNOWEXT |CPUID_EXT2_MMXEXT | CPUID_EXT2_FFXSR | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP,
@@ -418,7 +419,7 @@ static x86_def_t builtin_x86_defs[] = {/* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */ .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16,/* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */ - .ext2_features = (PPRO_FEATURES &CPUID_EXT2_AMD_ALIASES ) | + .ext2_features =EXT2_PPRO_FEATURES | CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,/* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC, CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
@@ -447,7 +448,7 @@ static x86_def_t builtin_x86_defs[] = { .features = PPRO_FEATURES | CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_PSE36, .ext_features = CPUID_EXT_SSE3, - .ext2_features = PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES, + .ext2_features = EXT2_PPRO_FEATURES, .ext3_features = 0, .xlevel =0x80000008 , .model_id = "Common 32-bit KVM processor"
@@ -514,7 +515,7 @@ static x86_def_t builtin_x86_defs[] = { .stepping = 3, .features =PPRO_FEATURES |CPUID_PSE36 |CPUID_VME |CPUID_MTRR | CPUID_MCA, - .ext2_features = (PPRO_FEATURES &CPUID_EXT2_AMD_ALIASES ) | + .ext2_features =EXT2_PPRO_FEATURES | CPUID_EXT2_MMXEXT | CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT, .xlevel = 0x80000008, },
@@ -531,7 +532,7 @@ static x86_def_t builtin_x86_defs[] = {/* Some CPUs got no CPUID_SEP */ .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_DSCPL | CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR, - .ext2_features = (PPRO_FEATURES &CPUID_EXT2_AMD_ALIASES ) | + .ext2_features =EXT2_PPRO_FEATURES | CPUID_EXT2_NX, .ext3_features = CPUID_EXT3_LAHF_LM, .xlevel = 0x8000000A,
Signature · 1 line
1.7.11.7
PATCH 2/2 target-i386: replace cpuid_*features fields with a feature word array
In reply to Eduardo HabkostThis replaces the feature-bit fields on both X86CPU and x86_def_t structs with arrays.
With this, we will be able to simplify code that simply repeats the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), and CPU feature-bit property lookup/registration).
---
Except by the line-wrap at 80-columns and other small coding-style changes that were done manually, all changes were done using search&replace in the text editor.
--- hw/kvm/clock.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu.c | 547 +++++++++++++++++++++++----------------------- target-i386/cpu.h | 27 ++- target-i386/helper.c | 4 +- target-i386/kvm.c | 5 +- target-i386/misc_helper.c | 14 +- target-i386/translate.c | 10 +- 9 files changed, 316 insertions(+), 299 deletions(-)
hw/kvm/clock.c +1 -1
@@ -129,7 +129,7 @@ static TypeInfo kvmclock_info = {void kvmclock_create (void ) {if (kvm_enabled () && - first_cpu->cpuid_kvm_features & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | + first_cpu->features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) {sysbus_create_simple ("kvmclock" ,-1 ,NULL ); }
linux-user/elfload.c +1 -1
@@ -130,7 +130,7 @@ static const char *get_elf_platform(void)static uint32_t get_elf_hwcap (void ) { -return thread_env->cpuid_features; +return thread_env->features[FEAT_1_EDX ]; }#ifdef TARGET_X86_64
linux-user/main.c +2 -2
@@ -3625,13 +3625,13 @@ int main(int argc, char **argv, char **envp) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; env->hflags |=HF_PE_MASK ; -if (env->cpuid_features &CPUID_SSE ) { +if (env->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->cpuid_ext2_features &CPUID_EXT2_LM )) { +if (!(env->features[FEAT_80000001_EDX ] &CPUID_EXT2_LM )) {fprintf (stderr,"The selected x86 CPU does not support 64 bit mode\n" );exit (1 ); }
target-i386/cpu.c +278 -269
877 lines not on this page · raw message
target-i386/cpu.h +17 -10
@@ -694,6 +694,21 @@ typedef enum TPRAccess {TPR_ACCESS_WRITE , } TPRAccess; +typedef enum X86CPUFeatureWord { +FEAT_1_EDX ,/* CPUID[1].EDX */ +FEAT_1_ECX ,/* CPUID[1].ECX */ +FEAT_7_0_EBX ,/* CPUID[EAX=7,ECX=0].EBX */ +FEAT_80000001_EDX ,/* CPUID[8000_0001].EDX */ +FEAT_80000001_ECX ,/* CPUID[8000_0001].ECX */ +FEAT_C0000001_EDX ,/* CPUID[C000_0001].EDX */ +FEAT_KVM ,/* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */ +FEAT_SVM ,/* CPUID[8000_000A].EDX */ +FEATURE_WORDS ,/* Size of the features arrays */ +}FeatureWord ; + +/* An array of feature words */ +typedef uint32_t X86CPUFeatureWords [FEATURE_WORDS ]; + typedef struct CPUX86State { /* standard registers */ target_ulong regs[CPU_NB_REGS];
@@ -801,23 +816,17 @@ typedef struct CPUX86State {/* processor features (e.g. for CPUID insn) */ uint32_t cpuid_level; +uint32_t cpuid_xlevel; +X86CPUFeatureWords features;uint32_t cpuid_vendor1;uint32_t cpuid_vendor2;uint32_t cpuid_vendor3;uint32_t cpuid_version; -uint32_t cpuid_features; -uint32_t cpuid_ext_features; -uint32_t cpuid_xlevel;uint32_t cpuid_model[12 ]; -uint32_t cpuid_ext2_features; -uint32_t cpuid_ext3_features;uint32_t cpuid_apic_id;int cpuid_vendor_override;/* Store the results of Centaur's CPUID instructions */ uint32_t cpuid_xlevel2; -uint32_t cpuid_ext4_features; -/* Flags from CPUID[EAX=7,ECX=0].EBX */ -uint32_t cpuid_7_0_ebx_features;/* MTRRs */ uint64_t mtrr_fixed[11 ];
@@ -831,8 +840,6 @@ typedef struct CPUX86State {uint8_t soft_interrupt;uint8_t has_error_code;uint32_t sipi_vector; -uint32_t cpuid_kvm_features; -uint32_t cpuid_svm_features;bool tsc_valid;int tsc_khz;void *kvm_xsave_buf;
target-i386/helper.c +2 -2
@@ -449,7 +449,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)tlb_flush (env,1 ); }/* SSE handling */ -if (!(env->cpuid_features &CPUID_SSE )) { +if (!(env->features[FEAT_1_EDX ] &CPUID_SSE )) { new_cr4 &= ~CR4_OSFXSR_MASK ; } env->hflags &= ~HF_OSFXSR_MASK ;
@@ -457,7 +457,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4) env->hflags |=HF_OSFXSR_MASK ; } -if (!(env->cpuid_7_0_ebx_features &CPUID_7_0_EBX_SMAP )) { +if (!(env->features[FEAT_7_0_EBX ] &CPUID_7_0_EBX_SMAP )) { new_cr4 &= ~CR4_SMAP_MASK ; } env->hflags &= ~HF_SMAP_MASK ;
target-i386/kvm.c +3 -2
@@ -438,7 +438,7 @@ int kvm_arch_init_vcpu(CPUX86State *env) c = &cpuid_data.entries[cpuid_i++];memset (c,0 ,sizeof (*c)); c->function =KVM_CPUID_FEATURES ; - c->eax = env->cpuid_kvm_features; + c->eax = env->features[FEAT_KVM ];if (hyperv_enabled ()) {memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 );
@@ -573,7 +573,8 @@ int kvm_arch_init_vcpu(CPUX86State *env) cpuid_data.cpuid.nent = cpuid_i;if (((env->cpuid_version >>8 )&0xF ) >=6 - && (env->cpuid_features&(CPUID_MCE |CPUID_MCA )) == (CPUID_MCE |CPUID_MCA ) + && (env->features[FEAT_1_EDX ] & (CPUID_MCE |CPUID_MCA )) == + (CPUID_MCE |CPUID_MCA ) &&kvm_check_extension (env->kvm_state,KVM_CAP_MCE ) >0 ) {uint64_t mcg_cap;int banks;
target-i386/misc_helper.c +7 -7
@@ -291,22 +291,22 @@ void helper_wrmsr(CPUX86State *env)uint64_t update_mask; update_mask =0 ; -if (env->cpuid_ext2_features &CPUID_EXT2_SYSCALL ) { +if (env->features[FEAT_80000001_EDX ] &CPUID_EXT2_SYSCALL ) { update_mask |=MSR_EFER_SCE ; } -if (env->cpuid_ext2_features &CPUID_EXT2_LM ) { +if (env->features[FEAT_80000001_EDX ] &CPUID_EXT2_LM ) { update_mask |=MSR_EFER_LME ; } -if (env->cpuid_ext2_features &CPUID_EXT2_FFXSR ) { +if (env->features[FEAT_80000001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } -if (env->cpuid_ext2_features &CPUID_EXT2_NX ) { +if (env->features[FEAT_80000001_EDX ] &CPUID_EXT2_NX ) { update_mask |=MSR_EFER_NXE ; } -if (env->cpuid_ext3_features &CPUID_EXT3_SVM ) { +if (env->features[FEAT_80000001_ECX ] &CPUID_EXT3_SVM ) { update_mask |=MSR_EFER_SVME ; } -if (env->cpuid_ext2_features &CPUID_EXT2_FFXSR ) { +if (env->features[FEAT_80000001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } cpu_load_efer(env, (env->efer & ~update_mask) |
@@ -513,7 +513,7 @@ void helper_rdmsr(CPUX86State *env) val = env->mtrr_deftype;break ;case MSR_MTRRcap: -if (env->cpuid_features &CPUID_MTRR ) { +if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) { val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT | MSR_MTRRcap_WC_SUPPORTED; }else {
target-i386/translate.c +5 -5
@@ -7926,11 +7926,11 @@ static inline void gen_intermediate_code_internal(CPUX86State *env,if (flags &HF_SOFTMMU_MASK ) { dc->mem_index = (cpu_mmu_index (env) +1 ) <<2 ; } - dc->cpuid_features = env->cpuid_features; - dc->cpuid_ext_features = env->cpuid_ext_features; - dc->cpuid_ext2_features = env->cpuid_ext2_features; - dc->cpuid_ext3_features = env->cpuid_ext3_features; - dc->cpuid_7_0_ebx_features = env->cpuid_7_0_ebx_features; + dc->cpuid_features = env->features[FEAT_1_EDX ]; + dc->cpuid_ext_features = env->features[FEAT_1_ECX ]; + dc->cpuid_ext2_features = env->features[FEAT_80000001_EDX ]; + dc->cpuid_ext3_features = env->features[FEAT_80000001_ECX ]; + dc->cpuid_7_0_ebx_features = env->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
1.7.11.7