Add a 2LS for VMMs
[akaros.git] / user / vmm / include / vmm / vmm.h
1 /* Copyright (c) 2015 Google Inc.
2  * Ron Minnich <rminnich@google.com>
3  * See LICENSE for details.
4  *
5  * VMM.h */
6
7 #pragma once
8
9 #include <ros/vmm.h>
10 #include <vmm/sched.h>
11
12 /* Structure to encapsulate all of the bookkeeping for a VM. */
13 struct virtual_machine {
14         struct guest_thread                     **gths;
15         unsigned int                            nr_gpcs;
16         struct vmm_gpcore_init          *gpcis;
17
18         /* TODO: put these in appropriate structures.  e.g., virtio things in
19          * something related to virtio.  low4k in something related to the guest's
20          * memory. */
21         uintptr_t                                       virtio_mmio_base;
22         int                                                     virtio_irq;
23         uint8_t                                         *low4k;
24 };
25
26 char *regname(uint8_t reg);
27 int decode(struct guest_thread *vm_thread, uint64_t *gpa, uint8_t *destreg,
28            uint64_t **regp, int *store, int *size, int *advance);
29 int io(struct guest_thread *vm_thread);
30 void showstatus(FILE *f, struct guest_thread *vm_thread);
31 int msrio(struct guest_thread *vm_thread, struct vmm_gpcore_init *gpci,
32           uint32_t opcode);
33 int do_ioapic(struct guest_thread *vm_thread, uint64_t gpa,
34               int destreg, uint64_t *regp, int store);
35 bool handle_vmexit(struct guest_thread *gth);
36 int __apic_access(struct guest_thread *vm_thread, uint64_t gpa, int destreg,
37                   uint64_t *regp, int store);
38
39 /* Lookup helpers */
40
41 static struct virtual_machine *gth_to_vm(struct guest_thread *gth)
42 {
43         return ((struct vmm_thread*)gth)->vm;
44 }
45
46 static struct vm_trapframe *gth_to_vmtf(struct guest_thread *gth)
47 {
48         return &gth->uthread.u_ctx.tf.vm_tf;
49 }
50
51 static struct vmm_gpcore_init *gth_to_gpci(struct guest_thread *gth)
52 {
53         struct virtual_machine *vm = gth_to_vm(gth);
54
55         return &vm->gpcis[gth->gpc_id];
56 }
57
58 static struct virtual_machine *get_my_vm(void)
59 {
60         return ((struct vmm_thread*)current_uthread)->vm;
61 }