Skip to content

Commit b2183c6

Browse files
Merge branch 'master' into add-peripheral
2 parents 5b012c0 + c0ce676 commit b2183c6

29 files changed

+1386
-131
lines changed

.github/workflows/changelog.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ jobs:
1919
filters: |
2020
riscv:
2121
- 'riscv/**'
22-
riscv-rt:
23-
- 'riscv-rt/**'
2422
riscv-pac:
2523
- 'riscv-pac/**'
2624
riscv-peripheral:
2725
- 'riscv-peripheral/**'
26+
riscv-rt:
27+
- 'riscv-rt/**'
28+
riscv-semihosting:
29+
- 'riscv-semihosting/**'
2830
2931
- name: Check for CHANGELOG.md (riscv)
3032
if: steps.changes.outputs.riscv == 'true'
@@ -34,6 +36,14 @@ jobs:
3436
skipLabels: 'skip changelog'
3537
missingUpdateErrorMessage: 'Please add a changelog entry in the riscv/CHANGELOG.md file.'
3638

39+
- name: Check for CHANGELOG.md (riscv-pac)
40+
if: steps.changes.outputs.riscv-pac == 'true'
41+
uses: dangoslen/changelog-enforcer@v3
42+
with:
43+
changeLogPath: ./riscv-pac/CHANGELOG.md
44+
skipLabels: 'skip changelog'
45+
missingUpdateErrorMessage: 'Please add a changelog entry in the riscv-pac/CHANGELOG.md file.'
46+
3747
- name: Check for CHANGELOG.md (riscv-rt)
3848
if: steps.changes.outputs.riscv-rt == 'true'
3949
uses: dangoslen/changelog-enforcer@v3
@@ -42,14 +52,14 @@ jobs:
4252
skipLabels: 'skip changelog'
4353
missingUpdateErrorMessage: 'Please add a changelog entry in the riscv-rt/CHANGELOG.md file.'
4454

45-
- name: Check for CHANGELOG.md (riscv-pac)
46-
if: steps.changes.outputs.riscv-pac == 'true'
55+
- name: Check for CHANGELOG.md (riscv-semihosting)
56+
if: steps.changes.outputs.riscv-semihosting == 'true'
4757
uses: dangoslen/changelog-enforcer@v3
4858
with:
49-
changeLogPath: ./riscv-pac/CHANGELOG.md
59+
changeLogPath: ./riscv-semihosting/CHANGELOG.md
5060
skipLabels: 'skip changelog'
51-
missingUpdateErrorMessage: 'Please add a changelog entry in the riscv-pac/CHANGELOG.md file.'
52-
61+
missingUpdateErrorMessage: 'Please add a changelog entry in the riscv-semihosting/CHANGELOG.md file.'
62+
5363
- name: Check for CHANGELOG.md (riscv-peripheral)
5464
if: steps.changes.outputs.riscv-peripheral == 'true'
5565
uses: dangoslen/changelog-enforcer@v3

.github/workflows/riscv-rt.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ jobs:
3535
targets: ${{ matrix.target }}
3636
- name: Build (no features)
3737
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }}
38-
- name : Build example (s-mode)
38+
- name : Build (s-mode)
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
40-
- name : Build example (single-hart)
40+
- 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 example (all features)
42+
- name: Build (all features)
4343
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --all-features
4444

4545
# Job to check that all the builds succeeded
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
on:
2+
push:
3+
branches: [ master ]
4+
pull_request:
5+
merge_group:
6+
7+
name: Build check (riscv-semihosting)
8+
9+
jobs:
10+
# We check that the crate builds and links for all the toolchains and targets.
11+
build-riscv:
12+
strategy:
13+
matrix:
14+
# All generated code should be running on stable now, MRSV is 1.60.0
15+
toolchain: [ stable, nightly, 1.60.0 ]
16+
target:
17+
- riscv32i-unknown-none-elf
18+
- riscv32imc-unknown-none-elf
19+
- riscv32imac-unknown-none-elf
20+
- riscv64imac-unknown-none-elf
21+
- riscv64gc-unknown-none-elf
22+
include:
23+
# Nightly is only for reference and allowed to fail
24+
- toolchain: nightly
25+
experimental: true
26+
runs-on: ubuntu-latest
27+
continue-on-error: ${{ matrix.experimental || false }}
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: dtolnay/rust-toolchain@master
31+
with:
32+
toolchain: ${{ matrix.toolchain }}
33+
targets: ${{ matrix.target }}
34+
- name: Build (M-mode)
35+
run: cargo build --package riscv-semihosting --target ${{ matrix.target }}
36+
- name: Build (U-mode)
37+
run: cargo build --package riscv-semihosting --target ${{ matrix.target }} --features=u-mode
38+
- name: Build (no semihosting)
39+
run: cargo build --package riscv-semihosting --target ${{ matrix.target }} --features=no-semihosting
40+
41+
# On MacOS, Ubuntu, and Windows, we at least make sure that the crate builds and links.
42+
build-others:
43+
strategy:
44+
matrix:
45+
os: [ macos-latest, ubuntu-latest, windows-latest ]
46+
runs-on: ${{ matrix.os }}
47+
steps:
48+
- uses: actions/checkout@v3
49+
- uses: dtolnay/rust-toolchain@stable
50+
- name: Build (no features)
51+
run: cargo build --package riscv-semihosting
52+
- name: Build (all features)
53+
run: cargo build --package riscv-semihosting --all-features
54+
55+
# Job to check that all the builds succeeded
56+
build-check:
57+
needs:
58+
- build-riscv
59+
- build-others
60+
runs-on: ubuntu-latest
61+
if: always()
62+
steps:
63+
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

.github/workflows/riscv.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ jobs:
3131
with:
3232
toolchain: ${{ matrix.toolchain }}
3333
targets: ${{ matrix.target }}
34-
- name: Build (no features)
34+
- name: Build (M-mode)
3535
run: cargo build --package riscv --target ${{ matrix.target }}
36+
- name: Build (M-mode, critical section)
37+
run: cargo build --package riscv --target ${{ matrix.target }} --features=critical-section-single-hart
38+
- name: Build (S-mode)
39+
run: cargo build --package riscv --target ${{ matrix.target }} --features=s-mode
3640
- name: Build (all features)
3741
run: cargo build --package riscv --target ${{ matrix.target }} --all-features
3842

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ members = [
55
"riscv-pac",
66
"riscv-peripheral",
77
"riscv-rt",
8+
"riscv-semihosting",
89
]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository contains various crates useful for writing Rust programs on RISC
66
* [`riscv-pac`]: Common traits to be implemented by RISC-V PACs
77
* [`riscv-peripheral`]: Interfaces for standard RISC-V peripherals
88
* [`riscv-rt`]: Startup code and interrupt handling
9-
9+
* [`riscv-semihosting`]: Semihosting for RISC-V processors
1010

1111
This project is developed and maintained by the [RISC-V team][team].
1212

@@ -26,5 +26,6 @@ to intervene to uphold that code of conduct.
2626
[`riscv-pac`]: https://crates.io/crates/riscv-pac
2727
[`riscv-peripheral`]: https://crates.io/crates/riscv-peripheral
2828
[`riscv-rt`]: https://crates.io/crates/riscv-rt
29+
[`riscv-semihosting`]: https://crates.io/crates/riscv-semihosting
2930
[team]: https://github.com/rust-embedded/wg#the-risc-v-team
3031
[CoC]: CODE_OF_CONDUCT.md

riscv-rt/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- Add `links` field in `Cargo.toml`
13+
- Add FPU initialization
14+
- Static array for vectored-like handling of exceptions
1215
- New GitHub workflow for checking invalid labels in PRs
1316
- New GitHub workflow for checking modifications on CHANGELOG.md
1417
- New GitHub workflow for checking clippy lints in PRs
1518
- Optional cargo feature `single-hart` for single CPU targets
1619

1720
### Changed
1821

22+
- Removed U-mode interrupts to align with latest RISC-V specification
23+
- Changed `Vector` union. Now, it uses `Option<fn>`, which is more idiomatic in Rust
1924
- Removed riscv-target dependency for build
2025
- Upgrade rust-version to 1.60
2126
- Cargo workspace for riscv and riscv-rt

riscv-rt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ documentation = "https://docs.rs/riscv-rt"
1010
keywords = ["riscv", "runtime", "startup"]
1111
license = "ISC"
1212
edition = "2021"
13+
links = "riscv-rt" # Prevent multiple versions of riscv-rt being linked
1314

1415
[features]
1516
s-mode = []

riscv-rt/build.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn add_linker_script(arch_width: u32) -> io::Result<()> {
1818
}
1919

2020
/// Parse the target RISC-V architecture and returns its bit width and the extension set
21-
fn parse_target(target: &str) -> (u32, HashSet<char>) {
21+
fn parse_target(target: &str, cargo_flags: &str) -> (u32, HashSet<char>) {
2222
// isolate bit width and extensions from the rest of the target information
2323
let arch = target
2424
.trim_start_matches("riscv")
@@ -43,18 +43,46 @@ fn parse_target(target: &str) -> (u32, HashSet<char>) {
4343
extensions.insert('d');
4444
}
4545

46+
let cargo_flags = cargo_flags
47+
.split(0x1fu8 as char)
48+
.filter(|arg| !arg.is_empty());
49+
50+
cargo_flags
51+
.filter(|k| k.starts_with("target-feature="))
52+
.flat_map(|str| {
53+
let flags = str.split('=').collect::<Vec<&str>>()[1];
54+
flags.split(',')
55+
})
56+
.for_each(|feature| {
57+
let chars = feature.chars().collect::<Vec<char>>();
58+
match chars[0] {
59+
'+' => {
60+
extensions.insert(chars[1]);
61+
}
62+
'-' => {
63+
extensions.remove(&chars[1]);
64+
}
65+
_ => {
66+
panic!("Unsupported target feature operation");
67+
}
68+
}
69+
});
70+
4671
(bits, extensions)
4772
}
4873

4974
fn main() {
5075
let target = env::var("TARGET").unwrap();
76+
let cargo_flags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();
5177
let _name = env::var("CARGO_PKG_NAME").unwrap();
5278

5379
// set configuration flags depending on the target
5480
if target.starts_with("riscv") {
5581
println!("cargo:rustc-cfg=riscv");
5682

57-
let (bits, extensions) = parse_target(&target);
83+
// This is required until target_arch & target_feature risc-v work is
84+
// stable and in-use (rust 1.75.0)
85+
let (bits, extensions) = parse_target(&target, &cargo_flags);
5886

5987
// generate the linker script and expose the ISA width
6088
let arch_width = match bits {

riscv-rt/link.x.in

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@ PROVIDE(_max_hart_id = 0);
2828
PROVIDE(_hart_stack_size = 2K);
2929
PROVIDE(_heap_size = 0);
3030

31-
PROVIDE(UserSoft = DefaultHandler);
31+
PROVIDE(InstructionMisaligned = ExceptionHandler);
32+
PROVIDE(InstructionFault = ExceptionHandler);
33+
PROVIDE(IllegalInstruction = ExceptionHandler);
34+
PROVIDE(Breakpoint = ExceptionHandler);
35+
PROVIDE(LoadMisaligned = ExceptionHandler);
36+
PROVIDE(LoadFault = ExceptionHandler);
37+
PROVIDE(StoreMisaligned = ExceptionHandler);
38+
PROVIDE(StoreFault = ExceptionHandler);;
39+
PROVIDE(UserEnvCall = ExceptionHandler);
40+
PROVIDE(SupervisorEnvCall = ExceptionHandler);
41+
PROVIDE(MachineEnvCall = ExceptionHandler);
42+
PROVIDE(InstructionPageFault = ExceptionHandler);
43+
PROVIDE(LoadPageFault = ExceptionHandler);
44+
PROVIDE(StorePageFault = ExceptionHandler);
45+
3246
PROVIDE(SupervisorSoft = DefaultHandler);
3347
PROVIDE(MachineSoft = DefaultHandler);
34-
PROVIDE(UserTimer = DefaultHandler);
3548
PROVIDE(SupervisorTimer = DefaultHandler);
3649
PROVIDE(MachineTimer = DefaultHandler);
37-
PROVIDE(UserExternal = DefaultHandler);
3850
PROVIDE(SupervisorExternal = DefaultHandler);
3951
PROVIDE(MachineExternal = DefaultHandler);
4052

0 commit comments

Comments
 (0)