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 new copyright and license
[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
27
28 vm_cpu_mode_t get_cpu_mode(struct guest_info * info) {
29   struct cr0_32 * cr0;
30   struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
31   struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
32   struct v3_segment * cs = &(info->segments.cs);
33
34   if (info->shdw_pg_mode == SHADOW_PAGING) {
35     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
36   } else if (info->shdw_pg_mode == NESTED_PAGING) {
37     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
38   } else {
39     PrintError("Invalid Paging Mode...\n");
40     V3_ASSERT(0);
41     return -1;
42   }
43
44   if (cr0->pe == 0) {
45     return REAL;
46   } else if ((cr4->pae == 0) && (efer->lma == 0)) {
47     return PROTECTED;
48   } else if (efer->lma == 0) {
49     return PROTECTED_PAE;
50   } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
51     return LONG;
52   } else {
53     return LONG_32_COMPAT;
54   }
55 }
56
57 vm_mem_mode_t get_mem_mode(struct guest_info * info) {
58   struct cr0_32 * cr0;
59
60   if (info->shdw_pg_mode == SHADOW_PAGING) {
61     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
62   } else if (info->shdw_pg_mode == NESTED_PAGING) {
63     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
64   } else {
65     PrintError("Invalid Paging Mode...\n");
66     V3_ASSERT(0);
67     return -1;
68   }
69
70
71
72   if (cr0->pg == 0) {
73     return PHYSICAL_MEM;
74   } else {
75     return VIRTUAL_MEM;
76   }
77 }
78
79
80 void PrintV3Segments(struct guest_info * info) {
81   struct v3_segments * segs = &(info->segments);
82   int i = 0;
83   struct v3_segment * seg_ptr;
84
85   seg_ptr=(struct v3_segment *)segs;
86   
87   char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
88   PrintDebug("Segments\n");
89
90   for (i = 0; seg_names[i] != NULL; i++) {
91
92     PrintDebug("\t%s: Sel=%x, base=%x, limit=%x\n", seg_names[i], seg_ptr[i].selector, seg_ptr[i].base, seg_ptr[i].limit);
93
94   }
95
96 }
97
98
99 void PrintV3CtrlRegs(struct guest_info * info) {
100   struct v3_ctrl_regs * regs = &(info->ctrl_regs);
101   int i = 0;
102   v3_reg_t * reg_ptr;
103   char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
104
105   reg_ptr= (v3_reg_t *)regs;
106
107   PrintDebug("32 bit Ctrl Regs:\n");
108
109   for (i = 0; reg_names[i] != NULL; i++) {
110     PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);  
111   }
112 }
113
114
115 void PrintV3GPRs(struct guest_info * info) {
116   struct v3_gprs * regs = &(info->vm_regs);
117   int i = 0;
118   v3_reg_t * reg_ptr;
119   char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
120
121   reg_ptr= (v3_reg_t *)regs;
122
123   PrintDebug("32 bit GPRs:\n");
124
125   for (i = 0; reg_names[i] != NULL; i++) {
126     PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);  
127   }
128 }