Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


0c3381a3a85c8e92e504757a01c85b46ac0099f6
[palacios.git] / palacios / src / palacios / vmm_direct_paging_32pae.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Steven Jaconette <stevenjaconette2007@u.northwestern.edu> 
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Steven Jaconette <stevenjaconette2007@u.northwestern.edu>
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #ifndef __VMM_DIRECT_PAGING_32PAE_H__
22 #define __VMM_DIRECT_PAGING_32PAE_H__
23
24 #include <palacios/vmm_mem.h>
25 #include <palacios/vmm_paging.h>
26 #include <palacios/vmm.h>
27 #include <palacios/vm_guest_mem.h>
28 #include <palacios/vm_guest.h>
29
30
31 static inline int handle_passthrough_pagefault_32pae(struct guest_info * info, 
32                                                      addr_t fault_addr, 
33                                                      pf_error_t error_code) {
34     pdpe32pae_t * pdpe = NULL;
35     pde32pae_t * pde = NULL;
36     pte32pae_t * pte = NULL;
37     addr_t host_addr = 0;
38
39     int pdpe_index = PDPE32PAE_INDEX(fault_addr);
40     int pde_index = PDE32PAE_INDEX(fault_addr);
41     int pte_index = PTE32PAE_INDEX(fault_addr);
42
43     struct v3_shadow_region * region =  v3_get_shadow_region(info->vm_info, info->cpu_id, fault_addr);
44   
45     if (region == NULL) {
46         PrintError("Invalid region in passthrough page fault 32PAE, addr=%p\n", 
47                    (void *)fault_addr);
48         return -1;
49     }
50
51     host_addr = v3_get_shadow_addr(region, info->cpu_id, fault_addr);
52
53     // Lookup the correct PDPE address based on the PAGING MODE
54     if (info->shdw_pg_mode == SHADOW_PAGING) {
55         pdpe = CR3_TO_PDPE32PAE_VA(info->ctrl_regs.cr3);
56     } else {
57         pdpe = CR3_TO_PDPE32PAE_VA(info->direct_map_pt);
58     }
59
60     // Fix up the PDPE entry
61     if (pdpe[pdpe_index].present == 0) {
62         pde = (pde32pae_t *)create_generic_pt_page();
63    
64         pdpe[pdpe_index].present = 1;
65         // Set default PDPE Flags...
66         pdpe[pdpe_index].pd_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pde));    
67     } else {
68         pde = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pdpe[pdpe_index].pd_base_addr));
69     }
70
71
72     // Fix up the PDE entry
73     if (pde[pde_index].present == 0) {
74         pte = (pte32pae_t *)create_generic_pt_page();
75
76         pde[pde_index].present = 1;
77         pde[pde_index].writable = 1;
78         pde[pde_index].user_page = 1;
79
80         pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
81     } else {
82         pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
83     }
84
85
86     // Fix up the PTE entry
87     if (pte[pte_index].present == 0) {
88         pte[pte_index].user_page = 1;
89
90         if ((region->flags.alloced == 1) && 
91             (region->flags.read == 1)) {
92
93             pte[pte_index].present = 1;
94
95             if (region->flags.write == 1) {
96                 pte[pte_index].writable = 1;
97             } else {
98                 pte[pte_index].writable = 0;
99             }
100
101             pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
102         }
103     }
104    
105     if (region->flags.hook == 1) {
106         if ((error_code.write == 1) || (region->flags.read == 0)) {
107             return v3_handle_mem_hook(info, fault_addr, fault_addr, region, error_code);
108         }
109     }
110
111     return 0;
112 }
113
114
115 static inline int invalidate_addr_32pae(struct guest_info * info, addr_t inv_addr) {
116     pdpe32pae_t * pdpe = NULL;
117     pde32pae_t * pde = NULL;
118     pte32pae_t * pte = NULL;
119
120
121     // TODO:
122     // Call INVLPGA
123
124     // clear the page table entry
125     int pdpe_index = PDPE32PAE_INDEX(inv_addr);
126     int pde_index = PDE32PAE_INDEX(inv_addr);
127     int pte_index = PTE32PAE_INDEX(inv_addr);
128
129     
130     // Lookup the correct PDE address based on the PAGING MODE
131     if (info->shdw_pg_mode == SHADOW_PAGING) {
132         pdpe = CR3_TO_PDPE32PAE_VA(info->ctrl_regs.cr3);
133     } else {
134         pdpe = CR3_TO_PDPE32PAE_VA(info->direct_map_pt);
135     }    
136
137
138     if (pdpe[pdpe_index].present == 0) {
139         return 0;
140     }
141
142     pde = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pdpe[pdpe_index].pd_base_addr));
143
144     if (pde[pde_index].present == 0) {
145         return 0;
146     } else if (pde[pde_index].large_page) {
147         pde[pde_index].present = 0;
148         return 0;
149     }
150
151     pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
152
153     pte[pte_index].present = 0;
154
155     return 0;
156 }
157
158
159
160 #endif