Skip to content

Add {M,P}SPLIM access routines found on ARMv8-M mainline extension #161

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 1 commit into from
Aug 12, 2019
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
28 changes: 28 additions & 0 deletions asm-v8-main.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.section .text.__msplim_r
.global __msplim_r
.thumb_func
__msplim_r:
mrs r0, MSPLIM
bx lr

.section .text.__msplim_w
.global __msplim_w
.thumb_func
__msplim_w:
msr MSPLIM, r0
bx lr

.section .text.__psplim_r
.global __psplim_r
.thumb_func
__psplim_r:
mrs r0, PSPLIM
bx lr

.section .text.__psplim_w
.global __psplim_w
.thumb_func
__psplim_w:
msr PSPLIM, r0
bx lr

6 changes: 5 additions & 1 deletion assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ 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.main asm.s -o bin/$crate.o
ar crs bin/thumbv8m.main-none-eabi.a 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-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

rm bin/$crate.o
rm bin/$crate-v7.o
rm bin/$crate-cm7-r0p1.o
rm bin/$crate-v8-main.o
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file added bin/thumbv8m.main-none-eabihf.a
Binary file not shown.
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ fn main() {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv7m");
//println!("cargo:rustc-cfg=armv7em");
} else if target.starts_with("thumbv8m") {
} else if target.starts_with("thumbv8m.base") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv8m");
} else if target.starts_with("thumbv8m.main") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv8m");
println!("cargo:rustc-cfg=armv8m_main");
}

if target.ends_with("-eabihf") {
Expand Down
6 changes: 6 additions & 0 deletions src/register/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub mod primask;

pub mod psp;

#[cfg(armv8m_main)]
pub mod msplim;

#[cfg(armv8m_main)]
pub mod psplim;

// Accessing these registers requires inline assembly because their contents are tied to the current
// stack frame
#[cfg(any(feature = "inline-asm", target_arch = "x86_64"))]
Expand Down
47 changes: 47 additions & 0 deletions src/register/msplim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Main Stack Pointer Limit Register

/// Reads the CPU register
#[inline]
pub fn read() -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let r;
unsafe { asm!("mrs $0,MSPLIM" : "=r"(r) ::: "volatile") }
r
}

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

__msplim_r()
},

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

/// Writes `bits` to the CPU register
#[inline]
pub unsafe fn write(_bits: u32) {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => asm!("msr MSPLIM,$0" :: "r"(_bits) :: "volatile"),

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

__msplim_w(_bits);
}

#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}
47 changes: 47 additions & 0 deletions src/register/psplim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Process Stack Pointer Limit Register

/// Reads the CPU register
#[inline]
pub fn read() -> u32 {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => {
let r;
unsafe { asm!("mrs $0,PSPLIM" : "=r"(r) ::: "volatile") }
r
}

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

__psplim_r()
},

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

/// Writes `bits` to the CPU register
#[inline]
pub unsafe fn write(_bits: u32) {
match () {
#[cfg(all(cortex_m, feature = "inline-asm"))]
() => asm!("msr PSPLIM,$0" :: "r"(_bits) :: "volatile"),

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

__psplim_w(_bits);
}

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