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.


Succesful transition to vmxassist, then to the bios, where it dies in keyboard init.
[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 #include <palacios/vmx_handler.h>
8
9 /* Same as SVM */
10 static int update_map(struct guest_info * info, uint16_t port, int hook_read, int hook_write)
11 {
12     uchar_t * bitmap = (uint8_t *)(info->io_map.arch_data);
13     int major = port / 8;
14     int minor = port % 8;
15
16     if ((hook_read == 0) && (hook_write == 0)) {
17         *(bitmap + major) &= ~(0x1 << minor);
18     } else {
19         *(bitmap + major) |= (0x1 << minor);
20     }
21
22     return 0;
23 }
24
25 int v3_init_vmx_io_map(struct guest_info * info)
26 {
27     info->io_map.update_map = update_map;
28     
29     info->io_map.arch_data = V3_VAddr(V3_AllocPages(2));
30     memset(info->io_map.arch_data, 0, PAGE_SIZE_4KB*2);
31
32     return 0;
33 }
34
35 int v3_handle_vmx_io_in(struct guest_info * info)
36 {
37     ulong_t exit_qual;
38
39     vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
40
41     struct vmexit_io_qual * io_qual = (struct vmexit_io_qual *)&exit_qual;
42
43     struct v3_io_hook * hook = v3_get_io_hook(info,io_qual->port);
44     int read_size = 0;
45
46     if(hook == NULL) {
47         PrintError("Hook not present for IN on port %x\n", io_qual->port);
48         return -1;
49     }
50
51     read_size = 1<<(io_qual->access_size);
52
53     PrintDebug("IN of %d bytes on port %d (0x%x)\n", read_size, io_qual->port, io_qual->port);
54
55     if(hook->read(io_qual->port, &(info->vm_regs.rax), read_size, hook->priv_data) != read_size) {
56         PrintError("Read failure for IN on port %x\n", io_qual->port);
57         return -1;
58     }
59
60     uint32_t instr_length = 0;
61
62     if(vmcs_read(VMCS_EXIT_INSTR_LEN, &instr_length) != VMX_SUCCESS) {
63         PrintError("Could not read instruction length\n");
64         return -1;
65     }
66
67     info->rip += instr_length;
68
69     return 0;
70 }
71
72 int v3_handle_vmx_io_ins(struct guest_info * info)
73 {
74     PrintDebug("INS not implemented\n");
75     return -1;
76 }
77
78 int v3_handle_vmx_io_out(struct guest_info * info)
79 {
80     ulong_t exit_qual;
81
82     vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
83
84     struct vmexit_io_qual * io_qual = (struct vmexit_io_qual *)&exit_qual;
85
86     struct v3_io_hook * hook = v3_get_io_hook(info, io_qual->port);
87
88     if(hook == NULL) {
89         PrintError("Hook not present for out on port %x\n", io_qual->port);
90         return -1;
91     }
92
93     int write_size = 1<<(io_qual->access_size);
94     
95     PrintDebug("OUT of %d bytes on port %d (0x%x)\n", write_size, io_qual->port, io_qual->port);
96
97
98     if(hook->write(io_qual->port, &(info->vm_regs.rax), write_size, hook->priv_data) != write_size) {
99         PrintError("Write failure for out on port %x\n",io_qual->port);
100         return -1;
101     }
102
103     uint32_t instr_length = 0;
104
105     if(vmcs_read(VMCS_EXIT_INSTR_LEN, &instr_length) != VMX_SUCCESS) {
106         PrintError("Could not read instruction length\n");
107         return -1;
108     } 
109
110     info->rip += instr_length;
111
112     return 0;
113 }
114
115 int v3_handle_vmx_io_outs(struct guest_info * info)
116 {
117     ulong_t exit_qual;
118
119     vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
120
121     struct vmexit_io_qual * io_qual = (struct vmexit_io_qual *)&exit_qual;
122
123     PrintDebug("OUTS on port %d, (0x%x)\n", io_qual->port, io_qual->port);
124     return -1;
125 }