Merge remote-tracking branch 'qemu/master'
[qemu/ar7.git] / include / qom / cpu.h
blobbf12ab82d778b06b2589096fa4216a7f6ec4afa5
1 /*
2 * QEMU CPU model
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
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.
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>
20 #ifndef QEMU_CPU_H
21 #define QEMU_CPU_H
23 #include "hw/qdev-core.h"
24 #include "disas/bfd.h"
25 #include "exec/hwaddr.h"
26 #include "exec/memattrs.h"
27 #include "qemu/queue.h"
28 #include "qemu/thread.h"
30 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
31 void *opaque);
33 /**
34 * vaddr:
35 * Type wide enough to contain any #target_ulong virtual address.
37 typedef uint64_t vaddr;
38 #define VADDR_PRId PRId64
39 #define VADDR_PRIu PRIu64
40 #define VADDR_PRIo PRIo64
41 #define VADDR_PRIx PRIx64
42 #define VADDR_PRIX PRIX64
43 #define VADDR_MAX UINT64_MAX
45 /**
46 * SECTION:cpu
47 * @section_id: QEMU-cpu
48 * @title: CPU Class
49 * @short_description: Base class for all CPUs
52 #define TYPE_CPU "cpu"
54 /* Since this macro is used a lot in hot code paths and in conjunction with
55 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
56 * an unchecked cast.
58 #define CPU(obj) ((CPUState *)(obj))
60 #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
61 #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
63 typedef enum MMUAccessType {
64 MMU_DATA_LOAD = 0,
65 MMU_DATA_STORE = 1,
66 MMU_INST_FETCH = 2
67 } MMUAccessType;
69 typedef struct CPUWatchpoint CPUWatchpoint;
71 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
72 bool is_write, bool is_exec, int opaque,
73 unsigned size);
75 struct TranslationBlock;
77 /**
78 * CPUClass:
79 * @class_by_name: Callback to map -cpu command line model name to an
80 * instantiatable CPU type.
81 * @parse_features: Callback to parse command line arguments.
82 * @reset: Callback to reset the #CPUState to its initial state.
83 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
84 * @has_work: Callback for checking if there is work to do.
85 * @do_interrupt: Callback for interrupt handling.
86 * @do_unassigned_access: Callback for unassigned access handling.
87 * @do_unaligned_access: Callback for unaligned access handling, if
88 * the target defines #ALIGNED_ONLY.
89 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
90 * runtime configurable endianness is currently big-endian. Non-configurable
91 * CPUs can use the default implementation of this method. This method should
92 * not be used by any callers other than the pre-1.0 virtio devices.
93 * @memory_rw_debug: Callback for GDB memory access.
94 * @dump_state: Callback for dumping state.
95 * @dump_statistics: Callback for dumping statistics.
96 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
97 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
98 * @get_memory_mapping: Callback for obtaining the memory mappings.
99 * @set_pc: Callback for setting the Program Counter register.
100 * @synchronize_from_tb: Callback for synchronizing state from a TCG
101 * #TranslationBlock.
102 * @handle_mmu_fault: Callback for handling an MMU fault.
103 * @get_phys_page_debug: Callback for obtaining a physical address.
104 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
105 * associated memory transaction attributes to use for the access.
106 * CPUs which use memory transaction attributes should implement this
107 * instead of get_phys_page_debug.
108 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
109 * a memory access with the specified memory transaction attributes.
110 * @gdb_read_register: Callback for letting GDB read a register.
111 * @gdb_write_register: Callback for letting GDB write a register.
112 * @debug_check_watchpoint: Callback: return true if the architectural
113 * watchpoint whose address has matched should really fire.
114 * @debug_excp_handler: Callback for handling debug exceptions.
115 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
116 * 64-bit VM coredump.
117 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
118 * note to a 32-bit VM coredump.
119 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
120 * 32-bit VM coredump.
121 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
122 * note to a 32-bit VM coredump.
123 * @vmsd: State description for migration.
124 * @gdb_num_core_regs: Number of core registers accessible to GDB.
125 * @gdb_core_xml_file: File name for core registers GDB XML description.
126 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
127 * before the insn which triggers a watchpoint rather than after it.
128 * @gdb_arch_name: Optional callback that returns the architecture name known
129 * to GDB. The caller must free the returned string with g_free.
130 * @cpu_exec_enter: Callback for cpu_exec preparation.
131 * @cpu_exec_exit: Callback for cpu_exec cleanup.
132 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
133 * @disas_set_info: Setup architecture specific components of disassembly info
135 * Represents a CPU family or model.
137 typedef struct CPUClass {
138 /*< private >*/
139 DeviceClass parent_class;
140 /*< public >*/
142 ObjectClass *(*class_by_name)(const char *cpu_model);
143 void (*parse_features)(const char *typename, char *str, Error **errp);
145 void (*reset)(CPUState *cpu);
146 int reset_dump_flags;
147 bool (*has_work)(CPUState *cpu);
148 void (*do_interrupt)(CPUState *cpu);
149 CPUUnassignedAccess do_unassigned_access;
150 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
151 MMUAccessType access_type,
152 int mmu_idx, uintptr_t retaddr);
153 bool (*virtio_is_big_endian)(CPUState *cpu);
154 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
155 uint8_t *buf, int len, bool is_write);
156 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
157 int flags);
158 void (*dump_statistics)(CPUState *cpu, FILE *f,
159 fprintf_function cpu_fprintf, int flags);
160 int64_t (*get_arch_id)(CPUState *cpu);
161 bool (*get_paging_enabled)(const CPUState *cpu);
162 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
163 Error **errp);
164 void (*set_pc)(CPUState *cpu, vaddr value);
165 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
166 int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int rw,
167 int mmu_index);
168 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
169 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
170 MemTxAttrs *attrs);
171 int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
172 int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
173 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
174 bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
175 void (*debug_excp_handler)(CPUState *cpu);
177 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
178 int cpuid, void *opaque);
179 int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
180 void *opaque);
181 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
182 int cpuid, void *opaque);
183 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
184 void *opaque);
186 const struct VMStateDescription *vmsd;
187 int gdb_num_core_regs;
188 const char *gdb_core_xml_file;
189 gchar * (*gdb_arch_name)(CPUState *cpu);
190 bool gdb_stop_before_watchpoint;
192 void (*cpu_exec_enter)(CPUState *cpu);
193 void (*cpu_exec_exit)(CPUState *cpu);
194 bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
196 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
197 } CPUClass;
199 #ifdef HOST_WORDS_BIGENDIAN
200 typedef struct icount_decr_u16 {
201 uint16_t high;
202 uint16_t low;
203 } icount_decr_u16;
204 #else
205 typedef struct icount_decr_u16 {
206 uint16_t low;
207 uint16_t high;
208 } icount_decr_u16;
209 #endif
211 typedef struct CPUBreakpoint {
212 vaddr pc;
213 int flags; /* BP_* */
214 QTAILQ_ENTRY(CPUBreakpoint) entry;
215 } CPUBreakpoint;
217 struct CPUWatchpoint {
218 vaddr vaddr;
219 vaddr len;
220 vaddr hitaddr;
221 MemTxAttrs hitattrs;
222 int flags; /* BP_* */
223 QTAILQ_ENTRY(CPUWatchpoint) entry;
226 struct KVMState;
227 struct kvm_run;
229 #define TB_JMP_CACHE_BITS 12
230 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
232 /* work queue */
233 struct qemu_work_item {
234 struct qemu_work_item *next;
235 void (*func)(void *data);
236 void *data;
237 int done;
238 bool free;
242 * CPUState:
243 * @cpu_index: CPU index (informative).
244 * @nr_cores: Number of cores within this CPU package.
245 * @nr_threads: Number of threads within this CPU.
246 * @numa_node: NUMA node this CPU is belonging to.
247 * @host_tid: Host thread ID.
248 * @running: #true if CPU is currently running (usermode).
249 * @created: Indicates whether the CPU thread has been successfully created.
250 * @interrupt_request: Indicates a pending interrupt request.
251 * @halted: Nonzero if the CPU is in suspended state.
252 * @stop: Indicates a pending stop request.
253 * @stopped: Indicates the CPU has been artificially stopped.
254 * @unplug: Indicates a pending CPU unplug request.
255 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
256 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
257 * CPU and return to its top level loop.
258 * @tb_flushed: Indicates the translation buffer has been flushed.
259 * @singlestep_enabled: Flags for single-stepping.
260 * @icount_extra: Instructions until next timer event.
261 * @icount_decr: Number of cycles left, with interrupt flag in high bit.
262 * This allows a single read-compare-cbranch-write sequence to test
263 * for both decrementer underflow and exceptions.
264 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
265 * requires that IO only be performed on the last instruction of a TB
266 * so that interrupts take effect immediately.
267 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
268 * AddressSpaces this CPU has)
269 * @num_ases: number of CPUAddressSpaces in @cpu_ases
270 * @as: Pointer to the first AddressSpace, for the convenience of targets which
271 * only have a single AddressSpace
272 * @env_ptr: Pointer to subclass-specific CPUArchState field.
273 * @gdb_regs: Additional GDB registers.
274 * @gdb_num_regs: Number of total registers accessible to GDB.
275 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
276 * @next_cpu: Next CPU sharing TB cache.
277 * @opaque: User data.
278 * @mem_io_pc: Host Program Counter at which the memory was accessed.
279 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
280 * @kvm_fd: vCPU file descriptor for KVM.
281 * @work_mutex: Lock to prevent multiple access to queued_work_*.
282 * @queued_work_first: First asynchronous work pending.
284 * State of one CPU core or thread.
286 struct CPUState {
287 /*< private >*/
288 DeviceState parent_obj;
289 /*< public >*/
291 int nr_cores;
292 int nr_threads;
293 int numa_node;
295 struct QemuThread *thread;
296 #ifdef _WIN32
297 HANDLE hThread;
298 #endif
299 int thread_id;
300 uint32_t host_tid;
301 bool running;
302 struct QemuCond *halt_cond;
303 bool thread_kicked;
304 bool created;
305 bool stop;
306 bool stopped;
307 /* Endianness, false = little endian, true = big endian. */
308 bool bigendian;
309 bool unplug;
310 bool crash_occurred;
311 bool exit_request;
312 bool tb_flushed;
313 uint32_t interrupt_request;
314 int singlestep_enabled;
315 int64_t icount_extra;
316 sigjmp_buf jmp_env;
318 QemuMutex work_mutex;
319 struct qemu_work_item *queued_work_first, *queued_work_last;
321 CPUAddressSpace *cpu_ases;
322 int num_ases;
323 AddressSpace *as;
324 MemoryRegion *memory;
326 void *env_ptr; /* CPUArchState */
327 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
328 struct GDBRegisterState *gdb_regs;
329 int gdb_num_regs;
330 int gdb_num_g_regs;
331 QTAILQ_ENTRY(CPUState) node;
333 /* ice debug support */
334 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
336 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
337 CPUWatchpoint *watchpoint_hit;
339 void *opaque;
341 /* In order to avoid passing too many arguments to the MMIO helpers,
342 * we store some rarely used information in the CPU context.
344 uintptr_t mem_io_pc;
345 vaddr mem_io_vaddr;
347 int kvm_fd;
348 bool kvm_vcpu_dirty;
349 struct KVMState *kvm_state;
350 struct kvm_run *kvm_run;
352 /* TODO Move common fields from CPUArchState here. */
353 int cpu_index; /* used by alpha TCG */
354 uint32_t halted; /* used by alpha, cris, ppc TCG */
355 union {
356 uint32_t u32;
357 icount_decr_u16 u16;
358 } icount_decr;
359 uint32_t can_do_io;
360 int32_t exception_index; /* used by m68k TCG */
362 /* Used to keep track of an outstanding cpu throttle thread for migration
363 * autoconverge
365 bool throttle_thread_scheduled;
367 /* Note that this is accessed at the start of every TB via a negative
368 offset from AREG0. Leave this field at the end so as to make the
369 (absolute value) offset as small as possible. This reduces code
370 size, especially for hosts without large memory offsets. */
371 uint32_t tcg_exit_req;
374 QTAILQ_HEAD(CPUTailQ, CPUState);
375 extern struct CPUTailQ cpus;
376 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
377 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
378 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
379 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
380 #define CPU_FOREACH_REVERSE(cpu) \
381 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
382 #define first_cpu QTAILQ_FIRST(&cpus)
384 extern __thread CPUState *current_cpu;
387 * cpu_paging_enabled:
388 * @cpu: The CPU whose state is to be inspected.
390 * Returns: %true if paging is enabled, %false otherwise.
392 bool cpu_paging_enabled(const CPUState *cpu);
395 * cpu_get_memory_mapping:
396 * @cpu: The CPU whose memory mappings are to be obtained.
397 * @list: Where to write the memory mappings to.
398 * @errp: Pointer for reporting an #Error.
400 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
401 Error **errp);
404 * cpu_write_elf64_note:
405 * @f: pointer to a function that writes memory to a file
406 * @cpu: The CPU whose memory is to be dumped
407 * @cpuid: ID number of the CPU
408 * @opaque: pointer to the CPUState struct
410 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
411 int cpuid, void *opaque);
414 * cpu_write_elf64_qemunote:
415 * @f: pointer to a function that writes memory to a file
416 * @cpu: The CPU whose memory is to be dumped
417 * @cpuid: ID number of the CPU
418 * @opaque: pointer to the CPUState struct
420 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
421 void *opaque);
424 * cpu_write_elf32_note:
425 * @f: pointer to a function that writes memory to a file
426 * @cpu: The CPU whose memory is to be dumped
427 * @cpuid: ID number of the CPU
428 * @opaque: pointer to the CPUState struct
430 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
431 int cpuid, void *opaque);
434 * cpu_write_elf32_qemunote:
435 * @f: pointer to a function that writes memory to a file
436 * @cpu: The CPU whose memory is to be dumped
437 * @cpuid: ID number of the CPU
438 * @opaque: pointer to the CPUState struct
440 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
441 void *opaque);
444 * CPUDumpFlags:
445 * @CPU_DUMP_CODE:
446 * @CPU_DUMP_FPU: dump FPU register state, not just integer
447 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
449 enum CPUDumpFlags {
450 CPU_DUMP_CODE = 0x00010000,
451 CPU_DUMP_FPU = 0x00020000,
452 CPU_DUMP_CCOP = 0x00040000,
456 * cpu_dump_state:
457 * @cpu: The CPU whose state is to be dumped.
458 * @f: File to dump to.
459 * @cpu_fprintf: Function to dump with.
460 * @flags: Flags what to dump.
462 * Dumps CPU state.
464 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
465 int flags);
468 * cpu_dump_statistics:
469 * @cpu: The CPU whose state is to be dumped.
470 * @f: File to dump to.
471 * @cpu_fprintf: Function to dump with.
472 * @flags: Flags what to dump.
474 * Dumps CPU statistics.
476 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
477 int flags);
479 #ifndef CONFIG_USER_ONLY
481 * cpu_get_phys_page_attrs_debug:
482 * @cpu: The CPU to obtain the physical page address for.
483 * @addr: The virtual address.
484 * @attrs: Updated on return with the memory transaction attributes to use
485 * for this access.
487 * Obtains the physical page corresponding to a virtual one, together
488 * with the corresponding memory transaction attributes to use for the access.
489 * Use it only for debugging because no protection checks are done.
491 * Returns: Corresponding physical page address or -1 if no page found.
493 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
494 MemTxAttrs *attrs)
496 CPUClass *cc = CPU_GET_CLASS(cpu);
498 if (cc->get_phys_page_attrs_debug) {
499 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
501 /* Fallback for CPUs which don't implement the _attrs_ hook */
502 *attrs = MEMTXATTRS_UNSPECIFIED;
503 return cc->get_phys_page_debug(cpu, addr);
507 * cpu_get_phys_page_debug:
508 * @cpu: The CPU to obtain the physical page address for.
509 * @addr: The virtual address.
511 * Obtains the physical page corresponding to a virtual one.
512 * Use it only for debugging because no protection checks are done.
514 * Returns: Corresponding physical page address or -1 if no page found.
516 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
518 MemTxAttrs attrs = {};
520 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
523 /** cpu_asidx_from_attrs:
524 * @cpu: CPU
525 * @attrs: memory transaction attributes
527 * Returns the address space index specifying the CPU AddressSpace
528 * to use for a memory access with the given transaction attributes.
530 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
532 CPUClass *cc = CPU_GET_CLASS(cpu);
534 if (cc->asidx_from_attrs) {
535 return cc->asidx_from_attrs(cpu, attrs);
537 return 0;
539 #endif
542 * cpu_reset:
543 * @cpu: The CPU whose state is to be reset.
545 void cpu_reset(CPUState *cpu);
548 * cpu_class_by_name:
549 * @typename: The CPU base type.
550 * @cpu_model: The model string without any parameters.
552 * Looks up a CPU #ObjectClass matching name @cpu_model.
554 * Returns: A #CPUClass or %NULL if not matching class is found.
556 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
559 * cpu_generic_init:
560 * @typename: The CPU base type.
561 * @cpu_model: The model string including optional parameters.
563 * Instantiates a CPU, processes optional parameters and realizes the CPU.
565 * Returns: A #CPUState or %NULL if an error occurred.
567 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
570 * cpu_has_work:
571 * @cpu: The vCPU to check.
573 * Checks whether the CPU has work to do.
575 * Returns: %true if the CPU has work, %false otherwise.
577 static inline bool cpu_has_work(CPUState *cpu)
579 CPUClass *cc = CPU_GET_CLASS(cpu);
581 g_assert(cc->has_work);
582 return cc->has_work(cpu);
586 * qemu_cpu_is_self:
587 * @cpu: The vCPU to check against.
589 * Checks whether the caller is executing on the vCPU thread.
591 * Returns: %true if called from @cpu's thread, %false otherwise.
593 bool qemu_cpu_is_self(CPUState *cpu);
596 * qemu_cpu_kick:
597 * @cpu: The vCPU to kick.
599 * Kicks @cpu's thread.
601 void qemu_cpu_kick(CPUState *cpu);
604 * cpu_is_stopped:
605 * @cpu: The CPU to check.
607 * Checks whether the CPU is stopped.
609 * Returns: %true if run state is not running or if artificially stopped;
610 * %false otherwise.
612 bool cpu_is_stopped(CPUState *cpu);
615 * run_on_cpu:
616 * @cpu: The vCPU to run on.
617 * @func: The function to be executed.
618 * @data: Data to pass to the function.
620 * Schedules the function @func for execution on the vCPU @cpu.
622 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
625 * async_run_on_cpu:
626 * @cpu: The vCPU to run on.
627 * @func: The function to be executed.
628 * @data: Data to pass to the function.
630 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
632 void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
635 * qemu_get_cpu:
636 * @index: The CPUState@cpu_index value of the CPU to obtain.
638 * Gets a CPU matching @index.
640 * Returns: The CPU or %NULL if there is no matching CPU.
642 CPUState *qemu_get_cpu(int index);
645 * cpu_exists:
646 * @id: Guest-exposed CPU ID to lookup.
648 * Search for CPU with specified ID.
650 * Returns: %true - CPU is found, %false - CPU isn't found.
652 bool cpu_exists(int64_t id);
655 * cpu_throttle_set:
656 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
658 * Throttles all vcpus by forcing them to sleep for the given percentage of
659 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
660 * (example: 10ms sleep for every 30ms awake).
662 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
663 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
664 * is called.
666 void cpu_throttle_set(int new_throttle_pct);
669 * cpu_throttle_stop:
671 * Stops the vcpu throttling started by cpu_throttle_set.
673 void cpu_throttle_stop(void);
676 * cpu_throttle_active:
678 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
680 bool cpu_throttle_active(void);
683 * cpu_throttle_get_percentage:
685 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
687 * Returns: The throttle percentage in range 1 to 99.
689 int cpu_throttle_get_percentage(void);
691 #ifndef CONFIG_USER_ONLY
693 typedef void (*CPUInterruptHandler)(CPUState *, int);
695 extern CPUInterruptHandler cpu_interrupt_handler;
698 * cpu_interrupt:
699 * @cpu: The CPU to set an interrupt on.
700 * @mask: The interupts to set.
702 * Invokes the interrupt handler.
704 static inline void cpu_interrupt(CPUState *cpu, int mask)
706 cpu_interrupt_handler(cpu, mask);
709 #else /* USER_ONLY */
711 void cpu_interrupt(CPUState *cpu, int mask);
713 #endif /* USER_ONLY */
715 #ifdef CONFIG_SOFTMMU
716 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
717 bool is_write, bool is_exec,
718 int opaque, unsigned size)
720 CPUClass *cc = CPU_GET_CLASS(cpu);
722 if (cc->do_unassigned_access) {
723 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
727 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
728 MMUAccessType access_type,
729 int mmu_idx, uintptr_t retaddr)
731 CPUClass *cc = CPU_GET_CLASS(cpu);
733 cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
735 #endif
738 * cpu_set_pc:
739 * @cpu: The CPU to set the program counter for.
740 * @addr: Program counter value.
742 * Sets the program counter for a CPU.
744 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
746 CPUClass *cc = CPU_GET_CLASS(cpu);
748 cc->set_pc(cpu, addr);
752 * cpu_reset_interrupt:
753 * @cpu: The CPU to clear the interrupt on.
754 * @mask: The interrupt mask to clear.
756 * Resets interrupts on the vCPU @cpu.
758 void cpu_reset_interrupt(CPUState *cpu, int mask);
761 * cpu_exit:
762 * @cpu: The CPU to exit.
764 * Requests the CPU @cpu to exit execution.
766 void cpu_exit(CPUState *cpu);
769 * cpu_resume:
770 * @cpu: The CPU to resume.
772 * Resumes CPU, i.e. puts CPU into runnable state.
774 void cpu_resume(CPUState *cpu);
777 * cpu_remove:
778 * @cpu: The CPU to remove.
780 * Requests the CPU to be removed.
782 void cpu_remove(CPUState *cpu);
785 * cpu_remove_sync:
786 * @cpu: The CPU to remove.
788 * Requests the CPU to be removed and waits till it is removed.
790 void cpu_remove_sync(CPUState *cpu);
793 * qemu_init_vcpu:
794 * @cpu: The vCPU to initialize.
796 * Initializes a vCPU.
798 void qemu_init_vcpu(CPUState *cpu);
800 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
801 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
802 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
805 * cpu_single_step:
806 * @cpu: CPU to the flags for.
807 * @enabled: Flags to enable.
809 * Enables or disables single-stepping for @cpu.
811 void cpu_single_step(CPUState *cpu, int enabled);
813 /* Breakpoint/watchpoint flags */
814 #define BP_MEM_READ 0x01
815 #define BP_MEM_WRITE 0x02
816 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
817 #define BP_STOP_BEFORE_ACCESS 0x04
818 /* 0x08 currently unused */
819 #define BP_GDB 0x10
820 #define BP_CPU 0x20
821 #define BP_ANY (BP_GDB | BP_CPU)
822 #define BP_WATCHPOINT_HIT_READ 0x40
823 #define BP_WATCHPOINT_HIT_WRITE 0x80
824 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
826 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
827 CPUBreakpoint **breakpoint);
828 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
829 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
830 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
832 /* Return true if PC matches an installed breakpoint. */
833 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
835 CPUBreakpoint *bp;
837 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
838 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
839 if (bp->pc == pc && (bp->flags & mask)) {
840 return true;
844 return false;
847 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
848 int flags, CPUWatchpoint **watchpoint);
849 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
850 vaddr len, int flags);
851 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
852 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
855 * cpu_get_address_space:
856 * @cpu: CPU to get address space from
857 * @asidx: index identifying which address space to get
859 * Return the requested address space of this CPU. @asidx
860 * specifies which address space to read.
862 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
864 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
865 GCC_FMT_ATTR(2, 3);
866 void cpu_exec_exit(CPUState *cpu);
868 #ifdef CONFIG_SOFTMMU
869 extern const struct VMStateDescription vmstate_cpu_common;
870 #else
871 #define vmstate_cpu_common vmstate_dummy
872 #endif
874 #define VMSTATE_CPU() { \
875 .name = "parent_obj", \
876 .size = sizeof(CPUState), \
877 .vmsd = &vmstate_cpu_common, \
878 .flags = VMS_STRUCT, \
879 .offset = 0, \
882 #endif