1 #include <geekos/vmm_stubs.h>
2 #include <palacios/vmm.h>
3 #include <geekos/debug.h>
4 #include <geekos/serial.h>
7 #define SPEAKER_PORT 0x61
12 inline void VM_Out_Byte(ushort_t port, uchar_t value)
14 __asm__ __volatile__ (
17 : "a" (value), "Nd" (port)
22 * Read a byte from an I/O port.
24 inline uchar_t VM_In_Byte(ushort_t port)
28 __asm__ __volatile__ (
39 int IO_Read(ushort_t port, void * dst, uint_t length) {
43 for (i = 0; i < length; i++) {
44 *iter = VM_In_Byte(port);
53 int IO_Write(ushort_t port, void * src, uint_t length) {
58 for (i = 0; i < length; i++) {
59 VM_Out_Byte(port, *iter);
68 int IO_Write_to_Serial(ushort_t port, void * src, uint_t length) {
69 PrintBoth("Output from Guest on port %d (0x%x) Length=%d\n", port, port, length);
73 PrintBoth(">0x%.2x\n", *(char*)src);
76 PrintBoth(">0x%.4x\n", *(ushort_t*)src);
79 PrintBoth(">0x%.8x\n", *(uint_t*)src);
85 // SerialMemDump(src, length);
98 __asm__ __volatile__ (
104 PrintBoth("Starting To Buzz\n");
106 init=VM_In_Byte(SPEAKER_PORT);
109 VM_Out_Byte(SPEAKER_PORT, init|0x2);
110 for (j=0;j<1000000;j++) {
113 VM_Out_Byte(SPEAKER_PORT, init);
114 for (j=0;j<1000000;j++) {
127 struct vmm_os_hooks os_hooks;
128 struct vmm_ctrl_ops vmm_ops;
129 struct guest_info vm_info;
133 memset(&os_hooks, 0, sizeof(struct vmm_os_hooks));
134 memset(&vmm_ops, 0, sizeof(struct vmm_ctrl_ops));
135 memset(&vm_info, 0, sizeof(struct guest_info));
137 os_hooks.print_debug = &PrintBoth;
138 os_hooks.print_info = &Print;
139 os_hooks.print_trace = &SerialPrint;
140 os_hooks.allocate_pages = &Allocate_VMM_Pages;
141 os_hooks.free_page = &Free_VMM_Page;
142 os_hooks.malloc = &VMM_Malloc;
143 os_hooks.free = &VMM_Free;
144 os_hooks.vaddr_to_paddr = &Identity;
145 os_hooks.paddr_to_vaddr = &Identity;
149 Init_VMM(&os_hooks, &vmm_ops);
151 init_shadow_map(&(vm_info.mem_map));
152 init_shadow_page_state(&(vm_info.shdw_pg_state));
153 vm_info.page_mode = SHADOW_PAGING;
155 vm_info.cpu_mode = REAL;
157 init_vmm_io_map(&(vm_info.io_map));
162 // add_shared_mem_range(&(vm_info.mem_layout), 0, 0x800000, 0x10000);
163 // add_shared_mem_range(&(vm_info.mem_layout), 0, 0x1000000, 0);
165 rip = (ulong_t)(void*)&BuzzVM;
167 // rip = (addr_t)(void*)&exit_test;
170 rsp = (addr_t)Alloc_Page();
172 vm_info.vm_regs.rsp = (rsp +4092 );// - 0x2000;
176 //add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x1000, 0x100000);
177 // add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x100000, 0x0);
179 shadow_region_t *ent = Malloc(sizeof(shadow_region_t));;
180 init_shadow_region_physical(ent,0,0x100000,GUEST_REGION_PHYSICAL_MEMORY,
181 0x100000, HOST_REGION_PHYSICAL_MEMORY);
182 add_shadow_region(&(vm_info.mem_map),ent);
184 hook_io_port(&(vm_info.io_map), 0x61, &IO_Read, &IO_Write);
185 hook_io_port(&(vm_info.io_map), 0x05, &IO_Read, &IO_Write_to_Serial);
189 vm_info.cs.base=0xf000;
190 vm_info.cs.limit=0xffff;
192 //vm_info.rip = 0xfff0;
195 vm_info.vm_regs.rsp = 0x0;
198 PrintBoth("Initializing Guest (eip=0x%.8x) (esp=0x%.8x)\n", (uint_t)vm_info.rip,(uint_t)vm_info.vm_regs.rsp);
199 (vmm_ops).init_guest(&vm_info);
200 PrintBoth("Starting Guest\n");
201 (vmm_ops).start_guest(&vm_info);