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.


Modified boot and vmxassist to handle real/protected transition.
[palacios.git] / palacios / src / palacios / vmx_ctrl_regs.c
1
2 /*
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.  
6  *
7  * The V3VEE Project is a joint project between Northwestern University
8  * and the University of New Mexico.  You can find out more at 
9  * http://www.v3vee.org
10  *
11  * Copyright (c) 2008, Andy Gocke <agocke@gmail.com>
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Andy Gocke <agocke@gmail.com>
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
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>
27
28 static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t new_val);
29
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);
32 }
33
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);
36
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);
40
41     // PG and PE are always enabled for VMX
42
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);
47             
48     if ( new_cr0->pe ) {
49
50         if (v3_vmxassist_ctx_switch(info) != 0) {
51             PrintError("Unable to execute VMXASSIST context switch!\n");
52             return -1;
53         }
54
55         ((struct vmx_data *)info->vmm_data)->state = VMXASSIST_DISABLED;
56
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))); 
59
60         return 0;
61     }
62
63     return -1;
64 }
65