Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 0bbd3d4

Browse files
authored
More regs (#45)
* Add the ID_AA64MMFR1_EL1 register * Add the VTCR_EL2 register * Add support for hardware dirty and access flags in TCR_ELx * Add support for FEAT_S2FWB in HCR_EL2 * Add support for implict synchronization in SCTLR * Add the VTTBR_EL2 register
1 parent 1b89998 commit 0bbd3d4

File tree

8 files changed

+344
-0
lines changed

8 files changed

+344
-0
lines changed

src/registers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod fp;
3737
mod hcr_el2;
3838
mod id_aa64mmfr0_el1;
3939
mod id_aa64isar0_el1;
40+
mod id_aa64mmfr1_el1;
4041
mod id_aa64mmfr2_el1;
4142
mod lr;
4243
mod mair_el1;
@@ -65,6 +66,8 @@ mod ttbr0_el2;
6566
mod ttbr1_el1;
6667
mod vbar_el1;
6768
mod vbar_el2;
69+
mod vtcr_el2;
70+
mod vttbr_el2;
6871

6972
pub use actlr_el1::ACTLR_EL1;
7073
pub use actlr_el2::ACTLR_EL2;
@@ -97,6 +100,7 @@ pub use fp::FP;
97100
pub use hcr_el2::HCR_EL2;
98101
pub use id_aa64mmfr0_el1::ID_AA64MMFR0_EL1;
99102
pub use id_aa64isar0_el1::ID_AA64ISAR0_EL1;
103+
pub use id_aa64mmfr1_el1::ID_AA64MMFR1_EL1;
100104
pub use id_aa64mmfr2_el1::ID_AA64MMFR2_EL1;
101105
pub use lr::LR;
102106
pub use mair_el1::MAIR_EL1;
@@ -125,3 +129,5 @@ pub use ttbr0_el2::TTBR0_EL2;
125129
pub use ttbr1_el1::TTBR1_EL1;
126130
pub use vbar_el1::VBAR_EL1;
127131
pub use vbar_el2::VBAR_EL2;
132+
pub use vtcr_el2::VTCR_EL2;
133+
pub use vttbr_el2::VTTBR_EL2;

src/registers/hcr_el2.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ use tock_registers::{
1919

2020
register_bitfields! {u64,
2121
pub HCR_EL2 [
22+
/// When FEAT_S2FWB is implemented Forced Write-back changes the combined cachability of stage1
23+
/// and stage2 attributes
24+
FWB OFFSET(46) NUMBITS(1) [
25+
/// Stage2 memory type and cacheability attributes are in bits[5:2] of the stage2 PTE
26+
Disabled = 0,
27+
/// Stage1 memory type can be overridden by Stage2 descriptor
28+
Enabled = 1,
29+
],
30+
2231
/// Controls the use of instructions related to Pointer Authentication:
2332
///
2433
/// - In EL0, when HCR_EL2.TGE==0 or HCR_EL2.E2H==0, and the associated SCTLR_EL1.En<N><M>==1.

src/registers/id_aa64mmfr1_el1.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
//
3+
// Copyright (c) 2018-2022 by the author(s)
4+
//
5+
// Author(s):
6+
// - Ali Saidi <[email protected]>
7+
8+
//! AArch64 Memory Model Feature Register 1 - EL1
9+
//!
10+
//! Provides information about the implemented memory model and memory
11+
//! management support in AArch64 state.
12+
13+
use tock_registers::{interfaces::Readable, register_bitfields};
14+
15+
register_bitfields! {u64,
16+
pub ID_AA64MMFR1_EL1 [
17+
/// Support for configurable trapping delay of WFE instructions
18+
TWED OFFSET(32) NUMBITS(4) [
19+
/// Delaying the trapping of WFE instructions isn't supported
20+
Unsupported = 0b0000,
21+
/// Delaying the trapping of WFE instructions is supported
22+
Supported = 0xb0001,
23+
],
24+
25+
/// Execute-never control at stage2 is distinct for EL0 and EL1
26+
XNX OFFSET(28) NUMBITS(4) [
27+
/// There are not distinct stage2 execute never controls for EL1 and EL0
28+
Unsupported = 0b0000,
29+
/// There are distinct stage2 execute never controls for EL1 and EL0
30+
Supported = 0xb0001,
31+
],
32+
33+
/// Speculative reads can generate SError Interrupts
34+
SpecSEI OFFSET(24) NUMBITS(4) [
35+
/// PE never generates SError interrupts on a speculative read
36+
Never = 0b0000,
37+
/// PE may generate SError interrupts on a speculative read
38+
Maybe = 0b0001
39+
],
40+
41+
/// Privileged Access Never support
42+
PAN OFFSET(20) NUMBITS(4) [
43+
/// Privileged Access Never isn't supported
44+
Unsupported = 0b0000,
45+
/// Privileged Access Never is supported
46+
Supported = 0xb0001,
47+
/// Privileged Access Never is supported along with AT instruction support
48+
SupportedAT = 0xb0010,
49+
/// Enhanced Privileged Access Never is supported
50+
SupportedEPAN = 0xb0011,
51+
],
52+
53+
/// Limited Ordered regions support
54+
LO OFFSET(16) NUMBITS(4) [
55+
/// Limited Ordered regions aren't supported
56+
Unsupported = 0b0000,
57+
/// Limited Ordered regions are supported
58+
Supported = 0xb0001,
59+
],
60+
61+
/// Hierarchical Permission can be disabled in TCRs
62+
HPDS OFFSET(12) NUMBITS(4) [
63+
/// HPDS aren't supported
64+
Unsupported = 0b0000,
65+
/// HPDS are supported
66+
Supported = 0xb0001,
67+
],
68+
69+
/// Virtualization Host Extensions
70+
VH OFFSET(8) NUMBITS(4) [
71+
/// Virtualization Host Extensions aren't supported
72+
Unsupported = 0b0000,
73+
/// Virtualization Host Extensions are supported
74+
Supported = 0xb0001,
75+
],
76+
77+
/// Number of VMID bits that are supported
78+
VMIDBits OFFSET(4) NUMBITS(4) [
79+
/// 8 bits of VMID are supported
80+
Bits8 = 0b0000,
81+
/// 16 bits of VMID are supported
82+
Bits16 = 0b0010,
83+
],
84+
85+
/// Hardware updates to Access and Dirty flags in translation tables
86+
HAFDBS OFFSET(0) NUMBITS(4) [
87+
/// Not supported
88+
Unsupported = 0b0000,
89+
/// Access flag is supported
90+
AccessOnly = 0xb0001,
91+
/// Access and dirty flags are supported
92+
AccessDirty = 0b0010,
93+
],
94+
]
95+
}
96+
97+
pub struct Reg;
98+
99+
impl Readable for Reg {
100+
type T = u64;
101+
type R = ID_AA64MMFR1_EL1::Register;
102+
103+
sys_coproc_read_raw!(u64, "ID_AA64MMFR1_EL1", "x");
104+
}
105+
106+
pub const ID_AA64MMFR1_EL1: Reg = Reg;

src/registers/sctlr_el2.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ register_bitfields! {u64,
2727
Big = 1
2828
],
2929

30+
/// When FEAT_ExS is implemented control if taking an exception to EL2 is a context
31+
/// synchonizing event
32+
EIS OFFSET(22) NUMBITS(1) [
33+
IsNotSynch = 0,
34+
IsSynch = 1
35+
],
36+
37+
/// When FEAT_IESB is implemented control if an implict ESB is added at each exception
38+
/// and before each ERET to/from EL2
39+
IESB OFFSET(21) NUMBITS(1) [
40+
Disable = 0,
41+
Enable = 1
42+
],
43+
3044
/// Force treatment of all memory regions with write permissions as XN.
3145
/// The possible values are:
3246
///

src/registers/tcr_el1.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ register_bitfields! {u64,
3636
/// Reserved, RES0.
3737
TBID0 OFFSET(51) NUMBITS(1) [],
3838

39+
/// When FEAT_HAFDBS is implemented hardware can update the dirty flags in the stage1
40+
/// descriptors
41+
HD OFFSET(40) NUMBITS(1) [
42+
Disable = 0,
43+
Enable = 1,
44+
],
45+
46+
/// When FEAT_HAFDBS is implemented hardware can update the access flags in the stage1
47+
/// descriptors
48+
HA OFFSET(39) NUMBITS(1) [
49+
Disable = 0,
50+
Enable = 1,
51+
],
52+
3953
/// Top Byte ignored - indicates whether the top byte of an address is used for address
4054
/// match for the TTBR1_EL1 region, or ignored and used for tagged addresses. Defined values
4155
/// are:

src/registers/tcr_el2.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ use tock_registers::{
1818
register_bitfields! {u64,
1919
pub TCR_EL2 [
2020

21+
/// When FEAT_HAFDBS is implemented hardware can update the dirty flags in the stage1
22+
/// descriptors
23+
HD OFFSET(22) NUMBITS(1) [
24+
Disable = 0,
25+
Enable = 1,
26+
],
27+
28+
/// When FEAT_HAFDBS is implemented hardware can update the access flags in the stage1
29+
/// descriptors
30+
HA OFFSET(21) NUMBITS(1) [
31+
Disable = 0,
32+
Enable = 1,
33+
],
34+
2135
/// Top Byte ignored - indicates whether the top byte of an address is used for address
2236
/// match for the TTBR0_EL2 region, or ignored and used for tagged addresses. Defined values
2337
/// are:

src/registers/vtcr_el2.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
//
3+
// Copyright (c) 2018-2022 by the author(s)
4+
//
5+
// Author(s):
6+
// - Ali Saidi <[email protected]>
7+
8+
//! Virtualization Translation Control Register - EL2
9+
//!
10+
//! Provides control of stage2 translation of EL0/1
11+
12+
use tock_registers::{
13+
interfaces::{Readable, Writeable},
14+
register_bitfields,
15+
};
16+
17+
register_bitfields! {u64,
18+
pub VTCR_EL2 [
19+
/// Hardware dirty flag update in stage2 translations when EL2 is enabled
20+
HD OFFSET(22) NUMBITS(1) [
21+
/// Stage2 hardware management of dirty state disabled
22+
Disabled = 0,
23+
/// Stage2 hardware management of dirty state enabled
24+
Enabled = 1,
25+
],
26+
/// Hardware access flag update in stage2 translations when EL2 is enabled
27+
HA OFFSET(21) NUMBITS(1) [
28+
/// Stage2 hardware management of access state disabled
29+
Disabled = 0,
30+
/// Stage2 hardware management of access state enabled
31+
Enabled = 1,
32+
],
33+
/// VMID Size
34+
VS OFFSET(19) NUMBITS(1) [
35+
/// 8-bit VMID
36+
Bits8 = 0,
37+
/// 16-bit VMID
38+
Bits16 = 1,
39+
],
40+
/// Physical Address size of the second stage of translation
41+
PS OFFSET(16) NUMBITS(3) [
42+
/// 32 bits, 4GB
43+
PA_32B_4GB = 0b000,
44+
/// 36 bits, 64GB
45+
PA_36B_64GB = 0b001,
46+
/// 40 bits, 1TB
47+
PA_40B_1TB = 0b010,
48+
/// 42 bits, 4TB
49+
PA_42B_4TB = 0b011,
50+
/// 44 bits, 16TB
51+
PA_44B_16TB = 0b100,
52+
/// 48 bits, 256TB
53+
PA_48B_256TB = 0b101,
54+
/// 52 bits, 4PB
55+
PA_52B_4PB = 0b110,
56+
],
57+
/// Granule size used for `VTTBR_EL2`
58+
TG0 OFFSET(14) NUMBITS(2) [
59+
/// Granule size of 4KB
60+
Granule4KB = 0b00,
61+
/// Granule size of 16KB
62+
Granule16KB = 0b10,
63+
/// Granule size of 64KB
64+
Granule64KB = 0b01,
65+
],
66+
/// Shareability attribute for memory associated with translation table
67+
/// walks using `VTTBR_EL2` and `VSTTBR_EL2`
68+
SH0 OFFSET(12) NUMBITS(2) [
69+
/// Non-shareable
70+
Non = 0b00,
71+
/// Outer sharable
72+
Outer = 0b10,
73+
/// Inner sharable
74+
Inner = 0b11,
75+
],
76+
/// Outer cacheability attribute for memory associated with translation table
77+
/// walks using `VTTBR_EL2` and `VSTTBR_EL2`
78+
ORGN0 OFFSET(10) NUMBITS(2) [
79+
/// Normal non-cacheable memory
80+
NormalNC = 0b00,
81+
/// Normal Write-back, Read-allocate, Write-allocate
82+
NormalWBRAWA = 0b01,
83+
/// Normal Write-through, Read-allocate, no Write-allocate
84+
NormalWTRAnWA = 0b10,
85+
/// Normal Write-back, Read-allocate, no Write-allocate
86+
NormalWBRAnWA = 0b11,
87+
],
88+
/// Inner cacheability attribute for memory associated with translation table
89+
/// walks using `VTTBR_EL2` and `VSTTBR_EL2`
90+
IRGN0 OFFSET(8) NUMBITS(2) [
91+
/// Normal non-cacheable memory
92+
NormalNC = 0b00,
93+
/// Normal Write-back, Read-allocate, Write-allocate
94+
NormalWBRAWA = 0b01,
95+
/// Normal Write-through, Read-allocate, no Write-allocate
96+
NormalWTRAnWA = 0b10,
97+
/// Normal Write-back, Read-allocate, no Write-allocate
98+
NormalWBRAnWA = 0b11,
99+
],
100+
/// Starting level of the stage2 translation lookup
101+
SL0 OFFSET(6) NUMBITS(2) [],
102+
/// The size of the offest of the memory region addressed by the `VTTBR_EL2`
103+
T0SZ OFFSET(0) NUMBITS(6) [],
104+
105+
]
106+
}
107+
pub struct Reg;
108+
109+
impl Readable for Reg {
110+
type T = u64;
111+
type R = VTCR_EL2::Register;
112+
113+
sys_coproc_read_raw!(u64, "VTCR_EL2", "x");
114+
}
115+
116+
impl Writeable for Reg {
117+
type T = u64;
118+
type R = VTCR_EL2::Register;
119+
120+
sys_coproc_write_raw!(u64, "VTCR_EL2", "x");
121+
}
122+
123+
pub const VTCR_EL2: Reg = Reg {};
124+

src/registers/vttbr_el2.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
//
3+
// Copyright (c) 2018-2022 by the author(s)
4+
//
5+
// Author(s):
6+
// - KarimAllah Ahmed <[email protected]>
7+
// - Andre Richter <[email protected]>
8+
9+
use tock_registers::{
10+
interfaces::{Readable, Writeable},
11+
register_bitfields,
12+
};
13+
14+
register_bitfields! {u64,
15+
pub VTTBR_EL2 [
16+
/// An VMID for the translation table
17+
///
18+
/// If the implementation only supports 8-bit VM IDs the top 8 bits are RES0
19+
VMID OFFSET(48) NUMBITS(16) [],
20+
21+
/// Translation table base address
22+
BADDR OFFSET(1) NUMBITS(48) [],
23+
24+
/// Common not Private
25+
CnP OFFSET(0) NUMBITS(1) []
26+
]
27+
}
28+
29+
pub struct Reg;
30+
31+
impl Readable for Reg {
32+
type T = u64;
33+
type R = VTTBR_EL2::Register;
34+
35+
sys_coproc_read_raw!(u64, "VTTBR_EL2", "x");
36+
}
37+
38+
impl Writeable for Reg {
39+
type T = u64;
40+
type R = VTTBR_EL2::Register;
41+
42+
sys_coproc_write_raw!(u64, "VTTBR_EL2", "x");
43+
}
44+
45+
impl Reg {
46+
#[inline(always)]
47+
pub fn get_baddr(&self) -> u64 {
48+
self.read(VTTBR_EL2::BADDR) << 1
49+
}
50+
51+
#[inline(always)]
52+
pub fn set_baddr(&self, addr: u64) {
53+
self.write(VTTBR_EL2::BADDR.val(addr >> 1));
54+
}
55+
}
56+
57+
pub const VTTBR_EL2: Reg = Reg {};

0 commit comments

Comments
 (0)