Skip to content

Commit dac8766

Browse files
authored
Merge pull request #909 from romancardenas/master
Add `mtvec_align` for RISC-V
2 parents 12c144c + 0e17ebf commit dac8766

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
- Add `mtvec_align` field to `riscv_config` to configure the byte alignment of interrupt vector table.
1011
- Fix reexport path when "%s" inside "derivedFrom"
1112
- Force using rust edition 2021 in CI
1213
- Added lifetime ellision for `FieldWriter` where the explicit lifetimes are not necessary, which

src/config.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::{bail, Result};
2-
use proc_macro2::Span;
2+
use proc_macro2::{Span, TokenStream};
33
use std::{
44
collections::HashMap,
55
ops::{Deref, DerefMut},
@@ -46,6 +46,12 @@ pub struct Config {
4646
pub settings: Settings,
4747
}
4848

49+
impl Config {
50+
pub fn extra_build(&self) -> Option<TokenStream> {
51+
self.settings.extra_build()
52+
}
53+
}
54+
4955
#[allow(clippy::upper_case_acronyms)]
5056
#[allow(non_camel_case_types)]
5157
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -345,6 +351,10 @@ impl Settings {
345351
self.riscv_config = source.riscv_config;
346352
}
347353
}
354+
355+
pub fn extra_build(&self) -> Option<TokenStream> {
356+
self.riscv_config.as_ref().and_then(|cfg| cfg.extra_build())
357+
}
348358
}
349359

350360
#[derive(Clone, PartialEq, Eq, Debug)]

src/config/riscv.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use proc_macro2::TokenStream;
2+
use quote::quote;
3+
14
#[cfg_attr(feature = "serde", derive(serde::Deserialize), serde(default))]
25
#[derive(Clone, PartialEq, Eq, Debug, Default)]
36
#[non_exhaustive]
@@ -8,6 +11,22 @@ pub struct RiscvConfig {
811
pub harts: Vec<RiscvEnumItem>,
912
pub clint: Option<RiscvClintConfig>,
1013
pub plic: Option<RiscvPlicConfig>,
14+
pub mtvec_align: Option<usize>,
15+
}
16+
17+
impl RiscvConfig {
18+
pub fn extra_build(&self) -> Option<TokenStream> {
19+
self.mtvec_align.map(|align| {
20+
quote! {
21+
// 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+
);
26+
println!("cargo:rerun-if-env-changed=RISCV_MTVEC_ALIGN");
27+
}
28+
})
29+
}
1130
}
1231

1332
#[cfg_attr(feature = "serde", derive(serde::Deserialize), serde(default))]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ pub fn generate(input: &str, config: &Config) -> Result<Generation> {
671671
} else {
672672
Some(DeviceSpecific {
673673
device_x,
674-
build_rs: util::build_rs().to_string(),
674+
build_rs: util::build_rs(&config).to_string(),
675675
})
676676
};
677677

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@ Ignore this option if you are not building your own FPGA based soft-cores."),
366366
.contains(&config.target)
367367
{
368368
writeln!(File::create(path.join("device.x"))?, "{device_x}")?;
369-
writeln!(File::create(path.join("build.rs"))?, "{}", build_rs())?;
369+
writeln!(
370+
File::create(path.join("build.rs"))?,
371+
"{}",
372+
build_rs(&config)
373+
)?;
370374
}
371375

372376
if config.feature_group || config.feature_peripheral {

src/util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ impl U32Ext for u32 {
399399
}
400400
}
401401

402-
pub fn build_rs() -> TokenStream {
402+
pub fn build_rs(config: &Config) -> TokenStream {
403+
let extra_build = config.extra_build();
404+
403405
quote! {
404406
//! Builder file for Peripheral access crate generated by svd2rust tool
405407
@@ -419,6 +421,8 @@ pub fn build_rs() -> TokenStream {
419421
println!("cargo:rustc-link-search={}", out.display());
420422

421423
println!("cargo:rerun-if-changed=device.x");
424+
425+
#extra_build
422426
}
423427

424428
println!("cargo:rerun-if-changed=build.rs");

0 commit comments

Comments
 (0)