0

If I have a fast interrupt handler (by adding __attribute__((interrupt("FIQ")))), can I invoke other non-fast-interrupt function inside the handler? For example,

void f() {//...}
void g() {//...}
void handler() __attribute__((interrupt("FIQ"))) {
    // ...
    f();
    g();
    // ...
}

I have a fast interrupt handler set up similarly as the example above and it's not working as intended. I used gdb to trace through the handler and I found that things are pushed to the stack during the f function call and are never popped out (similar for g). Then at the epilogue of the handler, the link register popped from the stack is wrong.

  • Can you show the disassembly of `handler`? Is the address of `handler` used directly in the vector table? Which ARM architecture version is this for? – Erlkoenig Feb 03 '20 at 08:27
  • @Erlkoenig I removed some busy-wait logging in the handler and things are working now. I guess invoking other functions in the handler shouldn't be an issue. I'm using arm920t and setting the handler by writing the address at `0x3c`. – Zhongwei Zhao Feb 03 '20 at 12:53
  • Shouldn't it be `0x1c` according to the ARM Architecture Reference Manual? The `LR` (and `r8`-`r13`) doesn't need to be saved/restored by `handler`, as the FIQ mode has a banked copy of those. Only if `f` were to call some other function, `f` would have to save/restore `LR`. – Erlkoenig Feb 03 '20 at 13:09
  • Yes, it should be `0x1c`. But `0x1c` originally store an instruction that branches to where `0x3c` points to. So setting `0x3c` also works. – Zhongwei Zhao Feb 03 '20 at 14:30
  • 2
    See: [GCC FIQ bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48429) and [Difference between FIQ and IRQ](https://stackoverflow.com/questions/973933/what-is-the-difference-between-fiq-and-irq-interrupt-system/21270225#21270225); you should not use FIQ with sub-routine calls and even this might not work. It is best to code in assembler. Otherwise, you need to manually create frames in some entry 'thunk' or assembler tail call whatever you would like to call it and don't bother with FIQ annotation. – artless noise Feb 03 '20 at 18:03
  • if you let the compiler wrap the functions then no probably not. But if you use generic functions that you wrap yourself (in ASM) then sure why not. – old_timer Feb 03 '20 at 23:45

0 Answers0