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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_intr.h>
22 #include <palacios/vmm_config.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_instrument.h>
25 #include <palacios/vmm_ctrl_regs.h>
26 #include <palacios/vmm_lowlevel.h>
29 #include <palacios/svm.h>
32 #include <palacios/vmx.h>
36 v3_cpu_arch_t v3_cpu_type;
37 struct v3_os_hooks * os_hooks = NULL;
41 static struct guest_info * allocate_guest() {
42 void * info = V3_Malloc(sizeof(struct guest_info));
43 memset(info, 0, sizeof(struct guest_info));
49 void Init_V3(struct v3_os_hooks * hooks, struct v3_ctrl_ops * vmm_ops) {
51 // Set global variables.
53 v3_cpu_type = V3_INVALID_CPU;
55 // Register all the possible device types
60 v3_init_instrumentation();
63 vmm_ops->allocate_guest = &allocate_guest;
66 if (v3_is_svm_capable()) {
67 PrintDebug("Machine is SVM Capable\n");
73 if (v3_is_vmx_capable()) {
74 PrintDebug("Machine is VMX Capable\n");
80 PrintError("CPU has no virtualization Extensions\n");
88 v3_cpu_mode_t v3_get_host_cpu_mode() {
98 cr4 = (struct cr4_32 *)&(cr4_val);
101 return PROTECTED_PAE;
109 v3_cpu_mode_t v3_get_host_cpu_mode() {
116 #define V3_Yield(addr) \
118 extern struct v3_os_hooks * os_hooks; \
119 if ((os_hooks) && (os_hooks)->yield_cpu) { \
120 (os_hooks)->yield_cpu(); \
125 void v3_yield_cond(struct guest_info * info) {
129 if (cur_cycle > (info->yield_start_cycle + info->yield_cycle_period)) {
132 PrintDebug("Conditional Yield (cur_cyle=%p, start_cycle=%p, period=%p)\n",
133 (void *)cur_cycle, (void *)info->yield_start_cycle, (void *)info->yield_cycle_period);
136 rdtscll(info->yield_start_cycle);
140 void v3_yield(struct guest_info * info) {
142 rdtscll(info->yield_start_cycle);