Skip to content

Commit f8bb38a

Browse files
Revert "Merge branch 'master' into rename"
This reverts commit 2779d92, reversing changes made to 38fcabe.
1 parent 2779d92 commit f8bb38a

File tree

8 files changed

+54
-84
lines changed

8 files changed

+54
-84
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
### Changed
11-
12-
- Adapted to new `riscv` version.
13-
1410
## [v0.16.0] - 2025-09-08
1511

1612
### Added

riscv-rt/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ targets = [
2424
riscv-target-parser = { path = "../riscv-target-parser", version = "0.1.2" }
2525

2626
[dependencies]
27-
riscv = { path = "../riscv", version = "0.15.0", features = ["rt"] }
28-
riscv-types = { path = "../riscv-pac", version = "0.2.0" }
27+
riscv = { path = "../riscv", version = "0.15.0" }
28+
riscv-types = { path = "../riscv-types", version = "0.2.0" }
2929
riscv-rt-macros = { path = "macros", version = "0.6.0" }
3030

3131
defmt = { version = "1.0.1", optional = true }
@@ -38,7 +38,7 @@ pre-init = []
3838
post-init = []
3939
s-mode = ["riscv-rt-macros/s-mode"]
4040
single-hart = []
41-
v-trap = ["riscv-rt-macros/v-trap", "riscv/rt-v-trap"]
41+
v-trap = ["riscv-rt-macros/v-trap"]
4242
u-boot = ["riscv-rt-macros/u-boot", "single-hart"]
4343
no-interrupts = []
4444
no-exceptions = []

riscv-rt/src/interrupts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
//! you may need to opt out this module. To do so, activate the `no-interrupts` feature of the
1818
//! `riscv-rt` crate.
1919
20+
// In vectored mode, we also must provide a vector table
2021
#[riscv::pac_enum(unsafe CoreInterruptNumber)]
2122
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2223
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
23-
#[allow(dead_code)] // otherwise compiler complains about Interrupt not being used
2424
enum Interrupt {
2525
SupervisorSoft = 1,
2626
MachineSoft = 3,

riscv/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Added DCSR (Debug Control and Status Register) CSR support for the RISC-V
1313
- Add `miselect` CSR
1414
- Improved assembly macro handling in asm.rs
15-
- New `rt` and `rt-v-trap` features to opt-in `riscv-rt`-related code in `riscv::pac_enum` macro.
16-
17-
# Changed
18-
19-
- Now, `riscv::pac_enum` macro only includes trap-related code if `rt` or `rt-v-trap` features are enabled.
2015

2116
## [v0.15.0] - 2025-09-08
2217

riscv/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ targets = [
2323
default = ["riscv-macros"]
2424
s-mode = []
2525
critical-section-single-hart = ["critical-section/restore-state-bool"]
26-
rt = ["riscv-macros/rt"]
27-
rt-v-trap = ["rt", "riscv-macros/rt-v-trap"]
2826

2927
[dependencies]
3028
critical-section = "1.2.0"

riscv/macros/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ edition = "2021"
1515
[lib]
1616
proc-macro = true
1717

18-
[features]
19-
rt = []
20-
rt-v-trap = ["rt"]
21-
2218
[dependencies]
2319
proc-macro2 = "1.0"
2420
quote = "1.0"

riscv/macros/src/lib.rs

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use syn::{
1111
};
1212

1313
/// Struct to represent a function parameter.
14-
#[cfg(feature = "rt")]
1514
struct FunctionParam {
1615
/// Name of the parameter.
1716
param_name: TokenStream2,
@@ -21,7 +20,6 @@ struct FunctionParam {
2120

2221
/// Configuration parameters of a trap. It is useful to abstract the
2322
/// differences between exception handlers and core interrupt handlers.
24-
#[cfg(feature = "rt")]
2523
struct TrapConfig {
2624
/// Name of the default handler (e.g., `DefaultHandler` for core interrupts).
2725
default_handler: TokenStream2,
@@ -33,7 +31,6 @@ struct TrapConfig {
3331
handlers_array_name: TokenStream2,
3432
}
3533

36-
#[cfg(feature = "rt")]
3734
impl TrapConfig {
3835
/// Vector with all the input parameters expected when declaring extern handler functions
3936
fn extern_signature(&self) -> Vec<TokenStream2> {
@@ -110,7 +107,6 @@ impl PacTrait {
110107
}
111108

112109
/// For Exception or an Interrupt enums, it returns the trap configuration details.
113-
#[cfg(feature = "rt")]
114110
fn trap_config(&self) -> Option<TrapConfig> {
115111
match self {
116112
Self::Exception => Some(TrapConfig {
@@ -167,7 +163,6 @@ impl InterruptType {
167163
}
168164

169165
/// Returns a token stream representing the name of the array of interrupt service routines
170-
#[cfg(feature = "rt")]
171166
fn isr_array_name(&self) -> TokenStream2 {
172167
match self {
173168
Self::Core => quote!(__CORE_INTERRUPTS),
@@ -176,7 +171,6 @@ impl InterruptType {
176171
}
177172

178173
/// Returns a token stream representing the name of the interrupt dispatch function
179-
#[cfg(feature = "rt")]
180174
fn dispatch_fn_name(&self) -> TokenStream2 {
181175
match self {
182176
Self::Core => quote!(_dispatch_core_interrupt),
@@ -245,7 +239,6 @@ impl PacEnumItem {
245239
}
246240

247241
/// Returns a vector of token streams representing the interrupt handler functions
248-
#[cfg(feature = "rt")]
249242
fn handlers(&self, trap_config: &TrapConfig) -> Vec<TokenStream2> {
250243
let signature = trap_config.extern_signature();
251244
self.numbers
@@ -259,7 +252,6 @@ impl PacEnumItem {
259252
/// Returns a sorted vector of token streams representing all the elements of the interrupt array.
260253
/// If an interrupt number is not present in the enum, the corresponding element is `None`.
261254
/// Otherwise, it is `Some(<interrupt_handler>)`.
262-
#[cfg(feature = "rt")]
263255
fn handlers_array(&self) -> Vec<TokenStream2> {
264256
let mut vectors = vec![];
265257
for i in 0..=self.max_number {
@@ -272,7 +264,6 @@ impl PacEnumItem {
272264
vectors
273265
}
274266

275-
#[cfg(feature = "rt-v-trap")]
276267
fn vector_table(&self) -> TokenStream2 {
277268
let align = match std::env::var("RISCV_MTVEC_ALIGN") {
278269
Ok(x) => x.parse::<u32>().ok(),
@@ -289,7 +280,7 @@ impl PacEnumItem {
289280
};
290281
let mut asm = format!(
291282
r#"
292-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
283+
#[cfg(all(feature = "v-trap", any(target_arch = "riscv32", target_arch = "riscv64")))]
293284
core::arch::global_asm!("
294285
.section .trap.vector, \"ax\"
295286
.global _vector_table
@@ -337,6 +328,8 @@ core::arch::global_asm!("
337328
let max_discriminant = self.max_number;
338329
let valid_matches = self.valid_matches();
339330

331+
let is_core_interrupt = matches!(attr, PacTrait::Interrupt(InterruptType::Core));
332+
340333
// Push the trait implementation
341334
res.push(quote! {
342335
unsafe impl riscv::#trait_name for #name {
@@ -361,51 +354,54 @@ core::arch::global_asm!("
361354
res.push(quote! { unsafe impl riscv::#marker_trait_name for #name {} });
362355
}
363356

364-
#[cfg(feature = "rt")]
365357
if let Some(trap_config) = attr.trap_config() {
366-
match attr {
367-
#[cfg(feature = "rt-v-trap")]
368-
PacTrait::Interrupt(InterruptType::Core) => {
369-
res.push(self.vector_table());
358+
let default_handler = &trap_config.default_handler;
359+
let extern_signature = trap_config.extern_signature();
360+
let handler_input = trap_config.handler_input();
361+
let array_signature = trap_config.array_signature();
362+
let dispatch_fn_name = &trap_config.dispatch_fn_name;
363+
let dispatch_fn_args = &trap_config.dispatch_fn_signature();
364+
let vector_table = &trap_config.handlers_array_name;
365+
366+
let handlers = self.handlers(&trap_config);
367+
let interrupt_array = self.handlers_array();
368+
let cfg_v_trap = match is_core_interrupt {
369+
true => Some(quote!(#[cfg(not(feature = "v-trap"))])),
370+
false => None,
371+
};
372+
373+
// Push the interrupt handler functions and the interrupt array
374+
res.push(quote! {
375+
#cfg_v_trap
376+
extern "C" {
377+
#(#handlers;)*
370378
}
371-
_ => {
372-
let default_handler = &trap_config.default_handler;
373-
let extern_signature = trap_config.extern_signature();
374-
let handler_input = trap_config.handler_input();
375-
let array_signature = trap_config.array_signature();
376-
let dispatch_fn_name = &trap_config.dispatch_fn_name;
377-
let dispatch_fn_args = &trap_config.dispatch_fn_signature();
378-
let vector_table = &trap_config.handlers_array_name;
379-
380-
let handlers = self.handlers(&trap_config);
381-
let interrupt_array = self.handlers_array();
382-
383-
res.push(quote! {
384-
extern "C" {
385-
#(#handlers;)*
386-
}
387-
388-
#[doc(hidden)]
389-
#[no_mangle]
390-
pub static #vector_table: [Option<unsafe extern "C" fn(#(#array_signature),*)>; #max_discriminant + 1] = [
391-
#(#interrupt_array),*
392-
];
393-
394-
#[inline]
395-
#[no_mangle]
396-
unsafe extern "C" fn #dispatch_fn_name(#(#dispatch_fn_args),*) {
397-
extern "C" {
398-
fn #default_handler(#(#extern_signature),*);
399-
}
400-
401-
match #vector_table.get(code) {
402-
Some(Some(handler)) => handler(#(#handler_input),*),
403-
_ => #default_handler(#(#handler_input),*),
404-
}
405-
}
406-
});
379+
380+
#cfg_v_trap
381+
#[doc(hidden)]
382+
#[no_mangle]
383+
pub static #vector_table: [Option<unsafe extern "C" fn(#(#array_signature),*)>; #max_discriminant + 1] = [
384+
#(#interrupt_array),*
385+
];
386+
387+
#cfg_v_trap
388+
#[inline]
389+
#[no_mangle]
390+
unsafe extern "C" fn #dispatch_fn_name(#(#dispatch_fn_args),*) {
391+
extern "C" {
392+
fn #default_handler(#(#extern_signature),*);
393+
}
394+
395+
match #vector_table.get(code) {
396+
Some(Some(handler)) => handler(#(#handler_input),*),
397+
_ => #default_handler(#(#handler_input),*),
398+
}
407399
}
408-
}
400+
});
401+
}
402+
403+
if is_core_interrupt {
404+
res.push(self.vector_table());
409405
}
410406

411407
res
@@ -417,8 +413,8 @@ core::arch::global_asm!("
417413
/// As these traits are unsafe, the macro must be called with the `unsafe` keyword followed by the trait name.
418414
/// In this way, we warn callers that they must comply with the requirements of the trait.
419415
///
420-
/// The trait name must be one of `ExceptionNumber`, `CoreInterruptNumber`, `ExternalInterruptNumber`,
421-
/// `PriorityNumber`, or `HartIdNumber`.
416+
/// The trait name must be one of `ExceptionNumber`, `InterruptNumber`, `PriorityNumber`, or `HartIdNumber`.
417+
/// Marker traits `CoreInterruptNumber` and `ExternalInterruptNumber` cannot be implemented using this macro.
422418
///
423419
/// # Safety
424420
///

riscv/src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@
3131
//! and may cause functional problems in systems where some interrupts must NOT be disabled
3232
//! or critical sections are managed as part of an RTOS. In these cases, you should use
3333
//! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
34-
//!
35-
//! ## `rt`
36-
//!
37-
//! This feature enables code related to [`riscv-rt`](https://github.com/rust-embedded/riscv/tree/master/riscv-rt)
38-
//! runtime support in the `riscv::pac_enum` macro. Namely, it enables the generation of
39-
//! trap handler functions and dispatch functions.
40-
//!
41-
//! ## `rt-v-trap`
42-
//!
43-
//! This feature enables code related to vectored trap handling in addition to the `rt` feature.
44-
//! Namely, it enables the generation of a vector table and the corresponding assembly code for core interrupts.
4534
4635
#![no_std]
4736
#![allow(clippy::missing_safety_doc)]

0 commit comments

Comments
 (0)