SVC call handler

16 Aug 2010

I have been trying to implement an SVC call handler with a view to creating a SW trapped interface to a controlled environment which I can use as the API to a RTOs. I am following the route according to Arm application note 178. I have placed the assembler in a separate .s file. Yes I know its not officially supported. Everything compiles and links OK. The only problem I had was finding the correct DEFINE for the SVC IRQ number I eventually settled for SVCCall_IRQn  - Can you confirm this is corrrect.

I installled the handler like this.

NVIC_SetVector(SVCall_IRQn, (uint32_t)&SVCHandler);

NVIC_EnableIRQ(SVCall_IRQn);

needless to say it crashes after executing this step.

I started to think maybe the SVC call is already being used by the Mbed library as an API system. So my main question is whether or not the SVC is available to use on Mbed, or whether it is already in use - explaining the problems I am having.

best regards

Nick

 

 

16 Aug 2010

Do it like this:

extern "C" void SVC_Handler(int R0)
{
  printf("SVC handler called with R0=%d\n", R0);
}

This will override the default weak SVC_Handler declared startup_LPC17xx.o, and will place your vector directly into the flash vector table.

You don't need to explicitly enable the exception, SVCall is always enabled. You can, however, configure its priority.

SVCall
This supervisor call handles the exception caused by the SVC instruction. SVCall is permanently enabled and has a configurable priority."

It seems you might also have to implement PendSV (PendSV_Handler). The ARMv7-M ARM is not terribly clear, but it says this:

PendSV
Used for software-generated system calls. An application uses a Supervisor call, if it requires servicing by the underlying operating system. The Supervisor call associated with PendSV executes when the processor takes the PendSV interrupt.
Note
For a Supervisor call that executes synchronously with program execution, software must use the SVC instruction. This generates an SVCall exception. PendSV is permanently enabled, and is controlled using the ICSR.PENDSVSET and ICSR.PENDSVCLR bits,.

16 Aug 2010

Hi Igor,

Thanks for your ideas.

As far as I understand it...

extern "C" void SVC_Handler(int R0)
{
  printf("SVC handler called with R0=%d\n", R0);
}

is just the external declaration, and i have already defined my handler in this way. What makes you think think this is enough to have it copied into the vector table as well.???

I think you are write about the enabling though, SVC should always be active and I will remove the line

NVIC_EnableIRQ(SVCall_IRQn); and see what happens.

This is my handler

void __svc(SVC_00) svc_zero(const char *string);
void __svc(SVC_01) svc_one(const char *string);

extern "C" void SVCHandler_main(unsigned int * svc_args)
{
unsigned int svc_number;
/*
* Stack contains:
* r0, r1, r2, r3, r12, r14, the return address and xPSR
* First argument (r0) is svc_args[0]
*/
svc_number = ((char *)svc_args[6])[-2];
switch(svc_number)
{
case SVC_00:
/* Handle SVC 00 */
break;
case SVC_01:
/* Handle SVC 01 */
break;
default:
/* Unknown SVC */
break;
}
}
and this is my assembler wrapper which has to be installed in the vector table.

  AREA |.text|, CODE, READONLY
    ENTRY
    EXPORT SVCHandler
SVCHandler
    IMPORT SVCHandler_main
    TST lr, #4
    MRSEQ r0, MSP
    MRSNE r0, PSP
    B SVCHandler_main
    END

I still suspect that mbed is using the SVC vector....
nick

 

16 Aug 2010

Hi again Igor,

Actually PENDSV is not connected with SVC althogh it is also a SW exception methos.

There is a good explanation of it here

http://books.google.nl/books?id=T9heqSaErCcC&pg=PA133&lpg=PA133&dq=Arm+M3+PendSV&source=bl&ots=eNwrEbHg1z&sig=RM-HWnFu9BeyvwbbUYzj14t00rE&hl=en&ei=IV1pTN6yINOOOPru5bgF&sa=X&oi=book_result&ct=result&resnum=4&ved=0CB0Q6AEwAw#v=onepage&q=Arm%20M3%20PendSV&f=false

actually it might be more suitable for what i want to do.

Of course I would still like to know if it is being used by the Mbed libraries.

 

Nick

16 Aug 2010

The default startup file has the following:

                DCD     SVC_Handler               ; SVCall Handler
[...]
SVC_Handler     PROC
                EXPORT  SVC_Handler               [WEAK]
                B       .
                ENDP
Thus, if you define your own non-weak SVC_Handler, it will take over. I have verified that the new vector is indeed in the compiled bin file.

To debug the problem, I suggest you to implement fault handlers and print messages or blink various LEDs in them, so you can see what happens. See here.

16 Aug 2010

HI Igor

Thanks. Yes I understand; the way the startup file does this the linker will find my routine if it has the same name.

I wasnt aware of this symbolic association in the examples I was following.

OK.. time to experiment.