Skip to content

Commit 2ed7cd3

Browse files
committed
Make _vector_table strong
1 parent c14faa3 commit 2ed7cd3

File tree

2 files changed

+11
-38
lines changed

2 files changed

+11
-38
lines changed

riscv-rt/src/interrupts.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ pub unsafe extern "C" fn _dispatch_core_interrupt(code: usize) {
7171
}
7272

7373
// In vectored mode, we also must provide a vector table
74-
#[cfg(all(
75-
any(target_arch = "riscv32", target_arch = "riscv64"),
76-
feature = "v-trap"
77-
))]
78-
riscv::vector_table!();
74+
#[riscv::pac_enum(unsafe CoreInterruptNumber)]
75+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
76+
enum Interrupt {
77+
SupervisorSoft = 1,
78+
MachineSoft = 3,
79+
SupervisorTimer = 5,
80+
MachineTimer = 7,
81+
SupervisorExternal = 9,
82+
MachineExternal = 11,
83+
}

riscv/macros/src/lib.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ struct PacEnumItem {
187187
max_number: usize,
188188
/// A map from discriminant values to variant names
189189
numbers: HashMap<usize, Ident>,
190-
/// Whether `_vector_table` should be a weak symbol
191-
weak_vector_table: bool,
192190
}
193191

194192
impl PacEnumItem {
@@ -227,7 +225,6 @@ impl PacEnumItem {
227225
name,
228226
max_number,
229227
numbers,
230-
weak_vector_table: false,
231228
}
232229
}
233230

@@ -268,11 +265,6 @@ impl PacEnumItem {
268265
}
269266

270267
fn vector_table(&self) -> TokenStream2 {
271-
let weak = if self.weak_vector_table {
272-
"weak"
273-
} else {
274-
"global"
275-
};
276268
let mut align = match std::env::var("RISCV_MTVEC_ALIGN") {
277269
Ok(x) => x.parse::<u32>().ok(),
278270
Err(std::env::VarError::NotPresent) => Some(4),
@@ -296,7 +288,7 @@ impl PacEnumItem {
296288
#[cfg(all(feature = "v-trap", any(target_arch = "riscv32", target_arch = "riscv64")))]
297289
core::arch::global_asm!("
298290
.section .trap, \"ax\"
299-
.{weak} _vector_table
291+
.global _vector_table
300292
.type _vector_table, @function
301293
302294
.option push
@@ -462,27 +454,3 @@ pub fn pac_enum(attr: TokenStream, item: TokenStream) -> TokenStream {
462454
}
463455
.into()
464456
}
465-
466-
#[proc_macro]
467-
/// Generates a weak '_vector_table' function in assembly.
468-
///
469-
/// The alignment constraint (in bytes) is read from the `RISCV_MTVEC_ALIGN` environment variable
470-
/// and defaults to 4.
471-
pub fn vector_table(_input: TokenStream) -> TokenStream {
472-
let span = proc_macro2::Span::call_site();
473-
let pac = PacEnumItem {
474-
name: Ident::new("unused", span),
475-
max_number: 11,
476-
numbers: [
477-
(1, Ident::new("SupervisorSoft", span)),
478-
(3, Ident::new("MachineSoft", span)),
479-
(5, Ident::new("SupervisorTimer", span)),
480-
(7, Ident::new("MachineTimer", span)),
481-
(9, Ident::new("SupervisorExternal", span)),
482-
(11, Ident::new("MachineExternal", span)),
483-
]
484-
.into(),
485-
weak_vector_table: true,
486-
};
487-
pac.vector_table().into()
488-
}

0 commit comments

Comments
 (0)