static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)

{

    unsigned int i;

    x86_def_t *def;



    char *s = strdup(cpu_model);

    char *featurestr, *name = strtok(s, ",");

    uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0;

    uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0;

    int family = -1, model = -1, stepping = -1;



    def = NULL;

    for (i = 0; i < ARRAY_SIZE(x86_defs); i++) {

        if (strcmp(name, x86_defs[i].name) == 0) {

            def = &x86_defs[i];

            break;

        }

    }

    if (kvm_enabled() && strcmp(name, "host") == 0) {

        cpu_x86_fill_host(x86_cpu_def);

    } else if (!def) {

        goto error;

    } else {

        memcpy(x86_cpu_def, def, sizeof(*def));

    }



    add_flagname_to_bitmaps("hypervisor", &plus_features,

        &plus_ext_features, &plus_ext2_features, &plus_ext3_features);



    featurestr = strtok(NULL, ",");



    while (featurestr) {

        char *val;

        if (featurestr[0] == '+') {

            add_flagname_to_bitmaps(featurestr + 1, &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features);

        } else if (featurestr[0] == '-') {

            add_flagname_to_bitmaps(featurestr + 1, &minus_features, &minus_ext_features, &minus_ext2_features, &minus_ext3_features);

        } else if ((val = strchr(featurestr, '='))) {

            *val = 0; val++;

            if (!strcmp(featurestr, "family")) {

                char *err;

                family = strtol(val, &err, 10);

                if (!*val || *err || family < 0) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->family = family;

            } else if (!strcmp(featurestr, "model")) {

                char *err;

                model = strtol(val, &err, 10);

                if (!*val || *err || model < 0 || model > 0xff) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->model = model;

            } else if (!strcmp(featurestr, "stepping")) {

                char *err;

                stepping = strtol(val, &err, 10);

                if (!*val || *err || stepping < 0 || stepping > 0xf) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->stepping = stepping;

            } else if (!strcmp(featurestr, "vendor")) {

                if (strlen(val) != 12) {

                    fprintf(stderr, "vendor string must be 12 chars long\n");

                    goto error;

                }

                x86_cpu_def->vendor1 = 0;

                x86_cpu_def->vendor2 = 0;

                x86_cpu_def->vendor3 = 0;

                for(i = 0; i < 4; i++) {

                    x86_cpu_def->vendor1 |= ((uint8_t)val[i    ]) << (8 * i);

                    x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i);

                    x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i);

                }

                x86_cpu_def->vendor_override = 1;

            } else if (!strcmp(featurestr, "model_id")) {

                pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),

                        val);

            } else {

                fprintf(stderr, "unrecognized feature %s\n", featurestr);

                goto error;

            }

        } else {

            fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);

            goto error;

        }

        featurestr = strtok(NULL, ",");

    }

    x86_cpu_def->features |= plus_features;

    x86_cpu_def->ext_features |= plus_ext_features;

    x86_cpu_def->ext2_features |= plus_ext2_features;

    x86_cpu_def->ext3_features |= plus_ext3_features;

    x86_cpu_def->features &= ~minus_features;

    x86_cpu_def->ext_features &= ~minus_ext_features;

    x86_cpu_def->ext2_features &= ~minus_ext2_features;

    x86_cpu_def->ext3_features &= ~minus_ext3_features;

    free(s);

    return 0;



error:

    free(s);

    return -1;

}

static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)

{

    unsigned int i;

    x86_def_t *def;



    char *s = strdup(cpu_model);

    char *featurestr, *name = strtok(s, ",");

    uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0;

    uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0;

    int family = -1, model = -1, stepping = -1;



    def = NULL;

    for (i = 0; i < ARRAY_SIZE(x86_defs); i++) {

        if (strcmp(name, x86_defs[i].name) == 0) {

            def = &x86_defs[i];

            break;

        }

    }

    if (kvm_enabled() && strcmp(name, "host") == 0) {

        cpu_x86_fill_host(x86_cpu_def);

    } else if (!def) {

        goto error;

    } else {

        memcpy(x86_cpu_def, def, sizeof(*def));

    }



    add_flagname_to_bitmaps("hypervisor", &plus_features,

        &plus_ext_features, &plus_ext2_features, &plus_ext3_features);



    featurestr = strtok(NULL, ",");



    while (featurestr) {

        char *val;

        if (featurestr[0] == '+') {

            add_flagname_to_bitmaps(featurestr + 1, &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features);

        } else if (featurestr[0] == '-') {

            add_flagname_to_bitmaps(featurestr + 1, &minus_features, &minus_ext_features, &minus_ext2_features, &minus_ext3_features);

        } else if ((val = strchr(featurestr, '='))) {

            *val = 0; val++;

            if (!strcmp(featurestr, "family")) {

                char *err;

                family = strtol(val, &err, 10);

                if (!*val || *err || family < 0) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->family = family;

            } else if (!strcmp(featurestr, "model")) {

                char *err;

                model = strtol(val, &err, 10);

                if (!*val || *err || model < 0 || model > 0xff) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->model = model;

            } else if (!strcmp(featurestr, "stepping")) {

                char *err;

                stepping = strtol(val, &err, 10);

                if (!*val || *err || stepping < 0 || stepping > 0xf) {

                    fprintf(stderr, "bad numerical value %s\n", val);

                    goto error;

                }

                x86_cpu_def->stepping = stepping;

            } else if (!strcmp(featurestr, "vendor")) {

                if (strlen(val) != 12) {

                    fprintf(stderr, "vendor string must be 12 chars long\n");

                    goto error;

                }

                x86_cpu_def->vendor1 = 0;

                x86_cpu_def->vendor2 = 0;

                x86_cpu_def->vendor3 = 0;

                for(i = 0; i < 4; i++) {

                    x86_cpu_def->vendor1 |= ((uint8_t)val[i    ]) << (8 * i);

                    x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i);

                    x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i);

                }

                x86_cpu_def->vendor_override = 1;

            } else if (!strcmp(featurestr, "model_id")) {

                pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),

                        val);

            } else {

                fprintf(stderr, "unrecognized feature %s\n", featurestr);

                goto error;

            }

        } else {

            fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);

            goto error;

        }

        featurestr = strtok(NULL, ",");

    }

    x86_cpu_def->features |= plus_features;

    x86_cpu_def->ext_features |= plus_ext_features;

    x86_cpu_def->ext2_features |= plus_ext2_features;

    x86_cpu_def->ext3_features |= plus_ext3_features;

    x86_cpu_def->features &= ~minus_features;

    x86_cpu_def->ext_features &= ~minus_ext_features;

    x86_cpu_def->ext2_features &= ~minus_ext2_features;

    x86_cpu_def->ext3_features &= ~minus_ext3_features;

    free(s);

    return 0;



error:

    free(s);

    return -1;

}

static int FUNC_0(x86_def_t *VAR_0, const char *VAR_1)

{

    unsigned int VAR_2;

    x86_def_t *def;



    char *VAR_3 = strdup(VAR_1);

    char *VAR_4, *VAR_5 = strtok(VAR_3, ",");

    uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0;

    uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0;

    int VAR_6 = -1, VAR_7 = -1, VAR_8 = -1;



    def = NULL;

    for (VAR_2 = 0; VAR_2 < ARRAY_SIZE(x86_defs); VAR_2++) {

        if (strcmp(VAR_5, x86_defs[VAR_2].VAR_5) == 0) {

            def = &x86_defs[VAR_2];

            break;

        }

    }

    if (kvm_enabled() && strcmp(VAR_5, "host") == 0) {

        cpu_x86_fill_host(VAR_0);

    } else if (!def) {

        goto error;

    } else {

        memcpy(VAR_0, def, sizeof(*def));

    }



    add_flagname_to_bitmaps("hypervisor", &plus_features,

        &plus_ext_features, &plus_ext2_features, &plus_ext3_features);



    VAR_4 = strtok(NULL, ",");



    while (VAR_4) {

        char *VAR_9;

        if (VAR_4[0] == '+') {

            add_flagname_to_bitmaps(VAR_4 + 1, &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features);

        } else if (VAR_4[0] == '-') {

            add_flagname_to_bitmaps(VAR_4 + 1, &minus_features, &minus_ext_features, &minus_ext2_features, &minus_ext3_features);

        } else if ((VAR_9 = strchr(VAR_4, '='))) {

            *VAR_9 = 0; VAR_9++;

            if (!strcmp(VAR_4, "VAR_6")) {

                char *VAR_11;

                VAR_6 = strtol(VAR_9, &VAR_11, 10);

                if (!*VAR_9 || *VAR_11 || VAR_6 < 0) {

                    fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9);

                    goto error;

                }

                VAR_0->VAR_6 = VAR_6;

            } else if (!strcmp(VAR_4, "VAR_7")) {

                char *VAR_11;

                VAR_7 = strtol(VAR_9, &VAR_11, 10);

                if (!*VAR_9 || *VAR_11 || VAR_7 < 0 || VAR_7 > 0xff) {

                    fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9);

                    goto error;

                }

                VAR_0->VAR_7 = VAR_7;

            } else if (!strcmp(VAR_4, "VAR_8")) {

                char *VAR_11;

                VAR_8 = strtol(VAR_9, &VAR_11, 10);

                if (!*VAR_9 || *VAR_11 || VAR_8 < 0 || VAR_8 > 0xf) {

                    fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9);

                    goto error;

                }

                VAR_0->VAR_8 = VAR_8;

            } else if (!strcmp(VAR_4, "vendor")) {

                if (strlen(VAR_9) != 12) {

                    fprintf(stderr, "vendor string must be 12 chars long\n");

                    goto error;

                }

                VAR_0->vendor1 = 0;

                VAR_0->vendor2 = 0;

                VAR_0->vendor3 = 0;

                for(VAR_2 = 0; VAR_2 < 4; VAR_2++) {

                    VAR_0->vendor1 |= ((uint8_t)VAR_9[VAR_2    ]) << (8 * VAR_2);

                    VAR_0->vendor2 |= ((uint8_t)VAR_9[VAR_2 + 4]) << (8 * VAR_2);

                    VAR_0->vendor3 |= ((uint8_t)VAR_9[VAR_2 + 8]) << (8 * VAR_2);

                }

                VAR_0->vendor_override = 1;

            } else if (!strcmp(VAR_4, "model_id")) {

                pstrcpy(VAR_0->model_id, sizeof(VAR_0->model_id),

                        VAR_9);

            } else {

                fprintf(stderr, "unrecognized feature %VAR_3\n", VAR_4);

                goto error;

            }

        } else {

            fprintf(stderr, "feature string `%VAR_3' not in format (+feature|-feature|feature=xyz)\n", VAR_4);

            goto error;

        }

        VAR_4 = strtok(NULL, ",");

    }

    VAR_0->features |= plus_features;

    VAR_0->ext_features |= plus_ext_features;

    VAR_0->ext2_features |= plus_ext2_features;

    VAR_0->ext3_features |= plus_ext3_features;

    VAR_0->features &= ~minus_features;

    VAR_0->ext_features &= ~minus_ext_features;

    VAR_0->ext2_features &= ~minus_ext2_features;

    VAR_0->ext3_features &= ~minus_ext3_features;

    free(VAR_3);

    return 0;



error:

    free(VAR_3);

    return -1;

}

static int FUNC_0(x86_def_t *VAR_0, const char *VAR_1)
{ unsigned int VAR_2; x86_def_t *def; char *VAR_3 = strdup(VAR_1); char *VAR_4, *VAR_5 = strtok(VAR_3, ","); uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0; uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0; int VAR_6 = -1, VAR_7 = -1, VAR_8 = -1; def = NULL; for (VAR_2 = 0; VAR_2 < ARRAY_SIZE(x86_defs); VAR_2++) { if (strcmp(VAR_5, x86_defs[VAR_2].VAR_5) == 0) { def = &x86_defs[VAR_2]; break; } } if (kvm_enabled() && strcmp(VAR_5, "host") == 0) { cpu_x86_fill_host(VAR_0); } else if (!def) { goto error; } else { memcpy(VAR_0, def, sizeof(*def)); } add_flagname_to_bitmaps("hypervisor", &plus_features,
&plus_ext_features, &plus_ext2_features, &plus_ext3_features); VAR_4 = strtok(NULL, ","); while (VAR_4) { char *VAR_9; if (VAR_4[0] == '+') { add_flagname_to_bitmaps(VAR_4 + 1, &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features); } else if (VAR_4[0] == '-') { add_flagname_to_bitmaps(VAR_4 + 1, &minus_features, &minus_ext_features, &minus_ext2_features, &minus_ext3_features); } else if ((VAR_9 = strchr(VAR_4, '='))) { *VAR_9 = 0; VAR_9++; if (!strcmp(VAR_4, "VAR_6")) { char *VAR_11; VAR_6 = strtol(VAR_9, &VAR_11, 10); if (!*VAR_9 || *VAR_11 || VAR_6 < 0) { fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9); goto error; } VAR_0->VAR_6 = VAR_6; } else if (!strcmp(VAR_4, "VAR_7")) { char *VAR_11; VAR_7 = strtol(VAR_9, &VAR_11, 10); if (!*VAR_9 || *VAR_11 || VAR_7 < 0 || VAR_7 > 0xff) { fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9); goto error; } VAR_0->VAR_7 = VAR_7; } else if (!strcmp(VAR_4, "VAR_8")) { char *VAR_11; VAR_8 = strtol(VAR_9, &VAR_11, 10); if (!*VAR_9 || *VAR_11 || VAR_8 < 0 || VAR_8 > 0xf) { fprintf(stderr, "bad numerical value %VAR_3\n", VAR_9); goto error; } VAR_0->VAR_8 = VAR_8; } else if (!strcmp(VAR_4, "vendor")) { if (strlen(VAR_9) != 12) { fprintf(stderr, "vendor string must be 12 chars long\n"); goto error; } VAR_0->vendor1 = 0; VAR_0->vendor2 = 0; VAR_0->vendor3 = 0; for(VAR_2 = 0; VAR_2 < 4; VAR_2++) { VAR_0->vendor1 |= ((uint8_t)VAR_9[VAR_2    ]) << (8 * VAR_2); VAR_0->vendor2 |= ((uint8_t)VAR_9[VAR_2 + 4]) << (8 * VAR_2); VAR_0->vendor3 |= ((uint8_t)VAR_9[VAR_2 + 8]) << (8 * VAR_2); } VAR_0->vendor_override = 1; } else if (!strcmp(VAR_4, "model_id")) { pstrcpy(VAR_0->model_id, sizeof(VAR_0->model_id),
VAR_9); } else { fprintf(stderr, "unrecognized feature %VAR_3\n", VAR_4); goto error; } } else { fprintf(stderr, "feature string `%VAR_3' not in format (+feature|-feature|feature=xyz)\n", VAR_4); goto error; } VAR_4 = strtok(NULL, ","); } VAR_0->features |= plus_features; VAR_0->ext_features |= plus_ext_features; VAR_0->ext2_features |= plus_ext2_features; VAR_0->ext3_features |= plus_ext3_features; VAR_0->features &= ~minus_features; VAR_0->ext_features &= ~minus_ext_features; VAR_0->ext2_features &= ~minus_ext2_features; VAR_0->ext3_features &= ~minus_ext3_features; free(VAR_3); return 0; error:
free(VAR_3); return -1; }