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 support for in/out instructions
[palacios.git] / palacios / src / geekos / svm_io.c
1 #include <geekos/svm_io.h>
2 #include <geekos/vmm_io.h>
3
4
5
6 // This should package up an IO request and call vmm_handle_io
7 int handle_svm_io_in(struct guest_info * info) {
8   vmcb_ctrl_t * ctrl_area = GET_VMCB_CTRL_AREA((vmcb_t *)(info->vmm_data));
9   //  vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
10   struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1);
11
12   vmm_io_hook_t * hook = get_io_hook(&(info->io_map), io_info->port);
13   uint_t read_size = 0;
14
15   if (hook == NULL) {
16     // error, we should not have exited on this port
17     return -1;
18   }
19
20   PrintDebug("IN on  port %d (0x%x)\n", io_info->port, io_info->port);
21
22   if (io_info->sz8) { 
23     read_size = 1;
24   } else if (io_info->sz16) {
25     read_size = 2;
26   } else if (io_info->sz32) {
27     read_size = 4;
28   }
29
30
31   if (hook->read(io_info->port, &(info->vm_regs.rax), read_size, read_size) != read_size) {
32     // not sure how we handle errors.....
33     return -1;
34   }
35
36   info->rip = ctrl_area->exit_info2;
37
38   return 0;
39 }
40
41
42 int handle_svm_io_ins(struct guest_info * info) {
43
44   //  PrintDebug("INS on  port %d (0x%x)\n", io_info->port, io_info->port);
45
46   return -1;
47
48 }
49
50 int handle_svm_io_out(struct guest_info * info) {
51   vmcb_ctrl_t * ctrl_area = GET_VMCB_CTRL_AREA((vmcb_t *)(info->vmm_data));
52   //  vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
53   struct svm_io_info * io_info = (struct svm_io_info *)&(ctrl_area->exit_info1);
54
55   vmm_io_hook_t * hook = get_io_hook(&(info->io_map), io_info->port);
56   uint_t write_size = 0;
57
58   if (hook == NULL) {
59     // error, we should not have exited on this port
60     return -1;
61   }
62
63   PrintDebug("OUT on  port %d (0x%x)\n", io_info->port, io_info->port);
64
65   if (io_info->sz8) { 
66     write_size = 1;
67   } else if (io_info->sz16) {
68     write_size = 2;
69   } else if (io_info->sz32) {
70     write_size = 4;
71   }
72
73
74   if (hook->write(io_info->port, &(info->vm_regs.rax), write_size, write_size) != write_size) {
75     // not sure how we handle errors.....
76     return -1;
77   }
78
79   info->rip = ctrl_area->exit_info2;
80
81   return 0;
82 }
83
84
85 int handle_svm_io_outs(struct guest_info * info) {
86   return -1;
87 }