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.


added MSR hook framework
[palacios.git] / palacios / src / palacios / vm_guest.c
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, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21
22
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_ctrl_regs.h>
25 #include <palacios/vmm.h>
26 #include <palacios/vmcb.h>
27
28
29 v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info) {
30   struct cr0_32 * cr0;
31   struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
32   struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
33   struct v3_segment * cs = &(info->segments.cs);
34
35   if (info->shdw_pg_mode == SHADOW_PAGING) {
36     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
37   } else if (info->shdw_pg_mode == NESTED_PAGING) {
38     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
39   } else {
40     PrintError("Invalid Paging Mode...\n");
41     V3_ASSERT(0);
42     return -1;
43   }
44
45   if (cr0->pe == 0) {
46     return REAL;
47   } else if ((cr4->pae == 0) && (efer->lma == 0)) {
48     return PROTECTED;
49   } else if (efer->lma == 0) {
50     return PROTECTED_PAE;
51   } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
52     return LONG;
53   } else {
54     return -1;
55     // What about LONG_16_COMPAT???
56     return LONG_32_COMPAT;
57   }
58 }
59
60 v3_vm_mem_mode_t v3_get_mem_mode(struct guest_info * info) {
61   struct cr0_32 * cr0;
62
63   if (info->shdw_pg_mode == SHADOW_PAGING) {
64     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
65   } else if (info->shdw_pg_mode == NESTED_PAGING) {
66     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
67   } else {
68     PrintError("Invalid Paging Mode...\n");
69     V3_ASSERT(0);
70     return -1;
71   }
72
73
74
75   if (cr0->pg == 0) {
76     return PHYSICAL_MEM;
77   } else {
78     return VIRTUAL_MEM;
79   }
80 }
81
82
83 void v3_print_segments(struct guest_info * info) {
84   struct v3_segments * segs = &(info->segments);
85   int i = 0;
86   struct v3_segment * seg_ptr;
87
88   seg_ptr=(struct v3_segment *)segs;
89   
90   char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
91   PrintDebug("Segments\n");
92
93   for (i = 0; seg_names[i] != NULL; i++) {
94
95     PrintDebug("\t%s: Sel=%x, base=%p, limit=%x\n", seg_names[i], seg_ptr[i].selector, 
96                (void *)(addr_t)seg_ptr[i].base, seg_ptr[i].limit);
97
98   }
99
100 }
101
102
103 void v3_print_ctrl_regs(struct guest_info * info) {
104   struct v3_ctrl_regs * regs = &(info->ctrl_regs);
105   int i = 0;
106   v3_reg_t * reg_ptr;
107   char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
108   vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA(info->vmm_data);
109
110   reg_ptr= (v3_reg_t *)regs;
111
112   PrintDebug("32 bit Ctrl Regs:\n");
113
114   for (i = 0; reg_names[i] != NULL; i++) {
115     PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]);  
116   }
117
118   PrintDebug("\tEFER=0x%p\n", (void*)(addr_t)(guest_state->efer));
119
120 }
121
122
123 void v3_print_GPRs(struct guest_info * info) {
124   struct v3_gprs * regs = &(info->vm_regs);
125   int i = 0;
126   v3_reg_t * reg_ptr;
127   char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
128
129   reg_ptr= (v3_reg_t *)regs;
130
131   PrintDebug("32 bit GPRs:\n");
132
133   for (i = 0; reg_names[i] != NULL; i++) {
134     PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]);  
135   }
136 }