From: Jack Lange Date: Tue, 22 Jul 2008 22:27:28 +0000 (+0000) Subject: code clean up X-Git-Tag: vmmhack1-ramdisk-boot-iso-puppy~55 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=a1e0475bbefa968791679c5e71232ddca522868b code clean up --- diff --git a/palacios/build/Makefile b/palacios/build/Makefile index 0512886..0462485 100644 --- a/palacios/build/Makefile +++ b/palacios/build/Makefile @@ -1,6 +1,6 @@ # Makefile for GeekOS kernel, userspace, and tools # Copyright (c) 2004,2005 David H. Hovemeyer -# $Revision: 1.49 $ +# $Revision: 1.50 $ # This is free software. You are permitted to use, # redistribute, and modify it as specified in the file "COPYING". @@ -188,7 +188,7 @@ VMM_C_SRCS := vm_guest.c \ vmm_intr.c vmm_time.c\ vmm_shadow_paging.c vm_guest_mem.c \ vm_dev.c vmm_dev_mgr.c vmm_decoder.c \ - svm_halt.c svm_pause.c + svm_halt.c svm_pause.c vmm_config.c #\ # vmx.c vmcs_gen.c vmcs.c diff --git a/palacios/include/geekos/vm.h b/palacios/include/geekos/vm.h index 23a2275..e8558c0 100644 --- a/palacios/include/geekos/vm.h +++ b/palacios/include/geekos/vm.h @@ -1,20 +1,6 @@ #ifndef __VM_H #define __VM_H -#define MAGIC_CODE 0xf1e2d3c4 - -struct layout_region { - ulong_t length; - ulong_t final_addr; -}; - -struct guest_mem_layout { - ulong_t magic; - ulong_t num_regions; - struct layout_region regions[0]; -}; - - int RunVMM(struct Boot_Info * bootInfo); diff --git a/palacios/include/palacios/svm.h b/palacios/include/palacios/svm.h index 3ede354..52c1e3f 100644 --- a/palacios/include/palacios/svm.h +++ b/palacios/include/palacios/svm.h @@ -1,12 +1,15 @@ #ifndef __SVM_H #define __SVM_H -#include + #include -#include + #ifdef __V3VEE__ +#include +#include + #define CPUID_FEATURE_IDS 0x80000001 #define CPUID_FEATURE_IDS_ecx_svm_avail 0x00000004 diff --git a/palacios/include/palacios/svm_halt.h b/palacios/include/palacios/svm_halt.h index 7ffce50..8e48d84 100644 --- a/palacios/include/palacios/svm_halt.h +++ b/palacios/include/palacios/svm_halt.h @@ -1,5 +1,8 @@ #ifndef __SVM_HALT_H #define __SVM_HALT_H + +#ifdef __V3VEE__ + #include #include #include @@ -7,6 +10,6 @@ int handle_svm_halt(struct guest_info * info); - +#endif // ! __V3VEE__ #endif diff --git a/palacios/include/palacios/svm_handler.h b/palacios/include/palacios/svm_handler.h index da5967d..bd3aae4 100644 --- a/palacios/include/palacios/svm_handler.h +++ b/palacios/include/palacios/svm_handler.h @@ -1,5 +1,8 @@ #ifndef __SVM_HANDLER_H #define __SVM_HANDLER_H + +#ifdef __V3VEE__ + #include #include #include @@ -180,4 +183,6 @@ int handle_svm_intr(struct guest_info * info); int handle_svm_exit(struct guest_info * info); +#endif // ! __V3VEE__ + #endif diff --git a/palacios/include/palacios/svm_io.h b/palacios/include/palacios/svm_io.h index adb220a..9c233f0 100644 --- a/palacios/include/palacios/svm_io.h +++ b/palacios/include/palacios/svm_io.h @@ -1,9 +1,13 @@ #ifndef __SVM_IO_H #define __SVM_IO_H + +#ifdef __V3VEE__ + #include #include #include + struct svm_io_info { uint_t type : 1 PACKED; // (0=out, 1=in) uint_t rsvd : 1 PACKED; // Must be Zero @@ -25,7 +29,7 @@ int handle_svm_io_ins(struct guest_info * info); int handle_svm_io_out(struct guest_info * info); int handle_svm_io_outs(struct guest_info * info); - +#endif // !__V3VEE__ #endif diff --git a/palacios/include/palacios/svm_pause.h b/palacios/include/palacios/svm_pause.h index 5db30ef..aa966a5 100644 --- a/palacios/include/palacios/svm_pause.h +++ b/palacios/include/palacios/svm_pause.h @@ -1,5 +1,8 @@ #ifndef __SVM_PAUSE_H #define __SVM_PAUSE_H + +#ifdef __V3VEE__ + #include #include #include @@ -8,5 +11,6 @@ int handle_svm_pause(struct guest_info * info); +#endif // ! __V3VEE__ #endif diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index 1a5f186..e2d94c4 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -1,7 +1,7 @@ #ifndef __VM_GUEST_H #define __VM_GUEST_H - +#ifdef __V3VEE__ #include @@ -69,6 +69,7 @@ struct v3_segments { struct shadow_page_state; struct shadow_map; +struct vmm_io_map; struct vm_ctrl_ops { @@ -126,5 +127,11 @@ void PrintV3Segments(struct guest_info * info); void PrintV3CtrlRegs(struct guest_info * info); void PrintV3GPRs(struct guest_info * info); +#else + + +#endif + + #endif diff --git a/palacios/include/palacios/vmcb.h b/palacios/include/palacios/vmcb.h index fda2847..3b97500 100644 --- a/palacios/include/palacios/vmcb.h +++ b/palacios/include/palacios/vmcb.h @@ -1,6 +1,8 @@ #ifndef __VMCB_H #define __VMCB_H +#ifdef __V3VEE__ + #include #include @@ -360,4 +362,6 @@ void PrintDebugVMCB(vmcb_t * vmcb); void set_vmcb_segments(vmcb_t * vmcb, struct v3_segments * segs); void get_vmcb_segments(vmcb_t * vmcb, struct v3_segments * segs); +#endif // ! __V3VEE__ + #endif diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index 7d8e69c..2caba33 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -149,18 +149,30 @@ #define VMM_VMX_CPU 1 #define VMM_SVM_CPU 2 + +// Maybe make this a define.... +typedef enum v3_cpu_arch {V3_INVALID_CPU, V3_SVM_CPU, V3_SVM_REV3_CPU, V3_VMX_CPU} v3_cpu_arch_t; + + #endif //!__V3VEE__ +#ifdef __V3VEE__ +typedef struct guest_info v3_guest_t; +#else +typedef void v3_guest_t; +#endif + + // // // This is the interrupt state that the VMM's interrupt handlers need to see // struct vmm_intr_state { - uint_t irq; - uint_t error; + unsigned int irq; + unsigned int error; - uint_t should_ack; // Should the vmm ack this interrupt, or will + unsigned int should_ack; // Should the vmm ack this interrupt, or will // the host OS do it? // This is the value given when the interrupt is hooked. @@ -188,7 +200,7 @@ struct vmm_os_hooks { // int (*hook_interrupt)(struct guest_info *s, int irq); - int (*hook_interrupt)(uint_t irq, void *opaque); + int (*hook_interrupt)(unsigned int irq, void *opaque); int (*ack_irq)(int irq); @@ -197,17 +209,26 @@ struct vmm_os_hooks { void (*start_kernel_thread)(); // include pointer to function -}; + // Filled in by initialization + +}; + + /* This will contain Function pointers that control the VMs */ struct vmm_ctrl_ops { - int (*init_guest)(struct guest_info* info); - int (*start_guest)(struct guest_info * info); + void *(*allocate_guest)(); + + int (*config_guest)(v3_guest_t * info, void * config_ptr); + int (*init_guest)(v3_guest_t * info); + int (*start_guest)(v3_guest_t * info); // int (*stop_vm)(uint_t vm_id); int (*has_nested_paging)(); + + // v3_cpu_arch_t (*get_cpu_arch)(); }; diff --git a/palacios/include/palacios/vmm_dev_mgr.h b/palacios/include/palacios/vmm_dev_mgr.h index eba13c8..931bdd3 100644 --- a/palacios/include/palacios/vmm_dev_mgr.h +++ b/palacios/include/palacios/vmm_dev_mgr.h @@ -8,6 +8,7 @@ struct vm_device; struct guest_info; + struct vmm_dev_mgr { uint_t num_devs; struct list_head dev_list; @@ -21,9 +22,6 @@ struct vmm_dev_mgr { }; -int dev_mgr_init(struct vmm_dev_mgr *mgr); -int dev_mgr_deinit(struct vmm_dev_mgr * mgr); - // Registration of devices @@ -36,7 +34,7 @@ int v3_attach_device(struct guest_info *vm, struct vm_device * dev); int v3_unattach_device(struct vm_device *dev); -void PrintDebugDevMgr(struct vmm_dev_mgr * mgr); + #ifdef __V3VEE__ @@ -66,8 +64,10 @@ struct dev_mem_hook { }; +int dev_mgr_init(struct guest_info * info); +int dev_mgr_deinit(struct guest_info * info); - +void PrintDebugDevMgr(struct guest_info * info); void PrintDebugDev(struct vm_device * dev); void PrintDebugDevIO(struct vm_device * dev); void PrintDebugDevMgrIO(struct vmm_dev_mgr * mgr); diff --git a/palacios/include/palacios/vmm_io.h b/palacios/include/palacios/vmm_io.h index 1b4ff8a..601bffe 100644 --- a/palacios/include/palacios/vmm_io.h +++ b/palacios/include/palacios/vmm_io.h @@ -7,38 +7,32 @@ #include +struct guest_info; struct vmm_io_hook; struct vmm_io_map { uint_t num_ports; - - struct vmm_io_hook * head; }; -int v3_unhook_io_port(struct vmm_io_map * io_map, uint_t port); +int v3_unhook_io_port(struct guest_info * info, uint_t port); /* External API */ -int v3_hook_io_port(struct vmm_io_map * io_map, uint_t port, +int v3_hook_io_port(struct guest_info * info, uint_t port, int (*read)(ushort_t port, void * dst, uint_t length, void * priv_data), int (*write)(ushort_t port, void * src, uint_t length, void * priv_data), void * priv_data); -void init_vmm_io_map(struct vmm_io_map * io_map); - - - -struct vmm_io_hook * v3_get_io_hook(struct vmm_io_map * io_map, uint_t port); - - +void init_vmm_io_map(struct guest_info * info); #ifdef __V3VEE__ + // FOREACH_IO_HOOK(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) #define FOREACH_IO_HOOK(io_map, io_hook) for (io_hook = (io_map).head; io_hook != NULL; io_hook = (io_hook)->next) @@ -60,8 +54,7 @@ struct vmm_io_hook { }; - - +struct vmm_io_hook * v3_get_io_hook(struct vmm_io_map * io_map, uint_t port); void PrintDebugIOMap(struct vmm_io_map * io_map); diff --git a/palacios/include/palacios/vmm_list.h b/palacios/include/palacios/vmm_list.h index da7a0b2..83b880d 100644 --- a/palacios/include/palacios/vmm_list.h +++ b/palacios/include/palacios/vmm_list.h @@ -1,6 +1,9 @@ #ifndef _VMM_LIST_H #define _VMM_LIST_H +// JRL FIXME +// #ifdef __V3VEE__ + #include #undef offsetof @@ -525,4 +528,7 @@ static inline void hlist_add_after(struct hlist_node *n, pos = n) +// JRL FIXME +//#endif // ! __V3VEE__ + #endif diff --git a/palacios/include/palacios/vmm_mem.h b/palacios/include/palacios/vmm_mem.h index f8b8d0d..b5feefd 100644 --- a/palacios/include/palacios/vmm_mem.h +++ b/palacios/include/palacios/vmm_mem.h @@ -2,6 +2,8 @@ #define __VMM_MEM_H +#ifdef __V3VEE__ + #include @@ -85,7 +87,7 @@ int add_shadow_region_passthrough(struct guest_info * guest_info, addr_t guest_addr_end, addr_t host_addr); -void init_shadow_map(struct shadow_map * map); +void init_shadow_map(struct guest_info * info); void free_shadow_map(struct shadow_map * map); struct shadow_region * get_shadow_region_by_addr(struct shadow_map * map, addr_t guest_addr); @@ -142,4 +144,8 @@ int unhook_guest_mem(struct guest_info * info, addr_t guest_addr); int mem_hook_dispatch(struct guest_info * info, addr_t mem_addr, pf_error_t access_info, struct vmm_mem_hook * hook); int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_error_t access_info); + +#endif // ! __V3VEE__ + + #endif diff --git a/palacios/include/palacios/vmm_shadow_paging.h b/palacios/include/palacios/vmm_shadow_paging.h index 344e160..ac20544 100644 --- a/palacios/include/palacios/vmm_shadow_paging.h +++ b/palacios/include/palacios/vmm_shadow_paging.h @@ -2,6 +2,7 @@ #define __VMM_SHADOW_PAGING_H +#ifdef __V3VEE__ #include #include @@ -29,11 +30,11 @@ struct shadow_page_state { struct guest_info; -int init_shadow_page_state(struct shadow_page_state * state); -#ifdef __V3VEE__ +int init_shadow_page_state(struct guest_info * info); + addr_t create_new_shadow_pt32(struct guest_info * info); int handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code); diff --git a/palacios/include/palacios/vmm_time.h b/palacios/include/palacios/vmm_time.h index 9af1840..fd73ab0 100644 --- a/palacios/include/palacios/vmm_time.h +++ b/palacios/include/palacios/vmm_time.h @@ -25,6 +25,8 @@ struct vm_time { }; +#ifdef __V3VEE__ + struct vm_timer_ops { void (*update_time)(ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data); @@ -38,9 +40,6 @@ struct vm_timer { }; -void v3_init_time(struct vm_time * time_state); - - int v3_add_timer(struct guest_info * info, struct vm_timer_ops * ops, void * private_data); @@ -49,4 +48,11 @@ int v3_remove_timer(struct guest_info * info, struct vm_timer * timer); void v3_update_time(struct guest_info * info, ullong_t cycles); +#endif // !__V3VEE__ + + +void v3_init_time(struct guest_info * info); + + + #endif diff --git a/palacios/include/palacios/vmm_util.h b/palacios/include/palacios/vmm_util.h index 38ae086..6ecfa55 100644 --- a/palacios/include/palacios/vmm_util.h +++ b/palacios/include/palacios/vmm_util.h @@ -1,6 +1,8 @@ #ifndef __VMM_UTIL_H #define __VMM_UTIL_H +#ifdef __V3VEE__ + #include @@ -136,6 +138,6 @@ void PrintTraceMemDump(unsigned char * start, int n); - +#endif // ! __V3VEE__ #endif diff --git a/palacios/src/geekos/vm.c b/palacios/src/geekos/vm.c index a6f5bb0..e23e64e 100644 --- a/palacios/src/geekos/vm.c +++ b/palacios/src/geekos/vm.c @@ -1,22 +1,15 @@ #include -#include + #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include + + -#include -#include -#include //test decoder //#include @@ -178,12 +171,12 @@ void BuzzVM() -int passthrough_mem_read(addr_t guest_addr, void * dst, uint_t length, void * priv_data) { +int passthrough_mem_read(void * guest_addr, void * dst, uint_t length, void * priv_data) { memcpy(dst, (void*)guest_addr, length); return length; } -int passthrough_mem_write(addr_t guest_addr, void * src, uint_t length, void * priv_data) { +int passthrough_mem_write(void * guest_addr, void * src, uint_t length, void * priv_data) { memcpy((void*)guest_addr, src, length); return length; } @@ -195,297 +188,69 @@ int passthrough_mem_write(addr_t guest_addr, void * src, uint_t length, void * p */ int RunVMM(struct Boot_Info * bootInfo) { + void * config_data; - struct vmm_os_hooks os_hooks; - struct vmm_ctrl_ops vmm_ops; - struct guest_info vm_info; - addr_t rsp; - addr_t rip; - - - - - - memset(&os_hooks, 0, sizeof(struct vmm_os_hooks)); - memset(&vmm_ops, 0, sizeof(struct vmm_ctrl_ops)); - memset(&vm_info, 0, sizeof(struct guest_info)); - - os_hooks.print_debug = &SerialPrint; - os_hooks.print_info = &Print; - os_hooks.print_trace = &SerialPrint; - os_hooks.allocate_pages = &Allocate_VMM_Pages; - os_hooks.free_page = &Free_VMM_Page; - os_hooks.malloc = &VMM_Malloc; - os_hooks.free = &VMM_Free; - os_hooks.vaddr_to_paddr = &Identity; - os_hooks.paddr_to_vaddr = &Identity; - os_hooks.hook_interrupt = &geekos_hook_interrupt_new; - os_hooks.ack_irq = &ack_irq; - os_hooks.get_cpu_khz = &get_cpu_khz; - - - - Init_V3(&os_hooks, &vmm_ops); - - //test decoder - PrintBoth("testing decoder\n"); - parse(); - PrintBoth("testing decoder done\n"); + struct vmm_os_hooks os_hooks; + struct vmm_ctrl_ops vmm_ops; + v3_guest_t* vm_info = 0; - /* MOVE THIS TO AN INIT GUEST ROUTINE */ - - - v3_init_time(&(vm_info.time_state)); - init_shadow_map(&(vm_info.mem_map)); - - if ((vmm_ops).has_nested_paging()) { - vm_info.shdw_pg_mode = NESTED_PAGING; - } else { - init_shadow_page_state(&(vm_info.shdw_pg_state)); - vm_info.shdw_pg_mode = SHADOW_PAGING; - } - - vm_info.cpu_mode = REAL; - vm_info.mem_mode = PHYSICAL_MEM; - //init_irq_map(&(vm_info.irq_map)); - init_vmm_io_map(&(vm_info.io_map)); - init_interrupt_state(&vm_info); - - dev_mgr_init(&(vm_info.dev_mgr)); - /* ** */ - - if (0) { - - // add_shared_mem_range(&(vm_info.mem_layout), 0, 0x800000, 0x10000); - // add_shared_mem_range(&(vm_info.mem_layout), 0, 0x1000000, 0); - - rip = (ulong_t)(void*)&BuzzVM; - // rip -= 0x10000; - // rip = (addr_t)(void*)&exit_test; - // rip -= 0x2000; - vm_info.rip = rip; - rsp = (addr_t)Alloc_Page(); - - vm_info.vm_regs.rsp = (rsp +4092 );// - 0x2000; - - - } else if (0) { - //add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x1000, 0x100000); - // add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x100000, 0x0); - - /* - shadow_region_t *ent = Malloc(sizeof(shadow_region_t));; - init_shadow_region_physical(ent,0,0x100000,GUEST_REGION_PHYSICAL_MEMORY, - 0x100000, HOST_REGION_PHYSICAL_MEMORY); - add_shadow_region(&(vm_info.mem_map),ent); - */ - - add_shadow_region_passthrough(&vm_info, 0x0, 0x100000, 0x100000); - - v3_hook_io_port(&(vm_info.io_map), 0x61, &IO_Read, &IO_Write, NULL); - v3_hook_io_port(&(vm_info.io_map), 0x05, &IO_Read, &IO_Write_to_Serial, NULL); - - /* - vm_info.cr0 = 0; - vm_info.cs.base=0xf000; - vm_info.cs.limit=0xffff; - */ - //vm_info.rip = 0xfff0; - - vm_info.rip = 0; - vm_info.vm_regs.rsp = 0x0; - } else { - int i; - void * region_start; - - extern char _binary_vm_kernel_start; - PrintBoth(" Guest Load Addr: 0x%x\n", &_binary_vm_kernel_start); - - struct guest_mem_layout * layout = (struct guest_mem_layout *)&_binary_vm_kernel_start; - - // SerialPrint("Guest Mem Dump at 0x%x\n", 0x100000); - //SerialMemDump((unsigned char *)(0x100000), 261 * 1024); - if (layout->magic != MAGIC_CODE) { - - PrintBoth("Layout Magic Mismatch (0x%x)\n", layout->magic); - return -1; - } - - PrintBoth("%d layout regions\n", layout->num_regions); - - region_start = (void *)&(layout->regions[layout->num_regions]); - - PrintBoth("region start = 0x%x\n", region_start); - - for (i = 0; i < layout->num_regions; i++) { - struct layout_region * reg = &(layout->regions[i]); - uint_t num_pages = (reg->length / PAGE_SIZE) + ((reg->length % PAGE_SIZE) ? 1 : 0); - void * guest_mem = Allocate_VMM_Pages(num_pages); - - PrintBoth("Layout Region %d bytes\n", reg->length); - memcpy(guest_mem, region_start, reg->length); - - SerialMemDump((unsigned char *)(guest_mem), 16); - - add_shadow_region_passthrough(&vm_info, reg->final_addr, reg->final_addr + (num_pages * PAGE_SIZE), (addr_t)guest_mem); - - PrintBoth("Adding Shadow Region (0x%x-0x%x) -> 0x%x\n", reg->final_addr, reg->final_addr + (num_pages * PAGE_SIZE), guest_mem); - - region_start += reg->length; - } - - // - add_shadow_region_passthrough(&vm_info, 0x0, 0xa0000, (addr_t)Allocate_VMM_Pages(160)); - - add_shadow_region_passthrough(&vm_info, 0xa0000, 0xc0000, 0xa0000); - //hook_guest_mem(&vm_info, 0xa0000, 0xc0000, passthrough_mem_read, passthrough_mem_write, NULL); - - - // TEMP - //add_shadow_region_passthrough(&vm_info, 0xc0000, 0xc8000, 0xc0000); - - if (1) { - add_shadow_region_passthrough(&vm_info, 0xc7000, 0xc8000, (addr_t)Allocate_VMM_Pages(1)); - if (add_shadow_region_passthrough(&vm_info, 0xc8000, 0xf0000, (addr_t)Allocate_VMM_Pages(40)) == -1) { - PrintBoth("Error adding shadow region\n"); - } - } else { - add_shadow_region_passthrough(&vm_info, 0xc0000, 0xc8000, 0xc0000); - add_shadow_region_passthrough(&vm_info, 0xc8000, 0xf0000, 0xc8000); - } - - - //add_shadow_region_passthrough(&vm_info, 0x100000, 0x2000000, (addr_t)Allocate_VMM_Pages(8192)); - add_shadow_region_passthrough(&vm_info, 0x100000, 0x1000000, (addr_t)Allocate_VMM_Pages(4096)); - - add_shadow_region_passthrough(&vm_info, 0x1000000, 0x8000000, (addr_t)Allocate_VMM_Pages(32768)); - - // test - give linux accesss to PCI space - PAD - add_shadow_region_passthrough(&vm_info, 0xc0000000,0xffffffff,0xc0000000); - - - print_shadow_map(&(vm_info.mem_map)); - - v3_hook_io_port(&(vm_info.io_map), 0x61, &IO_Read, &IO_Write, NULL); - //v3_hook_io_port(&(vm_info.io_map), 0x05, &IO_Read, &IO_Write_to_Serial, NULL); - - - v3_hook_io_port(&(vm_info.io_map), 0x400, &IO_Read, &IO_Write_to_Serial, NULL); - v3_hook_io_port(&(vm_info.io_map), 0x401, &IO_Read, &IO_Write_to_Serial, NULL); - v3_hook_io_port(&(vm_info.io_map), 0x402, &IO_Read, &IO_BOCHS_info, NULL); - v3_hook_io_port(&(vm_info.io_map), 0x403, &IO_Read, &IO_BOCHS_debug, NULL); - - { - - struct vm_device * nvram = create_nvram(); - //struct vm_device * timer = create_timer(); - struct vm_device * pic = create_pic(); - struct vm_device * keyboard = create_keyboard(); - struct vm_device * pit = create_pit(); - //struct vm_device * serial = create_serial(); - - -#define GENERIC 1 - -#if GENERIC - generic_port_range_type range[] = { -#if 1 - {0x00, 0x07, GENERIC_PRINT_AND_IGNORE}, // DMA 1 channels 0,1,2,3 (address, counter) - {0xc0, 0xc7, GENERIC_PRINT_AND_IGNORE}, // DMA 2 channels 4,5,6,7 (address, counter) - {0x87, 0x87, GENERIC_PRINT_AND_IGNORE}, // DMA 1 channel 0 page register - {0x83, 0x83, GENERIC_PRINT_AND_IGNORE}, // DMA 1 channel 1 page register - {0x81, 0x81, GENERIC_PRINT_AND_IGNORE}, // DMA 1 channel 2 page register - {0x82, 0x82, GENERIC_PRINT_AND_IGNORE}, // DMA 1 channel 3 page register - {0x8f, 0x8f, GENERIC_PRINT_AND_IGNORE}, // DMA 2 channel 4 page register - {0x8b, 0x8b, GENERIC_PRINT_AND_IGNORE}, // DMA 2 channel 5 page register - {0x89, 0x89, GENERIC_PRINT_AND_IGNORE}, // DMA 2 channel 6 page register - {0x8a, 0x8a, GENERIC_PRINT_AND_IGNORE}, // DMA 2 channel 7 page register - {0x08, 0x0f, GENERIC_PRINT_AND_IGNORE}, // DMA 1 misc registers (csr, req, smask,mode,clearff,reset,enable,mmask) - {0xd0, 0xde, GENERIC_PRINT_AND_IGNORE}, // DMA 2 misc registers -#endif - - - {0x3f8, 0x3f8+7, GENERIC_PRINT_AND_IGNORE}, // COM 1 - {0x2f8, 0x2f8+7, GENERIC_PRINT_AND_IGNORE}, // COM 2 - {0x3e8, 0x3e8+7, GENERIC_PRINT_AND_IGNORE}, // COM 3 - {0x2e8, 0x2e8+7, GENERIC_PRINT_AND_IGNORE}, // COM 4 - -#if 0 - {0x170, 0x178, GENERIC_PRINT_AND_PASSTHROUGH}, // IDE 1 - {0x376, 0x377, GENERIC_PRINT_AND_PASSTHROUGH}, // IDE 1 - {0x1f0, 0x1f8, GENERIC_PRINT_AND_PASSTHROUGH}, // IDE 0 - {0x3f6, 0x3f7, GENERIC_PRINT_AND_PASSTHROUGH}, // IDE 0 -#endif - - -#if 0 - {0x3f0, 0x3f2, GENERIC_PRINT_AND_IGNORE}, // Primary floppy controller (base,statusa/statusb,DOR) - {0x3f4, 0x3f5, GENERIC_PRINT_AND_IGNORE}, // Primary floppy controller (mainstat/datarate,data) - {0x3f7, 0x3f7, GENERIC_PRINT_AND_IGNORE}, // Primary floppy controller (DIR) - {0x370, 0x372, GENERIC_PRINT_AND_IGNORE}, // Secondary floppy controller (base,statusa/statusb,DOR) - {0x374, 0x375, GENERIC_PRINT_AND_IGNORE}, // Secondary floppy controller (mainstat/datarate,data) - {0x377, 0x377, GENERIC_PRINT_AND_IGNORE}, // Secondary floppy controller (DIR) - -#endif - - // {0x378, 0x400, GENERIC_PRINT_AND_IGNORE} - - {0,0,0}, // sentinal - must be last - - }; - - - struct vm_device * generic = create_generic(range, NULL, NULL); - -#endif - - v3_attach_device(&(vm_info), nvram); - //v3_attach_device(&(vm_info), timer); - v3_attach_device(&(vm_info), pic); - v3_attach_device(&(vm_info), pit); - v3_attach_device(&(vm_info), keyboard); - // v3_attach_device(&(vm_info), serial); - - -#if GENERIC - // Important that this be attached last! - v3_attach_device(&(vm_info), generic); - -#endif + + memset(&os_hooks, 0, sizeof(struct vmm_os_hooks)); + memset(&vmm_ops, 0, sizeof(struct vmm_ctrl_ops)); - PrintDebugDevMgr(&(vm_info.dev_mgr)); - } + + os_hooks.print_debug = &SerialPrint; + os_hooks.print_info = &Print; + os_hooks.print_trace = &SerialPrint; + os_hooks.allocate_pages = &Allocate_VMM_Pages; + os_hooks.free_page = &Free_VMM_Page; + os_hooks.malloc = &VMM_Malloc; + os_hooks.free = &VMM_Free; + os_hooks.vaddr_to_paddr = &Identity; + os_hooks.paddr_to_vaddr = &Identity; + os_hooks.hook_interrupt = &geekos_hook_interrupt_new; + os_hooks.ack_irq = &ack_irq; + os_hooks.get_cpu_khz = &get_cpu_khz; - // give keyboard interrupts to vm - // no longer needed since we have a keyboard device - //hook_irq(&vm_info, 1); - -#if 1 - // give floppy controller to vm - v3_hook_irq_for_guest_injection(&vm_info, 6); -#endif -#if 1 - //primary ide - v3_hook_irq_for_guest_injection(&vm_info, 14); + + Init_V3(&os_hooks, &vmm_ops); + + //test decoder + PrintBoth("testing decoder\n"); + parse(); + PrintBoth("testing decoder done\n"); + - // secondary ide - v3_hook_irq_for_guest_injection(&vm_info, 15); -#endif + extern char _binary_vm_kernel_start; + PrintBoth(" Guest Load Addr: 0x%x\n", &_binary_vm_kernel_start); + + config_data = &_binary_vm_kernel_start; + vm_info = (vmm_ops).allocate_guest(); - vm_info.rip = 0xfff0; - vm_info.vm_regs.rsp = 0x0; - } + PrintBoth("Allocated Guest\n"); + (vmm_ops).config_guest(vm_info, config_data); - PrintBoth("Initializing Guest (eip=0x%.8x) (esp=0x%.8x)\n", (uint_t)vm_info.rip,(uint_t)vm_info.vm_regs.rsp); - (vmm_ops).init_guest(&vm_info); - PrintBoth("Starting Guest\n"); - //Clear_Screen(); - (vmm_ops).start_guest(&vm_info); + PrintBoth("Configured guest\n"); + + v3_hook_io_port(vm_info, 0x61, &IO_Read, &IO_Write, NULL); + //v3_hook_io_port(&vm_info, 0x05, &IO_Read, &IO_Write_to_Serial, NULL); + + + v3_hook_io_port(vm_info, 0x400, &IO_Read, &IO_Write_to_Serial, NULL); + v3_hook_io_port(vm_info, 0x401, &IO_Read, &IO_Write_to_Serial, NULL); + v3_hook_io_port(vm_info, 0x402, &IO_Read, &IO_BOCHS_info, NULL); + v3_hook_io_port(vm_info, 0x403, &IO_Read, &IO_BOCHS_debug, NULL); + + (vmm_ops).init_guest(vm_info); + PrintBoth("Starting Guest\n"); + //Clear_Screen(); + (vmm_ops).start_guest(vm_info); + return 0; } diff --git a/palacios/src/geekos/vmm_stubs.c b/palacios/src/geekos/vmm_stubs.c index f419613..1afe27e 100644 --- a/palacios/src/geekos/vmm_stubs.c +++ b/palacios/src/geekos/vmm_stubs.c @@ -120,6 +120,8 @@ static void translate_intr_handler(struct Interrupt_State *state) } + +/* static void pic_intr_handler(struct Interrupt_State * state) { Begin_IRQ(state); struct guest_info * info = irq_map[state->intNum - 32]; @@ -135,11 +137,12 @@ static void pic_intr_handler(struct Interrupt_State * state) { // End_IRQ(state); } - +*/ // // // I really don't know what the heck this is doing... PAD // +/* int hook_irq_stub(struct guest_info * info, int irq) { if (irq_map[irq]) { return -1; @@ -149,7 +152,7 @@ int hook_irq_stub(struct guest_info * info, int irq) { irq_map[irq] = info; volatile void *foo = pic_intr_handler; - /* This is disabled for the time being */ + // This is disabled for the time being foo = 0; @@ -158,7 +161,7 @@ int hook_irq_stub(struct guest_info * info, int irq) { Enable_IRQ(irq); return 0; } - +*/ int geekos_hook_interrupt_new(uint_t irq, void * opaque) { diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 7526002..37e0224 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -221,13 +221,6 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { } - - - - - - - static int init_svm_guest(struct guest_info *info) { PrintDebug("Allocating VMCB\n"); diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 036d8ae..9ac1597 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -2,28 +2,32 @@ #include #include #include +#include +#include -uint_t vmm_cpu_type; - - - - +v3_cpu_arch_t v3_cpu_type; struct vmm_os_hooks * os_hooks = NULL; +void * allocate_guest() { + void * info = V3_Malloc(sizeof(struct guest_info)); + memset(info, 0, sizeof(struct guest_info)); + return info; +} -void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops) { - vmm_cpu_type = VMM_INVALID_CPU; +void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops) { os_hooks = hooks; + v3_cpu_type = V3_INVALID_CPU; if (is_svm_capable()) { - vmm_cpu_type = VMM_SVM_CPU; - PrintDebug("Machine is SVM Capable\n"); + PrintDebug("Machine is SVM Capable\n"); + vmm_ops->allocate_guest = &allocate_guest; + vmm_ops->config_guest = &config_guest; Init_SVM(vmm_ops); /* @@ -35,3 +39,7 @@ void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops) { PrintDebug("CPU has no virtualization Extensions\n"); } } + + +// Get CPU Type.. + diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index 1d6f35c..7f43e34 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -10,8 +10,8 @@ #define NULL 0 #endif -int dev_mgr_init(struct vmm_dev_mgr * mgr) { - +int dev_mgr_init(struct guest_info * info) { + struct vmm_dev_mgr * mgr = &(info->dev_mgr); INIT_LIST_HEAD(&(mgr->dev_list)); mgr->num_devs = 0; @@ -22,8 +22,9 @@ int dev_mgr_init(struct vmm_dev_mgr * mgr) { } -int dev_mgr_deinit(struct vmm_dev_mgr * mgr) { +int dev_mgr_deinit(struct guest_info * info) { struct vm_device * dev; + struct vmm_dev_mgr * mgr = &(info->dev_mgr); list_for_each_entry(dev, &(mgr->dev_list), dev_link) { v3_unattach_device(dev); @@ -123,10 +124,10 @@ int dev_hook_io(struct vm_device *dev, } - if (v3_hook_io_port(&(dev->vm->io_map), port, - (int (*)(ushort_t, void *, uint_t, void *))read, - (int (*)(ushort_t, void *, uint_t, void *))write, - (void *)dev) == 0) { + if (v3_hook_io_port(dev->vm, port, + (int (*)(ushort_t, void *, uint_t, void *))read, + (int (*)(ushort_t, void *, uint_t, void *))write, + (void *)dev) == 0) { hook->dev = dev; hook->port = port; @@ -157,7 +158,7 @@ int dev_unhook_io(struct vm_device *dev, dev_mgr_remove_io_hook(mgr, hook); dev_remove_io_hook(dev, hook); - return v3_unhook_io_port(&(dev->vm->io_map), port); + return v3_unhook_io_port(dev->vm, port); } @@ -244,7 +245,8 @@ int dev_mgr_unhook_mem(struct vm_device *dev, -void PrintDebugDevMgr(struct vmm_dev_mgr * mgr) { +void PrintDebugDevMgr(struct guest_info * info) { + struct vmm_dev_mgr * mgr = &(info->dev_mgr); struct vm_device * dev; PrintDebug("%d devices registered with manager\n", mgr->num_devs); diff --git a/palacios/src/palacios/vmm_io.c b/palacios/src/palacios/vmm_io.c index 8266837..3cfe633 100644 --- a/palacios/src/palacios/vmm_io.c +++ b/palacios/src/palacios/vmm_io.c @@ -11,7 +11,8 @@ #endif -void init_vmm_io_map(struct vmm_io_map * io_map) { +void init_vmm_io_map(struct guest_info * info) { + struct vmm_io_map * io_map = &(info->io_map); io_map->num_ports = 0; io_map->head = NULL; } @@ -130,10 +131,11 @@ static int default_read(ushort_t port, void * dst, uint_t length, void * priv_da return 0; } -int v3_hook_io_port(struct vmm_io_map * io_map, uint_t port, - int (*read)(ushort_t port, void * dst, uint_t length, void * priv_data), - int (*write)(ushort_t port, void * src, uint_t length, void * priv_data), - void * priv_data) { +int v3_hook_io_port(struct guest_info * info, uint_t port, + int (*read)(ushort_t port, void * dst, uint_t length, void * priv_data), + int (*write)(ushort_t port, void * src, uint_t length, void * priv_data), + void * priv_data) { + struct vmm_io_map * io_map = &(info->io_map); struct vmm_io_hook * io_hook = (struct vmm_io_hook *)V3_Malloc(sizeof(struct vmm_io_hook)); io_hook->port = port; @@ -163,7 +165,8 @@ int v3_hook_io_port(struct vmm_io_map * io_map, uint_t port, return 0; } -int v3_unhook_io_port(struct vmm_io_map * io_map, uint_t port) { +int v3_unhook_io_port(struct guest_info * info, uint_t port) { + struct vmm_io_map * io_map = &(info->io_map); struct vmm_io_hook * hook = v3_get_io_hook(io_map, port); if (hook == NULL) { diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index f31d471..7c2a53a 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -106,7 +106,9 @@ int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_erro -void init_shadow_map(struct shadow_map * map) { +void init_shadow_map(struct guest_info * info) { + struct shadow_map * map = &(info->mem_map); + map->num_regions = 0; map->head = NULL; diff --git a/palacios/src/palacios/vmm_shadow_paging.c b/palacios/src/palacios/vmm_shadow_paging.c index 3c79431..0097853 100644 --- a/palacios/src/palacios/vmm_shadow_paging.c +++ b/palacios/src/palacios/vmm_shadow_paging.c @@ -23,7 +23,8 @@ static int handle_shadow_pte32_fault(struct guest_info* info, static int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code); -int init_shadow_page_state(struct shadow_page_state * state) { +int init_shadow_page_state(struct guest_info * info) { + struct shadow_page_state * state = &(info->shdw_pg_state); state->guest_mode = PDE32; state->shadow_mode = PDE32; diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index 77459e2..1c345d4 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -2,7 +2,8 @@ #include "palacios/vmm.h" -void v3_init_time(struct vm_time * time_state) { +void v3_init_time(struct guest_info * info) { + struct vm_time * time_state = &(info->time_state); time_state->cpu_freq = V3_CPU_KHZ();