Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Merge #337
Browse files Browse the repository at this point in the history
337: Fix unwinding through `Reset` r=thejpster a=jonas-schievink

Unwinders may detect the end of the program by seeing `0xFFFFFFFF` in `lr`, which is why code to ensure that it has that value was added in #293. However, the `bl main` overwrites that value with the current program counter. This PR saves the old `lr` value on the stack, and adds debuginfo entries to allow an external unwinder to restore the value.

This fixes knurling-rs/probe-run#277

Co-authored-by: Jonas Schievink <[email protected]>
  • Loading branch information
bors[bot] and jonas-schievink authored Nov 23, 2021
2 parents e48af90 + b0c0ab3 commit c37794c
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 12 deletions.
8 changes: 8 additions & 0 deletions asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ Reset:
#endif

4:
# Preserve `lr` and emit debuginfo that lets external tools restore it.
# This fixes unwinding past the `Reset` handler.
# See https://sourceware.org/binutils/docs/as/CFI-directives.html for an
# explanation of the directives.
.cfi_def_cfa sp, 0
push {lr}
.cfi_offset lr, 0

# Jump to user main function. We use bl for the extended range, but the
# user main function may not return.
bl main
Expand Down
14 changes: 7 additions & 7 deletions assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ crate=cortex-m-rt
# remove existing blobs because otherwise this will append object files to the old blobs
rm -f bin/*.a

arm-none-eabi-gcc -c -march=armv6s-m asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv6s-m asm.S -o bin/$crate.o
ar crs bin/thumbv6m-none-eabi.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv7-m asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv7-m asm.S -o bin/$crate.o
ar crs bin/thumbv7m-none-eabi.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv7e-m asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv7e-m asm.S -o bin/$crate.o
ar crs bin/thumbv7em-none-eabi.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv7e-m asm.S -DHAS_FPU -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv7e-m asm.S -DHAS_FPU -o bin/$crate.o
ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv8-m.base asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv8-m.base asm.S -o bin/$crate.o
ar crs bin/thumbv8m.base-none-eabi.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv8-m.main asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv8-m.main asm.S -o bin/$crate.o
ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o

arm-none-eabi-gcc -c -march=armv8-m.main -DHAS_FPU asm.S -o bin/$crate.o
arm-none-eabi-gcc -g -c -march=armv8-m.main -DHAS_FPU asm.S -o bin/$crate.o
ar crs bin/thumbv8m.main-none-eabihf.a bin/$crate.o

rm bin/$crate.o
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.
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.
8 changes: 3 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

if target.starts_with("thumbv") {
fs::copy(
format!("bin/{}.a", target),
out_dir.join("libcortex-m-rt.a"),
)
.unwrap();
let lib_path = format!("bin/{}.a", target);
fs::copy(&lib_path, out_dir.join("libcortex-m-rt.a")).unwrap();
println!("cargo:rustc-link-lib=static=cortex-m-rt");
println!("cargo:rerun-if-changed={}", lib_path);
}

// Put the linker script somewhere the linker can find it
Expand Down

0 comments on commit c37794c

Please sign in to comment.