3 * This file is part of the Palacios Virtual Machine Monitor developed
4 * by the V3VEE Project with funding from the United States National
5 * Science Foundation and the Department of Energy.
7 * The V3VEE Project is a joint project between Northwestern University
8 * and the University of New Mexico. You can find out more at
11 * Copyright (c) 2008, Andy Gocke <agocke@gmail.com>
12 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
13 * All rights reserved.
15 * Author: Andy Gocke <agocke@gmail.com>
17 * This is free software. You are permitted to use,
18 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <palacios/vmx_ctrl_regs.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vmx_lowlevel.h>
24 #include <palacios/vmx.h>
25 #include <palacios/vmx_assist.h>
26 #include <palacios/vm_guest_mem.h>
28 static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t new_val);
30 int v3_vmx_handle_cr0_write(struct guest_info * info, v3_reg_t new_val) {
31 return handle_mov_to_cr0(info, new_val);
34 static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t new_val) {
35 PrintDebug("CR0 RIP: %p\n", (void *)info->rip);
37 struct cr0_32 * guest_cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
38 struct cr0_32 * new_cr0 = (struct cr0_32 *)&new_val;
39 struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
41 // PG and PE are always enabled for VMX
43 // Check if this is a paging transition
44 PrintDebug("Old CR0: 0x%x\n", *(uint32_t *)guest_cr0);
45 PrintDebug("Old shadow CR0: 0x%x\n", *(uint32_t *)shadow_cr0);
46 PrintDebug("New CR0: 0x%x\n", *(uint32_t *)new_cr0);
50 if (v3_vmxassist_ctx_switch(info) != 0) {
51 PrintError("Unable to execute VMXASSIST context switch!\n");
55 ((struct vmx_data *)info->vmm_data)->state = VMXASSIST_DISABLED;
57 PrintDebug("New Shadow: 0x%x\n", *(uint32_t *)shadow_cr0);
58 PrintDebug("mem_mode: %s\n", v3_mem_mode_to_str(v3_get_vm_mem_mode(info)));