Skip to content

Commit 63a4f5b

Browse files
authored
Merge pull request tock#4427 from tock/cortexm-mpu-address-per-arch
arch: Cortex-M: Set MPU address per arch
2 parents c5145e6 + 3dbaeae commit 63a4f5b

15 files changed

Lines changed: 56 additions & 14 deletions

File tree

arch/cortex-m/src/mpu.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ register_bitfields![u32,
129129
]
130130
];
131131

132-
const MPU_BASE_ADDRESS: StaticRef<MpuRegisters> =
133-
unsafe { StaticRef::new(0xE000ED90 as *const MpuRegisters) };
134-
135132
/// State related to the real physical MPU.
136133
///
137134
/// There should only be one instantiation of this object as it represents
@@ -149,9 +146,9 @@ pub struct MPU<const NUM_REGIONS: usize, const MIN_REGION_SIZE: usize> {
149146
}
150147

151148
impl<const NUM_REGIONS: usize, const MIN_REGION_SIZE: usize> MPU<NUM_REGIONS, MIN_REGION_SIZE> {
152-
pub const unsafe fn new() -> Self {
149+
pub const unsafe fn new(registers: StaticRef<MpuRegisters>) -> Self {
153150
Self {
154-
registers: MPU_BASE_ADDRESS,
151+
registers,
155152
config_count: Cell::new(NonZeroUsize::MIN),
156153
hardware_is_configured_for: OptionalCell::empty(),
157154
}

arch/cortex-m0p/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
use core::fmt::Write;
1010

1111
pub mod mpu {
12+
use kernel::utilities::StaticRef;
13+
1214
pub type MPU = cortexm::mpu::MPU<8, 256>;
15+
16+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
17+
unsafe { StaticRef::new(0xE000ED90 as *const cortexm::mpu::MpuRegisters) };
18+
19+
pub unsafe fn new() -> MPU {
20+
MPU::new(MPU_BASE_ADDRESS)
21+
}
1322
}
1423

1524
// Re-export the base generic cortex-m functions here as they are

arch/cortex-m3/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
use core::fmt::Write;
1010

1111
pub mod mpu {
12+
use kernel::utilities::StaticRef;
13+
1214
pub type MPU = cortexm::mpu::MPU<8, 32>;
15+
16+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
17+
unsafe { StaticRef::new(0xE000ED90 as *const cortexm::mpu::MpuRegisters) };
18+
19+
pub unsafe fn new() -> MPU {
20+
MPU::new(MPU_BASE_ADDRESS)
21+
}
1322
}
1423

1524
pub use cortexm::initialize_ram_jump_to_main;

arch/cortex-m4/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
use core::fmt::Write;
1010

1111
pub mod mpu {
12+
use kernel::utilities::StaticRef;
13+
1214
pub type MPU = cortexm::mpu::MPU<8, 32>;
15+
16+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
17+
unsafe { StaticRef::new(0xE000ED90 as *const cortexm::mpu::MpuRegisters) };
18+
19+
pub unsafe fn new() -> MPU {
20+
MPU::new(MPU_BASE_ADDRESS)
21+
}
1322
}
1423

1524
pub use cortexm::dwt;

arch/cortex-m4f/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
use core::fmt::Write;
1010

1111
pub mod mpu {
12+
use kernel::utilities::StaticRef;
13+
1214
pub type MPU = cortexm::mpu::MPU<8, 32>;
15+
16+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
17+
unsafe { StaticRef::new(0xE000ED90 as *const cortexm::mpu::MpuRegisters) };
18+
19+
pub unsafe fn new() -> MPU {
20+
MPU::new(MPU_BASE_ADDRESS)
21+
}
1322
}
1423

1524
pub use cortexm::dwt;

arch/cortex-m7/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
use core::fmt::Write;
1010

1111
pub mod mpu {
12+
use kernel::utilities::StaticRef;
13+
1214
pub type MPU = cortexm::mpu::MPU<16, 32>; // Cortex-M7 MPU has 16 regions
15+
16+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
17+
unsafe { StaticRef::new(0xE000ED90 as *const cortexm::mpu::MpuRegisters) };
18+
19+
pub unsafe fn new() -> MPU {
20+
MPU::new(MPU_BASE_ADDRESS)
21+
}
1322
}
1423

1524
pub use cortexm::initialize_ram_jump_to_main;

chips/apollo3/src/chip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Apollo3<I: InterruptService + 'static> {
1818
impl<I: InterruptService + 'static> Apollo3<I> {
1919
pub unsafe fn new(interrupt_service: &'static I) -> Self {
2020
Self {
21-
mpu: cortexm4f::mpu::MPU::new(),
21+
mpu: cortexm4f::mpu::new(),
2222
userspace_kernel_boundary: cortexm4f::syscall::SysCall::new(),
2323
interrupt_service,
2424
}

chips/imxrt10xx/src/chip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Imxrt10xx<I: InterruptService + 'static> {
2020
impl<I: InterruptService + 'static> Imxrt10xx<I> {
2121
pub unsafe fn new(interrupt_service: &'static I) -> Self {
2222
Imxrt10xx {
23-
mpu: cortexm7::mpu::MPU::new(),
23+
mpu: cortexm7::mpu::new(),
2424
userspace_kernel_boundary: cortexm7::syscall::SysCall::new(),
2525
interrupt_service,
2626
}

chips/msp432/src/chip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl kernel::platform::chip::InterruptService for Msp432DefaultPeripherals<'_> {
9797
impl<'a, I: InterruptService + 'a> Msp432<'a, I> {
9898
pub unsafe fn new(interrupt_service: &'a I) -> Self {
9999
Self {
100-
mpu: cortexm4::mpu::MPU::new(),
100+
mpu: cortexm4::mpu::new(),
101101
userspace_kernel_boundary: cortexm4::syscall::SysCall::new(),
102102
interrupt_service,
103103
}

chips/nrf52/src/chip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct NRF52<'a, I: InterruptService + 'a> {
1515
impl<'a, I: InterruptService + 'a> NRF52<'a, I> {
1616
pub unsafe fn new(interrupt_service: &'a I) -> Self {
1717
Self {
18-
mpu: cortexm4f::mpu::MPU::new(),
18+
mpu: cortexm4f::mpu::new(),
1919
userspace_kernel_boundary: cortexm4f::syscall::SysCall::new(),
2020
interrupt_service,
2121
}

0 commit comments

Comments
 (0)