Skip to content

Commit 02b0802

Browse files
authored
Merge pull request #17 from google/pagetable
Allow initial MAIR, TCR and SCTLR values to be specified.
2 parents 76b1699 + 442899c commit 02b0802

File tree

7 files changed

+232
-203
lines changed

7 files changed

+232
-203
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Improvements
6+
7+
- Added optional parameters to `initial_pagetable!` to allow initial MAIR, TCR and SCTLR values to
8+
be specified. The default values are exposed as constants.
9+
310
## 0.2.1
411

512
### Bugfixes

examples/qemu_el1.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#![no_std]
88
#![no_main]
99

10-
use aarch64_paging::paging::Attributes;
10+
use aarch64_paging::{
11+
mair::{Mair, MairAttribute, NormalMemory},
12+
paging::Attributes,
13+
};
1114
use aarch64_rt::{InitialPagetable, entry, initial_pagetable};
1215
use arm_pl011_uart::{PL011Registers, Uart, UniqueMmioPointer};
1316
use core::{fmt::Write, panic::PanicInfo, ptr::NonNull};
@@ -32,16 +35,33 @@ const MEMORY_ATTRIBUTES: Attributes = Attributes::VALID
3235
.union(Attributes::ACCESSED)
3336
.union(Attributes::NON_GLOBAL);
3437

35-
initial_pagetable!({
36-
let mut idmap = [0; 512];
37-
// 1 GiB of device memory.
38-
idmap[0] = DEVICE_ATTRIBUTES.bits();
39-
// 1 GiB of normal memory.
40-
idmap[1] = MEMORY_ATTRIBUTES.bits() | 0x40000000;
41-
// Another 1 GiB of device memory starting at 256 GiB.
42-
idmap[256] = DEVICE_ATTRIBUTES.bits() | 0x4000000000;
43-
InitialPagetable(idmap)
44-
});
38+
/// Indirect memory attributes to use.
39+
///
40+
/// These are used for `ATTRIBUTE_INDEX_0` and `ATTRIBUTE_INDEX_1` in `DEVICE_ATTRIBUTES` and
41+
/// `MEMORY_ATTRIBUTES` respectively.
42+
const MAIR: Mair = Mair::EMPTY
43+
.with_attribute(0, MairAttribute::DEVICE_NGNRE)
44+
.with_attribute(
45+
1,
46+
MairAttribute::normal(
47+
NormalMemory::WriteBackNonTransientReadWriteAllocate,
48+
NormalMemory::WriteBackNonTransientReadWriteAllocate,
49+
),
50+
);
51+
52+
initial_pagetable!(
53+
{
54+
let mut idmap = [0; 512];
55+
// 1 GiB of device memory.
56+
idmap[0] = DEVICE_ATTRIBUTES.bits();
57+
// 1 GiB of normal memory.
58+
idmap[1] = MEMORY_ATTRIBUTES.bits() | 0x40000000;
59+
// Another 1 GiB of device memory starting at 256 GiB.
60+
idmap[256] = DEVICE_ATTRIBUTES.bits() | 0x4000000000;
61+
InitialPagetable(idmap)
62+
},
63+
MAIR.0
64+
);
4565

4666
entry!(main);
4767
fn main(arg0: u64, arg1: u64, arg2: u64, arg3: u64) -> ! {

src/el1_enable_mmu.S

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/el2_enable_mmu.S

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/el3_enable_mmu.S

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod pagetable;
2222
use core::arch::asm;
2323
use core::arch::global_asm;
2424
#[cfg(feature = "initial-pagetable")]
25-
pub use pagetable::InitialPagetable;
25+
pub use pagetable::{DEFAULT_MAIR, DEFAULT_SCTLR, DEFAULT_TCR, InitialPagetable};
2626

2727
global_asm!(include_str!("entry.S"));
2828

0 commit comments

Comments
 (0)