Skip to content

Commit b23a94f

Browse files
Merge pull request #200 from rust-embedded/vectored-rt
`riscv-rt`: Support for vectored mode interrupt handling
2 parents e9f43ae + 5f0b9c6 commit b23a94f

File tree

9 files changed

+443
-75
lines changed

9 files changed

+443
-75
lines changed

.github/workflows/riscv-rt.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ master, riscv-rt-asm ]
3+
branches: [ master ]
44
pull_request:
55
merge_group:
66

@@ -39,6 +39,8 @@ jobs:
3939
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --features=s-mode
4040
- name : Build (single-hart)
4141
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --features=single-hart
42+
- name : Build (v-trap)
43+
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --features=v-trap
4244
- name: Build (all features)
4345
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --all-features
4446

riscv-rt/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- Add `pre_init_trap` to detect early errors during the boot process.
13+
- Add `v-trap` feature to enable interrupt handling in vectored mode.
14+
- Add `interrupt` proc macro to help defining interrupt handlers.
15+
If `v-trap` feature is enabled, this macro also generates its corresponding trap.
1316

1417
### Changed
1518

1619
- Moved all the assembly code to `asm.rs`
1720
- Use `weak` symbols for functions such as `_mp_hook` or `_start_trap`
1821
- `abort` is now `weak`, so it is possible to link third-party libraries including this symbol.
1922
- Made `cfg` variable selection more robust for custom targets
23+
- `_start_trap_rust` now only deals with exceptions. When an interrupt is detected, it now calls
24+
to `_dispatch_interrupt`.
2025

2126
### Removed
2227

riscv-rt/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ license = "ISC"
1212
edition = "2021"
1313
links = "riscv-rt" # Prevent multiple versions of riscv-rt being linked
1414

15-
[features]
16-
s-mode = []
17-
single-hart = []
18-
1915
[dependencies]
2016
riscv = {path = "../riscv", version = "0.11.1"}
2117
riscv-rt-macros = { path = "macros", version = "0.2.1" }
2218

2319
[dev-dependencies]
2420
panic-halt = "0.2.0"
21+
22+
[features]
23+
s-mode = ["riscv-rt-macros/s-mode"]
24+
single-hart = []
25+
v-trap = ["riscv-rt-macros/v-trap"]

riscv-rt/examples/empty.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
extern crate panic_halt;
55
extern crate riscv_rt;
66

7-
use riscv_rt::entry;
7+
use riscv_rt::{entry, interrupt};
88

99
#[entry]
1010
fn main() -> ! {
1111
// do something here
1212
loop {}
1313
}
14+
15+
#[interrupt]
16+
fn MachineSoft() {
17+
// do something here
18+
loop {}
19+
}

riscv-rt/link.x.in

+23-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ PROVIDE(_max_hart_id = 0);
2828
PROVIDE(_hart_stack_size = 2K);
2929
PROVIDE(_heap_size = 0);
3030

31+
/** TRAP ENTRY POINTS **/
32+
33+
/* Default trap entry point. The riscv-rt crate provides a weak alias of this function,
34+
which saves caller saved registers, calls _start_trap_rust, restores caller saved registers
35+
and then returns. Users can override this alias by defining the symbol themselves */
36+
EXTERN(_start_trap);
37+
38+
/* Default interrupt trap entry point. When vectored trap mode is enabled,
39+
the riscv-rt crate provides an implementation of this function, which saves caller saved
40+
registers, calls the the DefaultHandler ISR, restores caller saved registers and returns. */
41+
PROVIDE(_start_DefaultHandler_trap = _start_trap);
42+
43+
/* When vectored trap mode is enabled, each interrupt source must implement its own
44+
trap entry point. By default, all interrupts start in _start_trap. However, users can
45+
override these alias by defining the symbol themselves */
46+
PROVIDE(_start_SupervisorSoft_trap = _start_DefaultHandler_trap);
47+
PROVIDE(_start_MachineSoft_trap = _start_DefaultHandler_trap);
48+
PROVIDE(_start_SupervisorTimer_trap = _start_DefaultHandler_trap);
49+
PROVIDE(_start_MachineTimer_trap = _start_DefaultHandler_trap);
50+
PROVIDE(_start_SupervisorExternal_trap = _start_DefaultHandler_trap);
51+
PROVIDE(_start_MachineExternal_trap = _start_DefaultHandler_trap);
52+
3153
/** EXCEPTION HANDLERS **/
3254

3355
/* Default exception handler. The riscv-rt crate provides a weak alias of this function,
@@ -44,7 +66,7 @@ PROVIDE(Breakpoint = ExceptionHandler);
4466
PROVIDE(LoadMisaligned = ExceptionHandler);
4567
PROVIDE(LoadFault = ExceptionHandler);
4668
PROVIDE(StoreMisaligned = ExceptionHandler);
47-
PROVIDE(StoreFault = ExceptionHandler);;
69+
PROVIDE(StoreFault = ExceptionHandler);
4870
PROVIDE(UserEnvCall = ExceptionHandler);
4971
PROVIDE(SupervisorEnvCall = ExceptionHandler);
5072
PROVIDE(MachineEnvCall = ExceptionHandler);

riscv-rt/macros/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ proc-macro2 = "1.0"
2222
[dependencies.syn]
2323
version = "1.0"
2424
features = ["extra-traits", "full"]
25+
26+
[features]
27+
s-mode = []
28+
v-trap = []

0 commit comments

Comments
 (0)