spin2cpp
spin2cpp copied to clipboard
Interrupt Support
Just some brainstorming...
- Hand-written interrupt handlers should already work, as long as they push/pop the registers they use (and as long as they are lower priority than any high-level interrupt, it really doesn't matter which registers) and don't touch the CORDIC. Just isn't a documented feature / slightly cumbersome.
- High-level interrupt handlers would need a little more work
- Need a cog routine that saves/restores necessary state and adapters IRQ calls to normal calls
- CORDIC state needs saving
- I think it can be done (can re-inject old saved results into pipeline using QROTATE)
pa/pbneed to be saved (perhapsptrb, too?)localXXdoesn't need saving :+1:_varXXneeds savingargXXandresultXXneed savingobjptrneeds saving (and should be set to some useful value before entering the handler function)ptr_*???- maybe just change P2 codegen to not need these. Could generate a LOC instruction instead, which would also be smaller and faster than the ADD/SUB sequences.
- other misc. registers need saving:
COUNT_,RETADDR_,fp,muldiva_, etc - FCACHE...
- I guess
fcache_tmpb_contains the current FCACHE content pointer, so if size was also memo'd somewhere, we could just preserve those values and reload it if the interrupt handler loaded something else- I guess Spin2-style inline ASM can self-mutate. I guess these need special treatment (i.e. IRQ adapter needs to always dump FCACHE to stack and restore.) Perhaps have a separate
FCACHE_LOAD_version that clearsfcache_tmpb_, which signals this to the adapter. - wait, FCACHE isn't actually cached? (i.e. not reloaded every time)
- I guess Spin2-style inline ASM can self-mutate. I guess these need special treatment (i.e. IRQ adapter needs to always dump FCACHE to stack and restore.) Perhaps have a separate
- I guess
I guess the first steps would be getting rid of ptr_* (because that'd just improve code quality in general) and to change the way cog locations are allocated such that most of the volatile ones are a nice block that can be pushed and popped in one go, with labels either end.
Some of these problems would be simplified if we had a "stack only" compilation mode where all functions are compiled with locals and arguments on the stack. Performance would be horrible, but that may be the price for interrupt support.