5 #include <palacios/vm_guest.h>
6 #include <palacios/vmm_mem.h>
10 //#include <palacios/vmm_types.h>
11 #include <palacios/vmm_string.h>
14 //#include <palacios/vmm_paging.h>
16 /* utility definitions */
19 #define PrintDebug(fmt, args...) \
21 extern struct vmm_os_hooks * os_hooks; \
22 if ((os_hooks) && (os_hooks)->print_debug) { \
23 (os_hooks)->print_debug((fmt), ##args); \
27 #define PrintDebug(fmt,args ...)
32 #define PrintError(fmt, args...) \
34 extern struct vmm_os_hooks * os_hooks; \
35 if ((os_hooks) && (os_hooks)->print_debug) { \
36 (os_hooks)->print_debug((fmt), ##args); \
43 #define PrintInfo(fmt, args...) \
45 extern struct vmm_os_hooks * os_hooks; \
46 if ((os_hooks) && (os_hooks)->print_info) { \
47 (os_hooks)->print_info((fmt), ##args); \
51 #define PrintInfo(fmt, args...)
56 #define PrintTrace(fmt, args...) \
58 extern struct vmm_os_hooks * os_hooks; \
59 if ((os_hooks) && (os_hooks)->print_trace) { \
60 (os_hooks)->print_trace((fmt), ##args); \
64 #define PrintTrace(fmt, args...)
68 #define V3_AllocPages(num_pages) \
70 extern struct vmm_os_hooks * os_hooks; \
72 if ((os_hooks) && (os_hooks)->allocate_pages) { \
73 ptr = (os_hooks)->allocate_pages(num_pages); \
79 #define V3_FreePage(page) \
81 extern struct vmm_os_hooks * os_hooks; \
82 if ((os_hooks) && (os_hooks)->free_page) { \
83 (os_hooks)->free_page(page); \
90 #define V3_Malloc(size) ({ \
91 extern struct vmm_os_hooks * os_hooks; \
93 if ((os_hooks) && (os_hooks)->malloc) { \
94 var = (os_hooks)->malloc(size); \
99 // We need to check the hook structure at runtime to ensure its SAFE
100 #define V3_Free(addr) \
102 extern struct vmm_os_hooks * os_hooks; \
103 if ((os_hooks) && (os_hooks)->free) { \
104 (os_hooks)->free(addr); \
109 // uint_t V3_CPU_KHZ();
110 #define V3_CPU_KHZ() \
112 unsigned int khz = 0; \
113 extern struct vmm_os_hooks * os_hooks; \
114 if ((os_hooks) && (os_hooks)->get_cpu_khz) { \
115 khz = (os_hooks)->get_cpu_khz(); \
122 #define V3_Hook_Interrupt(irq, opaque) \
125 extern struct vmm_os_hooks * os_hooks; \
126 if ((os_hooks) && (os_hooks)->hook_interrupt) { \
127 ret = (os_hooks)->hook_interrupt(irq, opaque); \
135 #define V3_ASSERT(x) \
138 PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
139 __func__, #x, __FILE__, __LINE__, \
140 (ulong_t) __builtin_return_address(0)); \
148 #define VMM_INVALID_CPU 0
149 #define VMM_VMX_CPU 1
150 #define VMM_SVM_CPU 2
153 // Maybe make this a define....
154 typedef enum v3_cpu_arch {V3_INVALID_CPU, V3_SVM_CPU, V3_SVM_REV3_CPU, V3_VMX_CPU} v3_cpu_arch_t;
160 typedef struct guest_info v3_guest_t;
162 typedef void v3_guest_t;
169 // This is the interrupt state that the VMM's interrupt handlers need to see
171 struct vmm_intr_state {
175 unsigned int should_ack; // Should the vmm ack this interrupt, or will
176 // the host OS do it?
178 // This is the value given when the interrupt is hooked.
179 // This will never be NULL
183 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
186 /* This will contain function pointers that provide OS services */
187 struct vmm_os_hooks {
188 void (*print_info)(const char * format, ...);
189 void (*print_debug)(const char * format, ...);
190 void (*print_trace)(const char * format, ...);
192 void *(*allocate_pages)(int numPages);
193 void (*free_page)(void * page);
195 void *(*malloc)(unsigned int size);
196 void (*free)(void * addr);
198 void *(*paddr_to_vaddr)(void *addr);
199 void *(*vaddr_to_paddr)(void *addr);
201 // int (*hook_interrupt)(struct guest_info *s, int irq);
203 int (*hook_interrupt)(unsigned int irq, void *opaque);
205 int (*ack_irq)(int irq);
208 unsigned int (*get_cpu_khz)();
211 void (*start_kernel_thread)(); // include pointer to function
215 // Filled in by initialization
220 /* This will contain Function pointers that control the VMs */
221 struct vmm_ctrl_ops {
222 void *(*allocate_guest)();
224 int (*config_guest)(v3_guest_t * info, void * config_ptr);
225 int (*init_guest)(v3_guest_t * info);
226 int (*start_guest)(v3_guest_t * info);
227 // int (*stop_vm)(uint_t vm_id);
229 int (*has_nested_paging)();
231 // v3_cpu_arch_t (*get_cpu_arch)();
237 void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);