Skip to content

Commit d62c09d

Browse files
committed
ARM: rename x86_64 crate to arch
Also, * move the autogenerated code in a different crate named `arch_sys` * x86_64 code code inside `arch` and `arch_sys` is labeled as such Signed-off-by: Diana Popa <[email protected]>
1 parent 497b4fe commit d62c09d

File tree

24 files changed

+320
-284
lines changed

24 files changed

+320
-284
lines changed

Cargo.lock

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kernel = { path = "../kernel" }
2626
memory_model = { path = "../memory_model" }
2727
net_util = { path = "../net_util" }
2828
rate_limiter = { path = "../rate_limiter" }
29-
x86_64 = { path = "../x86_64" }
29+
arch = { path = "../arch" }
3030

3131
[features]
3232
vsock = ["vmm/vsock"]

api_server/src/request/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ impl PartialEq for ParsedRequest {
9797

9898
#[cfg(test)]
9999
mod tests {
100+
extern crate arch;
100101
extern crate devices;
101102
extern crate kernel;
102103
extern crate memory_model;
103104
extern crate net_util;
104-
extern crate x86_64;
105105

106106
use self::devices::virtio::net::Error as VirtioNetError;
107107
use self::memory_model::GuestMemoryError;
@@ -299,7 +299,7 @@ mod tests {
299299
check_error_response(vmm_resp, StatusCode::InternalServerError);
300300
let vmm_resp = VmmActionError::StartMicrovm(
301301
ErrorKind::Internal,
302-
StartMicrovmError::ConfigureSystem(x86_64::Error::E820Configuration),
302+
StartMicrovmError::ConfigureSystem(arch::Error::ZeroPagePastRamEnd),
303303
);
304304
check_error_response(vmm_resp, StatusCode::InternalServerError);
305305
let vmm_resp = VmmActionError::StartMicrovm(

x86_64/Cargo.toml renamed to arch/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[package]
2-
name = "x86_64"
2+
name = "arch"
33
version = "0.1.0"
44
authors = ["The Chromium OS Authors"]
55

66
[dependencies]
77
byteorder = "=1.2.1"
88
libc = ">=0.2.39"
99

10-
kvm_gen = { path = "../kvm_gen" }
10+
arch_gen = { path = "../arch_gen" }
1111
kvm = { path = "../kvm" }
12+
kvm_gen = { path = "../kvm_gen" }
1213
memory_model = { path = "../memory_model" }
1314
sys_util = { path = "../sys_util" }
1415

arch/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
extern crate byteorder;
5+
extern crate libc;
6+
7+
extern crate arch_gen;
8+
extern crate kvm;
9+
extern crate kvm_gen;
10+
extern crate memory_model;
11+
extern crate sys_util;
12+
13+
use std::result;
14+
15+
#[derive(Debug)]
16+
pub enum Error {
17+
/// The zero page extends past the end of guest_mem.
18+
ZeroPagePastRamEnd,
19+
/// Error writing the zero page of guest memory.
20+
ZeroPageSetup,
21+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
22+
/// X86_64 specific error triggered during system configuration.
23+
X86_64Setup(x86_64::Error),
24+
}
25+
pub type Result<T> = result::Result<T, Error>;
26+
27+
// 1MB. We don't put anything above here except the kernel itself.
28+
pub const HIMEM_START: usize = 0x100000;
29+
30+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
31+
pub mod x86_64;
32+
impl From<x86_64::Error> for Error {
33+
fn from(e: x86_64::Error) -> Error {
34+
Error::X86_64Setup(e)
35+
}
36+
}
File renamed without changes.
File renamed without changes.

x86_64/src/lib.rs renamed to arch/src/x86_64/mod.rs

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,46 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8-
extern crate byteorder;
9-
extern crate kvm;
10-
extern crate kvm_gen;
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-
408
mod gdt;
419
pub mod interrupts;
42-
pub mod layout;
4310
mod mptable;
4411
pub mod regs;
4512

4613
use std::mem;
47-
use std::result;
4814

49-
use bootparam::boot_params;
50-
use bootparam::E820_RAM;
15+
use arch_gen::x86::bootparam::{boot_params, E820_RAM};
5116
use memory_model::{GuestAddress, GuestMemory};
5217

53-
pub use interrupts::Error as IntError;
54-
pub use mptable::Error as MpTableError;
55-
pub use regs::Error as RegError;
56-
5718
#[derive(Debug)]
5819
pub enum Error {
5920
/// Invalid e820 setup params.
6021
E820Configuration,
6122
/// 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,
23+
MpTableSetup(mptable::Error),
6724
}
68-
pub type Result<T> = result::Result<T, Error>;
25+
26+
// Magic addresses used to lay out x86_64 VMs.
27+
28+
// Initial stack for the boot CPU.
29+
pub const BOOT_STACK_POINTER: usize = 0x8ff0;
30+
31+
// Kernel command line.
32+
pub const CMDLINE_START: usize = 0x20000;
33+
pub const CMDLINE_MAX_SIZE: usize = 0x10000;
34+
35+
// The 'zero page', a.k.a linux kernel bootparams.
36+
pub const ZERO_PAGE_START: usize = 0x7000;
37+
38+
// Where BIOS/VGA magic would live on a real PC.
39+
const EBDA_START: u64 = 0x9fc00;
40+
41+
// MPTABLE, describing VCPUS.
42+
const MPTABLE_START: usize = 0x9fc00;
43+
44+
// Initial pagetables.
45+
const PDE_START: usize = 0xb000;
46+
const PDPTE_START: usize = 0xa000;
47+
const PML4_START: usize = 0x9000;
6948

7049
const FIRST_ADDR_PAST_32BITS: usize = (1 << 32);
7150
const MEM_32BIT_GAP_SIZE: usize = (768 << 20);
@@ -97,7 +76,6 @@ pub fn arch_memory_regions(size: usize) -> Vec<(GuestAddress, usize)> {
9776
}
9877

9978
/// X86 specific memory hole/ memory mapped devices/ reserved area.
100-
///
10179
pub fn get_32bit_gap_start() -> usize {
10280
FIRST_ADDR_PAST_32BITS - MEM_32BIT_GAP_SIZE
10381
}
@@ -115,15 +93,15 @@ pub fn configure_system(
11593
cmdline_addr: GuestAddress,
11694
cmdline_size: usize,
11795
num_cpus: u8,
118-
) -> Result<()> {
96+
) -> super::Result<()> {
11997
const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
12098
const KERNEL_HDR_MAGIC: u32 = 0x53726448;
12199
const KERNEL_LOADER_OTHER: u8 = 0xff;
122100
const KERNEL_MIN_ALIGNMENT_BYTES: u32 = 0x1000000; // Must be non-zero.
123101
let first_addr_past_32bits = GuestAddress(FIRST_ADDR_PAST_32BITS);
124102
let end_32bit_gap_start = GuestAddress(get_32bit_gap_start());
125103

126-
let himem_start = GuestAddress(layout::HIMEM_START);
104+
let himem_start = GuestAddress(super::HIMEM_START);
127105

128106
// Note that this puts the mptable at the last 1k of Linux's 640k base RAM
129107
mptable::setup_mptable(guest_mem, num_cpus).map_err(Error::MpTableSetup)?;
@@ -137,7 +115,7 @@ pub fn configure_system(
137115
params.hdr.cmdline_size = cmdline_size as u32;
138116
params.hdr.kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES;
139117

140-
add_e820_entry(&mut params, 0, layout::EBDA_START, E820_RAM)?;
118+
add_e820_entry(&mut params, 0, EBDA_START, E820_RAM)?;
141119

142120
let mem_end = guest_mem.end_addr();
143121
if mem_end < end_32bit_gap_start {
@@ -164,20 +142,25 @@ pub fn configure_system(
164142
}
165143
}
166144

167-
let zero_page_addr = GuestAddress(layout::ZERO_PAGE_START);
145+
let zero_page_addr = GuestAddress(ZERO_PAGE_START);
168146
guest_mem
169147
.checked_offset(zero_page_addr, mem::size_of::<boot_params>())
170-
.ok_or(Error::ZeroPagePastRamEnd)?;
148+
.ok_or(super::Error::ZeroPagePastRamEnd)?;
171149
guest_mem
172150
.write_obj_at_addr(params, zero_page_addr)
173-
.map_err(|_| Error::ZeroPageSetup)?;
151+
.map_err(|_| super::Error::ZeroPageSetup)?;
174152

175153
Ok(())
176154
}
177155

178156
/// Add an e820 region to the e820 map.
179157
/// 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<()> {
158+
fn add_e820_entry(
159+
params: &mut boot_params,
160+
addr: u64,
161+
size: u64,
162+
mem_type: u32,
163+
) -> Result<(), Error> {
181164
if params.e820_entries >= params.e820_map.len() as u8 {
182165
return Err(Error::E820Configuration);
183166
}
@@ -193,7 +176,7 @@ fn add_e820_entry(params: &mut boot_params, addr: u64, size: u64, mem_type: u32)
193176
#[cfg(test)]
194177
mod tests {
195178
use super::*;
196-
use bootparam::e820entry;
179+
use arch_gen::x86::bootparam::e820entry;
197180

198181
#[test]
199182
fn regions_lt_4gb() {
@@ -223,7 +206,12 @@ mod tests {
223206
fn test_system_configuration() {
224207
let no_vcpus = 4;
225208
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap();
226-
assert!(configure_system(&gm, GuestAddress(0), 0, 1).is_err());
209+
let config_err = configure_system(&gm, GuestAddress(0), 0, 1);
210+
assert!(config_err.is_err());
211+
assert_eq!(
212+
format!("{:?}", config_err),
213+
"Err(X86_64Setup(MpTableSetup(NotEnoughMemory)))"
214+
);
227215

228216
// Now assigning some memory that falls before the 32bit memory hole.
229217
let mem_size = 128 << 20;

0 commit comments

Comments
 (0)