Skip to content

Initial Rust CMSE support #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget
[dependencies]
bare-metal = { version = "0.2.0", features = ["const-fn"] }
volatile-register = "0.2.0"
bitfield = "0.13.2"

[features]
cm7-r0p1 = []
Expand Down
27 changes: 27 additions & 0 deletions asm-v8.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.section .text.__tt
.global __tt
.thumb_func
__tt:
tt r0, r0
bx lr

.section .text.__ttt
.global __ttt
.thumb_func
__ttt:
ttt r0, r0
bx lr

.section .text.__tta
.global __tta
.thumb_func
__tta:
tta r0, r0
bx lr

.section .text.__ttat
.global __ttat
.thumb_func
__ttat:
ttat r0, r0
bx lr
9 changes: 6 additions & 3 deletions assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ ar crs bin/thumbv7em-none-eabi.a bin/$crate.o bin/$crate-v7.o bin/$crate-cm7-r0p
ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o bin/$crate-v7.o bin/$crate-cm7-r0p1.o

arm-none-eabi-as -march=armv8-m.base asm.s -o bin/$crate.o
ar crs bin/thumbv8m.base-none-eabi.a bin/$crate.o
arm-none-eabi-as -march=armv8-m.base asm-v8.s -o bin/$crate-v8.o
ar crs bin/thumbv8m.base-none-eabi.a bin/$crate.o bin/$crate-v8.o

arm-none-eabi-as -march=armv8-m.main asm.s -o bin/$crate.o
arm-none-eabi-as -march=armv8-m.main asm-v7.s -o bin/$crate-v7.o
arm-none-eabi-as -march=armv8-m.main asm-v8.s -o bin/$crate-v8.o
arm-none-eabi-as -march=armv8-m.main asm-v8-main.s -o bin/$crate-v8-main.o
ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8-main.o
ar crs bin/thumbv8m.main-none-eabihf.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8-main.o
ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8.o bin/$crate-v8-main.o
ar crs bin/thumbv8m.main-none-eabihf.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8.o bin/$crate-v8-main.o

rm bin/$crate.o
rm bin/$crate-v7.o
rm bin/$crate-cm7-r0p1.o
rm bin/$crate-v8.o
rm bin/$crate-v8-main.o
Binary file modified bin/thumbv8m.base-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf.a
Binary file not shown.
141 changes: 141 additions & 0 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,144 @@ pub fn dmb() {
() => unimplemented!(),
}
}

/// Test Target
///
/// Queries the Security state and access permissions of a memory location.
/// Returns a Test Target Response Payload (cf section D1.2.215 of
/// Armv8-M Architecture Reference Manual).
#[inline]
#[cfg(armv8m)]
// The __tt function does not dereference the pointer received.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn tt(addr: *mut u32) -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let tt_resp: u32;
unsafe {
asm!("tt $0, $1" : "=r"(tt_resp) : "r"(addr) :: "volatile");
}
tt_resp
}

#[cfg(all(cortex_m, not(feature = "inline-asm")))]
() => unsafe {
extern "C" {
fn __tt(_: *mut u32) -> u32;
}

__tt(addr)
},

#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}

/// Test Target Unprivileged
///
/// Queries the Security state and access permissions of a memory location for an unprivileged
/// access to that location.
/// Returns a Test Target Response Payload (cf section D1.2.215 of
/// Armv8-M Architecture Reference Manual).
#[inline]
#[cfg(armv8m)]
// The __ttt function does not dereference the pointer received.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn ttt(addr: *mut u32) -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let tt_resp: u32;
unsafe {
asm!("ttt $0, $1" : "=r"(tt_resp) : "r"(addr) :: "volatile");
}
tt_resp
}

#[cfg(all(cortex_m, not(feature = "inline-asm")))]
() => unsafe {
extern "C" {
fn __ttt(_: *mut u32) -> u32;
}

__ttt(addr)
},

#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}

/// Test Target Alternate Domain
///
/// Queries the Security state and access permissions of a memory location for a Non-Secure access
/// to that location. This instruction is only valid when executing in Secure state and is
/// undefined if used from Non-Secure state.
/// Returns a Test Target Response Payload (cf section D1.2.215 of
/// Armv8-M Architecture Reference Manual).
#[inline]
#[cfg(armv8m)]
// The __tta function does not dereference the pointer received.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn tta(addr: *mut u32) -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let tt_resp: u32;
unsafe {
asm!("tta $0, $1" : "=r"(tt_resp) : "r"(addr) :: "volatile");
}
tt_resp
}

#[cfg(all(cortex_m, not(feature = "inline-asm")))]
() => unsafe {
extern "C" {
fn __tta(_: *mut u32) -> u32;
}

__tta(addr)
},

#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}

/// Test Target Alternate Domain Unprivileged
///
/// Queries the Security state and access permissions of a memory location for a Non-Secure and
/// unprivileged access to that location. This instruction is only valid when executing in Secure
/// state and is undefined if used from Non-Secure state.
/// Returns a Test Target Response Payload (cf section D1.2.215 of
/// Armv8-M Architecture Reference Manual).
#[inline]
#[cfg(armv8m)]
// The __ttat function does not dereference the pointer received.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn ttat(addr: *mut u32) -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let tt_resp: u32;
unsafe {
asm!("ttat $0, $1" : "=r"(tt_resp) : "r"(addr) :: "volatile");
}
tt_resp
}

#[cfg(all(cortex_m, not(feature = "inline-asm")))]
() => unsafe {
extern "C" {
fn __ttat(_: *mut u32) -> u32;
}

__ttat(addr)
},

#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}
Loading