Skip to content

Commit b5baa79

Browse files
committed
arm64: added memory layout representation
The code follows the memory address mapping of a 64-bit guest. Signed-off-by: Diana Popa <[email protected]>
1 parent 5fa0e34 commit b5baa79

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

arch/src/aarch64/layout.rs

+53
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
// ==== Address map in use in ARM development systems today ====
5+
//
6+
// - 32-bit - - 36-bit - - 40-bit -
7+
//1024GB + + +-------------------+ <- 40-bit
8+
// | | DRAM |
9+
// ~ ~ ~ ~
10+
// | | |
11+
// | | |
12+
// | | |
13+
// | | |
14+
//544GB + + +-------------------+
15+
// | | Hole or DRAM |
16+
// | | |
17+
//512GB + + +-------------------+
18+
// | | Mapped |
19+
// | | I/O |
20+
// ~ ~ ~ ~
21+
// | | |
22+
//256GB + + +-------------------+
23+
// | | Reserved |
24+
// ~ ~ ~ ~
25+
// | | |
26+
//64GB + +-----------------------+-------------------+ <- 36-bit
27+
// | | DRAM |
28+
// ~ ~ ~ ~
29+
// | | |
30+
// | | |
31+
//34GB + +-----------------------+-------------------+
32+
// | | Hole or DRAM |
33+
//32GB + +-----------------------+-------------------+
34+
// | | Mapped I/O |
35+
// ~ ~ ~ ~
36+
// | | |
37+
//16GB + +-----------------------+-------------------+
38+
// | | Reserved |
39+
// ~ ~ ~ ~
40+
//4GB +-------------------+-----------------------+-------------------+ <- 32-bit
41+
// | 2GB of DRAM |
42+
// | |
43+
//2GB +-------------------+-----------------------+-------------------+
44+
// | Mapped I/O |
45+
//1GB +-------------------+-----------------------+-------------------+
46+
// | ROM & RAM & I/O |
47+
//0GB +-------------------+-----------------------+-------------------+ 0
48+
// - 32-bit - - 36-bit - - 40-bit -
49+
//
50+
// Taken from (http://infocenter.arm.com/help/topic/com.arm.doc.den0001c/DEN0001C_principles_of_arm_memory_maps.pdf).
51+
52+
/// Start of RAM on 64 bit ARM.
53+
pub const DRAM_MEM_START: usize = 0x80000000; // 2 GB.
54+
/// The maximum addressable RAM address.
55+
pub const DRAM_MEM_END: usize = 0xFF80000000; // 1024 - 2 = 1022 GB.
56+
457
/// Kernel command line start address.
558
pub const CMDLINE_START: usize = 0x0;
659
/// Kernel command line start address maximum size.

arch/src/aarch64/mod.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
pub mod layout;
55

6+
use std::cmp::min;
7+
68
use memory_model::{GuestAddress, GuestMemory};
79

8-
/// Stub function that needs to be implemented when aarch64 functionality is added.
10+
/// Returns a Vec of the valid memory addresses for aarch64
11+
/// See `layout` module for a drawing of the specific memory model for this platform.
912
pub fn arch_memory_regions(size: usize) -> Vec<(GuestAddress, usize)> {
10-
vec![(GuestAddress(0), size)]
13+
let dram_size = min(size, layout::DRAM_MEM_END);
14+
vec![(GuestAddress(layout::DRAM_MEM_START), dram_size)]
1115
}
1216

1317
/// Stub function that needs to be implemented when aarch64 functionality is added.
@@ -24,3 +28,24 @@ pub fn configure_system(
2428
pub fn get_reserved_mem_addr() -> usize {
2529
0
2630
}
31+
32+
#[cfg(test)]
33+
mod tests {
34+
use super::*;
35+
36+
#[test]
37+
fn regions_lt_1024gb() {
38+
let regions = arch_memory_regions(1usize << 29);
39+
assert_eq!(1, regions.len());
40+
assert_eq!(GuestAddress(super::layout::DRAM_MEM_START), regions[0].0);
41+
assert_eq!(1usize << 29, regions[0].1);
42+
}
43+
44+
#[test]
45+
fn regions_gt_1024gb() {
46+
let regions = arch_memory_regions(1usize << 41);
47+
assert_eq!(1, regions.len());
48+
assert_eq!(GuestAddress(super::layout::DRAM_MEM_START), regions[0].0);
49+
assert_eq!(super::layout::DRAM_MEM_END, regions[0].1);
50+
}
51+
}

0 commit comments

Comments
 (0)