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.


331a3076b48df57445e223ab0de312e981c9ba73
[palacios.git] / palacios / include / palacios / vmm_lowlevel.h
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 #include <palacios/vmm_types.h>
21
22
23 #define CPUID_FEATURE_IDS 0x00000001
24 #define CPUID_EXT_FEATURE_IDS 0x80000001
25
26 struct seg_selector {
27     union {
28         uint16_t value;
29         struct {
30             uint8_t rpl     : 2;
31             uint8_t ti      : 1;
32             uint16_t si     : 13;
33         } __attribute__((packed));
34     } __attribute__((packed));
35 } __attribute__((packed));
36
37 struct gen_segment {
38     uint16_t limit_lo;
39     uint32_t base_lo     : 24;
40     uint8_t type         : 4;
41     uint8_t system       : 1;
42     uint8_t dpl          : 2;
43     uint8_t present      : 1;
44     uint8_t limit_hi     : 4;
45     uint8_t avail        : 1;
46     uint8_t long_mode    : 1;
47     uint8_t db           : 1;
48     uint8_t granularity  : 1;
49     uint8_t base_hi      : 8;
50 } __attribute__((packed));
51
52 struct sys_segment64 {
53     uint16_t limit_lo;
54     uint32_t base_lo     : 24;
55     uint8_t type         : 4;
56     uint8_t rsvd0        : 1;
57     uint8_t dpl          : 2;
58     uint8_t present      : 1;
59     uint8_t limit_hi     : 4;
60     uint8_t avail        : 1;
61     uint8_t rsvd1        : 3;
62     uint8_t granularity  : 1;
63     uint64_t base_hi     : 40;
64     uint32_t rsvd2;
65 } __attribute__((packed));
66
67
68
69 static void __inline__ v3_cpuid(uint32_t target, 
70                                 uint32_t * eax, uint32_t * ebx, 
71                                 uint32_t * ecx, uint32_t * edx) {
72     __asm__ __volatile__ (
73                           "cpuid\n\t"
74                           : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
75                           : "0" (target), "2" (*ecx)
76                           );
77     return;
78 }
79
80
81 static void __inline__ v3_set_msr(uint_t msr, uint_t high_byte, uint_t low_byte) {
82     __asm__ __volatile__ (
83                           "wrmsr"
84                           : 
85                           : "c" (msr), "d" (high_byte), "a" (low_byte)
86                           );
87
88
89 }
90
91
92
93 static void __inline__ v3_get_msr(uint_t msr, uint_t * high_byte, uint_t * low_byte) {
94     __asm__ __volatile__ (
95                           "rdmsr"
96                           : "=d" (*high_byte), "=a" (*low_byte) 
97                           : "c" (msr)
98                           );
99 }
100
101
102
103 static void __inline__ v3_enable_ints() {
104     __asm__ __volatile__ ("sti");
105 }
106
107 static void __inline__ v3_disable_ints() {
108     __asm__ __volatile__ ("cli");
109 }
110
111
112
113
114 #ifdef __V3_32BIT__
115
116 static addr_t __inline__ v3_irq_save() {
117     addr_t state;
118
119     __asm__ __volatile__ ("pushf \n\t"
120                           "popl %0 \n\t"
121                           "cli \n\t"
122                           :"=g" (state)
123                           : 
124                           :"memory"
125                           ); 
126     return state;
127 }
128
129 static void __inline__ v3_irq_restore(addr_t state) {
130     __asm__ __volatile__("pushl %0 \n\t"
131                          "popfl \n\t"
132                          : 
133                          :"g" (state)
134                          :"memory", "cc"
135                          );
136 }
137
138 #elif __V3_64BIT__
139
140 static addr_t __inline__ v3_irq_save() {
141     addr_t state; 
142
143     __asm__ __volatile__ ("pushfq \n\t"
144                           "popq %0 \n\t"
145                           "cli \n\t"
146                           :"=g" (state)
147                           : 
148                           :"memory"
149                           ); 
150
151     return state;
152 }
153
154
155 static void __inline__ v3_irq_restore(addr_t state) {
156     __asm__ __volatile__("pushq %0 \n\t"
157                          "popfq \n\t"
158                          : 
159                          :"g" (state)
160                          :"memory", "cc"
161                          );
162 }
163
164 #endif