]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/core/cpu.h
trace: add mmu_index to mem_info
[mirror_qemu.git] / include / hw / core / cpu.h
CommitLineData
dd83b06a
AF
1/*
2 * QEMU CPU model
3 *
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
19 */
20#ifndef QEMU_CPU_H
21#define QEMU_CPU_H
22
961f8395 23#include "hw/qdev-core.h"
3979fca4 24#include "disas/dis-asm.h"
c658b94f 25#include "exec/hwaddr.h"
66b9b43c 26#include "exec/memattrs.h"
9af23989 27#include "qapi/qapi-types-run-state.h"
48151859 28#include "qemu/bitmap.h"
068a5ea0 29#include "qemu/rcu_queue.h"
bdc44640 30#include "qemu/queue.h"
1de7afc9 31#include "qemu/thread.h"
dd83b06a 32
b5ba1cc6
QN
33typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
34 void *opaque);
c72bf468 35
577f42c0
AF
36/**
37 * vaddr:
38 * Type wide enough to contain any #target_ulong virtual address.
39 */
40typedef uint64_t vaddr;
41#define VADDR_PRId PRId64
42#define VADDR_PRIu PRIu64
43#define VADDR_PRIo PRIo64
44#define VADDR_PRIx PRIx64
45#define VADDR_PRIX PRIX64
46#define VADDR_MAX UINT64_MAX
47
dd83b06a
AF
48/**
49 * SECTION:cpu
50 * @section_id: QEMU-cpu
51 * @title: CPU Class
52 * @short_description: Base class for all CPUs
53 */
54
55#define TYPE_CPU "cpu"
56
0d6d1ab4
AF
57/* Since this macro is used a lot in hot code paths and in conjunction with
58 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
59 * an unchecked cast.
60 */
61#define CPU(obj) ((CPUState *)(obj))
62
dd83b06a
AF
63#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
64#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
65
b35399bb
SS
66typedef enum MMUAccessType {
67 MMU_DATA_LOAD = 0,
68 MMU_DATA_STORE = 1,
69 MMU_INST_FETCH = 2
70} MMUAccessType;
71
568496c0 72typedef struct CPUWatchpoint CPUWatchpoint;
dd83b06a 73
c658b94f
AF
74typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
75 bool is_write, bool is_exec, int opaque,
76 unsigned size);
77
bdf7ae5b
AF
78struct TranslationBlock;
79
dd83b06a
AF
80/**
81 * CPUClass:
2b8c2754
AF
82 * @class_by_name: Callback to map -cpu command line model name to an
83 * instantiatable CPU type.
94a444b2 84 * @parse_features: Callback to parse command line arguments.
f5df5baf 85 * @reset: Callback to reset the #CPUState to its initial state.
91b1df8c 86 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
8c2e1b00 87 * @has_work: Callback for checking if there is work to do.
97a8ea5a 88 * @do_interrupt: Callback for interrupt handling.
c658b94f 89 * @do_unassigned_access: Callback for unassigned access handling.
0dff0939 90 * (this is deprecated: new targets should use do_transaction_failed instead)
93e22326 91 * @do_unaligned_access: Callback for unaligned access handling, if
52bf9771 92 * the target defines #TARGET_ALIGNED_ONLY.
0dff0939
PM
93 * @do_transaction_failed: Callback for handling failed memory transactions
94 * (ie bus faults or external aborts; not MMU faults)
c08295d4
PM
95 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
96 * runtime configurable endianness is currently big-endian. Non-configurable
97 * CPUs can use the default implementation of this method. This method should
98 * not be used by any callers other than the pre-1.0 virtio devices.
f3659eee 99 * @memory_rw_debug: Callback for GDB memory access.
878096ee
AF
100 * @dump_state: Callback for dumping state.
101 * @dump_statistics: Callback for dumping statistics.
997395d3 102 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
444d5590 103 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
a23bbfda 104 * @get_memory_mapping: Callback for obtaining the memory mappings.
42f6ed91
JS
105 * @set_pc: Callback for setting the Program Counter register. This
106 * should have the semantics used by the target architecture when
107 * setting the PC from a source such as an ELF file entry point;
108 * for example on Arm it will also set the Thumb mode bit based
109 * on the least significant bit of the new PC value.
110 * If the target behaviour here is anything other than "set
111 * the PC register to the value passed in" then the target must
112 * also implement the synchronize_from_tb hook.
bdf7ae5b 113 * @synchronize_from_tb: Callback for synchronizing state from a TCG
42f6ed91
JS
114 * #TranslationBlock. This is called when we abandon execution
115 * of a TB before starting it, and must set all parts of the CPU
116 * state which the previous TB in the chain may not have updated.
117 * This always includes at least the program counter; some targets
118 * will need to do more. If this hook is not implemented then the
119 * default is to call @set_pc(tb->pc).
da6bbf85
RH
120 * @tlb_fill: Callback for handling a softmmu tlb miss or user-only
121 * address fault. For system mode, if the access is valid, call
122 * tlb_set_page and return true; if the access is invalid, and
123 * probe is true, return false; otherwise raise an exception and
124 * do not return. For user-only mode, always raise an exception
125 * and do not return.
00b941e5 126 * @get_phys_page_debug: Callback for obtaining a physical address.
1dc6fb1f
PM
127 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
128 * associated memory transaction attributes to use for the access.
129 * CPUs which use memory transaction attributes should implement this
130 * instead of get_phys_page_debug.
d7f25a9e
PM
131 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
132 * a memory access with the specified memory transaction attributes.
5b50e790
AF
133 * @gdb_read_register: Callback for letting GDB read a register.
134 * @gdb_write_register: Callback for letting GDB write a register.
568496c0
SF
135 * @debug_check_watchpoint: Callback: return true if the architectural
136 * watchpoint whose address has matched should really fire.
86025ee4 137 * @debug_excp_handler: Callback for handling debug exceptions.
c08295d4
PM
138 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
139 * 64-bit VM coredump.
140 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
141 * note to a 32-bit VM coredump.
142 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
143 * 32-bit VM coredump.
144 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
145 * note to a 32-bit VM coredump.
b170fce3 146 * @vmsd: State description for migration.
a0e372f0 147 * @gdb_num_core_regs: Number of core registers accessible to GDB.
5b24c641 148 * @gdb_core_xml_file: File name for core registers GDB XML description.
2472b6c0
PM
149 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
150 * before the insn which triggers a watchpoint rather than after it.
b3820e6c
DH
151 * @gdb_arch_name: Optional callback that returns the architecture name known
152 * to GDB. The caller must free the returned string with g_free.
200bf5b7
AB
153 * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the
154 * gdb stub. Returns a pointer to the XML contents for the specified XML file
155 * or NULL if the CPU doesn't have a dynamically generated content for it.
cffe7b32
RH
156 * @cpu_exec_enter: Callback for cpu_exec preparation.
157 * @cpu_exec_exit: Callback for cpu_exec cleanup.
9585db68 158 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
37b9de46 159 * @disas_set_info: Setup architecture specific components of disassembly info
40612000
JB
160 * @adjust_watchpoint_address: Perform a target-specific adjustment to an
161 * address before attempting to match it against watchpoints.
dd83b06a
AF
162 *
163 * Represents a CPU family or model.
164 */
165typedef struct CPUClass {
166 /*< private >*/
961f8395 167 DeviceClass parent_class;
dd83b06a
AF
168 /*< public >*/
169
2b8c2754 170 ObjectClass *(*class_by_name)(const char *cpu_model);
62a48a2a 171 void (*parse_features)(const char *typename, char *str, Error **errp);
2b8c2754 172
dd83b06a 173 void (*reset)(CPUState *cpu);
91b1df8c 174 int reset_dump_flags;
8c2e1b00 175 bool (*has_work)(CPUState *cpu);
97a8ea5a 176 void (*do_interrupt)(CPUState *cpu);
c658b94f 177 CPUUnassignedAccess do_unassigned_access;
93e22326 178 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
b35399bb
SS
179 MMUAccessType access_type,
180 int mmu_idx, uintptr_t retaddr);
0dff0939
PM
181 void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
182 unsigned size, MMUAccessType access_type,
183 int mmu_idx, MemTxAttrs attrs,
184 MemTxResult response, uintptr_t retaddr);
bf7663c4 185 bool (*virtio_is_big_endian)(CPUState *cpu);
f3659eee
AF
186 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
187 uint8_t *buf, int len, bool is_write);
90c84c56 188 void (*dump_state)(CPUState *cpu, FILE *, int flags);
c86f106b 189 GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
11cb6c15 190 void (*dump_statistics)(CPUState *cpu, int flags);
997395d3 191 int64_t (*get_arch_id)(CPUState *cpu);
444d5590 192 bool (*get_paging_enabled)(const CPUState *cpu);
a23bbfda
AF
193 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
194 Error **errp);
f45748f1 195 void (*set_pc)(CPUState *cpu, vaddr value);
bdf7ae5b 196 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
da6bbf85
RH
197 bool (*tlb_fill)(CPUState *cpu, vaddr address, int size,
198 MMUAccessType access_type, int mmu_idx,
199 bool probe, uintptr_t retaddr);
00b941e5 200 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
1dc6fb1f
PM
201 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
202 MemTxAttrs *attrs);
d7f25a9e 203 int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
5b50e790
AF
204 int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
205 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
568496c0 206 bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
86025ee4 207 void (*debug_excp_handler)(CPUState *cpu);
b170fce3 208
c72bf468
JF
209 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
210 int cpuid, void *opaque);
211 int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
212 void *opaque);
213 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
214 int cpuid, void *opaque);
215 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
216 void *opaque);
a0e372f0 217
8a9358cc 218 const VMStateDescription *vmsd;
5b24c641 219 const char *gdb_core_xml_file;
b3820e6c 220 gchar * (*gdb_arch_name)(CPUState *cpu);
200bf5b7 221 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
cffe7b32
RH
222 void (*cpu_exec_enter)(CPUState *cpu);
223 void (*cpu_exec_exit)(CPUState *cpu);
9585db68 224 bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
37b9de46
PC
225
226 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
40612000 227 vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
55c3ceef
RH
228 void (*tcg_initialize)(void);
229
230 /* Keep non-pointer data at the end to minimize holes. */
231 int gdb_num_core_regs;
232 bool gdb_stop_before_watchpoint;
dd83b06a
AF
233} CPUClass;
234
5e140196
RH
235/*
236 * Low 16 bits: number of cycles left, used only in icount mode.
237 * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
238 * for this CPU and return to its top level loop (even in non-icount mode).
239 * This allows a single read-compare-cbranch-write sequence to test
240 * for both decrementer underflow and exceptions.
241 */
242typedef union IcountDecr {
243 uint32_t u32;
244 struct {
28ecfd7a 245#ifdef HOST_WORDS_BIGENDIAN
5e140196
RH
246 uint16_t high;
247 uint16_t low;
28ecfd7a 248#else
5e140196
RH
249 uint16_t low;
250 uint16_t high;
28ecfd7a 251#endif
5e140196
RH
252 } u16;
253} IcountDecr;
28ecfd7a 254
f0c3c505
AF
255typedef struct CPUBreakpoint {
256 vaddr pc;
257 int flags; /* BP_* */
258 QTAILQ_ENTRY(CPUBreakpoint) entry;
259} CPUBreakpoint;
260
568496c0 261struct CPUWatchpoint {
ff4700b0 262 vaddr vaddr;
05068c0d 263 vaddr len;
08225676 264 vaddr hitaddr;
66b9b43c 265 MemTxAttrs hitattrs;
ff4700b0
AF
266 int flags; /* BP_* */
267 QTAILQ_ENTRY(CPUWatchpoint) entry;
568496c0 268};
ff4700b0 269
a60f24b5 270struct KVMState;
f7575c96 271struct kvm_run;
a60f24b5 272
b0cb0a66
VP
273struct hax_vcpu_state;
274
8cd70437
AF
275#define TB_JMP_CACHE_BITS 12
276#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
277
4b4629d9 278/* work queue */
14e6fe12
PB
279
280/* The union type allows passing of 64 bit target pointers on 32 bit
281 * hosts in a single parameter
282 */
283typedef union {
284 int host_int;
285 unsigned long host_ulong;
286 void *host_ptr;
287 vaddr target_ptr;
288} run_on_cpu_data;
289
290#define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
291#define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
292#define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
293#define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
294#define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
295
296typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
297
d148d90e 298struct qemu_work_item;
4b4629d9 299
0b8497f0 300#define CPU_UNSET_NUMA_NODE_ID -1
d01c05c9 301#define CPU_TRACE_DSTATE_MAX_EVENTS 32
0b8497f0 302
dd83b06a
AF
303/**
304 * CPUState:
55e5c285 305 * @cpu_index: CPU index (informative).
7ea7b9ad
PM
306 * @cluster_index: Identifies which cluster this CPU is in.
307 * For boards which don't define clusters or for "loose" CPUs not assigned
308 * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
309 * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
310 * QOM parent.
ce3960eb
AF
311 * @nr_cores: Number of cores within this CPU package.
312 * @nr_threads: Number of threads within this CPU.
c265e976
PB
313 * @running: #true if CPU is currently running (lockless).
314 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
ab129972 315 * valid under cpu_list_lock.
61a46217 316 * @created: Indicates whether the CPU thread has been successfully created.
259186a7
AF
317 * @interrupt_request: Indicates a pending interrupt request.
318 * @halted: Nonzero if the CPU is in suspended state.
4fdeee7c 319 * @stop: Indicates a pending stop request.
f324e766 320 * @stopped: Indicates the CPU has been artificially stopped.
4c055ab5 321 * @unplug: Indicates a pending CPU unplug request.
bac05aa9 322 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
ed2803da 323 * @singlestep_enabled: Flags for single-stepping.
efee7340 324 * @icount_extra: Instructions until next timer event.
414b15c9
PB
325 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
326 * requires that IO only be performed on the last instruction of a TB
327 * so that interrupts take effect immediately.
32857f4d
PM
328 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
329 * AddressSpaces this CPU has)
12ebc9a7 330 * @num_ases: number of CPUAddressSpaces in @cpu_ases
32857f4d
PM
331 * @as: Pointer to the first AddressSpace, for the convenience of targets which
332 * only have a single AddressSpace
c05efcb1 333 * @env_ptr: Pointer to subclass-specific CPUArchState field.
5e140196 334 * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
eac8b355 335 * @gdb_regs: Additional GDB registers.
a0e372f0 336 * @gdb_num_regs: Number of total registers accessible to GDB.
35143f01 337 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
182735ef 338 * @next_cpu: Next CPU sharing TB cache.
0429a971 339 * @opaque: User data.
93afeade 340 * @mem_io_pc: Host Program Counter at which the memory was accessed.
8737c51c 341 * @kvm_fd: vCPU file descriptor for KVM.
376692b9
PB
342 * @work_mutex: Lock to prevent multiple access to queued_work_*.
343 * @queued_work_first: First asynchronous work pending.
d4381116
LV
344 * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
345 * to @trace_dstate).
48151859 346 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
ed860129
PM
347 * @ignore_memory_transaction_failures: Cached copy of the MachineState
348 * flag of the same name: allows the board to suppress calling of the
349 * CPU do_transaction_failed hook function.
dd83b06a
AF
350 *
351 * State of one CPU core or thread.
352 */
353struct CPUState {
354 /*< private >*/
961f8395 355 DeviceState parent_obj;
dd83b06a
AF
356 /*< public >*/
357
ce3960eb
AF
358 int nr_cores;
359 int nr_threads;
360
814e612e 361 struct QemuThread *thread;
bcba2a72
AF
362#ifdef _WIN32
363 HANDLE hThread;
364#endif
9f09e18a 365 int thread_id;
c265e976 366 bool running, has_waiter;
f5c121b8 367 struct QemuCond *halt_cond;
216fc9a4 368 bool thread_kicked;
61a46217 369 bool created;
4fdeee7c 370 bool stop;
f324e766 371 bool stopped;
4c055ab5 372 bool unplug;
bac05aa9 373 bool crash_occurred;
e0c38211 374 bool exit_request;
9b990ee5 375 uint32_t cflags_next_tb;
8d04fb55 376 /* updates protected by BQL */
259186a7 377 uint32_t interrupt_request;
ed2803da 378 int singlestep_enabled;
e4cd9657 379 int64_t icount_budget;
efee7340 380 int64_t icount_extra;
9c09a251 381 uint64_t random_seed;
6f03bef0 382 sigjmp_buf jmp_env;
bcba2a72 383
376692b9
PB
384 QemuMutex work_mutex;
385 struct qemu_work_item *queued_work_first, *queued_work_last;
386
32857f4d 387 CPUAddressSpace *cpu_ases;
12ebc9a7 388 int num_ases;
09daed84 389 AddressSpace *as;
6731d864 390 MemoryRegion *memory;
09daed84 391
c05efcb1 392 void *env_ptr; /* CPUArchState */
5e140196 393 IcountDecr *icount_decr_ptr;
7d7500d9 394
f3ced3c5 395 /* Accessed in parallel; all accesses must be atomic */
8cd70437 396 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
7d7500d9 397
eac8b355 398 struct GDBRegisterState *gdb_regs;
a0e372f0 399 int gdb_num_regs;
35143f01 400 int gdb_num_g_regs;
bdc44640 401 QTAILQ_ENTRY(CPUState) node;
d77953b9 402
f0c3c505 403 /* ice debug support */
b58deb34 404 QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
f0c3c505 405
b58deb34 406 QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
ff4700b0
AF
407 CPUWatchpoint *watchpoint_hit;
408
0429a971
AF
409 void *opaque;
410
93afeade
AF
411 /* In order to avoid passing too many arguments to the MMIO helpers,
412 * we store some rarely used information in the CPU context.
413 */
414 uintptr_t mem_io_pc;
dbea78a4
PM
415 /*
416 * This is only needed for the legacy cpu_unassigned_access() hook;
417 * when all targets using it have been converted to use
418 * cpu_transaction_failed() instead it can be removed.
419 */
420 MMUAccessType mem_io_access_type;
93afeade 421
8737c51c 422 int kvm_fd;
a60f24b5 423 struct KVMState *kvm_state;
f7575c96 424 struct kvm_run *kvm_run;
8737c51c 425
d01c05c9 426 /* Used for events with 'vcpu' and *without* the 'disabled' properties */
d4381116 427 DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
d01c05c9 428 DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
48151859 429
f5df5baf 430 /* TODO Move common fields from CPUArchState here. */
6fda014e 431 int cpu_index;
7ea7b9ad 432 int cluster_index;
6fda014e 433 uint32_t halted;
99df7dce 434 uint32_t can_do_io;
6fda014e 435 int32_t exception_index;
7e4fb26d 436
99f31832
SAGDR
437 /* shared by kvm, hax and hvf */
438 bool vcpu_dirty;
439
2adcc85d
JH
440 /* Used to keep track of an outstanding cpu throttle thread for migration
441 * autoconverge
442 */
443 bool throttle_thread_scheduled;
444
ed860129
PM
445 bool ignore_memory_transaction_failures;
446
b0cb0a66 447 struct hax_vcpu_state *hax_vcpu;
e3b9ca81 448
c97d6d2c 449 int hvf_fd;
1f871c5e
PM
450
451 /* track IOMMUs whose translations we've cached in the TCG TLB */
452 GArray *iommu_notifiers;
dd83b06a
AF
453};
454
f481ee2d
PB
455typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
456extern CPUTailQ cpus;
457
068a5ea0
EC
458#define first_cpu QTAILQ_FIRST_RCU(&cpus)
459#define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
460#define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
bdc44640 461#define CPU_FOREACH_SAFE(cpu, next_cpu) \
068a5ea0 462 QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
182735ef 463
f240eb6f 464extern __thread CPUState *current_cpu;
4917cf44 465
f3ced3c5
EC
466static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
467{
468 unsigned int i;
469
470 for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
471 atomic_set(&cpu->tb_jmp_cache[i], NULL);
472 }
473}
474
8d4e9146
FK
475/**
476 * qemu_tcg_mttcg_enabled:
477 * Check whether we are running MultiThread TCG or not.
478 *
479 * Returns: %true if we are in MTTCG mode %false otherwise.
480 */
481extern bool mttcg_enabled;
482#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
483
444d5590
AF
484/**
485 * cpu_paging_enabled:
486 * @cpu: The CPU whose state is to be inspected.
487 *
488 * Returns: %true if paging is enabled, %false otherwise.
489 */
490bool cpu_paging_enabled(const CPUState *cpu);
491
a23bbfda
AF
492/**
493 * cpu_get_memory_mapping:
494 * @cpu: The CPU whose memory mappings are to be obtained.
495 * @list: Where to write the memory mappings to.
496 * @errp: Pointer for reporting an #Error.
497 */
498void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
499 Error **errp);
500
c72bf468
JF
501/**
502 * cpu_write_elf64_note:
503 * @f: pointer to a function that writes memory to a file
504 * @cpu: The CPU whose memory is to be dumped
505 * @cpuid: ID number of the CPU
506 * @opaque: pointer to the CPUState struct
507 */
508int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
509 int cpuid, void *opaque);
510
511/**
512 * cpu_write_elf64_qemunote:
513 * @f: pointer to a function that writes memory to a file
514 * @cpu: The CPU whose memory is to be dumped
515 * @cpuid: ID number of the CPU
516 * @opaque: pointer to the CPUState struct
517 */
518int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
519 void *opaque);
520
521/**
522 * cpu_write_elf32_note:
523 * @f: pointer to a function that writes memory to a file
524 * @cpu: The CPU whose memory is to be dumped
525 * @cpuid: ID number of the CPU
526 * @opaque: pointer to the CPUState struct
527 */
528int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
529 int cpuid, void *opaque);
530
531/**
532 * cpu_write_elf32_qemunote:
533 * @f: pointer to a function that writes memory to a file
534 * @cpu: The CPU whose memory is to be dumped
535 * @cpuid: ID number of the CPU
536 * @opaque: pointer to the CPUState struct
537 */
538int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
539 void *opaque);
dd83b06a 540
c86f106b
AN
541/**
542 * cpu_get_crash_info:
543 * @cpu: The CPU to get crash information for
544 *
545 * Gets the previously saved crash information.
546 * Caller is responsible for freeing the data.
547 */
548GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
549
878096ee
AF
550/**
551 * CPUDumpFlags:
552 * @CPU_DUMP_CODE:
553 * @CPU_DUMP_FPU: dump FPU register state, not just integer
554 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
555 */
556enum CPUDumpFlags {
557 CPU_DUMP_CODE = 0x00010000,
558 CPU_DUMP_FPU = 0x00020000,
559 CPU_DUMP_CCOP = 0x00040000,
560};
561
562/**
563 * cpu_dump_state:
564 * @cpu: The CPU whose state is to be dumped.
90c84c56 565 * @f: If non-null, dump to this stream, else to current print sink.
878096ee
AF
566 *
567 * Dumps CPU state.
568 */
90c84c56 569void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
878096ee
AF
570
571/**
572 * cpu_dump_statistics:
573 * @cpu: The CPU whose state is to be dumped.
878096ee
AF
574 * @flags: Flags what to dump.
575 *
11cb6c15
MA
576 * Dump CPU statistics to the current monitor if we have one, else to
577 * stdout.
878096ee 578 */
11cb6c15 579void cpu_dump_statistics(CPUState *cpu, int flags);
878096ee 580
00b941e5 581#ifndef CONFIG_USER_ONLY
1dc6fb1f
PM
582/**
583 * cpu_get_phys_page_attrs_debug:
584 * @cpu: The CPU to obtain the physical page address for.
585 * @addr: The virtual address.
586 * @attrs: Updated on return with the memory transaction attributes to use
587 * for this access.
588 *
589 * Obtains the physical page corresponding to a virtual one, together
590 * with the corresponding memory transaction attributes to use for the access.
591 * Use it only for debugging because no protection checks are done.
592 *
593 * Returns: Corresponding physical page address or -1 if no page found.
594 */
595static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
596 MemTxAttrs *attrs)
597{
598 CPUClass *cc = CPU_GET_CLASS(cpu);
599
600 if (cc->get_phys_page_attrs_debug) {
601 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
602 }
603 /* Fallback for CPUs which don't implement the _attrs_ hook */
604 *attrs = MEMTXATTRS_UNSPECIFIED;
605 return cc->get_phys_page_debug(cpu, addr);
606}
607
00b941e5
AF
608/**
609 * cpu_get_phys_page_debug:
610 * @cpu: The CPU to obtain the physical page address for.
611 * @addr: The virtual address.
612 *
613 * Obtains the physical page corresponding to a virtual one.
614 * Use it only for debugging because no protection checks are done.
615 *
616 * Returns: Corresponding physical page address or -1 if no page found.
617 */
618static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
619{
1dc6fb1f 620 MemTxAttrs attrs = {};
00b941e5 621
1dc6fb1f 622 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
00b941e5 623}
d7f25a9e
PM
624
625/** cpu_asidx_from_attrs:
626 * @cpu: CPU
627 * @attrs: memory transaction attributes
628 *
629 * Returns the address space index specifying the CPU AddressSpace
630 * to use for a memory access with the given transaction attributes.
631 */
632static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
633{
634 CPUClass *cc = CPU_GET_CLASS(cpu);
9c8c334b 635 int ret = 0;
d7f25a9e
PM
636
637 if (cc->asidx_from_attrs) {
9c8c334b
RH
638 ret = cc->asidx_from_attrs(cpu, attrs);
639 assert(ret < cpu->num_ases && ret >= 0);
d7f25a9e 640 }
9c8c334b 641 return ret;
d7f25a9e 642}
00b941e5
AF
643#endif
644
267f685b
PB
645/**
646 * cpu_list_add:
647 * @cpu: The CPU to be added to the list of CPUs.
648 */
649void cpu_list_add(CPUState *cpu);
650
651/**
652 * cpu_list_remove:
653 * @cpu: The CPU to be removed from the list of CPUs.
654 */
655void cpu_list_remove(CPUState *cpu);
656
dd83b06a
AF
657/**
658 * cpu_reset:
659 * @cpu: The CPU whose state is to be reset.
660 */
661void cpu_reset(CPUState *cpu);
662
2b8c2754
AF
663/**
664 * cpu_class_by_name:
665 * @typename: The CPU base type.
666 * @cpu_model: The model string without any parameters.
667 *
668 * Looks up a CPU #ObjectClass matching name @cpu_model.
669 *
670 * Returns: A #CPUClass or %NULL if not matching class is found.
671 */
672ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
673
3c72234c
IM
674/**
675 * cpu_create:
676 * @typename: The CPU type.
677 *
678 * Instantiates a CPU and realizes the CPU.
679 *
680 * Returns: A #CPUState or %NULL if an error occurred.
681 */
682CPUState *cpu_create(const char *typename);
683
684/**
c1c8cfe5
EH
685 * parse_cpu_option:
686 * @cpu_option: The -cpu option including optional parameters.
3c72234c
IM
687 *
688 * processes optional parameters and registers them as global properties
689 *
4482e05c
IM
690 * Returns: type of CPU to create or prints error and terminates process
691 * if an error occurred.
3c72234c 692 */
c1c8cfe5 693const char *parse_cpu_option(const char *cpu_option);
9262685b 694
3993c6bd 695/**
8c2e1b00 696 * cpu_has_work:
3993c6bd
AF
697 * @cpu: The vCPU to check.
698 *
699 * Checks whether the CPU has work to do.
700 *
701 * Returns: %true if the CPU has work, %false otherwise.
702 */
8c2e1b00
AF
703static inline bool cpu_has_work(CPUState *cpu)
704{
705 CPUClass *cc = CPU_GET_CLASS(cpu);
706
707 g_assert(cc->has_work);
708 return cc->has_work(cpu);
709}
3993c6bd 710
60e82579
AF
711/**
712 * qemu_cpu_is_self:
713 * @cpu: The vCPU to check against.
714 *
715 * Checks whether the caller is executing on the vCPU thread.
716 *
717 * Returns: %true if called from @cpu's thread, %false otherwise.
718 */
719bool qemu_cpu_is_self(CPUState *cpu);
720
c08d7424
AF
721/**
722 * qemu_cpu_kick:
723 * @cpu: The vCPU to kick.
724 *
725 * Kicks @cpu's thread.
726 */
727void qemu_cpu_kick(CPUState *cpu);
728
2fa45344
AF
729/**
730 * cpu_is_stopped:
731 * @cpu: The CPU to check.
732 *
733 * Checks whether the CPU is stopped.
734 *
735 * Returns: %true if run state is not running or if artificially stopped;
736 * %false otherwise.
737 */
738bool cpu_is_stopped(CPUState *cpu);
739
d148d90e
SF
740/**
741 * do_run_on_cpu:
742 * @cpu: The vCPU to run on.
743 * @func: The function to be executed.
744 * @data: Data to pass to the function.
745 * @mutex: Mutex to release while waiting for @func to run.
746 *
747 * Used internally in the implementation of run_on_cpu.
748 */
14e6fe12 749void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
d148d90e
SF
750 QemuMutex *mutex);
751
f100f0b3
AF
752/**
753 * run_on_cpu:
754 * @cpu: The vCPU to run on.
755 * @func: The function to be executed.
756 * @data: Data to pass to the function.
757 *
758 * Schedules the function @func for execution on the vCPU @cpu.
759 */
14e6fe12 760void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
f100f0b3 761
3c02270d
CV
762/**
763 * async_run_on_cpu:
764 * @cpu: The vCPU to run on.
765 * @func: The function to be executed.
766 * @data: Data to pass to the function.
767 *
768 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
769 */
14e6fe12 770void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
3c02270d 771
53f5ed95
PB
772/**
773 * async_safe_run_on_cpu:
774 * @cpu: The vCPU to run on.
775 * @func: The function to be executed.
776 * @data: Data to pass to the function.
777 *
778 * Schedules the function @func for execution on the vCPU @cpu asynchronously,
779 * while all other vCPUs are sleeping.
780 *
781 * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
782 * BQL.
783 */
14e6fe12 784void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
53f5ed95 785
38d8f5c8
AF
786/**
787 * qemu_get_cpu:
788 * @index: The CPUState@cpu_index value of the CPU to obtain.
789 *
790 * Gets a CPU matching @index.
791 *
792 * Returns: The CPU or %NULL if there is no matching CPU.
793 */
794CPUState *qemu_get_cpu(int index);
795
69e5ff06
IM
796/**
797 * cpu_exists:
798 * @id: Guest-exposed CPU ID to lookup.
799 *
800 * Search for CPU with specified ID.
801 *
802 * Returns: %true - CPU is found, %false - CPU isn't found.
803 */
804bool cpu_exists(int64_t id);
805
5ce46cb3
EH
806/**
807 * cpu_by_arch_id:
808 * @id: Guest-exposed CPU ID of the CPU to obtain.
809 *
810 * Get a CPU with matching @id.
811 *
812 * Returns: The CPU or %NULL if there is no matching CPU.
813 */
814CPUState *cpu_by_arch_id(int64_t id);
815
2adcc85d
JH
816/**
817 * cpu_throttle_set:
818 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
819 *
820 * Throttles all vcpus by forcing them to sleep for the given percentage of
821 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
822 * (example: 10ms sleep for every 30ms awake).
823 *
824 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
825 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
826 * is called.
827 */
828void cpu_throttle_set(int new_throttle_pct);
829
830/**
831 * cpu_throttle_stop:
832 *
833 * Stops the vcpu throttling started by cpu_throttle_set.
834 */
835void cpu_throttle_stop(void);
836
837/**
838 * cpu_throttle_active:
839 *
840 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
841 */
842bool cpu_throttle_active(void);
843
844/**
845 * cpu_throttle_get_percentage:
846 *
847 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
848 *
849 * Returns: The throttle percentage in range 1 to 99.
850 */
851int cpu_throttle_get_percentage(void);
852
c3affe56
AF
853#ifndef CONFIG_USER_ONLY
854
855typedef void (*CPUInterruptHandler)(CPUState *, int);
856
857extern CPUInterruptHandler cpu_interrupt_handler;
858
859/**
860 * cpu_interrupt:
861 * @cpu: The CPU to set an interrupt on.
7e63bc38 862 * @mask: The interrupts to set.
c3affe56
AF
863 *
864 * Invokes the interrupt handler.
865 */
866static inline void cpu_interrupt(CPUState *cpu, int mask)
867{
868 cpu_interrupt_handler(cpu, mask);
869}
870
871#else /* USER_ONLY */
872
873void cpu_interrupt(CPUState *cpu, int mask);
874
875#endif /* USER_ONLY */
876
47507383
TH
877#ifdef NEED_CPU_H
878
93e22326 879#ifdef CONFIG_SOFTMMU
c658b94f
AF
880static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
881 bool is_write, bool is_exec,
882 int opaque, unsigned size)
883{
884 CPUClass *cc = CPU_GET_CLASS(cpu);
885
886 if (cc->do_unassigned_access) {
887 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
888 }
889}
890
93e22326 891static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
b35399bb
SS
892 MMUAccessType access_type,
893 int mmu_idx, uintptr_t retaddr)
93e22326
PB
894{
895 CPUClass *cc = CPU_GET_CLASS(cpu);
896
b35399bb 897 cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
93e22326 898}
0dff0939
PM
899
900static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr,
901 vaddr addr, unsigned size,
902 MMUAccessType access_type,
903 int mmu_idx, MemTxAttrs attrs,
904 MemTxResult response,
905 uintptr_t retaddr)
906{
907 CPUClass *cc = CPU_GET_CLASS(cpu);
908
ed860129 909 if (!cpu->ignore_memory_transaction_failures && cc->do_transaction_failed) {
0dff0939
PM
910 cc->do_transaction_failed(cpu, physaddr, addr, size, access_type,
911 mmu_idx, attrs, response, retaddr);
912 }
913}
c658b94f
AF
914#endif
915
47507383
TH
916#endif /* NEED_CPU_H */
917
2991b890
PC
918/**
919 * cpu_set_pc:
920 * @cpu: The CPU to set the program counter for.
921 * @addr: Program counter value.
922 *
923 * Sets the program counter for a CPU.
924 */
925static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
926{
927 CPUClass *cc = CPU_GET_CLASS(cpu);
928
929 cc->set_pc(cpu, addr);
930}
931
d8ed887b
AF
932/**
933 * cpu_reset_interrupt:
934 * @cpu: The CPU to clear the interrupt on.
935 * @mask: The interrupt mask to clear.
936 *
937 * Resets interrupts on the vCPU @cpu.
938 */
939void cpu_reset_interrupt(CPUState *cpu, int mask);
940
60a3e17a
AF
941/**
942 * cpu_exit:
943 * @cpu: The CPU to exit.
944 *
945 * Requests the CPU @cpu to exit execution.
946 */
947void cpu_exit(CPUState *cpu);
948
2993683b
IM
949/**
950 * cpu_resume:
951 * @cpu: The CPU to resume.
952 *
953 * Resumes CPU, i.e. puts CPU into runnable state.
954 */
955void cpu_resume(CPUState *cpu);
dd83b06a 956
4c055ab5
GZ
957/**
958 * cpu_remove:
959 * @cpu: The CPU to remove.
960 *
961 * Requests the CPU to be removed.
962 */
963void cpu_remove(CPUState *cpu);
964
2c579042
BR
965 /**
966 * cpu_remove_sync:
967 * @cpu: The CPU to remove.
968 *
969 * Requests the CPU to be removed and waits till it is removed.
970 */
971void cpu_remove_sync(CPUState *cpu);
972
d148d90e
SF
973/**
974 * process_queued_cpu_work() - process all items on CPU work queue
975 * @cpu: The CPU which work queue to process.
976 */
977void process_queued_cpu_work(CPUState *cpu);
978
ab129972
PB
979/**
980 * cpu_exec_start:
981 * @cpu: The CPU for the current thread.
982 *
983 * Record that a CPU has started execution and can be interrupted with
984 * cpu_exit.
985 */
986void cpu_exec_start(CPUState *cpu);
987
988/**
989 * cpu_exec_end:
990 * @cpu: The CPU for the current thread.
991 *
992 * Record that a CPU has stopped execution and exclusive sections
993 * can be executed without interrupting it.
994 */
995void cpu_exec_end(CPUState *cpu);
996
997/**
998 * start_exclusive:
999 *
1000 * Wait for a concurrent exclusive section to end, and then start
1001 * a section of work that is run while other CPUs are not running
1002 * between cpu_exec_start and cpu_exec_end. CPUs that are running
1003 * cpu_exec are exited immediately. CPUs that call cpu_exec_start
1004 * during the exclusive section go to sleep until this CPU calls
1005 * end_exclusive.
ab129972
PB
1006 */
1007void start_exclusive(void);
1008
1009/**
1010 * end_exclusive:
1011 *
1012 * Concludes an exclusive execution section started by start_exclusive.
ab129972
PB
1013 */
1014void end_exclusive(void);
1015
c643bed9
AF
1016/**
1017 * qemu_init_vcpu:
1018 * @cpu: The vCPU to initialize.
1019 *
1020 * Initializes a vCPU.
1021 */
1022void qemu_init_vcpu(CPUState *cpu);
1023
3825b28f
AF
1024#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
1025#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
1026#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
1027
1028/**
1029 * cpu_single_step:
1030 * @cpu: CPU to the flags for.
1031 * @enabled: Flags to enable.
1032 *
1033 * Enables or disables single-stepping for @cpu.
1034 */
1035void cpu_single_step(CPUState *cpu, int enabled);
1036
b3310ab3
AF
1037/* Breakpoint/watchpoint flags */
1038#define BP_MEM_READ 0x01
1039#define BP_MEM_WRITE 0x02
1040#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
1041#define BP_STOP_BEFORE_ACCESS 0x04
08225676 1042/* 0x08 currently unused */
b3310ab3
AF
1043#define BP_GDB 0x10
1044#define BP_CPU 0x20
b933066a 1045#define BP_ANY (BP_GDB | BP_CPU)
08225676
PM
1046#define BP_WATCHPOINT_HIT_READ 0x40
1047#define BP_WATCHPOINT_HIT_WRITE 0x80
1048#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
b3310ab3
AF
1049
1050int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
1051 CPUBreakpoint **breakpoint);
1052int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
1053void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
1054void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
1055
b933066a
RH
1056/* Return true if PC matches an installed breakpoint. */
1057static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
1058{
1059 CPUBreakpoint *bp;
1060
1061 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
1062 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
1063 if (bp->pc == pc && (bp->flags & mask)) {
1064 return true;
1065 }
1066 }
1067 }
1068 return false;
1069}
1070
74841f04
RH
1071#ifdef CONFIG_USER_ONLY
1072static inline int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
1073 int flags, CPUWatchpoint **watchpoint)
1074{
1075 return -ENOSYS;
1076}
1077
1078static inline int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
1079 vaddr len, int flags)
1080{
1081 return -ENOSYS;
1082}
1083
1084static inline void cpu_watchpoint_remove_by_ref(CPUState *cpu,
1085 CPUWatchpoint *wp)
1086{
1087}
1088
1089static inline void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
1090{
1091}
0026348b
DH
1092
1093static inline void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
1094 MemTxAttrs atr, int fl, uintptr_t ra)
1095{
1096}
56ad8b00
RH
1097
1098static inline int cpu_watchpoint_address_matches(CPUState *cpu,
1099 vaddr addr, vaddr len)
1100{
1101 return 0;
1102}
74841f04 1103#else
75a34036
AF
1104int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
1105 int flags, CPUWatchpoint **watchpoint);
1106int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
1107 vaddr len, int flags);
1108void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
1109void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
0026348b
DH
1110void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
1111 MemTxAttrs attrs, int flags, uintptr_t ra);
56ad8b00 1112int cpu_watchpoint_address_matches(CPUState *cpu, vaddr addr, vaddr len);
74841f04 1113#endif
75a34036 1114
63c91552
PB
1115/**
1116 * cpu_get_address_space:
1117 * @cpu: CPU to get address space from
1118 * @asidx: index identifying which address space to get
1119 *
1120 * Return the requested address space of this CPU. @asidx
1121 * specifies which address space to read.
1122 */
1123AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
1124
a47dddd7
AF
1125void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
1126 GCC_FMT_ATTR(2, 3);
c7e002c5 1127extern Property cpu_common_props[];
39e329e3 1128void cpu_exec_initfn(CPUState *cpu);
ce5b1bbf 1129void cpu_exec_realizefn(CPUState *cpu, Error **errp);
7bbc124e 1130void cpu_exec_unrealizefn(CPUState *cpu);
a47dddd7 1131
c95ac103
TH
1132/**
1133 * target_words_bigendian:
1134 * Returns true if the (default) endianness of the target is big endian,
1135 * false otherwise. Note that in target-specific code, you can use
1136 * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
1137 * code should normally never need to know about the endianness of the
1138 * target, so please do *not* use this function unless you know very well
1139 * what you are doing!
1140 */
1141bool target_words_bigendian(void);
1142
47507383
TH
1143#ifdef NEED_CPU_H
1144
1a1562f5 1145#ifdef CONFIG_SOFTMMU
8a9358cc 1146extern const VMStateDescription vmstate_cpu_common;
1a1562f5
AF
1147#else
1148#define vmstate_cpu_common vmstate_dummy
1149#endif
1150
1151#define VMSTATE_CPU() { \
1152 .name = "parent_obj", \
1153 .size = sizeof(CPUState), \
1154 .vmsd = &vmstate_cpu_common, \
1155 .flags = VMS_STRUCT, \
1156 .offset = 0, \
1157}
1158
47507383
TH
1159#endif /* NEED_CPU_H */
1160
a07f953e 1161#define UNASSIGNED_CPU_INDEX -1
7ea7b9ad 1162#define UNASSIGNED_CLUSTER_INDEX -1
a07f953e 1163
dd83b06a 1164#endif