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.

Clarification on "TRAPS" in spru732h

Hi,

Could someone explain about TRAPS described in spru732 (section 5.7.4)?

 

Is this applicable to both c64x and c64x+?

 

Is this something that can be automatically triggered on some condition (something like an exception handler?) or this has to be explicitly called (something like manually triggering an interrupt bu writing to Interrupt set register)?

 

Is there any better documentation that describes configuration and application?

Regards,

Justin

  • Justin,

    Looking at the document, it seems that TRAPS are just a method of implementing software exceptions.  I think you could do something similar on any architecture.  It is noted that the 64x+ actually has hardware to assist in handling exceptions so this type of trap is not necessary.  It doesn't seem like there is anything special here.  the example just shows you hot to implement your own exception handler in assembly.  You essentially check for the condition and store the true/false in A0-A2 or B0-B2.  You then use this code to call your trap handler

     

    [A1] MVKL TRAP_HANDLER,B0 ; load 32-bit trap address
    [A1] MVKH TRAP_HANDLER,B0
    [A1] B B0 ; branch to trap handler
    [A1] MVC CSR,B0 ; read CSR
    [A1] AND -2,B0,B1 ; disable interrupts: GIE = 0
    [A1] MVC B1,CSR ; write to CSR
    [A1] MVKL TRAP_RETURN,B1 ; load 32-bit return address
    [A1] MVKH TRAP_RETURN,B1
    TRAP_RETURN: (post-trap code)
    Note: A1 contains the trap condition.

    And then this code to return

    B B1 ; return
    MVC B0,CSR ; restore CSR
    NOP 4 ; delay slots

     

    Note that the difference between this and a typical function call is really only the disable of interrupts during the trap and the re-enabling when restoring the CSR.


    Regards,

    Dan

     

     

  • Dan,

    Thanks for the reply.

    Is there any document or a sample example code on "how to write and use TRAP_HANDLER"? 

    Is it possible to invoke this TRAP_HANDLER if application code accesses an entire memory range or it works only for one memory address at a time? 

    Regards,

    Justin

     

  • Justin,

    I don't think there is any example code other than what's in SPRU732.  But it should be straightforward to create one.  You just use toe code I pasted in, and right before the top section, test for the trap condition and store the result in A1.  If the result is true, the trap code will be executed.

    Regards,
    Dan