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 * create_direct_passthrough_pts_32(struct guest_info * info) {
29 return create_pde32();
33 static inline int handle_passthrough_pagefault_32(struct guest_info * info,
35 pf_error_t error_code) {
36 // Check to see if pde and pte exist (create them if not)
37 pde32_t * pde = CR3_TO_PDE32_VA(info->ctrl_regs.cr3);
38 int pde_index = PDE32_INDEX(fault_addr);
39 int pte_index = PTE32_INDEX(fault_addr);
41 if (pde[pde_index].present != 1) {
43 PrintError("Creating new page table for PTE index: %d\n", pde_index);
45 pte32_t * pte = create_pte32();
48 if(guest_pa_to_host_pa(info, fault_addr, &host_addr) == -1) return -1;
50 struct v3_shadow_region * region = v3_get_shadow_region(info, PAGE_BASE_ADDR(host_addr));
52 pte[pte_index].present = 1;
53 pte[pte_index].writable = 1;
54 pte[pte_index].user_page = 1;
55 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
57 pde[pde_index].present = 1;
58 pde[pde_index].writable = 1;
59 pde[pde_index].user_page = 1;
60 pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
62 if (region->host_type == SHDW_REGION_WRITE_HOOK) {
63 pte[pte_index].writable = 0;
66 PrintError("Fault Addr: 0x%p\nHost Addr: 0x%p\n", (void*)fault_addr, (void*)host_addr);
69 pte32_t * pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
71 if (pte[pte_index].present != 1) {
74 if (guest_pa_to_host_pa(info, fault_addr, &host_addr) == -1) return -1;
76 struct v3_shadow_region * region = v3_get_shadow_region(info, PAGE_BASE_ADDR(host_addr));
78 pte[pte_index].present = 1;
79 pte[pte_index].writable = 1;
80 pte[pte_index].user_page = 1;
81 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
83 if (region->host_type == SHDW_REGION_WRITE_HOOK) {
84 pte[pte_index].writable = 0;