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.


vmx updates
[palacios.git] / palacios / src / palacios / vmx_hw_info.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) 2011, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2011, 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 #include <palacios/vmm.h>
21 #include <palacios/vmm_lowlevel.h>
22 #include <palacios/vmx_hw_info.h>
23 #include <palacios/vmm_msr.h>
24
25 // Intel VMX Feature MSRs
26
27
28
29 static int get_ex_ctrl_caps(struct vmx_hw_info * hw_info, struct vmx_ctrl_field * field, 
30                   uint32_t old_msr, uint32_t true_msr) {
31     uint32_t old_0;  /* Bit is 1 => MB1 */
32     uint32_t old_1;  /* Bit is 0 => MBZ */
33     uint32_t true_0; /* Bit is 1 => MB1 */
34     uint32_t true_1; /* Bit is 0 => MBZ */
35
36     v3_get_msr(old_msr, &old_1, &old_0);
37     field->def_val = old_0;
38
39     if (hw_info->basic_info.def1_maybe_0) {
40         v3_get_msr(true_msr, &true_1, &true_0);
41     } else {
42         true_0 = old_0;
43         true_1 = old_1;
44     }
45     
46     field->req_val = true_0;
47     field->req_mask = ~(true_1 ^ true_0);
48
49     return 0;
50 }
51
52
53 static int get_ctrl_caps(struct vmx_ctrl_field * field, uint32_t msr) {
54     uint32_t mbz = 0; /* Bit is 0 => MBZ */
55     uint32_t mb1 = 0; /* Bit is 1 => MB1 */
56     
57     v3_get_msr(msr, &mbz, &mb1);
58     
59     field->def_val = mb1;
60     field->req_val = mb1;
61     field->req_mask = ~(mbz ^ mb1);
62
63     return 0;
64 }
65
66
67
68 static int get_cr_fields(struct vmx_cr_field * field, uint32_t fixed_1_msr, uint32_t fixed_0_msr) {
69     struct v3_msr mbz; /* Bit is 0 => MBZ */
70     struct v3_msr mb1; /* Bit is 0 => MBZ */
71
72     v3_get_msr(fixed_1_msr, &(mbz.hi), &(mbz.lo));
73     v3_get_msr(fixed_0_msr, &(mb1.hi), &(mb1.lo));
74      
75     field->def_val = mb1.value;
76     field->req_val = mb1.value;
77     field->req_mask = ~(mbz.value ^ mb1.value);
78
79     return 0;
80 }
81
82
83
84
85
86 int v3_init_vmx_hw(struct vmx_hw_info * hw_info) {
87     //  extern v3_cpu_arch_t v3_cpu_types[];
88
89     memset(hw_info, 0, sizeof(struct vmx_hw_info));
90
91     v3_get_msr(VMX_BASIC_MSR, &(hw_info->basic_info.hi), &(hw_info->basic_info.lo));
92     v3_get_msr(VMX_MISC_MSR, &(hw_info->misc_info.hi), &(hw_info->misc_info.lo));
93     v3_get_msr(VMX_EPT_VPID_CAP_MSR, &(hw_info->ept_info.hi), &(hw_info->ept_info.lo));
94
95     PrintError("BASIC_MSR: Lo: %x, Hi: %x\n", hw_info->basic_info.lo, hw_info->basic_info.hi);
96
97     get_ex_ctrl_caps(hw_info, &(hw_info->pin_ctrls), VMX_PINBASED_CTLS_MSR, VMX_TRUE_PINBASED_CTLS_MSR);
98     get_ex_ctrl_caps(hw_info, &(hw_info->proc_ctrls), VMX_PROCBASED_CTLS_MSR, VMX_TRUE_PROCBASED_CTLS_MSR);
99     get_ex_ctrl_caps(hw_info, &(hw_info->exit_ctrls), VMX_EXIT_CTLS_MSR, VMX_TRUE_EXIT_CTLS_MSR);
100     get_ex_ctrl_caps(hw_info, &(hw_info->entry_ctrls), VMX_ENTRY_CTLS_MSR, VMX_TRUE_ENTRY_CTLS_MSR);
101
102     /* Get secondary PROCBASED controls if secondary controls are available (optional or required) */
103     /* Intel Manual 3B. Sect. G.3.3 */
104     if ( ((hw_info->proc_ctrls.req_mask & 0x80000000) == 0) || 
105          ((hw_info->proc_ctrls.req_val & 0x80000000) == 1) ) {
106         get_ctrl_caps(&(hw_info->sec_proc_ctrls), VMX_PROCBASED_CTLS2_MSR);
107     }
108     
109     get_cr_fields(&(hw_info->cr0), VMX_CR0_FIXED1_MSR, VMX_CR0_FIXED0_MSR);
110     get_cr_fields(&(hw_info->cr4), VMX_CR4_FIXED1_MSR, VMX_CR4_FIXED0_MSR);
111
112     return 0;
113 }