xref: /qemu/include/system/hvf_int.h (revision 989dd906ed5556563a57b32ae7abf9db5e1f38ba)
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 
18 #ifdef __aarch64__
19 #include <Hypervisor/Hypervisor.h>
20 typedef hv_vcpu_t hvf_vcpuid;
21 #else
22 #include <Hypervisor/hv.h>
23 typedef hv_vcpuid_t hvf_vcpuid;
24 #endif
25 
26 /* hvf_slot flags */
27 #define HVF_SLOT_LOG (1 << 0)
28 
29 typedef struct hvf_slot {
30     uint64_t start;
31     uint64_t size;
32     uint8_t *mem;
33     int slot_id;
34     uint32_t flags;
35     MemoryRegion *region;
36 } hvf_slot;
37 
38 typedef struct hvf_vcpu_caps {
39     uint64_t vmx_cap_pinbased;
40     uint64_t vmx_cap_procbased;
41     uint64_t vmx_cap_procbased2;
42     uint64_t vmx_cap_entry;
43     uint64_t vmx_cap_exit;
44     uint64_t vmx_cap_preemption_timer;
45 } hvf_vcpu_caps;
46 
47 struct HVFState {
48     AccelState parent;
49 
50     hvf_slot slots[32];
51     int num_slots;
52 
53     hvf_vcpu_caps *hvf_caps;
54     uint64_t vtimer_offset;
55     QTAILQ_HEAD(, hvf_sw_breakpoint) hvf_sw_breakpoints;
56 };
57 extern HVFState *hvf_state;
58 
59 struct AccelCPUState {
60     hvf_vcpuid fd;
61     void *exit;
62     bool vtimer_masked;
63     sigset_t unblock_ipi_mask;
64     bool guest_debug_enabled;
65 };
66 
67 void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
68                         const char *exp);
69 #define assert_hvf_ok(EX) assert_hvf_ok_impl((EX), __FILE__, __LINE__, #EX)
70 const char *hvf_return_string(hv_return_t ret);
71 int hvf_arch_init(void);
72 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
73 int hvf_arch_init_vcpu(CPUState *cpu);
74 void hvf_arch_vcpu_destroy(CPUState *cpu);
75 int hvf_vcpu_exec(CPUState *);
76 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
77 int hvf_put_registers(CPUState *);
78 int hvf_get_registers(CPUState *);
79 void hvf_kick_vcpu_thread(CPUState *cpu);
80 
81 struct hvf_sw_breakpoint {
82     vaddr pc;
83     vaddr saved_insn;
84     int use_count;
85     QTAILQ_ENTRY(hvf_sw_breakpoint) entry;
86 };
87 
88 struct hvf_sw_breakpoint *hvf_find_sw_breakpoint(CPUState *cpu,
89                                                  vaddr pc);
90 int hvf_sw_breakpoints_active(CPUState *cpu);
91 
92 int hvf_arch_insert_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp);
93 int hvf_arch_remove_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp);
94 int hvf_arch_insert_hw_breakpoint(vaddr addr, vaddr len, int type);
95 int hvf_arch_remove_hw_breakpoint(vaddr addr, vaddr len, int type);
96 void hvf_arch_remove_all_hw_breakpoints(void);
97 
98 /*
99  * hvf_update_guest_debug:
100  * @cs: CPUState for the CPU to update
101  *
102  * Update guest to enable or disable debugging. Per-arch specifics will be
103  * handled by calling down to hvf_arch_update_guest_debug.
104  */
105 int hvf_update_guest_debug(CPUState *cpu);
106 void hvf_arch_update_guest_debug(CPUState *cpu);
107 
108 /*
109  * Return whether the guest supports debugging.
110  */
111 bool hvf_arch_supports_guest_debug(void);
112 
113 #endif
114