cpu: Add callback to check architectural watchpoint match
[qemu/ar7.git] / include / qom / cpu.h
blobff54600e71dc0c3d736fd000cc530e58a3eb60a4
1 /*
2 * QEMU CPU model
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
20 #ifndef QEMU_CPU_H
21 #define QEMU_CPU_H
23 #include <signal.h>
24 #include <setjmp.h>
25 #include "hw/qdev-core.h"
26 #include "disas/bfd.h"
27 #include "exec/hwaddr.h"
28 #include "exec/memattrs.h"
29 #include "qemu/queue.h"
30 #include "qemu/thread.h"
31 #include "qemu/typedefs.h"
33 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
34 void *opaque);
36 /**
37 * vaddr:
38 * Type wide enough to contain any #target_ulong virtual address.
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
48 /**
49 * SECTION:cpu
50 * @section_id: QEMU-cpu
51 * @title: CPU Class
52 * @short_description: Base class for all CPUs
55 #define TYPE_CPU "cpu"
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.
61 #define CPU(obj) ((CPUState *)(obj))
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)
66 typedef struct CPUState CPUState;
67 typedef struct CPUWatchpoint CPUWatchpoint;
69 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
70 bool is_write, bool is_exec, int opaque,
71 unsigned size);
73 struct TranslationBlock;
75 /**
76 * CPUClass:
77 * @class_by_name: Callback to map -cpu command line model name to an
78 * instantiatable CPU type.
79 * @parse_features: Callback to parse command line arguments.
80 * @reset: Callback to reset the #CPUState to its initial state.
81 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
82 * @has_work: Callback for checking if there is work to do.
83 * @do_interrupt: Callback for interrupt handling.
84 * @do_unassigned_access: Callback for unassigned access handling.
85 * @do_unaligned_access: Callback for unaligned access handling, if
86 * the target defines #ALIGNED_ONLY.
87 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
88 * runtime configurable endianness is currently big-endian. Non-configurable
89 * CPUs can use the default implementation of this method. This method should
90 * not be used by any callers other than the pre-1.0 virtio devices.
91 * @memory_rw_debug: Callback for GDB memory access.
92 * @dump_state: Callback for dumping state.
93 * @dump_statistics: Callback for dumping statistics.
94 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
95 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
96 * @get_memory_mapping: Callback for obtaining the memory mappings.
97 * @set_pc: Callback for setting the Program Counter register.
98 * @synchronize_from_tb: Callback for synchronizing state from a TCG
99 * #TranslationBlock.
100 * @handle_mmu_fault: Callback for handling an MMU fault.
101 * @get_phys_page_debug: Callback for obtaining a physical address.
102 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
103 * associated memory transaction attributes to use for the access.
104 * CPUs which use memory transaction attributes should implement this
105 * instead of get_phys_page_debug.
106 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
107 * a memory access with the specified memory transaction attributes.
108 * @gdb_read_register: Callback for letting GDB read a register.
109 * @gdb_write_register: Callback for letting GDB write a register.
110 * @debug_check_watchpoint: Callback: return true if the architectural
111 * watchpoint whose address has matched should really fire.
112 * @debug_excp_handler: Callback for handling debug exceptions.
113 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
114 * 64-bit VM coredump.
115 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
116 * note to a 32-bit VM coredump.
117 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
118 * 32-bit VM coredump.
119 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
120 * note to a 32-bit VM coredump.
121 * @vmsd: State description for migration.
122 * @gdb_num_core_regs: Number of core registers accessible to GDB.
123 * @gdb_core_xml_file: File name for core registers GDB XML description.
124 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
125 * before the insn which triggers a watchpoint rather than after it.
126 * @gdb_arch_name: Optional callback that returns the architecture name known
127 * to GDB. The caller must free the returned string with g_free.
128 * @cpu_exec_enter: Callback for cpu_exec preparation.
129 * @cpu_exec_exit: Callback for cpu_exec cleanup.
130 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
131 * @disas_set_info: Setup architecture specific components of disassembly info
133 * Represents a CPU family or model.
135 typedef struct CPUClass {
136 /*< private >*/
137 DeviceClass parent_class;
138 /*< public >*/
140 ObjectClass *(*class_by_name)(const char *cpu_model);
141 void (*parse_features)(CPUState *cpu, char *str, Error **errp);
143 void (*reset)(CPUState *cpu);
144 int reset_dump_flags;
145 bool (*has_work)(CPUState *cpu);
146 void (*do_interrupt)(CPUState *cpu);
147 CPUUnassignedAccess do_unassigned_access;
148 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
149 int is_write, int is_user, uintptr_t retaddr);
150 bool (*virtio_is_big_endian)(CPUState *cpu);
151 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
152 uint8_t *buf, int len, bool is_write);
153 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
154 int flags);
155 void (*dump_statistics)(CPUState *cpu, FILE *f,
156 fprintf_function cpu_fprintf, int flags);
157 int64_t (*get_arch_id)(CPUState *cpu);
158 bool (*get_paging_enabled)(const CPUState *cpu);
159 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
160 Error **errp);
161 void (*set_pc)(CPUState *cpu, vaddr value);
162 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
163 int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int rw,
164 int mmu_index);
165 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
166 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
167 MemTxAttrs *attrs);
168 int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
169 int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
170 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
171 bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
172 void (*debug_excp_handler)(CPUState *cpu);
174 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
175 int cpuid, void *opaque);
176 int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
177 void *opaque);
178 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
179 int cpuid, void *opaque);
180 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
181 void *opaque);
183 const struct VMStateDescription *vmsd;
184 int gdb_num_core_regs;
185 const char *gdb_core_xml_file;
186 gchar * (*gdb_arch_name)(CPUState *cpu);
187 bool gdb_stop_before_watchpoint;
189 void (*cpu_exec_enter)(CPUState *cpu);
190 void (*cpu_exec_exit)(CPUState *cpu);
191 bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
193 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
194 } CPUClass;
196 #ifdef HOST_WORDS_BIGENDIAN
197 typedef struct icount_decr_u16 {
198 uint16_t high;
199 uint16_t low;
200 } icount_decr_u16;
201 #else
202 typedef struct icount_decr_u16 {
203 uint16_t low;
204 uint16_t high;
205 } icount_decr_u16;
206 #endif
208 typedef struct CPUBreakpoint {
209 vaddr pc;
210 int flags; /* BP_* */
211 QTAILQ_ENTRY(CPUBreakpoint) entry;
212 } CPUBreakpoint;
214 struct CPUWatchpoint {
215 vaddr vaddr;
216 vaddr len;
217 vaddr hitaddr;
218 MemTxAttrs hitattrs;
219 int flags; /* BP_* */
220 QTAILQ_ENTRY(CPUWatchpoint) entry;
223 struct KVMState;
224 struct kvm_run;
226 #define TB_JMP_CACHE_BITS 12
227 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
230 * CPUState:
231 * @cpu_index: CPU index (informative).
232 * @nr_cores: Number of cores within this CPU package.
233 * @nr_threads: Number of threads within this CPU.
234 * @numa_node: NUMA node this CPU is belonging to.
235 * @host_tid: Host thread ID.
236 * @running: #true if CPU is currently running (usermode).
237 * @created: Indicates whether the CPU thread has been successfully created.
238 * @interrupt_request: Indicates a pending interrupt request.
239 * @halted: Nonzero if the CPU is in suspended state.
240 * @stop: Indicates a pending stop request.
241 * @stopped: Indicates the CPU has been artificially stopped.
242 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
243 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
244 * CPU and return to its top level loop.
245 * @singlestep_enabled: Flags for single-stepping.
246 * @icount_extra: Instructions until next timer event.
247 * @icount_decr: Number of cycles left, with interrupt flag in high bit.
248 * This allows a single read-compare-cbranch-write sequence to test
249 * for both decrementer underflow and exceptions.
250 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
251 * requires that IO only be performed on the last instruction of a TB
252 * so that interrupts take effect immediately.
253 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
254 * AddressSpaces this CPU has)
255 * @num_ases: number of CPUAddressSpaces in @cpu_ases
256 * @as: Pointer to the first AddressSpace, for the convenience of targets which
257 * only have a single AddressSpace
258 * @env_ptr: Pointer to subclass-specific CPUArchState field.
259 * @current_tb: Currently executing TB.
260 * @gdb_regs: Additional GDB registers.
261 * @gdb_num_regs: Number of total registers accessible to GDB.
262 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
263 * @next_cpu: Next CPU sharing TB cache.
264 * @opaque: User data.
265 * @mem_io_pc: Host Program Counter at which the memory was accessed.
266 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
267 * @kvm_fd: vCPU file descriptor for KVM.
268 * @work_mutex: Lock to prevent multiple access to queued_work_*.
269 * @queued_work_first: First asynchronous work pending.
271 * State of one CPU core or thread.
273 struct CPUState {
274 /*< private >*/
275 DeviceState parent_obj;
276 /*< public >*/
278 int nr_cores;
279 int nr_threads;
280 int numa_node;
282 struct QemuThread *thread;
283 #ifdef _WIN32
284 HANDLE hThread;
285 #endif
286 int thread_id;
287 uint32_t host_tid;
288 bool running;
289 struct QemuCond *halt_cond;
290 bool thread_kicked;
291 bool created;
292 bool stop;
293 bool stopped;
294 bool crash_occurred;
295 bool exit_request;
296 uint32_t interrupt_request;
297 int singlestep_enabled;
298 int64_t icount_extra;
299 sigjmp_buf jmp_env;
301 QemuMutex work_mutex;
302 struct qemu_work_item *queued_work_first, *queued_work_last;
304 CPUAddressSpace *cpu_ases;
305 int num_ases;
306 AddressSpace *as;
307 MemoryRegion *memory;
309 void *env_ptr; /* CPUArchState */
310 struct TranslationBlock *current_tb;
311 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
312 struct GDBRegisterState *gdb_regs;
313 int gdb_num_regs;
314 int gdb_num_g_regs;
315 QTAILQ_ENTRY(CPUState) node;
317 /* ice debug support */
318 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
320 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
321 CPUWatchpoint *watchpoint_hit;
323 void *opaque;
325 /* In order to avoid passing too many arguments to the MMIO helpers,
326 * we store some rarely used information in the CPU context.
328 uintptr_t mem_io_pc;
329 vaddr mem_io_vaddr;
331 int kvm_fd;
332 bool kvm_vcpu_dirty;
333 struct KVMState *kvm_state;
334 struct kvm_run *kvm_run;
336 /* TODO Move common fields from CPUArchState here. */
337 int cpu_index; /* used by alpha TCG */
338 uint32_t halted; /* used by alpha, cris, ppc TCG */
339 union {
340 uint32_t u32;
341 icount_decr_u16 u16;
342 } icount_decr;
343 uint32_t can_do_io;
344 int32_t exception_index; /* used by m68k TCG */
346 /* Used to keep track of an outstanding cpu throttle thread for migration
347 * autoconverge
349 bool throttle_thread_scheduled;
351 /* Note that this is accessed at the start of every TB via a negative
352 offset from AREG0. Leave this field at the end so as to make the
353 (absolute value) offset as small as possible. This reduces code
354 size, especially for hosts without large memory offsets. */
355 uint32_t tcg_exit_req;
358 QTAILQ_HEAD(CPUTailQ, CPUState);
359 extern struct CPUTailQ cpus;
360 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
361 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
362 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
363 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
364 #define CPU_FOREACH_REVERSE(cpu) \
365 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
366 #define first_cpu QTAILQ_FIRST(&cpus)
368 extern __thread CPUState *current_cpu;
371 * cpu_paging_enabled:
372 * @cpu: The CPU whose state is to be inspected.
374 * Returns: %true if paging is enabled, %false otherwise.
376 bool cpu_paging_enabled(const CPUState *cpu);
379 * cpu_get_memory_mapping:
380 * @cpu: The CPU whose memory mappings are to be obtained.
381 * @list: Where to write the memory mappings to.
382 * @errp: Pointer for reporting an #Error.
384 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
385 Error **errp);
388 * cpu_write_elf64_note:
389 * @f: pointer to a function that writes memory to a file
390 * @cpu: The CPU whose memory is to be dumped
391 * @cpuid: ID number of the CPU
392 * @opaque: pointer to the CPUState struct
394 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
395 int cpuid, void *opaque);
398 * cpu_write_elf64_qemunote:
399 * @f: pointer to a function that writes memory to a file
400 * @cpu: The CPU whose memory is to be dumped
401 * @cpuid: ID number of the CPU
402 * @opaque: pointer to the CPUState struct
404 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
405 void *opaque);
408 * cpu_write_elf32_note:
409 * @f: pointer to a function that writes memory to a file
410 * @cpu: The CPU whose memory is to be dumped
411 * @cpuid: ID number of the CPU
412 * @opaque: pointer to the CPUState struct
414 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
415 int cpuid, void *opaque);
418 * cpu_write_elf32_qemunote:
419 * @f: pointer to a function that writes memory to a file
420 * @cpu: The CPU whose memory is to be dumped
421 * @cpuid: ID number of the CPU
422 * @opaque: pointer to the CPUState struct
424 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
425 void *opaque);
428 * CPUDumpFlags:
429 * @CPU_DUMP_CODE:
430 * @CPU_DUMP_FPU: dump FPU register state, not just integer
431 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
433 enum CPUDumpFlags {
434 CPU_DUMP_CODE = 0x00010000,
435 CPU_DUMP_FPU = 0x00020000,
436 CPU_DUMP_CCOP = 0x00040000,
440 * cpu_dump_state:
441 * @cpu: The CPU whose state is to be dumped.
442 * @f: File to dump to.
443 * @cpu_fprintf: Function to dump with.
444 * @flags: Flags what to dump.
446 * Dumps CPU state.
448 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
449 int flags);
452 * cpu_dump_statistics:
453 * @cpu: The CPU whose state is to be dumped.
454 * @f: File to dump to.
455 * @cpu_fprintf: Function to dump with.
456 * @flags: Flags what to dump.
458 * Dumps CPU statistics.
460 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
461 int flags);
463 #ifndef CONFIG_USER_ONLY
465 * cpu_get_phys_page_attrs_debug:
466 * @cpu: The CPU to obtain the physical page address for.
467 * @addr: The virtual address.
468 * @attrs: Updated on return with the memory transaction attributes to use
469 * for this access.
471 * Obtains the physical page corresponding to a virtual one, together
472 * with the corresponding memory transaction attributes to use for the access.
473 * Use it only for debugging because no protection checks are done.
475 * Returns: Corresponding physical page address or -1 if no page found.
477 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
478 MemTxAttrs *attrs)
480 CPUClass *cc = CPU_GET_CLASS(cpu);
482 if (cc->get_phys_page_attrs_debug) {
483 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
485 /* Fallback for CPUs which don't implement the _attrs_ hook */
486 *attrs = MEMTXATTRS_UNSPECIFIED;
487 return cc->get_phys_page_debug(cpu, addr);
491 * cpu_get_phys_page_debug:
492 * @cpu: The CPU to obtain the physical page address for.
493 * @addr: The virtual address.
495 * Obtains the physical page corresponding to a virtual one.
496 * Use it only for debugging because no protection checks are done.
498 * Returns: Corresponding physical page address or -1 if no page found.
500 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
502 MemTxAttrs attrs = {};
504 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
507 /** cpu_asidx_from_attrs:
508 * @cpu: CPU
509 * @attrs: memory transaction attributes
511 * Returns the address space index specifying the CPU AddressSpace
512 * to use for a memory access with the given transaction attributes.
514 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
516 CPUClass *cc = CPU_GET_CLASS(cpu);
518 if (cc->asidx_from_attrs) {
519 return cc->asidx_from_attrs(cpu, attrs);
521 return 0;
523 #endif
526 * cpu_reset:
527 * @cpu: The CPU whose state is to be reset.
529 void cpu_reset(CPUState *cpu);
532 * cpu_class_by_name:
533 * @typename: The CPU base type.
534 * @cpu_model: The model string without any parameters.
536 * Looks up a CPU #ObjectClass matching name @cpu_model.
538 * Returns: A #CPUClass or %NULL if not matching class is found.
540 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
543 * cpu_generic_init:
544 * @typename: The CPU base type.
545 * @cpu_model: The model string including optional parameters.
547 * Instantiates a CPU, processes optional parameters and realizes the CPU.
549 * Returns: A #CPUState or %NULL if an error occurred.
551 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
554 * cpu_has_work:
555 * @cpu: The vCPU to check.
557 * Checks whether the CPU has work to do.
559 * Returns: %true if the CPU has work, %false otherwise.
561 static inline bool cpu_has_work(CPUState *cpu)
563 CPUClass *cc = CPU_GET_CLASS(cpu);
565 g_assert(cc->has_work);
566 return cc->has_work(cpu);
570 * qemu_cpu_is_self:
571 * @cpu: The vCPU to check against.
573 * Checks whether the caller is executing on the vCPU thread.
575 * Returns: %true if called from @cpu's thread, %false otherwise.
577 bool qemu_cpu_is_self(CPUState *cpu);
580 * qemu_cpu_kick:
581 * @cpu: The vCPU to kick.
583 * Kicks @cpu's thread.
585 void qemu_cpu_kick(CPUState *cpu);
588 * cpu_is_stopped:
589 * @cpu: The CPU to check.
591 * Checks whether the CPU is stopped.
593 * Returns: %true if run state is not running or if artificially stopped;
594 * %false otherwise.
596 bool cpu_is_stopped(CPUState *cpu);
599 * run_on_cpu:
600 * @cpu: The vCPU to run on.
601 * @func: The function to be executed.
602 * @data: Data to pass to the function.
604 * Schedules the function @func for execution on the vCPU @cpu.
606 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
609 * async_run_on_cpu:
610 * @cpu: The vCPU to run on.
611 * @func: The function to be executed.
612 * @data: Data to pass to the function.
614 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
616 void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
619 * qemu_get_cpu:
620 * @index: The CPUState@cpu_index value of the CPU to obtain.
622 * Gets a CPU matching @index.
624 * Returns: The CPU or %NULL if there is no matching CPU.
626 CPUState *qemu_get_cpu(int index);
629 * cpu_exists:
630 * @id: Guest-exposed CPU ID to lookup.
632 * Search for CPU with specified ID.
634 * Returns: %true - CPU is found, %false - CPU isn't found.
636 bool cpu_exists(int64_t id);
639 * cpu_throttle_set:
640 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
642 * Throttles all vcpus by forcing them to sleep for the given percentage of
643 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
644 * (example: 10ms sleep for every 30ms awake).
646 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
647 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
648 * is called.
650 void cpu_throttle_set(int new_throttle_pct);
653 * cpu_throttle_stop:
655 * Stops the vcpu throttling started by cpu_throttle_set.
657 void cpu_throttle_stop(void);
660 * cpu_throttle_active:
662 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
664 bool cpu_throttle_active(void);
667 * cpu_throttle_get_percentage:
669 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
671 * Returns: The throttle percentage in range 1 to 99.
673 int cpu_throttle_get_percentage(void);
675 #ifndef CONFIG_USER_ONLY
677 typedef void (*CPUInterruptHandler)(CPUState *, int);
679 extern CPUInterruptHandler cpu_interrupt_handler;
682 * cpu_interrupt:
683 * @cpu: The CPU to set an interrupt on.
684 * @mask: The interupts to set.
686 * Invokes the interrupt handler.
688 static inline void cpu_interrupt(CPUState *cpu, int mask)
690 cpu_interrupt_handler(cpu, mask);
693 #else /* USER_ONLY */
695 void cpu_interrupt(CPUState *cpu, int mask);
697 #endif /* USER_ONLY */
699 #ifdef CONFIG_SOFTMMU
700 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
701 bool is_write, bool is_exec,
702 int opaque, unsigned size)
704 CPUClass *cc = CPU_GET_CLASS(cpu);
706 if (cc->do_unassigned_access) {
707 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
711 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
712 int is_write, int is_user,
713 uintptr_t retaddr)
715 CPUClass *cc = CPU_GET_CLASS(cpu);
717 cc->do_unaligned_access(cpu, addr, is_write, is_user, retaddr);
719 #endif
722 * cpu_set_pc:
723 * @cpu: The CPU to set the program counter for.
724 * @addr: Program counter value.
726 * Sets the program counter for a CPU.
728 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
730 CPUClass *cc = CPU_GET_CLASS(cpu);
732 cc->set_pc(cpu, addr);
736 * cpu_reset_interrupt:
737 * @cpu: The CPU to clear the interrupt on.
738 * @mask: The interrupt mask to clear.
740 * Resets interrupts on the vCPU @cpu.
742 void cpu_reset_interrupt(CPUState *cpu, int mask);
745 * cpu_exit:
746 * @cpu: The CPU to exit.
748 * Requests the CPU @cpu to exit execution.
750 void cpu_exit(CPUState *cpu);
753 * cpu_resume:
754 * @cpu: The CPU to resume.
756 * Resumes CPU, i.e. puts CPU into runnable state.
758 void cpu_resume(CPUState *cpu);
761 * qemu_init_vcpu:
762 * @cpu: The vCPU to initialize.
764 * Initializes a vCPU.
766 void qemu_init_vcpu(CPUState *cpu);
768 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
769 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
770 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
773 * cpu_single_step:
774 * @cpu: CPU to the flags for.
775 * @enabled: Flags to enable.
777 * Enables or disables single-stepping for @cpu.
779 void cpu_single_step(CPUState *cpu, int enabled);
781 /* Breakpoint/watchpoint flags */
782 #define BP_MEM_READ 0x01
783 #define BP_MEM_WRITE 0x02
784 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
785 #define BP_STOP_BEFORE_ACCESS 0x04
786 /* 0x08 currently unused */
787 #define BP_GDB 0x10
788 #define BP_CPU 0x20
789 #define BP_ANY (BP_GDB | BP_CPU)
790 #define BP_WATCHPOINT_HIT_READ 0x40
791 #define BP_WATCHPOINT_HIT_WRITE 0x80
792 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
794 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
795 CPUBreakpoint **breakpoint);
796 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
797 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
798 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
800 /* Return true if PC matches an installed breakpoint. */
801 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
803 CPUBreakpoint *bp;
805 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
806 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
807 if (bp->pc == pc && (bp->flags & mask)) {
808 return true;
812 return false;
815 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
816 int flags, CPUWatchpoint **watchpoint);
817 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
818 vaddr len, int flags);
819 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
820 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
822 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
823 GCC_FMT_ATTR(2, 3);
824 void cpu_exec_exit(CPUState *cpu);
826 #ifdef CONFIG_SOFTMMU
827 extern const struct VMStateDescription vmstate_cpu_common;
828 #else
829 #define vmstate_cpu_common vmstate_dummy
830 #endif
832 #define VMSTATE_CPU() { \
833 .name = "parent_obj", \
834 .size = sizeof(CPUState), \
835 .vmsd = &vmstate_cpu_common, \
836 .flags = VMS_STRUCT, \
837 .offset = 0, \
840 #endif