5.3.5. Explicit memory barriers

Two explicit memory barrier operations are described in this section:

In addition, to ensure correct operation where the processor writes code, an explicit Flush Prefetch Buffer operation is provided.

These operations are implemented by writing to the CP15 Cache operation register c7. For details on how to use this register, see c7, Cache Operations Register.

Data Memory Barrier

This memory barrier ensures that all explicit memory transactions occurring in program order before this instruction are completed. No explicit memory transactions occurring in program order after this instruction are started until this instruction completes. Other instructions can complete out of order with the Data Memory Barrier instruction.

Drain Write Buffer

This memory barrier completes when all explicit memory transactions occurring in program order before this instruction are completed. No explicit memory transactions occurring in program order after this instruction are started until this instruction completes. In fact, no instructions occurring in program order until after the Drain Write Buffer complete.

For Shared memory, the data of a write is visible to all observers before the end of a Drain Write Buffer memory barrier.

For Strongly Ordered memory, the data and the side effects of a write are visible to all observers before the end of a Drain Write Buffer memory barrier.

For Non-Shared memory, the data of a write is visible to the processor before the end of a Drain Write Buffer memory barrier.

Flush Prefetch Buffer

The Flush Prefetch Buffer instruction flushes the pipeline in the processor, so that all instructions following the pipeline flush are fetched from memory, including the cache, after the instruction has been completed.

The Flush Prefetch Buffer is guaranteed to perform this function. Alternative methods of performing the same task, such as a branch instruction, can be optimized in the hardware to avoid the pipeline flush, for example, by using a branch predictor.

Combining this with Drain Write Buffer, and potentially invalidating the instruction cache, ensures that any instructions written by the processor are executed.

The execution of a Drain Write Buffer instruction and the invalidation of the instruction cache and Flush Prefetch Buffer is the mechanism that guarantees the correct handling of the self-modifying code.

Memory synchronization primitives

Memory synchronization primitives exist to ensure synchronization between different processes, which might be running on the same processor or on different processors. You can use memory synchronization primitives in regions of memory marked as Shared and Non-Shared when the processes to be synchronized are running on the same processor. You must only use them in Shared areas of memory when the processes to be synchronized are running on different processors.

Copyright © 2005-2007 ARM Limited. All rights reserved.ARM DDI 0290G
Non-Confidential