]> git.proxmox.com Git - mirror_qemu.git/blob - target-moxie/cpu.c
cpu: Change cpu_exec_init() arg to cpu, not env
[mirror_qemu.git] / target-moxie / cpu.c
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
25 static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
26 {
27 MoxieCPU *cpu = MOXIE_CPU(cs);
28
29 cpu->env.pc = value;
30 }
31
32 static bool moxie_cpu_has_work(CPUState *cs)
33 {
34 return cs->interrupt_request & CPU_INTERRUPT_HARD;
35 }
36
37 static void moxie_cpu_reset(CPUState *s)
38 {
39 MoxieCPU *cpu = MOXIE_CPU(s);
40 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
41 CPUMoxieState *env = &cpu->env;
42
43 mcc->parent_reset(s);
44
45 memset(env, 0, sizeof(CPUMoxieState));
46 env->pc = 0x1000;
47
48 tlb_flush(s, 1);
49 }
50
51 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
52 {
53 CPUState *cs = CPU(dev);
54 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
55
56 qemu_init_vcpu(cs);
57 cpu_reset(cs);
58
59 mcc->parent_realize(dev, errp);
60 }
61
62 static void moxie_cpu_initfn(Object *obj)
63 {
64 CPUState *cs = CPU(obj);
65 MoxieCPU *cpu = MOXIE_CPU(obj);
66 static int inited;
67
68 cs->env_ptr = &cpu->env;
69 cpu_exec_init(cs, &error_abort);
70
71 if (tcg_enabled() && !inited) {
72 inited = 1;
73 moxie_translate_init();
74 }
75 }
76
77 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
78 {
79 ObjectClass *oc;
80
81 if (cpu_model == NULL) {
82 return NULL;
83 }
84
85 oc = object_class_by_name(cpu_model);
86 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
87 object_class_is_abstract(oc))) {
88 return NULL;
89 }
90 return oc;
91 }
92
93 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
94 {
95 DeviceClass *dc = DEVICE_CLASS(oc);
96 CPUClass *cc = CPU_CLASS(oc);
97 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
98
99 mcc->parent_realize = dc->realize;
100 dc->realize = moxie_cpu_realizefn;
101
102 mcc->parent_reset = cc->reset;
103 cc->reset = moxie_cpu_reset;
104
105 cc->class_by_name = moxie_cpu_class_by_name;
106
107 cc->has_work = moxie_cpu_has_work;
108 cc->do_interrupt = moxie_cpu_do_interrupt;
109 cc->dump_state = moxie_cpu_dump_state;
110 cc->set_pc = moxie_cpu_set_pc;
111 #ifdef CONFIG_USER_ONLY
112 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
113 #else
114 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
115 cc->vmsd = &vmstate_moxie_cpu;
116 #endif
117 }
118
119 static void moxielite_initfn(Object *obj)
120 {
121 /* Set cpu feature flags */
122 }
123
124 static void moxie_any_initfn(Object *obj)
125 {
126 /* Set cpu feature flags */
127 }
128
129 typedef struct MoxieCPUInfo {
130 const char *name;
131 void (*initfn)(Object *obj);
132 } MoxieCPUInfo;
133
134 static const MoxieCPUInfo moxie_cpus[] = {
135 { .name = "MoxieLite", .initfn = moxielite_initfn },
136 { .name = "any", .initfn = moxie_any_initfn },
137 };
138
139 MoxieCPU *cpu_moxie_init(const char *cpu_model)
140 {
141 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
142 }
143
144 static 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
158 static 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
167 static 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
176 type_init(moxie_cpu_register_types)