Skip to content

Commit e77ecb8

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

File tree

23 files changed

+276
-237
lines changed

23 files changed

+276
-237
lines changed

Cargo.lock

Lines changed: 23 additions & 15 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
@@ -21,12 +21,12 @@ sys_util = { path = "../sys_util" }
2121
vmm = { path = "../vmm" }
2222

2323
[dev-dependencies]
24+
arch = { path = "../arch" }
2425
devices = { path = "../devices" }
2526
kernel = { path = "../kernel" }
2627
memory_model = { path = "../memory_model" }
2728
net_util = { path = "../net_util" }
2829
rate_limiter = { path = "../rate_limiter" }
29-
x86_64 = { path = "../x86_64" }
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;
@@ -300,7 +300,7 @@ mod tests {
300300
check_error_response(vmm_resp, StatusCode::InternalServerError);
301301
let vmm_resp = VmmActionError::StartMicrovm(
302302
ErrorKind::Internal,
303-
StartMicrovmError::ConfigureSystem(x86_64::Error::E820Configuration),
303+
StartMicrovmError::ConfigureSystem(arch::Error::ZeroPagePastRamEnd),
304304
);
305305
check_error_response(vmm_resp, StatusCode::InternalServerError);
306306
let vmm_resp = VmmActionError::StartMicrovm(

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

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

@@ -8,6 +8,7 @@ byteorder = "=1.2.1"
88
kvm_wrapper = ">=0.1.0"
99
libc = ">=0.2.39"
1010

11+
arch_gen = { path = "../arch_gen" }
1112
kvm = { path = "../kvm" }
1213
memory_model = { path = "../memory_model" }
1314
sys_util = { path = "../sys_util" }

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 kvm_wrapper;
6+
extern crate libc;
7+
8+
extern crate arch_gen;
9+
extern crate kvm;
10+
extern crate memory_model;
11+
extern crate sys_util;
12+
13+
use std::result;
14+
15+
#[derive(Debug, PartialEq)]
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(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(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.

arch/src/x86_64/layout.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
5+
// Use of this source code is governed by a BSD-style license that can be
6+
// found in the THIRD-PARTY file.
7+
8+
/// Magic addresses externally used to lay out x86_64 VMs.
9+
10+
/// Initial stack for the boot CPU.
11+
pub const BOOT_STACK_START: usize = 0x8000;
12+
pub const BOOT_STACK_POINTER: usize = 0x8ff0;
13+
14+
/// Kernel command line start address.
15+
pub const CMDLINE_START: usize = 0x20000;
16+
/// Kernel command line start address maximum size.
17+
pub const CMDLINE_MAX_SIZE: usize = 0x10000;
18+
19+
/// The 'zero page', a.k.a linux kernel bootparams.
20+
pub const ZERO_PAGE_START: usize = 0x7000;

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

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,29 @@
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_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-
408
mod gdt;
419
pub mod interrupts;
4210
pub mod layout;
4311
mod mptable;
4412
pub mod regs;
4513

4614
use std::mem;
47-
use std::result;
4815

49-
use bootparam::boot_params;
50-
use bootparam::E820_RAM;
16+
use arch_gen::x86::bootparam::{boot_params, E820_RAM};
5117
use memory_model::{GuestAddress, GuestMemory};
5218

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);
5623

57-
#[derive(Debug)]
24+
#[derive(Debug, PartialEq)]
5825
pub enum Error {
5926
/// Invalid e820 setup params.
6027
E820Configuration,
6128
/// 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),
6730
}
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);
7231

7332
/// Returns a Vec of the valid memory addresses.
7433
/// 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)> {
9655
regions
9756
}
9857

99-
/// X86 specific memory hole/ memory mapped devices/ reserved area.
100-
///
58+
/// X86 specific memory hole/memory mapped devices/reserved area.
10159
pub fn get_32bit_gap_start() -> usize {
10260
FIRST_ADDR_PAST_32BITS - MEM_32BIT_GAP_SIZE
10361
}
@@ -115,15 +73,15 @@ pub fn configure_system(
11573
cmdline_addr: GuestAddress,
11674
cmdline_size: usize,
11775
num_cpus: u8,
118-
) -> Result<()> {
76+
) -> super::Result<()> {
11977
const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
12078
const KERNEL_HDR_MAGIC: u32 = 0x53726448;
12179
const KERNEL_LOADER_OTHER: u8 = 0xff;
12280
const KERNEL_MIN_ALIGNMENT_BYTES: u32 = 0x1000000; // Must be non-zero.
12381
let first_addr_past_32bits = GuestAddress(FIRST_ADDR_PAST_32BITS);
12482
let end_32bit_gap_start = GuestAddress(get_32bit_gap_start());
12583

126-
let himem_start = GuestAddress(layout::HIMEM_START);
84+
let himem_start = GuestAddress(super::HIMEM_START);
12785

12886
// Note that this puts the mptable at the last 1k of Linux's 640k base RAM
12987
mptable::setup_mptable(guest_mem, num_cpus).map_err(Error::MpTableSetup)?;
@@ -137,7 +95,7 @@ pub fn configure_system(
13795
params.hdr.cmdline_size = cmdline_size as u32;
13896
params.hdr.kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES;
13997

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

142100
let mem_end = guest_mem.end_addr();
143101
if mem_end < end_32bit_gap_start {
@@ -167,17 +125,22 @@ pub fn configure_system(
167125
let zero_page_addr = GuestAddress(layout::ZERO_PAGE_START);
168126
guest_mem
169127
.checked_offset(zero_page_addr, mem::size_of::<boot_params>())
170-
.ok_or(Error::ZeroPagePastRamEnd)?;
128+
.ok_or(super::Error::ZeroPagePastRamEnd)?;
171129
guest_mem
172130
.write_obj_at_addr(params, zero_page_addr)
173-
.map_err(|_| Error::ZeroPageSetup)?;
131+
.map_err(|_| super::Error::ZeroPageSetup)?;
174132

175133
Ok(())
176134
}
177135

178136
/// Add an e820 region to the e820 map.
179137
/// 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> {
181144
if params.e820_entries >= params.e820_map.len() as u8 {
182145
return Err(Error::E820Configuration);
183146
}
@@ -193,7 +156,7 @@ fn add_e820_entry(params: &mut boot_params, addr: u64, size: u64, mem_type: u32)
193156
#[cfg(test)]
194157
mod tests {
195158
use super::*;
196-
use bootparam::e820entry;
159+
use arch_gen::x86::bootparam::e820entry;
197160

198161
#[test]
199162
fn regions_lt_4gb() {
@@ -223,7 +186,14 @@ mod tests {
223186
fn test_system_configuration() {
224187
let no_vcpus = 4;
225188
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+
);
227197

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

0 commit comments

Comments
 (0)