Skip to content

Commit 97febe5

Browse files
committed
feat(port_arm): disable SCTLR::{AFE, TE} and clear NS in page table
1 parent 07d2e59 commit 97febe5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/constance_port_arm/src/arm/sctlr.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ register::register_bitfields! {u32,
3434
V OFFSET(13) NUMBITS(1) [
3535
Low = 0,
3636
High = 1
37+
],
38+
39+
/// Access flag enable
40+
AFE OFFSET(29) NUMBITS(1) [
41+
Disable = 0,
42+
Enable = 1
43+
],
44+
45+
/// Thumb Exception Enable
46+
TE OFFSET(30) NUMBITS(1) [
47+
Arm = 0,
48+
Thumb = 1
3749
]
3850
]
3951
}

src/constance_port_arm/src/startup/imp.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ extern "C" fn reset_handler1<System: EntryPoint + StartupOptions>() {
170170
// Enable alignment fault checking
171171
arm::SCTLR::A::Enable +
172172
// Enable branch prediction
173-
arm::SCTLR::Z::Enable,
173+
arm::SCTLR::Z::Enable +
174+
// Disable access flags in a page table
175+
arm::SCTLR::AFE::Disable +
176+
// Exceptions are taken in Arm state
177+
arm::SCTLR::TE::Arm,
174178
);
175179

176180
// Ensure the changes made to `SCTLR` here take effect immediately
@@ -365,8 +369,8 @@ impl FirstLevelPageEntry {
365369
/// Construct a page table entry.
366370
const fn page_table(table: *const SecondLevelPageTable) -> Self {
367371
let domain = 0u32;
368-
let ns = true; // Non-Secure access
369-
let pxn = false; // not using Large Physical Address Extension
372+
let ns = false; // Secure access
373+
let pxn = false; // not enabling Privilege Execute Never
370374

371375
Self {
372376
// Assuming physical address == virtual address for `table`
@@ -387,7 +391,7 @@ impl FirstLevelPageEntry {
387391
xn,
388392
} = attr;
389393
let domain = 0u32;
390-
let ns = true; // Non-Secure access
394+
let ns = false; // Secure access
391395
let ng = false; // global (not Not-Global)
392396
let pxn = false; // not using Large Physical Address Extension
393397

0 commit comments

Comments
 (0)