Date : Tue, 09 Mar 2004 13:35:09 +0100
From : John Kortink <kortink@...>
Subject: Re: CLI then SEI
On Tue, 09 Mar 2004 00:41:32 -0000, you wrote:
>Here's an interesting thing that I found out whilst tearing my hair
>out over Empire Strikes Back.
>
>Empire Strikes Back sets the OS' System VIA IRQ mask via OSBYTE &E9
>such that the T1 flag is clear. Eventually, T1 times out, and never
>gets acknowledged. Empire Strikes Back then calls OSBYTE &7A, which
>after a bit of faffing runs this bit of code:
>
> F129 JSR &F12E ;call autoscan
> F12C CLI ;allow interrupts
> F12D SEI ;disable interrupts
>
>On my emulator, the moment CLI is finished, the T1 interrupt happens.
>The OS runs the IRQ routine, but doesn't acknowledge the T1 flag, and
>so the moment RTI has run (popping the status register with I clear)
>the interrupt happens again. And then again. And then again.
>
>But on a real BBC, it seems there's some kind of pipelining-like
>behaviour going on. After a bit of playing around, I found that the
>interrupt doesn't happen until after the instruction following the
>CLI has run! So a CLI/SEI pair won't cause an infinite chain of
>interrupts, though a CLI/NOP/SEI will. (The address on the stack on
>entry to the IRQ routine is the instruction after the instruction
>after the CLI.)
>
>Very strange.
>
>Should I have known this already?! :)
I think nobody should, but I'm having deja vu. I had a
similar problem yonks ago and can remember tracking down
docs with a precise description of 6502 interrupt behaviour.
The 6502 only services the interrupt once it has seen I clear
(and an interrupt source) for at least one clock (in this case,
then, only after it executes the SEI, which causes it to 'PHP'
with I set). Highly likely because it clocks the interrupt
source (because it comes in asynchronously), and decides
combinatorially to service it. It's not a pipeline issue.
John Kortink