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/bitmap.h"
28 #include "qemu/queue.h"
29 #include "qemu/thread.h"
30 #include "trace/generated-events.h"
32 typedef int (*WriteCoreDumpFunction
)(const void *buf
, size_t size
,
37 * Type wide enough to contain any #target_ulong virtual address.
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
49 * @section_id: QEMU-cpu
51 * @short_description: Base class for all CPUs
54 #define TYPE_CPU "cpu"
56 /* Since this macro is used a lot in hot code paths and in conjunction with
57 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
60 #define CPU(obj) ((CPUState *)(obj))
62 #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
63 #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
65 typedef enum MMUAccessType
{
71 typedef struct CPUWatchpoint CPUWatchpoint
;
73 typedef void (*CPUUnassignedAccess
)(CPUState
*cpu
, hwaddr addr
,
74 bool is_write
, bool is_exec
, int opaque
,
77 struct TranslationBlock
;
81 * @class_by_name: Callback to map -cpu command line model name to an
82 * instantiatable CPU type.
83 * @parse_features: Callback to parse command line arguments.
84 * @reset: Callback to reset the #CPUState to its initial state.
85 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
86 * @has_work: Callback for checking if there is work to do.
87 * @do_interrupt: Callback for interrupt handling.
88 * @do_unassigned_access: Callback for unassigned access handling.
89 * @do_unaligned_access: Callback for unaligned access handling, if
90 * the target defines #ALIGNED_ONLY.
91 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
92 * runtime configurable endianness is currently big-endian. Non-configurable
93 * CPUs can use the default implementation of this method. This method should
94 * not be used by any callers other than the pre-1.0 virtio devices.
95 * @memory_rw_debug: Callback for GDB memory access.
96 * @dump_state: Callback for dumping state.
97 * @dump_statistics: Callback for dumping statistics.
98 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
99 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
100 * @get_memory_mapping: Callback for obtaining the memory mappings.
101 * @set_pc: Callback for setting the Program Counter register.
102 * @synchronize_from_tb: Callback for synchronizing state from a TCG
104 * @handle_mmu_fault: Callback for handling an MMU fault.
105 * @get_phys_page_debug: Callback for obtaining a physical address.
106 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
107 * associated memory transaction attributes to use for the access.
108 * CPUs which use memory transaction attributes should implement this
109 * instead of get_phys_page_debug.
110 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
111 * a memory access with the specified memory transaction attributes.
112 * @gdb_read_register: Callback for letting GDB read a register.
113 * @gdb_write_register: Callback for letting GDB write a register.
114 * @debug_check_watchpoint: Callback: return true if the architectural
115 * watchpoint whose address has matched should really fire.
116 * @debug_excp_handler: Callback for handling debug exceptions.
117 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
118 * 64-bit VM coredump.
119 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
120 * note to a 32-bit VM coredump.
121 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
122 * 32-bit VM coredump.
123 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
124 * note to a 32-bit VM coredump.
125 * @vmsd: State description for migration.
126 * @gdb_num_core_regs: Number of core registers accessible to GDB.
127 * @gdb_core_xml_file: File name for core registers GDB XML description.
128 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
129 * before the insn which triggers a watchpoint rather than after it.
130 * @gdb_arch_name: Optional callback that returns the architecture name known
131 * to GDB. The caller must free the returned string with g_free.
132 * @cpu_exec_enter: Callback for cpu_exec preparation.
133 * @cpu_exec_exit: Callback for cpu_exec cleanup.
134 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
135 * @disas_set_info: Setup architecture specific components of disassembly info
137 * Represents a CPU family or model.
139 typedef struct CPUClass
{
141 DeviceClass parent_class
;
144 ObjectClass
*(*class_by_name
)(const char *cpu_model
);
145 void (*parse_features
)(const char *typename
, char *str
, Error
**errp
);
147 void (*reset
)(CPUState
*cpu
);
148 int reset_dump_flags
;
149 bool (*has_work
)(CPUState
*cpu
);
150 void (*do_interrupt
)(CPUState
*cpu
);
151 CPUUnassignedAccess do_unassigned_access
;
152 void (*do_unaligned_access
)(CPUState
*cpu
, vaddr addr
,
153 MMUAccessType access_type
,
154 int mmu_idx
, uintptr_t retaddr
);
155 bool (*virtio_is_big_endian
)(CPUState
*cpu
);
156 int (*memory_rw_debug
)(CPUState
*cpu
, vaddr addr
,
157 uint8_t *buf
, int len
, bool is_write
);
158 void (*dump_state
)(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
160 void (*dump_statistics
)(CPUState
*cpu
, FILE *f
,
161 fprintf_function cpu_fprintf
, int flags
);
162 int64_t (*get_arch_id
)(CPUState
*cpu
);
163 bool (*get_paging_enabled
)(const CPUState
*cpu
);
164 void (*get_memory_mapping
)(CPUState
*cpu
, MemoryMappingList
*list
,
166 void (*set_pc
)(CPUState
*cpu
, vaddr value
);
167 void (*synchronize_from_tb
)(CPUState
*cpu
, struct TranslationBlock
*tb
);
168 int (*handle_mmu_fault
)(CPUState
*cpu
, vaddr address
, int rw
,
170 hwaddr (*get_phys_page_debug
)(CPUState
*cpu
, vaddr addr
);
171 hwaddr (*get_phys_page_attrs_debug
)(CPUState
*cpu
, vaddr addr
,
173 int (*asidx_from_attrs
)(CPUState
*cpu
, MemTxAttrs attrs
);
174 int (*gdb_read_register
)(CPUState
*cpu
, uint8_t *buf
, int reg
);
175 int (*gdb_write_register
)(CPUState
*cpu
, uint8_t *buf
, int reg
);
176 bool (*debug_check_watchpoint
)(CPUState
*cpu
, CPUWatchpoint
*wp
);
177 void (*debug_excp_handler
)(CPUState
*cpu
);
179 int (*write_elf64_note
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
180 int cpuid
, void *opaque
);
181 int (*write_elf64_qemunote
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
183 int (*write_elf32_note
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
184 int cpuid
, void *opaque
);
185 int (*write_elf32_qemunote
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
188 const struct VMStateDescription
*vmsd
;
189 int gdb_num_core_regs
;
190 const char *gdb_core_xml_file
;
191 gchar
* (*gdb_arch_name
)(CPUState
*cpu
);
192 bool gdb_stop_before_watchpoint
;
194 void (*cpu_exec_enter
)(CPUState
*cpu
);
195 void (*cpu_exec_exit
)(CPUState
*cpu
);
196 bool (*cpu_exec_interrupt
)(CPUState
*cpu
, int interrupt_request
);
198 void (*disas_set_info
)(CPUState
*cpu
, disassemble_info
*info
);
201 #ifdef HOST_WORDS_BIGENDIAN
202 typedef struct icount_decr_u16
{
207 typedef struct icount_decr_u16
{
213 typedef struct CPUBreakpoint
{
215 int flags
; /* BP_* */
216 QTAILQ_ENTRY(CPUBreakpoint
) entry
;
219 struct CPUWatchpoint
{
224 int flags
; /* BP_* */
225 QTAILQ_ENTRY(CPUWatchpoint
) entry
;
231 #define TB_JMP_CACHE_BITS 12
232 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
235 typedef void (*run_on_cpu_func
)(CPUState
*cpu
, void *data
);
237 struct qemu_work_item
{
238 struct qemu_work_item
*next
;
239 run_on_cpu_func func
;
247 * @cpu_index: CPU index (informative).
248 * @nr_cores: Number of cores within this CPU package.
249 * @nr_threads: Number of threads within this CPU.
250 * @numa_node: NUMA node this CPU is belonging to.
251 * @host_tid: Host thread ID.
252 * @running: #true if CPU is currently running (usermode).
253 * @created: Indicates whether the CPU thread has been successfully created.
254 * @interrupt_request: Indicates a pending interrupt request.
255 * @halted: Nonzero if the CPU is in suspended state.
256 * @stop: Indicates a pending stop request.
257 * @stopped: Indicates the CPU has been artificially stopped.
258 * @unplug: Indicates a pending CPU unplug request.
259 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
260 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
261 * CPU and return to its top level loop.
262 * @tb_flushed: Indicates the translation buffer has been flushed.
263 * @singlestep_enabled: Flags for single-stepping.
264 * @icount_extra: Instructions until next timer event.
265 * @icount_decr: Number of cycles left, with interrupt flag in high bit.
266 * This allows a single read-compare-cbranch-write sequence to test
267 * for both decrementer underflow and exceptions.
268 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
269 * requires that IO only be performed on the last instruction of a TB
270 * so that interrupts take effect immediately.
271 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
272 * AddressSpaces this CPU has)
273 * @num_ases: number of CPUAddressSpaces in @cpu_ases
274 * @as: Pointer to the first AddressSpace, for the convenience of targets which
275 * only have a single AddressSpace
276 * @env_ptr: Pointer to subclass-specific CPUArchState field.
277 * @gdb_regs: Additional GDB registers.
278 * @gdb_num_regs: Number of total registers accessible to GDB.
279 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
280 * @next_cpu: Next CPU sharing TB cache.
281 * @opaque: User data.
282 * @mem_io_pc: Host Program Counter at which the memory was accessed.
283 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
284 * @kvm_fd: vCPU file descriptor for KVM.
285 * @work_mutex: Lock to prevent multiple access to queued_work_*.
286 * @queued_work_first: First asynchronous work pending.
287 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
289 * State of one CPU core or thread.
293 DeviceState parent_obj
;
300 struct QemuThread
*thread
;
307 struct QemuCond
*halt_cond
;
316 uint32_t interrupt_request
;
317 int singlestep_enabled
;
318 int64_t icount_extra
;
321 QemuMutex work_mutex
;
322 struct qemu_work_item
*queued_work_first
, *queued_work_last
;
324 CPUAddressSpace
*cpu_ases
;
327 MemoryRegion
*memory
;
329 void *env_ptr
; /* CPUArchState */
330 struct TranslationBlock
*tb_jmp_cache
[TB_JMP_CACHE_SIZE
];
331 struct GDBRegisterState
*gdb_regs
;
334 QTAILQ_ENTRY(CPUState
) node
;
336 /* ice debug support */
337 QTAILQ_HEAD(breakpoints_head
, CPUBreakpoint
) breakpoints
;
339 QTAILQ_HEAD(watchpoints_head
, CPUWatchpoint
) watchpoints
;
340 CPUWatchpoint
*watchpoint_hit
;
344 /* In order to avoid passing too many arguments to the MMIO helpers,
345 * we store some rarely used information in the CPU context.
352 struct KVMState
*kvm_state
;
353 struct kvm_run
*kvm_run
;
355 /* Used for events with 'vcpu' and *without* the 'disabled' properties */
356 DECLARE_BITMAP(trace_dstate
, TRACE_VCPU_EVENT_COUNT
);
358 /* TODO Move common fields from CPUArchState here. */
359 int cpu_index
; /* used by alpha TCG */
360 uint32_t halted
; /* used by alpha, cris, ppc TCG */
366 int32_t exception_index
; /* used by m68k TCG */
368 /* Used to keep track of an outstanding cpu throttle thread for migration
371 bool throttle_thread_scheduled
;
373 /* Note that this is accessed at the start of every TB via a negative
374 offset from AREG0. Leave this field at the end so as to make the
375 (absolute value) offset as small as possible. This reduces code
376 size, especially for hosts without large memory offsets. */
377 uint32_t tcg_exit_req
;
380 QTAILQ_HEAD(CPUTailQ
, CPUState
);
381 extern struct CPUTailQ cpus
;
382 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
383 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
384 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
385 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
386 #define CPU_FOREACH_REVERSE(cpu) \
387 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
388 #define first_cpu QTAILQ_FIRST(&cpus)
390 extern __thread CPUState
*current_cpu
;
393 * cpu_paging_enabled:
394 * @cpu: The CPU whose state is to be inspected.
396 * Returns: %true if paging is enabled, %false otherwise.
398 bool cpu_paging_enabled(const CPUState
*cpu
);
401 * cpu_get_memory_mapping:
402 * @cpu: The CPU whose memory mappings are to be obtained.
403 * @list: Where to write the memory mappings to.
404 * @errp: Pointer for reporting an #Error.
406 void cpu_get_memory_mapping(CPUState
*cpu
, MemoryMappingList
*list
,
410 * cpu_write_elf64_note:
411 * @f: pointer to a function that writes memory to a file
412 * @cpu: The CPU whose memory is to be dumped
413 * @cpuid: ID number of the CPU
414 * @opaque: pointer to the CPUState struct
416 int cpu_write_elf64_note(WriteCoreDumpFunction f
, CPUState
*cpu
,
417 int cpuid
, void *opaque
);
420 * cpu_write_elf64_qemunote:
421 * @f: pointer to a function that writes memory to a file
422 * @cpu: The CPU whose memory is to be dumped
423 * @cpuid: ID number of the CPU
424 * @opaque: pointer to the CPUState struct
426 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f
, CPUState
*cpu
,
430 * cpu_write_elf32_note:
431 * @f: pointer to a function that writes memory to a file
432 * @cpu: The CPU whose memory is to be dumped
433 * @cpuid: ID number of the CPU
434 * @opaque: pointer to the CPUState struct
436 int cpu_write_elf32_note(WriteCoreDumpFunction f
, CPUState
*cpu
,
437 int cpuid
, void *opaque
);
440 * cpu_write_elf32_qemunote:
441 * @f: pointer to a function that writes memory to a file
442 * @cpu: The CPU whose memory is to be dumped
443 * @cpuid: ID number of the CPU
444 * @opaque: pointer to the CPUState struct
446 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f
, CPUState
*cpu
,
452 * @CPU_DUMP_FPU: dump FPU register state, not just integer
453 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
456 CPU_DUMP_CODE
= 0x00010000,
457 CPU_DUMP_FPU
= 0x00020000,
458 CPU_DUMP_CCOP
= 0x00040000,
463 * @cpu: The CPU whose state is to be dumped.
464 * @f: File to dump to.
465 * @cpu_fprintf: Function to dump with.
466 * @flags: Flags what to dump.
470 void cpu_dump_state(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
474 * cpu_dump_statistics:
475 * @cpu: The CPU whose state is to be dumped.
476 * @f: File to dump to.
477 * @cpu_fprintf: Function to dump with.
478 * @flags: Flags what to dump.
480 * Dumps CPU statistics.
482 void cpu_dump_statistics(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
485 #ifndef CONFIG_USER_ONLY
487 * cpu_get_phys_page_attrs_debug:
488 * @cpu: The CPU to obtain the physical page address for.
489 * @addr: The virtual address.
490 * @attrs: Updated on return with the memory transaction attributes to use
493 * Obtains the physical page corresponding to a virtual one, together
494 * with the corresponding memory transaction attributes to use for the access.
495 * Use it only for debugging because no protection checks are done.
497 * Returns: Corresponding physical page address or -1 if no page found.
499 static inline hwaddr
cpu_get_phys_page_attrs_debug(CPUState
*cpu
, vaddr addr
,
502 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
504 if (cc
->get_phys_page_attrs_debug
) {
505 return cc
->get_phys_page_attrs_debug(cpu
, addr
, attrs
);
507 /* Fallback for CPUs which don't implement the _attrs_ hook */
508 *attrs
= MEMTXATTRS_UNSPECIFIED
;
509 return cc
->get_phys_page_debug(cpu
, addr
);
513 * cpu_get_phys_page_debug:
514 * @cpu: The CPU to obtain the physical page address for.
515 * @addr: The virtual address.
517 * Obtains the physical page corresponding to a virtual one.
518 * Use it only for debugging because no protection checks are done.
520 * Returns: Corresponding physical page address or -1 if no page found.
522 static inline hwaddr
cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
)
524 MemTxAttrs attrs
= {};
526 return cpu_get_phys_page_attrs_debug(cpu
, addr
, &attrs
);
529 /** cpu_asidx_from_attrs:
531 * @attrs: memory transaction attributes
533 * Returns the address space index specifying the CPU AddressSpace
534 * to use for a memory access with the given transaction attributes.
536 static inline int cpu_asidx_from_attrs(CPUState
*cpu
, MemTxAttrs attrs
)
538 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
540 if (cc
->asidx_from_attrs
) {
541 return cc
->asidx_from_attrs(cpu
, attrs
);
549 * @cpu: The CPU to be added to the list of CPUs.
551 void cpu_list_add(CPUState
*cpu
);
555 * @cpu: The CPU to be removed from the list of CPUs.
557 void cpu_list_remove(CPUState
*cpu
);
561 * @cpu: The CPU whose state is to be reset.
563 void cpu_reset(CPUState
*cpu
);
567 * @typename: The CPU base type.
568 * @cpu_model: The model string without any parameters.
570 * Looks up a CPU #ObjectClass matching name @cpu_model.
572 * Returns: A #CPUClass or %NULL if not matching class is found.
574 ObjectClass
*cpu_class_by_name(const char *typename
, const char *cpu_model
);
578 * @typename: The CPU base type.
579 * @cpu_model: The model string including optional parameters.
581 * Instantiates a CPU, processes optional parameters and realizes the CPU.
583 * Returns: A #CPUState or %NULL if an error occurred.
585 CPUState
*cpu_generic_init(const char *typename
, const char *cpu_model
);
589 * @cpu: The vCPU to check.
591 * Checks whether the CPU has work to do.
593 * Returns: %true if the CPU has work, %false otherwise.
595 static inline bool cpu_has_work(CPUState
*cpu
)
597 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
599 g_assert(cc
->has_work
);
600 return cc
->has_work(cpu
);
605 * @cpu: The vCPU to check against.
607 * Checks whether the caller is executing on the vCPU thread.
609 * Returns: %true if called from @cpu's thread, %false otherwise.
611 bool qemu_cpu_is_self(CPUState
*cpu
);
615 * @cpu: The vCPU to kick.
617 * Kicks @cpu's thread.
619 void qemu_cpu_kick(CPUState
*cpu
);
623 * @cpu: The CPU to check.
625 * Checks whether the CPU is stopped.
627 * Returns: %true if run state is not running or if artificially stopped;
630 bool cpu_is_stopped(CPUState
*cpu
);
634 * @cpu: The vCPU to run on.
635 * @func: The function to be executed.
636 * @data: Data to pass to the function.
638 * Schedules the function @func for execution on the vCPU @cpu.
640 void run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
);
644 * @cpu: The vCPU to run on.
645 * @func: The function to be executed.
646 * @data: Data to pass to the function.
648 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
650 void async_run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
);
654 * @index: The CPUState@cpu_index value of the CPU to obtain.
656 * Gets a CPU matching @index.
658 * Returns: The CPU or %NULL if there is no matching CPU.
660 CPUState
*qemu_get_cpu(int index
);
664 * @id: Guest-exposed CPU ID to lookup.
666 * Search for CPU with specified ID.
668 * Returns: %true - CPU is found, %false - CPU isn't found.
670 bool cpu_exists(int64_t id
);
674 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
676 * Throttles all vcpus by forcing them to sleep for the given percentage of
677 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
678 * (example: 10ms sleep for every 30ms awake).
680 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
681 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
684 void cpu_throttle_set(int new_throttle_pct
);
689 * Stops the vcpu throttling started by cpu_throttle_set.
691 void cpu_throttle_stop(void);
694 * cpu_throttle_active:
696 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
698 bool cpu_throttle_active(void);
701 * cpu_throttle_get_percentage:
703 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
705 * Returns: The throttle percentage in range 1 to 99.
707 int cpu_throttle_get_percentage(void);
709 #ifndef CONFIG_USER_ONLY
711 typedef void (*CPUInterruptHandler
)(CPUState
*, int);
713 extern CPUInterruptHandler cpu_interrupt_handler
;
717 * @cpu: The CPU to set an interrupt on.
718 * @mask: The interupts to set.
720 * Invokes the interrupt handler.
722 static inline void cpu_interrupt(CPUState
*cpu
, int mask
)
724 cpu_interrupt_handler(cpu
, mask
);
727 #else /* USER_ONLY */
729 void cpu_interrupt(CPUState
*cpu
, int mask
);
731 #endif /* USER_ONLY */
733 #ifdef CONFIG_SOFTMMU
734 static inline void cpu_unassigned_access(CPUState
*cpu
, hwaddr addr
,
735 bool is_write
, bool is_exec
,
736 int opaque
, unsigned size
)
738 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
740 if (cc
->do_unassigned_access
) {
741 cc
->do_unassigned_access(cpu
, addr
, is_write
, is_exec
, opaque
, size
);
745 static inline void cpu_unaligned_access(CPUState
*cpu
, vaddr addr
,
746 MMUAccessType access_type
,
747 int mmu_idx
, uintptr_t retaddr
)
749 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
751 cc
->do_unaligned_access(cpu
, addr
, access_type
, mmu_idx
, retaddr
);
757 * @cpu: The CPU to set the program counter for.
758 * @addr: Program counter value.
760 * Sets the program counter for a CPU.
762 static inline void cpu_set_pc(CPUState
*cpu
, vaddr addr
)
764 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
766 cc
->set_pc(cpu
, addr
);
770 * cpu_reset_interrupt:
771 * @cpu: The CPU to clear the interrupt on.
772 * @mask: The interrupt mask to clear.
774 * Resets interrupts on the vCPU @cpu.
776 void cpu_reset_interrupt(CPUState
*cpu
, int mask
);
780 * @cpu: The CPU to exit.
782 * Requests the CPU @cpu to exit execution.
784 void cpu_exit(CPUState
*cpu
);
788 * @cpu: The CPU to resume.
790 * Resumes CPU, i.e. puts CPU into runnable state.
792 void cpu_resume(CPUState
*cpu
);
796 * @cpu: The CPU to remove.
798 * Requests the CPU to be removed.
800 void cpu_remove(CPUState
*cpu
);
804 * @cpu: The CPU to remove.
806 * Requests the CPU to be removed and waits till it is removed.
808 void cpu_remove_sync(CPUState
*cpu
);
812 * @cpu: The vCPU to initialize.
814 * Initializes a vCPU.
816 void qemu_init_vcpu(CPUState
*cpu
);
818 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
819 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
820 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
824 * @cpu: CPU to the flags for.
825 * @enabled: Flags to enable.
827 * Enables or disables single-stepping for @cpu.
829 void cpu_single_step(CPUState
*cpu
, int enabled
);
831 /* Breakpoint/watchpoint flags */
832 #define BP_MEM_READ 0x01
833 #define BP_MEM_WRITE 0x02
834 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
835 #define BP_STOP_BEFORE_ACCESS 0x04
836 /* 0x08 currently unused */
839 #define BP_ANY (BP_GDB | BP_CPU)
840 #define BP_WATCHPOINT_HIT_READ 0x40
841 #define BP_WATCHPOINT_HIT_WRITE 0x80
842 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
844 int cpu_breakpoint_insert(CPUState
*cpu
, vaddr pc
, int flags
,
845 CPUBreakpoint
**breakpoint
);
846 int cpu_breakpoint_remove(CPUState
*cpu
, vaddr pc
, int flags
);
847 void cpu_breakpoint_remove_by_ref(CPUState
*cpu
, CPUBreakpoint
*breakpoint
);
848 void cpu_breakpoint_remove_all(CPUState
*cpu
, int mask
);
850 /* Return true if PC matches an installed breakpoint. */
851 static inline bool cpu_breakpoint_test(CPUState
*cpu
, vaddr pc
, int mask
)
855 if (unlikely(!QTAILQ_EMPTY(&cpu
->breakpoints
))) {
856 QTAILQ_FOREACH(bp
, &cpu
->breakpoints
, entry
) {
857 if (bp
->pc
== pc
&& (bp
->flags
& mask
)) {
865 int cpu_watchpoint_insert(CPUState
*cpu
, vaddr addr
, vaddr len
,
866 int flags
, CPUWatchpoint
**watchpoint
);
867 int cpu_watchpoint_remove(CPUState
*cpu
, vaddr addr
,
868 vaddr len
, int flags
);
869 void cpu_watchpoint_remove_by_ref(CPUState
*cpu
, CPUWatchpoint
*watchpoint
);
870 void cpu_watchpoint_remove_all(CPUState
*cpu
, int mask
);
873 * cpu_get_address_space:
874 * @cpu: CPU to get address space from
875 * @asidx: index identifying which address space to get
877 * Return the requested address space of this CPU. @asidx
878 * specifies which address space to read.
880 AddressSpace
*cpu_get_address_space(CPUState
*cpu
, int asidx
);
882 void QEMU_NORETURN
cpu_abort(CPUState
*cpu
, const char *fmt
, ...)
884 void cpu_exec_exit(CPUState
*cpu
);
886 #ifdef CONFIG_SOFTMMU
887 extern const struct VMStateDescription vmstate_cpu_common
;
889 #define vmstate_cpu_common vmstate_dummy
892 #define VMSTATE_CPU() { \
893 .name = "parent_obj", \
894 .size = sizeof(CPUState), \
895 .vmsd = &vmstate_cpu_common, \
896 .flags = VMS_STRUCT, \
900 #define UNASSIGNED_CPU_INDEX -1