Skip to content

Commit 970ee2a

Browse files
committed
Add base_isa setting for RISC-V
1 parent 6b2dd03 commit 970ee2a

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1111
- Adapt RISC-V specific codegen for `riscv-peripheral` v0.3.0 rework
1212
- Include `riscv-peripheral` peripherals in `Peripherals` struct
1313
- Ensure `__INTERRUPTS` are `#[no_mangle]` on Xtensa.
14+
- Add `base_isa` field to `riscv_config` to allow the `riscv_rt::core_interrupt`
15+
macro to properly generate start trap assembly routines in vectored mode.
1416

1517
## [v0.36.1] - 2025-04-04
1618

src/config/riscv.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use log::warn;
12
use proc_macro2::TokenStream;
23
use quote::quote;
34

@@ -11,21 +12,38 @@ pub struct RiscvConfig {
1112
pub harts: Vec<RiscvEnumItem>,
1213
pub clint: Option<RiscvClintConfig>,
1314
pub plic: Option<RiscvPlicConfig>,
15+
pub base_isa: Option<String>,
1416
pub mtvec_align: Option<usize>,
1517
}
1618

1719
impl RiscvConfig {
1820
pub fn extra_build(&self) -> Option<TokenStream> {
19-
self.mtvec_align.map(|align| {
20-
quote! {
21+
let mut res = vec![];
22+
if let Some(base_isa) = self.base_isa.as_ref() {
23+
let base_isa = base_isa.to_lowercase();
24+
let rustcv_env = format!("cargo:rustc-env=RISCV_RT_BASE_ISA={base_isa}");
25+
res.push(quote! {
26+
// set environment variable RISCV_BASE_ISA to enforce correct base ISA.
27+
println!(#rustcv_env);
28+
println!("cargo:rerun-if-env-changed=RISCV_RT_BASE_ISA");
29+
});
30+
} else {
31+
warn!("No base RISC-V ISA specified in settings file.");
32+
warn!("If your target supports vectored mode, you must specify the base ISA.");
33+
warn!("Otherwise, `riscv-rt` macros will not provide start trap routines to core interrupt handlers");
34+
}
35+
if let Some(align) = self.mtvec_align {
36+
let rustcv_env = format!("cargo:rustc-env=RISCV_MTVEC_ALIGN={align}");
37+
res.push(quote! {
2138
// set environment variable RISCV_MTVEC_ALIGN enfoce correct byte alignment of interrupt vector.
22-
println!(
23-
"cargo:rustc-env=RISCV_MTVEC_ALIGN={}",
24-
#align
25-
);
39+
println!(#rustcv_env);
2640
println!("cargo:rerun-if-env-changed=RISCV_MTVEC_ALIGN");
27-
}
28-
})
41+
});
42+
}
43+
match res.is_empty() {
44+
true => None,
45+
false => Some(quote! { #(#res)* }),
46+
}
2947
}
3048
}
3149

@@ -66,3 +84,15 @@ pub struct RiscvPlicConfig {
6684
pub core_interrupt: Option<String>,
6785
pub hart_id: Option<String>,
6886
}
87+
88+
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
89+
pub enum RiscvBaseIsa {
90+
#[cfg_attr(feature = "serde", serde(rename = "rv32i"))]
91+
Rv32I,
92+
#[cfg_attr(feature = "serde", serde(rename = "rv32e"))]
93+
Rv32E,
94+
#[cfg_attr(feature = "serde", serde(rename = "rv64i"))]
95+
Rv64I,
96+
#[cfg_attr(feature = "serde", serde(rename = "rv64e"))]
97+
Rv64E,
98+
}

0 commit comments

Comments
 (0)