Skip to content

Commit e79a0c9

Browse files
bors[bot]aurabindo
andcommitted
Merge #161
161: Add {M,P}SPLIM access routines found on ARMv8-M mainline extension r=thejpster a=aurabindo I'd like to add better v8-M support. I'm not sure if this is PR has an optimal way of handling arch extension. As per ARMv8 Architecture reference manual, the baseline variant is not compatible with ARMv7-M. Only the main extension brings backward compatibility with v7-M. This PR adds support for accessing MSPLIM and PSPLIM registers, and missing binaries for `thumbv8m.main-none-eabihf` architecture. Co-authored-by: Aurabindo Jayamohanan <[email protected]>
2 parents 1aa7d5d + 57d44f6 commit e79a0c9

File tree

8 files changed

+138
-2
lines changed

8 files changed

+138
-2
lines changed

asm-v8-main.s

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.section .text.__msplim_r
2+
.global __msplim_r
3+
.thumb_func
4+
__msplim_r:
5+
mrs r0, MSPLIM
6+
bx lr
7+
8+
.section .text.__msplim_w
9+
.global __msplim_w
10+
.thumb_func
11+
__msplim_w:
12+
msr MSPLIM, r0
13+
bx lr
14+
15+
.section .text.__psplim_r
16+
.global __psplim_r
17+
.thumb_func
18+
__psplim_r:
19+
mrs r0, PSPLIM
20+
bx lr
21+
22+
.section .text.__psplim_w
23+
.global __psplim_w
24+
.thumb_func
25+
__psplim_w:
26+
msr PSPLIM, r0
27+
bx lr
28+

assemble.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ arm-none-eabi-as -march=armv8-m.base asm.s -o bin/$crate.o
2626
ar crs bin/thumbv8m.base-none-eabi.a bin/$crate.o
2727

2828
arm-none-eabi-as -march=armv8-m.main asm.s -o bin/$crate.o
29-
ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o
29+
arm-none-eabi-as -march=armv8-m.main asm-v7.s -o bin/$crate-v7.o
30+
arm-none-eabi-as -march=armv8-m.main asm-v8-main.s -o bin/$crate-v8-main.o
31+
ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8-main.o
32+
ar crs bin/thumbv8m.main-none-eabihf.a bin/$crate.o bin/$crate-v7.o bin/$crate-v8-main.o
3033

3134
rm bin/$crate.o
3235
rm bin/$crate-v7.o
3336
rm bin/$crate-cm7-r0p1.o
37+
rm bin/$crate-v8-main.o

bin/thumbv8m.main-none-eabi.a

2.35 KB
Binary file not shown.

bin/thumbv8m.main-none-eabihf.a

5.1 KB
Binary file not shown.

build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ fn main() {
2626
println!("cargo:rustc-cfg=cortex_m");
2727
println!("cargo:rustc-cfg=armv7m");
2828
//println!("cargo:rustc-cfg=armv7em");
29-
} else if target.starts_with("thumbv8m") {
29+
} else if target.starts_with("thumbv8m.base") {
3030
println!("cargo:rustc-cfg=cortex_m");
3131
println!("cargo:rustc-cfg=armv8m");
32+
} else if target.starts_with("thumbv8m.main") {
33+
println!("cargo:rustc-cfg=cortex_m");
34+
println!("cargo:rustc-cfg=armv8m");
35+
println!("cargo:rustc-cfg=armv8m_main");
3236
}
3337

3438
if target.ends_with("-eabihf") {

src/register/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ pub mod primask;
4343

4444
pub mod psp;
4545

46+
#[cfg(armv8m_main)]
47+
pub mod msplim;
48+
49+
#[cfg(armv8m_main)]
50+
pub mod psplim;
51+
4652
// Accessing these registers requires inline assembly because their contents are tied to the current
4753
// stack frame
4854
#[cfg(any(feature = "inline-asm", target_arch = "x86_64"))]

src/register/msplim.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Main Stack Pointer Limit Register
2+
3+
/// Reads the CPU register
4+
#[inline]
5+
pub fn read() -> u32 {
6+
match () {
7+
#[cfg(all(cortex_m, feature = "inline-asm"))]
8+
() => {
9+
let r;
10+
unsafe { asm!("mrs $0,MSPLIM" : "=r"(r) ::: "volatile") }
11+
r
12+
}
13+
14+
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
15+
() => unsafe {
16+
extern "C" {
17+
fn __msplim_r() -> u32;
18+
}
19+
20+
__msplim_r()
21+
},
22+
23+
#[cfg(not(cortex_m))]
24+
() => unimplemented!(),
25+
}
26+
}
27+
28+
/// Writes `bits` to the CPU register
29+
#[inline]
30+
pub unsafe fn write(_bits: u32) {
31+
match () {
32+
#[cfg(all(cortex_m, feature = "inline-asm"))]
33+
() => asm!("msr MSPLIM,$0" :: "r"(_bits) :: "volatile"),
34+
35+
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
36+
() => {
37+
extern "C" {
38+
fn __msplim_w(_: u32);
39+
}
40+
41+
__msplim_w(_bits);
42+
}
43+
44+
#[cfg(not(cortex_m))]
45+
() => unimplemented!(),
46+
}
47+
}

src/register/psplim.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Process Stack Pointer Limit Register
2+
3+
/// Reads the CPU register
4+
#[inline]
5+
pub fn read() -> u32 {
6+
match () {
7+
#[cfg(all(cortex_m, feature = "inline-asm"))]
8+
() => {
9+
let r;
10+
unsafe { asm!("mrs $0,PSPLIM" : "=r"(r) ::: "volatile") }
11+
r
12+
}
13+
14+
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
15+
() => unsafe {
16+
extern "C" {
17+
fn __psplim_r() -> u32;
18+
}
19+
20+
__psplim_r()
21+
},
22+
23+
#[cfg(not(cortex_m))]
24+
() => unimplemented!(),
25+
}
26+
}
27+
28+
/// Writes `bits` to the CPU register
29+
#[inline]
30+
pub unsafe fn write(_bits: u32) {
31+
match () {
32+
#[cfg(all(cortex_m, feature = "inline-asm"))]
33+
() => asm!("msr PSPLIM,$0" :: "r"(_bits) :: "volatile"),
34+
35+
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
36+
() => {
37+
extern "C" {
38+
fn __psplim_w(_: u32);
39+
}
40+
41+
__psplim_w(_bits);
42+
}
43+
44+
#[cfg(not(cortex_m))]
45+
() => unimplemented!(),
46+
}
47+
}

0 commit comments

Comments
 (0)