ARM R4F Computer Hardware User Manual


 
Debug
ARM DDI 0363E Copyright © 2009 ARM Limited. All rights reserved. 11-65
ID013010 Non-Confidential, Unrestricted Access
Example 11-17 Writing the CPSR
WriteCPSR(uint32 cpsr_val)
{
// Step 1. Save R0.
saved_r0 := ReadRegister(0);
// Step 2. Write the new CPSR value to R0.
WriteRegister(0, cpsr_val);
// Step 3. Execute instruction MSR R0, CPSR through the ITR.
ExecuteARMInstruction(0xE12FF000);
// Step 4. Execute a PrefetchFlush instruction through the ITR.
ExecuteARMInstruction(9xEE070F95);
// Step 5. Restore the value of R0.
WriteRegister(0, saved_r0);
}
Reading memory
Example 11-18 shows the code for reading a byte of memory.
Example 11-18 Reading a byte of memory
uint8 ReadByte(uint32 address, bool &aborted)
{
// Step 1. Save the values of R0 and R1.
saved_r0 := ReadRegister(0);
saved_r1 := ReadRegister(1);
// Step 2. Write the address to R0.
WriteRegister(0, address);
// Step 3. Execute the instruction LDRB R1,[R0] through the ITR.
ExecuteARMInstruction(0xE5D01000);
// Step 4. Read the value of R1 that contains the data at the address.
datum := ReadRegister(1);
// Step 5. Restore the corrupted registers R0 and R1.
WriteRegister(0, saved_r0);
WriteRegister(1, saved_r1);
// Step 6. Check the DSCR for a sticky abort.
aborted := CheckForAborts();
return datum;
}
Example 11-19 shows the code for checking for aborts after a memory access.
Example 11-19 Checking for an abort after memory access
bool CheckForAborts()
{
// Step 1. Check the DSCR for a sticky abort.
dscr := ReadDebugRegister(34);
if (dscr & ((1<<6) + (1<<7))
{
// Step 2. Clear the sticky flag by writing DRCR[2].
WriteDebugRegister(36, 1<<2);
return true;
}
else