]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/core/cpu.h
hw/core: Introduce CPUClass.gdb_adjust_breakpoint
[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"
54cb65d8 32#include "qemu/plugin.h"
db1015e9 33#include "qom/object.h"
dd83b06a 34
b5ba1cc6
QN
35typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
36 void *opaque);
c72bf468 37
577f42c0
AF
38/**
39 * vaddr:
40 * Type wide enough to contain any #target_ulong virtual address.
41 */
42typedef 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
49
dd83b06a
AF
50/**
51 * SECTION:cpu
52 * @section_id: QEMU-cpu
53 * @title: CPU Class
54 * @short_description: Base class for all CPUs
55 */
56
57#define TYPE_CPU "cpu"
58
0d6d1ab4
AF
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.
62 */
63#define CPU(obj) ((CPUState *)(obj))
64
db1015e9 65typedef struct CPUClass CPUClass;
8110fa1d
EH
66DECLARE_CLASS_CHECKERS(CPUClass, CPU,
67 TYPE_CPU)
dd83b06a 68
b35399bb
SS
69typedef enum MMUAccessType {
70 MMU_DATA_LOAD = 0,
71 MMU_DATA_STORE = 1,
72 MMU_INST_FETCH = 2
73} MMUAccessType;
74
568496c0 75typedef struct CPUWatchpoint CPUWatchpoint;
dd83b06a 76
78271684
CF
77/* see tcg-cpu-ops.h */
78struct TCGCPUOps;
e9e51b71 79
fb6916dd
CF
80/* see accel-cpu.h */
81struct AccelCPUClass;
82
8b80bd28
PMD
83/* see sysemu-cpu-ops.h */
84struct SysemuCPUOps;
85
dd83b06a
AF
86/**
87 * CPUClass:
2b8c2754
AF
88 * @class_by_name: Callback to map -cpu command line model name to an
89 * instantiatable CPU type.
94a444b2 90 * @parse_features: Callback to parse command line arguments.
91b1df8c 91 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
8c2e1b00 92 * @has_work: Callback for checking if there is work to do.
f3659eee 93 * @memory_rw_debug: Callback for GDB memory access.
878096ee 94 * @dump_state: Callback for dumping state.
997395d3 95 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
42f6ed91
JS
96 * @set_pc: Callback for setting the Program Counter register. This
97 * should have the semantics used by the target architecture when
98 * setting the PC from a source such as an ELF file entry point;
99 * for example on Arm it will also set the Thumb mode bit based
100 * on the least significant bit of the new PC value.
101 * If the target behaviour here is anything other than "set
102 * the PC register to the value passed in" then the target must
103 * also implement the synchronize_from_tb hook.
5b50e790
AF
104 * @gdb_read_register: Callback for letting GDB read a register.
105 * @gdb_write_register: Callback for letting GDB write a register.
5bc31e94
RH
106 * @gdb_adjust_breakpoint: Callback for adjusting the address of a
107 * breakpoint. Used by AVR to handle a gdb mis-feature with
108 * its Harvard architecture split code and data.
a0e372f0 109 * @gdb_num_core_regs: Number of core registers accessible to GDB.
5b24c641 110 * @gdb_core_xml_file: File name for core registers GDB XML description.
2472b6c0
PM
111 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
112 * before the insn which triggers a watchpoint rather than after it.
b3820e6c
DH
113 * @gdb_arch_name: Optional callback that returns the architecture name known
114 * to GDB. The caller must free the returned string with g_free.
200bf5b7
AB
115 * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the
116 * gdb stub. Returns a pointer to the XML contents for the specified XML file
117 * or NULL if the CPU doesn't have a dynamically generated content for it.
37b9de46 118 * @disas_set_info: Setup architecture specific components of disassembly info
40612000
JB
119 * @adjust_watchpoint_address: Perform a target-specific adjustment to an
120 * address before attempting to match it against watchpoints.
61ad65d0
RH
121 * @deprecation_note: If this CPUClass is deprecated, this field provides
122 * related information.
dd83b06a
AF
123 *
124 * Represents a CPU family or model.
125 */
db1015e9 126struct CPUClass {
dd83b06a 127 /*< private >*/
961f8395 128 DeviceClass parent_class;
dd83b06a
AF
129 /*< public >*/
130
2b8c2754 131 ObjectClass *(*class_by_name)(const char *cpu_model);
62a48a2a 132 void (*parse_features)(const char *typename, char *str, Error **errp);
2b8c2754 133
91b1df8c 134 int reset_dump_flags;
8c2e1b00 135 bool (*has_work)(CPUState *cpu);
f3659eee
AF
136 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
137 uint8_t *buf, int len, bool is_write);
90c84c56 138 void (*dump_state)(CPUState *cpu, FILE *, int flags);
997395d3 139 int64_t (*get_arch_id)(CPUState *cpu);
f45748f1 140 void (*set_pc)(CPUState *cpu, vaddr value);
a010bdbe 141 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
5b50e790 142 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
5bc31e94 143 vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr);
b170fce3 144
5b24c641 145 const char *gdb_core_xml_file;
b3820e6c 146 gchar * (*gdb_arch_name)(CPUState *cpu);
200bf5b7 147 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
37b9de46
PC
148
149 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
55c3ceef 150
61ad65d0 151 const char *deprecation_note;
55c3ceef
RH
152 /* Keep non-pointer data at the end to minimize holes. */
153 int gdb_num_core_regs;
154 bool gdb_stop_before_watchpoint;
fb6916dd 155 struct AccelCPUClass *accel_cpu;
e9e51b71 156
8b80bd28
PMD
157 /* when system emulation is not available, this pointer is NULL */
158 const struct SysemuCPUOps *sysemu_ops;
159
78271684 160 /* when TCG is not available, this pointer is NULL */
11906557 161 const struct TCGCPUOps *tcg_ops;
cc3f2be6
CF
162
163 /*
164 * if not NULL, this is called in order for the CPUClass to initialize
165 * class data that depends on the accelerator, see accel/accel-common.c.
166 */
167 void (*init_accel_cpu)(struct AccelCPUClass *accel_cpu, CPUClass *cc);
db1015e9 168};
dd83b06a 169
5e140196
RH
170/*
171 * Low 16 bits: number of cycles left, used only in icount mode.
172 * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
173 * for this CPU and return to its top level loop (even in non-icount mode).
174 * This allows a single read-compare-cbranch-write sequence to test
175 * for both decrementer underflow and exceptions.
176 */
177typedef union IcountDecr {
178 uint32_t u32;
179 struct {
28ecfd7a 180#ifdef HOST_WORDS_BIGENDIAN
5e140196
RH
181 uint16_t high;
182 uint16_t low;
28ecfd7a 183#else
5e140196
RH
184 uint16_t low;
185 uint16_t high;
28ecfd7a 186#endif
5e140196
RH
187 } u16;
188} IcountDecr;
28ecfd7a 189
f0c3c505
AF
190typedef struct CPUBreakpoint {
191 vaddr pc;
192 int flags; /* BP_* */
193 QTAILQ_ENTRY(CPUBreakpoint) entry;
194} CPUBreakpoint;
195
568496c0 196struct CPUWatchpoint {
ff4700b0 197 vaddr vaddr;
05068c0d 198 vaddr len;
08225676 199 vaddr hitaddr;
66b9b43c 200 MemTxAttrs hitattrs;
ff4700b0
AF
201 int flags; /* BP_* */
202 QTAILQ_ENTRY(CPUWatchpoint) entry;
568496c0 203};
ff4700b0 204
2f3a57ee
AB
205#ifdef CONFIG_PLUGIN
206/*
207 * For plugins we sometime need to save the resolved iotlb data before
208 * the memory regions get moved around by io_writex.
209 */
210typedef struct SavedIOTLB {
211 hwaddr addr;
212 MemoryRegionSection *section;
213 hwaddr mr_offset;
214} SavedIOTLB;
215#endif
216
a60f24b5 217struct KVMState;
f7575c96 218struct kvm_run;
a60f24b5 219
b0cb0a66 220struct hax_vcpu_state;
b533450e 221struct hvf_vcpu_state;
b0cb0a66 222
8cd70437
AF
223#define TB_JMP_CACHE_BITS 12
224#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
225
4b4629d9 226/* work queue */
14e6fe12
PB
227
228/* The union type allows passing of 64 bit target pointers on 32 bit
229 * hosts in a single parameter
230 */
231typedef union {
232 int host_int;
233 unsigned long host_ulong;
234 void *host_ptr;
235 vaddr target_ptr;
236} run_on_cpu_data;
237
238#define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
239#define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
240#define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
241#define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
242#define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
243
244typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
245
d148d90e 246struct qemu_work_item;
4b4629d9 247
0b8497f0 248#define CPU_UNSET_NUMA_NODE_ID -1
d01c05c9 249#define CPU_TRACE_DSTATE_MAX_EVENTS 32
0b8497f0 250
dd83b06a
AF
251/**
252 * CPUState:
55e5c285 253 * @cpu_index: CPU index (informative).
7ea7b9ad
PM
254 * @cluster_index: Identifies which cluster this CPU is in.
255 * For boards which don't define clusters or for "loose" CPUs not assigned
256 * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
257 * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
258 * QOM parent.
6cc9d67c 259 * @tcg_cflags: Pre-computed cflags for this cpu.
ce3960eb
AF
260 * @nr_cores: Number of cores within this CPU package.
261 * @nr_threads: Number of threads within this CPU.
c265e976
PB
262 * @running: #true if CPU is currently running (lockless).
263 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
ab129972 264 * valid under cpu_list_lock.
61a46217 265 * @created: Indicates whether the CPU thread has been successfully created.
259186a7
AF
266 * @interrupt_request: Indicates a pending interrupt request.
267 * @halted: Nonzero if the CPU is in suspended state.
4fdeee7c 268 * @stop: Indicates a pending stop request.
f324e766 269 * @stopped: Indicates the CPU has been artificially stopped.
4c055ab5 270 * @unplug: Indicates a pending CPU unplug request.
bac05aa9 271 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
ed2803da 272 * @singlestep_enabled: Flags for single-stepping.
efee7340 273 * @icount_extra: Instructions until next timer event.
414b15c9
PB
274 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
275 * requires that IO only be performed on the last instruction of a TB
276 * so that interrupts take effect immediately.
32857f4d
PM
277 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
278 * AddressSpaces this CPU has)
12ebc9a7 279 * @num_ases: number of CPUAddressSpaces in @cpu_ases
32857f4d
PM
280 * @as: Pointer to the first AddressSpace, for the convenience of targets which
281 * only have a single AddressSpace
c05efcb1 282 * @env_ptr: Pointer to subclass-specific CPUArchState field.
5e140196 283 * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
eac8b355 284 * @gdb_regs: Additional GDB registers.
a0e372f0 285 * @gdb_num_regs: Number of total registers accessible to GDB.
35143f01 286 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
182735ef 287 * @next_cpu: Next CPU sharing TB cache.
0429a971 288 * @opaque: User data.
93afeade 289 * @mem_io_pc: Host Program Counter at which the memory was accessed.
8737c51c 290 * @kvm_fd: vCPU file descriptor for KVM.
0c0fcc20
EC
291 * @work_mutex: Lock to prevent multiple access to @work_list.
292 * @work_list: List of pending asynchronous work.
d4381116
LV
293 * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
294 * to @trace_dstate).
48151859 295 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
54cb65d8 296 * @plugin_mask: Plugin event bitmap. Modified only via async work.
ed860129
PM
297 * @ignore_memory_transaction_failures: Cached copy of the MachineState
298 * flag of the same name: allows the board to suppress calling of the
299 * CPU do_transaction_failed hook function.
b4420f19
PX
300 * @kvm_dirty_gfns: Points to the KVM dirty ring for this CPU when KVM dirty
301 * ring is enabled.
302 * @kvm_fetch_index: Keeps the index that we last fetched from the per-vCPU
303 * dirty ring structure.
dd83b06a
AF
304 *
305 * State of one CPU core or thread.
306 */
307struct CPUState {
308 /*< private >*/
961f8395 309 DeviceState parent_obj;
dd83b06a
AF
310 /*< public >*/
311
ce3960eb
AF
312 int nr_cores;
313 int nr_threads;
314
814e612e 315 struct QemuThread *thread;
bcba2a72
AF
316#ifdef _WIN32
317 HANDLE hThread;
318#endif
9f09e18a 319 int thread_id;
c265e976 320 bool running, has_waiter;
f5c121b8 321 struct QemuCond *halt_cond;
216fc9a4 322 bool thread_kicked;
61a46217 323 bool created;
4fdeee7c 324 bool stop;
f324e766 325 bool stopped;
c1b70158
TJB
326
327 /* Should CPU start in powered-off state? */
328 bool start_powered_off;
329
4c055ab5 330 bool unplug;
bac05aa9 331 bool crash_occurred;
e0c38211 332 bool exit_request;
cfbc3c60 333 bool in_exclusive_context;
9b990ee5 334 uint32_t cflags_next_tb;
8d04fb55 335 /* updates protected by BQL */
259186a7 336 uint32_t interrupt_request;
ed2803da 337 int singlestep_enabled;
e4cd9657 338 int64_t icount_budget;
efee7340 339 int64_t icount_extra;
9c09a251 340 uint64_t random_seed;
6f03bef0 341 sigjmp_buf jmp_env;
bcba2a72 342
376692b9 343 QemuMutex work_mutex;
0c0fcc20 344 QSIMPLEQ_HEAD(, qemu_work_item) work_list;
376692b9 345
32857f4d 346 CPUAddressSpace *cpu_ases;
12ebc9a7 347 int num_ases;
09daed84 348 AddressSpace *as;
6731d864 349 MemoryRegion *memory;
09daed84 350
c05efcb1 351 void *env_ptr; /* CPUArchState */
5e140196 352 IcountDecr *icount_decr_ptr;
7d7500d9 353
f3ced3c5 354 /* Accessed in parallel; all accesses must be atomic */
8349d2ae 355 TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
7d7500d9 356
eac8b355 357 struct GDBRegisterState *gdb_regs;
a0e372f0 358 int gdb_num_regs;
35143f01 359 int gdb_num_g_regs;
bdc44640 360 QTAILQ_ENTRY(CPUState) node;
d77953b9 361
f0c3c505 362 /* ice debug support */
b58deb34 363 QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
f0c3c505 364
b58deb34 365 QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
ff4700b0
AF
366 CPUWatchpoint *watchpoint_hit;
367
0429a971
AF
368 void *opaque;
369
93afeade
AF
370 /* In order to avoid passing too many arguments to the MMIO helpers,
371 * we store some rarely used information in the CPU context.
372 */
373 uintptr_t mem_io_pc;
93afeade 374
b4420f19 375 /* Only used in KVM */
8737c51c 376 int kvm_fd;
a60f24b5 377 struct KVMState *kvm_state;
f7575c96 378 struct kvm_run *kvm_run;
b4420f19
PX
379 struct kvm_dirty_gfn *kvm_dirty_gfns;
380 uint32_t kvm_fetch_index;
8737c51c 381
d01c05c9 382 /* Used for events with 'vcpu' and *without* the 'disabled' properties */
d4381116 383 DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
d01c05c9 384 DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
48151859 385
54cb65d8
EC
386 DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX);
387
2f3a57ee 388#ifdef CONFIG_PLUGIN
54cb65d8 389 GArray *plugin_mem_cbs;
2f3a57ee
AB
390 /* saved iotlb data from io_writex */
391 SavedIOTLB saved_iotlb;
392#endif
54cb65d8 393
f5df5baf 394 /* TODO Move common fields from CPUArchState here. */
6fda014e 395 int cpu_index;
7ea7b9ad 396 int cluster_index;
6cc9d67c 397 uint32_t tcg_cflags;
6fda014e 398 uint32_t halted;
99df7dce 399 uint32_t can_do_io;
6fda014e 400 int32_t exception_index;
7e4fb26d 401
99f31832
SAGDR
402 /* shared by kvm, hax and hvf */
403 bool vcpu_dirty;
404
2adcc85d
JH
405 /* Used to keep track of an outstanding cpu throttle thread for migration
406 * autoconverge
407 */
408 bool throttle_thread_scheduled;
409
ed860129
PM
410 bool ignore_memory_transaction_failures;
411
b0cb0a66 412 struct hax_vcpu_state *hax_vcpu;
e3b9ca81 413
b533450e 414 struct hvf_vcpu_state *hvf;
1f871c5e
PM
415
416 /* track IOMMUs whose translations we've cached in the TCG TLB */
417 GArray *iommu_notifiers;
dd83b06a
AF
418};
419
f481ee2d
PB
420typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
421extern CPUTailQ cpus;
422
068a5ea0
EC
423#define first_cpu QTAILQ_FIRST_RCU(&cpus)
424#define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
425#define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
bdc44640 426#define CPU_FOREACH_SAFE(cpu, next_cpu) \
068a5ea0 427 QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
182735ef 428
f240eb6f 429extern __thread CPUState *current_cpu;
4917cf44 430
f3ced3c5
EC
431static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
432{
433 unsigned int i;
434
435 for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
d73415a3 436 qatomic_set(&cpu->tb_jmp_cache[i], NULL);
f3ced3c5
EC
437 }
438}
439
8d4e9146
FK
440/**
441 * qemu_tcg_mttcg_enabled:
442 * Check whether we are running MultiThread TCG or not.
443 *
444 * Returns: %true if we are in MTTCG mode %false otherwise.
445 */
446extern bool mttcg_enabled;
447#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
448
444d5590
AF
449/**
450 * cpu_paging_enabled:
451 * @cpu: The CPU whose state is to be inspected.
452 *
453 * Returns: %true if paging is enabled, %false otherwise.
454 */
455bool cpu_paging_enabled(const CPUState *cpu);
456
a23bbfda
AF
457/**
458 * cpu_get_memory_mapping:
459 * @cpu: The CPU whose memory mappings are to be obtained.
460 * @list: Where to write the memory mappings to.
461 * @errp: Pointer for reporting an #Error.
462 */
463void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
464 Error **errp);
465
cfe35d48
PMD
466#if !defined(CONFIG_USER_ONLY)
467
c72bf468
JF
468/**
469 * cpu_write_elf64_note:
470 * @f: pointer to a function that writes memory to a file
471 * @cpu: The CPU whose memory is to be dumped
472 * @cpuid: ID number of the CPU
473 * @opaque: pointer to the CPUState struct
474 */
475int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
476 int cpuid, void *opaque);
477
478/**
479 * cpu_write_elf64_qemunote:
480 * @f: pointer to a function that writes memory to a file
481 * @cpu: The CPU whose memory is to be dumped
482 * @cpuid: ID number of the CPU
483 * @opaque: pointer to the CPUState struct
484 */
485int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
486 void *opaque);
487
488/**
489 * cpu_write_elf32_note:
490 * @f: pointer to a function that writes memory to a file
491 * @cpu: The CPU whose memory is to be dumped
492 * @cpuid: ID number of the CPU
493 * @opaque: pointer to the CPUState struct
494 */
495int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
496 int cpuid, void *opaque);
497
498/**
499 * cpu_write_elf32_qemunote:
500 * @f: pointer to a function that writes memory to a file
501 * @cpu: The CPU whose memory is to be dumped
502 * @cpuid: ID number of the CPU
503 * @opaque: pointer to the CPUState struct
504 */
505int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
506 void *opaque);
dd83b06a 507
c86f106b
AN
508/**
509 * cpu_get_crash_info:
510 * @cpu: The CPU to get crash information for
511 *
512 * Gets the previously saved crash information.
513 * Caller is responsible for freeing the data.
514 */
515GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
516
cfe35d48
PMD
517#endif /* !CONFIG_USER_ONLY */
518
878096ee
AF
519/**
520 * CPUDumpFlags:
521 * @CPU_DUMP_CODE:
522 * @CPU_DUMP_FPU: dump FPU register state, not just integer
523 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
524 */
525enum CPUDumpFlags {
526 CPU_DUMP_CODE = 0x00010000,
527 CPU_DUMP_FPU = 0x00020000,
528 CPU_DUMP_CCOP = 0x00040000,
529};
530
531/**
532 * cpu_dump_state:
533 * @cpu: The CPU whose state is to be dumped.
90c84c56 534 * @f: If non-null, dump to this stream, else to current print sink.
878096ee
AF
535 *
536 * Dumps CPU state.
537 */
90c84c56 538void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
878096ee 539
00b941e5 540#ifndef CONFIG_USER_ONLY
1dc6fb1f
PM
541/**
542 * cpu_get_phys_page_attrs_debug:
543 * @cpu: The CPU to obtain the physical page address for.
544 * @addr: The virtual address.
545 * @attrs: Updated on return with the memory transaction attributes to use
546 * for this access.
547 *
548 * Obtains the physical page corresponding to a virtual one, together
549 * with the corresponding memory transaction attributes to use for the access.
550 * Use it only for debugging because no protection checks are done.
551 *
552 * Returns: Corresponding physical page address or -1 if no page found.
553 */
a41d3aae
PMD
554hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
555 MemTxAttrs *attrs);
1dc6fb1f 556
00b941e5
AF
557/**
558 * cpu_get_phys_page_debug:
559 * @cpu: The CPU to obtain the physical page address for.
560 * @addr: The virtual address.
561 *
562 * Obtains the physical page corresponding to a virtual one.
563 * Use it only for debugging because no protection checks are done.
564 *
565 * Returns: Corresponding physical page address or -1 if no page found.
566 */
a41d3aae 567hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
d7f25a9e
PM
568
569/** cpu_asidx_from_attrs:
570 * @cpu: CPU
571 * @attrs: memory transaction attributes
572 *
573 * Returns the address space index specifying the CPU AddressSpace
574 * to use for a memory access with the given transaction attributes.
575 */
a41d3aae 576int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
d7f25a9e 577
cdba7e2f
PMD
578/**
579 * cpu_virtio_is_big_endian:
580 * @cpu: CPU
581
582 * Returns %true if a CPU which supports runtime configurable endianness
583 * is currently big-endian.
584 */
585bool cpu_virtio_is_big_endian(CPUState *cpu);
cfe35d48
PMD
586
587#endif /* CONFIG_USER_ONLY */
00b941e5 588
267f685b
PB
589/**
590 * cpu_list_add:
591 * @cpu: The CPU to be added to the list of CPUs.
592 */
593void cpu_list_add(CPUState *cpu);
594
595/**
596 * cpu_list_remove:
597 * @cpu: The CPU to be removed from the list of CPUs.
598 */
599void cpu_list_remove(CPUState *cpu);
600
dd83b06a
AF
601/**
602 * cpu_reset:
603 * @cpu: The CPU whose state is to be reset.
604 */
605void cpu_reset(CPUState *cpu);
606
2b8c2754
AF
607/**
608 * cpu_class_by_name:
609 * @typename: The CPU base type.
610 * @cpu_model: The model string without any parameters.
611 *
612 * Looks up a CPU #ObjectClass matching name @cpu_model.
613 *
614 * Returns: A #CPUClass or %NULL if not matching class is found.
615 */
616ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
617
3c72234c
IM
618/**
619 * cpu_create:
620 * @typename: The CPU type.
621 *
622 * Instantiates a CPU and realizes the CPU.
623 *
624 * Returns: A #CPUState or %NULL if an error occurred.
625 */
626CPUState *cpu_create(const char *typename);
627
628/**
c1c8cfe5
EH
629 * parse_cpu_option:
630 * @cpu_option: The -cpu option including optional parameters.
3c72234c
IM
631 *
632 * processes optional parameters and registers them as global properties
633 *
4482e05c
IM
634 * Returns: type of CPU to create or prints error and terminates process
635 * if an error occurred.
3c72234c 636 */
c1c8cfe5 637const char *parse_cpu_option(const char *cpu_option);
9262685b 638
3993c6bd 639/**
8c2e1b00 640 * cpu_has_work:
3993c6bd
AF
641 * @cpu: The vCPU to check.
642 *
643 * Checks whether the CPU has work to do.
644 *
645 * Returns: %true if the CPU has work, %false otherwise.
646 */
8c2e1b00
AF
647static inline bool cpu_has_work(CPUState *cpu)
648{
649 CPUClass *cc = CPU_GET_CLASS(cpu);
650
651 g_assert(cc->has_work);
652 return cc->has_work(cpu);
653}
3993c6bd 654
60e82579
AF
655/**
656 * qemu_cpu_is_self:
657 * @cpu: The vCPU to check against.
658 *
659 * Checks whether the caller is executing on the vCPU thread.
660 *
661 * Returns: %true if called from @cpu's thread, %false otherwise.
662 */
663bool qemu_cpu_is_self(CPUState *cpu);
664
c08d7424
AF
665/**
666 * qemu_cpu_kick:
667 * @cpu: The vCPU to kick.
668 *
669 * Kicks @cpu's thread.
670 */
671void qemu_cpu_kick(CPUState *cpu);
672
2fa45344
AF
673/**
674 * cpu_is_stopped:
675 * @cpu: The CPU to check.
676 *
677 * Checks whether the CPU is stopped.
678 *
679 * Returns: %true if run state is not running or if artificially stopped;
680 * %false otherwise.
681 */
682bool cpu_is_stopped(CPUState *cpu);
683
d148d90e
SF
684/**
685 * do_run_on_cpu:
686 * @cpu: The vCPU to run on.
687 * @func: The function to be executed.
688 * @data: Data to pass to the function.
689 * @mutex: Mutex to release while waiting for @func to run.
690 *
691 * Used internally in the implementation of run_on_cpu.
692 */
14e6fe12 693void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
d148d90e
SF
694 QemuMutex *mutex);
695
f100f0b3
AF
696/**
697 * run_on_cpu:
698 * @cpu: The vCPU to run on.
699 * @func: The function to be executed.
700 * @data: Data to pass to the function.
701 *
702 * Schedules the function @func for execution on the vCPU @cpu.
703 */
14e6fe12 704void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
f100f0b3 705
3c02270d
CV
706/**
707 * async_run_on_cpu:
708 * @cpu: The vCPU to run on.
709 * @func: The function to be executed.
710 * @data: Data to pass to the function.
711 *
712 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
713 */
14e6fe12 714void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
3c02270d 715
53f5ed95
PB
716/**
717 * async_safe_run_on_cpu:
718 * @cpu: The vCPU to run on.
719 * @func: The function to be executed.
720 * @data: Data to pass to the function.
721 *
722 * Schedules the function @func for execution on the vCPU @cpu asynchronously,
723 * while all other vCPUs are sleeping.
724 *
725 * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
726 * BQL.
727 */
14e6fe12 728void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
53f5ed95 729
cfbc3c60
EC
730/**
731 * cpu_in_exclusive_context()
732 * @cpu: The vCPU to check
733 *
734 * Returns true if @cpu is an exclusive context, for example running
735 * something which has previously been queued via async_safe_run_on_cpu().
736 */
737static inline bool cpu_in_exclusive_context(const CPUState *cpu)
738{
739 return cpu->in_exclusive_context;
740}
741
38d8f5c8
AF
742/**
743 * qemu_get_cpu:
744 * @index: The CPUState@cpu_index value of the CPU to obtain.
745 *
746 * Gets a CPU matching @index.
747 *
748 * Returns: The CPU or %NULL if there is no matching CPU.
749 */
750CPUState *qemu_get_cpu(int index);
751
69e5ff06
IM
752/**
753 * cpu_exists:
754 * @id: Guest-exposed CPU ID to lookup.
755 *
756 * Search for CPU with specified ID.
757 *
758 * Returns: %true - CPU is found, %false - CPU isn't found.
759 */
760bool cpu_exists(int64_t id);
761
5ce46cb3
EH
762/**
763 * cpu_by_arch_id:
764 * @id: Guest-exposed CPU ID of the CPU to obtain.
765 *
766 * Get a CPU with matching @id.
767 *
768 * Returns: The CPU or %NULL if there is no matching CPU.
769 */
770CPUState *cpu_by_arch_id(int64_t id);
771
c3affe56
AF
772/**
773 * cpu_interrupt:
774 * @cpu: The CPU to set an interrupt on.
7e63bc38 775 * @mask: The interrupts to set.
c3affe56
AF
776 *
777 * Invokes the interrupt handler.
778 */
c3affe56
AF
779
780void cpu_interrupt(CPUState *cpu, int mask);
781
2991b890
PC
782/**
783 * cpu_set_pc:
784 * @cpu: The CPU to set the program counter for.
785 * @addr: Program counter value.
786 *
787 * Sets the program counter for a CPU.
788 */
789static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
790{
791 CPUClass *cc = CPU_GET_CLASS(cpu);
792
793 cc->set_pc(cpu, addr);
794}
795
d8ed887b
AF
796/**
797 * cpu_reset_interrupt:
798 * @cpu: The CPU to clear the interrupt on.
799 * @mask: The interrupt mask to clear.
800 *
801 * Resets interrupts on the vCPU @cpu.
802 */
803void cpu_reset_interrupt(CPUState *cpu, int mask);
804
60a3e17a
AF
805/**
806 * cpu_exit:
807 * @cpu: The CPU to exit.
808 *
809 * Requests the CPU @cpu to exit execution.
810 */
811void cpu_exit(CPUState *cpu);
812
2993683b
IM
813/**
814 * cpu_resume:
815 * @cpu: The CPU to resume.
816 *
817 * Resumes CPU, i.e. puts CPU into runnable state.
818 */
819void cpu_resume(CPUState *cpu);
dd83b06a 820
4c055ab5 821/**
2c579042
BR
822 * cpu_remove_sync:
823 * @cpu: The CPU to remove.
824 *
825 * Requests the CPU to be removed and waits till it is removed.
826 */
827void cpu_remove_sync(CPUState *cpu);
828
d148d90e
SF
829/**
830 * process_queued_cpu_work() - process all items on CPU work queue
831 * @cpu: The CPU which work queue to process.
832 */
833void process_queued_cpu_work(CPUState *cpu);
834
ab129972
PB
835/**
836 * cpu_exec_start:
837 * @cpu: The CPU for the current thread.
838 *
839 * Record that a CPU has started execution and can be interrupted with
840 * cpu_exit.
841 */
842void cpu_exec_start(CPUState *cpu);
843
844/**
845 * cpu_exec_end:
846 * @cpu: The CPU for the current thread.
847 *
848 * Record that a CPU has stopped execution and exclusive sections
849 * can be executed without interrupting it.
850 */
851void cpu_exec_end(CPUState *cpu);
852
853/**
854 * start_exclusive:
855 *
856 * Wait for a concurrent exclusive section to end, and then start
857 * a section of work that is run while other CPUs are not running
858 * between cpu_exec_start and cpu_exec_end. CPUs that are running
859 * cpu_exec are exited immediately. CPUs that call cpu_exec_start
860 * during the exclusive section go to sleep until this CPU calls
861 * end_exclusive.
ab129972
PB
862 */
863void start_exclusive(void);
864
865/**
866 * end_exclusive:
867 *
868 * Concludes an exclusive execution section started by start_exclusive.
ab129972
PB
869 */
870void end_exclusive(void);
871
c643bed9
AF
872/**
873 * qemu_init_vcpu:
874 * @cpu: The vCPU to initialize.
875 *
876 * Initializes a vCPU.
877 */
878void qemu_init_vcpu(CPUState *cpu);
879
3825b28f
AF
880#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
881#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
882#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
883
884/**
885 * cpu_single_step:
886 * @cpu: CPU to the flags for.
887 * @enabled: Flags to enable.
888 *
889 * Enables or disables single-stepping for @cpu.
890 */
891void cpu_single_step(CPUState *cpu, int enabled);
892
b3310ab3
AF
893/* Breakpoint/watchpoint flags */
894#define BP_MEM_READ 0x01
895#define BP_MEM_WRITE 0x02
896#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
897#define BP_STOP_BEFORE_ACCESS 0x04
08225676 898/* 0x08 currently unused */
b3310ab3
AF
899#define BP_GDB 0x10
900#define BP_CPU 0x20
b933066a 901#define BP_ANY (BP_GDB | BP_CPU)
08225676
PM
902#define BP_WATCHPOINT_HIT_READ 0x40
903#define BP_WATCHPOINT_HIT_WRITE 0x80
904#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
b3310ab3
AF
905
906int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
907 CPUBreakpoint **breakpoint);
908int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
909void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
910void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
911
b933066a
RH
912/* Return true if PC matches an installed breakpoint. */
913static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
914{
915 CPUBreakpoint *bp;
916
917 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
918 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
919 if (bp->pc == pc && (bp->flags & mask)) {
920 return true;
921 }
922 }
923 }
924 return false;
925}
926
74841f04
RH
927#ifdef CONFIG_USER_ONLY
928static inline int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
929 int flags, CPUWatchpoint **watchpoint)
930{
931 return -ENOSYS;
932}
933
934static inline int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
935 vaddr len, int flags)
936{
937 return -ENOSYS;
938}
939
940static inline void cpu_watchpoint_remove_by_ref(CPUState *cpu,
941 CPUWatchpoint *wp)
942{
943}
944
945static inline void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
946{
947}
0026348b
DH
948
949static inline void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
950 MemTxAttrs atr, int fl, uintptr_t ra)
951{
952}
56ad8b00
RH
953
954static inline int cpu_watchpoint_address_matches(CPUState *cpu,
955 vaddr addr, vaddr len)
956{
957 return 0;
958}
74841f04 959#else
75a34036
AF
960int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
961 int flags, CPUWatchpoint **watchpoint);
962int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
963 vaddr len, int flags);
964void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
965void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
390734a4
RH
966
967/**
968 * cpu_check_watchpoint:
969 * @cpu: cpu context
970 * @addr: guest virtual address
971 * @len: access length
972 * @attrs: memory access attributes
973 * @flags: watchpoint access type
974 * @ra: unwind return address
975 *
976 * Check for a watchpoint hit in [addr, addr+len) of the type
977 * specified by @flags. Exit via exception with a hit.
978 */
0026348b
DH
979void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
980 MemTxAttrs attrs, int flags, uintptr_t ra);
390734a4
RH
981
982/**
983 * cpu_watchpoint_address_matches:
984 * @cpu: cpu context
985 * @addr: guest virtual address
986 * @len: access length
987 *
988 * Return the watchpoint flags that apply to [addr, addr+len).
989 * If no watchpoint is registered for the range, the result is 0.
990 */
56ad8b00 991int cpu_watchpoint_address_matches(CPUState *cpu, vaddr addr, vaddr len);
74841f04 992#endif
75a34036 993
63c91552
PB
994/**
995 * cpu_get_address_space:
996 * @cpu: CPU to get address space from
997 * @asidx: index identifying which address space to get
998 *
999 * Return the requested address space of this CPU. @asidx
1000 * specifies which address space to read.
1001 */
1002AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
1003
a47dddd7
AF
1004void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
1005 GCC_FMT_ATTR(2, 3);
7df5e3d6
CF
1006
1007/* $(top_srcdir)/cpu.c */
39e329e3 1008void cpu_exec_initfn(CPUState *cpu);
ce5b1bbf 1009void cpu_exec_realizefn(CPUState *cpu, Error **errp);
7bbc124e 1010void cpu_exec_unrealizefn(CPUState *cpu);
a47dddd7 1011
c95ac103
TH
1012/**
1013 * target_words_bigendian:
1014 * Returns true if the (default) endianness of the target is big endian,
1015 * false otherwise. Note that in target-specific code, you can use
1016 * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
1017 * code should normally never need to know about the endianness of the
1018 * target, so please do *not* use this function unless you know very well
1019 * what you are doing!
1020 */
1021bool target_words_bigendian(void);
1022
47507383
TH
1023#ifdef NEED_CPU_H
1024
1a1562f5 1025#ifdef CONFIG_SOFTMMU
feece4d0 1026
8a9358cc 1027extern const VMStateDescription vmstate_cpu_common;
1a1562f5
AF
1028
1029#define VMSTATE_CPU() { \
1030 .name = "parent_obj", \
1031 .size = sizeof(CPUState), \
1032 .vmsd = &vmstate_cpu_common, \
1033 .flags = VMS_STRUCT, \
1034 .offset = 0, \
1035}
feece4d0 1036#endif /* CONFIG_SOFTMMU */
1a1562f5 1037
47507383
TH
1038#endif /* NEED_CPU_H */
1039
a07f953e 1040#define UNASSIGNED_CPU_INDEX -1
7ea7b9ad 1041#define UNASSIGNED_CLUSTER_INDEX -1
a07f953e 1042
dd83b06a 1043#endif