5 #include <geekos/ktypes.h>
6 #include <geekos/string.h>
8 #include <geekos/vmm_mem.h>
9 #include <geekos/vmm_paging.h>
12 /* utility definitions */
13 #define PrintDebug(fmt, args...) \
15 extern struct vmm_os_hooks * os_hooks; \
16 if ((os_hooks) && (os_hooks)->print_debug) { \
17 (os_hooks)->print_debug((fmt), ##args); \
23 #define PrintInfo(fmt, args...) \
25 extern struct vmm_os_hooks * os_hooks; \
26 if ((os_hooks) && (os_hooks)->print_info) { \
27 (os_hooks)->print_info((fmt), ##args); \
32 #define PrintTrace(fmt, args...) \
34 extern struct vmm_os_hooks * os_hooks; \
35 if ((os_hooks) && (os_hooks)->print_trace) { \
36 (os_hooks)->print_trace((fmt), ##args); \
43 /* This clearly won't work, we need some way to get a return value out of it */
44 #define VMMMalloc(size) \
46 extern struct vmm_os_hooks * os_hooks; \
47 if ((os_hooks) && (os_hooks)->malloc) { \
48 (os_hooks)->malloc(size); \
53 // We need to check the hook structure at runtime to ensure its SAFE
54 #define VMMFree(addr) \
56 extern struct vmm_os_hooks * os_hooks; \
57 if ((os_hooks) && (os_hooks)->free) { \
58 (os_hooks)->free(addr); \
66 #define VMM_INVALID_CPU 0
72 typedef struct guest_info {
76 vmm_mem_list_t mem_list;
77 vmm_mem_layout_t mem_layout;
80 pml4e64_t * page_tables;
86 /* We need a memory map and an IO device map */
88 /* This will contain function pointers that provide OS services */
90 void (*print_info)(const char * format, ...);
91 void (*print_debug)(const char * format, ...);
92 void (*print_trace)(const char * format, ...);
94 void *(*allocate_pages)(int numPages);
95 void (*free_page)(void * page);
97 void *(*malloc)(uint_t size);
98 void (*free)(void * addr);
101 void (*start_kernel_thread)(); // include pointer to function
107 /* This will contain Function pointers that control the VMs */
108 struct vmm_ctrl_ops {
109 int (*init_guest)(struct guest_info* info);
110 int (*start_guest)(struct guest_info * info);
111 // int (*stop_vm)(uint_t vm_id);
120 void Init_VMM(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);