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>
9 static int update_map(struct guest_info * info, uint16_t port, int hook_read, int hook_write)
11 uchar_t * bitmap = (uint8_t *)(info->io_map.arch_data);
15 if ((hook_read == 0) && (hook_write == 0)) {
16 *(bitmap + major) &= ~(0x1 << minor);
18 *(bitmap + major) |= (0x1 << minor);
24 int v3_init_vmx_io_map(struct guest_info * info)
26 info->io_map.update_map = update_map;
28 info->io_map.arch_data = V3_VAddr(V3_AllocPages(2));
29 memset(info->io_map.arch_data, 0, PAGE_SIZE_4KB*2);
34 int v3_handle_vmx_io_in(struct guest_info * info)
36 PrintDebug("IN not implemented\n");
40 int v3_handle_vmx_io_ins(struct guest_info * info)
42 PrintDebug("INS not implemented\n");
46 int v3_handle_vmx_io_out(struct guest_info * info)
50 vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
52 struct vmcs_io_qual * io_qual = (struct vmcs_io_qual *)&exit_qual;
54 struct v3_io_hook * hook = v3_get_io_hook(info, io_qual->port);
57 PrintError("Hook not present for out on port %x\n", io_qual->port);
61 int write_size = 1<<(io_qual->accessSize);
63 PrintDebug("OUT of %d bytes on port %d (0x%x)\n", write_size, io_qual->port, io_qual->port);
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);
70 uint32_t instr_length;
72 vmcs_read(VMCS_EXIT_INSTR_LEN, &instr_length);
74 info->rip += instr_length;
79 int v3_handle_vmx_io_outs(struct guest_info * info)
83 vmcs_read(VMCS_EXIT_QUAL, &exit_qual);
85 struct vmcs_io_qual * io_qual = (struct vmcs_io_qual *)&exit_qual;
87 PrintDebug("OUTS on port %d, (0x%x)\n", io_qual->port, io_qual->port);