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.


6624da63cf6a6655e5ab2c28144e797588ae1d3b
[palacios.git] / palacios / src / geekos / svm_handler.c
1 #include <geekos/svm_handler.h>
2 #include <geekos/vmm.h>
3 #include <geekos/svm_ctrl_regs.h>
4
5 extern struct vmm_os_hooks * os_hooks;
6
7
8 int handle_svm_exit(struct guest_info * info) {
9   vmcb_ctrl_t * guest_ctrl = 0;
10   vmcb_saved_state_t * guest_state = 0;
11   ulong_t exit_code = 0;
12   
13   guest_ctrl = GET_VMCB_CTRL_AREA((vmcb_t*)(info->vmm_data));
14   guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
15   
16
17   // Update the high level state 
18   info->rip = guest_state->rip;
19   info->vm_regs.rsp = guest_state->rsp;
20   info->vm_regs.rax = guest_state->rax;
21   info->vm_regs.rsp = guest_state->rsp;
22
23
24   PrintDebug("SVM Returned: (Exit Code=%x) (VMCB=%x)\n", &(guest_ctrl->exit_code), info->vmm_data); 
25   PrintDebug("RIP: %x\n", guest_state->rip);
26   
27
28
29   exit_code = guest_ctrl->exit_code;
30   
31   // PrintDebugVMCB((vmcb_t*)(info->vmm_data));
32   PrintDebug("SVM Returned: Exit Code: %x\n",exit_code); 
33   PrintDebug("io_info1 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info1));
34   PrintDebug("io_info1 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info1)) + 4));
35
36   PrintDebug("io_info2 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info2));
37   PrintDebug("io_info2 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info2)) + 4));
38   if (exit_code == VMEXIT_IOIO) {
39     handle_svm_io(info);
40
41   } else if (exit_code == VMEXIT_CR0_WRITE) {
42     PrintDebug("CR0 Write\n");
43     ullong_t new_cr0 = 0;
44
45     handle_cr0_write(info, &new_cr0);
46
47     guest_state->cr0 = new_cr0;
48
49   } else if (( (exit_code == VMEXIT_CR3_READ)  ||
50                (exit_code == VMEXIT_CR3_WRITE) ||
51                (exit_code == VMEXIT_INVLPG)    ||
52                (exit_code == VMEXIT_INVLPGA)   || 
53                (exit_code == VMEXIT_EXCP14)) && 
54              (info->page_mode == SHADOW_PAGING)) {
55     handle_shadow_paging(info);
56   }
57
58
59   // Update the low level state
60   guest_state->rax = info->vm_regs.rax;
61   guest_state->rip = info->rip;
62   guest_state->rsp = info->vm_regs.rsp;
63
64   return 0;
65 }
66
67
68
69 // This should package up an IO request and call vmm_handle_io
70 int handle_svm_io(struct guest_info * info) {
71   vmcb_ctrl_t * ctrl_area = GET_VMCB_CTRL_AREA((vmcb_t *)(info->vmm_data));
72   vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
73
74   PrintDebug("Ctrl Area=%x\n", ctrl_area);
75
76   //  struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1);
77
78
79
80   //  PrintDebugVMCB((vmcb_t*)(info->vmm_data));
81
82   guest_state->rip = ctrl_area->exit_info2;
83
84
85   
86
87   //  PrintDebug("Exit On Port %d\n", io_info->port);
88
89   return 0;
90 }
91
92
93 int handle_shadow_paging(struct guest_info * info) {
94   vmcb_ctrl_t * guest_ctrl = GET_VMCB_CTRL_AREA((vmcb_t*)(info->vmm_data));
95   //  vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
96
97   if (guest_ctrl->exit_code == VMEXIT_CR3_READ) {
98
99   }
100
101   return 0;
102 }
103
104
105