Copy Link
Add to Bookmark
Report
Saxonia Issue 01 Part 010
Easy way to handle interrupts
By Rumrunner/VOID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When you write a program that doesn't multitask, but leaves
the os interrupts on, there are several ways to handle your own
interrupt.
One way is to use the "legal" method, starting the interrupt by using
the os library functions. However this makes you unable to select whether
your routines should run before the rest of the interrupt or not.
That's correct as far as I know, but I don't have much documentation
so if anyone has found out something different, please write an article
about it, and send it to us. We'll print it in the next issue.
The other way to install you own interrupt is by using self modifying
code. You simply store the adress of the os interrupt, and then jump to
it after you have executed your own routines, like this :
interrupt:
movem.l d0-d7/a0-a6,-(a7) ;store regs
..
.. ;your routines
..
movem.l (a7)+,d0-d7/a0-a6 ;get regs back
dc.w $4ef9 ;jmp intruction
storeosintadresshere:
dc.l 0 ;save the os interrupt adress here
This will execute your routines first, and then jump into the os
interrupt. However, this can cause problems on processors bigger than
the 68000, because of the cache. The saved adress will be in the data
cache, and not in the instruction cache, so it will mess up.
You can turn caches off when storing the adress and then turn them back
afterwards, but caches are different from processor to processor, so
this is a boring task, unless you use the os functions for it.
But, the very simple solution to the problem is not far avay. Store the
os interrupt adress. When you are finished with your part of the
interrupt, simply use this code :
interrupt:
movem.l d0-d7/a0-a6,-(a7) ;store regs
..
.. ;do the routines
movem.l (a7)+,d0-d7/a0-a6 ;get regs
move.l storedosintadress,-(a7) ;jump to this adress
rts ;jump there by doing an rts
This way you will not need to worry about the cache or processor type.
It will keep all registers in the state they should be.