Skip to content

Commit 7854e96

Browse files
bors[bot]japaric
andcommitted
Merge #90
90: turn macros into attributes r=adamgreig a=japaric This is a PoC implementation of RFC #82. Assuming that we are OK with this implementation we should add some compile fail tests (e.g. using a function with the wrong signature as the entry point) before landing this. Look at the diff of the examples to get an overview of the changes. cc @rust-embedded/cortex-m Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 0fb0510 + 31713ab commit 7854e96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1205
-319
lines changed

cortex-m-rt/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/*.rs.bk
2+
.#*
23
Cargo.lock
34
bin/*.after
45
bin/*.before

cortex-m-rt/.travis.yml

+21-16
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ language: rust
33
matrix:
44
include:
55
- env: TARGET=x86_64-unknown-linux-gnu
6-
rust: stable
7-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
8-
9-
- env: TARGET=thumbv6m-none-eabi
10-
rust: stable
11-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
12-
13-
- env: TARGET=thumbv7m-none-eabi
14-
rust: stable
15-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
16-
17-
- env: TARGET=thumbv7em-none-eabi
18-
rust: stable
6+
# TODO switch to 1.30-beta
7+
rust: nightly
198
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
209

21-
- env: TARGET=thumbv7em-none-eabihf
22-
rust: stable
23-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
10+
# TODO enable when 1.30-beta is out
11+
# - env: TARGET=thumbv6m-none-eabi
12+
# rust: beta
13+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
14+
15+
# TODO enable when 1.30-beta is out
16+
# - env: TARGET=thumbv7m-none-eabi
17+
# rust: beta
18+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
19+
20+
# TODO enable when 1.30-beta is out
21+
# - env: TARGET=thumbv7em-none-eabi
22+
# rust: beta
23+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
24+
25+
# TODO enable when 1.30-beta is out
26+
# - env: TARGET=thumbv7em-none-eabihf
27+
# rust: beta
28+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2429

2530
- env: TARGET=thumbv6m-none-eabi
2631
rust: nightly

cortex-m-rt/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ version = "0.5.3"
1212

1313
[dependencies]
1414
r0 = "0.2.1"
15+
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }
1516

1617
[dev-dependencies]
17-
panic-semihosting = "0.3.0"
18-
panic-abort = "0.2.0"
1918
cortex-m = "0.5.4"
19+
panic-abort = "0.3.0"
20+
panic-semihosting = "0.4.0"
21+
22+
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
23+
compiletest_rs = "0.3.14"
2024

2125
[features]
2226
device = []

cortex-m-rt/ci/script.sh

+15-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@ main() {
55

66
cargo check --target $TARGET --features device
77

8+
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
9+
( cd macros && cargo check && cargo test )
10+
11+
cargo test --test compiletest
12+
fi
13+
814
local examples=(
915
alignment
10-
minimal
16+
divergent-default-handler
17+
divergent-exception
18+
entry-static
1119
main
20+
minimal
1221
override-exception
1322
pre_init
1423
state
24+
unsafe-default-handler
25+
unsafe-hard-fault
26+
unsafe-entry
27+
unsafe-exception
1528
)
1629
local fail_examples=(
1730
data_overflow
1831
)
19-
if [ $TRAVIS_RUST_VERSION = nightly ]; then
32+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
2033
# linking with GNU LD
2134
for ex in "${examples[@]}"; do
2235
cargo rustc --target $TARGET --example $ex -- \
@@ -48,29 +61,23 @@ main() {
4861
# linking with rustc's LLD
4962
for ex in "${examples[@]}"; do
5063
cargo rustc --target $TARGET --example $ex -- \
51-
-C linker=rust-lld \
5264
-C link-arg=-Tlink.x
5365

5466
cargo rustc --target $TARGET --example $ex --release -- \
55-
-C linker=rust-lld \
5667
-C link-arg=-Tlink.x
5768
done
5869
for ex in "${fail_examples[@]}"; do
5970
! cargo rustc --target $TARGET --example $ex -- \
60-
-C linker=rust-lld \
6171
-C link-arg=-Tlink.x
6272

6373
! cargo rustc --target $TARGET --example $ex --release -- \
64-
-C linker=rust-lld \
6574
-C link-arg=-Tlink.x
6675
done
6776

6877
cargo rustc --target $TARGET --example device --features device -- \
69-
-C linker=rust-lld \
7078
-C link-arg=-Tlink.x
7179

7280
cargo rustc --target $TARGET --example device --features device --release -- \
73-
-C linker=rust-lld \
7481
-C link-arg=-Tlink.x
7582
fi
7683

cortex-m-rt/examples/alignment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#![no_main]
55
#![no_std]
66

7-
#[macro_use(entry)]
87
extern crate cortex_m_rt as rt;
98
extern crate panic_abort;
109

1110
use core::ptr;
1211

13-
entry!(main);
12+
use rt::entry;
1413

1514
static mut BSS1: u16 = 0;
1615
static mut BSS2: u8 = 0;
@@ -19,6 +18,7 @@ static mut DATA2: u16 = 1;
1918
static RODATA1: &[u8; 3] = b"012";
2019
static RODATA2: &[u8; 2] = b"34";
2120

21+
#[entry]
2222
fn main() -> ! {
2323
unsafe {
2424
let _bss1 = ptr::read_volatile(&BSS1);

cortex-m-rt/examples/data_overflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_abort;
1110

1211
use core::ptr;
1312

14-
entry!(main);
13+
use rt::entry;
1514

1615
// This large static array uses most of .rodata
1716
static RODATA: [u8; 48*1024] = [1u8; 48*1024];
@@ -20,6 +19,7 @@ static RODATA: [u8; 48*1024] = [1u8; 48*1024];
2019
// without also overflowing RAM.
2120
static mut DATA: [u8; 16*1024] = [1u8; 16*1024];
2221

22+
#[entry]
2323
fn main() -> ! {
2424
unsafe {
2525
let _bigdata = ptr::read_volatile(&RODATA as *const u8);

cortex-m-rt/examples/device.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::entry;
1412

13+
#[entry]
1514
fn main() -> ! {
1615
loop {}
1716
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![deny(unsafe_code)]
2+
#![deny(warnings)]
3+
#![no_main]
4+
#![no_std]
5+
6+
extern crate cortex_m_rt;
7+
extern crate panic_semihosting;
8+
9+
use cortex_m_rt::{entry, exception};
10+
11+
#[entry]
12+
fn foo() -> ! {
13+
loop {}
14+
}
15+
16+
#[exception]
17+
fn DefaultHandler(_irqn: i16) -> ! {
18+
loop {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![deny(warnings)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate cortex_m_rt;
6+
extern crate panic_semihosting;
7+
8+
use cortex_m_rt::{entry, exception};
9+
10+
#[entry]
11+
fn foo() -> ! {
12+
loop {}
13+
}
14+
15+
#[exception]
16+
fn SysTick() -> ! {
17+
loop {}
18+
}

cortex-m-rt/examples/entry-static.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! `static mut` variables local to the entry point are safe to use
2+
3+
#![deny(unsafe_code)]
4+
#![deny(warnings)]
5+
#![no_main]
6+
#![no_std]
7+
8+
extern crate cortex_m_rt as rt;
9+
extern crate panic_semihosting;
10+
11+
use rt::entry;
12+
13+
#[entry]
14+
fn main() -> ! {
15+
static mut COUNT: u32 = 0;
16+
17+
loop {
18+
*COUNT += 1;
19+
}
20+
}

cortex-m-rt/examples/minimal.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::entry;
1412

13+
// the program entry point
14+
#[entry]
1515
fn main() -> ! {
1616
loop {}
1717
}

cortex-m-rt/examples/override-exception.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,24 @@
66
#![no_std]
77

88
extern crate cortex_m;
9-
#[macro_use(entry, exception)]
109
extern crate cortex_m_rt as rt;
1110
extern crate panic_semihosting;
1211

1312
use cortex_m::asm;
14-
use rt::ExceptionFrame;
15-
16-
// the program entry point
17-
entry!(main);
13+
use rt::{entry, exception, ExceptionFrame};
1814

15+
#[entry]
1916
fn main() -> ! {
2017
loop {}
2118
}
2219

23-
exception!(*, default_handler);
24-
25-
fn default_handler(_irqn: i16) {
20+
#[exception]
21+
fn DefaultHandler(_irqn: i16) {
2622
asm::bkpt();
2723
}
2824

29-
exception!(HardFault, hard_fault);
30-
31-
fn hard_fault(_ef: &ExceptionFrame) -> ! {
25+
#[exception]
26+
fn HardFault(_ef: &ExceptionFrame) -> ! {
3227
asm::bkpt();
3328

3429
loop {}

cortex-m-rt/examples/pre_init.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
#![no_main]
55
#![no_std]
66

7-
#[macro_use(entry, pre_init)]
87
extern crate cortex_m_rt as rt;
98
extern crate panic_semihosting;
109

11-
pre_init!(disable_watchdog);
10+
use rt::{entry, pre_init};
1211

12+
#[pre_init]
1313
unsafe fn disable_watchdog() {
1414
// Do what you need to disable the watchdog.
1515
}
1616

17-
// the program entry point
18-
entry!(main);
19-
17+
#[entry]
2018
fn main() -> ! {
2119
loop {}
2220
}

cortex-m-rt/examples/state.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry, exception)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::{entry, exception};
1412

13+
#[entry]
1514
fn main() -> ! {
1615
loop {}
1716
}
1817

1918
// exception handler with state
20-
exception!(SysTick, sys_tick, state: u32 = 0);
19+
#[exception]
20+
fn SysTick() {
21+
static mut STATE: u32 = 0;
2122

22-
fn sys_tick(state: &mut u32) {
23-
*state += 1;
23+
*STATE += 1;
2424
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![deny(warnings)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate cortex_m_rt;
6+
extern crate panic_semihosting;
7+
8+
use cortex_m_rt::{entry, exception};
9+
10+
#[entry]
11+
fn foo() -> ! {
12+
loop {}
13+
}
14+
15+
#[exception]
16+
unsafe fn DefaultHandler(_irqn: i16) {}

cortex-m-rt/examples/unsafe-entry.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![deny(warnings)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate cortex_m_rt;
6+
extern crate panic_semihosting;
7+
8+
use cortex_m_rt::entry;
9+
10+
#[entry]
11+
unsafe fn foo() -> ! {
12+
loop {}
13+
}

0 commit comments

Comments
 (0)