
MOTOROLA
Chapter 4. Instruction and Data Cache Operation
For More Information On This Product,
Go to: www.freescale.com
4-41
Cache Locking
Because instructions are intentionally executed speculatively, care must be taken to ensure
that all I/O memory is marked guarded. Otherwise, speculative loads and stores to I/O space
could potentially cause data loss. See the
Programming Environments Manual
for a full
discussion of guarded memory.
The code that prefetches must be in cache-inhibited memory as in the following example:
# Assuming exceptions are disabled, cache has been flushed,
# the MMU is on, and we are executing in a cache-inhibited
# location in memory
# LR and r6 = Starting address of code to lock
# CTR = Number of cache blocks to lock
# r2 = non-zero numerator and denominator
# ‘loop’ must begin on an 8-byte boundary to ensure that
# the divw and beqlr+ are fetched on the same cycle.
.orig
0xFFF04000
loop:
divw.
beqlr+
r2, r2, r2
# LONG divide w/ non-zero result
# Cause the prefetch to happen
addi
mtlr
bdnz-
r6, r6, 32
r6
loop
# Find next block to prefetch
# set the next block
# Decrement the counter and
# branch if CTR != 0
In the above example, both the
divw
and
beqlr+
instructions are fetched at the same time
(this assumes a 64-bit 60x data bus; the preloading code does not work for a 32-bit data bus)
due to their placement on a double-word boundary. The divide instruction was chosen
because it takes many cycles to execute. During execution of the divide, the processor starts
fetching instructions speculatively at the target destination of the branch instruction. The
speculation occurs because the branch is statically predicted as taken. This speculative
fetching causes the cache block that is pointed to by the link register (LR) to be loaded into
the cache. Because the
divw.
instruction always produces a non-zero result, the
beqlr+
is
not taken and execution of all speculatively fetched instructions is canceled. However, the
instructions remain valid in the cache.
If the destination instruction stream contains an unconditional branch to another memory
location, it is possible to also prefetch the destination of the unconditional branch
instruction. This does not cause a problem if the destination of the unconditional branch is
also inside the area of memory that needs to be preloaded. But if the destination of the
unconditional branch is not in the area of memory to be loaded, then care must be taken to
ensure that the branch destination is to an area of memory that is cache inhibited.
Otherwise, unintentional instructions may be locked in the cache and the desired
instructions may not be in their expected way within the cache.
F
Freescale Semiconductor, Inc.
n
.