| 1 | /* |
| 2 | * CPU operations specific to system emulation |
| 3 | * |
| 4 | * Copyright (c) 2012 SUSE LINUX Products GmbH |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 7 | * See the COPYING file in the top-level directory. |
| 8 | */ |
| 9 | |
| 10 | #ifndef SYSTEM_CPU_OPS_H |
| 11 | #define SYSTEM_CPU_OPS_H |
| 12 | |
| 13 | #include "hw/core/cpu.h" |
| 14 | |
| 15 | /* |
| 16 | * struct SysemuCPUOps: System operations specific to a CPU class |
| 17 | */ |
| 18 | typedef struct SysemuCPUOps { |
| 19 | /** |
| 20 | * @has_work: Callback for checking if there is work to do. |
| 21 | * |
| 22 | * This function should be idempotent (i.e. not change state) as |
| 23 | * it will likely be queried multiple times before a CPU resumes. |
| 24 | */ |
| 25 | bool (*has_work)(CPUState *cpu); /* MANDATORY NON-NULL */ |
| 26 | /** |
| 27 | * @get_memory_mapping: Callback for obtaining the memory mappings. |
| 28 | */ |
| 29 | bool (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list, |
| 30 | Error **errp); |
| 31 | /** |
| 32 | * @get_paging_enabled: Callback for inquiring whether paging is enabled. |
| 33 | */ |
| 34 | bool (*get_paging_enabled)(const CPUState *cpu); |
| 35 | /** |
| 36 | * @get_phys_addr_debug: Callback for obtaining a physical address. |
| 37 | * This must be able to handle a non-page-aligned address, and will |
| 38 | * return the physical address corresponding to that address. |
| 39 | * |
| 40 | * CPUs should prefer to implement translate_for_debug instead of |
| 41 | * this (and must do so if their translations are not always valid |
| 42 | * for a complete target page or they use memory attributes). |
| 43 | */ |
| 44 | hwaddr (*get_phys_addr_debug)(CPUState *cpu, vaddr addr); |
| 45 | /** |
| 46 | * @translate_for_debug: Callback for translating a virtual address into |
| 47 | * a physical address for debug purposes. |
| 48 | * The implementation should fill in @result with the physical address, |
| 49 | * transaction attributes, and log2 of the size of the aligned block of |
| 50 | * memory that the translation is valid for. |
| 51 | * This must be able to handle a non-page-aligned address, and will |
| 52 | * return the physical address corresponding to that address. |
| 53 | * The attributes must include the debug flag being set. |
| 54 | * Returns false on translation failure; on success returns true and |
| 55 | * fills in @result. |
| 56 | * |
| 57 | * This is the preferred method to implement for new CPUs. |
| 58 | */ |
| 59 | bool (*translate_for_debug)(CPUState *cpu, vaddr addr, |
| 60 | TranslateForDebugResult *result); |
| 61 | /** |
| 62 | * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for |
| 63 | * a memory access with the specified memory transaction attributes. |
| 64 | */ |
| 65 | int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs); |
| 66 | /** |
| 67 | * @get_crash_info: Callback for reporting guest crash information in |
| 68 | * GUEST_PANICKED events. |
| 69 | */ |
| 70 | GuestPanicInformation* (*get_crash_info)(CPUState *cpu); |
| 71 | /** |
| 72 | * @write_elf32_note: Callback for writing a CPU-specific ELF note to a |
| 73 | * 32-bit VM coredump. |
| 74 | */ |
| 75 | int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu, |
| 76 | int cpuid, DumpState *s); |
| 77 | /** |
| 78 | * @write_elf64_note: Callback for writing a CPU-specific ELF note to a |
| 79 | * 64-bit VM coredump. |
| 80 | */ |
| 81 | int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, |
| 82 | int cpuid, DumpState *s); |
| 83 | /** |
| 84 | * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF |
| 85 | * note to a 32-bit VM coredump. |
| 86 | */ |
| 87 | int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, |
| 88 | DumpState *s); |
| 89 | /** |
| 90 | * @write_elf64_qemunote: Callback for writing a CPU- and QEMU-specific ELF |
| 91 | * note to a 64-bit VM coredump. |
| 92 | */ |
| 93 | int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, |
| 94 | DumpState *s); |
| 95 | /** |
| 96 | * @internal_is_big_endian: Callback to return %true if a CPU which supports |
| 97 | * runtime configurable endianness is currently big-endian. |
| 98 | * Non-configurable CPUs can use the default implementation of this method. |
| 99 | * This method should not be used by any callers other than the pre-1.0 |
| 100 | * virtio devices and the semihosting interface. |
| 101 | */ |
| 102 | bool (*internal_is_big_endian)(CPUState *cpu); |
| 103 | |
| 104 | /** |
| 105 | * @monitor_get_register: Callback to fill @pval with register @name value. |
| 106 | * This field is legacy, use @gdb_core_xml_file |
| 107 | * to dump registers instead. |
| 108 | * Returns: 0 on success or negative errno on failure. |
| 109 | */ |
| 110 | int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval); |
| 111 | |
| 112 | #ifdef CONFIG_HMP |
| 113 | /** |
| 114 | * @monitor_defs: Array of MonitorDef entries. This field is legacy, |
| 115 | * use @gdb_core_xml_file to dump registers instead. |
| 116 | */ |
| 117 | const MonitorDef *monitor_defs; |
| 118 | #endif |
| 119 | |
| 120 | /** |
| 121 | * @legacy_vmsd: Legacy state for migration. |
| 122 | * Do not use in new targets, use #DeviceClass::vmsd instead. |
| 123 | */ |
| 124 | const VMStateDescription *legacy_vmsd; |
| 125 | |
| 126 | } SysemuCPUOps; |
| 127 | |
| 128 | #endif /* SYSTEM_CPU_OPS_H */ |