Nestor Soriano <[EMAIL PROTECTED]> wrote:
> Hi people... problems again... this time, when changing stack. In a new
> update of NestorAcentos I'm developing, I put the following piece of code
> attached to the timer interrupt hook. The code is placed in a reserved zone
> on page 3:
>
> ld (SAVESP),sp
> ld sp,NEWSP+100
> push all
> .
> . (changes slot and segment on page 2, do stuff and restores old status)
> .
> pop all
> ld sp,(SAVESP)
> jp old interrupt hook
>
> SAVESP: dw 0
> NEWSP: ds 100
>
> Well, a program executing such code causes the system to crash when any
> other program is executed. Someone knows where is the problem?
Advanced interrupt programming.... ;-))
Isn't it possible, that sometimes a next interrupt occurs, while a
previous interrupt routine is still being processed?
If that happens everytime, it will crash, but if occasionally, then
no problem with proper written interrupt routine.
For this to work, the interrupt routine should be re-entrant:
allowing to be executed again, even when not finished.
Try the above:
save (FIXED address), stackpointer
...
(interrupted again)
...
save (same fixed address), stackpointer for 2nd interrupt
....
restore stack for 2nd interrupt
finish 2nd interrupt (=return to previous interrupt handling)
....
restore stack for 1st interrupt, with SP that was overwritten by 2nd
interrupt -> SP corrupted -> crash/hang
Solution:
Disable interrupts (DI), then save SP etc., don't call
anything that could re-enable interrupts in between, restore SP, and
only AFTER that restore, further interrupts could be allowed.
OR: if possible, don't switch stacks at all.
Other possibility: 100 bytes stack space reserved? Are you sure that
is enough? (try making far bigger, and see if still crashes)
Greetings,
Alwin Henseler ([EMAIL PROTECTED])
http://huizen.dds.nl/~alwinh/msx MSX Tech Doc page
****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****