Skip to content

Commit e0f6994

Browse files
committed
Adapt riscv to edition 2024
1 parent e10133a commit e0f6994

27 files changed

+113
-106
lines changed

.github/workflows/riscv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
build-riscv:
1212
strategy:
1313
matrix:
14-
# All generated code should be running on stable now, MRSV is 1.67.0
15-
toolchain: [ stable, nightly, 1.67.0 ]
14+
# All generated code should be running on stable now, MRSV is 1.85.0
15+
toolchain: [ stable, nightly, 1.85.0 ]
1616
target:
1717
- riscv32i-unknown-none-elf
1818
- riscv32imc-unknown-none-elf

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- Use `cfg(any(target_arch = "riscv32", target_arch = "riscv64"))` instead of `cfg(riscv)`.
13+
- Update to Rust edition 2024 (MSRV 1.85)
1314

1415
### Removed
1516

riscv/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "riscv"
33
version = "0.14.0"
4-
edition = "2021"
5-
rust-version = "1.67"
4+
edition = "2024"
5+
rust-version = "1.85"
66
repository = "https://github.com/rust-embedded/riscv"
77
authors = ["The RISC-V Team <risc-v@teams.rust-embedded.org>"]
88
categories = ["embedded", "hardware-support", "no-std"]

riscv/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [RISC-V team][team].
1111

1212
## Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.61 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.85 and up. It **won't**
1515
compile with older versions but that may change in any new patch release.
1616

1717
## License

riscv/macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
1010
name = "riscv-macros"
1111
repository = "https://github.com/rust-embedded/riscv"
1212
version = "0.2.0"
13-
edition = "2021"
13+
edition = "2024"
1414

1515
[lib]
1616
proc-macro = true

riscv/macros/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use quote::quote;
44
use std::collections::HashMap;
55
use std::str::FromStr;
66
use syn::{
7+
Data, DeriveInput, Ident, Token,
78
parse::{Parse, ParseStream},
89
parse_macro_input,
910
spanned::Spanned,
10-
Data, DeriveInput, Ident, Token,
1111
};
1212

1313
/// Struct to represent a function parameter.
@@ -275,7 +275,7 @@ impl PacEnumItem {
275275
_ => {
276276
return quote!(compile_error!(
277277
"RISCV_MTVEC_ALIGN is not a power of 2 (minimum 4)"
278-
))
278+
));
279279
}
280280
};
281281
let mut asm = format!(
@@ -373,28 +373,28 @@ core::arch::global_asm!("
373373
// Push the interrupt handler functions and the interrupt array
374374
res.push(quote! {
375375
#cfg_v_trap
376-
extern "C" {
376+
unsafe extern "C" {
377377
#(#handlers;)*
378378
}
379379

380380
#cfg_v_trap
381381
#[doc(hidden)]
382-
#[no_mangle]
382+
#[unsafe(no_mangle)]
383383
pub static #vector_table: [Option<unsafe extern "C" fn(#(#array_signature),*)>; #max_discriminant + 1] = [
384384
#(#interrupt_array),*
385385
];
386386

387387
#cfg_v_trap
388388
#[inline]
389-
#[no_mangle]
389+
#[unsafe(no_mangle)]
390390
unsafe extern "C" fn #dispatch_fn_name(#(#dispatch_fn_args),*) {
391-
extern "C" {
391+
unsafe extern "C" {
392392
fn #default_handler(#(#extern_signature),*);
393393
}
394394

395395
match #vector_table.get(code) {
396-
Some(Some(handler)) => handler(#(#handler_input),*),
397-
_ => #default_handler(#(#handler_input),*),
396+
Some(Some(handler)) => unsafe { handler(#(#handler_input),*) },
397+
_ => unsafe { #default_handler(#(#handler_input),*) },
398398
}
399399
}
400400
});

riscv/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! instruction {
66
#[inline(always)]
77
pub unsafe fn $fnname() {
88
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
9-
core::arch::asm!($asm, $($options)*);
9+
unsafe { core::arch::asm!($asm, $($options)*) };
1010
#[cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))]
1111
unimplemented!();
1212
}

riscv/src/critical_section.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use critical_section::{set_impl, Impl, RawRestoreState};
1+
use critical_section::{Impl, RawRestoreState, set_impl};
22

33
use crate::interrupt;
44

riscv/src/interrupt/machine.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::{
33
register::{mcause, mepc, mstatus},
44
};
55
use riscv_pac::{
6-
result::{Error, Result},
76
CoreInterruptNumber, ExceptionNumber, InterruptNumber,
7+
result::{Error, Result},
88
};
99

1010
/// Standard M-mode RISC-V interrupts
@@ -110,7 +110,7 @@ pub fn disable() {
110110
/// Do not call this function inside a critical section.
111111
#[inline]
112112
pub unsafe fn enable() {
113-
mstatus::set_mie()
113+
unsafe { mstatus::set_mie() }
114114
}
115115

116116
/// Retrieves the cause of a trap in the current hart (machine mode).
@@ -181,7 +181,7 @@ where
181181
let mepc = mepc::read();
182182

183183
// enable interrupts to allow nested interrupts
184-
enable();
184+
unsafe { enable() };
185185

186186
let r = f();
187187

@@ -193,10 +193,12 @@ where
193193

194194
// Restore MSTATUS.PIE, MSTATUS.MPP, and SEPC
195195
if mstatus.mpie() {
196-
mstatus::set_mpie();
196+
unsafe { mstatus::set_mpie() };
197197
}
198-
mstatus::set_mpp(mstatus.mpp());
199-
mepc::write(mepc);
198+
unsafe {
199+
mstatus::set_mpp(mstatus.mpp());
200+
mepc::write(mepc);
201+
};
200202

201203
r
202204
}

riscv/src/interrupt/supervisor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::{
33
register::{scause, sepc, sstatus},
44
};
55
use riscv_pac::{
6-
result::{Error, Result},
76
CoreInterruptNumber, ExceptionNumber, InterruptNumber,
7+
result::{Error, Result},
88
};
99

1010
/// Interrupt
@@ -102,7 +102,7 @@ pub fn disable() {
102102
/// Do not call this function inside a critical section.
103103
#[inline]
104104
pub unsafe fn enable() {
105-
sstatus::set_sie()
105+
unsafe { sstatus::set_sie() }
106106
}
107107

108108
/// Retrieves the cause of a trap in the current hart (supervisor mode).
@@ -173,7 +173,7 @@ where
173173
let sepc = sepc::read();
174174

175175
// enable interrupts to allow nested interrupts
176-
enable();
176+
unsafe { enable() };
177177

178178
let r = f();
179179

@@ -185,10 +185,12 @@ where
185185

186186
// Restore SSTATUS.SPIE, SSTATUS.SPP, and SEPC
187187
if sstatus.spie() {
188-
sstatus::set_spie();
188+
unsafe { sstatus::set_spie() };
189+
}
190+
unsafe {
191+
sstatus::set_spp(sstatus.spp());
192+
sepc::write(sepc);
189193
}
190-
sstatus::set_spp(sstatus.spp());
191-
sepc::write(sepc);
192194

193195
r
194196
}

0 commit comments

Comments
 (0)