
Chapter 3. L1 and L2 Cache Operation
3-35
Memory and Cache Coherency
3.4.4.4 Atomic Memory References
The PowerPC architecture deTnes the Load Word and Reserve Indexed (
lwarx
) and the
Store Word Conditional Indexed (
stwcx.
) instructions to provide an atomic update function
for a single, aligned word of memory. These instructions can be used to develop a rich set
of multiprocessor synchronization primitives. Note that atomic memory references
constructed using
lwarx
/
stwcx.
instructions depend on the presence of a coherent memory
system for correct operation. These instructions should not be expected to provide atomic
access to noncoherent memory. For detailed information on these instructions, refer to
Chapter 2, òProgramming Model,ó in this book and Chapter 8, òInstruction Set,ó in
The
Programming Environments
Manual
.
The
lwarx
instruction performs a load word from memory operation and creates a
reservation for the 32-byte section of memory that contains the accessed word. The
reservation granularity is 32 bytes. The
lwarx
instruction makes a non-speciTc reservation
with respect to the executing processor and a speciTc reservation with respect to other
masters. This means that any subsequent
stwcx.
executed by the same processor, regardless
of address, will cancel the reservation. Also, any bus write or invalidate operation from
another processor to an address that matches the reservation address will cancel the
reservation.
The
stwcx.
instruction does not check the reservation for a matching address. The
stwcx.
instruction is only required to determine whether a reservation exists. The
stwcx.
instruction performs a store word operation only if the reservation exists. If the reservation
has been cancelled for any reason, then the
stwcx.
instruction fails and clears the CR0[EQ]
bit in the condition register. The architectural intent is to follow the
lwarx
/
stwcx.
instruction pair with a conditional branch which checks to see whether the
stwcx.
instruction failed.
Executing an
lwarx
or
stwcx.
instruction to areas marked write-through or when the L1
data cache is enabled and locked causes a DSI exception.
If the page table entry is marked caching-allowed (WIMG = x0xx), and an
lwarx
access
misses in the cache, then the MPC7400 performs a cache block Tll. If the page is marked
caching-inhibited (WIMG = x1xx) and the access misses, then the
lwarx
instruction
appears on the bus as a single-beat load. All bus operations that are a direct result of either
an
lwarx
instruction or an
stwcx.
instruction are placed on the bus with a special encoding.
Note that this does not force all
lwarx
instructions to generate bus transactions, but rather
provides a means for identifying when an
lwarx
instruction does generate a bus transaction.
If an implementation requires that all
lwarx
instructions generate bus transactions, then the
associated pages should be marked as caching-inhibited. Note also that the MPC7400 uses
the
lwarx
encoding to differentiate instruction fetches from data loads when HID0[IFTT]
is set.