bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block
[qemu/ar7.git] / include / qom / cpu.h
blob7052eee7b78ad1e1c9ccf96e7a3dddd953ee9329
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 <setjmp.h>
24 #include "hw/qdev-core.h"
25 #include "disas/bfd.h"
26 #include "exec/hwaddr.h"
27 #include "exec/memattrs.h"
28 #include "qemu/queue.h"
29 #include "qemu/thread.h"
30 #include "qemu/typedefs.h"
32 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
33 void *opaque);
35 /**
36 * vaddr:
37 * Type wide enough to contain any #target_ulong virtual address.
39 typedef uint64_t vaddr;
40 #define VADDR_PRId PRId64
41 #define VADDR_PRIu PRIu64
42 #define VADDR_PRIo PRIo64
43 #define VADDR_PRIx PRIx64
44 #define VADDR_PRIX PRIX64
45 #define VADDR_MAX UINT64_MAX
47 /**
48 * SECTION:cpu
49 * @section_id: QEMU-cpu
50 * @title: CPU Class
51 * @short_description: Base class for all CPUs
54 #define TYPE_CPU "cpu"
56 /* Since this macro is used a lot in hot code paths and in conjunction with
57 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
58 * an unchecked cast.
60 #define CPU(obj) ((CPUState *)(obj))
62 #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
63 #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
65 typedef struct CPUWatchpoint CPUWatchpoint;
67 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
68 bool is_write, bool is_exec, int opaque,
69 unsigned size);
71 struct TranslationBlock;
73 /**
74 * CPUClass:
75 * @class_by_name: Callback to map -cpu command line model name to an
76 * instantiatable CPU type.
77 * @parse_features: Callback to parse command line arguments.
78 * @reset: Callback to reset the #CPUState to its initial state.
79 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
80 * @has_work: Callback for checking if there is work to do.
81 * @do_interrupt: Callback for interrupt handling.
82 * @do_unassigned_access: Callback for unassigned access handling.
83 * @do_unaligned_access: Callback for unaligned access handling, if
84 * the target defines #ALIGNED_ONLY.
85 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
86 * runtime configurable endianness is currently big-endian. Non-configurable
87 * CPUs can use the default implementation of this method. This method should
88 * not be used by any callers other than the pre-1.0 virtio devices.
89 * @memory_rw_debug: Callback for GDB memory access.
90 * @dump_state: Callback for dumping state.
91 * @dump_statistics: Callback for dumping statistics.
92 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
93 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
94 * @get_memory_mapping: Callback for obtaining the memory mappings.
95 * @set_pc: Callback for setting the Program Counter register.
96 * @synchronize_from_tb: Callback for synchronizing state from a TCG
97 * #TranslationBlock.
98 * @handle_mmu_fault: Callback for handling an MMU fault.
99 * @get_phys_page_debug: Callback for obtaining a physical address.
100 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
101 * associated memory transaction attributes to use for the access.
102 * CPUs which use memory transaction attributes should implement this
103 * instead of get_phys_page_debug.
104 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
105 * a memory access with the specified memory transaction attributes.
106 * @gdb_read_register: Callback for letting GDB read a register.
107 * @gdb_write_register: Callback for letting GDB write a register.
108 * @debug_check_watchpoint: Callback: return true if the architectural
109 * watchpoint whose address has matched should really fire.
110 * @debug_excp_handler: Callback for handling debug exceptions.
111 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
112 * 64-bit VM coredump.
113 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
114 * note to a 32-bit VM coredump.
115 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
116 * 32-bit VM coredump.
117 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
118 * note to a 32-bit VM coredump.
119 * @vmsd: State description for migration.
120 * @gdb_num_core_regs: Number of core registers accessible to GDB.
121 * @gdb_core_xml_file: File name for core registers GDB XML description.
122 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
123 * before the insn which triggers a watchpoint rather than after it.
124 * @gdb_arch_name: Optional callback that returns the architecture name known
125 * to GDB. The caller must free the returned string with g_free.
126 * @cpu_exec_enter: Callback for cpu_exec preparation.
127 * @cpu_exec_exit: Callback for cpu_exec cleanup.
128 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
129 * @disas_set_info: Setup architecture specific components of disassembly info
131 * Represents a CPU family or model.
133 typedef struct CPUClass {
134 /*< private >*/
135 DeviceClass parent_class;
136 /*< public >*/
138 ObjectClass *(*class_by_name)(const char *cpu_model);
139 void (*parse_features)(CPUState *cpu, char *str, Error **errp);
141 void (*reset)(CPUState *cpu);
142 int reset_dump_flags;
143 bool (*has_work)(CPUState *cpu);
144 void (*do_interrupt)(CPUState *cpu);
145 CPUUnassignedAccess do_unassigned_access;
146 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
147 int is_write, int is_user, uintptr_t retaddr);
148 bool (*virtio_is_big_endian)(CPUState *cpu);
149 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
150 uint8_t *buf, int len, bool is_write);
151 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
152 int flags);
153 void (*dump_statistics)(CPUState *cpu, FILE *f,
154 fprintf_function cpu_fprintf, int flags);
155 int64_t (*get_arch_id)(CPUState *cpu);
156 bool (*get_paging_enabled)(const CPUState *cpu);
157 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
158 Error **errp);
159 void (*set_pc)(CPUState *cpu, vaddr value);
160 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
161 int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int rw,
162 int mmu_index);
163 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
164 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
165 MemTxAttrs *attrs);
166 int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
167 int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
168 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
169 bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
170 void (*debug_excp_handler)(CPUState *cpu);
172 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
173 int cpuid, void *opaque);
174 int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
175 void *opaque);
176 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
177 int cpuid, void *opaque);
178 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
179 void *opaque);
181 const struct VMStateDescription *vmsd;
182 int gdb_num_core_regs;
183 const char *gdb_core_xml_file;
184 gchar * (*gdb_arch_name)(CPUState *cpu);
185 bool gdb_stop_before_watchpoint;
187 void (*cpu_exec_enter)(CPUState *cpu);
188 void (*cpu_exec_exit)(CPUState *cpu);
189 bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
191 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
192 } CPUClass;
194 #ifdef HOST_WORDS_BIGENDIAN
195 typedef struct icount_decr_u16 {
196 uint16_t high;
197 uint16_t low;
198 } icount_decr_u16;
199 #else
200 typedef struct icount_decr_u16 {
201 uint16_t low;
202 uint16_t high;
203 } icount_decr_u16;
204 #endif
206 typedef struct CPUBreakpoint {
207 vaddr pc;
208 int flags; /* BP_* */
209 QTAILQ_ENTRY(CPUBreakpoint) entry;
210 } CPUBreakpoint;
212 struct CPUWatchpoint {
213 vaddr vaddr;
214 vaddr len;
215 vaddr hitaddr;
216 MemTxAttrs hitattrs;
217 int flags; /* BP_* */
218 QTAILQ_ENTRY(CPUWatchpoint) entry;
221 struct KVMState;
222 struct kvm_run;
224 #define TB_JMP_CACHE_BITS 12
225 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
228 * CPUState:
229 * @cpu_index: CPU index (informative).
230 * @nr_cores: Number of cores within this CPU package.
231 * @nr_threads: Number of threads within this CPU.
232 * @numa_node: NUMA node this CPU is belonging to.
233 * @host_tid: Host thread ID.
234 * @running: #true if CPU is currently running (usermode).
235 * @created: Indicates whether the CPU thread has been successfully created.
236 * @interrupt_request: Indicates a pending interrupt request.
237 * @halted: Nonzero if the CPU is in suspended state.
238 * @stop: Indicates a pending stop request.
239 * @stopped: Indicates the CPU has been artificially stopped.
240 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
241 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
242 * CPU and return to its top level loop.
243 * @singlestep_enabled: Flags for single-stepping.
244 * @icount_extra: Instructions until next timer event.
245 * @icount_decr: Number of cycles left, with interrupt flag in high bit.
246 * This allows a single read-compare-cbranch-write sequence to test
247 * for both decrementer underflow and exceptions.
248 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
249 * requires that IO only be performed on the last instruction of a TB
250 * so that interrupts take effect immediately.
251 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
252 * AddressSpaces this CPU has)
253 * @num_ases: number of CPUAddressSpaces in @cpu_ases
254 * @as: Pointer to the first AddressSpace, for the convenience of targets which
255 * only have a single AddressSpace
256 * @env_ptr: Pointer to subclass-specific CPUArchState field.
257 * @current_tb: Currently executing TB.
258 * @gdb_regs: Additional GDB registers.
259 * @gdb_num_regs: Number of total registers accessible to GDB.
260 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
261 * @next_cpu: Next CPU sharing TB cache.
262 * @opaque: User data.
263 * @mem_io_pc: Host Program Counter at which the memory was accessed.
264 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
265 * @kvm_fd: vCPU file descriptor for KVM.
266 * @work_mutex: Lock to prevent multiple access to queued_work_*.
267 * @queued_work_first: First asynchronous work pending.
269 * State of one CPU core or thread.
271 struct CPUState {
272 /*< private >*/
273 DeviceState parent_obj;
274 /*< public >*/
276 int nr_cores;
277 int nr_threads;
278 int numa_node;
280 struct QemuThread *thread;
281 #ifdef _WIN32
282 HANDLE hThread;
283 #endif
284 int thread_id;
285 uint32_t host_tid;
286 bool running;
287 struct QemuCond *halt_cond;
288 bool thread_kicked;
289 bool created;
290 bool stop;
291 bool stopped;
292 bool crash_occurred;
293 bool exit_request;
294 uint32_t interrupt_request;
295 int singlestep_enabled;
296 int64_t icount_extra;
297 sigjmp_buf jmp_env;
299 QemuMutex work_mutex;
300 struct qemu_work_item *queued_work_first, *queued_work_last;
302 CPUAddressSpace *cpu_ases;
303 int num_ases;
304 AddressSpace *as;
305 MemoryRegion *memory;
307 void *env_ptr; /* CPUArchState */
308 struct TranslationBlock *current_tb;
309 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
310 struct GDBRegisterState *gdb_regs;
311 int gdb_num_regs;
312 int gdb_num_g_regs;
313 QTAILQ_ENTRY(CPUState) node;
315 /* ice debug support */
316 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
318 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
319 CPUWatchpoint *watchpoint_hit;
321 void *opaque;
323 /* In order to avoid passing too many arguments to the MMIO helpers,
324 * we store some rarely used information in the CPU context.
326 uintptr_t mem_io_pc;
327 vaddr mem_io_vaddr;
329 int kvm_fd;
330 bool kvm_vcpu_dirty;
331 struct KVMState *kvm_state;
332 struct kvm_run *kvm_run;
334 /* TODO Move common fields from CPUArchState here. */
335 int cpu_index; /* used by alpha TCG */
336 uint32_t halted; /* used by alpha, cris, ppc TCG */
337 union {
338 uint32_t u32;
339 icount_decr_u16 u16;
340 } icount_decr;
341 uint32_t can_do_io;
342 int32_t exception_index; /* used by m68k TCG */
344 /* Used to keep track of an outstanding cpu throttle thread for migration
345 * autoconverge
347 bool throttle_thread_scheduled;
349 /* Note that this is accessed at the start of every TB via a negative
350 offset from AREG0. Leave this field at the end so as to make the
351 (absolute value) offset as small as possible. This reduces code
352 size, especially for hosts without large memory offsets. */
353 uint32_t tcg_exit_req;
356 QTAILQ_HEAD(CPUTailQ, CPUState);
357 extern struct CPUTailQ cpus;
358 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
359 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
360 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
361 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
362 #define CPU_FOREACH_REVERSE(cpu) \
363 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
364 #define first_cpu QTAILQ_FIRST(&cpus)
366 extern __thread CPUState *current_cpu;
369 * cpu_paging_enabled:
370 * @cpu: The CPU whose state is to be inspected.
372 * Returns: %true if paging is enabled, %false otherwise.
374 bool cpu_paging_enabled(const CPUState *cpu);
377 * cpu_get_memory_mapping:
378 * @cpu: The CPU whose memory mappings are to be obtained.
379 * @list: Where to write the memory mappings to.
380 * @errp: Pointer for reporting an #Error.
382 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
383 Error **errp);
386 * cpu_write_elf64_note:
387 * @f: pointer to a function that writes memory to a file
388 * @cpu: The CPU whose memory is to be dumped
389 * @cpuid: ID number of the CPU
390 * @opaque: pointer to the CPUState struct
392 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
393 int cpuid, void *opaque);
396 * cpu_write_elf64_qemunote:
397 * @f: pointer to a function that writes memory to a file
398 * @cpu: The CPU whose memory is to be dumped
399 * @cpuid: ID number of the CPU
400 * @opaque: pointer to the CPUState struct
402 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
403 void *opaque);
406 * cpu_write_elf32_note:
407 * @f: pointer to a function that writes memory to a file
408 * @cpu: The CPU whose memory is to be dumped
409 * @cpuid: ID number of the CPU
410 * @opaque: pointer to the CPUState struct
412 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
413 int cpuid, void *opaque);
416 * cpu_write_elf32_qemunote:
417 * @f: pointer to a function that writes memory to a file
418 * @cpu: The CPU whose memory is to be dumped
419 * @cpuid: ID number of the CPU
420 * @opaque: pointer to the CPUState struct
422 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
423 void *opaque);
426 * CPUDumpFlags:
427 * @CPU_DUMP_CODE:
428 * @CPU_DUMP_FPU: dump FPU register state, not just integer
429 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
431 enum CPUDumpFlags {
432 CPU_DUMP_CODE = 0x00010000,
433 CPU_DUMP_FPU = 0x00020000,
434 CPU_DUMP_CCOP = 0x00040000,
438 * cpu_dump_state:
439 * @cpu: The CPU whose state is to be dumped.
440 * @f: File to dump to.
441 * @cpu_fprintf: Function to dump with.
442 * @flags: Flags what to dump.
444 * Dumps CPU state.
446 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
447 int flags);
450 * cpu_dump_statistics:
451 * @cpu: The CPU whose state is to be dumped.
452 * @f: File to dump to.
453 * @cpu_fprintf: Function to dump with.
454 * @flags: Flags what to dump.
456 * Dumps CPU statistics.
458 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
459 int flags);
461 #ifndef CONFIG_USER_ONLY
463 * cpu_get_phys_page_attrs_debug:
464 * @cpu: The CPU to obtain the physical page address for.
465 * @addr: The virtual address.
466 * @attrs: Updated on return with the memory transaction attributes to use
467 * for this access.
469 * Obtains the physical page corresponding to a virtual one, together
470 * with the corresponding memory transaction attributes to use for the access.
471 * Use it only for debugging because no protection checks are done.
473 * Returns: Corresponding physical page address or -1 if no page found.
475 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
476 MemTxAttrs *attrs)
478 CPUClass *cc = CPU_GET_CLASS(cpu);
480 if (cc->get_phys_page_attrs_debug) {
481 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
483 /* Fallback for CPUs which don't implement the _attrs_ hook */
484 *attrs = MEMTXATTRS_UNSPECIFIED;
485 return cc->get_phys_page_debug(cpu, addr);
489 * cpu_get_phys_page_debug:
490 * @cpu: The CPU to obtain the physical page address for.
491 * @addr: The virtual address.
493 * Obtains the physical page corresponding to a virtual one.
494 * Use it only for debugging because no protection checks are done.
496 * Returns: Corresponding physical page address or -1 if no page found.
498 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
500 MemTxAttrs attrs = {};
502 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
505 /** cpu_asidx_from_attrs:
506 * @cpu: CPU
507 * @attrs: memory transaction attributes
509 * Returns the address space index specifying the CPU AddressSpace
510 * to use for a memory access with the given transaction attributes.
512 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
514 CPUClass *cc = CPU_GET_CLASS(cpu);
516 if (cc->asidx_from_attrs) {
517 return cc->asidx_from_attrs(cpu, attrs);
519 return 0;
521 #endif
524 * cpu_reset:
525 * @cpu: The CPU whose state is to be reset.
527 void cpu_reset(CPUState *cpu);
530 * cpu_class_by_name:
531 * @typename: The CPU base type.
532 * @cpu_model: The model string without any parameters.
534 * Looks up a CPU #ObjectClass matching name @cpu_model.
536 * Returns: A #CPUClass or %NULL if not matching class is found.
538 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
541 * cpu_generic_init:
542 * @typename: The CPU base type.
543 * @cpu_model: The model string including optional parameters.
545 * Instantiates a CPU, processes optional parameters and realizes the CPU.
547 * Returns: A #CPUState or %NULL if an error occurred.
549 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
552 * cpu_has_work:
553 * @cpu: The vCPU to check.
555 * Checks whether the CPU has work to do.
557 * Returns: %true if the CPU has work, %false otherwise.
559 static inline bool cpu_has_work(CPUState *cpu)
561 CPUClass *cc = CPU_GET_CLASS(cpu);
563 g_assert(cc->has_work);
564 return cc->has_work(cpu);
568 * qemu_cpu_is_self:
569 * @cpu: The vCPU to check against.
571 * Checks whether the caller is executing on the vCPU thread.
573 * Returns: %true if called from @cpu's thread, %false otherwise.
575 bool qemu_cpu_is_self(CPUState *cpu);
578 * qemu_cpu_kick:
579 * @cpu: The vCPU to kick.
581 * Kicks @cpu's thread.
583 void qemu_cpu_kick(CPUState *cpu);
586 * cpu_is_stopped:
587 * @cpu: The CPU to check.
589 * Checks whether the CPU is stopped.
591 * Returns: %true if run state is not running or if artificially stopped;
592 * %false otherwise.
594 bool cpu_is_stopped(CPUState *cpu);
597 * run_on_cpu:
598 * @cpu: The vCPU to run on.
599 * @func: The function to be executed.
600 * @data: Data to pass to the function.
602 * Schedules the function @func for execution on the vCPU @cpu.
604 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
607 * async_run_on_cpu:
608 * @cpu: The vCPU to run on.
609 * @func: The function to be executed.
610 * @data: Data to pass to the function.
612 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
614 void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
617 * qemu_get_cpu:
618 * @index: The CPUState@cpu_index value of the CPU to obtain.
620 * Gets a CPU matching @index.
622 * Returns: The CPU or %NULL if there is no matching CPU.
624 CPUState *qemu_get_cpu(int index);
627 * cpu_exists:
628 * @id: Guest-exposed CPU ID to lookup.
630 * Search for CPU with specified ID.
632 * Returns: %true - CPU is found, %false - CPU isn't found.
634 bool cpu_exists(int64_t id);
637 * cpu_throttle_set:
638 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
640 * Throttles all vcpus by forcing them to sleep for the given percentage of
641 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
642 * (example: 10ms sleep for every 30ms awake).
644 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
645 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
646 * is called.
648 void cpu_throttle_set(int new_throttle_pct);
651 * cpu_throttle_stop:
653 * Stops the vcpu throttling started by cpu_throttle_set.
655 void cpu_throttle_stop(void);
658 * cpu_throttle_active:
660 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
662 bool cpu_throttle_active(void);
665 * cpu_throttle_get_percentage:
667 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
669 * Returns: The throttle percentage in range 1 to 99.
671 int cpu_throttle_get_percentage(void);
673 #ifndef CONFIG_USER_ONLY
675 typedef void (*CPUInterruptHandler)(CPUState *, int);
677 extern CPUInterruptHandler cpu_interrupt_handler;
680 * cpu_interrupt:
681 * @cpu: The CPU to set an interrupt on.
682 * @mask: The interupts to set.
684 * Invokes the interrupt handler.
686 static inline void cpu_interrupt(CPUState *cpu, int mask)
688 cpu_interrupt_handler(cpu, mask);
691 #else /* USER_ONLY */
693 void cpu_interrupt(CPUState *cpu, int mask);
695 #endif /* USER_ONLY */
697 #ifdef CONFIG_SOFTMMU
698 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
699 bool is_write, bool is_exec,
700 int opaque, unsigned size)
702 CPUClass *cc = CPU_GET_CLASS(cpu);
704 if (cc->do_unassigned_access) {
705 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
709 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
710 int is_write, int is_user,
711 uintptr_t retaddr)
713 CPUClass *cc = CPU_GET_CLASS(cpu);
715 cc->do_unaligned_access(cpu, addr, is_write, is_user, retaddr);
717 #endif
720 * cpu_set_pc:
721 * @cpu: The CPU to set the program counter for.
722 * @addr: Program counter value.
724 * Sets the program counter for a CPU.
726 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
728 CPUClass *cc = CPU_GET_CLASS(cpu);
730 cc->set_pc(cpu, addr);
734 * cpu_reset_interrupt:
735 * @cpu: The CPU to clear the interrupt on.
736 * @mask: The interrupt mask to clear.
738 * Resets interrupts on the vCPU @cpu.
740 void cpu_reset_interrupt(CPUState *cpu, int mask);
743 * cpu_exit:
744 * @cpu: The CPU to exit.
746 * Requests the CPU @cpu to exit execution.
748 void cpu_exit(CPUState *cpu);
751 * cpu_resume:
752 * @cpu: The CPU to resume.
754 * Resumes CPU, i.e. puts CPU into runnable state.
756 void cpu_resume(CPUState *cpu);
759 * qemu_init_vcpu:
760 * @cpu: The vCPU to initialize.
762 * Initializes a vCPU.
764 void qemu_init_vcpu(CPUState *cpu);
766 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
767 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
768 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
771 * cpu_single_step:
772 * @cpu: CPU to the flags for.
773 * @enabled: Flags to enable.
775 * Enables or disables single-stepping for @cpu.
777 void cpu_single_step(CPUState *cpu, int enabled);
779 /* Breakpoint/watchpoint flags */
780 #define BP_MEM_READ 0x01
781 #define BP_MEM_WRITE 0x02
782 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
783 #define BP_STOP_BEFORE_ACCESS 0x04
784 /* 0x08 currently unused */
785 #define BP_GDB 0x10
786 #define BP_CPU 0x20
787 #define BP_ANY (BP_GDB | BP_CPU)
788 #define BP_WATCHPOINT_HIT_READ 0x40
789 #define BP_WATCHPOINT_HIT_WRITE 0x80
790 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
792 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
793 CPUBreakpoint **breakpoint);
794 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
795 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
796 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
798 /* Return true if PC matches an installed breakpoint. */
799 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
801 CPUBreakpoint *bp;
803 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
804 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
805 if (bp->pc == pc && (bp->flags & mask)) {
806 return true;
810 return false;
813 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
814 int flags, CPUWatchpoint **watchpoint);
815 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
816 vaddr len, int flags);
817 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
818 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
820 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
821 GCC_FMT_ATTR(2, 3);
822 void cpu_exec_exit(CPUState *cpu);
824 #ifdef CONFIG_SOFTMMU
825 extern const struct VMStateDescription vmstate_cpu_common;
826 #else
827 #define vmstate_cpu_common vmstate_dummy
828 #endif
830 #define VMSTATE_CPU() { \
831 .name = "parent_obj", \
832 .size = sizeof(CPUState), \
833 .vmsd = &vmstate_cpu_common, \
834 .flags = VMS_STRUCT, \
835 .offset = 0, \
838 #endif