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 */
17 #define PrintDebug(fmt, args...) \
19 extern struct vmm_os_hooks * os_hooks; \
20 if ((os_hooks) && (os_hooks)->print_debug) { \
21 (os_hooks)->print_debug((fmt), ##args); \
27 #define PrintInfo(fmt, args...) \
29 extern struct vmm_os_hooks * os_hooks; \
30 if ((os_hooks) && (os_hooks)->print_info) { \
31 (os_hooks)->print_info((fmt), ##args); \
36 #define PrintTrace(fmt, args...) \
38 extern struct vmm_os_hooks * os_hooks; \
39 if ((os_hooks) && (os_hooks)->print_trace) { \
40 (os_hooks)->print_trace((fmt), ##args); \
46 #define V3_AllocPages(ptr, num_pages) \
48 extern struct vmm_os_hooks * os_hooks; \
50 if ((os_hooks) && (os_hooks)->allocate_pages) { \
51 ptr = (os_hooks)->allocate_pages(num_pages); \
57 #define V3_Malloc(type, var, size) \
59 extern struct vmm_os_hooks * os_hooks; \
61 if ((os_hooks) && (os_hooks)->malloc) { \
62 var = (type)(os_hooks)->malloc(size); \
67 #define V3_Malloc(size) ({ \
68 extern struct vmm_os_hooks * os_hooks; \
70 if ((os_hooks) && (os_hooks)->malloc) { \
71 var = (os_hooks)->malloc(size); \
76 // We need to check the hook structure at runtime to ensure its SAFE
77 #define V3_Free(addr) \
79 extern struct vmm_os_hooks * os_hooks; \
80 if ((os_hooks) && (os_hooks)->free) { \
81 (os_hooks)->free(addr); \
85 #define V3_CPU_KHZ() \
87 unsigned int khz = 0; \
88 extern struct vmm_os_hooks * os_hooks; \
89 if ((os_hooks) && (os_hooks)->get_cpu_khz) { \
90 khz = (os_hooks)->get_cpu_khz(); \
98 #define V3_ASSERT(x) \
101 PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
102 __func__, #x, __FILE__, __LINE__, \
103 (ulong_t) __builtin_return_address(0)); \
109 #define VMM_INVALID_CPU 0
110 #define VMM_VMX_CPU 1
111 #define VMM_SVM_CPU 2
116 /* This will contain function pointers that provide OS services */
117 struct vmm_os_hooks {
118 void (*print_info)(const char * format, ...);
119 void (*print_debug)(const char * format, ...);
120 void (*print_trace)(const char * format, ...);
122 void *(*allocate_pages)(int numPages);
123 void (*free_page)(void * page);
125 void *(*malloc)(unsigned int size);
126 void (*free)(void * addr);
128 void *(*paddr_to_vaddr)(void *addr);
129 void *(*vaddr_to_paddr)(void *addr);
131 int (*hook_interrupt)(struct guest_info * info, int irq);
132 int (*ack_irq)(int irq);
135 unsigned int (*get_cpu_khz)();
137 // Do we need this here?
138 // void (*snprintf)(char * dst, char * format, int len, ...);
142 void (*start_kernel_thread)(); // include pointer to function
147 /* This will contain Function pointers that control the VMs */
148 struct vmm_ctrl_ops {
149 int (*init_guest)(struct guest_info* info);
150 int (*start_guest)(struct guest_info * info);
151 // int (*stop_vm)(uint_t vm_id);
160 void Init_VMM(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);