]>
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 | #ifndef QEMU_CPU_H | |
21 | #define QEMU_CPU_H | |
22 | ||
fcd7d003 | 23 | #include <signal.h> |
6f03bef0 | 24 | #include <setjmp.h> |
961f8395 | 25 | #include "hw/qdev-core.h" |
c658b94f | 26 | #include "exec/hwaddr.h" |
bdc44640 | 27 | #include "qemu/queue.h" |
1de7afc9 | 28 | #include "qemu/thread.h" |
4917cf44 | 29 | #include "qemu/tls.h" |
a23bbfda | 30 | #include "qemu/typedefs.h" |
dd83b06a | 31 | |
b5ba1cc6 QN |
32 | typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, |
33 | void *opaque); | |
c72bf468 | 34 | |
577f42c0 AF |
35 | /** |
36 | * vaddr: | |
37 | * Type wide enough to contain any #target_ulong virtual address. | |
38 | */ | |
39 | typedef uint64_t vaddr; | |
40 | #define VADDR_PRId PRId64 | |
41 | #define VADDR_PRIu PRIu64 | |
42 | #define VADDR_PRIo PRIo64 | |
43 | #define VADDR_PRIx PRIx64 | |
44 | #define VADDR_PRIX PRIX64 | |
45 | #define VADDR_MAX UINT64_MAX | |
46 | ||
dd83b06a AF |
47 | /** |
48 | * SECTION:cpu | |
49 | * @section_id: QEMU-cpu | |
50 | * @title: CPU Class | |
51 | * @short_description: Base class for all CPUs | |
52 | */ | |
53 | ||
54 | #define TYPE_CPU "cpu" | |
55 | ||
56 | #define CPU(obj) OBJECT_CHECK(CPUState, (obj), TYPE_CPU) | |
57 | #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU) | |
58 | #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU) | |
59 | ||
60 | typedef struct CPUState CPUState; | |
61 | ||
c658b94f AF |
62 | typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr, |
63 | bool is_write, bool is_exec, int opaque, | |
64 | unsigned size); | |
65 | ||
bdf7ae5b AF |
66 | struct TranslationBlock; |
67 | ||
dd83b06a AF |
68 | /** |
69 | * CPUClass: | |
2b8c2754 AF |
70 | * @class_by_name: Callback to map -cpu command line model name to an |
71 | * instantiatable CPU type. | |
94a444b2 | 72 | * @parse_features: Callback to parse command line arguments. |
f5df5baf | 73 | * @reset: Callback to reset the #CPUState to its initial state. |
91b1df8c | 74 | * @reset_dump_flags: #CPUDumpFlags to use for reset logging. |
8c2e1b00 | 75 | * @has_work: Callback for checking if there is work to do. |
97a8ea5a | 76 | * @do_interrupt: Callback for interrupt handling. |
c658b94f | 77 | * @do_unassigned_access: Callback for unassigned access handling. |
f3659eee | 78 | * @memory_rw_debug: Callback for GDB memory access. |
878096ee AF |
79 | * @dump_state: Callback for dumping state. |
80 | * @dump_statistics: Callback for dumping statistics. | |
997395d3 | 81 | * @get_arch_id: Callback for getting architecture-dependent CPU ID. |
444d5590 | 82 | * @get_paging_enabled: Callback for inquiring whether paging is enabled. |
a23bbfda | 83 | * @get_memory_mapping: Callback for obtaining the memory mappings. |
f45748f1 | 84 | * @set_pc: Callback for setting the Program Counter register. |
bdf7ae5b AF |
85 | * @synchronize_from_tb: Callback for synchronizing state from a TCG |
86 | * #TranslationBlock. | |
7510454e | 87 | * @handle_mmu_fault: Callback for handling an MMU fault. |
00b941e5 | 88 | * @get_phys_page_debug: Callback for obtaining a physical address. |
5b50e790 AF |
89 | * @gdb_read_register: Callback for letting GDB read a register. |
90 | * @gdb_write_register: Callback for letting GDB write a register. | |
b170fce3 | 91 | * @vmsd: State description for migration. |
a0e372f0 | 92 | * @gdb_num_core_regs: Number of core registers accessible to GDB. |
5b24c641 | 93 | * @gdb_core_xml_file: File name for core registers GDB XML description. |
dd83b06a AF |
94 | * |
95 | * Represents a CPU family or model. | |
96 | */ | |
97 | typedef struct CPUClass { | |
98 | /*< private >*/ | |
961f8395 | 99 | DeviceClass parent_class; |
dd83b06a AF |
100 | /*< public >*/ |
101 | ||
2b8c2754 | 102 | ObjectClass *(*class_by_name)(const char *cpu_model); |
94a444b2 | 103 | void (*parse_features)(CPUState *cpu, char *str, Error **errp); |
2b8c2754 | 104 | |
dd83b06a | 105 | void (*reset)(CPUState *cpu); |
91b1df8c | 106 | int reset_dump_flags; |
8c2e1b00 | 107 | bool (*has_work)(CPUState *cpu); |
97a8ea5a | 108 | void (*do_interrupt)(CPUState *cpu); |
c658b94f | 109 | CPUUnassignedAccess do_unassigned_access; |
f3659eee AF |
110 | int (*memory_rw_debug)(CPUState *cpu, vaddr addr, |
111 | uint8_t *buf, int len, bool is_write); | |
878096ee AF |
112 | void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, |
113 | int flags); | |
114 | void (*dump_statistics)(CPUState *cpu, FILE *f, | |
115 | fprintf_function cpu_fprintf, int flags); | |
997395d3 | 116 | int64_t (*get_arch_id)(CPUState *cpu); |
444d5590 | 117 | bool (*get_paging_enabled)(const CPUState *cpu); |
a23bbfda AF |
118 | void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list, |
119 | Error **errp); | |
f45748f1 | 120 | void (*set_pc)(CPUState *cpu, vaddr value); |
bdf7ae5b | 121 | void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb); |
7510454e AF |
122 | int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int rw, |
123 | int mmu_index); | |
00b941e5 | 124 | hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr); |
5b50e790 AF |
125 | int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg); |
126 | int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); | |
b170fce3 | 127 | |
c72bf468 JF |
128 | int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, |
129 | int cpuid, void *opaque); | |
130 | int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, | |
131 | void *opaque); | |
132 | int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu, | |
133 | int cpuid, void *opaque); | |
134 | int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, | |
135 | void *opaque); | |
a0e372f0 AF |
136 | |
137 | const struct VMStateDescription *vmsd; | |
138 | int gdb_num_core_regs; | |
5b24c641 | 139 | const char *gdb_core_xml_file; |
dd83b06a AF |
140 | } CPUClass; |
141 | ||
28ecfd7a AF |
142 | #ifdef HOST_WORDS_BIGENDIAN |
143 | typedef struct icount_decr_u16 { | |
144 | uint16_t high; | |
145 | uint16_t low; | |
146 | } icount_decr_u16; | |
147 | #else | |
148 | typedef struct icount_decr_u16 { | |
149 | uint16_t low; | |
150 | uint16_t high; | |
151 | } icount_decr_u16; | |
152 | #endif | |
153 | ||
ff4700b0 AF |
154 | typedef struct CPUWatchpoint { |
155 | vaddr vaddr; | |
156 | vaddr len_mask; | |
157 | int flags; /* BP_* */ | |
158 | QTAILQ_ENTRY(CPUWatchpoint) entry; | |
159 | } CPUWatchpoint; | |
160 | ||
a60f24b5 | 161 | struct KVMState; |
f7575c96 | 162 | struct kvm_run; |
a60f24b5 | 163 | |
8cd70437 AF |
164 | #define TB_JMP_CACHE_BITS 12 |
165 | #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) | |
166 | ||
dd83b06a AF |
167 | /** |
168 | * CPUState: | |
55e5c285 | 169 | * @cpu_index: CPU index (informative). |
ce3960eb AF |
170 | * @nr_cores: Number of cores within this CPU package. |
171 | * @nr_threads: Number of threads within this CPU. | |
1b1ed8dc | 172 | * @numa_node: NUMA node this CPU is belonging to. |
0d34282f | 173 | * @host_tid: Host thread ID. |
0315c31c | 174 | * @running: #true if CPU is currently running (usermode). |
61a46217 | 175 | * @created: Indicates whether the CPU thread has been successfully created. |
259186a7 AF |
176 | * @interrupt_request: Indicates a pending interrupt request. |
177 | * @halted: Nonzero if the CPU is in suspended state. | |
4fdeee7c | 178 | * @stop: Indicates a pending stop request. |
f324e766 | 179 | * @stopped: Indicates the CPU has been artificially stopped. |
378df4b2 PM |
180 | * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this |
181 | * CPU and return to its top level loop. | |
ed2803da | 182 | * @singlestep_enabled: Flags for single-stepping. |
efee7340 | 183 | * @icount_extra: Instructions until next timer event. |
28ecfd7a AF |
184 | * @icount_decr: Number of cycles left, with interrupt flag in high bit. |
185 | * This allows a single read-compare-cbranch-write sequence to test | |
186 | * for both decrementer underflow and exceptions. | |
99df7dce | 187 | * @can_do_io: Nonzero if memory-mapped IO is safe. |
c05efcb1 | 188 | * @env_ptr: Pointer to subclass-specific CPUArchState field. |
d77953b9 | 189 | * @current_tb: Currently executing TB. |
eac8b355 | 190 | * @gdb_regs: Additional GDB registers. |
a0e372f0 | 191 | * @gdb_num_regs: Number of total registers accessible to GDB. |
35143f01 | 192 | * @gdb_num_g_regs: Number of registers in GDB 'g' packets. |
182735ef | 193 | * @next_cpu: Next CPU sharing TB cache. |
0429a971 | 194 | * @opaque: User data. |
93afeade AF |
195 | * @mem_io_pc: Host Program Counter at which the memory was accessed. |
196 | * @mem_io_vaddr: Target virtual address at which the memory was accessed. | |
8737c51c | 197 | * @kvm_fd: vCPU file descriptor for KVM. |
dd83b06a AF |
198 | * |
199 | * State of one CPU core or thread. | |
200 | */ | |
201 | struct CPUState { | |
202 | /*< private >*/ | |
961f8395 | 203 | DeviceState parent_obj; |
dd83b06a AF |
204 | /*< public >*/ |
205 | ||
ce3960eb AF |
206 | int nr_cores; |
207 | int nr_threads; | |
1b1ed8dc | 208 | int numa_node; |
ce3960eb | 209 | |
814e612e | 210 | struct QemuThread *thread; |
bcba2a72 AF |
211 | #ifdef _WIN32 |
212 | HANDLE hThread; | |
213 | #endif | |
9f09e18a | 214 | int thread_id; |
0d34282f | 215 | uint32_t host_tid; |
0315c31c | 216 | bool running; |
f5c121b8 | 217 | struct QemuCond *halt_cond; |
c64ca814 | 218 | struct qemu_work_item *queued_work_first, *queued_work_last; |
216fc9a4 | 219 | bool thread_kicked; |
61a46217 | 220 | bool created; |
4fdeee7c | 221 | bool stop; |
f324e766 | 222 | bool stopped; |
fcd7d003 | 223 | volatile sig_atomic_t exit_request; |
378df4b2 | 224 | volatile sig_atomic_t tcg_exit_req; |
259186a7 | 225 | uint32_t interrupt_request; |
ed2803da | 226 | int singlestep_enabled; |
efee7340 | 227 | int64_t icount_extra; |
6f03bef0 | 228 | sigjmp_buf jmp_env; |
bcba2a72 | 229 | |
09daed84 EI |
230 | AddressSpace *as; |
231 | MemoryListener *tcg_as_listener; | |
232 | ||
c05efcb1 | 233 | void *env_ptr; /* CPUArchState */ |
d77953b9 | 234 | struct TranslationBlock *current_tb; |
8cd70437 | 235 | struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; |
eac8b355 | 236 | struct GDBRegisterState *gdb_regs; |
a0e372f0 | 237 | int gdb_num_regs; |
35143f01 | 238 | int gdb_num_g_regs; |
bdc44640 | 239 | QTAILQ_ENTRY(CPUState) node; |
d77953b9 | 240 | |
ff4700b0 AF |
241 | QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; |
242 | CPUWatchpoint *watchpoint_hit; | |
243 | ||
0429a971 AF |
244 | void *opaque; |
245 | ||
93afeade AF |
246 | /* In order to avoid passing too many arguments to the MMIO helpers, |
247 | * we store some rarely used information in the CPU context. | |
248 | */ | |
249 | uintptr_t mem_io_pc; | |
250 | vaddr mem_io_vaddr; | |
251 | ||
8737c51c | 252 | int kvm_fd; |
20d695a9 | 253 | bool kvm_vcpu_dirty; |
a60f24b5 | 254 | struct KVMState *kvm_state; |
f7575c96 | 255 | struct kvm_run *kvm_run; |
8737c51c | 256 | |
f5df5baf | 257 | /* TODO Move common fields from CPUArchState here. */ |
55e5c285 | 258 | int cpu_index; /* used by alpha TCG */ |
259186a7 | 259 | uint32_t halted; /* used by alpha, cris, ppc TCG */ |
28ecfd7a AF |
260 | union { |
261 | uint32_t u32; | |
262 | icount_decr_u16 u16; | |
263 | } icount_decr; | |
99df7dce | 264 | uint32_t can_do_io; |
27103424 | 265 | int32_t exception_index; /* used by m68k TCG */ |
dd83b06a AF |
266 | }; |
267 | ||
bdc44640 AF |
268 | QTAILQ_HEAD(CPUTailQ, CPUState); |
269 | extern struct CPUTailQ cpus; | |
270 | #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node) | |
271 | #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node) | |
272 | #define CPU_FOREACH_SAFE(cpu, next_cpu) \ | |
273 | QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu) | |
274 | #define first_cpu QTAILQ_FIRST(&cpus) | |
182735ef | 275 | |
4917cf44 AF |
276 | DECLARE_TLS(CPUState *, current_cpu); |
277 | #define current_cpu tls_var(current_cpu) | |
278 | ||
444d5590 AF |
279 | /** |
280 | * cpu_paging_enabled: | |
281 | * @cpu: The CPU whose state is to be inspected. | |
282 | * | |
283 | * Returns: %true if paging is enabled, %false otherwise. | |
284 | */ | |
285 | bool cpu_paging_enabled(const CPUState *cpu); | |
286 | ||
a23bbfda AF |
287 | /** |
288 | * cpu_get_memory_mapping: | |
289 | * @cpu: The CPU whose memory mappings are to be obtained. | |
290 | * @list: Where to write the memory mappings to. | |
291 | * @errp: Pointer for reporting an #Error. | |
292 | */ | |
293 | void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, | |
294 | Error **errp); | |
295 | ||
c72bf468 JF |
296 | /** |
297 | * cpu_write_elf64_note: | |
298 | * @f: pointer to a function that writes memory to a file | |
299 | * @cpu: The CPU whose memory is to be dumped | |
300 | * @cpuid: ID number of the CPU | |
301 | * @opaque: pointer to the CPUState struct | |
302 | */ | |
303 | int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, | |
304 | int cpuid, void *opaque); | |
305 | ||
306 | /** | |
307 | * cpu_write_elf64_qemunote: | |
308 | * @f: pointer to a function that writes memory to a file | |
309 | * @cpu: The CPU whose memory is to be dumped | |
310 | * @cpuid: ID number of the CPU | |
311 | * @opaque: pointer to the CPUState struct | |
312 | */ | |
313 | int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, | |
314 | void *opaque); | |
315 | ||
316 | /** | |
317 | * cpu_write_elf32_note: | |
318 | * @f: pointer to a function that writes memory to a file | |
319 | * @cpu: The CPU whose memory is to be dumped | |
320 | * @cpuid: ID number of the CPU | |
321 | * @opaque: pointer to the CPUState struct | |
322 | */ | |
323 | int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, | |
324 | int cpuid, void *opaque); | |
325 | ||
326 | /** | |
327 | * cpu_write_elf32_qemunote: | |
328 | * @f: pointer to a function that writes memory to a file | |
329 | * @cpu: The CPU whose memory is to be dumped | |
330 | * @cpuid: ID number of the CPU | |
331 | * @opaque: pointer to the CPUState struct | |
332 | */ | |
333 | int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, | |
334 | void *opaque); | |
dd83b06a | 335 | |
878096ee AF |
336 | /** |
337 | * CPUDumpFlags: | |
338 | * @CPU_DUMP_CODE: | |
339 | * @CPU_DUMP_FPU: dump FPU register state, not just integer | |
340 | * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state | |
341 | */ | |
342 | enum CPUDumpFlags { | |
343 | CPU_DUMP_CODE = 0x00010000, | |
344 | CPU_DUMP_FPU = 0x00020000, | |
345 | CPU_DUMP_CCOP = 0x00040000, | |
346 | }; | |
347 | ||
348 | /** | |
349 | * cpu_dump_state: | |
350 | * @cpu: The CPU whose state is to be dumped. | |
351 | * @f: File to dump to. | |
352 | * @cpu_fprintf: Function to dump with. | |
353 | * @flags: Flags what to dump. | |
354 | * | |
355 | * Dumps CPU state. | |
356 | */ | |
357 | void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, | |
358 | int flags); | |
359 | ||
360 | /** | |
361 | * cpu_dump_statistics: | |
362 | * @cpu: The CPU whose state is to be dumped. | |
363 | * @f: File to dump to. | |
364 | * @cpu_fprintf: Function to dump with. | |
365 | * @flags: Flags what to dump. | |
366 | * | |
367 | * Dumps CPU statistics. | |
368 | */ | |
369 | void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, | |
370 | int flags); | |
371 | ||
00b941e5 AF |
372 | #ifndef CONFIG_USER_ONLY |
373 | /** | |
374 | * cpu_get_phys_page_debug: | |
375 | * @cpu: The CPU to obtain the physical page address for. | |
376 | * @addr: The virtual address. | |
377 | * | |
378 | * Obtains the physical page corresponding to a virtual one. | |
379 | * Use it only for debugging because no protection checks are done. | |
380 | * | |
381 | * Returns: Corresponding physical page address or -1 if no page found. | |
382 | */ | |
383 | static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) | |
384 | { | |
385 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
386 | ||
387 | return cc->get_phys_page_debug(cpu, addr); | |
388 | } | |
389 | #endif | |
390 | ||
dd83b06a AF |
391 | /** |
392 | * cpu_reset: | |
393 | * @cpu: The CPU whose state is to be reset. | |
394 | */ | |
395 | void cpu_reset(CPUState *cpu); | |
396 | ||
2b8c2754 AF |
397 | /** |
398 | * cpu_class_by_name: | |
399 | * @typename: The CPU base type. | |
400 | * @cpu_model: The model string without any parameters. | |
401 | * | |
402 | * Looks up a CPU #ObjectClass matching name @cpu_model. | |
403 | * | |
404 | * Returns: A #CPUClass or %NULL if not matching class is found. | |
405 | */ | |
406 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); | |
407 | ||
9262685b AF |
408 | /** |
409 | * cpu_generic_init: | |
410 | * @typename: The CPU base type. | |
411 | * @cpu_model: The model string including optional parameters. | |
412 | * | |
413 | * Instantiates a CPU, processes optional parameters and realizes the CPU. | |
414 | * | |
415 | * Returns: A #CPUState or %NULL if an error occurred. | |
416 | */ | |
417 | CPUState *cpu_generic_init(const char *typename, const char *cpu_model); | |
418 | ||
3993c6bd | 419 | /** |
8c2e1b00 | 420 | * cpu_has_work: |
3993c6bd AF |
421 | * @cpu: The vCPU to check. |
422 | * | |
423 | * Checks whether the CPU has work to do. | |
424 | * | |
425 | * Returns: %true if the CPU has work, %false otherwise. | |
426 | */ | |
8c2e1b00 AF |
427 | static inline bool cpu_has_work(CPUState *cpu) |
428 | { | |
429 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
430 | ||
431 | g_assert(cc->has_work); | |
432 | return cc->has_work(cpu); | |
433 | } | |
3993c6bd | 434 | |
60e82579 AF |
435 | /** |
436 | * qemu_cpu_is_self: | |
437 | * @cpu: The vCPU to check against. | |
438 | * | |
439 | * Checks whether the caller is executing on the vCPU thread. | |
440 | * | |
441 | * Returns: %true if called from @cpu's thread, %false otherwise. | |
442 | */ | |
443 | bool qemu_cpu_is_self(CPUState *cpu); | |
444 | ||
c08d7424 AF |
445 | /** |
446 | * qemu_cpu_kick: | |
447 | * @cpu: The vCPU to kick. | |
448 | * | |
449 | * Kicks @cpu's thread. | |
450 | */ | |
451 | void qemu_cpu_kick(CPUState *cpu); | |
452 | ||
2fa45344 AF |
453 | /** |
454 | * cpu_is_stopped: | |
455 | * @cpu: The CPU to check. | |
456 | * | |
457 | * Checks whether the CPU is stopped. | |
458 | * | |
459 | * Returns: %true if run state is not running or if artificially stopped; | |
460 | * %false otherwise. | |
461 | */ | |
462 | bool cpu_is_stopped(CPUState *cpu); | |
463 | ||
f100f0b3 AF |
464 | /** |
465 | * run_on_cpu: | |
466 | * @cpu: The vCPU to run on. | |
467 | * @func: The function to be executed. | |
468 | * @data: Data to pass to the function. | |
469 | * | |
470 | * Schedules the function @func for execution on the vCPU @cpu. | |
471 | */ | |
472 | void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); | |
473 | ||
3c02270d CV |
474 | /** |
475 | * async_run_on_cpu: | |
476 | * @cpu: The vCPU to run on. | |
477 | * @func: The function to be executed. | |
478 | * @data: Data to pass to the function. | |
479 | * | |
480 | * Schedules the function @func for execution on the vCPU @cpu asynchronously. | |
481 | */ | |
482 | void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); | |
483 | ||
38d8f5c8 AF |
484 | /** |
485 | * qemu_get_cpu: | |
486 | * @index: The CPUState@cpu_index value of the CPU to obtain. | |
487 | * | |
488 | * Gets a CPU matching @index. | |
489 | * | |
490 | * Returns: The CPU or %NULL if there is no matching CPU. | |
491 | */ | |
492 | CPUState *qemu_get_cpu(int index); | |
493 | ||
69e5ff06 IM |
494 | /** |
495 | * cpu_exists: | |
496 | * @id: Guest-exposed CPU ID to lookup. | |
497 | * | |
498 | * Search for CPU with specified ID. | |
499 | * | |
500 | * Returns: %true - CPU is found, %false - CPU isn't found. | |
501 | */ | |
502 | bool cpu_exists(int64_t id); | |
503 | ||
c3affe56 AF |
504 | #ifndef CONFIG_USER_ONLY |
505 | ||
506 | typedef void (*CPUInterruptHandler)(CPUState *, int); | |
507 | ||
508 | extern CPUInterruptHandler cpu_interrupt_handler; | |
509 | ||
510 | /** | |
511 | * cpu_interrupt: | |
512 | * @cpu: The CPU to set an interrupt on. | |
513 | * @mask: The interupts to set. | |
514 | * | |
515 | * Invokes the interrupt handler. | |
516 | */ | |
517 | static inline void cpu_interrupt(CPUState *cpu, int mask) | |
518 | { | |
519 | cpu_interrupt_handler(cpu, mask); | |
520 | } | |
521 | ||
522 | #else /* USER_ONLY */ | |
523 | ||
524 | void cpu_interrupt(CPUState *cpu, int mask); | |
525 | ||
526 | #endif /* USER_ONLY */ | |
527 | ||
c658b94f AF |
528 | #ifndef CONFIG_USER_ONLY |
529 | ||
530 | static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr, | |
531 | bool is_write, bool is_exec, | |
532 | int opaque, unsigned size) | |
533 | { | |
534 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
535 | ||
536 | if (cc->do_unassigned_access) { | |
537 | cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size); | |
538 | } | |
539 | } | |
540 | ||
541 | #endif | |
542 | ||
d8ed887b AF |
543 | /** |
544 | * cpu_reset_interrupt: | |
545 | * @cpu: The CPU to clear the interrupt on. | |
546 | * @mask: The interrupt mask to clear. | |
547 | * | |
548 | * Resets interrupts on the vCPU @cpu. | |
549 | */ | |
550 | void cpu_reset_interrupt(CPUState *cpu, int mask); | |
551 | ||
60a3e17a AF |
552 | /** |
553 | * cpu_exit: | |
554 | * @cpu: The CPU to exit. | |
555 | * | |
556 | * Requests the CPU @cpu to exit execution. | |
557 | */ | |
558 | void cpu_exit(CPUState *cpu); | |
559 | ||
2993683b IM |
560 | /** |
561 | * cpu_resume: | |
562 | * @cpu: The CPU to resume. | |
563 | * | |
564 | * Resumes CPU, i.e. puts CPU into runnable state. | |
565 | */ | |
566 | void cpu_resume(CPUState *cpu); | |
dd83b06a | 567 | |
c643bed9 AF |
568 | /** |
569 | * qemu_init_vcpu: | |
570 | * @cpu: The vCPU to initialize. | |
571 | * | |
572 | * Initializes a vCPU. | |
573 | */ | |
574 | void qemu_init_vcpu(CPUState *cpu); | |
575 | ||
3825b28f AF |
576 | #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */ |
577 | #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */ | |
578 | #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */ | |
579 | ||
580 | /** | |
581 | * cpu_single_step: | |
582 | * @cpu: CPU to the flags for. | |
583 | * @enabled: Flags to enable. | |
584 | * | |
585 | * Enables or disables single-stepping for @cpu. | |
586 | */ | |
587 | void cpu_single_step(CPUState *cpu, int enabled); | |
588 | ||
1a1562f5 AF |
589 | #ifdef CONFIG_SOFTMMU |
590 | extern const struct VMStateDescription vmstate_cpu_common; | |
591 | #else | |
592 | #define vmstate_cpu_common vmstate_dummy | |
593 | #endif | |
594 | ||
595 | #define VMSTATE_CPU() { \ | |
596 | .name = "parent_obj", \ | |
597 | .size = sizeof(CPUState), \ | |
598 | .vmsd = &vmstate_cpu_common, \ | |
599 | .flags = VMS_STRUCT, \ | |
600 | .offset = 0, \ | |
601 | } | |
602 | ||
dd83b06a | 603 | #endif |