]>
Commit | Line | Data |
---|---|---|
dd83b06a AF |
1 | /* |
2 | * QEMU CPU model | |
3 | * | |
4 | * Copyright (c) 2012 SUSE LINUX Products GmbH | |
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 |
28 | typedef struct CPUExistsArgs { |
29 | int64_t id; | |
30 | bool found; | |
31 | } CPUExistsArgs; | |
32 | ||
33 | static void cpu_exist_cb(CPUState *cpu, void *data) | |
34 | { | |
35 | CPUClass *klass = CPU_GET_CLASS(cpu); | |
36 | CPUExistsArgs *arg = data; | |
37 | ||
38 | if (klass->get_arch_id(cpu) == arg->id) { | |
39 | arg->found = true; | |
40 | } | |
41 | } | |
42 | ||
43 | bool cpu_exists(int64_t id) | |
44 | { | |
45 | CPUExistsArgs data = { | |
46 | .id = id, | |
47 | .found = false, | |
48 | }; | |
49 | ||
50 | qemu_for_each_cpu(cpu_exist_cb, &data); | |
51 | return data.found; | |
52 | } | |
53 | ||
444d5590 AF |
54 | bool cpu_paging_enabled(const CPUState *cpu) |
55 | { | |
56 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
57 | ||
58 | return cc->get_paging_enabled(cpu); | |
59 | } | |
60 | ||
61 | static bool cpu_common_get_paging_enabled(const CPUState *cpu) | |
62 | { | |
6db297ea | 63 | return false; |
444d5590 AF |
64 | } |
65 | ||
a23bbfda AF |
66 | void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, |
67 | Error **errp) | |
68 | { | |
69 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
70 | ||
71 | return cc->get_memory_mapping(cpu, list, errp); | |
72 | } | |
73 | ||
74 | static void cpu_common_get_memory_mapping(CPUState *cpu, | |
75 | MemoryMappingList *list, | |
76 | Error **errp) | |
77 | { | |
78 | error_setg(errp, "Obtaining memory mappings is unsupported on this CPU."); | |
79 | } | |
80 | ||
066e9b27 IM |
81 | /* CPU hot-plug notifiers */ |
82 | static NotifierList cpu_added_notifiers = | |
83 | NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); | |
84 | ||
85 | void qemu_register_cpu_added_notifier(Notifier *notifier) | |
86 | { | |
87 | notifier_list_add(&cpu_added_notifiers, notifier); | |
88 | } | |
dd83b06a | 89 | |
d8ed887b AF |
90 | void cpu_reset_interrupt(CPUState *cpu, int mask) |
91 | { | |
92 | cpu->interrupt_request &= ~mask; | |
93 | } | |
94 | ||
60a3e17a AF |
95 | void cpu_exit(CPUState *cpu) |
96 | { | |
97 | cpu->exit_request = 1; | |
98 | cpu->tcg_exit_req = 1; | |
99 | } | |
100 | ||
c72bf468 JF |
101 | int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, |
102 | void *opaque) | |
103 | { | |
104 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
105 | ||
106 | return (*cc->write_elf32_qemunote)(f, cpu, opaque); | |
107 | } | |
108 | ||
109 | static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f, | |
110 | CPUState *cpu, void *opaque) | |
111 | { | |
112 | return -1; | |
113 | } | |
114 | ||
115 | int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, | |
116 | int cpuid, void *opaque) | |
117 | { | |
118 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
119 | ||
120 | return (*cc->write_elf32_note)(f, cpu, cpuid, opaque); | |
121 | } | |
122 | ||
123 | static int cpu_common_write_elf32_note(WriteCoreDumpFunction f, | |
124 | CPUState *cpu, int cpuid, | |
125 | void *opaque) | |
126 | { | |
127 | return -1; | |
128 | } | |
129 | ||
130 | int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, | |
131 | void *opaque) | |
132 | { | |
133 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
134 | ||
135 | return (*cc->write_elf64_qemunote)(f, cpu, opaque); | |
136 | } | |
137 | ||
138 | static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f, | |
139 | CPUState *cpu, void *opaque) | |
140 | { | |
141 | return -1; | |
142 | } | |
143 | ||
144 | int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, | |
145 | int cpuid, void *opaque) | |
146 | { | |
147 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
148 | ||
149 | return (*cc->write_elf64_note)(f, cpu, cpuid, opaque); | |
150 | } | |
151 | ||
152 | static int cpu_common_write_elf64_note(WriteCoreDumpFunction f, | |
153 | CPUState *cpu, int cpuid, | |
154 | void *opaque) | |
155 | { | |
156 | return -1; | |
157 | } | |
158 | ||
159 | ||
878096ee AF |
160 | void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, |
161 | int flags) | |
162 | { | |
163 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
164 | ||
165 | if (cc->dump_state) { | |
166 | cc->dump_state(cpu, f, cpu_fprintf, flags); | |
167 | } | |
168 | } | |
169 | ||
170 | void 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 |
180 | void 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 | ||
189 | static 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 | ||
fcd7d003 | 198 | cpu->exit_request = 0; |
259186a7 | 199 | cpu->interrupt_request = 0; |
d77953b9 | 200 | cpu->current_tb = NULL; |
259186a7 | 201 | cpu->halted = 0; |
dd83b06a AF |
202 | } |
203 | ||
2b8c2754 AF |
204 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) |
205 | { | |
206 | CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); | |
207 | ||
208 | return cc->class_by_name(cpu_model); | |
209 | } | |
210 | ||
211 | static ObjectClass *cpu_common_class_by_name(const char *cpu_model) | |
212 | { | |
213 | return NULL; | |
214 | } | |
215 | ||
4f658099 AF |
216 | static void cpu_common_realizefn(DeviceState *dev, Error **errp) |
217 | { | |
13eed94e IM |
218 | CPUState *cpu = CPU(dev); |
219 | ||
c643bed9 AF |
220 | qemu_init_vcpu(cpu); |
221 | ||
13eed94e IM |
222 | if (dev->hotplugged) { |
223 | cpu_synchronize_post_init(cpu); | |
066e9b27 | 224 | notifier_list_notify(&cpu_added_notifiers, dev); |
6afb4721 | 225 | cpu_resume(cpu); |
13eed94e | 226 | } |
4f658099 AF |
227 | } |
228 | ||
997395d3 IM |
229 | static int64_t cpu_common_get_arch_id(CPUState *cpu) |
230 | { | |
231 | return cpu->cpu_index; | |
232 | } | |
233 | ||
dd83b06a AF |
234 | static void cpu_class_init(ObjectClass *klass, void *data) |
235 | { | |
961f8395 | 236 | DeviceClass *dc = DEVICE_CLASS(klass); |
dd83b06a AF |
237 | CPUClass *k = CPU_CLASS(klass); |
238 | ||
2b8c2754 | 239 | k->class_by_name = cpu_common_class_by_name; |
dd83b06a | 240 | k->reset = cpu_common_reset; |
997395d3 | 241 | k->get_arch_id = cpu_common_get_arch_id; |
444d5590 | 242 | k->get_paging_enabled = cpu_common_get_paging_enabled; |
a23bbfda | 243 | k->get_memory_mapping = cpu_common_get_memory_mapping; |
c72bf468 JF |
244 | k->write_elf32_qemunote = cpu_common_write_elf32_qemunote; |
245 | k->write_elf32_note = cpu_common_write_elf32_note; | |
246 | k->write_elf64_qemunote = cpu_common_write_elf64_qemunote; | |
247 | k->write_elf64_note = cpu_common_write_elf64_note; | |
4f658099 | 248 | dc->realize = cpu_common_realizefn; |
961f8395 | 249 | dc->no_user = 1; |
dd83b06a AF |
250 | } |
251 | ||
961f8395 | 252 | static const TypeInfo cpu_type_info = { |
dd83b06a | 253 | .name = TYPE_CPU, |
961f8395 | 254 | .parent = TYPE_DEVICE, |
dd83b06a AF |
255 | .instance_size = sizeof(CPUState), |
256 | .abstract = true, | |
257 | .class_size = sizeof(CPUClass), | |
258 | .class_init = cpu_class_init, | |
259 | }; | |
260 | ||
261 | static void cpu_register_types(void) | |
262 | { | |
263 | type_register_static(&cpu_type_info); | |
264 | } | |
265 | ||
266 | type_init(cpu_register_types) |