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.


updated IO and MSRs to allow hooking/unhooking dynamic at runtime
[palacios.git] / palacios / src / palacios / vmm_msr.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <palacios/vmm_msr.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24
25
26 void v3_init_msr_map(struct guest_info * info) {
27     struct v3_msr_map * msr_map  = &(info->msr_map);
28
29     INIT_LIST_HEAD(&(msr_map->hook_list));
30     msr_map->num_hooks = 0;
31
32     msr_map->arch_data = NULL;
33     msr_map->update_map = NULL;
34 }
35
36
37 int v3_hook_msr(struct guest_info * info, uint_t msr, 
38                 int (*read)(uint_t msr, struct v3_msr * dst, void * priv_data),
39                 int (*write)(uint_t msr, struct v3_msr src, void * priv_data),
40                 void * priv_data) {
41
42     struct v3_msr_map * msr_map = &(info->msr_map);
43     struct v3_msr_hook * hook = NULL;
44
45     hook = (struct v3_msr_hook *)V3_Malloc(sizeof(struct v3_msr_hook));
46
47     if (hook == NULL) {
48         PrintError("Could not allocate msr hook for MSR %d\n", msr);
49         return -1;
50     }
51
52     hook->read = read;
53     hook->write = write;
54     hook->msr = msr;
55     hook->priv_data = priv_data;
56
57     msr_map->num_hooks++;
58
59     list_add(&(hook->link), &(msr_map->hook_list));
60
61     msr_map->update_map(info, msr, 
62                         (read == NULL) ? 0 : 1,
63                         (write == NULL) ? 0 : 1);
64     return 0;
65 }
66
67
68 int v3_unhook_msr(struct guest_info * info, uint_t msr) {
69     return -1;
70 }
71
72
73
74 struct v3_msr_hook * v3_get_msr_hook(struct guest_info * info, uint_t msr) {
75     struct v3_msr_map * msr_map = &(info->msr_map);
76     struct v3_msr_hook * hook = NULL;
77
78     list_for_each_entry(hook, &(msr_map->hook_list), link) {
79         if (hook->msr == msr) {
80             return hook;
81         }
82     }
83
84     return NULL;
85 }
86
87
88 void v3_print_msr_map(struct guest_info * info) {
89     struct v3_msr_map * msr_map = &(info->msr_map);
90     struct v3_msr_hook * hook = NULL;
91
92     list_for_each_entry(hook, &(msr_map->hook_list), link) {
93         PrintDebug("MSR HOOK (MSR=%d) (read=0x%p) (write=0x%p)\n",
94                    hook->msr, hook->read, hook->write);
95     }
96 }