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(ptr, 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); \
78 #define V3_FreePage(page) \
80 extern struct vmm_os_hooks * os_hooks; \
81 if ((os_hooks) && (os_hooks)->free_page) { \
82 (os_hooks)->free_page(page); \
89 #define V3_Malloc(size) ({ \
90 extern struct vmm_os_hooks * os_hooks; \
92 if ((os_hooks) && (os_hooks)->malloc) { \
93 var = (os_hooks)->malloc(size); \
98 // We need to check the hook structure at runtime to ensure its SAFE
99 #define V3_Free(addr) \
101 extern struct vmm_os_hooks * os_hooks; \
102 if ((os_hooks) && (os_hooks)->free) { \
103 (os_hooks)->free(addr); \
108 // uint_t V3_CPU_KHZ();
109 #define V3_CPU_KHZ() \
111 unsigned int khz = 0; \
112 extern struct vmm_os_hooks * os_hooks; \
113 if ((os_hooks) && (os_hooks)->get_cpu_khz) { \
114 khz = (os_hooks)->get_cpu_khz(); \
121 #define V3_Hook_Interrupt(irq, opaque) \
124 extern struct vmm_os_hooks * os_hooks; \
125 if ((os_hooks) && (os_hooks)->hook_interrupt) { \
126 ret = (os_hooks)->hook_interrupt(irq, opaque); \
134 #define V3_ASSERT(x) \
137 PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
138 __func__, #x, __FILE__, __LINE__, \
139 (ulong_t) __builtin_return_address(0)); \
147 #define VMM_INVALID_CPU 0
148 #define VMM_VMX_CPU 1
149 #define VMM_SVM_CPU 2
156 // This is the interrupt state that the VMM's interrupt handlers need to see
158 struct vmm_intr_state {
162 uint_t should_ack; // Should the vmm ack this interrupt, or will
163 // the host OS do it?
165 // This is the value given when the interrupt is hooked.
166 // This will never be NULL
170 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
173 /* This will contain function pointers that provide OS services */
174 struct vmm_os_hooks {
175 void (*print_info)(const char * format, ...);
176 void (*print_debug)(const char * format, ...);
177 void (*print_trace)(const char * format, ...);
179 void *(*allocate_pages)(int numPages);
180 void (*free_page)(void * page);
182 void *(*malloc)(unsigned int size);
183 void (*free)(void * addr);
185 void *(*paddr_to_vaddr)(void *addr);
186 void *(*vaddr_to_paddr)(void *addr);
188 // int (*hook_interrupt)(struct guest_info *s, int irq);
190 int (*hook_interrupt)(uint_t irq, void *opaque);
192 int (*ack_irq)(int irq);
195 unsigned int (*get_cpu_khz)();
198 void (*start_kernel_thread)(); // include pointer to function
203 /* This will contain Function pointers that control the VMs */
204 struct vmm_ctrl_ops {
205 int (*init_guest)(struct guest_info* info);
206 int (*start_guest)(struct guest_info * info);
207 // int (*stop_vm)(uint_t vm_id);
209 int (*has_nested_paging)();
215 void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);