]> Git Repo - qemu.git/blame - qom/cpu.c
cpu: Implement CPUClass::parse_features() for the rest of CPUs
[qemu.git] / qom / cpu.c
CommitLineData
dd83b06a
AF
1/*
2 * QEMU CPU model
3 *
1590bbcb 4 * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
dd83b06a
AF
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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
14 * GNU 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
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
19 */
20
dd83b06a 21#include "qemu-common.h"
878096ee 22#include "qom/cpu.h"
13eed94e 23#include "sysemu/kvm.h"
066e9b27 24#include "qemu/notify.h"
91b1df8c 25#include "qemu/log.h"
066e9b27
IM
26#include "sysemu/sysemu.h"
27
69e5ff06
IM
28bool cpu_exists(int64_t id)
29{
38fcbd3f
AF
30 CPUState *cpu;
31
32 CPU_FOREACH(cpu) {
33 CPUClass *cc = CPU_GET_CLASS(cpu);
69e5ff06 34
38fcbd3f
AF
35 if (cc->get_arch_id(cpu) == id) {
36 return true;
37 }
38 }
39 return false;
69e5ff06
IM
40}
41
444d5590
AF
42bool cpu_paging_enabled(const CPUState *cpu)
43{
44 CPUClass *cc = CPU_GET_CLASS(cpu);
45
46 return cc->get_paging_enabled(cpu);
47}
48
49static bool cpu_common_get_paging_enabled(const CPUState *cpu)
50{
6db297ea 51 return false;
444d5590
AF
52}
53
a23bbfda
AF
54void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
55 Error **errp)
56{
57 CPUClass *cc = CPU_GET_CLASS(cpu);
58
59 return cc->get_memory_mapping(cpu, list, errp);
60}
61
62static void cpu_common_get_memory_mapping(CPUState *cpu,
63 MemoryMappingList *list,
64 Error **errp)
65{
66 error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
67}
68
066e9b27
IM
69/* CPU hot-plug notifiers */
70static NotifierList cpu_added_notifiers =
71 NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
72
73void qemu_register_cpu_added_notifier(Notifier *notifier)
74{
75 notifier_list_add(&cpu_added_notifiers, notifier);
76}
dd83b06a 77
d8ed887b
AF
78void cpu_reset_interrupt(CPUState *cpu, int mask)
79{
80 cpu->interrupt_request &= ~mask;
81}
82
60a3e17a
AF
83void cpu_exit(CPUState *cpu)
84{
85 cpu->exit_request = 1;
86 cpu->tcg_exit_req = 1;
87}
88
c72bf468
JF
89int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
90 void *opaque)
91{
92 CPUClass *cc = CPU_GET_CLASS(cpu);
93
94 return (*cc->write_elf32_qemunote)(f, cpu, opaque);
95}
96
97static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f,
98 CPUState *cpu, void *opaque)
99{
100 return -1;
101}
102
103int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
104 int cpuid, void *opaque)
105{
106 CPUClass *cc = CPU_GET_CLASS(cpu);
107
108 return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
109}
110
111static int cpu_common_write_elf32_note(WriteCoreDumpFunction f,
112 CPUState *cpu, int cpuid,
113 void *opaque)
114{
115 return -1;
116}
117
118int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
119 void *opaque)
120{
121 CPUClass *cc = CPU_GET_CLASS(cpu);
122
123 return (*cc->write_elf64_qemunote)(f, cpu, opaque);
124}
125
126static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f,
127 CPUState *cpu, void *opaque)
128{
129 return -1;
130}
131
132int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
133 int cpuid, void *opaque)
134{
135 CPUClass *cc = CPU_GET_CLASS(cpu);
136
137 return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
138}
139
140static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
141 CPUState *cpu, int cpuid,
142 void *opaque)
143{
144 return -1;
145}
146
147
5b50e790
AF
148static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg)
149{
150 return 0;
151}
152
153static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
154{
155 return 0;
156}
157
158
878096ee
AF
159void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
160 int flags)
161{
162 CPUClass *cc = CPU_GET_CLASS(cpu);
163
164 if (cc->dump_state) {
97577fd4 165 cpu_synchronize_state(cpu);
878096ee
AF
166 cc->dump_state(cpu, f, cpu_fprintf, flags);
167 }
168}
169
170void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
171 int flags)
172{
173 CPUClass *cc = CPU_GET_CLASS(cpu);
174
175 if (cc->dump_statistics) {
176 cc->dump_statistics(cpu, f, cpu_fprintf, flags);
177 }
178}
179
dd83b06a
AF
180void cpu_reset(CPUState *cpu)
181{
182 CPUClass *klass = CPU_GET_CLASS(cpu);
183
184 if (klass->reset != NULL) {
185 (*klass->reset)(cpu);
186 }
187}
188
189static void cpu_common_reset(CPUState *cpu)
190{
91b1df8c
AF
191 CPUClass *cc = CPU_GET_CLASS(cpu);
192
193 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
194 qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
195 log_cpu_state(cpu, cc->reset_dump_flags);
196 }
197
259186a7 198 cpu->interrupt_request = 0;
d77953b9 199 cpu->current_tb = NULL;
259186a7 200 cpu->halted = 0;
dd83b06a
AF
201}
202
8c2e1b00
AF
203static bool cpu_common_has_work(CPUState *cs)
204{
205 return false;
206}
207
2b8c2754
AF
208ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
209{
210 CPUClass *cc = CPU_CLASS(object_class_by_name(typename));
211
212 return cc->class_by_name(cpu_model);
213}
214
215static ObjectClass *cpu_common_class_by_name(const char *cpu_model)
216{
217 return NULL;
218}
219
1590bbcb
AF
220static void cpu_common_parse_features(CPUState *cpu, char *features,
221 Error **errp)
222{
223 char *featurestr; /* Single "key=value" string being parsed */
224 char *val;
225 Error *err = NULL;
226
227 featurestr = features ? strtok(features, ",") : NULL;
228
229 while (featurestr) {
230 val = strchr(featurestr, '=');
231 if (val) {
232 *val = 0;
233 val++;
234 object_property_parse(OBJECT(cpu), val, featurestr, &err);
235 if (err) {
236 error_propagate(errp, err);
237 return;
238 }
239 } else {
240 error_setg(errp, "Expected key=value format, found %s.",
241 featurestr);
242 return;
243 }
244 featurestr = strtok(NULL, ",");
245 }
246}
247
4f658099
AF
248static void cpu_common_realizefn(DeviceState *dev, Error **errp)
249{
13eed94e
IM
250 CPUState *cpu = CPU(dev);
251
252 if (dev->hotplugged) {
253 cpu_synchronize_post_init(cpu);
066e9b27 254 notifier_list_notify(&cpu_added_notifiers, dev);
6afb4721 255 cpu_resume(cpu);
13eed94e 256 }
4f658099
AF
257}
258
a0e372f0
AF
259static void cpu_common_initfn(Object *obj)
260{
261 CPUState *cpu = CPU(obj);
262 CPUClass *cc = CPU_GET_CLASS(obj);
263
35143f01 264 cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
a0e372f0
AF
265}
266
997395d3
IM
267static int64_t cpu_common_get_arch_id(CPUState *cpu)
268{
269 return cpu->cpu_index;
270}
271
dd83b06a
AF
272static void cpu_class_init(ObjectClass *klass, void *data)
273{
961f8395 274 DeviceClass *dc = DEVICE_CLASS(klass);
dd83b06a
AF
275 CPUClass *k = CPU_CLASS(klass);
276
2b8c2754 277 k->class_by_name = cpu_common_class_by_name;
1590bbcb 278 k->parse_features = cpu_common_parse_features;
dd83b06a 279 k->reset = cpu_common_reset;
997395d3 280 k->get_arch_id = cpu_common_get_arch_id;
8c2e1b00 281 k->has_work = cpu_common_has_work;
444d5590 282 k->get_paging_enabled = cpu_common_get_paging_enabled;
a23bbfda 283 k->get_memory_mapping = cpu_common_get_memory_mapping;
c72bf468
JF
284 k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
285 k->write_elf32_note = cpu_common_write_elf32_note;
286 k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
287 k->write_elf64_note = cpu_common_write_elf64_note;
5b50e790
AF
288 k->gdb_read_register = cpu_common_gdb_read_register;
289 k->gdb_write_register = cpu_common_gdb_write_register;
4f658099 290 dc->realize = cpu_common_realizefn;
ffa95714
MA
291 /*
292 * Reason: CPUs still need special care by board code: wiring up
293 * IRQs, adding reset handlers, halting non-first CPUs, ...
294 */
295 dc->cannot_instantiate_with_device_add_yet = true;
dd83b06a
AF
296}
297
961f8395 298static const TypeInfo cpu_type_info = {
dd83b06a 299 .name = TYPE_CPU,
961f8395 300 .parent = TYPE_DEVICE,
dd83b06a 301 .instance_size = sizeof(CPUState),
a0e372f0 302 .instance_init = cpu_common_initfn,
dd83b06a
AF
303 .abstract = true,
304 .class_size = sizeof(CPUClass),
305 .class_init = cpu_class_init,
306};
307
308static void cpu_register_types(void)
309{
310 type_register_static(&cpu_type_info);
311}
312
313type_init(cpu_register_types)
This page took 0.27755 seconds and 4 git commands to generate.