Statistics
| Branch: | Revision:

root / target-alpha / cpu.c @ 5b50e790

History | View | Annotate | Download (7.8 kB)

1
/*
2
 * QEMU Alpha CPU
3
 *
4
 * Copyright (c) 2007 Jocelyn Mayer
5
 * Copyright (c) 2012 SUSE LINUX Products GmbH
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, see
19
 * <http://www.gnu.org/licenses/lgpl-2.1.html>
20
 */
21

    
22
#include "cpu.h"
23
#include "qemu-common.h"
24
#include "migration/vmstate.h"
25

    
26

    
27
static void alpha_cpu_set_pc(CPUState *cs, vaddr value)
28
{
29
    AlphaCPU *cpu = ALPHA_CPU(cs);
30

    
31
    cpu->env.pc = value;
32
}
33

    
34
static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
35
{
36
    AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
37

    
38
    acc->parent_realize(dev, errp);
39
}
40

    
41
/* Sort alphabetically by type name. */
42
static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
43
{
44
    ObjectClass *class_a = (ObjectClass *)a;
45
    ObjectClass *class_b = (ObjectClass *)b;
46
    const char *name_a, *name_b;
47

    
48
    name_a = object_class_get_name(class_a);
49
    name_b = object_class_get_name(class_b);
50
    return strcmp(name_a, name_b);
51
}
52

    
53
static void alpha_cpu_list_entry(gpointer data, gpointer user_data)
54
{
55
    ObjectClass *oc = data;
56
    CPUListState *s = user_data;
57

    
58
    (*s->cpu_fprintf)(s->file, "  %s\n",
59
                      object_class_get_name(oc));
60
}
61

    
62
void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
63
{
64
    CPUListState s = {
65
        .file = f,
66
        .cpu_fprintf = cpu_fprintf,
67
    };
68
    GSList *list;
69

    
70
    list = object_class_get_list(TYPE_ALPHA_CPU, false);
71
    list = g_slist_sort(list, alpha_cpu_list_compare);
72
    (*cpu_fprintf)(f, "Available CPUs:\n");
73
    g_slist_foreach(list, alpha_cpu_list_entry, &s);
74
    g_slist_free(list);
75
}
76

    
77
/* Models */
78

    
79
#define TYPE(model) model "-" TYPE_ALPHA_CPU
80

    
81
typedef struct AlphaCPUAlias {
82
    const char *alias;
83
    const char *typename;
84
} AlphaCPUAlias;
85

    
86
static const AlphaCPUAlias alpha_cpu_aliases[] = {
87
    { "21064",   TYPE("ev4") },
88
    { "21164",   TYPE("ev5") },
89
    { "21164a",  TYPE("ev56") },
90
    { "21164pc", TYPE("pca56") },
91
    { "21264",   TYPE("ev6") },
92
    { "21264a",  TYPE("ev67") },
93
};
94

    
95
static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
96
{
97
    ObjectClass *oc = NULL;
98
    char *typename;
99
    int i;
100

    
101
    if (cpu_model == NULL) {
102
        return NULL;
103
    }
104

    
105
    oc = object_class_by_name(cpu_model);
106
    if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL &&
107
        !object_class_is_abstract(oc)) {
108
        return oc;
109
    }
110

    
111
    for (i = 0; i < ARRAY_SIZE(alpha_cpu_aliases); i++) {
112
        if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) {
113
            oc = object_class_by_name(alpha_cpu_aliases[i].typename);
114
            assert(oc != NULL && !object_class_is_abstract(oc));
115
            return oc;
116
        }
117
    }
118

    
119
    typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
120
    oc = object_class_by_name(typename);
121
    g_free(typename);
122
    if (oc != NULL && object_class_is_abstract(oc)) {
123
        oc = NULL;
124
    }
125
    return oc;
126
}
127

    
128
AlphaCPU *cpu_alpha_init(const char *cpu_model)
129
{
130
    AlphaCPU *cpu;
131
    CPUAlphaState *env;
132
    ObjectClass *cpu_class;
133

    
134
    cpu_class = alpha_cpu_class_by_name(cpu_model);
135
    if (cpu_class == NULL) {
136
        /* Default to ev67; no reason not to emulate insns by default.  */
137
        cpu_class = object_class_by_name(TYPE("ev67"));
138
    }
139
    cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
140
    env = &cpu->env;
141

    
142
    env->cpu_model_str = cpu_model;
143

    
144
    object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
145

    
146
    return cpu;
147
}
148

    
149
static void ev4_cpu_initfn(Object *obj)
150
{
151
    AlphaCPU *cpu = ALPHA_CPU(obj);
152
    CPUAlphaState *env = &cpu->env;
153

    
154
    env->implver = IMPLVER_2106x;
155
}
156

    
157
static const TypeInfo ev4_cpu_type_info = {
158
    .name = TYPE("ev4"),
159
    .parent = TYPE_ALPHA_CPU,
160
    .instance_init = ev4_cpu_initfn,
161
};
162

    
163
static void ev5_cpu_initfn(Object *obj)
164
{
165
    AlphaCPU *cpu = ALPHA_CPU(obj);
166
    CPUAlphaState *env = &cpu->env;
167

    
168
    env->implver = IMPLVER_21164;
169
}
170

    
171
static const TypeInfo ev5_cpu_type_info = {
172
    .name = TYPE("ev5"),
173
    .parent = TYPE_ALPHA_CPU,
174
    .instance_init = ev5_cpu_initfn,
175
};
176

    
177
static void ev56_cpu_initfn(Object *obj)
178
{
179
    AlphaCPU *cpu = ALPHA_CPU(obj);
180
    CPUAlphaState *env = &cpu->env;
181

    
182
    env->amask |= AMASK_BWX;
183
}
184

    
185
static const TypeInfo ev56_cpu_type_info = {
186
    .name = TYPE("ev56"),
187
    .parent = TYPE("ev5"),
188
    .instance_init = ev56_cpu_initfn,
189
};
190

    
191
static void pca56_cpu_initfn(Object *obj)
192
{
193
    AlphaCPU *cpu = ALPHA_CPU(obj);
194
    CPUAlphaState *env = &cpu->env;
195

    
196
    env->amask |= AMASK_MVI;
197
}
198

    
199
static const TypeInfo pca56_cpu_type_info = {
200
    .name = TYPE("pca56"),
201
    .parent = TYPE("ev56"),
202
    .instance_init = pca56_cpu_initfn,
203
};
204

    
205
static void ev6_cpu_initfn(Object *obj)
206
{
207
    AlphaCPU *cpu = ALPHA_CPU(obj);
208
    CPUAlphaState *env = &cpu->env;
209

    
210
    env->implver = IMPLVER_21264;
211
    env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
212
}
213

    
214
static const TypeInfo ev6_cpu_type_info = {
215
    .name = TYPE("ev6"),
216
    .parent = TYPE_ALPHA_CPU,
217
    .instance_init = ev6_cpu_initfn,
218
};
219

    
220
static void ev67_cpu_initfn(Object *obj)
221
{
222
    AlphaCPU *cpu = ALPHA_CPU(obj);
223
    CPUAlphaState *env = &cpu->env;
224

    
225
    env->amask |= AMASK_CIX | AMASK_PREFETCH;
226
}
227

    
228
static const TypeInfo ev67_cpu_type_info = {
229
    .name = TYPE("ev67"),
230
    .parent = TYPE("ev6"),
231
    .instance_init = ev67_cpu_initfn,
232
};
233

    
234
static const TypeInfo ev68_cpu_type_info = {
235
    .name = TYPE("ev68"),
236
    .parent = TYPE("ev67"),
237
};
238

    
239
static void alpha_cpu_initfn(Object *obj)
240
{
241
    CPUState *cs = CPU(obj);
242
    AlphaCPU *cpu = ALPHA_CPU(obj);
243
    CPUAlphaState *env = &cpu->env;
244

    
245
    cs->env_ptr = env;
246
    cpu_exec_init(env);
247
    tlb_flush(env, 1);
248

    
249
    alpha_translate_init();
250

    
251
#if defined(CONFIG_USER_ONLY)
252
    env->ps = PS_USER_MODE;
253
    cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
254
                               | FPCR_UNFD | FPCR_INED | FPCR_DNOD
255
                               | FPCR_DYN_NORMAL));
256
#endif
257
    env->lock_addr = -1;
258
    env->fen = 1;
259
}
260

    
261
static void alpha_cpu_class_init(ObjectClass *oc, void *data)
262
{
263
    DeviceClass *dc = DEVICE_CLASS(oc);
264
    CPUClass *cc = CPU_CLASS(oc);
265
    AlphaCPUClass *acc = ALPHA_CPU_CLASS(oc);
266

    
267
    acc->parent_realize = dc->realize;
268
    dc->realize = alpha_cpu_realizefn;
269

    
270
    cc->class_by_name = alpha_cpu_class_by_name;
271
    cc->do_interrupt = alpha_cpu_do_interrupt;
272
    cc->dump_state = alpha_cpu_dump_state;
273
    cc->set_pc = alpha_cpu_set_pc;
274
    cc->gdb_read_register = alpha_cpu_gdb_read_register;
275
    cc->gdb_write_register = alpha_cpu_gdb_write_register;
276
#ifndef CONFIG_USER_ONLY
277
    cc->do_unassigned_access = alpha_cpu_unassigned_access;
278
    cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
279
    dc->vmsd = &vmstate_alpha_cpu;
280
#endif
281
    cc->gdb_num_core_regs = 67;
282
}
283

    
284
static const TypeInfo alpha_cpu_type_info = {
285
    .name = TYPE_ALPHA_CPU,
286
    .parent = TYPE_CPU,
287
    .instance_size = sizeof(AlphaCPU),
288
    .instance_init = alpha_cpu_initfn,
289
    .abstract = true,
290
    .class_size = sizeof(AlphaCPUClass),
291
    .class_init = alpha_cpu_class_init,
292
};
293

    
294
static void alpha_cpu_register_types(void)
295
{
296
    type_register_static(&alpha_cpu_type_info);
297
    type_register_static(&ev4_cpu_type_info);
298
    type_register_static(&ev5_cpu_type_info);
299
    type_register_static(&ev56_cpu_type_info);
300
    type_register_static(&pca56_cpu_type_info);
301
    type_register_static(&ev6_cpu_type_info);
302
    type_register_static(&ev67_cpu_type_info);
303
    type_register_static(&ev68_cpu_type_info);
304
}
305

    
306
type_init(alpha_cpu_register_types)