1 #ifndef __VMM_DIRECT_PAGING_32_H__
2 #define __VMM_DIRECT_PAGING_32_H__
4 #include <palacios/vmm_mem.h>
5 #include <palacios/vmm_paging.h>
6 #include <palacios/vmm.h>
7 #include <palacios/vm_guest_mem.h>
8 #include <palacios/vm_guest.h>
10 static pde32_t * create_pde32() {
12 pde = V3_VAddr(V3_AllocPages(1));
13 memset(pde, 0, PAGE_SIZE);
15 return (pde32_t *) pde;
19 static pte32_t * create_pte32() {
21 pte = V3_VAddr(V3_AllocPages(1));
22 memset(pte, 0, PAGE_SIZE);
24 return (pte32_t *) pte;
28 static inline pde32_t * v3_create_direct_passthrough_pts_32(struct guest_info * info) {
29 return create_pde32();
33 static inline int v3_handle_shadow_pagefault_physical_mode_32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
34 // Check to see if pde and pte exist (create them if not)
35 pde32_t * pde = CR3_TO_PDE32_VA(info->ctrl_regs.cr3);
36 int pde_index = PDE32_INDEX(fault_addr);
37 int pte_index = PTE32_INDEX(fault_addr);
38 if(pde[pde_index].present != 1) {
39 PrintError("Creating new page table for PTE index: %d\n", pde_index);
40 pte32_t * pte = create_pte32();
42 if(guest_pa_to_host_pa(info, fault_addr, &host_addr) == -1) return -1;
43 struct v3_shadow_region * region = v3_get_shadow_region(info, PAGE_BASE_ADDR(host_addr));
44 pte[pte_index].present = 1;
45 pte[pte_index].writable = 1;
46 pte[pte_index].user_page = 1;
47 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
49 pde[pde_index].present = 1;
50 pde[pde_index].writable = 1;
51 pde[pde_index].user_page = 1;
52 pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
53 if(region->host_type == SHDW_REGION_WRITE_HOOK) {
54 pte[pte_index].writable = 0;
56 PrintError("Fault Addr: 0x%p\nHost Addr: 0x%p\n", (void*)fault_addr, (void*)host_addr);
59 pte32_t * pte = (void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr);
60 if(pte[pte_index].present != 1) {
62 if(guest_pa_to_host_pa(info, fault_addr, &host_addr) == -1) return -1;
63 struct v3_shadow_region * region = v3_get_shadow_region(info, PAGE_BASE_ADDR(host_addr));
64 pte[pte_index].present = 1;
65 pte[pte_index].writable = 1;
66 pte[pte_index].user_page = 1;
67 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
68 if(region->host_type == SHDW_REGION_WRITE_HOOK) {
69 pte[pte_index].writable = 0;