Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-tcg-20210526' into staging
[qemu/ar7.git] / include / hw / core / cpu.h
blob044f668a6e95014d8c404f3173cf1aecdc2d9c7e
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/dis-asm.h"
25 #include "exec/hwaddr.h"
26 #include "exec/memattrs.h"
27 #include "qapi/qapi-types-run-state.h"
28 #include "qemu/bitmap.h"
29 #include "qemu/rcu_queue.h"
30 #include "qemu/queue.h"
31 #include "qemu/thread.h"
32 #include "qemu/plugin.h"
33 #include "qom/object.h"
35 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
36 void *opaque);
38 /**
39 * vaddr:
40 * Type wide enough to contain any #target_ulong virtual address.
42 typedef uint64_t vaddr;
43 #define VADDR_PRId PRId64
44 #define VADDR_PRIu PRIu64
45 #define VADDR_PRIo PRIo64
46 #define VADDR_PRIx PRIx64
47 #define VADDR_PRIX PRIX64
48 #define VADDR_MAX UINT64_MAX
50 /**
51 * SECTION:cpu
52 * @section_id: QEMU-cpu
53 * @title: CPU Class
54 * @short_description: Base class for all CPUs
57 #define TYPE_CPU "cpu"
59 /* Since this macro is used a lot in hot code paths and in conjunction with
60 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
61 * an unchecked cast.
63 #define CPU(obj) ((CPUState *)(obj))
65 typedef struct CPUClass CPUClass;
66 DECLARE_CLASS_CHECKERS(CPUClass, CPU,
67 TYPE_CPU)
69 typedef enum MMUAccessType {
70 MMU_DATA_LOAD = 0,
71 MMU_DATA_STORE = 1,
72 MMU_INST_FETCH = 2
73 } MMUAccessType;
75 typedef struct CPUWatchpoint CPUWatchpoint;
77 /* see tcg-cpu-ops.h */
78 struct TCGCPUOps;
80 /* see accel-cpu.h */
81 struct AccelCPUClass;
83 /* see sysemu-cpu-ops.h */
84 struct SysemuCPUOps;
86 /**
87 * CPUClass:
88 * @class_by_name: Callback to map -cpu command line model name to an
89 * instantiatable CPU type.
90 * @parse_features: Callback to parse command line arguments.
91 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
92 * @has_work: Callback for checking if there is work to do.
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 * @set_pc: Callback for setting the Program Counter register. This
98 * should have the semantics used by the target architecture when
99 * setting the PC from a source such as an ELF file entry point;
100 * for example on Arm it will also set the Thumb mode bit based
101 * on the least significant bit of the new PC value.
102 * If the target behaviour here is anything other than "set
103 * the PC register to the value passed in" then the target must
104 * also implement the synchronize_from_tb hook.
105 * @gdb_read_register: Callback for letting GDB read a register.
106 * @gdb_write_register: Callback for letting GDB write a register.
107 * @gdb_num_core_regs: Number of core registers accessible to GDB.
108 * @gdb_core_xml_file: File name for core registers GDB XML description.
109 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
110 * before the insn which triggers a watchpoint rather than after it.
111 * @gdb_arch_name: Optional callback that returns the architecture name known
112 * to GDB. The caller must free the returned string with g_free.
113 * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the
114 * gdb stub. Returns a pointer to the XML contents for the specified XML file
115 * or NULL if the CPU doesn't have a dynamically generated content for it.
116 * @disas_set_info: Setup architecture specific components of disassembly info
117 * @adjust_watchpoint_address: Perform a target-specific adjustment to an
118 * address before attempting to match it against watchpoints.
119 * @deprecation_note: If this CPUClass is deprecated, this field provides
120 * related information.
122 * Represents a CPU family or model.
124 struct CPUClass {
125 /*< private >*/
126 DeviceClass parent_class;
127 /*< public >*/
129 ObjectClass *(*class_by_name)(const char *cpu_model);
130 void (*parse_features)(const char *typename, char *str, Error **errp);
132 int reset_dump_flags;
133 bool (*has_work)(CPUState *cpu);
134 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
135 uint8_t *buf, int len, bool is_write);
136 void (*dump_state)(CPUState *cpu, FILE *, int flags);
137 void (*dump_statistics)(CPUState *cpu, int flags);
138 int64_t (*get_arch_id)(CPUState *cpu);
139 void (*set_pc)(CPUState *cpu, vaddr value);
140 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
141 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
143 const char *gdb_core_xml_file;
144 gchar * (*gdb_arch_name)(CPUState *cpu);
145 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
147 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
149 const char *deprecation_note;
150 /* Keep non-pointer data at the end to minimize holes. */
151 int gdb_num_core_regs;
152 bool gdb_stop_before_watchpoint;
153 struct AccelCPUClass *accel_cpu;
155 /* when system emulation is not available, this pointer is NULL */
156 const struct SysemuCPUOps *sysemu_ops;
158 /* when TCG is not available, this pointer is NULL */
159 const struct TCGCPUOps *tcg_ops;
162 * if not NULL, this is called in order for the CPUClass to initialize
163 * class data that depends on the accelerator, see accel/accel-common.c.
165 void (*init_accel_cpu)(struct AccelCPUClass *accel_cpu, CPUClass *cc);
169 * Low 16 bits: number of cycles left, used only in icount mode.
170 * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
171 * for this CPU and return to its top level loop (even in non-icount mode).
172 * This allows a single read-compare-cbranch-write sequence to test
173 * for both decrementer underflow and exceptions.
175 typedef union IcountDecr {
176 uint32_t u32;
177 struct {
178 #ifdef HOST_WORDS_BIGENDIAN
179 uint16_t high;
180 uint16_t low;
181 #else
182 uint16_t low;
183 uint16_t high;
184 #endif
185 } u16;
186 } IcountDecr;
188 typedef struct CPUBreakpoint {
189 vaddr pc;
190 int flags; /* BP_* */
191 QTAILQ_ENTRY(CPUBreakpoint) entry;
192 } CPUBreakpoint;
194 struct CPUWatchpoint {
195 vaddr vaddr;
196 vaddr len;
197 vaddr hitaddr;
198 MemTxAttrs hitattrs;
199 int flags; /* BP_* */
200 QTAILQ_ENTRY(CPUWatchpoint) entry;
203 #ifdef CONFIG_PLUGIN
205 * For plugins we sometime need to save the resolved iotlb data before
206 * the memory regions get moved around by io_writex.
208 typedef struct SavedIOTLB {
209 hwaddr addr;
210 MemoryRegionSection *section;
211 hwaddr mr_offset;
212 } SavedIOTLB;
213 #endif
215 struct KVMState;
216 struct kvm_run;
218 struct hax_vcpu_state;
220 #define TB_JMP_CACHE_BITS 12
221 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
223 /* work queue */
225 /* The union type allows passing of 64 bit target pointers on 32 bit
226 * hosts in a single parameter
228 typedef union {
229 int host_int;
230 unsigned long host_ulong;
231 void *host_ptr;
232 vaddr target_ptr;
233 } run_on_cpu_data;
235 #define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
236 #define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
237 #define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
238 #define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
239 #define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
241 typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
243 struct qemu_work_item;
245 #define CPU_UNSET_NUMA_NODE_ID -1
246 #define CPU_TRACE_DSTATE_MAX_EVENTS 32
249 * CPUState:
250 * @cpu_index: CPU index (informative).
251 * @cluster_index: Identifies which cluster this CPU is in.
252 * For boards which don't define clusters or for "loose" CPUs not assigned
253 * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
254 * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
255 * QOM parent.
256 * @tcg_cflags: Pre-computed cflags for this cpu.
257 * @nr_cores: Number of cores within this CPU package.
258 * @nr_threads: Number of threads within this CPU.
259 * @running: #true if CPU is currently running (lockless).
260 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
261 * valid under cpu_list_lock.
262 * @created: Indicates whether the CPU thread has been successfully created.
263 * @interrupt_request: Indicates a pending interrupt request.
264 * @halted: Nonzero if the CPU is in suspended state.
265 * @stop: Indicates a pending stop request.
266 * @stopped: Indicates the CPU has been artificially stopped.
267 * @unplug: Indicates a pending CPU unplug request.
268 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
269 * @singlestep_enabled: Flags for single-stepping.
270 * @icount_extra: Instructions until next timer event.
271 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
272 * requires that IO only be performed on the last instruction of a TB
273 * so that interrupts take effect immediately.
274 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
275 * AddressSpaces this CPU has)
276 * @num_ases: number of CPUAddressSpaces in @cpu_ases
277 * @as: Pointer to the first AddressSpace, for the convenience of targets which
278 * only have a single AddressSpace
279 * @env_ptr: Pointer to subclass-specific CPUArchState field.
280 * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
281 * @gdb_regs: Additional GDB registers.
282 * @gdb_num_regs: Number of total registers accessible to GDB.
283 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
284 * @next_cpu: Next CPU sharing TB cache.
285 * @opaque: User data.
286 * @mem_io_pc: Host Program Counter at which the memory was accessed.
287 * @kvm_fd: vCPU file descriptor for KVM.
288 * @work_mutex: Lock to prevent multiple access to @work_list.
289 * @work_list: List of pending asynchronous work.
290 * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
291 * to @trace_dstate).
292 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
293 * @plugin_mask: Plugin event bitmap. Modified only via async work.
294 * @ignore_memory_transaction_failures: Cached copy of the MachineState
295 * flag of the same name: allows the board to suppress calling of the
296 * CPU do_transaction_failed hook function.
297 * @kvm_dirty_gfns: Points to the KVM dirty ring for this CPU when KVM dirty
298 * ring is enabled.
299 * @kvm_fetch_index: Keeps the index that we last fetched from the per-vCPU
300 * dirty ring structure.
302 * State of one CPU core or thread.
304 struct CPUState {
305 /*< private >*/
306 DeviceState parent_obj;
307 /*< public >*/
309 int nr_cores;
310 int nr_threads;
312 struct QemuThread *thread;
313 #ifdef _WIN32
314 HANDLE hThread;
315 #endif
316 int thread_id;
317 bool running, has_waiter;
318 struct QemuCond *halt_cond;
319 bool thread_kicked;
320 bool created;
321 bool stop;
322 bool stopped;
324 /* Should CPU start in powered-off state? */
325 bool start_powered_off;
327 bool unplug;
328 bool crash_occurred;
329 bool exit_request;
330 bool in_exclusive_context;
331 uint32_t cflags_next_tb;
332 /* updates protected by BQL */
333 uint32_t interrupt_request;
334 int singlestep_enabled;
335 int64_t icount_budget;
336 int64_t icount_extra;
337 uint64_t random_seed;
338 sigjmp_buf jmp_env;
340 QemuMutex work_mutex;
341 QSIMPLEQ_HEAD(, qemu_work_item) work_list;
343 CPUAddressSpace *cpu_ases;
344 int num_ases;
345 AddressSpace *as;
346 MemoryRegion *memory;
348 void *env_ptr; /* CPUArchState */
349 IcountDecr *icount_decr_ptr;
351 /* Accessed in parallel; all accesses must be atomic */
352 TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
354 struct GDBRegisterState *gdb_regs;
355 int gdb_num_regs;
356 int gdb_num_g_regs;
357 QTAILQ_ENTRY(CPUState) node;
359 /* ice debug support */
360 QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
362 QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
363 CPUWatchpoint *watchpoint_hit;
365 void *opaque;
367 /* In order to avoid passing too many arguments to the MMIO helpers,
368 * we store some rarely used information in the CPU context.
370 uintptr_t mem_io_pc;
372 /* Only used in KVM */
373 int kvm_fd;
374 struct KVMState *kvm_state;
375 struct kvm_run *kvm_run;
376 struct kvm_dirty_gfn *kvm_dirty_gfns;
377 uint32_t kvm_fetch_index;
379 /* Used for events with 'vcpu' and *without* the 'disabled' properties */
380 DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
381 DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
383 DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX);
385 #ifdef CONFIG_PLUGIN
386 GArray *plugin_mem_cbs;
387 /* saved iotlb data from io_writex */
388 SavedIOTLB saved_iotlb;
389 #endif
391 /* TODO Move common fields from CPUArchState here. */
392 int cpu_index;
393 int cluster_index;
394 uint32_t tcg_cflags;
395 uint32_t halted;
396 uint32_t can_do_io;
397 int32_t exception_index;
399 /* shared by kvm, hax and hvf */
400 bool vcpu_dirty;
402 /* Used to keep track of an outstanding cpu throttle thread for migration
403 * autoconverge
405 bool throttle_thread_scheduled;
407 bool ignore_memory_transaction_failures;
409 struct hax_vcpu_state *hax_vcpu;
411 int hvf_fd;
413 /* track IOMMUs whose translations we've cached in the TCG TLB */
414 GArray *iommu_notifiers;
417 typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
418 extern CPUTailQ cpus;
420 #define first_cpu QTAILQ_FIRST_RCU(&cpus)
421 #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
422 #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
423 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
424 QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
426 extern __thread CPUState *current_cpu;
428 static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
430 unsigned int i;
432 for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
433 qatomic_set(&cpu->tb_jmp_cache[i], NULL);
438 * qemu_tcg_mttcg_enabled:
439 * Check whether we are running MultiThread TCG or not.
441 * Returns: %true if we are in MTTCG mode %false otherwise.
443 extern bool mttcg_enabled;
444 #define qemu_tcg_mttcg_enabled() (mttcg_enabled)
447 * cpu_paging_enabled:
448 * @cpu: The CPU whose state is to be inspected.
450 * Returns: %true if paging is enabled, %false otherwise.
452 bool cpu_paging_enabled(const CPUState *cpu);
455 * cpu_get_memory_mapping:
456 * @cpu: The CPU whose memory mappings are to be obtained.
457 * @list: Where to write the memory mappings to.
458 * @errp: Pointer for reporting an #Error.
460 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
461 Error **errp);
463 #if !defined(CONFIG_USER_ONLY)
466 * cpu_write_elf64_note:
467 * @f: pointer to a function that writes memory to a file
468 * @cpu: The CPU whose memory is to be dumped
469 * @cpuid: ID number of the CPU
470 * @opaque: pointer to the CPUState struct
472 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
473 int cpuid, void *opaque);
476 * cpu_write_elf64_qemunote:
477 * @f: pointer to a function that writes memory to a file
478 * @cpu: The CPU whose memory is to be dumped
479 * @cpuid: ID number of the CPU
480 * @opaque: pointer to the CPUState struct
482 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
483 void *opaque);
486 * cpu_write_elf32_note:
487 * @f: pointer to a function that writes memory to a file
488 * @cpu: The CPU whose memory is to be dumped
489 * @cpuid: ID number of the CPU
490 * @opaque: pointer to the CPUState struct
492 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
493 int cpuid, void *opaque);
496 * cpu_write_elf32_qemunote:
497 * @f: pointer to a function that writes memory to a file
498 * @cpu: The CPU whose memory is to be dumped
499 * @cpuid: ID number of the CPU
500 * @opaque: pointer to the CPUState struct
502 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
503 void *opaque);
506 * cpu_get_crash_info:
507 * @cpu: The CPU to get crash information for
509 * Gets the previously saved crash information.
510 * Caller is responsible for freeing the data.
512 GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
514 #endif /* !CONFIG_USER_ONLY */
517 * CPUDumpFlags:
518 * @CPU_DUMP_CODE:
519 * @CPU_DUMP_FPU: dump FPU register state, not just integer
520 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
522 enum CPUDumpFlags {
523 CPU_DUMP_CODE = 0x00010000,
524 CPU_DUMP_FPU = 0x00020000,
525 CPU_DUMP_CCOP = 0x00040000,
529 * cpu_dump_state:
530 * @cpu: The CPU whose state is to be dumped.
531 * @f: If non-null, dump to this stream, else to current print sink.
533 * Dumps CPU state.
535 void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
538 * cpu_dump_statistics:
539 * @cpu: The CPU whose state is to be dumped.
540 * @flags: Flags what to dump.
542 * Dump CPU statistics to the current monitor if we have one, else to
543 * stdout.
545 void cpu_dump_statistics(CPUState *cpu, int flags);
547 #ifndef CONFIG_USER_ONLY
549 * cpu_get_phys_page_attrs_debug:
550 * @cpu: The CPU to obtain the physical page address for.
551 * @addr: The virtual address.
552 * @attrs: Updated on return with the memory transaction attributes to use
553 * for this access.
555 * Obtains the physical page corresponding to a virtual one, together
556 * with the corresponding memory transaction attributes to use for the access.
557 * Use it only for debugging because no protection checks are done.
559 * Returns: Corresponding physical page address or -1 if no page found.
561 hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
562 MemTxAttrs *attrs);
565 * cpu_get_phys_page_debug:
566 * @cpu: The CPU to obtain the physical page address for.
567 * @addr: The virtual address.
569 * Obtains the physical page corresponding to a virtual one.
570 * Use it only for debugging because no protection checks are done.
572 * Returns: Corresponding physical page address or -1 if no page found.
574 hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
576 /** cpu_asidx_from_attrs:
577 * @cpu: CPU
578 * @attrs: memory transaction attributes
580 * Returns the address space index specifying the CPU AddressSpace
581 * to use for a memory access with the given transaction attributes.
583 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
586 * cpu_virtio_is_big_endian:
587 * @cpu: CPU
589 * Returns %true if a CPU which supports runtime configurable endianness
590 * is currently big-endian.
592 bool cpu_virtio_is_big_endian(CPUState *cpu);
594 #endif /* CONFIG_USER_ONLY */
597 * cpu_list_add:
598 * @cpu: The CPU to be added to the list of CPUs.
600 void cpu_list_add(CPUState *cpu);
603 * cpu_list_remove:
604 * @cpu: The CPU to be removed from the list of CPUs.
606 void cpu_list_remove(CPUState *cpu);
609 * cpu_reset:
610 * @cpu: The CPU whose state is to be reset.
612 void cpu_reset(CPUState *cpu);
615 * cpu_class_by_name:
616 * @typename: The CPU base type.
617 * @cpu_model: The model string without any parameters.
619 * Looks up a CPU #ObjectClass matching name @cpu_model.
621 * Returns: A #CPUClass or %NULL if not matching class is found.
623 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
626 * cpu_create:
627 * @typename: The CPU type.
629 * Instantiates a CPU and realizes the CPU.
631 * Returns: A #CPUState or %NULL if an error occurred.
633 CPUState *cpu_create(const char *typename);
636 * parse_cpu_option:
637 * @cpu_option: The -cpu option including optional parameters.
639 * processes optional parameters and registers them as global properties
641 * Returns: type of CPU to create or prints error and terminates process
642 * if an error occurred.
644 const char *parse_cpu_option(const char *cpu_option);
647 * cpu_has_work:
648 * @cpu: The vCPU to check.
650 * Checks whether the CPU has work to do.
652 * Returns: %true if the CPU has work, %false otherwise.
654 static inline bool cpu_has_work(CPUState *cpu)
656 CPUClass *cc = CPU_GET_CLASS(cpu);
658 g_assert(cc->has_work);
659 return cc->has_work(cpu);
663 * qemu_cpu_is_self:
664 * @cpu: The vCPU to check against.
666 * Checks whether the caller is executing on the vCPU thread.
668 * Returns: %true if called from @cpu's thread, %false otherwise.
670 bool qemu_cpu_is_self(CPUState *cpu);
673 * qemu_cpu_kick:
674 * @cpu: The vCPU to kick.
676 * Kicks @cpu's thread.
678 void qemu_cpu_kick(CPUState *cpu);
681 * cpu_is_stopped:
682 * @cpu: The CPU to check.
684 * Checks whether the CPU is stopped.
686 * Returns: %true if run state is not running or if artificially stopped;
687 * %false otherwise.
689 bool cpu_is_stopped(CPUState *cpu);
692 * do_run_on_cpu:
693 * @cpu: The vCPU to run on.
694 * @func: The function to be executed.
695 * @data: Data to pass to the function.
696 * @mutex: Mutex to release while waiting for @func to run.
698 * Used internally in the implementation of run_on_cpu.
700 void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
701 QemuMutex *mutex);
704 * run_on_cpu:
705 * @cpu: The vCPU to run on.
706 * @func: The function to be executed.
707 * @data: Data to pass to the function.
709 * Schedules the function @func for execution on the vCPU @cpu.
711 void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
714 * async_run_on_cpu:
715 * @cpu: The vCPU to run on.
716 * @func: The function to be executed.
717 * @data: Data to pass to the function.
719 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
721 void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
724 * async_safe_run_on_cpu:
725 * @cpu: The vCPU to run on.
726 * @func: The function to be executed.
727 * @data: Data to pass to the function.
729 * Schedules the function @func for execution on the vCPU @cpu asynchronously,
730 * while all other vCPUs are sleeping.
732 * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
733 * BQL.
735 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
738 * cpu_in_exclusive_context()
739 * @cpu: The vCPU to check
741 * Returns true if @cpu is an exclusive context, for example running
742 * something which has previously been queued via async_safe_run_on_cpu().
744 static inline bool cpu_in_exclusive_context(const CPUState *cpu)
746 return cpu->in_exclusive_context;
750 * qemu_get_cpu:
751 * @index: The CPUState@cpu_index value of the CPU to obtain.
753 * Gets a CPU matching @index.
755 * Returns: The CPU or %NULL if there is no matching CPU.
757 CPUState *qemu_get_cpu(int index);
760 * cpu_exists:
761 * @id: Guest-exposed CPU ID to lookup.
763 * Search for CPU with specified ID.
765 * Returns: %true - CPU is found, %false - CPU isn't found.
767 bool cpu_exists(int64_t id);
770 * cpu_by_arch_id:
771 * @id: Guest-exposed CPU ID of the CPU to obtain.
773 * Get a CPU with matching @id.
775 * Returns: The CPU or %NULL if there is no matching CPU.
777 CPUState *cpu_by_arch_id(int64_t id);
780 * cpu_interrupt:
781 * @cpu: The CPU to set an interrupt on.
782 * @mask: The interrupts to set.
784 * Invokes the interrupt handler.
787 void cpu_interrupt(CPUState *cpu, int mask);
790 * cpu_set_pc:
791 * @cpu: The CPU to set the program counter for.
792 * @addr: Program counter value.
794 * Sets the program counter for a CPU.
796 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
798 CPUClass *cc = CPU_GET_CLASS(cpu);
800 cc->set_pc(cpu, addr);
804 * cpu_reset_interrupt:
805 * @cpu: The CPU to clear the interrupt on.
806 * @mask: The interrupt mask to clear.
808 * Resets interrupts on the vCPU @cpu.
810 void cpu_reset_interrupt(CPUState *cpu, int mask);
813 * cpu_exit:
814 * @cpu: The CPU to exit.
816 * Requests the CPU @cpu to exit execution.
818 void cpu_exit(CPUState *cpu);
821 * cpu_resume:
822 * @cpu: The CPU to resume.
824 * Resumes CPU, i.e. puts CPU into runnable state.
826 void cpu_resume(CPUState *cpu);
829 * cpu_remove_sync:
830 * @cpu: The CPU to remove.
832 * Requests the CPU to be removed and waits till it is removed.
834 void cpu_remove_sync(CPUState *cpu);
837 * process_queued_cpu_work() - process all items on CPU work queue
838 * @cpu: The CPU which work queue to process.
840 void process_queued_cpu_work(CPUState *cpu);
843 * cpu_exec_start:
844 * @cpu: The CPU for the current thread.
846 * Record that a CPU has started execution and can be interrupted with
847 * cpu_exit.
849 void cpu_exec_start(CPUState *cpu);
852 * cpu_exec_end:
853 * @cpu: The CPU for the current thread.
855 * Record that a CPU has stopped execution and exclusive sections
856 * can be executed without interrupting it.
858 void cpu_exec_end(CPUState *cpu);
861 * start_exclusive:
863 * Wait for a concurrent exclusive section to end, and then start
864 * a section of work that is run while other CPUs are not running
865 * between cpu_exec_start and cpu_exec_end. CPUs that are running
866 * cpu_exec are exited immediately. CPUs that call cpu_exec_start
867 * during the exclusive section go to sleep until this CPU calls
868 * end_exclusive.
870 void start_exclusive(void);
873 * end_exclusive:
875 * Concludes an exclusive execution section started by start_exclusive.
877 void end_exclusive(void);
880 * qemu_init_vcpu:
881 * @cpu: The vCPU to initialize.
883 * Initializes a vCPU.
885 void qemu_init_vcpu(CPUState *cpu);
887 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
888 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
889 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
892 * cpu_single_step:
893 * @cpu: CPU to the flags for.
894 * @enabled: Flags to enable.
896 * Enables or disables single-stepping for @cpu.
898 void cpu_single_step(CPUState *cpu, int enabled);
900 /* Breakpoint/watchpoint flags */
901 #define BP_MEM_READ 0x01
902 #define BP_MEM_WRITE 0x02
903 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
904 #define BP_STOP_BEFORE_ACCESS 0x04
905 /* 0x08 currently unused */
906 #define BP_GDB 0x10
907 #define BP_CPU 0x20
908 #define BP_ANY (BP_GDB | BP_CPU)
909 #define BP_WATCHPOINT_HIT_READ 0x40
910 #define BP_WATCHPOINT_HIT_WRITE 0x80
911 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
913 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
914 CPUBreakpoint **breakpoint);
915 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
916 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
917 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
919 /* Return true if PC matches an installed breakpoint. */
920 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
922 CPUBreakpoint *bp;
924 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
925 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
926 if (bp->pc == pc && (bp->flags & mask)) {
927 return true;
931 return false;
934 #ifdef CONFIG_USER_ONLY
935 static inline int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
936 int flags, CPUWatchpoint **watchpoint)
938 return -ENOSYS;
941 static inline int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
942 vaddr len, int flags)
944 return -ENOSYS;
947 static inline void cpu_watchpoint_remove_by_ref(CPUState *cpu,
948 CPUWatchpoint *wp)
952 static inline void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
956 static inline void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
957 MemTxAttrs atr, int fl, uintptr_t ra)
961 static inline int cpu_watchpoint_address_matches(CPUState *cpu,
962 vaddr addr, vaddr len)
964 return 0;
966 #else
967 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
968 int flags, CPUWatchpoint **watchpoint);
969 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
970 vaddr len, int flags);
971 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
972 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
975 * cpu_check_watchpoint:
976 * @cpu: cpu context
977 * @addr: guest virtual address
978 * @len: access length
979 * @attrs: memory access attributes
980 * @flags: watchpoint access type
981 * @ra: unwind return address
983 * Check for a watchpoint hit in [addr, addr+len) of the type
984 * specified by @flags. Exit via exception with a hit.
986 void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
987 MemTxAttrs attrs, int flags, uintptr_t ra);
990 * cpu_watchpoint_address_matches:
991 * @cpu: cpu context
992 * @addr: guest virtual address
993 * @len: access length
995 * Return the watchpoint flags that apply to [addr, addr+len).
996 * If no watchpoint is registered for the range, the result is 0.
998 int cpu_watchpoint_address_matches(CPUState *cpu, vaddr addr, vaddr len);
999 #endif
1002 * cpu_get_address_space:
1003 * @cpu: CPU to get address space from
1004 * @asidx: index identifying which address space to get
1006 * Return the requested address space of this CPU. @asidx
1007 * specifies which address space to read.
1009 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
1011 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
1012 GCC_FMT_ATTR(2, 3);
1014 /* $(top_srcdir)/cpu.c */
1015 void cpu_exec_initfn(CPUState *cpu);
1016 void cpu_exec_realizefn(CPUState *cpu, Error **errp);
1017 void cpu_exec_unrealizefn(CPUState *cpu);
1020 * target_words_bigendian:
1021 * Returns true if the (default) endianness of the target is big endian,
1022 * false otherwise. Note that in target-specific code, you can use
1023 * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
1024 * code should normally never need to know about the endianness of the
1025 * target, so please do *not* use this function unless you know very well
1026 * what you are doing!
1028 bool target_words_bigendian(void);
1030 #ifdef NEED_CPU_H
1032 #ifdef CONFIG_SOFTMMU
1034 extern const VMStateDescription vmstate_cpu_common;
1036 #define VMSTATE_CPU() { \
1037 .name = "parent_obj", \
1038 .size = sizeof(CPUState), \
1039 .vmsd = &vmstate_cpu_common, \
1040 .flags = VMS_STRUCT, \
1041 .offset = 0, \
1043 #endif /* CONFIG_SOFTMMU */
1045 #endif /* NEED_CPU_H */
1047 #define UNASSIGNED_CPU_INDEX -1
1048 #define UNASSIGNED_CLUSTER_INDEX -1
1050 #endif