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.


VMX is working for a 32-bit Linux kernel. It should also work for a 64-bit kernel...
[palacios.git] / palacios / src / palacios / vmx_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, Andy Gocke <agocke@gmail.com>
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Andy Gocke <agocke@gmail.com>
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 #include <palacios/vmm.h>
21 #include <palacios/vm_guest.h>
22 #include <palacios/vmm_msr.h>
23
24 #define LOW_MSR_START   0x00000000
25 #define LOW_MSR_END     0x1fff
26 #define HIGH_MSR_START  0xc0000000
27 #define HIGH_MSR_END    0xc0001fff
28
29 #define LOW_MSR_INDEX   0
30 #define HIGH_MSR_INDEX  1024
31
32 static int get_bitmap_index(uint_t msr)
33 {
34     if( (msr >= LOW_MSR_START) && msr <= LOW_MSR_END) {
35         return LOW_MSR_INDEX + msr;
36     } else if (( msr >= HIGH_MSR_START ) && (msr <= HIGH_MSR_END)) {
37         return HIGH_MSR_INDEX + (msr - HIGH_MSR_START);
38     } else {
39         PrintError("MSR out of range: 0x%x\n", msr);
40         return -1;
41     }
42 }
43
44 /* Same as SVM */
45 static int update_map(struct guest_info * info, uint_t msr, int hook_reads, int hook_writes) {
46
47     int index = get_bitmap_index(msr);
48     uint_t major = index / 8;
49     uint_t minor = (index % 8);
50     uchar_t mask = 0x1;
51     uint8_t read_val = (hook_reads) ? 0x1 : 0x0;
52     uint8_t write_val = (hook_writes) ? 0x1 : 0x0;
53     uint8_t * bitmap = (uint8_t *)(info->msr_map.arch_data);
54
55
56     *(bitmap + major) &= ~(mask << minor);
57     *(bitmap + major) |= (read_val << minor);
58     
59
60     *(bitmap + 2048 + major) &= ~(mask << minor);
61     *(bitmap + 2048 + major) |= (write_val << minor);
62     
63     return 0;
64 }
65
66 int v3_init_vmx_msr_map(struct guest_info * info) {
67    struct v3_msr_map * msr_map = &(info->msr_map);
68
69    msr_map->update_map = update_map;
70    
71    msr_map->arch_data = V3_VAddr(V3_AllocPages(1));
72    memset(msr_map->arch_data, 0, PAGE_SIZE_4KB);
73
74    return 0;
75 }