12.11. Using the debug functionality

This section provides some examples of using the debug functionality, both from the point of view of a software engineer writing code to run on an ARM processor and of a developer creating debug tools for the processor. In the former case, examples are given in ARM assembly language. In the latter case, the examples are in C pseudo-language, intended to convey the algorithms to be used. These examples are not intended as source code for a debugger.

The debugger examples use a pair of pseudo-functions such as the following:

uint32 ReadDebugRegister(int reg_num)
{
    // read the value of the debug register reg_num at address reg_num << 2
}

WriteDebugRegister(int reg_num, uint32 val)
{
    // write the value val to the debug register reg_num at address reg_num >> 2
}

A basic function for using the debug state is executing an instruction through the ITR. Example 12.1 shows the sequence for executing an ARM instruction through the ITR.

Example 12.1. Executing an ARM instruction through the ITR

ExecuteARMInstruction(uint32 instr)
{
    // Step 1. Poll DSCR until InstrCompl is set to 1.
    repeat
    {
        dscr := ReadDebugRegister(34);
    }
    until (dscr & (1<<24));
    // Step 2. Write the opcode to the ITR.
    WriteDebugRegister(33, instr);
    // Step 3. Poll DSCR until InstrCompl is set to 1.
    repeat
    {
    dscr := ReadDebugRegister(34);
    }
    until (dscr & (1<<24);
}

Copyright © 2006-2009 ARM Limited. All rights reserved.ARM DDI 0344I
Non-Confidential