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 copyright tags
[palacios.git] / palacios / src / palacios / vm_guest.c
1 /* Northwestern University */
2 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
3
4 #include <palacios/vm_guest.h>
5 #include <palacios/vmm_ctrl_regs.h>
6 #include <palacios/vmm.h>
7
8
9 vm_cpu_mode_t get_cpu_mode(struct guest_info * info) {
10   struct cr0_32 * cr0;
11   struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
12   struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
13   struct v3_segment * cs = &(info->segments.cs);
14
15   if (info->shdw_pg_mode == SHADOW_PAGING) {
16     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
17   } else if (info->shdw_pg_mode == NESTED_PAGING) {
18     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
19   } else {
20     PrintError("Invalid Paging Mode...\n");
21     V3_ASSERT(0);
22     return -1;
23   }
24
25   if (cr0->pe == 0) {
26     return REAL;
27   } else if ((cr4->pae == 0) && (efer->lma == 0)) {
28     return PROTECTED;
29   } else if (efer->lma == 0) {
30     return PROTECTED_PAE;
31   } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
32     return LONG;
33   } else {
34     return LONG_32_COMPAT;
35   }
36 }
37
38 vm_mem_mode_t get_mem_mode(struct guest_info * info) {
39   struct cr0_32 * cr0;
40
41   if (info->shdw_pg_mode == SHADOW_PAGING) {
42     cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
43   } else if (info->shdw_pg_mode == NESTED_PAGING) {
44     cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
45   } else {
46     PrintError("Invalid Paging Mode...\n");
47     V3_ASSERT(0);
48     return -1;
49   }
50
51
52
53   if (cr0->pg == 0) {
54     return PHYSICAL_MEM;
55   } else {
56     return VIRTUAL_MEM;
57   }
58 }
59
60
61 void PrintV3Segments(struct guest_info * info) {
62   struct v3_segments * segs = &(info->segments);
63   int i = 0;
64   struct v3_segment * seg_ptr;
65
66   seg_ptr=(struct v3_segment *)segs;
67   
68   char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
69   PrintDebug("Segments\n");
70
71   for (i = 0; seg_names[i] != NULL; i++) {
72
73     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);
74
75   }
76
77 }
78
79
80 void PrintV3CtrlRegs(struct guest_info * info) {
81   struct v3_ctrl_regs * regs = &(info->ctrl_regs);
82   int i = 0;
83   v3_reg_t * reg_ptr;
84   char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
85
86   reg_ptr= (v3_reg_t *)regs;
87
88   PrintDebug("32 bit Ctrl Regs:\n");
89
90   for (i = 0; reg_names[i] != NULL; i++) {
91     PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);  
92   }
93 }
94
95
96 void PrintV3GPRs(struct guest_info * info) {
97   struct v3_gprs * regs = &(info->vm_regs);
98   int i = 0;
99   v3_reg_t * reg_ptr;
100   char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
101
102   reg_ptr= (v3_reg_t *)regs;
103
104   PrintDebug("32 bit GPRs:\n");
105
106   for (i = 0; reg_names[i] != NULL; i++) {
107     PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);  
108   }
109 }