Specifications

Page D-2 Appendix D
D.1.2What You Must Do..
The only sure way to address this issue is to flush the instruction cache after loading
instructions into memory, but before executing those instructions. Because the method
by which you flush the cache is different on the various 680x0 processors, you will need
to add code specific to the 68040.
You must be certain to handle the different processors individually. Failure to do so may
result in inadvertently disabling certain processor features. For example, trying to flush
the 68040 cache using the 68030 method will result in the 68040’s instruction cache
being disabled. This will seriously degrade system performance.
To test to see if a program is executing on a 68040, use the following code fragment:
MOV SYSTEM,D7 ; get the system flags
AND #SY$M40,D7 ; is the 040 bit set?
BNE yes we’re on a 040! ; yes - take the branch
To simply flush the cache, use the following code fragment:
SUPVR ; enter supervisor mode
CINVA ; invalidate cache
LSTS #0 ; return to user mode
To turn off the instruction cache, as is needed in some cases, use the following code:
SUPVR ; enter supervisor mode
SVLOK ; ensure interrupts are off
CLR D7 ; clear the CACR
MOVEC D7,CACR ; flags
LSTS #0 ; return to user mode and enable
; interrupts again
To turn the instruction cache back on, use the following:
SUPVR ; enter supervisor mode
SVLOK ; turn off interrupts
CINVA ; invalidate cache
MOV #^H08000,D7 ; set the ICACHE
MOVEC D7,CACR ; enable bit
LSTS #0 ; return to user mode and enable
; interrupts again
Remember to turn the instruction cache back on! If you don’t, system performance will
be seriously impaired.
PDI-00172-40, Rev. A05