Question

  1. I am trying to do a context switching on lpc 1769 (cortex m3). I am trying to write a routine that calculates the exponential of a number, runs it as a subroutine in User mode, but uses SVC calls and an interrupt handler to ask the SVC process to interact with the terminal on its behalf. Values to be printed out should be passed as register arguments to the SVC.

  2. If I do mode switch from user mode to main mode, how can I get the values stored in stack of user mode to main mode?

  3. Can anyone please write a small program for the above queries?

Thank you in advance.

Was it helpful?

Solution

  1. You can pass up to four parameters easily. Just write a C function and use inline assembler to call the supervisor:

    #define svc(code) asm volatile ("svc %[immediate]"::[immediate] "I" (code))
    #define SVC_WRITE_DATA 1
    
    void sv_call_write_data(char *string, int length)
    {
        svc(SVC_WRITE_DATA);
    }
    

See point 3 how to extract those parameters in the supervisor call handler.

  1. You can get the values from the user mode stack directly. Use inline assembler to determine the stack used by the caller:

        asm volatile(
            "tst lr, #4\t\n" /* Check EXC_RETURN[2] */
            "ite eq\t\n"
            "mrseq r0, msp\t\n"
            "mrsne r0, psp\t\n"
            "b %[sv_call_handler_main]\t\n"
            : /* no output */
            : [sv_call_handler_main] "i" (sv_call_handler_main) /* input */
            : "r0" /* clobber */
        );
    
  2. Since I'm currently hassling around with this too, I wrote a blog post about it. Your IDE uses GCC, so this should apply for you too: http://falstaff.agner.ch/2013/02/18/cortex-m3-supervisor-call-svc-using-gcc/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top