Programmers Model
ARM DDI 0363G
Copyright © 2006-2011 ARM Limited. All rights reserved.
3-23
ID073015
Non-Confidential
The processor modifies the IT execution state bits on exception entry so that the values that the
processor writes into the SPSR are correct for the instruction following the SVC. This means
that the SVC handler does not have to perform any special action to accommodate the IT
instruction. For more information on the IT instruction, see the
ARM Architecture Reference
Manual
.
3.7.6
Undefined instruction
When an Undefined instruction is encountered, or a VFP instruction, when the VFP is not
enabled, the processor takes the Undefined Instruction exception. Software can use this
mechanism to extend the ARM instruction set by emulating Undefined instructions. Undefined
Instruction exceptions also occur when a
UDIV
or
SDIV
instruction is executed, when the value in
Rm is zero and the DZ bit in the SCTLR is set.
If the handler is required to return after the instruction that caused the Undefined Instruction
exception, it must:
•
Advance the IT execution state bits in the SPSR before restoring SPSR to CPSR. This is
so that the correct condition codes are applied to the next instruction on return. The
pseudo-code for advancing the IT bits is:
Mask = SPSR[11,10,26,25];if (Mask != 0) {
Mask = Mask <<
1;
SPSR[12,11,10,26,25] = Mask;
}if (Mask[3:0] == 0) {
SPSR[15:12] = 0;}
•
Obtain the instruction that caused the Undefined Instruction exception and return
correctly after it. Exception handlers must also be aware of the potential for both 16-bit
and 32-bit instructions in Thumb state.
After testing the SPSR and determining the instruction was executed in Thumb state, the
Undefined handler must use the following pseudo-code or equivalent to obtain this
information:
addr = R14_undef - 2
instr = Memory[addr,2]
if (instr >> 11) > 28 { /* 32-bit instruction */
instr = (instr << 16) | Memory[addr+2,2]
if (emulating) {/*so return after instruction wanted */
R14= 2 //
} //
}
After this,
instr
holds the instruction (in the range
0x0000
-
0xE7FF
for a 16-bit instruction,
0xE8000000
-
0xFFFFFFFF
for a 32-bit instruction), and the exception can be returned from
using a
MOVS PC, R14
to return after it.
IRQs are disabled when an Undefined instruction trap occurs. For more information about
Undefined instructions, see the
ARM Architecture Reference Manual
.
3.7.7
Breakpoint instruction
A breakpoint (BKPT) instruction operates as though the instruction causes a Prefetch Abort.
A breakpoint instruction does not cause the processor to take the Prefetch Abort exception until
the instruction is to be executed. If the instruction is not executed, for example because a branch
occurs while it is in the pipeline, the breakpoint does not take place.
After dealing with the breakpoint, the handler executes the following instruction irrespective of
the processor operating state:
SUBS PC, R14_abt, #4
This action restores both the PC and the CPSR, and retries the breakpointed instruction.