05.02.2013 Views

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A3.4.4 Context switch support<br />

Application Level Memory Model<br />

After a context switch, software must ensure that the local monitor is in the Open Access state. This requires<br />

it to either:<br />

execute a CLREX instruction<br />

execute a dummy STREX to a memory address allocated for this purpose.<br />

Note<br />

Using a dummy STREX for this purpose is backwards-compatible with the <strong>ARM</strong>v6 implementation of<br />

the exclusive operations. The CLREX instruction is introduced in <strong>ARM</strong>v6K.<br />

Context switching is not an application level operation. However, this information is included here to<br />

complete the description of the exclusive operations.<br />

The STREX or CLREX instruction following a context switch might cause a subsequent Store-Exclusive to fail,<br />

requiring a load … store sequence to be replayed. To minimize the possibility of this happening, <strong>ARM</strong><br />

recommends that the Store-Exclusive instruction is kept as close as possible to the associated<br />

Load-Exclusive instruction, see Load-Exclusive <strong>and</strong> Store-Exclusive usage restrictions.<br />

A3.4.5 Load-Exclusive <strong>and</strong> Store-Exclusive usage restrictions<br />

The Load-Exclusive <strong>and</strong> Store-Exclusive instructions are intended to work together, as a pair, for example<br />

a LDREX/STREX pair or a LDREXB/STREXB pair. As mentioned in Context switch support, <strong>ARM</strong> recommends that<br />

the Store-Exclusive instruction always follows within a few instructions of its associated Load-Exclusive<br />

instructions. To support different implementations of these functions, software must follow the notes <strong>and</strong><br />

restrictions given here.<br />

These notes describe use of an LDREX/STREX pair, but apply equally to any other<br />

Load-Exclusive/Store-Exclusive pair:<br />

The exclusives support a single outst<strong>and</strong>ing exclusive access for each processor thread that is<br />

executed. The architecture makes use of this by not requiring an address or size check as part of the<br />

IsExclusiveLocal() function. If the target address of an STREX is different from the preceding LDREX in<br />

the same execution thread, behavior can be UNPREDICTABLE. As a result, an LDREX/STREX pair can only<br />

be relied upon to eventually succeed if they are executed with the same address. Where a context<br />

switch or exception might result in a change of execution thread, a CLREX instruction or a dummy<br />

STREX instruction must be executed to avoid unwanted effects, as described in Context switch support<br />

Using an STREX in this way is the only occasion where software can program an STREX with a different<br />

address from the previously executed LDREX.<br />

An explicit store to memory can cause the clearing of exclusive monitors associated with other<br />

processors, therefore, performing a store between the LDREX <strong>and</strong> the STREX can result in a livelock<br />

situation. As a result, code must avoid placing an explicit store between an LDREX <strong>and</strong> an STREX in a<br />

single code sequence.<br />

<strong>ARM</strong> DDI 0406B Copyright © 1996-1998, 2000, 2004-2008 <strong>ARM</strong> Limited. All rights reserved. A3-21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!