AArch64 EL2 hypervisor for QEMU virt that boots at EL2
1#ifndef HV_VCPU_H
2#define HV_VCPU_H
3
4#include "hv/types.h"
5
6enum vcpu_run_state {
7 VCPU_CREATED = 0,
8 VCPU_READY,
9 VCPU_RUNNING,
10 VCPU_PAUSED,
11 VCPU_PANICKED,
12};
13
14struct el1_sysreg_shadow {
15 uint64_t sctlr_el1;
16 uint64_t ttbr0_el1;
17 uint64_t ttbr1_el1;
18 uint64_t tcr_el1;
19 uint64_t mair_el1;
20 uint64_t vbar_el1;
21 uint64_t contextidr_el1;
22 uint64_t tpidr_el1;
23 uint64_t tpidrro_el0;
24 uint64_t cntv_ctl_el0;
25 uint64_t cntv_tval_el0;
26 uint64_t cntv_cval_el0;
27 uint64_t cntkctl_el1;
28 uint64_t cpacr_el1;
29 uint64_t mdscr_el1;
30 uint64_t csselr_el1;
31 uint64_t elr_el1;
32 uint64_t spsr_el1;
33 uint64_t esr_el1;
34 uint64_t far_el1;
35};
36
37struct vcpu_stats {
38 uint64_t traps;
39 uint64_t sysreg_traps;
40 uint64_t hvc_calls;
41 uint64_t smc_denied;
42 uint64_t wfx_traps;
43 uint64_t data_aborts;
44 uint64_t instruction_aborts;
45 uint64_t unknown_exceptions;
46 uint64_t injected_undefs;
47 uint64_t virtual_irqs_injected;
48 uint64_t virtual_irqs_completed;
49 uint64_t timer_syncs;
50 uint64_t timer_last_delta;
51};
52
53struct vcpu {
54 uint64_t x[31];
55 uint64_t sp_el0;
56 uint64_t sp_el1;
57 uint64_t pc;
58 uint64_t pstate;
59 struct el1_sysreg_shadow sysregs;
60 uint64_t pending_virtual_irq;
61 uint64_t active_virtual_irq;
62 uint32_t id;
63 enum vcpu_run_state state;
64 uint64_t last_esr;
65 uint64_t last_far;
66 uint64_t last_hpfar;
67 struct vcpu_stats stats;
68};
69
70struct trap_frame {
71 uint64_t x[31];
72 uint64_t sp_el0;
73 uint64_t sp_el1;
74 uint64_t elr_el2;
75 uint64_t spsr_el2;
76 uint64_t esr_el2;
77 uint64_t far_el2;
78 uint64_t hpfar_el2;
79};
80
81void vcpu_init(struct vcpu *vcpu, uint32_t id, uint64_t entry, uint64_t stack_top);
82void vcpu_load_frame(struct vcpu *vcpu, const struct trap_frame *frame);
83void vcpu_store_frame(const struct vcpu *vcpu, struct trap_frame *frame);
84uint64_t vcpu_read_gpr(const struct vcpu *vcpu, uint32_t rt);
85void vcpu_write_gpr(struct vcpu *vcpu, uint32_t rt, uint64_t value);
86void vcpu_set_pending_irq(struct vcpu *vcpu, uint32_t intid);
87void vcpu_clear_pending_irq(struct vcpu *vcpu, uint32_t intid);
88struct vcpu *vcpu_current(void);
89void vcpu_set_current(struct vcpu *vcpu);
90void vcpu_dump(const struct vcpu *vcpu);
91bool vcpu_frame_selftest(void);
92
93#endif