> We generate code:
> 1)
> save regs
> ...
> restore regs
> reti
> 2)
> di
> save regs
> ...
> restore regs
> ei
> reti
> 3)
> save regs
> ...
> restore regs
> retn
>
> Out of these, 3) looks correct to me. But 1) fails to reenable
> interrupts at the end (I think there should be an ei before the reti).
> And 2) is completly wrong, I think it should be:
> ei
> save regs
> ...
> restore regs
> reti
>
> Did I miss something?
When I looked at this ages ago I came to the same conclusion but never
worried about it as I couldn't use those methods anyway because I needed
to be able to save/restore interrupt state.
Of the others
Your changes to #1 are IMHO correct
You can't implement #2 on a Z80 this way
#3 appears to be correct (as far as it goes for Z80)
For the #2 case you can't do the ei because on many platforms (eg MSX)
you'll immediately take another interrupt and execute nothing but
ei
push af
irq entry
ei
push af
irq entry
until you crash.
The #1 case is only safe because the ei takes effect the instruction
after (ie after the reti), a detail quite a few emulators get wrong
The general case of a Z80 interrupt handler that can be re-entered is
irq_entry:
push stuff
save state from interrupting device
ack interrupt source on priority aware controller
ei
process state from device
pop stuff
ret
In some situations you even end up having to do stuff like
irq_entry:
push stuff
save state from interrupting device
push dummy_ret
ei
reti ; acks the IRQ returns to the next instr
dummy_ret:
process state from device
pop stuff
ret
Neither of those can be expressed in a function entry annotation
Z180 is different again because you've got multiple IRQ sources and
something resembling onboard interrupt controllers.
Alan
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user