spin2cpp icon indicating copy to clipboard operation
spin2cpp copied to clipboard

Interrupt Support

Open Wuerfel21 opened this issue 2 years ago • 1 comments

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/pb need to be saved (perhaps ptrb, too?)
    • localXX doesn't need saving :+1:
    • _varXX needs saving
    • argXX and resultXX need saving
    • objptr needs 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 clears fcache_tmpb_, which signals this to the adapter.
        • wait, FCACHE isn't actually cached? (i.e. not reloaded every time)

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.

Wuerfel21 avatar Mar 19 '22 21:03 Wuerfel21

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.

totalspectrum avatar Jul 07 '22 00:07 totalspectrum