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.


Added shadow page handling, IO and MSR bitmap allocation, and started
[palacios.git] / palacios / src / palacios / vmx_io.c
1
2 #include <palacios/vmx_io.h>
3 #include <palacios/vmm_io.h>
4 #include <palacios/vmcs.h>
5 #include <palacios/vmx_lowlevel.h>
6 #include <palacios/vmm.h>
7
8 /* Same as SVM */
9 static int update_map(struct guest_info * info, uint16_t port, int hook_read, int hook_write)
10 {
11     uchar_t * bitmap = (uint8_t *)(info->io_map.arch_data);
12     int major = port / 8;
13     int minor = port % 8;
14
15     if ((hook_read == 0) && (hook_write == 0)) {
16         *(bitmap + major) &= ~(0x1 << minor);
17     } else {
18         *(bitmap + major) |= (0x1 << minor);
19     }
20
21     return 0;
22 }
23
24 int v3_init_vmx_io_map(struct guest_info * info)
25 {
26     info->io_map.update_map = update_map;
27     
28     info->io_map.arch_data = V3_VAddr(V3_AllocPages(2));
29     memset(info->io_map.arch_data, 0, PAGE_SIZE_4KB*2);
30
31     return 0;
32 }
33
34 int v3_handle_vmx_io_in(struct guest_info * info)
35 {
36     PrintDebug("IN not implemented\n");
37     return -1;
38 }
39
40 int v3_handle_vmx_io_ins(struct guest_info * info)
41 {
42     PrintDebug("INS not implemented\n");
43     return -1;
44 }
45
46 int v3_handle_vmx_io_out(struct guest_info * info)
47 {
48     ulong_t exit_qual;
49
50     vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
51
52     struct vmcs_io_qual * io_qual = (struct vmcs_io_qual *)&exit_qual;
53
54     struct v3_io_hook * hook = v3_get_io_hook(info, io_qual->port);
55
56     if(hook == NULL) {
57         PrintError("Hook not present for out on port %x\n", io_qual->port);
58         return -1;
59     }
60
61     int write_size = 1<<(io_qual->accessSize);
62     
63     PrintDebug("OUT of %d bytes on port %d (0x%x)\n", write_size, io_qual->port, io_qual->port);
64
65     if(hook->write(io_qual->port, &(info->vm_regs.rax), write_size, hook->priv_data) != write_size) {
66         PrintError("Write failure for out on port %x\n",io_qual->port);
67         return -1;
68     }
69
70     uint32_t instr_length;
71
72     vmcs_read(VMCS_EXIT_INSTR_LEN, &instr_length);
73
74     info->rip += instr_length;
75
76     return 0;
77 }
78
79 int v3_handle_vmx_io_outs(struct guest_info * info)
80 {
81     ulong_t exit_qual;
82
83     vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
84
85     struct vmcs_io_qual * io_qual = (struct vmcs_io_qual *)&exit_qual;
86
87     PrintDebug("OUTS on port %d, (0x%x)\n", io_qual->port, io_qual->port);
88     return -1;
89 }