@@ -14,11 +14,6 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- #[ cfg( mshv3) ]
18- extern crate mshv_bindings;
19- #[ cfg( mshv3) ]
20- extern crate mshv_ioctls;
21-
2217#[ cfg( target_os = "windows" ) ]
2318use std:: collections:: HashSet ;
2419
@@ -32,6 +27,25 @@ use windows::Win32::System::Hypervisor::*;
3227#[ cfg( target_os = "windows" ) ]
3328use super :: FromWhpRegisterError ;
3429
30+ cfg_if:: cfg_if! {
31+ if #[ cfg( feature = "init-paging" ) ] {
32+ pub ( crate ) const CR4_PAE : u64 = 1 << 5 ;
33+ pub ( crate ) const CR4_OSFXSR : u64 = 1 << 9 ;
34+ pub ( crate ) const CR4_OSXMMEXCPT : u64 = 1 << 10 ;
35+ pub ( crate ) const CR0_PE : u64 = 1 ;
36+ pub ( crate ) const CR0_MP : u64 = 1 << 1 ;
37+ pub ( crate ) const CR0_ET : u64 = 1 << 4 ;
38+ pub ( crate ) const CR0_NE : u64 = 1 << 5 ;
39+ pub ( crate ) const CR0_WP : u64 = 1 << 16 ;
40+ pub ( crate ) const CR0_AM : u64 = 1 << 18 ;
41+ pub ( crate ) const CR0_PG : u64 = 1 << 31 ;
42+ pub ( crate ) const EFER_LME : u64 = 1 << 8 ;
43+ pub ( crate ) const EFER_LMA : u64 = 1 << 10 ;
44+ pub ( crate ) const EFER_SCE : u64 = 1 ;
45+ pub ( crate ) const EFER_NX : u64 = 1 << 11 ;
46+ }
47+ }
48+
3549#[ derive( Debug , Default , Copy , Clone , PartialEq ) ]
3650pub ( crate ) struct CommonSpecialRegisters {
3751 pub cs : CommonSegmentRegister ,
@@ -54,6 +68,77 @@ pub(crate) struct CommonSpecialRegisters {
5468 pub interrupt_bitmap : [ u64 ; 4 ] ,
5569}
5670
71+ impl CommonSpecialRegisters {
72+ #[ cfg( feature = "init-paging" ) ]
73+ pub ( crate ) fn standard_64bit_defaults ( pml4_addr : u64 ) -> Self {
74+ CommonSpecialRegisters {
75+ cs : CommonSegmentRegister {
76+ l : 1 , // 64-bit
77+ type_ : 0b1011 , // Code, Readable, Accessed
78+ present : 1 , // Present
79+ s : 1 , // Non-system
80+ ..Default :: default ( )
81+ } ,
82+ tr : CommonSegmentRegister {
83+ limit : 0xFFFF ,
84+ type_ : 0b1011 ,
85+ present : 1 ,
86+ ..Default :: default ( )
87+ } ,
88+ efer : EFER_LME | EFER_LMA | EFER_SCE | EFER_NX ,
89+ ds : Default :: default ( ) ,
90+ es : Default :: default ( ) ,
91+ fs : Default :: default ( ) ,
92+ gs : Default :: default ( ) ,
93+ ss : Default :: default ( ) ,
94+ ldt : Default :: default ( ) ,
95+ gdt : Default :: default ( ) ,
96+ idt : Default :: default ( ) ,
97+ cr0 : CR0_PE | CR0_MP | CR0_ET | CR0_NE | CR0_AM | CR0_WP | CR0_PG ,
98+ cr2 : 0 ,
99+ cr4 : CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT ,
100+ cr3 : pml4_addr,
101+ cr8 : 0 ,
102+ apic_base : 0 ,
103+ interrupt_bitmap : [ 0 ; 4 ] ,
104+ }
105+ }
106+
107+ #[ cfg( not( feature = "init-paging" ) ) ]
108+ pub ( crate ) fn standard_real_mode_defaults ( ) -> Self {
109+ CommonSpecialRegisters {
110+ cs : CommonSegmentRegister {
111+ base : 0 ,
112+ selector : 0 ,
113+ limit : 0xFFFF ,
114+ type_ : 11 ,
115+ present : 1 ,
116+ s : 1 ,
117+ ..Default :: default ( )
118+ } ,
119+ ds : CommonSegmentRegister {
120+ base : 0 ,
121+ selector : 0 ,
122+ limit : 0xFFFF ,
123+ type_ : 3 ,
124+ present : 1 ,
125+ s : 1 ,
126+ ..Default :: default ( )
127+ } ,
128+ tr : CommonSegmentRegister {
129+ base : 0 ,
130+ selector : 0 ,
131+ limit : 0xFFFF ,
132+ type_ : 11 ,
133+ present : 1 ,
134+ s : 0 ,
135+ ..Default :: default ( )
136+ } ,
137+ ..Default :: default ( )
138+ }
139+ }
140+ }
141+
57142#[ cfg( mshv3) ]
58143impl From < & SpecialRegisters > for CommonSpecialRegisters {
59144 fn from ( value : & SpecialRegisters ) -> Self {
0 commit comments