]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/core/cpu.h
target/mips: Fold jazz behaviour into mips_cpu_do_transaction_failed
[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
AF
94 * @dump_state: Callback for dumping state.
95 * @dump_statistics: Callback for dumping statistics.
997395d3 96 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
42f6ed91
JS
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.
5b50e790
AF
105 * @gdb_read_register: Callback for letting GDB read a register.
106 * @gdb_write_register: Callback for letting GDB write a register.
a0e372f0 107 * @gdb_num_core_regs: Number of core registers accessible to GDB.
5b24c641 108 * @gdb_core_xml_file: File name for core registers GDB XML description.
2472b6c0
PM
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.
b3820e6c
DH
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.
200bf5b7
AB
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.
37b9de46 116 * @disas_set_info: Setup architecture specific components of disassembly info
40612000
JB
117 * @adjust_watchpoint_address: Perform a target-specific adjustment to an
118 * address before attempting to match it against watchpoints.
61ad65d0
RH
119 * @deprecation_note: If this CPUClass is deprecated, this field provides
120 * related information.
dd83b06a
AF
121 *
122 * Represents a CPU family or model.
123 */
db1015e9 124struct CPUClass {
dd83b06a 125 /*< private >*/
961f8395 126 DeviceClass parent_class;
dd83b06a
AF
127 /*< public >*/
128
2b8c2754 129 ObjectClass *(*class_by_name)(const char *cpu_model);
62a48a2a 130 void (*parse_features)(const char *typename, char *str, Error **errp);
2b8c2754 131
91b1df8c 132 int reset_dump_flags;
8c2e1b00 133 bool (*has_work)(CPUState *cpu);
f3659eee
AF
134 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
135 uint8_t *buf, int len, bool is_write);
90c84c56 136 void (*dump_state)(CPUState *cpu, FILE *, int flags);
11cb6c15 137 void (*dump_statistics)(CPUState *cpu, int flags);
997395d3 138 int64_t (*get_arch_id)(CPUState *cpu);
f45748f1 139 void (*set_pc)(CPUState *cpu, vaddr value);
a010bdbe 140 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
5b50e790 141 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
b170fce3 142
5b24c641 143 const char *gdb_core_xml_file;
b3820e6c 144 gchar * (*gdb_arch_name)(CPUState *cpu);
200bf5b7 145 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
37b9de46
PC
146
147 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
55c3ceef 148
61ad65d0 149 const char *deprecation_note;
55c3ceef
RH
150 /* Keep non-pointer data at the end to minimize holes. */
151 int gdb_num_core_regs;
152 bool gdb_stop_before_watchpoint;
fb6916dd 153 struct AccelCPUClass *accel_cpu;
e9e51b71 154
8b80bd28
PMD
155 /* when system emulation is not available, this pointer is NULL */
156 const struct SysemuCPUOps *sysemu_ops;
157
78271684
CF
158 /* when TCG is not available, this pointer is NULL */
159 struct TCGCPUOps *tcg_ops;
cc3f2be6
CF
160
161 /*
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.
164 */
165 void (*init_accel_cpu)(struct AccelCPUClass *accel_cpu, CPUClass *cc);
db1015e9 166};
dd83b06a 167
5e140196
RH
168/*
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.
174 */
175typedef union IcountDecr {
176 uint32_t u32;
177 struct {
28ecfd7a 178#ifdef HOST_WORDS_BIGENDIAN
5e140196
RH
179 uint16_t high;
180 uint16_t low;
28ecfd7a 181#else
5e140196
RH
182 uint16_t low;
183 uint16_t high;
28ecfd7a 184#endif
5e140196
RH
185 } u16;
186} IcountDecr;
28ecfd7a 187
f0c3c505
AF
188typedef struct CPUBreakpoint {
189 vaddr pc;
190 int flags; /* BP_* */
191 QTAILQ_ENTRY(CPUBreakpoint) entry;
192} CPUBreakpoint;
193
568496c0 194struct CPUWatchpoint {
ff4700b0 195 vaddr vaddr;
05068c0d 196 vaddr len;
08225676 197 vaddr hitaddr;
66b9b43c 198 MemTxAttrs hitattrs;
ff4700b0
AF
199 int flags; /* BP_* */
200 QTAILQ_ENTRY(CPUWatchpoint) entry;
568496c0 201};
ff4700b0 202
2f3a57ee
AB
203#ifdef CONFIG_PLUGIN
204/*
205 * For plugins we sometime need to save the resolved iotlb data before
206 * the memory regions get moved around by io_writex.
207 */
208typedef struct SavedIOTLB {
209 hwaddr addr;
210 MemoryRegionSection *section;
211 hwaddr mr_offset;
212} SavedIOTLB;
213#endif
214
a60f24b5 215struct KVMState;
f7575c96 216struct kvm_run;
a60f24b5 217
b0cb0a66
VP
218struct hax_vcpu_state;
219
8cd70437
AF
220#define TB_JMP_CACHE_BITS 12
221#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
222
4b4629d9 223/* work queue */
14e6fe12
PB
224
225/* The union type allows passing of 64 bit target pointers on 32 bit
226 * hosts in a single parameter
227 */
228typedef union {
229 int host_int;
230 unsigned long host_ulong;
231 void *host_ptr;
232 vaddr target_ptr;
233} run_on_cpu_data;
234
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)
240
241typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
242
d148d90e 243struct qemu_work_item;
4b4629d9 244
0b8497f0 245#define CPU_UNSET_NUMA_NODE_ID -1
d01c05c9 246#define CPU_TRACE_DSTATE_MAX_EVENTS 32
0b8497f0 247
dd83b06a
AF
248/**
249 * CPUState:
55e5c285 250 * @cpu_index: CPU index (informative).
7ea7b9ad
PM
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.
6cc9d67c 256 * @tcg_cflags: Pre-computed cflags for this cpu.
ce3960eb
AF
257 * @nr_cores: Number of cores within this CPU package.
258 * @nr_threads: Number of threads within this CPU.
c265e976
PB
259 * @running: #true if CPU is currently running (lockless).
260 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
ab129972 261 * valid under cpu_list_lock.
61a46217 262 * @created: Indicates whether the CPU thread has been successfully created.
259186a7
AF
263 * @interrupt_request: Indicates a pending interrupt request.
264 * @halted: Nonzero if the CPU is in suspended state.
4fdeee7c 265 * @stop: Indicates a pending stop request.
f324e766 266 * @stopped: Indicates the CPU has been artificially stopped.
4c055ab5 267 * @unplug: Indicates a pending CPU unplug request.
bac05aa9 268 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
ed2803da 269 * @singlestep_enabled: Flags for single-stepping.
efee7340 270 * @icount_extra: Instructions until next timer event.
414b15c9
PB
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.
32857f4d
PM
274 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
275 * AddressSpaces this CPU has)
12ebc9a7 276 * @num_ases: number of CPUAddressSpaces in @cpu_ases
32857f4d
PM
277 * @as: Pointer to the first AddressSpace, for the convenience of targets which
278 * only have a single AddressSpace
c05efcb1 279 * @env_ptr: Pointer to subclass-specific CPUArchState field.
5e140196 280 * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
eac8b355 281 * @gdb_regs: Additional GDB registers.
a0e372f0 282 * @gdb_num_regs: Number of total registers accessible to GDB.
35143f01 283 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
182735ef 284 * @next_cpu: Next CPU sharing TB cache.
0429a971 285 * @opaque: User data.
93afeade 286 * @mem_io_pc: Host Program Counter at which the memory was accessed.
8737c51c 287 * @kvm_fd: vCPU file descriptor for KVM.
0c0fcc20
EC
288 * @work_mutex: Lock to prevent multiple access to @work_list.
289 * @work_list: List of pending asynchronous work.
d4381116
LV
290 * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
291 * to @trace_dstate).
48151859 292 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
54cb65d8 293 * @plugin_mask: Plugin event bitmap. Modified only via async work.
ed860129
PM
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.
dd83b06a
AF
297 *
298 * State of one CPU core or thread.
299 */
300struct CPUState {
301 /*< private >*/
961f8395 302 DeviceState parent_obj;
dd83b06a
AF
303 /*< public >*/
304
ce3960eb
AF
305 int nr_cores;
306 int nr_threads;
307
814e612e 308 struct QemuThread *thread;
bcba2a72
AF
309#ifdef _WIN32
310 HANDLE hThread;
311#endif
9f09e18a 312 int thread_id;
c265e976 313 bool running, has_waiter;
f5c121b8 314 struct QemuCond *halt_cond;
216fc9a4 315 bool thread_kicked;
61a46217 316 bool created;
4fdeee7c 317 bool stop;
f324e766 318 bool stopped;
c1b70158
TJB
319
320 /* Should CPU start in powered-off state? */
321 bool start_powered_off;
322
4c055ab5 323 bool unplug;
bac05aa9 324 bool crash_occurred;
e0c38211 325 bool exit_request;
cfbc3c60 326 bool in_exclusive_context;
9b990ee5 327 uint32_t cflags_next_tb;
8d04fb55 328 /* updates protected by BQL */
259186a7 329 uint32_t interrupt_request;
ed2803da 330 int singlestep_enabled;
e4cd9657 331 int64_t icount_budget;
efee7340 332 int64_t icount_extra;
9c09a251 333 uint64_t random_seed;
6f03bef0 334 sigjmp_buf jmp_env;
bcba2a72 335
376692b9 336 QemuMutex work_mutex;
0c0fcc20 337 QSIMPLEQ_HEAD(, qemu_work_item) work_list;
376692b9 338
32857f4d 339 CPUAddressSpace *cpu_ases;
12ebc9a7 340 int num_ases;
09daed84 341 AddressSpace *as;
6731d864 342 MemoryRegion *memory;
09daed84 343
c05efcb1 344 void *env_ptr; /* CPUArchState */
5e140196 345 IcountDecr *icount_decr_ptr;
7d7500d9 346
f3ced3c5 347 /* Accessed in parallel; all accesses must be atomic */
8349d2ae 348 TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
7d7500d9 349
eac8b355 350 struct GDBRegisterState *gdb_regs;
a0e372f0 351 int gdb_num_regs;
35143f01 352 int gdb_num_g_regs;
bdc44640 353 QTAILQ_ENTRY(CPUState) node;
d77953b9 354
f0c3c505 355 /* ice debug support */
b58deb34 356 QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
f0c3c505 357
b58deb34 358 QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
ff4700b0
AF
359 CPUWatchpoint *watchpoint_hit;
360
0429a971
AF
361 void *opaque;
362
93afeade
AF
363 /* In order to avoid passing too many arguments to the MMIO helpers,
364 * we store some rarely used information in the CPU context.
365 */
366 uintptr_t mem_io_pc;
93afeade 367
8737c51c 368 int kvm_fd;
a60f24b5 369 struct KVMState *kvm_state;
f7575c96 370 struct kvm_run *kvm_run;
8737c51c 371
d01c05c9 372 /* Used for events with 'vcpu' and *without* the 'disabled' properties */
d4381116 373 DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
d01c05c9 374 DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
48151859 375
54cb65d8
EC
376 DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX);
377
2f3a57ee 378#ifdef CONFIG_PLUGIN
54cb65d8 379 GArray *plugin_mem_cbs;
2f3a57ee
AB
380 /* saved iotlb data from io_writex */
381 SavedIOTLB saved_iotlb;
382#endif
54cb65d8 383
f5df5baf 384 /* TODO Move common fields from CPUArchState here. */
6fda014e 385 int cpu_index;
7ea7b9ad 386 int cluster_index;
6cc9d67c 387 uint32_t tcg_cflags;
6fda014e 388 uint32_t halted;
99df7dce 389 uint32_t can_do_io;
6fda014e 390 int32_t exception_index;
7e4fb26d 391
99f31832
SAGDR
392 /* shared by kvm, hax and hvf */
393 bool vcpu_dirty;
394
2adcc85d
JH
395 /* Used to keep track of an outstanding cpu throttle thread for migration
396 * autoconverge
397 */
398 bool throttle_thread_scheduled;
399
ed860129
PM
400 bool ignore_memory_transaction_failures;
401
b0cb0a66 402 struct hax_vcpu_state *hax_vcpu;
e3b9ca81 403
c97d6d2c 404 int hvf_fd;
1f871c5e
PM
405
406 /* track IOMMUs whose translations we've cached in the TCG TLB */
407 GArray *iommu_notifiers;
dd83b06a
AF
408};
409
f481ee2d
PB
410typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
411extern CPUTailQ cpus;
412
068a5ea0
EC
413#define first_cpu QTAILQ_FIRST_RCU(&cpus)
414#define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
415#define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
bdc44640 416#define CPU_FOREACH_SAFE(cpu, next_cpu) \
068a5ea0 417 QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
182735ef 418
f240eb6f 419extern __thread CPUState *current_cpu;
4917cf44 420
f3ced3c5
EC
421static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
422{
423 unsigned int i;
424
425 for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
d73415a3 426 qatomic_set(&cpu->tb_jmp_cache[i], NULL);
f3ced3c5
EC
427 }
428}
429
8d4e9146
FK
430/**
431 * qemu_tcg_mttcg_enabled:
432 * Check whether we are running MultiThread TCG or not.
433 *
434 * Returns: %true if we are in MTTCG mode %false otherwise.
435 */
436extern bool mttcg_enabled;
437#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
438
444d5590
AF
439/**
440 * cpu_paging_enabled:
441 * @cpu: The CPU whose state is to be inspected.
442 *
443 * Returns: %true if paging is enabled, %false otherwise.
444 */
445bool cpu_paging_enabled(const CPUState *cpu);
446
a23bbfda
AF
447/**
448 * cpu_get_memory_mapping:
449 * @cpu: The CPU whose memory mappings are to be obtained.
450 * @list: Where to write the memory mappings to.
451 * @errp: Pointer for reporting an #Error.
452 */
453void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
454 Error **errp);
455
cfe35d48
PMD
456#if !defined(CONFIG_USER_ONLY)
457
c72bf468
JF
458/**
459 * cpu_write_elf64_note:
460 * @f: pointer to a function that writes memory to a file
461 * @cpu: The CPU whose memory is to be dumped
462 * @cpuid: ID number of the CPU
463 * @opaque: pointer to the CPUState struct
464 */
465int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
466 int cpuid, void *opaque);
467
468/**
469 * cpu_write_elf64_qemunote:
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_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
476 void *opaque);
477
478/**
479 * cpu_write_elf32_note:
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_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
486 int cpuid, void *opaque);
487
488/**
489 * cpu_write_elf32_qemunote:
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_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
496 void *opaque);
dd83b06a 497
c86f106b
AN
498/**
499 * cpu_get_crash_info:
500 * @cpu: The CPU to get crash information for
501 *
502 * Gets the previously saved crash information.
503 * Caller is responsible for freeing the data.
504 */
505GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
506
cfe35d48
PMD
507#endif /* !CONFIG_USER_ONLY */
508
878096ee
AF
509/**
510 * CPUDumpFlags:
511 * @CPU_DUMP_CODE:
512 * @CPU_DUMP_FPU: dump FPU register state, not just integer
513 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
514 */
515enum CPUDumpFlags {
516 CPU_DUMP_CODE = 0x00010000,
517 CPU_DUMP_FPU = 0x00020000,
518 CPU_DUMP_CCOP = 0x00040000,
519};
520
521/**
522 * cpu_dump_state:
523 * @cpu: The CPU whose state is to be dumped.
90c84c56 524 * @f: If non-null, dump to this stream, else to current print sink.
878096ee
AF
525 *
526 * Dumps CPU state.
527 */
90c84c56 528void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
878096ee
AF
529
530/**
531 * cpu_dump_statistics:
532 * @cpu: The CPU whose state is to be dumped.
878096ee
AF
533 * @flags: Flags what to dump.
534 *
11cb6c15
MA
535 * Dump CPU statistics to the current monitor if we have one, else to
536 * stdout.
878096ee 537 */
11cb6c15 538void cpu_dump_statistics(CPUState *cpu, 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);
cfe35d48 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);
586
cfe35d48 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