2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2012, Kyle C. Hale <kh@u.northwestern.edu>
11 * Copyright (c) 2012, Peter Dinda <pdinda@northwestern.edu>
12 * Copyright (c) 2012, The V3VEE Project <http://www.v3vee.org>
13 * All rights reserved.
15 * Authors: Kyle C. Hale <kh@u.northwestern.edu>
16 * Peter Dinda <pdinda@northwestern.edu>
18 * This is free software. You are permitted to use,
19 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vm_guest_mem.h>
25 #include <palacios/vmm_hypercall.h>
26 #include <palacios/vmm_types.h>
28 #include <interfaces/vmm_host_hypercall.h>
31 #define GET_SET_GPR_IMPL(R) \
32 static uint64_t get_##R(palacios_core_t core) { return ((struct guest_info *)core)->vm_regs.R;} \
33 static void set_##R(palacios_core_t core, uint64_t val) { ((struct guest_info *)core)->vm_regs.R = val; }
35 #define GET_SET_CR_IMPL(R) \
36 static uint64_t get_##R(palacios_core_t core) { return ((struct guest_info *)core)->ctrl_regs.R;} \
37 static void set_##R(palacios_core_t core, uint64_t val) { ((struct guest_info *)core)->ctrl_regs.R = val; }
39 #define DECL_IT(R) .get_##R = get_##R, .set_##R = set_##R,
58 static uint64_t get_rip(palacios_core_t core) { return ((struct guest_info *)core)->rip;}
60 static void set_rip(palacios_core_t core, uint64_t val) { ((struct guest_info *)core)->rip = val; }
67 GET_SET_CR_IMPL(apic_tpr)
69 GET_SET_CR_IMPL(rflags)
73 static struct guest_accessors guest_acc = {
100 .gva_to_hva = (int (*)(palacios_core_t, uint64_t, uint64_t *)) v3_gva_to_hva,
101 .gpa_to_hva = (int (*)(palacios_core_t, uint64_t, uint64_t *)) v3_gpa_to_hva,
102 .gva_to_gpa = (int (*)(palacios_core_t, uint64_t, uint64_t *)) v3_gva_to_gpa,
103 .read_gva = (int (*)(palacios_core_t, uint64_t, int, void *)) v3_read_gva_memory,
104 .read_gpa = (int (*)(palacios_core_t, uint64_t, int, void *)) v3_read_gpa_memory,
105 .write_gva = (int (*)(palacios_core_t, uint64_t, int, void *)) v3_write_gva_memory,
106 .write_gpa = (int (*)(palacios_core_t, uint64_t, int, void *)) v3_write_gpa_memory,
116 int (*hypercall)(palacios_core_t core,
117 unsigned int hcall_id,
118 struct guest_accessors *accessors,
123 static int bounce(struct guest_info *core,
124 unsigned int hcall_id,
127 struct bounce_data *b = (struct bounce_data *) priv_data;
129 return b->hypercall(core,hcall_id,&guest_acc,b->priv_data);
134 int v3_register_host_hypercall(host_vm_info_t * vm,
135 unsigned int hypercall_id,
136 int (*hypercall)(palacios_core_t core,
138 struct guest_accessors *acc,
142 struct bounce_data *b = V3_Malloc(sizeof(struct bounce_data));
145 PrintError((struct v3_vm_info*)vm, VCORE_NONE, "Unable to allocate in registering host hypercall\n");
149 b->hypercall=hypercall;
150 b->priv_data=priv_data;
152 if (v3_register_hypercall((struct v3_vm_info*) vm,
156 PrintError((struct v3_vm_info*)vm, VCORE_NONE, "Cannot register host hypercall\n");
164 int v3_unregister_host_hypercall(host_vm_info_t * vm,
165 unsigned int hypercall_id)
167 return v3_remove_hypercall((struct v3_vm_info*)vm, hypercall_id);