]> Git Repo - qemu.git/blame - target-moxie/cpu.c
cpu: Introduce CPUClass::synchronize_from_tb() for cpu_pc_from_tb()
[qemu.git] / target-moxie / cpu.c
CommitLineData
525bd324
AG
1/*
2 * QEMU Moxie CPU
3 *
4 * Copyright (c) 2013 Anthony Green
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "cpu.h"
21#include "qemu-common.h"
22#include "migration/vmstate.h"
23#include "machine.h"
24
a10b978c
AF
25static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
26{
27 MoxieCPU *cpu = MOXIE_CPU(cs);
28
29 cpu->env.pc = value;
30}
31
525bd324
AG
32static void moxie_cpu_reset(CPUState *s)
33{
34 MoxieCPU *cpu = MOXIE_CPU(s);
35 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
36 CPUMoxieState *env = &cpu->env;
37
525bd324
AG
38 mcc->parent_reset(s);
39
40 memset(env, 0, offsetof(CPUMoxieState, breakpoints));
41 env->pc = 0x1000;
42
43 tlb_flush(env, 1);
44}
45
46static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
47{
48 MoxieCPU *cpu = MOXIE_CPU(dev);
c643bed9 49 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
525bd324 50
525bd324
AG
51 cpu_reset(CPU(cpu));
52
c643bed9 53 mcc->parent_realize(dev, errp);
525bd324
AG
54}
55
56static void moxie_cpu_initfn(Object *obj)
57{
58 CPUState *cs = CPU(obj);
59 MoxieCPU *cpu = MOXIE_CPU(obj);
60 static int inited;
61
62 cs->env_ptr = &cpu->env;
63 cpu_exec_init(&cpu->env);
64
65 if (tcg_enabled() && !inited) {
66 inited = 1;
67 moxie_translate_init();
68 }
69}
70
71static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
72{
73 ObjectClass *oc;
74
75 if (cpu_model == NULL) {
76 return NULL;
77 }
78
79 oc = object_class_by_name(cpu_model);
80 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
81 object_class_is_abstract(oc))) {
82 return NULL;
83 }
84 return oc;
85}
86
87static void moxie_cpu_class_init(ObjectClass *oc, void *data)
88{
89 DeviceClass *dc = DEVICE_CLASS(oc);
90 CPUClass *cc = CPU_CLASS(oc);
91 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
92
93 mcc->parent_realize = dc->realize;
94 dc->realize = moxie_cpu_realizefn;
95
96 mcc->parent_reset = cc->reset;
97 cc->reset = moxie_cpu_reset;
98
99 cc->class_by_name = moxie_cpu_class_by_name;
100
53574064 101 cc->do_interrupt = moxie_cpu_do_interrupt;
878096ee 102 cc->dump_state = moxie_cpu_dump_state;
a10b978c 103 cc->set_pc = moxie_cpu_set_pc;
878096ee 104 cpu_class_set_vmsd(cc, &vmstate_moxie_cpu);
525bd324
AG
105}
106
107static void moxielite_initfn(Object *obj)
108{
109 /* Set cpu feature flags */
110}
111
112static void moxie_any_initfn(Object *obj)
113{
114 /* Set cpu feature flags */
115}
116
117typedef struct MoxieCPUInfo {
118 const char *name;
119 void (*initfn)(Object *obj);
120} MoxieCPUInfo;
121
122static const MoxieCPUInfo moxie_cpus[] = {
123 { .name = "MoxieLite", .initfn = moxielite_initfn },
124 { .name = "any", .initfn = moxie_any_initfn },
125};
126
127MoxieCPU *cpu_moxie_init(const char *cpu_model)
128{
129 MoxieCPU *cpu;
130 ObjectClass *oc;
131
132 oc = moxie_cpu_class_by_name(cpu_model);
133 if (oc == NULL) {
134 return NULL;
135 }
136 cpu = MOXIE_CPU(object_new(object_class_get_name(oc)));
137 cpu->env.cpu_model_str = cpu_model;
138
139 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
140
141 return cpu;
142}
143
144static void cpu_register(const MoxieCPUInfo *info)
145{
146 TypeInfo type_info = {
147 .parent = TYPE_MOXIE_CPU,
148 .instance_size = sizeof(MoxieCPU),
149 .instance_init = info->initfn,
150 .class_size = sizeof(MoxieCPUClass),
151 };
152
153 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
154 type_register(&type_info);
155 g_free((void *)type_info.name);
156}
157
158static const TypeInfo moxie_cpu_type_info = {
159 .name = TYPE_MOXIE_CPU,
160 .parent = TYPE_CPU,
161 .instance_size = sizeof(MoxieCPU),
162 .instance_init = moxie_cpu_initfn,
163 .class_size = sizeof(MoxieCPUClass),
164 .class_init = moxie_cpu_class_init,
165};
166
167static void moxie_cpu_register_types(void)
168{
169 int i;
170 type_register_static(&moxie_cpu_type_info);
171 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
172 cpu_register(&moxie_cpus[i]);
173 }
174}
175
176type_init(moxie_cpu_register_types)
This page took 0.108225 seconds and 4 git commands to generate.