This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SVC_Handler for Cortex M0

Note: This was originally posted on 25th October 2012 at http://forums.arm.com

Hello

we are trying to find  a short implementation for the SVCHandler interrupt.
I want to do exactly like described here, but then a working version for the Cortex-m0:

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0203j/BABFGEFG.html

and here:

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s07.html

we have no experts at assembly and the only thing we need is to get the svc number and arguments.
But if someone can explain me how the svc handler works I would be greatly helped.
And maybe someone can point me in the right direction on how to return values : "[font=Verdana, Tahoma, Arial, Helvetica, sans-serif][size=2]Any return value must also be passed back to the caller by modifying the stacked register values[/size][/font]".

Thank you in advance!

Martijn
Parents
  • Note: This was originally posted on 26th October 2012 at http://forums.arm.com

    Hi

    Look like a text formatting issue confused the MDK tool.
    Please try adding indentations as follows:

    // SVC handler - Assembly wrapper to extract
    //         stack frame starting address
    __asm void SVC_Handler(void)
    {
      MOVS   r0, #4
      MOV r1, LR
      TST r0, r1
      BEQ stacking_used_MSP
      MRS R0, PSP ; first parameter - stacking was using PSP
      LDR R1,=__cpp(SVC_Handler_main)
      BX  R1
    stacking_used_MSP
      MRS R0, MSP ; first parameter - stacking was using MSP
      LDR R1,=__cpp(SVC_Handler_main)
      BX  R1
    }


    The other solution you found works too, but only if your application always use MSP (Main Stack Pointer).

    The code (svc_number = ((char *)svc_args[6])[-2])

    svc_args[6] is the stacked PC. It is the address of the instruction after the SVC.

    The SVC instruction is located in the memory address [stacked_PC - 2], because SVC is a 2 byte instruction.

    The SVC number is the lower byte of the instruction.

    So if without the "[-2]", (char *)svc_args[6] read the lower byte of the instruction after the SVC.
    Adding the "[-2]", it handle that as array of bytes and therefore read the SVC number.

    Hope this is clearer.

    regards,
    Joseph
Reply
  • Note: This was originally posted on 26th October 2012 at http://forums.arm.com

    Hi

    Look like a text formatting issue confused the MDK tool.
    Please try adding indentations as follows:

    // SVC handler - Assembly wrapper to extract
    //         stack frame starting address
    __asm void SVC_Handler(void)
    {
      MOVS   r0, #4
      MOV r1, LR
      TST r0, r1
      BEQ stacking_used_MSP
      MRS R0, PSP ; first parameter - stacking was using PSP
      LDR R1,=__cpp(SVC_Handler_main)
      BX  R1
    stacking_used_MSP
      MRS R0, MSP ; first parameter - stacking was using MSP
      LDR R1,=__cpp(SVC_Handler_main)
      BX  R1
    }


    The other solution you found works too, but only if your application always use MSP (Main Stack Pointer).

    The code (svc_number = ((char *)svc_args[6])[-2])

    svc_args[6] is the stacked PC. It is the address of the instruction after the SVC.

    The SVC instruction is located in the memory address [stacked_PC - 2], because SVC is a 2 byte instruction.

    The SVC number is the lower byte of the instruction.

    So if without the "[-2]", (char *)svc_args[6] read the lower byte of the instruction after the SVC.
    Adding the "[-2]", it handle that as array of bytes and therefore read the SVC number.

    Hope this is clearer.

    regards,
    Joseph
Children
No data