I like to collect all possible interrupt and relay them to an alternative handler interrupt table what the user can set.
In order to do this i have to:
1) collect all/any interrup request
2) identify where is the interruption came from
3) relay the call to another table the user pointed.
If you familiar with interrupts you know if you registers a single function to all interrupt handler there's no way to idenfity the source of the interrupt. But registering unique interrupt handler that carries the information of the source and calls another function to dispatch call, for each interrupt is a code space wasting. Eg.: the atmega328 has 24 interrupt handlers. Each of the is compiled with the avr-gcc consumes 76 bytes.
But i have and idea how it is possible to register one handler function and identify the source:
00000000 <__vectors>:
0: 0c 94 34 00 jmp 0x68 ; 0x68 <__ctors_end>
4: 0c 94 51 00 jmp 0xa2 ; 0xa2 <__bad_interrupt>
8: 0c 94 51 00 jmp 0xa2 ; 0xa2 <__bad_interrupt>
c: 0c 94 51 00 jmp 0xa2 ; 0xa2 <__bad_interrupt>
If i define an interrupt handler (even if it can fit the 4 byte space) a jmp instruction is placed. If it can be replaced to eg.: call 0xa2 (which can fit in 4 bytes), is can be used to identify the interrupt source address.
Because call
stores the return address, the function started at 0xa2 can read back that address and therefor idenfity the caller. Then add an extra pop
(pop the stack address accumulated by the call
at the interrup table) and reti
(to return as like from an interrupt handler) after the function body.
If this can work theorically, to achieve this only one question remains:
How can i replace the jmp
instructions to call
in interrupt table?