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 configuration fixes
[palacios.git] / palacios / src / palacios / vmm.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 #include <palacios/vmm.h>
21 #include <palacios/svm.h>
22 #include <palacios/vmx.h>
23 #include <palacios/vmm_intr.h>
24 #include <palacios/vmm_config.h>
25 #include <palacios/vm_guest.h>
26 #include <palacios/vmm_instrument.h>
27 #include <palacios/vmm_ctrl_regs.h>
28 #include <palacios/vmm_lowlevel.h>
29
30
31
32
33 v3_cpu_arch_t v3_cpu_type;
34 struct v3_os_hooks * os_hooks = NULL;
35
36
37
38 static struct guest_info * allocate_guest() {
39     void * info = V3_Malloc(sizeof(struct guest_info));
40     memset(info, 0, sizeof(struct guest_info));
41     return info;
42 }
43
44
45
46 void Init_V3(struct v3_os_hooks * hooks, struct v3_ctrl_ops * vmm_ops) {
47     
48     // Set global variables. 
49     os_hooks = hooks;
50     v3_cpu_type = V3_INVALID_CPU;
51
52     // Register all the possible device types
53     v3_init_devices();
54
55
56 #ifdef INSTRUMENT_VMM
57     v3_init_instrumentation();
58 #endif
59
60     vmm_ops->allocate_guest = &allocate_guest;
61
62 #ifdef CONFIG_SVM
63     if (v3_is_svm_capable()) {
64         PrintDebug("Machine is SVM Capable\n");
65         v3_init_SVM(vmm_ops);
66
67     } else 
68 #endif
69 #ifdef CONFIG_VMX
70     if (v3_is_vmx_capable()) {
71         PrintDebug("Machine is VMX Capable\n");
72         v3_init_vmx(vmm_ops);
73         
74     } else 
75 #endif
76     {
77        PrintDebug("CPU has no virtualization Extensions\n");
78     }
79 }
80
81
82
83 #ifdef __V3_32BIT__
84
85 v3_cpu_mode_t v3_get_host_cpu_mode() {
86     uint32_t cr4_val;
87     struct cr4_32 * cr4;
88
89     __asm__ (
90              "movl %%cr4, %0; "
91              : "=r"(cr4_val) 
92              );
93
94     
95     cr4 = (struct cr4_32 *)&(cr4_val);
96
97     if (cr4->pae == 1) {
98         return PROTECTED_PAE;
99     } else {
100         return PROTECTED;
101     }
102 }
103
104 #elif __V3_64BIT__
105
106 v3_cpu_mode_t v3_get_host_cpu_mode() {
107     return LONG;
108 }
109
110 #endif 
111
112
113 #define V3_Yield(addr)                                  \
114     do {                                                \
115         extern struct v3_os_hooks * os_hooks;           \
116         if ((os_hooks) && (os_hooks)->yield_cpu) {      \
117             (os_hooks)->yield_cpu();                    \
118         }                                               \
119     } while (0)                                         \
120
121
122 void v3_yield_cond(struct guest_info * info) {
123     uint64_t cur_cycle;
124     rdtscll(cur_cycle);
125
126     if (cur_cycle > (info->yield_start_cycle + info->yield_cycle_period)) {
127
128         /*
129           PrintDebug("Conditional Yield (cur_cyle=%p, start_cycle=%p, period=%p)\n", 
130           (void *)cur_cycle, (void *)info->yield_start_cycle, (void *)info->yield_cycle_period);
131         */
132         V3_Yield();
133         rdtscll(info->yield_start_cycle);
134     }
135 }
136
137 void v3_yield(struct guest_info * info) {
138     V3_Yield();
139     rdtscll(info->yield_start_cycle);
140 }