From 411648eb0ca4eb7ce2208820b288731c07038dc2 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Mon, 8 Jun 2020 08:30:36 +0800 Subject: [PATCH] cleanup x86 code --- qemu/target-i386/cpu.c | 415 +---------------------------------------- 1 file changed, 1 insertion(+), 414 deletions(-) diff --git a/qemu/target-i386/cpu.c b/qemu/target-i386/cpu.c index 88b49296..b8f57016 100644 --- a/qemu/target-i386/cpu.c +++ b/qemu/target-i386/cpu.c @@ -1224,356 +1224,6 @@ static void report_unavailable_features(FeatureWord w, uint32_t mask) } } -#if 0 -static void x86_cpuid_version_get_family(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - int64_t value; - - value = (env->cpuid_version >> 8) & 0xf; - if (value == 0xf) { - value += (env->cpuid_version >> 20) & 0xff; - } - visit_type_int(v, &value, name, errp); -} - -static int x86_cpuid_version_set_family(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - const int64_t min = 0; - const int64_t max = 0xff + 0xf; - Error *local_err = NULL; - int64_t value; - - visit_type_int(v, &value, name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); - return -1; - } - - env->cpuid_version &= ~0xff00f00; - if (value > 0x0f) { - env->cpuid_version |= 0xf00 | ((value - 0x0f) << 20); - } else { - env->cpuid_version |= value << 8; - } - - return 0; -} - -static void x86_cpuid_version_get_model(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - int64_t value; - - value = (env->cpuid_version >> 4) & 0xf; - value |= ((env->cpuid_version >> 16) & 0xf) << 4; - visit_type_int(v, &value, name, errp); -} - -static int x86_cpuid_version_set_model(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - const int64_t min = 0; - const int64_t max = 0xff; - Error *local_err = NULL; - int64_t value; - - visit_type_int(v, &value, name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); - return -1; - } - - env->cpuid_version &= ~0xf00f0; - env->cpuid_version |= ((value & 0xf) << 4) | ((value >> 4) << 16); - - return 0; -} - -static void x86_cpuid_version_get_stepping(struct uc_struct *uc, Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - int64_t value; - - value = env->cpuid_version & 0xf; - visit_type_int(v, &value, name, errp); -} - -static int x86_cpuid_version_set_stepping(struct uc_struct *uc, Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - const int64_t min = 0; - const int64_t max = 0xf; - Error *local_err = NULL; - int64_t value; - - visit_type_int(v, &value, name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); - return -1; - } - - env->cpuid_version &= ~0xf; - env->cpuid_version |= value & 0xf; - - return 0; -} - -static void x86_cpuid_get_level(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - - visit_type_uint32(v, &cpu->env.cpuid_level, name, errp); -} - -static int x86_cpuid_set_level(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - - visit_type_uint32(v, &cpu->env.cpuid_level, name, errp); - - return 0; -} - -static void x86_cpuid_get_xlevel(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - - visit_type_uint32(v, &cpu->env.cpuid_xlevel, name, errp); -} - -static int x86_cpuid_set_xlevel(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - - visit_type_uint32(v, &cpu->env.cpuid_xlevel, name, errp); - - return 0; -} - -static char *x86_cpuid_get_vendor(struct uc_struct *uc, Object *obj, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - char *value; - - value = (char *)g_malloc(CPUID_VENDOR_SZ + 1); - x86_cpu_vendor_words2str(value, env->cpuid_vendor1, env->cpuid_vendor2, - env->cpuid_vendor3); - return value; -} - -static int x86_cpuid_set_vendor(struct uc_struct *uc, Object *obj, const char *value, - Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - int i; - - if (strlen(value) != CPUID_VENDOR_SZ) { - error_set(errp, QERR_PROPERTY_VALUE_BAD, "", - "vendor", value); - return -1; - } - - env->cpuid_vendor1 = 0; - 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_vendor2 |= ((uint8_t)value[i + 4]) << (8 * i); - env->cpuid_vendor3 |= ((uint8_t)value[i + 8]) << (8 * i); - } - - return 0; -} - -static char *x86_cpuid_get_model_id(struct uc_struct *uc, Object *obj, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - char *value; - int i; - - value = g_malloc(48 + 1); - for (i = 0; i < 48; i++) { - value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3)); - } - value[48] = '\0'; - return value; -} - -static int x86_cpuid_set_model_id(struct uc_struct *uc, Object *obj, const char *model_id, - Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - CPUX86State *env = &cpu->env; - int c, len, i; - - if (model_id == NULL) { - model_id = ""; - } - len = strlen(model_id); - memset(env->cpuid_model, 0, 48); - for (i = 0; i < 48; i++) { - if (i >= len) { - c = '\0'; - } else { - c = (uint8_t)model_id[i]; - } - env->cpuid_model[i >> 2] |= c << (8 * (i & 3)); - } - - return 0; -} - -static void x86_cpuid_get_tsc_freq(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - int64_t value; - - value = cpu->env.tsc_khz * 1000; - visit_type_int(v, &value, name, errp); -} - -static int x86_cpuid_set_tsc_freq(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - const int64_t min = 0; - const int64_t max = INT64_MAX; - Error *local_err = NULL; - int64_t value; - - visit_type_int(v, &value, name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - if (value < min || value > max) { - error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "", - name ? name : "null", value, min, max); - return -1; - } - - cpu->env.tsc_khz = (int)(value / 1000); - - return 0; -} - -static void x86_cpuid_get_apic_id(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - int64_t value = cpu->env.cpuid_apic_id; - - visit_type_int(v, &value, name, errp); -} - -static int x86_cpuid_set_apic_id(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - X86CPU *cpu = X86_CPU(uc, obj); - DeviceState *dev = DEVICE(uc, obj); - const int64_t min = 0; - const int64_t max = UINT32_MAX; - Error *error = NULL; - int64_t value; - - if (dev->realized) { - error_setg(errp, "Attempt to set property '%s' on '%s' after " - "it was realized", name, object_get_typename(obj)); - return -1; - } - - visit_type_int(v, &value, name, &error); - if (error) { - error_propagate(errp, error); - return -1; - } - if (value < min || value > max) { - error_setg(errp, "Property %s.%s doesn't take value %" PRId64 - " (minimum: %" PRId64 ", maximum: %" PRId64 ")" , - object_get_typename(obj), name, value, min, max); - return -1; - } - - if ((value != cpu->env.cpuid_apic_id) && cpu_exists(uc, value)) { - error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value); - return -1; - } - cpu->env.cpuid_apic_id = (uint32_t)value; - - return 0; -} - -/* Generic getter for "feature-words" and "filtered-features" properties */ -static void x86_cpu_get_feature_words(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - uint32_t *array = (uint32_t *)opaque; - FeatureWord w; - Error *err = NULL; - // These all get setup below, so no need to initialise them here. - X86CPUFeatureWordInfo word_infos[FEATURE_WORDS]; - X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS]; - X86CPUFeatureWordInfoList *list = NULL; - - for (w = 0; w < FEATURE_WORDS; w++) { - FeatureWordInfo *wi = &feature_word_info[w]; - X86CPUFeatureWordInfo *qwi = &word_infos[w]; - qwi->cpuid_input_eax = wi->cpuid_eax; - qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; - qwi->cpuid_input_ecx = wi->cpuid_ecx; - qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; - qwi->features = array[w]; - - /* List will be in reverse order, but order shouldn't matter */ - list_entries[w].next = list; - list_entries[w].value = &word_infos[w]; - list = &list_entries[w]; - } - - visit_type_X86CPUFeatureWordInfoList(v, &list, "feature-words", &err); - error_propagate(errp, err); -} -#endif - /* Convert all '_' in a feature string option name to '-', to make feature * name conform to QOM property naming rule, which uses '-' instead of '_'. */ @@ -1707,41 +1357,16 @@ static int x86_cpu_filter_features(X86CPU *cpu) static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def) { CPUX86State *env = &cpu->env; -#if 0 - const char *vendor; -#endif FeatureWord w; -#if 0 - object_property_set_int(env->uc, OBJECT(cpu), def->level, "level", errp); - object_property_set_int(env->uc, OBJECT(cpu), def->family, "family", errp); - object_property_set_int(env->uc, OBJECT(cpu), def->model, "model", errp); - object_property_set_int(env->uc, OBJECT(cpu), def->stepping, "stepping", errp); - object_property_set_int(env->uc, OBJECT(cpu), def->xlevel, "xlevel", errp); -#endif env->cpuid_xlevel2 = def->xlevel2; cpu->cache_info_passthrough = def->cache_info_passthrough; -#if 0 - object_property_set_str(env->uc, OBJECT(cpu), def->model_id, "model-id", errp); -#endif + for (w = 0; w < FEATURE_WORDS; w++) { env->features[w] = def->features[w]; } env->features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR; - -#if 0 - /* sysenter isn't supported in compatibility mode on AMD, - * syscall isn't supported in compatibility mode on Intel. - * Normally we advertise the actual CPU vendor, but you can - * override this using the 'vendor' property if you want to use - * KVM's sysenter/syscall emulation in compatibility mode and - * when doing cross vendor migration - */ - vendor = def->vendor; - - object_property_set_str(env->uc, OBJECT(cpu), vendor, "vendor", errp); -#endif } #if !defined(CONFIG_USER_ONLY) @@ -2291,42 +1916,6 @@ static void x86_cpu_initfn(struct uc_struct *uc, CPUState *obj, void *opaque) cs->env_ptr = env; cpu_exec_init(env, opaque); -#if 0 - object_property_add(obj, "family", "int", - x86_cpuid_version_get_family, - x86_cpuid_version_set_family, NULL, NULL, NULL); - object_property_add(obj, "model", "int", - x86_cpuid_version_get_model, - x86_cpuid_version_set_model, NULL, NULL, NULL); - object_property_add(obj, "stepping", "int", - x86_cpuid_version_get_stepping, - x86_cpuid_version_set_stepping, NULL, NULL, NULL); - object_property_add(obj, "level", "int", - x86_cpuid_get_level, - x86_cpuid_set_level, NULL, NULL, NULL); - object_property_add(obj, "xlevel", "int", - x86_cpuid_get_xlevel, - x86_cpuid_set_xlevel, NULL, NULL, NULL); - object_property_add_str(obj, "vendor", - x86_cpuid_get_vendor, - x86_cpuid_set_vendor, NULL); - object_property_add_str(obj, "model-id", - x86_cpuid_get_model_id, - x86_cpuid_set_model_id, NULL); - object_property_add(obj, "tsc-frequency", "int", - x86_cpuid_get_tsc_freq, - x86_cpuid_set_tsc_freq, NULL, NULL, NULL); - object_property_add(obj, "apic-id", "int", - x86_cpuid_get_apic_id, - x86_cpuid_set_apic_id, NULL, NULL, NULL); - object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo", - x86_cpu_get_feature_words, - NULL, NULL, (void *)env->features, NULL); - object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo", - x86_cpu_get_feature_words, - NULL, NULL, (void *)cpu->filtered_features, NULL); -#endif - cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY; env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index); @@ -2371,14 +1960,12 @@ static bool x86_cpu_has_work(CPUState *cs) X86CPU *cpu = X86_CPU(cs->uc, cs); CPUX86State *env = &cpu->env; -#if !defined(CONFIG_USER_ONLY) if (cs->interrupt_request & CPU_INTERRUPT_POLL) { #if 0 apic_poll_irq(cpu->apic_state); #endif cpu_reset_interrupt(cs, CPU_INTERRUPT_POLL); } -#endif return ((cs->interrupt_request & CPU_INTERRUPT_HARD) && (env->eflags & IF_MASK)) ||