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.


minor changes to organization
[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 // KCH: for system-call interposition
31 #define STAR_MSR                 0xc0000081 /* Legacy mode SYSCALL target */
32 #define LSTAR_MSR                0xc0000082 /* Long mode SYSCALL target */
33 #define CSTAR_MSR                0xc0000083 /* compat mode SYSCALL target */
34 #define SF_MASK_MSR              0xc0000084 /* EFLAGS mask for syscall */
35 #define FS_BASE_MSR              0xc0000100 /* 64-bit FS base */
36 #define GS_BASE_MSR              0xc0000101 /* 64-bit GS base */
37 #define KERN_GS_BASE_MSR         0xc0000102 /* swapGS GS shadow */
38
39 /* Intel specific */
40 #define IA32_SYSENTER_CS_MSR     0x00000174
41 #define IA32_SYSENTER_ESP_MSR    0x00000175
42 #define IA32_SYSENTER_EIP_MSR    0x00000176
43
44 struct cr0_real {
45     uint_t pe    : 1;
46     uint_t mp    : 1;
47     uint_t em    : 1;
48     uint_t ts    : 1;
49 } __attribute__((packed));
50
51
52 struct cr0_32 {
53     uint_t pe    : 1;
54     uint_t mp    : 1;
55     uint_t em    : 1;
56     uint_t ts    : 1;
57     uint_t et    : 1;
58     uint_t ne    : 1;
59     uint_t rsvd1 : 10;
60     uint_t wp    : 1;
61     uint_t rsvd2 : 1;
62     uint_t am    : 1;
63     uint_t rsvd3 : 10;
64     uint_t nw    : 1;
65     uint_t cd    : 1;
66     uint_t pg    : 1;
67 } __attribute__((packed));
68
69
70 struct cr0_64 {
71     uint_t pe    : 1;
72     uint_t mp    : 1;
73     uint_t em    : 1;
74     uint_t ts    : 1;
75     uint_t et    : 1;
76     uint_t ne    : 1;
77     uint_t rsvd1 : 10;
78     uint_t wp    : 1;
79     uint_t rsvd2 : 1;
80     uint_t am    : 1;
81     uint_t rsvd3 : 10;
82     uint_t nw    : 1;
83     uint_t cd    : 1;
84     uint_t pg    : 1;
85
86     uint_t  rsvd4;  // MBZ
87 } __attribute__((packed));
88
89
90 struct cr2_32 {
91     uint_t pf_vaddr;
92 } __attribute__((packed));
93
94 struct cr2_64 {
95     ullong_t pf_vaddr;
96 } __attribute__((packed));
97
98
99 struct cr3_32 {
100     uint_t rsvd1             : 3;
101     uint_t pwt               : 1;
102     uint_t pcd               : 1;
103     uint_t rsvd2             : 7;
104     uint_t pdt_base_addr    : 20;
105 } __attribute__((packed));
106
107
108 struct cr3_32_PAE {
109     uint_t rsvd1             : 3;
110     uint_t pwt               : 1;
111     uint_t pcd               : 1;
112     uint_t pdpt_base_addr    : 27;
113 } __attribute__((packed));
114
115
116 struct cr3_64 {
117     uint_t rsvd1             : 3;
118     uint_t pwt               : 1;
119     uint_t pcd               : 1;
120     uint_t rsvd2             : 7;
121     ullong_t pml4t_base_addr : 40;
122     uint_t rsvd3             : 12; 
123 } __attribute__((packed));
124
125
126 struct cr4_32 {
127     uint_t vme               : 1;
128     uint_t pvi               : 1;
129     uint_t tsd               : 1;
130     uint_t de                : 1;
131     uint_t pse               : 1;
132     uint_t pae               : 1;
133     uint_t mce               : 1;
134     uint_t pge               : 1;
135     uint_t pce               : 1;
136     uint_t osf_xsr           : 1;
137     uint_t osx               : 1;
138     uint_t rsvd1             : 21;
139 } __attribute__((packed));
140
141 struct cr4_64 {
142     uint_t vme               : 1;
143     uint_t pvi               : 1;
144     uint_t tsd               : 1;
145     uint_t de                : 1;
146     uint_t pse               : 1;
147     uint_t pae               : 1;
148     uint_t mce               : 1;
149     uint_t pge               : 1;
150     uint_t pce               : 1;
151     uint_t osf_xsr           : 1;
152     uint_t osx               : 1;
153     uint_t rsvd1             : 21;
154     uint_t rsvd2             : 32;
155 } __attribute__((packed));
156
157
158
159 struct efer_64 {
160     uint_t sce              : 1;
161     uint_t rsvd1            : 7; // RAZ
162     uint_t lme              : 1;
163     uint_t rsvd2            : 1; // MBZ
164     uint_t lma              : 1;
165     uint_t nxe              : 1;
166     uint_t svme             : 1;
167     uint_t rsvd3            : 1; // MBZ
168     uint_t ffxsr            : 1;
169     uint_t rsvd4            : 12; // MBZ
170     uint_t rsvd5            : 32; // MBZ
171 } __attribute__((packed));
172
173
174 struct rflags {
175     uint_t cf                : 1;  // carry flag
176     uint_t rsvd1             : 1;  // Must be 1
177     uint_t pf                : 1;  // parity flag
178     uint_t rsvd2             : 1;  // Read as 0
179     uint_t af                : 1;  // Auxillary flag
180     uint_t rsvd3             : 1;  // Read as 0
181     uint_t zf                : 1;  // zero flag
182     uint_t sf                : 1;  // sign flag
183     uint_t tf                : 1;  // trap flag
184     uint_t intr              : 1;  // interrupt flag
185     uint_t df                : 1;  // direction flag
186     uint_t of                : 1;  // overflow flag
187     uint_t iopl              : 2;  // IO privilege level
188     uint_t nt                : 1;  // nested task
189     uint_t rsvd4             : 1;  // read as 0
190     uint_t rf                : 1;  // resume flag
191     uint_t vm                : 1;  // Virtual-8086 mode
192     uint_t ac                : 1;  // alignment check
193     uint_t vif               : 1;  // virtual interrupt flag
194     uint_t vip               : 1;  // virtual interrupt pending
195     uint_t id                : 1;  // ID flag
196     uint_t rsvd5             : 10; // Read as 0
197     uint_t rsvd6             : 32; // Read as 0
198 } __attribute__((packed));
199
200
201
202
203
204 /*
205 // First opcode byte
206 static const uchar_t cr_access_byte = 0x0f;
207
208 // Second opcode byte
209 static const uchar_t lmsw_byte = 0x01;
210 static const uchar_t lmsw_reg_byte = 0x6;
211 static const uchar_t smsw_byte = 0x01;
212 static const uchar_t smsw_reg_byte = 0x4;
213 static const uchar_t clts_byte = 0x06;
214 static const uchar_t mov_to_cr_byte = 0x22;
215 static const uchar_t mov_from_cr_byte = 0x20;
216 */
217
218
219 int v3_handle_cr0_write(struct guest_info * info);
220 int v3_handle_cr0_read(struct guest_info * info);
221
222 int v3_handle_cr3_write(struct guest_info * info);
223 int v3_handle_cr3_read(struct guest_info * info);
224
225 int v3_handle_cr4_write(struct guest_info * info);
226 int v3_handle_cr4_read(struct guest_info * info);
227
228
229 int v3_handle_efer_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
230 int v3_handle_efer_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
231
232 int v3_handle_star_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
233 int v3_handle_star_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
234 int v3_handle_lstar_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
235 int v3_handle_lstar_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
236 int v3_handle_cstar_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
237 int v3_handle_cstar_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
238
239 int v3_handle_seeip_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
240 int v3_handle_seeip_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
241
242 int v3_handle_vm_cr_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data);
243 int v3_handle_vm_cr_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data);
244
245
246 #endif // ! __V3VEE__
247
248
249 #endif