1+ use log:: warn;
12use proc_macro2:: TokenStream ;
23use 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
1719impl 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