5
5
// Use of this source code is governed by a BSD-style license that can be
6
6
// found in the THIRD-PARTY file.
7
7
8
- extern crate byteorder;
9
- extern crate kvm;
10
- extern crate kvm_wrapper;
11
- extern crate libc;
12
- extern crate memory_model;
13
- extern crate sys_util;
14
-
15
- #[ allow( dead_code) ]
16
- #[ allow( non_upper_case_globals) ]
17
- #[ allow( non_camel_case_types) ]
18
- #[ allow( non_snake_case) ]
19
- mod bootparam;
20
- // boot_params is just a series of ints, it is safe to initialize it.
21
- unsafe impl memory_model:: DataInit for bootparam:: boot_params { }
22
-
23
- #[ allow( dead_code) ]
24
- #[ allow( non_upper_case_globals) ]
25
- mod msr_index;
26
-
27
- #[ allow( dead_code) ]
28
- #[ allow( non_upper_case_globals) ]
29
- #[ allow( non_camel_case_types) ]
30
- mod mpspec;
31
- // These mpspec types are only data, reading them from data is a safe initialization.
32
- unsafe impl memory_model:: DataInit for mpspec:: mpc_bus { }
33
- unsafe impl memory_model:: DataInit for mpspec:: mpc_cpu { }
34
- unsafe impl memory_model:: DataInit for mpspec:: mpc_intsrc { }
35
- unsafe impl memory_model:: DataInit for mpspec:: mpc_ioapic { }
36
- unsafe impl memory_model:: DataInit for mpspec:: mpc_table { }
37
- unsafe impl memory_model:: DataInit for mpspec:: mpc_lintsrc { }
38
- unsafe impl memory_model:: DataInit for mpspec:: mpf_intel { }
39
-
40
8
mod gdt;
41
9
pub mod interrupts;
42
10
pub mod layout;
43
11
mod mptable;
44
12
pub mod regs;
45
13
46
14
use std:: mem;
47
- use std:: result;
48
15
49
- use bootparam:: boot_params;
50
- use bootparam:: E820_RAM ;
16
+ use arch_gen:: x86:: bootparam:: { boot_params, E820_RAM } ;
51
17
use memory_model:: { GuestAddress , GuestMemory } ;
52
18
53
- pub use interrupts:: Error as IntError ;
54
- pub use mptable:: Error as MpTableError ;
55
- pub use regs:: Error as RegError ;
19
+ // Where BIOS/VGA magic would live on a real PC.
20
+ const EBDA_START : u64 = 0x9fc00 ;
21
+ const FIRST_ADDR_PAST_32BITS : usize = ( 1 << 32 ) ;
22
+ const MEM_32BIT_GAP_SIZE : usize = ( 768 << 20 ) ;
56
23
57
- #[ derive( Debug ) ]
24
+ #[ derive( Debug , PartialEq ) ]
58
25
pub enum Error {
59
26
/// Invalid e820 setup params.
60
27
E820Configuration ,
61
28
/// Error writing MP table to memory.
62
- MpTableSetup ( MpTableError ) ,
63
- /// The zero page extends past the end of guest_mem.
64
- ZeroPagePastRamEnd ,
65
- /// Error writing the zero page of guest memory.
66
- ZeroPageSetup ,
29
+ MpTableSetup ( mptable:: Error ) ,
67
30
}
68
- pub type Result < T > = result:: Result < T , Error > ;
69
-
70
- const FIRST_ADDR_PAST_32BITS : usize = ( 1 << 32 ) ;
71
- const MEM_32BIT_GAP_SIZE : usize = ( 768 << 20 ) ;
72
31
73
32
/// Returns a Vec of the valid memory addresses.
74
33
/// These should be used to configure the GuestMemory structure for the platform.
@@ -96,8 +55,7 @@ pub fn arch_memory_regions(size: usize) -> Vec<(GuestAddress, usize)> {
96
55
regions
97
56
}
98
57
99
- /// X86 specific memory hole/ memory mapped devices/ reserved area.
100
- ///
58
+ /// X86 specific memory hole/memory mapped devices/reserved area.
101
59
pub fn get_32bit_gap_start ( ) -> usize {
102
60
FIRST_ADDR_PAST_32BITS - MEM_32BIT_GAP_SIZE
103
61
}
@@ -115,15 +73,15 @@ pub fn configure_system(
115
73
cmdline_addr : GuestAddress ,
116
74
cmdline_size : usize ,
117
75
num_cpus : u8 ,
118
- ) -> Result < ( ) > {
76
+ ) -> super :: Result < ( ) > {
119
77
const KERNEL_BOOT_FLAG_MAGIC : u16 = 0xaa55 ;
120
78
const KERNEL_HDR_MAGIC : u32 = 0x53726448 ;
121
79
const KERNEL_LOADER_OTHER : u8 = 0xff ;
122
80
const KERNEL_MIN_ALIGNMENT_BYTES : u32 = 0x1000000 ; // Must be non-zero.
123
81
let first_addr_past_32bits = GuestAddress ( FIRST_ADDR_PAST_32BITS ) ;
124
82
let end_32bit_gap_start = GuestAddress ( get_32bit_gap_start ( ) ) ;
125
83
126
- let himem_start = GuestAddress ( layout :: HIMEM_START ) ;
84
+ let himem_start = GuestAddress ( super :: HIMEM_START ) ;
127
85
128
86
// Note that this puts the mptable at the last 1k of Linux's 640k base RAM
129
87
mptable:: setup_mptable ( guest_mem, num_cpus) . map_err ( Error :: MpTableSetup ) ?;
@@ -137,7 +95,7 @@ pub fn configure_system(
137
95
params. hdr . cmdline_size = cmdline_size as u32 ;
138
96
params. hdr . kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES ;
139
97
140
- add_e820_entry ( & mut params, 0 , layout :: EBDA_START , E820_RAM ) ?;
98
+ add_e820_entry ( & mut params, 0 , EBDA_START , E820_RAM ) ?;
141
99
142
100
let mem_end = guest_mem. end_addr ( ) ;
143
101
if mem_end < end_32bit_gap_start {
@@ -167,17 +125,22 @@ pub fn configure_system(
167
125
let zero_page_addr = GuestAddress ( layout:: ZERO_PAGE_START ) ;
168
126
guest_mem
169
127
. checked_offset ( zero_page_addr, mem:: size_of :: < boot_params > ( ) )
170
- . ok_or ( Error :: ZeroPagePastRamEnd ) ?;
128
+ . ok_or ( super :: Error :: ZeroPagePastRamEnd ) ?;
171
129
guest_mem
172
130
. write_obj_at_addr ( params, zero_page_addr)
173
- . map_err ( |_| Error :: ZeroPageSetup ) ?;
131
+ . map_err ( |_| super :: Error :: ZeroPageSetup ) ?;
174
132
175
133
Ok ( ( ) )
176
134
}
177
135
178
136
/// Add an e820 region to the e820 map.
179
137
/// Returns Ok(()) if successful, or an error if there is no space left in the map.
180
- fn add_e820_entry ( params : & mut boot_params , addr : u64 , size : u64 , mem_type : u32 ) -> Result < ( ) > {
138
+ fn add_e820_entry (
139
+ params : & mut boot_params ,
140
+ addr : u64 ,
141
+ size : u64 ,
142
+ mem_type : u32 ,
143
+ ) -> Result < ( ) , Error > {
181
144
if params. e820_entries >= params. e820_map . len ( ) as u8 {
182
145
return Err ( Error :: E820Configuration ) ;
183
146
}
@@ -193,7 +156,7 @@ fn add_e820_entry(params: &mut boot_params, addr: u64, size: u64, mem_type: u32)
193
156
#[ cfg( test) ]
194
157
mod tests {
195
158
use super :: * ;
196
- use bootparam:: e820entry;
159
+ use arch_gen :: x86 :: bootparam:: e820entry;
197
160
198
161
#[ test]
199
162
fn regions_lt_4gb ( ) {
@@ -223,7 +186,14 @@ mod tests {
223
186
fn test_system_configuration ( ) {
224
187
let no_vcpus = 4 ;
225
188
let gm = GuestMemory :: new ( & vec ! [ ( GuestAddress ( 0 ) , 0x10000 ) ] ) . unwrap ( ) ;
226
- assert ! ( configure_system( & gm, GuestAddress ( 0 ) , 0 , 1 ) . is_err( ) ) ;
189
+ let config_err = configure_system ( & gm, GuestAddress ( 0 ) , 0 , 1 ) ;
190
+ assert ! ( config_err. is_err( ) ) ;
191
+ assert_eq ! (
192
+ config_err. unwrap_err( ) ,
193
+ super :: super :: Error :: X86_64Setup ( super :: Error :: MpTableSetup (
194
+ mptable:: Error :: NotEnoughMemory
195
+ ) )
196
+ ) ;
227
197
228
198
// Now assigning some memory that falls before the 32bit memory hole.
229
199
let mem_size = 128 << 20 ;
0 commit comments