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