Program Flow Prediction
ARM DDI 0301H
Copyright © 2004-2009 ARM Limited. All rights reserved.
5-8
ID012310
Non-Confidential, Unrestricted Access
5.4
Memory Barriers
Memory barrier is the general term applied to an instruction, or sequence of instructions, used
to force synchronization events by a processor with respect to retiring load/store instructions in
a processor core. A memory barrier is used to guarantee completion of preceding load/store
instructions to the programmers model, flushing of any prefetched instructions prior to the
event, or both. The ARMv6 architecture mandates three explicit barrier instructions in the
System Control Coprocessor to support the memory order model, see the
ARM Architecture
Reference Manual
, and requires these instructions to be available in both Privileged and User
modes:
•
Data Memory Barrier, see
Data Memory Barrier operation
on page 3-84
•
Data Synchronization Barrier, see
Data Synchronization Barrier operation
on page 3-83
•
Prefetch Flush, see
Flush operations
on page 3-79.
Note
The Data Synchronization Barrier operation is synonymous with Drain Write Buffer and Data
Write Barrier in earlier versions of the architecture.
These instructions might be sufficient on their own, or might have to be used in conjunction with
cache and memory management maintenance operations, operations that are only available in
Privileged modes.
5.4.1
Instruction Memory Barriers (IMBs)
Because it is impossible to entirely avoid self modifying code it is necessary to define a
sequence of operations that can be used in the middle of a self-modifying code sequence to make
it execute reliably. This sequence is called an
Instruction Memory Barrier
(IMB), and might
depend both on the ARM processor implementation and on the memory system implementation.
The IMB sequence must be executed after the new instructions have been stored to memory and
before they are executed, for example, after a program has been loaded and before its entry point
is branched to. Any self-modifying code sequence that does not use an IMB in this way has
Unpredictable behavior.
An IMB might be included in-line where required, however, it is recommended that software is
designed so that the IMB sequence is provided as a call to an easily replaceable system
dependencies module. This eases porting across different architecture variants, ARM
processors, and memory systems.
IMB sequences can include operations that are only usable from Privileged processor modes,
such as the cache cleaning and invalidation operations supplied by the system control
coprocessor. To enable User mode programs access to privileged IMB sequences, it is
recommended that they are supplied as operating system calls, invoked by SVC instructions. For
systems that use the 24-bit immediate in an SVC instruction to specify the required operating
system service, that are default values as follows:
SVC 0xF00000; the general case
SVC 0xF00001; where the system can take advantage of specifying an
; affected address range
These are recommended for general use unless an operating system has good reason to choose
differently, to align with a broader range of operating system specific system services.
The SVC
0xF00000
call takes no parameters, does not return a result, and, apart from the fact that
a SVC instruction is used for the call, rather than a BL instruction, uses the same calling
conventions as a call to a C function with prototype: