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.


update outdated CR4 definitions
[palacios.git] / palacios / include / palacios / vmm_ctrl_regs.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 #ifndef __VMM_CTRL_REGS_H
21 #define __VMM_CTRL_REGS_H
22
23 #ifdef __V3VEE__
24
25
26 #include <palacios/vm_guest.h>
27
28 #define EFER_MSR                 0xc0000080
29
30 struct cr0_real {
31     uint_t pe    : 1;
32     uint_t mp    : 1;
33     uint_t em    : 1;
34     uint_t ts    : 1;
35 } __attribute__((packed));
36
37
38 struct cr0_32 {
39     uint_t pe    : 1;
40     uint_t mp    : 1;
41     uint_t em    : 1;
42     uint_t ts    : 1;
43     uint_t et    : 1;
44     uint_t ne    : 1;
45     uint_t rsvd1 : 10;
46     uint_t wp    : 1;
47     uint_t rsvd2 : 1;
48     uint_t am    : 1;
49     uint_t rsvd3 : 10;
50     uint_t nw    : 1;
51     uint_t cd    : 1;
52     uint_t pg    : 1;
53 } __attribute__((packed));
54
55
56 struct cr0_64 {
57     uint_t pe    : 1;
58     uint_t mp    : 1;
59     uint_t em    : 1;
60     uint_t ts    : 1;
61     uint_t et    : 1;
62     uint_t ne    : 1;
63     uint_t rsvd1 : 10;
64     uint_t wp    : 1;
65     uint_t rsvd2 : 1;
66     uint_t am    : 1;
67     uint_t rsvd3 : 10;
68     uint_t nw    : 1;
69     uint_t cd    : 1;
70     uint_t pg    : 1;
71
72     uint_t  rsvd4;  // MBZ
73 } __attribute__((packed));
74
75
76 struct cr2_32 {
77     uint_t pf_vaddr;
78 } __attribute__((packed));
79
80 struct cr2_64 {
81     ullong_t pf_vaddr;
82 } __attribute__((packed));
83
84
85 struct cr3_32 {
86     uint_t rsvd1             : 3;
87     uint_t pwt               : 1;
88     uint_t pcd               : 1;
89     uint_t rsvd2             : 7;
90     uint_t pdt_base_addr    : 20;
91 } __attribute__((packed));
92
93
94 struct cr3_32_PAE {
95     uint_t rsvd1             : 3;
96     uint_t pwt               : 1;
97     uint_t pcd               : 1;
98     uint_t pdpt_base_addr    : 27;
99 } __attribute__((packed));
100
101
102 struct cr3_64 {
103     uint_t rsvd1             : 3;
104     uint_t pwt               : 1;
105     uint_t pcd               : 1;
106     uint_t rsvd2             : 7;
107     ullong_t pml4t_base_addr : 40;
108     uint_t rsvd3             : 12; 
109 } __attribute__((packed));
110
111
112 struct cr4_32 {
113     uint_t vme               : 1;
114     uint_t pvi               : 1;
115     uint_t tsd               : 1;
116     uint_t de                : 1;
117     uint_t pse               : 1;
118     uint_t pae               : 1;
119     uint_t mce               : 1;
120     uint_t pge               : 1;
121     uint_t pce               : 1;
122     uint_t os_fxsr           : 1;
123     uint_t osxmmexcpt        : 1;
124     uint_t rsvd0             : 5;
125     uint_t fsgsbase          : 1;
126     uint_t rsvd1             : 1;
127     uint_t osxsave           : 1;
128     uint_t rsvd2             : 13;
129 } __attribute__((packed));
130
131 struct cr4_64 {
132     uint_t vme               : 1;
133     uint_t pvi               : 1;
134     uint_t tsd               : 1;
135     uint_t de                : 1;
136     uint_t pse               : 1;
137     uint_t pae               : 1;
138     uint_t mce               : 1;
139     uint_t pge               : 1;
140     uint_t pce               : 1;
141     uint_t os_fxsr           : 1;
142     uint_t osxmmexcpt        : 1;
143     uint_t rsvd0             : 5;
144     uint_t fsgsbase          : 1;
145     uint_t rsvd1             : 1;
146     uint_t osxsave           : 1;
147     uint_t rsvd2             : 13;
148     uint_t rsvd3             : 32;
149 } __attribute__((packed));
150
151
152
153 struct efer_64 {
154     uint_t sce              : 1;
155     uint_t rsvd1            : 7; // RAZ
156     uint_t lme              : 1;
157     uint_t rsvd2            : 1; // MBZ
158     uint_t lma              : 1;
159     uint_t nxe              : 1;
160     uint_t svme             : 1;
161     uint_t rsvd3            : 1; // MBZ
162     uint_t ffxsr            : 1;
163     uint_t rsvd4            : 12; // MBZ
164     uint_t rsvd5            : 32; // MBZ
165 } __attribute__((packed));
166
167
168 struct rflags {
169     uint_t cf                : 1;  // carry flag
170     uint_t rsvd1             : 1;  // Must be 1
171     uint_t pf                : 1;  // parity flag
172     uint_t rsvd2             : 1;  // Read as 0
173     uint_t af                : 1;  // Auxillary flag
174     uint_t rsvd3             : 1;  // Read as 0
175     uint_t zf                : 1;  // zero flag
176     uint_t sf                : 1;  // sign flag
177     uint_t tf                : 1;  // trap flag
178     uint_t intr              : 1;  // interrupt flag
179     uint_t df                : 1;  // direction flag
180     uint_t of                : 1;  // overflow flag
181     uint_t iopl              : 2;  // IO privilege level
182     uint_t nt                : 1;  // nested task
183     uint_t rsvd4             : 1;  // read as 0
184     uint_t rf                : 1;  // resume flag
185     uint_t vm                : 1;  // Virtual-8086 mode
186     uint_t ac                : 1;  // alignment check
187     uint_t vif               : 1;  // virtual interrupt flag
188     uint_t vip               : 1;  // virtual interrupt pending
189     uint_t id                : 1;  // ID flag
190     uint_t rsvd5             : 10; // Read as 0
191     uint_t rsvd6             : 32; // Read as 0
192 } __attribute__((packed));
193
194
195
196
197 /*
198 // First opcode byte
199 static const uchar_t cr_access_byte = 0x0f;
200
201 // Second opcode byte
202 static const uchar_t lmsw_byte = 0x01;
203 static const uchar_t lmsw_reg_byte = 0x6;
204 static const uchar_t smsw_byte = 0x01;
205 static const uchar_t smsw_reg_byte = 0x4;
206 static const uchar_t clts_byte = 0x06;
207 static const uchar_t mov_to_cr_byte = 0x22;
208 static const uchar_t mov_from_cr_byte = 0x20;
209 */
210
211
212 int v3_handle_cr0_write(struct guest_info * info);
213 int v3_handle_cr0_read(struct guest_info * info);
214
215 int v3_handle_cr3_write(struct guest_info * info);
216 int v3_handle_cr3_read(struct guest_info * info);
217
218 int v3_handle_cr4_write(struct guest_info * info);
219 int v3_handle_cr4_read(struct guest_info * info);
220
221 int v3_handle_cr8_write(struct guest_info * info);
222 int v3_handle_cr8_read(struct guest_info * info);
223
224
225 int v3_handle_efer_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
226 int v3_handle_efer_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
227
228 int v3_handle_vm_cr_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
229 int v3_handle_vm_cr_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
230
231
232 #endif // ! __V3VEE__
233
234
235 #endif