1
+ use log:: warn;
1
2
use proc_macro2:: TokenStream ;
2
3
use quote:: quote;
3
4
@@ -11,21 +12,38 @@ pub struct RiscvConfig {
11
12
pub harts : Vec < RiscvEnumItem > ,
12
13
pub clint : Option < RiscvClintConfig > ,
13
14
pub plic : Option < RiscvPlicConfig > ,
15
+ pub base_isa : Option < String > ,
14
16
pub mtvec_align : Option < usize > ,
15
17
}
16
18
17
19
impl RiscvConfig {
18
20
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 ! {
21
38
// 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) ;
26
40
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
+ }
29
47
}
30
48
}
31
49
@@ -66,3 +84,15 @@ pub struct RiscvPlicConfig {
66
84
pub core_interrupt : Option < String > ,
67
85
pub hart_id : Option < String > ,
68
86
}
87
+
88
+ #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) ) ]
89
+ pub enum RiscvBaseIsa {
90
+ #[ serde( rename = "rv32i" ) ]
91
+ Rv32I ,
92
+ #[ serde( rename = "rv32e" ) ]
93
+ Rv32E ,
94
+ #[ serde( rename = "rv64i" ) ]
95
+ Rv64I ,
96
+ #[ serde( rename = "rv64e" ) ]
97
+ Rv64E ,
98
+ }
0 commit comments