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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/svm_msr.h>
21 #include <palacios/vmm_msr.h>
22 #include <palacios/vmm_sprintf.h>
23 #include <palacios/vmm_list.h>
24 #include <palacios/vm_guest.h>
26 #define PENTIUM_MSRS_START 0x00000000
27 #define PENTIUM_MSRS_END 0x00001fff
28 #define AMD_6_GEN_MSRS_START 0xc0000000
29 #define AMD_6_GEN_MSRS_END 0xc0001fff
30 #define AMD_7_8_GEN_MSRS_START 0xc0010000
31 #define AMD_7_8_GEN_MSRS_END 0xc0011fff
33 #define PENTIUM_MSRS_INDEX (0)
34 #define AMD_6_GEN_MSRS_INDEX (0x2000)
35 #define AMD_7_8_GEN_MSRS_INDEX (0x4000)
39 static int get_bitmap_index(uint_t msr) {
40 if ((msr >= PENTIUM_MSRS_START) &&
41 (msr <= PENTIUM_MSRS_END)) {
42 return (PENTIUM_MSRS_INDEX + (msr - PENTIUM_MSRS_START));
43 } else if ((msr >= AMD_6_GEN_MSRS_START) &&
44 (msr <= AMD_6_GEN_MSRS_END)) {
45 return (AMD_6_GEN_MSRS_INDEX + (msr - AMD_6_GEN_MSRS_START));
46 } else if ((msr >= AMD_7_8_GEN_MSRS_START) &&
47 (msr <= AMD_7_8_GEN_MSRS_END)) {
48 return (AMD_7_8_GEN_MSRS_INDEX + (msr - AMD_7_8_GEN_MSRS_START));
50 PrintError("MSR out of range (MSR=0x%x)\n", msr);
56 static int update_map(struct v3_vm_info * vm, uint_t msr, int hook_reads, int hook_writes) {
57 int index = get_bitmap_index(msr);
58 uint_t major = index / 4;
59 uint_t minor = (index % 4) * 2;
62 uint8_t * bitmap = (uint8_t *)(vm->msr_map.arch_data);
72 *(bitmap + major) &= ~(mask << minor);
73 *(bitmap + major) |= (val << minor);
79 int v3_init_svm_msr_map(struct v3_vm_info * vm) {
80 struct v3_msr_map * msr_map = &(vm->msr_map);
82 msr_map->update_map = update_map;
84 msr_map->arch_data = V3_VAddr(V3_AllocPages(2));
85 memset(msr_map->arch_data, 0, PAGE_SIZE_4KB * 2);
87 v3_refresh_msr_map(vm);
92 int v3_deinit_svm_msr_map(struct v3_vm_info * vm) {
93 V3_FreePages(V3_PAddr(vm->msr_map.arch_data), 2);