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