Hi John,

I guess I should clarify.

When REX is operating, I must have the interrupts enabled, so the Timer
hook can be used to grab control automatically , and do the ROM selection
and a bunch of other things.

So, if an RST 7 call happens to be in process when the timer hook fires,
disabling interrupts can't prevent that.

So the sequence of events is

...timer interrupts happening... (timer interrupt is processed by REX.  RST
7  table may be altered)
...RST 7 occurs.....
.....timer interrupt occurs (during RST 7!).....---> (REX  processes
interrupt. do NOT alter RST7 table!)

Yes, I can use DI to protect REX code from unwanted interrupts, but the
troublesome scenario itself cannot be avoided.



On Sat, Dec 12, 2020 at 4:29 PM John R. Hogerhuis <[email protected]> wrote:

> Hi Steve --
>
> " The M100 during normal operation isn't in disabled state."
>
> Right. Otherwise, interrupts would be broken.
>
> "In fact I am relying on the TIMER hook to enable all those functions of
> REX -* so the timer hook has to happen."*
>
> Not sure I understand what you're saying.
>
> The code you showed in the first post proves that dispatch of hooks is not
> atomic and it's not protected from interrupt.
>

correct


>
> It could be made atomic by adding DI/SI or maybe using a different
> instruction but we can't because it's ROM code.
>

correct, but "in ROM" as you say.

>
> However, I think that to address that, all you should have to do is DI/SI
> around the hook install, as Philip suggested
>

It is the ROM itself that is calling RST 7 in this case.  Yes if REX was
calling RST 7 I could protect it.


>
> In fact I think what you've proven is to safely install a hook you MUST
> DI/SI around the hook install.
>
>
!YES!

Once you "DI" then that should mean
>
> a) That implies it's your code doing the DI, so it's your code is running,
> not the timer hook dispatch code.
> b) the timer hook dispatch code will not be able to run until you SI
>
> Walking back the stack is fraught... I think I've seen cases where it's
> necessary but they are very rare and it's hard to make it work.
>

Sometimes I have to use it.  For example, The way I currently detect that
MENU is running is by inspecting the stack during timer interrupts.


>
> So I guess I'm asking, are you sure that protecting the hook install point
> doesn't fix the issue for you? It definitely seems like it should.
>

In the case of the main ROM calling RST 7, and an interrupt occuring where
REX is handling the interrupt, you can't protect RST 7.


>
> Guess I better go fix SET_HOOK/CLEAR_HOOK macros in HTERM source.
>
> -- John.
>

Reply via email to