This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

data abort handler example available?

Other Parts Discussed in Thread: HALCOGEN

hello

I am writing a test that tests the MPU configuration. If a violate a MPU-region-setting, I get a data-abort, as expected.

I have been searching for a code-example, that shows, how data-aborts are handled. Is something like this available?

If not, I would appreciate a code-snippet that shows the following:
1 detect the reason for the data-abort (e.g. MPU-fault)
2 depending on the reason, continue execution of the MPU-test or
3 reset the processor
4 after the reset of the processor, the program shall be able to figure out what the reset reason was. By readind the SYSESR register I only get limited information, Is there a way of determining the reset reason in more detail (e.g. MPU-Fault causing data-abort)?

Best regards

Flurin

  • Hello Flurin,

    1 detect the reason for the data-abort (e.g. MPU-fault)

    You need to read the Cortex R4 system registers for Data Fault address and status:

    	dabt_addr = Read_DFAR();
    dabt_stat = Read_DFSR();
    Read_DFSR:
    MRC p15, #0, r0, c5, c0, #0
    MOV pc, r14

    Read_DFAR:
    MRC p15, #0, r0, c6, c0, #0
    MOV pc, r14

    2 depending on the reason, continue execution of the MPU-test or

    If that is the case you can return to the next address to execute by checking the address stored on the stack and changing it to the next address:

        asm(" ldr r0,[sp,#8]");
    asm(" add r0,r0,#4");
    asm(" str r0,[sp,#8]");


    3 reset the processor

    The software reset is part of register System Exception Control Register (SWRESET)


    4 after the reset of the processor, the program shall be able to figure out what the reset reason was. By readind the SYSESR register I only get limited information, Is there a way of determining the reset reason in more detail (e.g. MPU-Fault causing data-abort)?

    The status registers in case of a prefetch or data abort can be internal to the CPU. For the MPU all relevant documentation will be in the Cortex R4 TRM.

    I hope this helps.

    Luc

  • Flurin,

    I attached a simple example for a Data Abort Handler, this can be used with the HDK.

    The example setup some MPU regions (done with HALCoGen) and provoke an access error on address 0x08000000, which is read in user mode but it is setup to be only readable in priv mode.

    In general this example uses the CP15 functions which comes with HALCoGen. The declaration of these function can be found in the file sys_core.h and the definitions in sys_core.asm.

    With the function _coreGetDataFault_ the DFSR (Data Fault Status Register) can be read.
    With the function _coreGetDataFaultAddress_ the DFAR (Data Fault Address Register) can be read.
    These registers are described here: http://infocenter.arm.com/help/topic/com.arm.doc.ddi0363g/BGBEDEIF.html?resultof=%22%44%46%53%52%22%20%22%64%66%73%72%22%20

    Best Regards,

    Christian

    DataAbortHandler.zip
  • Hi Christian

    I would like to get the address in the code that generated the data abort. From the Cortex-R4 technical reference manual, chapter 2.8.1: SUBS PC, R14_abt, #8. How can I get the value of the address in C?

    Thanks Daniel

  • Daniel,

    if you want to get this address I would propose to write a small data abort handler in Assembly which than can call a second level C abort handler.
    The Assembly handler can take the value of the LR and pass it to the C handler via the argument registers (R0-R3).

    Please find an modified example project attached.

     

    Best Regards,
    Christian

    DataAbortHandler.zip