
Debug in depth
C-24
Copyright 2000 ARM Limited. All rights reserved.
ARM DDI 0165B
C.8
Behavior of the program counter during debug
The debugger must keep track of what happens to the PC, so that you can force the
ARM9E-S to branch back to the place at which program flow was interrupted by debug.
Program flow can be interrupted by any of the following:
a breakpoint
a watchpoint
a watchpoint when another exception occurs
a debug request
a system speed access.
C.8.1
Breakpoints
Entry to debug state from a breakpointed instruction advances the PC by 16 bytes in
ARM state, or 8 bytes in Thumb state. Each instruction executed in debug state
advances the PC by one address (4 bytes). The normal way to exit from debug state after
a breakpoint is to remove the breakpoint and branch back to the previously breakpointed
address.
For example, if the ARM9E-S entered debug state from a breakpoint set on a given
address and two debug speed instructions were executed, a branch of seven addresses
must occur (four for debug entry, plus two for the instructions, plus one for the final
branch). The following sequence shows ARM instructions scanned into scan chain 1.
This is the Most Significant Bit (MSB) first, so the first digit represents the value to be
scanned into the SYSSPEED bit, followed by the instruction.
0 EAFFFFF9 ; B -7 addresses (two’s complement)
1 E1A00000 ; NOP (MOV R0, R0), SYSSPEED bit is set
After the ARM9E-S enters debug state, it must execute a minimum of two instructions
before the branch, although these can both be NOPs (MOV R0, R0). For small branches,
you can replace the final branch with a subtract, with the PC as the destination (SUB
PC, PC, #28
in the above example).
C.8.2
Watchpoints
To return to program execution after entry to debug state from a watchpoint, use the
Debug entry adds four addresses to the PC, and every instruction adds one address. The
difference from breakpoint is that the instruction that caused the watchpoint has
executed, and the program must return to the next instruction.