From: Jack Lange Date: Tue, 22 Jul 2008 20:47:32 +0000 (+0000) Subject: code clean up X-Git-Tag: vmmhack1-ramdisk-boot-iso-puppy~57 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6c28cc8753bb0e1b17b5c6c2ee296eb60e09079c code clean up getting rid of typedefs and making functions static --- diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index bc2c814..1a5f186 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -101,7 +101,7 @@ struct guest_info { // This structure is how we get interrupts for the guest struct vm_intr intr_state; - vmm_io_map_t io_map; + struct vmm_io_map io_map; // device_map struct vmm_dev_mgr dev_mgr; diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index 8e64a04..7d8e69c 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -65,14 +65,15 @@ #endif -#define V3_AllocPages(ptr, num_pages) \ - do { \ +#define V3_AllocPages(num_pages) \ + ({ \ extern struct vmm_os_hooks * os_hooks; \ - ptr = 0; \ + void * ptr = 0; \ if ((os_hooks) && (os_hooks)->allocate_pages) { \ ptr = (os_hooks)->allocate_pages(num_pages); \ } \ - } while (0) \ + ptr; \ + }) \ #define V3_FreePage(page) \ diff --git a/palacios/include/palacios/vmm_io.h b/palacios/include/palacios/vmm_io.h index 9609453..1b4ff8a 100644 --- a/palacios/include/palacios/vmm_io.h +++ b/palacios/include/palacios/vmm_io.h @@ -9,29 +9,29 @@ struct vmm_io_hook; -typedef struct vmm_io_map { +struct vmm_io_map { uint_t num_ports; struct vmm_io_hook * head; -} vmm_io_map_t; +}; -int v3_unhook_io_port(vmm_io_map_t * io_map, uint_t port); +int v3_unhook_io_port(struct vmm_io_map * io_map, uint_t port); /* External API */ -int v3_hook_io_port(vmm_io_map_t * io_map, uint_t port, +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); -void init_vmm_io_map(vmm_io_map_t * io_map); +void init_vmm_io_map(struct vmm_io_map * io_map); -struct vmm_io_hook * v3_get_io_hook(vmm_io_map_t * io_map, uint_t port); +struct vmm_io_hook * v3_get_io_hook(struct vmm_io_map * io_map, uint_t port); @@ -59,12 +59,12 @@ struct vmm_io_hook { }; -typedef struct vmm_io_hook vmm_io_hook_t; -void PrintDebugIOMap(vmm_io_map_t * io_map); + +void PrintDebugIOMap(struct vmm_io_map * io_map); #endif // !__V3VEE__ diff --git a/palacios/include/palacios/vmm_shadow_paging.h b/palacios/include/palacios/vmm_shadow_paging.h index 4ca198b..344e160 100644 --- a/palacios/include/palacios/vmm_shadow_paging.h +++ b/palacios/include/palacios/vmm_shadow_paging.h @@ -31,30 +31,14 @@ struct guest_info; int init_shadow_page_state(struct shadow_page_state * state); +#ifdef __V3VEE__ -addr_t create_new_shadow_pt32(struct guest_info * info); -addr_t setup_shadow_pt32(struct guest_info * info, addr_t virt_cr3); -addr_t setup_shadow_pte32(struct guest_info * info, addr_t pt_host_addr); +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); -int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code); - -int handle_shadow_pde32_fault(struct guest_info * info, - addr_t fault_addr, - pf_error_t error_code, - pde32_t * shadow_pde, - pde32_t * guest_pde); - - -int handle_shadow_pte32_fault(struct guest_info* info, - addr_t fault_addr, - pf_error_t error_code, - pte32_t * shadow_pte, - pte32_t * guest_pte); - - - int handle_shadow_invlpg(struct guest_info * info); +#endif // ! __V3VEE__ + #endif diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 2f11c0c..7526002 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -12,7 +12,7 @@ #include -extern struct vmm_os_hooks * os_hooks; + extern uint_t cpuid_ecx(uint_t op); extern uint_t cpuid_edx(uint_t op); @@ -37,7 +37,7 @@ extern void EnableInts(); static vmcb_t * Allocate_VMCB() { - vmcb_t * vmcb_page = (vmcb_t*)os_hooks->allocate_pages(1); + vmcb_t * vmcb_page = (vmcb_t *)V3_AllocPages(1); memset(vmcb_page, 0, 4096); @@ -135,10 +135,10 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { guest_state->dr7 = 0x0000000000000400LL; if (vm_info->io_map.num_ports > 0) { - vmm_io_hook_t * iter; + struct vmm_io_hook * iter; addr_t io_port_bitmap; - io_port_bitmap = (addr_t)os_hooks->allocate_pages(3); + io_port_bitmap = (addr_t)V3_AllocPages(3); memset((uchar_t*)io_port_bitmap, 0, PAGE_SIZE * 3); ctrl_area->IOPM_BASE_PA = io_port_bitmap; @@ -467,7 +467,7 @@ void Init_SVM(struct vmm_ctrl_ops * vmm_ops) { // Setup the host state save area - host_state = os_hooks->allocate_pages(4); + host_state = V3_AllocPages(4); msr.e_reg.high = 0; msr.e_reg.low = (uint_t)host_state; @@ -588,10 +588,10 @@ void Init_SVM(struct vmm_ctrl_ops * vmm_ops) { } if (vm_info.io_map.num_ports > 0) { - vmm_io_hook_t * iter; + struct vmm_io_hook * iter; addr_t io_port_bitmap; - io_port_bitmap = (addr_t)os_hooks->allocate_pages(3); + io_port_bitmap = (addr_t)V3_AllocPages(3); memset((uchar_t*)io_port_bitmap, 0, PAGE_SIZE * 3); ctrl_area->IOPM_BASE_PA = io_port_bitmap; @@ -749,7 +749,7 @@ void Init_VMCB_pe(vmcb_t *vmcb, struct guest_info vm_info) { ctrl_area->instrs.IOIO_PROT = 1; - ctrl_area->IOPM_BASE_PA = (uint_t)os_hooks->allocate_pages(3); + ctrl_area->IOPM_BASE_PA = (uint_t)V3_AllocPages(3); { reg_ex_t tmp_reg; diff --git a/palacios/src/palacios/svm_io.c b/palacios/src/palacios/svm_io.c index efc5294..40c1b76 100644 --- a/palacios/src/palacios/svm_io.c +++ b/palacios/src/palacios/svm_io.c @@ -16,7 +16,7 @@ int handle_svm_io_in(struct guest_info * info) { // vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data)); struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1); - vmm_io_hook_t * hook = v3_get_io_hook(&(info->io_map), io_info->port); + struct vmm_io_hook * hook = v3_get_io_hook(&(info->io_map), io_info->port); uint_t read_size = 0; if (hook == NULL) { @@ -60,7 +60,7 @@ int handle_svm_io_ins(struct guest_info * info) { struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1); - vmm_io_hook_t * hook = v3_get_io_hook(&(info->io_map), io_info->port); + struct vmm_io_hook * hook = v3_get_io_hook(&(info->io_map), io_info->port); uint_t read_size = 0; addr_t dst_addr = 0; @@ -195,7 +195,7 @@ int handle_svm_io_out(struct guest_info * info) { // vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data)); struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1); - vmm_io_hook_t * hook = v3_get_io_hook(&(info->io_map), io_info->port); + struct vmm_io_hook * hook = v3_get_io_hook(&(info->io_map), io_info->port); uint_t write_size = 0; if (hook == NULL) { @@ -238,7 +238,7 @@ int handle_svm_io_outs(struct guest_info * info) { struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1); - vmm_io_hook_t * hook = v3_get_io_hook(&(info->io_map), io_info->port); + struct vmm_io_hook * hook = v3_get_io_hook(&(info->io_map), io_info->port); uint_t write_size = 0; addr_t dst_addr = 0; diff --git a/palacios/src/palacios/vmm_io.c b/palacios/src/palacios/vmm_io.c index 91fef14..8266837 100644 --- a/palacios/src/palacios/vmm_io.c +++ b/palacios/src/palacios/vmm_io.c @@ -11,7 +11,7 @@ #endif -void init_vmm_io_map(vmm_io_map_t * io_map) { +void init_vmm_io_map(struct vmm_io_map * io_map) { io_map->num_ports = 0; io_map->head = NULL; } @@ -20,7 +20,7 @@ void init_vmm_io_map(vmm_io_map_t * io_map) { -static int add_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) { +static int add_io_hook(struct vmm_io_map * io_map, struct vmm_io_hook * io_hook) { if (!(io_map->head)) { io_map->head = io_hook; @@ -35,7 +35,7 @@ static int add_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) { return 0; } else { - vmm_io_hook_t * tmp_hook = io_map->head; + struct vmm_io_hook * tmp_hook = io_map->head; while ((tmp_hook->next) && (tmp_hook->next->port <= io_hook->port)) { @@ -64,7 +64,7 @@ static int add_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) { return -1; } -static int remove_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) { +static int remove_io_hook(struct vmm_io_map * io_map, struct vmm_io_hook * io_hook) { if (io_map->head == io_hook) { io_map->head = io_hook->next; } else if (io_hook->prev) { @@ -130,11 +130,11 @@ static int default_read(ushort_t port, void * dst, uint_t length, void * priv_da return 0; } -int v3_hook_io_port(vmm_io_map_t * io_map, uint_t port, +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) { - vmm_io_hook_t * io_hook = (vmm_io_hook_t *)V3_Malloc(sizeof(vmm_io_hook_t)); + struct vmm_io_hook * io_hook = (struct vmm_io_hook *)V3_Malloc(sizeof(struct vmm_io_hook)); io_hook->port = port; @@ -163,8 +163,8 @@ int v3_hook_io_port(vmm_io_map_t * io_map, uint_t port, return 0; } -int v3_unhook_io_port(vmm_io_map_t * io_map, uint_t port) { - vmm_io_hook_t * hook = v3_get_io_hook(io_map, port); +int v3_unhook_io_port(struct vmm_io_map * io_map, uint_t port) { + struct vmm_io_hook * hook = v3_get_io_hook(io_map, port); if (hook == NULL) { return -1; @@ -175,8 +175,8 @@ int v3_unhook_io_port(vmm_io_map_t * io_map, uint_t port) { } -vmm_io_hook_t * v3_get_io_hook(vmm_io_map_t * io_map, uint_t port) { - vmm_io_hook_t * tmp_hook; +struct vmm_io_hook * v3_get_io_hook(struct vmm_io_map * io_map, uint_t port) { + struct vmm_io_hook * tmp_hook; FOREACH_IO_HOOK(*io_map, tmp_hook) { if (tmp_hook->port == port) { return tmp_hook; @@ -187,8 +187,8 @@ vmm_io_hook_t * v3_get_io_hook(vmm_io_map_t * io_map, uint_t port) { -void PrintDebugIOMap(vmm_io_map_t * io_map) { - vmm_io_hook_t * iter = io_map->head; +void PrintDebugIOMap(struct vmm_io_map * io_map) { + struct vmm_io_hook * iter = io_map->head; PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports); diff --git a/palacios/src/palacios/vmm_shadow_paging.c b/palacios/src/palacios/vmm_shadow_paging.c index 2c2d03d..3c79431 100644 --- a/palacios/src/palacios/vmm_shadow_paging.c +++ b/palacios/src/palacios/vmm_shadow_paging.c @@ -11,6 +11,18 @@ #endif + + + + +static int handle_shadow_pte32_fault(struct guest_info* info, + addr_t fault_addr, + pf_error_t error_code, + pte32_t * shadow_pte, + pte32_t * guest_pte); + +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) { state->guest_mode = PDE32; state->shadow_mode = PDE32; @@ -47,7 +59,7 @@ int handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_erro addr_t create_new_shadow_pt32(struct guest_info * info) { void * host_pde = 0; - V3_AllocPages(host_pde, 1); + host_pde = V3_AllocPages(1); memset(host_pde, 0, PAGE_SIZE); return (addr_t)host_pde; @@ -89,7 +101,7 @@ static int handle_pd32_nonaligned_4MB_page(struct guest_info * info, pte32_t * p return 0; } -int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) { +static int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) { pde32_t * guest_pd = NULL; pde32_t * shadow_pd = (pde32_t *)CR3_TO_PDE32(info->shdw_pg_state.shadow_cr3); addr_t guest_cr3 = CR3_TO_PDE32(info->shdw_pg_state.guest_cr3); @@ -172,7 +184,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er if (guest_pde->large_page == 0) { pte32_t * shadow_pt = NULL; - V3_AllocPages(shadow_pt, 1); + shadow_pt = V3_AllocPages(1); memset(shadow_pt, 0, PAGE_SIZE); shadow_pde->pt_base_addr = PD32_BASE_ADDR(shadow_pt); @@ -238,7 +250,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er shadow_pde->large_page = 0; - V3_AllocPages(shadow_pt, 1); + shadow_pt = V3_AllocPages(1); memset(shadow_pt, 0, PAGE_SIZE); if (handle_pd32_nonaligned_4MB_page(info, shadow_pt, guest_start_addr, large_shadow_pde) == -1) { @@ -334,7 +346,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er /* * We assume the the guest pte pointer has already been translated to a host virtual address */ -int handle_shadow_pte32_fault(struct guest_info * info, +static int handle_shadow_pte32_fault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code, pte32_t * shadow_pt, @@ -572,83 +584,3 @@ int handle_shadow_invlpg(struct guest_info * info) { } - -/* Deprecated */ -/* -addr_t setup_shadow_pt32(struct guest_info * info, addr_t virt_cr3) { - addr_t cr3_guest_addr = CR3_TO_PDE32(virt_cr3); - pde32_t * guest_pde; - pde32_t * host_pde = NULL; - int i; - - // Setup up guest_pde to point to the PageDir in host addr - if (guest_pa_to_host_va(info, cr3_guest_addr, (addr_t*)&guest_pde) == -1) { - return 0; - } - - V3_AllocPages(host_pde, 1); - memset(host_pde, 0, PAGE_SIZE); - - for (i = 0; i < MAX_PDE32_ENTRIES; i++) { - if (guest_pde[i].present == 1) { - addr_t pt_host_addr; - addr_t host_pte; - - if (guest_pa_to_host_va(info, PDE32_T_ADDR(guest_pde[i]), &pt_host_addr) == -1) { - return 0; - } - - if ((host_pte = setup_shadow_pte32(info, pt_host_addr)) == 0) { - return 0; - } - - host_pde[i].present = 1; - host_pde[i].pt_base_addr = PD32_BASE_ADDR(host_pte); - - // - // Set Page DIR flags - // - } - } - - PrintDebugPageTables(host_pde); - - return (addr_t)host_pde; -} - - - -addr_t setup_shadow_pte32(struct guest_info * info, addr_t pt_host_addr) { - pte32_t * guest_pte = (pte32_t *)pt_host_addr; - pte32_t * host_pte = NULL; - int i; - - V3_AllocPages(host_pte, 1); - memset(host_pte, 0, PAGE_SIZE); - - for (i = 0; i < MAX_PTE32_ENTRIES; i++) { - if (guest_pte[i].present == 1) { - addr_t guest_pa = PTE32_T_ADDR(guest_pte[i]); - shadow_mem_type_t page_type; - addr_t host_pa = 0; - - page_type = get_shadow_addr_type(info, guest_pa); - - if (page_type == HOST_REGION_PHYSICAL_MEMORY) { - host_pa = get_shadow_addr(info, guest_pa); - } else { - - // - // Setup various memory types - // - } - - host_pte[i].page_base_addr = PT32_BASE_ADDR(host_pa); - host_pte[i].present = 1; - } - } - - return (addr_t)host_pte; -} - -*/