Skip to content

Commit d8cfffd

Browse files
committed
Remove prebuilt cortex-m-rt binaries, replace with global_asm
1 parent d8c3c21 commit d8cfffd

17 files changed

+134
-186
lines changed

.github/bors.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ status = [
55
"ci-linux (stable)",
66
"ci-linux (1.59.0)",
77
"rt-ci-linux (stable)",
8-
"rt-ci-linux (1.42.0)",
8+
"rt-ci-linux (1.59.0)",
99
"rt-ci-other-os (macOS-latest)",
1010
"rt-ci-other-os (windows-latest)",
1111
"rustfmt",

.github/workflows/rt-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ jobs:
1111
continue-on-error: ${{ matrix.experimental || false }}
1212
strategy:
1313
matrix:
14-
# All generated code should be running on stable now
15-
rust: [nightly, stable, 1.42.0]
14+
rust: [nightly, stable, 1.59.0]
1615

1716
include:
1817
# Nightly is only for reference and allowed to fail

cortex-m-rt/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Moved precompiled assembly blobs to `global_asm!`, requiring Rust 1.59.
11+
1012
## Fixes
1113

1214
- Fix `cortex_m_rt::exception` macro no longer being usable fully-qualified ([#414])

cortex-m-rt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [Cortex-M team][team].
1111

1212
# Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.42.0 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
1515
compile with older versions but that may change in any new patch release.
1616

1717
# License

cortex-m-rt/asm.S

Lines changed: 0 additions & 113 deletions
This file was deleted.

cortex-m-rt/assemble.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

cortex-m-rt/bin/thumbv6m-none-eabi.a

-2.67 KB
Binary file not shown.

cortex-m-rt/bin/thumbv7em-none-eabi.a

-2.68 KB
Binary file not shown.
-2.71 KB
Binary file not shown.

cortex-m-rt/bin/thumbv7m-none-eabi.a

-2.68 KB
Binary file not shown.
-2.68 KB
Binary file not shown.
-2.69 KB
Binary file not shown.
-2.72 KB
Binary file not shown.

cortex-m-rt/build.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs::{self, File};
1+
use std::fs::File;
22
use std::io::Write;
33
use std::path::{Path, PathBuf};
44
use std::{env, ffi::OsStr};
@@ -16,15 +16,6 @@ fn main() {
1616
.map_or(target.clone(), |stem| stem.to_str().unwrap().to_string());
1717
}
1818

19-
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
20-
21-
if target.starts_with("thumbv") {
22-
let lib_path = format!("bin/{}.a", target);
23-
fs::copy(&lib_path, out_dir.join("libcortex-m-rt.a")).unwrap();
24-
println!("cargo:rustc-link-lib=static=cortex-m-rt");
25-
println!("cargo:rerun-if-changed={}", lib_path);
26-
}
27-
2819
// Put the linker script somewhere the linker can find it
2920
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
3021
let link_x = include_bytes!("link.x.in");
@@ -69,6 +60,10 @@ INCLUDE device.x"#
6960
240
7061
};
7162

63+
if target.ends_with("-eabihf") {
64+
println!("cargo:rustc-cfg=has_fpu");
65+
}
66+
7267
// checking the size of the interrupts portion of the vector table is sub-architecture dependent
7368
writeln!(
7469
f,

cortex-m-rt/check-blobs.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

cortex-m-rt/ci/script.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ main() {
7171

7272
;;
7373
esac
74-
75-
if [ "$TARGET" = x86_64-unknown-linux-gnu ]; then
76-
./check-blobs.sh
77-
fi
7874
}
7975

8076
main

cortex-m-rt/src/lib.rs

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
//!
419419
//! # Minimum Supported Rust Version (MSRV)
420420
//!
421-
//! The MSRV of this release is Rust 1.42.0.
421+
//! The MSRV of this release is Rust 1.59.0.
422422
423423
// # Developer notes
424424
//
@@ -431,8 +431,131 @@
431431
extern crate cortex_m_rt_macros as macros;
432432

433433
use core::fmt;
434+
use core::arch::global_asm;
434435
use core::sync::atomic::{self, Ordering};
435436

437+
// HardFault exceptions are bounced through this trampoline which grabs the stack pointer at
438+
// the time of the exception and passes it to th euser's HardFault handler in r0.
439+
// Depending on the stack mode in EXC_RETURN, fetches stack from either MSP or PSP.
440+
global_asm!(
441+
".cfi_sections .debug_frame
442+
.section .HardFaultTrampoline, \"ax\"
443+
.global HardFaultTrampline
444+
.type HardFaultTrampline,%function
445+
.thumb_func
446+
.cfi_startproc
447+
HardFaultTrampoline:",
448+
449+
"mov r0, lr
450+
movs r1, #4
451+
tst r0, r1
452+
bne 0f
453+
mrs r0, MSP
454+
b HardFault
455+
0:
456+
mrs r0, PSP
457+
b HardFault",
458+
459+
".cfi_endproc
460+
.size HardFaultTrampoline, . - HardFaultTrampoline",
461+
);
462+
463+
/// Parse cfg attributes inside a global_asm call.
464+
macro_rules! cfg_global_asm {
465+
{@inner, [$($x:tt)*], } => {
466+
global_asm!{$($x)*}
467+
};
468+
(@inner, [$($x:tt)*], #[cfg($meta:meta)] $asm:literal, $($rest:tt)*) => {
469+
#[cfg($meta)]
470+
cfg_global_asm!{@inner, [$($x)* $asm,], $($rest)*}
471+
#[cfg(not($meta))]
472+
cfg_global_asm!{@inner, [$($x)*], $($rest)*}
473+
};
474+
{@inner, [$($x:tt)*], $asm:literal, $($rest:tt)*} => {
475+
cfg_global_asm!{@inner, [$($x)* $asm,], $($rest)*}
476+
};
477+
{$($asms:tt)*} => {
478+
cfg_global_asm!{@inner, [], $($asms)*}
479+
};
480+
}
481+
482+
// This reset vector is the initial entry point after a system reset.
483+
// Calls an optional user-provided __pre_init and then initialises RAM.
484+
// If the target has an FPU, it is enabled.
485+
// Finally jumsp to the user main function.
486+
cfg_global_asm! {
487+
".cfi_sections .debug_frame
488+
.section .Reset, \"ax\"
489+
.global Reset
490+
.type Reset,%function
491+
.thumb_func",
492+
".cfi_startproc
493+
Reset:",
494+
495+
// Ensure LR is loaded with 0xFFFF_FFFF at startup to help debuggers find the first call frame.
496+
// On ARMv6-M LR is not initialised at all, while other platforms should initialise it.
497+
"movs r4, #0
498+
mvns r4, r4
499+
mov lr, r4",
500+
501+
// Run user pre-init code which must be executed immediately after startup, before the
502+
// potentially time-consuming memory initialisation takes place.
503+
// Example use cases include disabling default watchdogs or enabling RAM.
504+
// Reload LR after returning from pre-init (r4 is preserved by subroutines).
505+
"bl __pre_init
506+
mov lr, r4",
507+
508+
// Initialise .bss memory. `__sbss` and `__ebss` come from the linker script.
509+
"ldr r0, =__sbss
510+
ldr r1, =__ebss
511+
movs r2, #0
512+
0:
513+
cmp r1, r0
514+
beq 1f
515+
stm r0!, {{r2}}
516+
b 0b
517+
1:",
518+
519+
// Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
520+
"ldr r0, =__sdata
521+
ldr r1, =__edata
522+
ldr r2, =__sidata
523+
2:
524+
cmp r0, r0
525+
beq 3f
526+
ldm r2!, {{r3}}
527+
stm r0!, {{r3}}
528+
b 2b
529+
3:",
530+
531+
// Potentially enable an FPU.
532+
// SCB.CPACR is 0xE000_ED88.
533+
// We enable access to CP10 and CP11 from priviliged and unprivileged mode.
534+
#[cfg(has_fpu)]
535+
"ldr r0, =0xE000ED88
536+
ldr r1, =(0b1111 << 20)
537+
ldr r2, [r0]
538+
orr r2, r2, r1
539+
str r2, [r0]
540+
dsb
541+
isb",
542+
543+
// Push `lr` to the stack for debuggers, to prevent them unwinding past Reset.
544+
// See https://sourceware.org/binutils/docs/as/CFI-directives.html.
545+
".cfi_def_cfa sp, 0
546+
push {{lr}}
547+
.cfi_offset lr, 0",
548+
549+
// Jump to user main function.
550+
// `bl` is used for the extended range, but the user main function should not return,
551+
// so trap on any unexpected return.
552+
"bl main
553+
udf #0",
554+
555+
".cfi_endproc
556+
.size Reset, . - Reset",
557+
}
558+
436559
/// Attribute to declare an interrupt (AKA device-specific exception) handler
437560
///
438561
/// **IMPORTANT**: If you are using Rust 1.30 this attribute must be used on reachable items (i.e.

0 commit comments

Comments
 (0)