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.

SWI Handler

Other Parts Discussed in Thread: TMS570LS2125

Where can I find information needed to write a SWI handler?

The TMS470 C Compiler user's manual provides information on the compiler intrinsic _call_swi() but doesn't explain how to find the SWI #, for example.

So how do you write a handler that responds to different SWI #'s?

 

  • Anthony,

    You need to read the swi number from the instruction causing the current swi. Below code snippet is a typical TMS570 ISR

    SUPERVISOR SERVICE ROUTINE
    svc:    STMFD   sp!, {r0-r12,lr}        ; Save registers on stack
                LDR   r0, [lr,#-4]                 ; Load the SVC inst into R0
                BIC    r0, r0, #0xFF000000  ; Mask out SVC number
    -----
    -----
    -----
                LDMFD   sp!, {r0-r12,pc}^   ; Restore registers and return

     

  • Please be aware that the use of SWI is deprecated on the v7R architecture (Cortex-R4(f)). It should be replaced by the SVC instruction in any code.

    The code Prathap posted works with retrieving the SVC number when the instruction is coded in ARM instruction set, but it will not work if the instruction is coded in Thumb/Thumb-2. To be able to cover both cases, following code snippet can be used:

    SUPERVISOR SERVICE ROUTINE
    svc:    STMFD       sp!, {r0-r12,lr}        ; Save registers on stack
             LDRB         r0, [lr,#-1]         ; Load the SVC-# into R0
    -----
    -----
    -----
             LDMFD   sp!, {r0-r12,pc}^   ; Restore registers and return
    The above code will only load the lower byte of the instruction and this will cover both ARM and Thumb(-2) instruction sets. The only restriction is that only 256 individual numbers can be passed to the SVC handler. But in most cases this should be enough for specific operating system calls. Another advantage of this approach is that it saves one instruction (BIC) and speeds up the code execution.
  • Frank,

    I am using a TMS570LS2125 and working with legacy code that has a SWI handler. My legacy SWI handler does not seem to work with this processor.

    Could you please post an example written in C for how to implement a SVC handler to replace the functionality of the SWI handler? The example I am working with seems to suggest that a -o2 compiler option is required for this mechanism to work. Is the same true for a SVC handler?

    http://e2e.ti.com/support/microcontrollers/hercules/f/312/t/150918.aspx#572849

    I have versions v4.6.3 and v4.9.1 of the cgtools if this makes any difference.

    Thank you.