Skip to content

Commit 7c7383b

Browse files
committed
arch: add code for the Cortex-M33 architecture
This commits adds the code for the Cortex-M33 architecture. It also adds the possibility to use the Non-Secure alias of the MPU
1 parent 63a4f5b commit 7c7383b

7 files changed

Lines changed: 708 additions & 0 deletions

File tree

arch/cortex-m/src/mpu.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ impl<const NUM_REGIONS: usize, const MIN_REGION_SIZE: usize> MPU<NUM_REGIONS, MI
154154
}
155155
}
156156

157+
// Function for boards that have TrustZone.
158+
pub const unsafe fn new_ns() -> Self {
159+
Self {
160+
registers: MPU_NS_BASE_ADDRESS,
161+
config_count: Cell::new(NonZeroUsize::MIN),
162+
hardware_is_configured_for: OptionalCell::empty(),
163+
}
164+
}
165+
157166
// Function useful for boards where the bootloader sets up some
158167
// MPU configuration that conflicts with Tock's configuration:
159168
pub unsafe fn clear_mpu(&self) {

arch/cortex-m33/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2022.
4+
5+
[package]
6+
name = "cortexm33"
7+
version.workspace = true
8+
authors.workspace = true
9+
edition.workspace = true
10+
11+
[dependencies]
12+
kernel = { path = "../../kernel" }
13+
cortexm = { path = "../cortex-m" }
14+
cortexv8m = { path = "../cortex-v8m" }
15+
16+
[lints]
17+
workspace = true

arch/cortex-m33/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Cortex-M33 Architecture
2+
======================
3+
4+
Architecture support for Cortex-M33 devices. This largely only re-exports the
5+
correct functions from the Cortex-M crate.

arch/cortex-m33/src/lib.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed under the Apache License, Version 2.0 or the MIT License.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
// Copyright Tock Contributors 2022.
4+
5+
//! Shared implementations for ARM Cortex-M33 MCUs.
6+
7+
#![crate_name = "cortexm33"]
8+
#![crate_type = "rlib"]
9+
#![no_std]
10+
11+
use core::fmt::Write;
12+
13+
pub mod mpu {
14+
pub type MPU = cortexm::mpu::MPU<16, 32>; // Cortex-M7 MPU has 16 regions
15+
}
16+
17+
pub use cortexm::initialize_ram_jump_to_main;
18+
pub use cortexm::interrupt_mask;
19+
pub use cortexm::nvic;
20+
pub use cortexm::scb;
21+
pub use cortexm::support;
22+
pub use cortexm::systick;
23+
pub use cortexm::unhandled_interrupt;
24+
pub use cortexm::CortexMVariant;
25+
26+
// Enum with no variants to ensure that this type is not instantiable. It is
27+
// only used to pass architecture-specific constants and functions via the
28+
// `CortexMVariant` trait.
29+
pub enum CortexM33 {}
30+
31+
impl cortexm::CortexMVariant for CortexM33 {
32+
const GENERIC_ISR: unsafe extern "C" fn() = cortexv8m::generic_isr_arm_v8m;
33+
const SYSTICK_HANDLER: unsafe extern "C" fn() = cortexv8m::systick_handler_arm_v8m;
34+
const SVC_HANDLER: unsafe extern "C" fn() = cortexv8m::svc_handler_arm_v8m;
35+
const HARD_FAULT_HANDLER: unsafe extern "C" fn() = cortexv8m::hard_fault_handler_arm_v8m;
36+
37+
#[cfg(all(target_arch = "arm", target_os = "none"))]
38+
unsafe fn switch_to_user(
39+
user_stack: *const usize,
40+
process_regs: &mut [usize; 8],
41+
) -> *const usize {
42+
cortexv8m::switch_to_user_arm_v8m(user_stack, process_regs)
43+
}
44+
45+
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
46+
unsafe fn switch_to_user(
47+
_user_stack: *const usize,
48+
_process_regs: &mut [usize; 8],
49+
) -> *const usize {
50+
unimplemented!()
51+
}
52+
53+
#[inline]
54+
unsafe fn print_cortexm_state(writer: &mut dyn Write) {
55+
cortexm::print_cortexm_state(writer)
56+
}
57+
}
58+
59+
pub mod syscall {
60+
pub type SysCall = cortexm::syscall::SysCall<crate::CortexM33>;
61+
}

arch/cortex-v8m/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2024.
4+
5+
[package]
6+
name = "cortexv8m"
7+
version.workspace = true
8+
authors.workspace = true
9+
edition.workspace = true
10+
11+
[dependencies]
12+
kernel = { path = "../../kernel" }
13+
14+
[lints]
15+
workspace = true

arch/cortex-v8m/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Cortex-M v8m Architecture
2+
=========================
3+
4+
This crate includes shared low-level code for the Cortex-M v8m family of CPU
5+
architectures.
6+
7+
Boards and chips should not depend on this crate directly. Instead, all of the
8+
relevant modules and features should be exported through the specific Cortex-M
9+
crates (e.g. Cortex-M33), and chips and boards should depend on the more specific
10+
crate.

0 commit comments

Comments
 (0)