1 /* 2 * QEMU Hypervisor.framework (HVF) support 3 * 4 * This work is licensed under the terms of the GNU GPL, version 2 or later. 5 * See the COPYING file in the top-level directory. 6 * 7 */ 8 9 /* header to be included in HVF-specific code */ 10 11 #ifndef HVF_INT_H 12 #define HVF_INT_H 13 14 #include "qemu/queue.h" 15 #include "exec/vaddr.h" 16 #include "qom/object.h" 17 #include "accel/accel-ops.h" 18 19 #ifdef __aarch64__ 20 #include <Hypervisor/Hypervisor.h> 21 typedef hv_vcpu_t hvf_vcpuid; 22 #else 23 #include <Hypervisor/hv.h> 24 typedef hv_vcpuid_t hvf_vcpuid; 25 #endif 26 27 /* hvf_slot flags */ 28 #define HVF_SLOT_LOG (1 << 0) 29 30 typedef struct hvf_slot { 31 uint64_t start; 32 uint64_t size; 33 uint8_t *mem; 34 int slot_id; 35 uint32_t flags; 36 MemoryRegion *region; 37 } hvf_slot; 38 39 typedef struct hvf_vcpu_caps { 40 uint64_t vmx_cap_pinbased; 41 uint64_t vmx_cap_procbased; 42 uint64_t vmx_cap_procbased2; 43 uint64_t vmx_cap_entry; 44 uint64_t vmx_cap_exit; 45 uint64_t vmx_cap_preemption_timer; 46 } hvf_vcpu_caps; 47 48 struct HVFState { 49 AccelState parent_obj; 50 51 hvf_slot slots[32]; 52 int num_slots; 53 54 hvf_vcpu_caps *hvf_caps; 55 uint64_t vtimer_offset; 56 QTAILQ_HEAD(, hvf_sw_breakpoint) hvf_sw_breakpoints; 57 }; 58 extern HVFState *hvf_state; 59 60 struct AccelCPUState { 61 hvf_vcpuid fd; 62 void *exit; 63 bool vtimer_masked; 64 sigset_t unblock_ipi_mask; 65 bool guest_debug_enabled; 66 }; 67 68 void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line, 69 const char *exp); 70 #define assert_hvf_ok(EX) assert_hvf_ok_impl((EX), __FILE__, __LINE__, #EX) 71 const char *hvf_return_string(hv_return_t ret); 72 int hvf_arch_init(void); 73 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range); 74 int hvf_arch_init_vcpu(CPUState *cpu); 75 void hvf_arch_vcpu_destroy(CPUState *cpu); 76 int hvf_vcpu_exec(CPUState *); 77 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t); 78 int hvf_put_registers(CPUState *); 79 int hvf_get_registers(CPUState *); 80 void hvf_kick_vcpu_thread(CPUState *cpu); 81 82 struct hvf_sw_breakpoint { 83 vaddr pc; 84 vaddr saved_insn; 85 int use_count; 86 QTAILQ_ENTRY(hvf_sw_breakpoint) entry; 87 }; 88 89 struct hvf_sw_breakpoint *hvf_find_sw_breakpoint(CPUState *cpu, 90 vaddr pc); 91 int hvf_sw_breakpoints_active(CPUState *cpu); 92 93 int hvf_arch_insert_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp); 94 int hvf_arch_remove_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp); 95 int hvf_arch_insert_hw_breakpoint(vaddr addr, vaddr len, int type); 96 int hvf_arch_remove_hw_breakpoint(vaddr addr, vaddr len, int type); 97 void hvf_arch_remove_all_hw_breakpoints(void); 98 99 /* 100 * hvf_update_guest_debug: 101 * @cs: CPUState for the CPU to update 102 * 103 * Update guest to enable or disable debugging. Per-arch specifics will be 104 * handled by calling down to hvf_arch_update_guest_debug. 105 */ 106 int hvf_update_guest_debug(CPUState *cpu); 107 void hvf_arch_update_guest_debug(CPUState *cpu); 108 109 /* 110 * Return whether the guest supports debugging. 111 */ 112 bool hvf_arch_supports_guest_debug(void); 113 114 #endif 115