-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #53996 - sekineh:thumb-run, r=japaric
[CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded] ## What's included? - Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` - We are using `cortex-m-rt = "=0.5.4"` which does not use `proc_macro`. (reason: stage2 build of rustc does not work well with `proc_macro` in `run-make` phase.) - We are using GNU LD for now. ## Blocker All resolved. - ~[Waiting] `#[panic_handler]` is not available in stable.~ - [Merged] #53619 - ~[Waiting] https://github.com/japaric/lm3s6965evb: does not compile on stable.~ - [OK] dependent crate ~`panic-abort`~ `panic-halt`: already moved to use `#[panic_handler]`. ## Update `#[panic_handler]` will be stabilized in Rust 1.30. CC @kennytm @jamesmunns @nerdyvaishali
- Loading branch information
Showing
7 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
# How to run this | ||
# $ ./x.py clean | ||
# $ ./x.py test --target thumbv7m-none-eabi src/test/run-make | ||
|
||
ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7m-none-eabi)) | ||
|
||
# For cargo setting | ||
export RUSTC := $(RUSTC_ORIGINAL) | ||
export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) | ||
# We need to be outside of 'src' dir in order to run cargo | ||
export WORK_DIR := $(TMPDIR) | ||
export HERE := $(shell pwd) | ||
|
||
## clean up unused env variables which might cause harm. | ||
unexport RUSTC_LINKER | ||
unexport RUSTC_BOOTSTRAP | ||
unexport RUST_BUILD_STAGE | ||
unexport RUST_TEST_THREADS | ||
unexport RUST_TEST_TMPDIR | ||
unexport AR | ||
unexport CC | ||
unexport CXX | ||
|
||
all: | ||
bash script.sh | ||
else | ||
all: | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[target.thumbv7m-none-eabi] | ||
# uncomment this to make `cargo run` execute programs on QEMU | ||
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" | ||
|
||
[target.thumbv6m-none-eabi] | ||
# uncomment this to make `cargo run` execute programs on QEMU | ||
# For now, we use cortex-m3 instead of cortex-m0 which are not supported by QEMU | ||
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" | ||
|
||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
# uncomment ONE of these three option to make `cargo run` start a GDB session | ||
# which option to pick depends on your system | ||
# runner = "arm-none-eabi-gdb -q -x openocd.gdb" | ||
# runner = "gdb-multiarch -q -x openocd.gdb" | ||
# runner = "gdb -q -x openocd.gdb" | ||
|
||
rustflags = [ | ||
# LLD (shipped with the Rust toolchain) is used as the default linker | ||
"-C", "link-arg=-Tlink.x", | ||
|
||
# if you run into problems with LLD switch to the GNU linker by commenting out | ||
# this line | ||
# "-C", "linker=arm-none-eabi-ld", | ||
|
||
# if you need to link to pre-compiled C libraries provided by a C toolchain | ||
# use GCC as the linker by commenting out both lines above and then | ||
# uncommenting the three lines below | ||
# "-C", "linker=arm-none-eabi-gcc", | ||
# "-C", "link-arg=-Wl,-Tlink.x", | ||
# "-C", "link-arg=-nostartfiles", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "example" | ||
version = "0.1.0" | ||
authors = ["Hideki Sekine <sekineh@me.com>"] | ||
# edition = "2018" | ||
|
||
[dependencies] | ||
cortex-m = "0.5.4" | ||
cortex-m-rt = "=0.5.4" | ||
panic-halt = "0.2.0" | ||
cortex-m-semihosting = "0.3.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Device specific memory layout */ | ||
|
||
/* This file is used to build the cortex-m-rt examples, | ||
but not other applications using cortex-m-rt. */ | ||
|
||
MEMORY | ||
{ | ||
/* FLASH and RAM are mandatory memory regions */ | ||
/* Update examples/data_overflow.rs if you change these sizes. */ | ||
FLASH : ORIGIN = 0x00000000, LENGTH = 256K | ||
RAM : ORIGIN = 0x20000000, LENGTH = 64K | ||
|
||
/* More memory regions can declared: for example this is a second RAM region */ | ||
/* CCRAM : ORIGIN = 0x10000000, LENGTH = 8K */ | ||
} | ||
|
||
/* The location of the stack can be overridden using the `_stack_start` symbol. | ||
By default it will be placed at the end of the RAM region */ | ||
/* _stack_start = ORIGIN(CCRAM) + LENGTH(CCRAM); */ | ||
|
||
/* The location of the .text section can be overridden using the `_stext` symbol. | ||
By default it will place after .vector_table */ | ||
/* _stext = ORIGIN(FLASH) + 0x40c; */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// #![feature(stdsimd)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate cortex_m; | ||
|
||
extern crate cortex_m_rt as rt; | ||
extern crate cortex_m_semihosting as semihosting; | ||
extern crate panic_halt; | ||
|
||
use core::fmt::Write; | ||
use cortex_m::asm; | ||
use rt::entry; | ||
|
||
entry!(main); | ||
|
||
fn main() -> ! { | ||
let x = 42; | ||
|
||
loop { | ||
asm::nop(); | ||
|
||
// write something through semihosting interface | ||
let mut hstdout = semihosting::hio::hstdout().unwrap(); | ||
write!(hstdout, "x = {}\n", x); | ||
|
||
// exit from qemu | ||
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
set -exuo pipefail | ||
|
||
CRATE=example | ||
|
||
env | sort | ||
mkdir -p $WORK_DIR | ||
pushd $WORK_DIR | ||
rm -rf $CRATE || echo OK | ||
cp -a $HERE/example . | ||
pushd $CRATE | ||
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \ | ||
$CARGO run --target $TARGET | grep "x = 42" | ||
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \ | ||
$CARGO run --target $TARGET --release | grep "x = 42" | ||
popd | ||
popd |