Skip to content

Commit

Permalink
Make _vector_table strong
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Jan 21, 2025
1 parent c14faa3 commit 2ed7cd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 38 deletions.
15 changes: 10 additions & 5 deletions riscv-rt/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ pub unsafe extern "C" fn _dispatch_core_interrupt(code: usize) {
}

// In vectored mode, we also must provide a vector table
#[cfg(all(
any(target_arch = "riscv32", target_arch = "riscv64"),
feature = "v-trap"
))]
riscv::vector_table!();
#[riscv::pac_enum(unsafe CoreInterruptNumber)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Interrupt {
SupervisorSoft = 1,
MachineSoft = 3,
SupervisorTimer = 5,
MachineTimer = 7,
SupervisorExternal = 9,
MachineExternal = 11,
}
34 changes: 1 addition & 33 deletions riscv/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ struct PacEnumItem {
max_number: usize,
/// A map from discriminant values to variant names
numbers: HashMap<usize, Ident>,
/// Whether `_vector_table` should be a weak symbol
weak_vector_table: bool,
}

impl PacEnumItem {
Expand Down Expand Up @@ -227,7 +225,6 @@ impl PacEnumItem {
name,
max_number,
numbers,
weak_vector_table: false,
}
}

Expand Down Expand Up @@ -268,11 +265,6 @@ impl PacEnumItem {
}

fn vector_table(&self) -> TokenStream2 {
let weak = if self.weak_vector_table {
"weak"
} else {
"global"
};
let mut align = match std::env::var("RISCV_MTVEC_ALIGN") {
Ok(x) => x.parse::<u32>().ok(),
Err(std::env::VarError::NotPresent) => Some(4),
Expand All @@ -296,7 +288,7 @@ impl PacEnumItem {
#[cfg(all(feature = "v-trap", any(target_arch = "riscv32", target_arch = "riscv64")))]
core::arch::global_asm!("
.section .trap, \"ax\"
.{weak} _vector_table
.global _vector_table
.type _vector_table, @function
.option push
Expand Down Expand Up @@ -462,27 +454,3 @@ pub fn pac_enum(attr: TokenStream, item: TokenStream) -> TokenStream {
}
.into()
}

#[proc_macro]
/// Generates a weak '_vector_table' function in assembly.
///
/// The alignment constraint (in bytes) is read from the `RISCV_MTVEC_ALIGN` environment variable
/// and defaults to 4.
pub fn vector_table(_input: TokenStream) -> TokenStream {
let span = proc_macro2::Span::call_site();
let pac = PacEnumItem {
name: Ident::new("unused", span),
max_number: 11,
numbers: [
(1, Ident::new("SupervisorSoft", span)),
(3, Ident::new("MachineSoft", span)),
(5, Ident::new("SupervisorTimer", span)),
(7, Ident::new("MachineTimer", span)),
(9, Ident::new("SupervisorExternal", span)),
(11, Ident::new("MachineExternal", span)),
]
.into(),
weak_vector_table: true,
};
pac.vector_table().into()
}

0 comments on commit 2ed7cd3

Please sign in to comment.