Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an ARM interrupt occur in mid-instruction?

Tags:

arm

This question will be short and sweet.

I know an instruction can occur between instruction but can an interrupt happen during an instruction? Can a load multiple instruction be interrupted before it's loaded all the values into the registers?

mov r0, r1
                 < interrupt can happen here
ldm r0, {r1-r4}  < can an interrupt happen **during** a load multiple instruction?
like image 334
tangrs Avatar asked Mar 25 '12 03:03

tangrs


1 Answers

The load multiple instructions are explicitly not atomic. See section A3.5.3 of the ARM V7C architecture reference manual.

LDM, LDC, LDC2, LDRD, STM, STC, STC2, STRD, PUSH, POP, RFE, SRS, VLDM, VLDR, VSTM, and VSTR instructions are executed as a sequence of word-aligned word accesses. Each 32-bit word access is guaranteed to be single-copy atomic. The architecture does not require subsequences of two or more word accesses from the sequence to be single-copy atomic.

If you read on, you'll find out that the LDM/STM instructions can be aborted by an interrupt (and restarted from the beginning on interrupt return). LDM and STM instructions can always be interrupted by a data abort, so they're non atomic in that sense. Otherwise, the ARMv7-A architecture does its best to help you out. For interrupts, they can only be interrupted if low interrupt latency is enabled, AND normal memory is being accessed. So at the very least, you won't get repeated accesses to device memory. You don't want to do anything that expects atomic read/writes of normal memory though.

On v7-M, LDM and STM can be interrupted at any time (see section B1.5.10 of the ARMv7-M Architecture Reference Manual). It's implementation defined whether or not the instruction is restarted from the beginning of the list of loads/stores, or whether it's restarted from where it left off. As the ARM says:

The ARMv7-M architecture supports continuation of, or restarting from the beginning, an abandoned LDM or STM instruction as outlined below. Where an LDM or STM is abandoned and restarted (ICI bits are not supported), the instructions should not be used with volatile memory.

In other words, don't rely on LDM or STM being atomic if you're trying to write portable code.

like image 145
Jacques Avatar answered Oct 10 '22 10:10

Jacques