Revision aaed909a target-i386/helper2.c

b/target-i386/helper2.c
31 31

  
32 32
//#define DEBUG_MMU
33 33

  
34
static struct x86_def_t *x86_cpu_def;
35
typedef struct x86_def_t x86_def_t;
36
static int cpu_x86_register (CPUX86State *env, const x86_def_t *def);
34
static int cpu_x86_register (CPUX86State *env, const char *cpu_model);
37 35

  
38 36
static void add_flagname_to_bitmaps(char *flagname, uint32_t *features, 
39 37
                                    uint32_t *ext_features, 
......
92 90
    fprintf(stderr, "CPU feature %s not found\n", flagname);
93 91
}
94 92

  
95
CPUX86State *cpu_x86_init(void)
93
CPUX86State *cpu_x86_init(const char *cpu_model)
96 94
{
97 95
    CPUX86State *env;
98 96
    static int inited;
......
107 105
        inited = 1;
108 106
        optimize_flags_init();
109 107
    }
110
    cpu_x86_register(env, x86_cpu_def);
108
    if (cpu_x86_register(env, cpu_model) < 0) {
109
        cpu_x86_close(env);
110
        return NULL;
111
    }
111 112
    cpu_reset(env);
112 113
#ifdef USE_KQEMU
113 114
    kqemu_init(env);
......
115 116
    return env;
116 117
}
117 118

  
118
struct x86_def_t {
119
typedef struct x86_def_t {
119 120
    const char *name;
120 121
    uint32_t vendor1, vendor2, vendor3;
121 122
    int family;
......
123 124
    int stepping;
124 125
    uint32_t features, ext_features, ext2_features, ext3_features;
125 126
    uint32_t xlevel;
126
};
127
} x86_def_t;
127 128

  
128 129
#define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
129 130
          CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
......
194 195
    },
195 196
};
196 197

  
197
int x86_find_cpu_by_name(const unsigned char *cpu_model)
198
static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
198 199
{
199
    int ret;
200 200
    unsigned int i;
201
    x86_def_t *def;
201 202

  
202 203
    char *s = strdup(cpu_model);
203 204
    char *featurestr, *name = strtok(s, ",");
......
205 206
    uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0;
206 207
    int family = -1, model = -1, stepping = -1;
207 208

  
208
    ret = -1;
209
    x86_cpu_def = NULL;
209
    def = NULL;
210 210
    for (i = 0; i < sizeof(x86_defs) / sizeof(x86_def_t); i++) {
211 211
        if (strcmp(name, x86_defs[i].name) == 0) {
212
            x86_cpu_def = &x86_defs[i];
213
            ret = 0;
212
            def = &x86_defs[i];
214 213
            break;
215 214
        }
216 215
    }
217
    if (!x86_cpu_def)
216
    if (!def)
218 217
        goto error;
218
    memcpy(x86_cpu_def, def, sizeof(*def));
219 219

  
220 220
    featurestr = strtok(NULL, ",");
221 221

  
......
274 274
    x86_cpu_def->ext_features &= ~minus_ext_features;
275 275
    x86_cpu_def->ext2_features &= ~minus_ext2_features;
276 276
    x86_cpu_def->ext3_features &= ~minus_ext3_features;
277
    free(s);
278
    return 0;
277 279

  
278 280
error:
279 281
    free(s);
280
    return ret;
282
    return -1;
281 283
}
282 284

  
283 285
void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
......
288 290
        (*cpu_fprintf)(f, "x86 %16s\n", x86_defs[i].name);
289 291
}
290 292

  
291
int cpu_x86_register (CPUX86State *env, const x86_def_t *def)
293
static int cpu_x86_register (CPUX86State *env, const char *cpu_model)
292 294
{
295
    x86_def_t def1, *def = &def1;
296

  
297
    if (cpu_x86_find_by_name(def, cpu_model) < 0)
298
        return -1;
293 299
    if (def->vendor1) {
294 300
        env->cpuid_vendor1 = def->vendor1;
295 301
        env->cpuid_vendor2 = def->vendor2;

Also available in: Unified diff