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 PrintInfo(fmt, args...) \
34 extern struct vmm_os_hooks * os_hooks; \
35 if ((os_hooks) && (os_hooks)->print_info) { \
36 (os_hooks)->print_info((fmt), ##args); \
40 #define PrintInfo(fmt, args...)
45 #define PrintTrace(fmt, args...) \
47 extern struct vmm_os_hooks * os_hooks; \
48 if ((os_hooks) && (os_hooks)->print_trace) { \
49 (os_hooks)->print_trace((fmt), ##args); \
53 #define PrintTrace(fmt, args...)
57 #define V3_AllocPages(ptr, num_pages) \
59 extern struct vmm_os_hooks * os_hooks; \
61 if ((os_hooks) && (os_hooks)->allocate_pages) { \
62 ptr = (os_hooks)->allocate_pages(num_pages); \
68 #define V3_Malloc(type, var, size) \
70 extern struct vmm_os_hooks * os_hooks; \
72 if ((os_hooks) && (os_hooks)->malloc) { \
73 var = (type)(os_hooks)->malloc(size); \
78 #define V3_Malloc(size) ({ \
79 extern struct vmm_os_hooks * os_hooks; \
81 if ((os_hooks) && (os_hooks)->malloc) { \
82 var = (os_hooks)->malloc(size); \
87 // We need to check the hook structure at runtime to ensure its SAFE
88 #define V3_Free(addr) \
90 extern struct vmm_os_hooks * os_hooks; \
91 if ((os_hooks) && (os_hooks)->free) { \
92 (os_hooks)->free(addr); \
96 #define V3_CPU_KHZ() \
98 unsigned int khz = 0; \
99 extern struct vmm_os_hooks * os_hooks; \
100 if ((os_hooks) && (os_hooks)->get_cpu_khz) { \
101 khz = (os_hooks)->get_cpu_khz(); \
109 #define V3_ASSERT(x) \
112 PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
113 __func__, #x, __FILE__, __LINE__, \
114 (ulong_t) __builtin_return_address(0)); \
120 #define VMM_INVALID_CPU 0
121 #define VMM_VMX_CPU 1
122 #define VMM_SVM_CPU 2
127 /* This will contain function pointers that provide OS services */
128 struct vmm_os_hooks {
129 void (*print_info)(const char * format, ...);
130 void (*print_debug)(const char * format, ...);
131 void (*print_trace)(const char * format, ...);
133 void *(*allocate_pages)(int numPages);
134 void (*free_page)(void * page);
136 void *(*malloc)(unsigned int size);
137 void (*free)(void * addr);
139 void *(*paddr_to_vaddr)(void *addr);
140 void *(*vaddr_to_paddr)(void *addr);
142 int (*hook_interrupt)(struct guest_info * info, int irq);
143 int (*ack_irq)(int irq);
146 unsigned int (*get_cpu_khz)();
148 // Do we need this here?
149 // void (*snprintf)(char * dst, char * format, int len, ...);
153 void (*start_kernel_thread)(); // include pointer to function
158 /* This will contain Function pointers that control the VMs */
159 struct vmm_ctrl_ops {
160 int (*init_guest)(struct guest_info* info);
161 int (*start_guest)(struct guest_info * info);
162 // int (*stop_vm)(uint_t vm_id);
171 void Init_VMM(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);