]> Git Repo - qemu.git/blob - include/qom/cpu.h
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20160211' into...
[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 <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"
32
33 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
34                                      void *opaque);
35
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
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
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
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
66 typedef struct CPUState CPUState;
67 typedef struct CPUWatchpoint CPUWatchpoint;
68
69 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
70                                     bool is_write, bool is_exec, int opaque,
71                                     unsigned size);
72
73 struct TranslationBlock;
74
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
132  *
133  * Represents a CPU family or model.
134  */
135 typedef struct CPUClass {
136     /*< private >*/
137     DeviceClass parent_class;
138     /*< public >*/
139
140     ObjectClass *(*class_by_name)(const char *cpu_model);
141     void (*parse_features)(CPUState *cpu, char *str, Error **errp);
142
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);
173
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);
182
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;
188
189     void (*cpu_exec_enter)(CPUState *cpu);
190     void (*cpu_exec_exit)(CPUState *cpu);
191     bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
192
193     void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
194 } CPUClass;
195
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
207
208 typedef struct CPUBreakpoint {
209     vaddr pc;
210     int flags; /* BP_* */
211     QTAILQ_ENTRY(CPUBreakpoint) entry;
212 } CPUBreakpoint;
213
214 struct CPUWatchpoint {
215     vaddr vaddr;
216     vaddr len;
217     vaddr hitaddr;
218     MemTxAttrs hitattrs;
219     int flags; /* BP_* */
220     QTAILQ_ENTRY(CPUWatchpoint) entry;
221 };
222
223 struct KVMState;
224 struct kvm_run;
225
226 #define TB_JMP_CACHE_BITS 12
227 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
228
229 /**
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.
270  *
271  * State of one CPU core or thread.
272  */
273 struct CPUState {
274     /*< private >*/
275     DeviceState parent_obj;
276     /*< public >*/
277
278     int nr_cores;
279     int nr_threads;
280     int numa_node;
281
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;
300
301     QemuMutex work_mutex;
302     struct qemu_work_item *queued_work_first, *queued_work_last;
303
304     CPUAddressSpace *cpu_ases;
305     int num_ases;
306     AddressSpace *as;
307     MemoryRegion *memory;
308
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;
316
317     /* ice debug support */
318     QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
319
320     QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
321     CPUWatchpoint *watchpoint_hit;
322
323     void *opaque;
324
325     /* In order to avoid passing too many arguments to the MMIO helpers,
326      * we store some rarely used information in the CPU context.
327      */
328     uintptr_t mem_io_pc;
329     vaddr mem_io_vaddr;
330
331     int kvm_fd;
332     bool kvm_vcpu_dirty;
333     struct KVMState *kvm_state;
334     struct kvm_run *kvm_run;
335
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 */
345
346     /* Used to keep track of an outstanding cpu throttle thread for migration
347      * autoconverge
348      */
349     bool throttle_thread_scheduled;
350
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;
356 };
357
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)
367
368 extern __thread CPUState *current_cpu;
369
370 /**
371  * cpu_paging_enabled:
372  * @cpu: The CPU whose state is to be inspected.
373  *
374  * Returns: %true if paging is enabled, %false otherwise.
375  */
376 bool cpu_paging_enabled(const CPUState *cpu);
377
378 /**
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.
383  */
384 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
385                             Error **errp);
386
387 /**
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
393  */
394 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
395                          int cpuid, void *opaque);
396
397 /**
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
403  */
404 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
405                              void *opaque);
406
407 /**
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
413  */
414 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
415                          int cpuid, void *opaque);
416
417 /**
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
423  */
424 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
425                              void *opaque);
426
427 /**
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
432  */
433 enum CPUDumpFlags {
434     CPU_DUMP_CODE = 0x00010000,
435     CPU_DUMP_FPU  = 0x00020000,
436     CPU_DUMP_CCOP = 0x00040000,
437 };
438
439 /**
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.
445  *
446  * Dumps CPU state.
447  */
448 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
449                     int flags);
450
451 /**
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.
457  *
458  * Dumps CPU statistics.
459  */
460 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
461                          int flags);
462
463 #ifndef CONFIG_USER_ONLY
464 /**
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.
470  *
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.
474  *
475  * Returns: Corresponding physical page address or -1 if no page found.
476  */
477 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
478                                                    MemTxAttrs *attrs)
479 {
480     CPUClass *cc = CPU_GET_CLASS(cpu);
481
482     if (cc->get_phys_page_attrs_debug) {
483         return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
484     }
485     /* Fallback for CPUs which don't implement the _attrs_ hook */
486     *attrs = MEMTXATTRS_UNSPECIFIED;
487     return cc->get_phys_page_debug(cpu, addr);
488 }
489
490 /**
491  * cpu_get_phys_page_debug:
492  * @cpu: The CPU to obtain the physical page address for.
493  * @addr: The virtual address.
494  *
495  * Obtains the physical page corresponding to a virtual one.
496  * Use it only for debugging because no protection checks are done.
497  *
498  * Returns: Corresponding physical page address or -1 if no page found.
499  */
500 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
501 {
502     MemTxAttrs attrs = {};
503
504     return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
505 }
506
507 /** cpu_asidx_from_attrs:
508  * @cpu: CPU
509  * @attrs: memory transaction attributes
510  *
511  * Returns the address space index specifying the CPU AddressSpace
512  * to use for a memory access with the given transaction attributes.
513  */
514 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
515 {
516     CPUClass *cc = CPU_GET_CLASS(cpu);
517
518     if (cc->asidx_from_attrs) {
519         return cc->asidx_from_attrs(cpu, attrs);
520     }
521     return 0;
522 }
523 #endif
524
525 /**
526  * cpu_reset:
527  * @cpu: The CPU whose state is to be reset.
528  */
529 void cpu_reset(CPUState *cpu);
530
531 /**
532  * cpu_class_by_name:
533  * @typename: The CPU base type.
534  * @cpu_model: The model string without any parameters.
535  *
536  * Looks up a CPU #ObjectClass matching name @cpu_model.
537  *
538  * Returns: A #CPUClass or %NULL if not matching class is found.
539  */
540 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
541
542 /**
543  * cpu_generic_init:
544  * @typename: The CPU base type.
545  * @cpu_model: The model string including optional parameters.
546  *
547  * Instantiates a CPU, processes optional parameters and realizes the CPU.
548  *
549  * Returns: A #CPUState or %NULL if an error occurred.
550  */
551 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
552
553 /**
554  * cpu_has_work:
555  * @cpu: The vCPU to check.
556  *
557  * Checks whether the CPU has work to do.
558  *
559  * Returns: %true if the CPU has work, %false otherwise.
560  */
561 static inline bool cpu_has_work(CPUState *cpu)
562 {
563     CPUClass *cc = CPU_GET_CLASS(cpu);
564
565     g_assert(cc->has_work);
566     return cc->has_work(cpu);
567 }
568
569 /**
570  * qemu_cpu_is_self:
571  * @cpu: The vCPU to check against.
572  *
573  * Checks whether the caller is executing on the vCPU thread.
574  *
575  * Returns: %true if called from @cpu's thread, %false otherwise.
576  */
577 bool qemu_cpu_is_self(CPUState *cpu);
578
579 /**
580  * qemu_cpu_kick:
581  * @cpu: The vCPU to kick.
582  *
583  * Kicks @cpu's thread.
584  */
585 void qemu_cpu_kick(CPUState *cpu);
586
587 /**
588  * cpu_is_stopped:
589  * @cpu: The CPU to check.
590  *
591  * Checks whether the CPU is stopped.
592  *
593  * Returns: %true if run state is not running or if artificially stopped;
594  * %false otherwise.
595  */
596 bool cpu_is_stopped(CPUState *cpu);
597
598 /**
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.
603  *
604  * Schedules the function @func for execution on the vCPU @cpu.
605  */
606 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
607
608 /**
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.
613  *
614  * Schedules the function @func for execution on the vCPU @cpu asynchronously.
615  */
616 void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
617
618 /**
619  * qemu_get_cpu:
620  * @index: The CPUState@cpu_index value of the CPU to obtain.
621  *
622  * Gets a CPU matching @index.
623  *
624  * Returns: The CPU or %NULL if there is no matching CPU.
625  */
626 CPUState *qemu_get_cpu(int index);
627
628 /**
629  * cpu_exists:
630  * @id: Guest-exposed CPU ID to lookup.
631  *
632  * Search for CPU with specified ID.
633  *
634  * Returns: %true - CPU is found, %false - CPU isn't found.
635  */
636 bool cpu_exists(int64_t id);
637
638 /**
639  * cpu_throttle_set:
640  * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
641  *
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).
645  *
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.
649  */
650 void cpu_throttle_set(int new_throttle_pct);
651
652 /**
653  * cpu_throttle_stop:
654  *
655  * Stops the vcpu throttling started by cpu_throttle_set.
656  */
657 void cpu_throttle_stop(void);
658
659 /**
660  * cpu_throttle_active:
661  *
662  * Returns: %true if the vcpus are currently being throttled, %false otherwise.
663  */
664 bool cpu_throttle_active(void);
665
666 /**
667  * cpu_throttle_get_percentage:
668  *
669  * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
670  *
671  * Returns: The throttle percentage in range 1 to 99.
672  */
673 int cpu_throttle_get_percentage(void);
674
675 #ifndef CONFIG_USER_ONLY
676
677 typedef void (*CPUInterruptHandler)(CPUState *, int);
678
679 extern CPUInterruptHandler cpu_interrupt_handler;
680
681 /**
682  * cpu_interrupt:
683  * @cpu: The CPU to set an interrupt on.
684  * @mask: The interupts to set.
685  *
686  * Invokes the interrupt handler.
687  */
688 static inline void cpu_interrupt(CPUState *cpu, int mask)
689 {
690     cpu_interrupt_handler(cpu, mask);
691 }
692
693 #else /* USER_ONLY */
694
695 void cpu_interrupt(CPUState *cpu, int mask);
696
697 #endif /* USER_ONLY */
698
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)
703 {
704     CPUClass *cc = CPU_GET_CLASS(cpu);
705
706     if (cc->do_unassigned_access) {
707         cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
708     }
709 }
710
711 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
712                                         int is_write, int is_user,
713                                         uintptr_t retaddr)
714 {
715     CPUClass *cc = CPU_GET_CLASS(cpu);
716
717     cc->do_unaligned_access(cpu, addr, is_write, is_user, retaddr);
718 }
719 #endif
720
721 /**
722  * cpu_set_pc:
723  * @cpu: The CPU to set the program counter for.
724  * @addr: Program counter value.
725  *
726  * Sets the program counter for a CPU.
727  */
728 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
729 {
730     CPUClass *cc = CPU_GET_CLASS(cpu);
731
732     cc->set_pc(cpu, addr);
733 }
734
735 /**
736  * cpu_reset_interrupt:
737  * @cpu: The CPU to clear the interrupt on.
738  * @mask: The interrupt mask to clear.
739  *
740  * Resets interrupts on the vCPU @cpu.
741  */
742 void cpu_reset_interrupt(CPUState *cpu, int mask);
743
744 /**
745  * cpu_exit:
746  * @cpu: The CPU to exit.
747  *
748  * Requests the CPU @cpu to exit execution.
749  */
750 void cpu_exit(CPUState *cpu);
751
752 /**
753  * cpu_resume:
754  * @cpu: The CPU to resume.
755  *
756  * Resumes CPU, i.e. puts CPU into runnable state.
757  */
758 void cpu_resume(CPUState *cpu);
759
760 /**
761  * qemu_init_vcpu:
762  * @cpu: The vCPU to initialize.
763  *
764  * Initializes a vCPU.
765  */
766 void qemu_init_vcpu(CPUState *cpu);
767
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 */
771
772 /**
773  * cpu_single_step:
774  * @cpu: CPU to the flags for.
775  * @enabled: Flags to enable.
776  *
777  * Enables or disables single-stepping for @cpu.
778  */
779 void cpu_single_step(CPUState *cpu, int enabled);
780
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)
793
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);
799
800 /* Return true if PC matches an installed breakpoint.  */
801 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
802 {
803     CPUBreakpoint *bp;
804
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;
809             }
810         }
811     }
812     return false;
813 }
814
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);
821
822 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
823     GCC_FMT_ATTR(2, 3);
824 void cpu_exec_exit(CPUState *cpu);
825
826 #ifdef CONFIG_SOFTMMU
827 extern const struct VMStateDescription vmstate_cpu_common;
828 #else
829 #define vmstate_cpu_common vmstate_dummy
830 #endif
831
832 #define VMSTATE_CPU() {                                                     \
833     .name = "parent_obj",                                                   \
834     .size = sizeof(CPUState),                                               \
835     .vmsd = &vmstate_cpu_common,                                            \
836     .flags = VMS_STRUCT,                                                    \
837     .offset = 0,                                                            \
838 }
839
840 #endif
This page took 0.067299 seconds and 4 git commands to generate.