Skip to content

Commit 741bfa4

Browse files
committed
arch/aarch64: Implement paging
This commit adds initial paging support for aarch64. This implementation creates identity mapping translation tables for Cloud Hypervisor. The most of paging implementation is based on [1]. It also introduces use of `asm_const` [2] to parameterize FDT base address and stack base address. [1] https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/10_virtual_mem_part1_identity_mapping [2] rust-lang/rust#93332 Signed-off-by: Akira Moroo <retrage01@gmail.com>
1 parent e4f99ae commit 741bfa4

File tree

9 files changed

+653
-3
lines changed

9 files changed

+653
-3
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ atomic_refcell = "0.1.8"
3131
r-efi = "4.1.0"
3232
linked_list_allocator = "0.10.3"
3333

34+
[target.'cfg(target_arch = "aarch64")'.dependencies]
35+
tock-registers = "0.8.1"
36+
cortex-a = "8.0.0"
37+
3438
[target.'cfg(target_arch = "x86_64")'.dependencies]
3539
uart_16550 = "0.2.18"
3640
x86_64 = "0.14.10"

src/arch/aarch64/asm.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2022 Akira Moroo
33

4+
use super::layout::map;
45
use core::arch::global_asm;
56

6-
global_asm!(include_str!("ram64.s"));
7+
global_asm!(include_str!("ram64.s"),
8+
FDT_START = const map::dram::FDT_START,
9+
STACK_END = const map::dram::STACK_END);

src/arch/aarch64/layout.rs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2022 Akira Moroo
3+
// Copyright (c) 2021-2022 Andre Richter <andre.o.richter@gmail.com>
4+
5+
use core::ops::RangeInclusive;
6+
7+
use super::paging::*;
8+
9+
pub mod map {
10+
pub const END: usize = 0x1_0000_0000;
11+
12+
pub mod fw {
13+
pub const START: usize = 0x0000_0000;
14+
pub const END: usize = 0x0040_0000;
15+
}
16+
pub mod mmio {
17+
pub const START: usize = super::fw::END;
18+
pub const PL011_START: usize = 0x0900_0000;
19+
pub const PL031_START: usize = 0x0901_0000;
20+
pub const END: usize = 0x4000_0000;
21+
}
22+
23+
pub mod dram {
24+
const FDT_SIZE: usize = 0x0020_0000;
25+
const ACPI_SIZE: usize = 0x0020_0000;
26+
pub const STACK_SIZE: usize = 0x0800_0000;
27+
28+
pub const START: usize = super::mmio::END;
29+
pub const FDT_START: usize = START;
30+
pub const ACPI_START: usize = FDT_START + FDT_SIZE;
31+
pub const KERNEL_START: usize = ACPI_START + ACPI_SIZE;
32+
pub const STACK_START: usize = STACK_END - STACK_SIZE;
33+
pub const STACK_END: usize = RESERVED_START;
34+
pub const RESERVED_START: usize = 0xfc00_0000;
35+
pub const END: usize = super::END;
36+
}
37+
}
38+
39+
pub type KernelAddrSpace = AddressSpace<{ map::END }>;
40+
41+
const NUM_MEM_RANGES: usize = 3;
42+
43+
pub static LAYOUT: KernelVirtualLayout<NUM_MEM_RANGES> = KernelVirtualLayout::new(
44+
map::END - 1,
45+
[
46+
TranslationDescriptor {
47+
name: "Firmware",
48+
virtual_range: RangeInclusive::new(map::fw::START, map::fw::END - 1),
49+
physical_range_translation: Translation::Identity,
50+
attribute_fields: AttributeFields {
51+
mem_attributes: MemAttributes::CacheableDRAM,
52+
acc_perms: AccessPermissions::ReadWrite,
53+
execute_never: false,
54+
},
55+
},
56+
TranslationDescriptor {
57+
name: "Device MMIO",
58+
virtual_range: RangeInclusive::new(map::mmio::START, map::mmio::END - 1),
59+
physical_range_translation: Translation::Identity,
60+
attribute_fields: AttributeFields {
61+
mem_attributes: MemAttributes::Device,
62+
acc_perms: AccessPermissions::ReadWrite,
63+
execute_never: true,
64+
},
65+
},
66+
TranslationDescriptor {
67+
name: "System Memory",
68+
virtual_range: RangeInclusive::new(map::dram::START, map::dram::END - 1),
69+
physical_range_translation: Translation::Identity,
70+
attribute_fields: AttributeFields {
71+
mem_attributes: MemAttributes::CacheableDRAM,
72+
acc_perms: AccessPermissions::ReadWrite, // FIXME
73+
execute_never: false,
74+
},
75+
},
76+
],
77+
);
78+
79+
pub fn virt_mem_layout() -> &'static KernelVirtualLayout<NUM_MEM_RANGES> {
80+
&LAYOUT
81+
}

src/arch/aarch64/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
#[cfg(not(test))]
55
pub mod asm;
6+
pub mod layout;
7+
pub mod paging;
8+
mod translation;

0 commit comments

Comments
 (0)