libcortex_a9: added interrupt_handler macro #77
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "pca006132/zynq-rs:master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Addresses #73.
The concern is that, normal functions require prologue before the actual function body, which push and pop from the stack, and function calls would modify the stack pointer. When those interrupts are called, the stack pointer should be 0, and I'm not entirely sure why the program works.
This commit added
interrupt_handler
macro. It would setup a interrupt handler to setup the stack pointer and jump to the actual interrupt handler, running normal rust function with C calling convention. The stack pointer location can be customized, but defaults to__stack0_start
and__stack1_start
for core0 and core1 respectively.Due to limitation of rust macro, a
name2
has to be provided to name the actual interrupt handler. (concat_idents
is really useless as it can't be used in function definition...)@ -38,0 +40,4 @@
/// - `name` is the name of the interrupt, should be the same as the one defined in vector table.
/// - `name2` is the name for the actual handler, should be different from name.
/// - `stack0` is the stack for the interrupt handler when called from core0, default to
/// `__stack0_start`.
I don't get this. Won't it make interrupt handlers overwrite the main program's stack?
For the interrupts that we use now, they would never return to main program, so it does not matter.
If we need to avoid this later for some interrupts, we can provide two dedicated stacks for interrupts (1 for each core), and arguments can be provided to the macro to override the stack pointer location.
Okay I see. It is a very niche use case that we have, and it shouldn't be the default for the more general-purpose zynq-rs crate.
We may not even need to support this optimization since a few kilobytes of dedicated interrupt stack is nothing compared to the size of the SDRAM. And it avoids creating any confusion during debugging if we ever examine the main stack after the ISR has run.
4ff5d16691
to06c646e61f
@ -5,3 +5,1 @@
#[link_section = ".text.boot"]
#[no_mangle]
pub unsafe extern "C" fn UndefinedInstruction() {
interrupt_handler!(UndefinedInstruction, undefined_instruction, __stack0_start, __stack1_start, {
I think we probably want to inspect the main stack when this happens... so it should not get mangled.
@ -56,3 +58,1 @@
#[link_section = ".text.boot"]
#[no_mangle]
pub unsafe extern "C" fn IRQ() {
interrupt_handler!(IRQ, irq, __stack0_start, __stack1_start, {
Still the main stack?
sorry I forgot this one, fixed.
8dd68d262d
to78d58d17ec