
Cache Lockdown
Copyright 2000–2001 by LSI Logic Corporation. All rights reserved.
4-11
Where the number of sets multiplied by the line length in bytes is 128 for
a 4-way associative cache. This would be 64 for a 2-way associative
cache and 32 for a direct-mapped cache. The table above is correct for
a 4-way associative cache. A direct-mapped or 2-way cache would have
larger values for N.
It is usual to clean the cache before flushing it, so that external memory
is updated with any dirty data. The following code shows how you can
clean and flush the entire cache (assuming a 4 Kbyte D-cache).
MOV
r1, #0
; Initialize set counter
outer_loop
MOV
inner_loop
ORR
MCR
ADD
CMP
set
BNE
ADD
CMP
BNE
r0, #0
; Initialize line counter
r2, r1, r0
p15, 0, r2, c7, c14, 2
r0, r0, #0x20
r0, #0x400
; Generate set and line address
; Clean and flush the line
; Increment to next line
; Complete all entries in one
inner_loop
r1, r1, #0x40000000
r1, #0x0
outer_loop
; If not branch back to inner_loop
; Increment set counter
; Complete all sets
; If not branch back to outer_loop
4.4 Cache Lockdown
To provide predictable code behavior in embedded systems, a
mechanism is provided for locking code into the I-cache and D-cache.
For example, you can use this feature to hold high-priority interrupt
routines where there is a hard real-time constraint, or to hold the
coefficients of a DSP filter routine in order to reduce external bus traffic.
You can lockdown a region of the I-cache or D-cache by executing a
short software routine, taking note of these requirements:
The program must be held in a noncacheable area of memory.
The cache must be enabled and interrupts must be disabled.
Software must ensure that the code or data to be locked down is not
already in the cache.
If the caches have been used after the last reset, the software must
ensure that the cache in question is cleaned, if appropriate, and then
flushed.