#include <palacios/vmm_sprintf.h>
+#ifndef CONFIG_DEBUG_SVM
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
+
+
uint32_t v3_last_exit;
// This is a global pointer to the host's VMCB
//
-
-
ctrl_area->svm_instrs.VMRUN = 1;
ctrl_area->svm_instrs.VMMCALL = 1;
ctrl_area->svm_instrs.VMLOAD = 1;
ctrl_area->instrs.CPUID = 1;
ctrl_area->instrs.HLT = 1;
+
+#ifdef CONFIG_TIME_VIRTUALIZE_TSC
+ ctrl_area->instrs.rdtsc = 1;
+ ctrl_area->svm_instrs.rdtscp = 1;
+#endif
+
// guest_state->cr0 = 0x00000001; // PE
/*
int v3_svm_enter(struct guest_info * info) {
vmcb_ctrl_t * guest_ctrl = GET_VMCB_CTRL_AREA((vmcb_t*)(info->vmm_data));
vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
- ullong_t tmp_tsc;
addr_t exit_code = 0, exit_info1 = 0, exit_info2 = 0;
// Conditionally yield the CPU if the timeslice has expired
}
#endif
+ v3_update_timers(info);
- rdtscll(tmp_tsc);
- v3_update_time(info, (tmp_tsc - info->time_state.cached_host_tsc));
- rdtscll(info->time_state.cached_host_tsc);
- // guest_ctrl->TSC_OFFSET = info->time_state.guest_tsc - info->time_state.cached_host_tsc;
+ guest_ctrl->TSC_OFFSET = v3_tsc_host_offset(&info->time_state);
//V3_Print("Calling v3_svm_launch\n");
-
-#if 0
- if (info->cpu_id==1) {
- V3_Print("Entering Core 1\n");
- v3_print_guest_state(info);
- }
-#endif
-
v3_svm_launch((vmcb_t *)V3_PAddr(info->vmm_data), &(info->vm_regs), (vmcb_t *)host_vmcbs[info->cpu_id]);
-
- //V3_Print("SVM Returned: Exit Code: %x, guest_rip=%lx\n", (uint32_t)(guest_ctrl->exit_code), (unsigned long)guest_state->rip);
+ v3_adjust_time(info);
- v3_last_exit = (uint32_t)(guest_ctrl->exit_code);
+ //V3_Print("SVM Returned: Exit Code: %x, guest_rip=%lx\n", (uint32_t)(guest_ctrl->exit_code), (unsigned long)guest_state->rip);
- //rdtscll(tmp_tsc);
- // v3_update_time(info, tmp_tsc - info->time_state.cached_host_tsc);
+ v3_last_exit = (uint32_t)(guest_ctrl->exit_code);
//PrintDebug("SVM Returned\n");
info->num_exits++;
-
-
-
// Save Guest state from VMCB
info->rip = guest_state->rip;
info->vm_regs.rsp = guest_state->rsp;
-#if 0
- if (info->cpu_id==1) {
- V3_Print("Exited Core 1, before handler\n");
- v3_print_guest_state(info);
- PrintDebugVMCB((vmcb_t*)(info->vmm_data));
- }
-#endif
-
-
if (v3_handle_svm_exit(info, exit_code, exit_info1, exit_info2) != 0) {
PrintError("Error in SVM exit handler\n");
return -1;
}
-#if 0
- if (info->cpu_id==1) {
- V3_Print("Exited Core 1, after handler\n");
- v3_print_guest_state(info);
- PrintDebugVMCB((vmcb_t*)(info->vmm_data));
- }
-#endif
-
-
-
return 0;
}
//PrintDebugVMCB((vmcb_t*)(info->vmm_data));
info->vm_info->run_state = VM_RUNNING;
- rdtscll(info->yield_start_cycle);
-
+ v3_start_time(info);
while (1) {
if (v3_svm_enter(info) == -1) {