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>
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,
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
47 * @section_id: QEMU-cpu
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
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 {
69 typedef struct CPUWatchpoint CPUWatchpoint;
71 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
72 bool is_write, bool is_exec, int opaque,
75 struct TranslationBlock;
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
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 {
139 DeviceClass parent_class;
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,
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,
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,
168 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
169 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
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,
181 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
182 int cpuid, void *opaque);
183 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
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);
199 #ifdef HOST_WORDS_BIGENDIAN
200 typedef struct icount_decr_u16 {
205 typedef struct icount_decr_u16 {
211 typedef struct CPUBreakpoint {
213 int flags; /* BP_* */
214 QTAILQ_ENTRY(CPUBreakpoint) entry;
217 struct CPUWatchpoint {
222 int flags; /* BP_* */
223 QTAILQ_ENTRY(CPUWatchpoint) entry;
229 #define TB_JMP_CACHE_BITS 12
230 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
233 struct qemu_work_item {
234 struct qemu_work_item *next;
235 void (*func)(void *data);
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.
288 DeviceState parent_obj;
295 struct QemuThread *thread;
302 struct QemuCond *halt_cond;
311 uint32_t interrupt_request;
312 int singlestep_enabled;
313 int64_t icount_extra;
316 QemuMutex work_mutex;
317 struct qemu_work_item *queued_work_first, *queued_work_last;
319 CPUAddressSpace *cpu_ases;
322 MemoryRegion *memory;
324 void *env_ptr; /* CPUArchState */
325 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
326 struct GDBRegisterState *gdb_regs;
329 QTAILQ_ENTRY(CPUState) node;
331 /* ice debug support */
332 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
334 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
335 CPUWatchpoint *watchpoint_hit;
339 /* In order to avoid passing too many arguments to the MMIO helpers,
340 * we store some rarely used information in the CPU context.
347 struct KVMState *kvm_state;
348 struct kvm_run *kvm_run;
350 /* TODO Move common fields from CPUArchState here. */
351 int cpu_index; /* used by alpha TCG */
352 uint32_t halted; /* used by alpha, cris, ppc TCG */
358 int32_t exception_index; /* used by m68k TCG */
360 /* Used to keep track of an outstanding cpu throttle thread for migration
363 bool throttle_thread_scheduled;
365 /* Note that this is accessed at the start of every TB via a negative
366 offset from AREG0. Leave this field at the end so as to make the
367 (absolute value) offset as small as possible. This reduces code
368 size, especially for hosts without large memory offsets. */
369 uint32_t tcg_exit_req;
372 QTAILQ_HEAD(CPUTailQ, CPUState);
373 extern struct CPUTailQ cpus;
374 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
375 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
376 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
377 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
378 #define CPU_FOREACH_REVERSE(cpu) \
379 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
380 #define first_cpu QTAILQ_FIRST(&cpus)
382 extern __thread CPUState *current_cpu;
385 * cpu_paging_enabled:
386 * @cpu: The CPU whose state is to be inspected.
388 * Returns: %true if paging is enabled, %false otherwise.
390 bool cpu_paging_enabled(const CPUState *cpu);
393 * cpu_get_memory_mapping:
394 * @cpu: The CPU whose memory mappings are to be obtained.
395 * @list: Where to write the memory mappings to.
396 * @errp: Pointer for reporting an #Error.
398 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
402 * cpu_write_elf64_note:
403 * @f: pointer to a function that writes memory to a file
404 * @cpu: The CPU whose memory is to be dumped
405 * @cpuid: ID number of the CPU
406 * @opaque: pointer to the CPUState struct
408 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
409 int cpuid, void *opaque);
412 * cpu_write_elf64_qemunote:
413 * @f: pointer to a function that writes memory to a file
414 * @cpu: The CPU whose memory is to be dumped
415 * @cpuid: ID number of the CPU
416 * @opaque: pointer to the CPUState struct
418 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
422 * cpu_write_elf32_note:
423 * @f: pointer to a function that writes memory to a file
424 * @cpu: The CPU whose memory is to be dumped
425 * @cpuid: ID number of the CPU
426 * @opaque: pointer to the CPUState struct
428 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
429 int cpuid, void *opaque);
432 * cpu_write_elf32_qemunote:
433 * @f: pointer to a function that writes memory to a file
434 * @cpu: The CPU whose memory is to be dumped
435 * @cpuid: ID number of the CPU
436 * @opaque: pointer to the CPUState struct
438 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
444 * @CPU_DUMP_FPU: dump FPU register state, not just integer
445 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
448 CPU_DUMP_CODE = 0x00010000,
449 CPU_DUMP_FPU = 0x00020000,
450 CPU_DUMP_CCOP = 0x00040000,
455 * @cpu: The CPU whose state is to be dumped.
456 * @f: File to dump to.
457 * @cpu_fprintf: Function to dump with.
458 * @flags: Flags what to dump.
462 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
466 * cpu_dump_statistics:
467 * @cpu: The CPU whose state is to be dumped.
468 * @f: File to dump to.
469 * @cpu_fprintf: Function to dump with.
470 * @flags: Flags what to dump.
472 * Dumps CPU statistics.
474 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
477 #ifndef CONFIG_USER_ONLY
479 * cpu_get_phys_page_attrs_debug:
480 * @cpu: The CPU to obtain the physical page address for.
481 * @addr: The virtual address.
482 * @attrs: Updated on return with the memory transaction attributes to use
485 * Obtains the physical page corresponding to a virtual one, together
486 * with the corresponding memory transaction attributes to use for the access.
487 * Use it only for debugging because no protection checks are done.
489 * Returns: Corresponding physical page address or -1 if no page found.
491 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
494 CPUClass *cc = CPU_GET_CLASS(cpu);
496 if (cc->get_phys_page_attrs_debug) {
497 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
499 /* Fallback for CPUs which don't implement the _attrs_ hook */
500 *attrs = MEMTXATTRS_UNSPECIFIED;
501 return cc->get_phys_page_debug(cpu, addr);
505 * cpu_get_phys_page_debug:
506 * @cpu: The CPU to obtain the physical page address for.
507 * @addr: The virtual address.
509 * Obtains the physical page corresponding to a virtual one.
510 * Use it only for debugging because no protection checks are done.
512 * Returns: Corresponding physical page address or -1 if no page found.
514 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
516 MemTxAttrs attrs = {};
518 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
521 /** cpu_asidx_from_attrs:
523 * @attrs: memory transaction attributes
525 * Returns the address space index specifying the CPU AddressSpace
526 * to use for a memory access with the given transaction attributes.
528 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
530 CPUClass *cc = CPU_GET_CLASS(cpu);
532 if (cc->asidx_from_attrs) {
533 return cc->asidx_from_attrs(cpu, attrs);
541 * @cpu: The CPU whose state is to be reset.
543 void cpu_reset(CPUState *cpu);
547 * @typename: The CPU base type.
548 * @cpu_model: The model string without any parameters.
550 * Looks up a CPU #ObjectClass matching name @cpu_model.
552 * Returns: A #CPUClass or %NULL if not matching class is found.
554 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
558 * @typename: The CPU base type.
559 * @cpu_model: The model string including optional parameters.
561 * Instantiates a CPU, processes optional parameters and realizes the CPU.
563 * Returns: A #CPUState or %NULL if an error occurred.
565 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
569 * @cpu: The vCPU to check.
571 * Checks whether the CPU has work to do.
573 * Returns: %true if the CPU has work, %false otherwise.
575 static inline bool cpu_has_work(CPUState *cpu)
577 CPUClass *cc = CPU_GET_CLASS(cpu);
579 g_assert(cc->has_work);
580 return cc->has_work(cpu);
585 * @cpu: The vCPU to check against.
587 * Checks whether the caller is executing on the vCPU thread.
589 * Returns: %true if called from @cpu's thread, %false otherwise.
591 bool qemu_cpu_is_self(CPUState *cpu);
595 * @cpu: The vCPU to kick.
597 * Kicks @cpu's thread.
599 void qemu_cpu_kick(CPUState *cpu);
603 * @cpu: The CPU to check.
605 * Checks whether the CPU is stopped.
607 * Returns: %true if run state is not running or if artificially stopped;
610 bool cpu_is_stopped(CPUState *cpu);
614 * @cpu: The vCPU to run on.
615 * @func: The function to be executed.
616 * @data: Data to pass to the function.
618 * Schedules the function @func for execution on the vCPU @cpu.
620 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
624 * @cpu: The vCPU to run on.
625 * @func: The function to be executed.
626 * @data: Data to pass to the function.
628 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
630 void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
634 * @index: The CPUState@cpu_index value of the CPU to obtain.
636 * Gets a CPU matching @index.
638 * Returns: The CPU or %NULL if there is no matching CPU.
640 CPUState *qemu_get_cpu(int index);
644 * @id: Guest-exposed CPU ID to lookup.
646 * Search for CPU with specified ID.
648 * Returns: %true - CPU is found, %false - CPU isn't found.
650 bool cpu_exists(int64_t id);
654 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
656 * Throttles all vcpus by forcing them to sleep for the given percentage of
657 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
658 * (example: 10ms sleep for every 30ms awake).
660 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
661 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
664 void cpu_throttle_set(int new_throttle_pct);
669 * Stops the vcpu throttling started by cpu_throttle_set.
671 void cpu_throttle_stop(void);
674 * cpu_throttle_active:
676 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
678 bool cpu_throttle_active(void);
681 * cpu_throttle_get_percentage:
683 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
685 * Returns: The throttle percentage in range 1 to 99.
687 int cpu_throttle_get_percentage(void);
689 #ifndef CONFIG_USER_ONLY
691 typedef void (*CPUInterruptHandler)(CPUState *, int);
693 extern CPUInterruptHandler cpu_interrupt_handler;
697 * @cpu: The CPU to set an interrupt on.
698 * @mask: The interupts to set.
700 * Invokes the interrupt handler.
702 static inline void cpu_interrupt(CPUState *cpu, int mask)
704 cpu_interrupt_handler(cpu, mask);
707 #else /* USER_ONLY */
709 void cpu_interrupt(CPUState *cpu, int mask);
711 #endif /* USER_ONLY */
713 #ifdef CONFIG_SOFTMMU
714 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
715 bool is_write, bool is_exec,
716 int opaque, unsigned size)
718 CPUClass *cc = CPU_GET_CLASS(cpu);
720 if (cc->do_unassigned_access) {
721 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
725 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
726 MMUAccessType access_type,
727 int mmu_idx, uintptr_t retaddr)
729 CPUClass *cc = CPU_GET_CLASS(cpu);
731 cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
737 * @cpu: The CPU to set the program counter for.
738 * @addr: Program counter value.
740 * Sets the program counter for a CPU.
742 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
744 CPUClass *cc = CPU_GET_CLASS(cpu);
746 cc->set_pc(cpu, addr);
750 * cpu_reset_interrupt:
751 * @cpu: The CPU to clear the interrupt on.
752 * @mask: The interrupt mask to clear.
754 * Resets interrupts on the vCPU @cpu.
756 void cpu_reset_interrupt(CPUState *cpu, int mask);
760 * @cpu: The CPU to exit.
762 * Requests the CPU @cpu to exit execution.
764 void cpu_exit(CPUState *cpu);
768 * @cpu: The CPU to resume.
770 * Resumes CPU, i.e. puts CPU into runnable state.
772 void cpu_resume(CPUState *cpu);
776 * @cpu: The CPU to remove.
778 * Requests the CPU to be removed.
780 void cpu_remove(CPUState *cpu);
784 * @cpu: The CPU to remove.
786 * Requests the CPU to be removed and waits till it is removed.
788 void cpu_remove_sync(CPUState *cpu);
792 * @cpu: The vCPU to initialize.
794 * Initializes a vCPU.
796 void qemu_init_vcpu(CPUState *cpu);
798 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
799 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
800 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
804 * @cpu: CPU to the flags for.
805 * @enabled: Flags to enable.
807 * Enables or disables single-stepping for @cpu.
809 void cpu_single_step(CPUState *cpu, int enabled);
811 /* Breakpoint/watchpoint flags */
812 #define BP_MEM_READ 0x01
813 #define BP_MEM_WRITE 0x02
814 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
815 #define BP_STOP_BEFORE_ACCESS 0x04
816 /* 0x08 currently unused */
819 #define BP_ANY (BP_GDB | BP_CPU)
820 #define BP_WATCHPOINT_HIT_READ 0x40
821 #define BP_WATCHPOINT_HIT_WRITE 0x80
822 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
824 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
825 CPUBreakpoint **breakpoint);
826 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
827 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
828 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
830 /* Return true if PC matches an installed breakpoint. */
831 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
835 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
836 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
837 if (bp->pc == pc && (bp->flags & mask)) {
845 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
846 int flags, CPUWatchpoint **watchpoint);
847 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
848 vaddr len, int flags);
849 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
850 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
853 * cpu_get_address_space:
854 * @cpu: CPU to get address space from
855 * @asidx: index identifying which address space to get
857 * Return the requested address space of this CPU. @asidx
858 * specifies which address space to read.
860 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
862 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
864 void cpu_exec_exit(CPUState *cpu);
866 #ifdef CONFIG_SOFTMMU
867 extern const struct VMStateDescription vmstate_cpu_common;
869 #define vmstate_cpu_common vmstate_dummy
872 #define VMSTATE_CPU() { \
873 .name = "parent_obj", \
874 .size = sizeof(CPUState), \
875 .vmsd = &vmstate_cpu_common, \
876 .flags = VMS_STRUCT, \