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.


more work on the memory system
[palacios.git] / palacios / src / geekos / vm_guest_mem.c
1 #include <geekos/vm_guest_mem.c>
2
3 #include <geekos/vmm_paging.h>
4
5 extern struct vmm_os_hooks * os_hooks;
6
7
8
9 int guest_va_to_guest_pa(guest_info_t * guest_info, addr_t guest_va, addr_t * guest_pa) {
10   if (guest_info->page_mode == SHADOW_PAGING) {
11     switch (guest_info->cpu_mode) {
12     case REAL:
13     case PROTECTED:
14     case LONG:
15     case PROTECTED_PAE:
16       // guest virtual address is the same as the physical
17       *guest_pa = guest_va;
18       return 0;
19     case PROTECTED_PG:
20       {
21         addr_t tmp_pa;
22         pde32_t * pde;
23         addr_t guest_pde = CR3_TO_PDE32(guest_info->shadow_page_state.guest_cr3);
24
25         if (guest_pa_to_host_va(guest_info, guest_pde, (addr_t *)&pde) == -1) {
26           return -1;
27         }
28
29         switch (pde32_lookup(pde, guest_va, &tmp_pa)) {
30         case NOT_PRESENT: 
31           *guest_page = 0;
32           return -1;
33         case LARGE_PAGE:
34           *guest_pa = tmp_pa;
35           return 0;
36         case PTE32:
37           {
38             pte32_t * pte;
39
40             if (guest_pa_to_host_va(guest_info, tmp_pa, (addr_t*)&pte) == -1) {
41               return -1;
42             }
43             
44             if (pte32_lookup(pte, guest_va, guest_pa) != 0) {
45               return -1;
46             }
47
48             return 0;       
49           }
50         default:
51           return -1;
52         }
53       }
54       case PROTECTED_PAE_PG:
55         {
56           // Fill in
57         }
58       case LONG_PG:
59         {
60           // Fill in
61         }
62     default:
63       return -1;
64     }
65   } else if (guest_info->page_mode == NESTED_PAGING) {
66
67     // Fill in
68
69   } else {
70     return -1;
71   }
72
73
74   return 0;
75 }
76
77
78
79
80
81
82
83 int guest_pa_to_host_va(guest_info_t * guest_info, addr_t guest_pa, addr_t * host_va) {
84   addr_t host_pa;
85
86   if (guest_pa_to_host_pa(guest_info, guest_pa, &host_pa) != 0) {
87     return -1;
88   }
89   
90   if (host_pa_to_host_va(host_pa, host_va) != 0) {
91     return -1;
92   }
93
94   return 0;
95 }
96
97
98 int guest_pa_to_host_pa(guest_info_t * guest_info, addr_t guest_pa, addr_t * host_pa) {
99   // we use the shadow map here...
100   if (lookup_shadow_map_addr(guest_info->shadow_map, guest_pa, host_pa) != HOST_REGION_PHYSICAL_MEMORY) {
101     return -1;
102   }
103                                   
104   return 0;
105 }
106
107
108
109
110 int host_va_to_host_pa(addr_t host_va, addr_t * host_pa) {
111   *host_pa = os_hooks->vaddr_to_paddr(host_va);
112   
113   if (*host_pa == 0) {
114     return -1;
115   }
116
117   return 0;
118 }
119
120
121 int host_pa_to_host_va(addr_t host_pa, addr_t * host_va) {
122   *host_va = os_hooks->paddr_to_vaddr(host_pa);
123
124   if (*host_va == 0) {
125     return -1;
126   }
127
128   return 0;
129 }