]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/portasm.c
Add support for running FreeRTOS on Secure Side only in Cortex M33 port. Also, change...
[freertos] / FreeRTOS / Source / portable / ARMv8M / non_secure / portable / GCC / ARM_CM33_NTZ / portasm.c
index b8fd05bfa37f48e4cd22d805212a8fc434ccbdd3..68aafd83e9b883423c2c46837073bf7ac0c35f80 100644 (file)
 \r
 void vRestoreContextOfFirstTask( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    .syntax unified                                \n"\r
-    "                                                   \n"\r
-    "    ldr  r2, pxCurrentTCBConst2                    \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
-    "    ldr  r1, [r2]                                  \n" /* Read pxCurrentTCB. */\r
-    "    ldr  r0, [r1]                                  \n" /* Read top of stack from TCB - The first item in pxCurrentTCB is the task top of stack. */\r
-    "                                                   \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "    adds r1, #4                                    \n" /* r1 = r1 + 4. r1 now points to MAIR0 in TCB. */\r
-    "    ldr  r3, [r1]                                  \n" /* r3 = *r1 i.e. r3 = MAIR0. */\r
-    "    ldr  r2, xMAIR0Const2                          \n" /* r2 = 0xe000edc0 [Location of MAIR0]. */\r
-    "    str  r3, [r2]                                  \n" /* Program MAIR0. */\r
-    "    ldr  r2, xRNRConst2                            \n" /* r2 = 0xe000ed98 [Location of RNR]. */\r
-    "    movs r3, #4                                    \n" /* r3 = 4. */\r
-    "    str  r3, [r2]                                  \n" /* Program RNR = 4. */\r
-    "    adds r1, #4                                    \n" /* r1 = r1 + 4. r1 now points to first RBAR in TCB. */\r
-    "    ldr  r2, xRBARConst2                           \n" /* r2 = 0xe000ed9c [Location of RBAR]. */\r
-    "    ldmia r1!, {r4-r11}                            \n" /* Read 4 set of RBAR/RLAR registers from TCB. */\r
-    "    stmia r2!, {r4-r11}                            \n" /* Write 4 set of RBAR/RLAR registers using alias registers. */\r
-    #endif /* configENABLE_MPU */\r
-    "                                                   \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "    ldm  r0!, {r1-r3}                              \n" /* Read from stack - r1 = PSPLIM, r2 = CONTROL and r3 = EXC_RETURN. */\r
-    "    msr  psplim, r1                                \n" /* Set this task's PSPLIM value. */\r
-    "    msr  control, r2                               \n" /* Set this task's CONTROL value. */\r
-    "    adds r0, #32                                   \n" /* Discard everything up to r0. */\r
-    "    msr  psp, r0                                   \n" /* This is now the new top of stack to use in the task. */\r
-    "    isb                                            \n"\r
-    "    bx   r3                                        \n" /* Finally, branch to EXC_RETURN. */\r
-    #else /* configENABLE_MPU */\r
-    "    ldm  r0!, {r1-r2}                              \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */\r
-    "    msr  psplim, r1                                \n" /* Set this task's PSPLIM value. */\r
-    "    movs r1, #2                                    \n" /* r1 = 2. */\r
-    "    msr  CONTROL, r1                               \n" /* Switch to use PSP in the thread mode. */\r
-    "    adds r0, #32                                   \n" /* Discard everything up to r0. */\r
-    "    msr  psp, r0                                   \n" /* This is now the new top of stack to use in the task. */\r
-    "    isb                                            \n"\r
-    "    bx   r2                                        \n" /* Finally, branch to EXC_RETURN. */\r
-    #endif /* configENABLE_MPU */\r
-    "                                                   \n"\r
-    "    .align 4                                       \n"\r
-    "pxCurrentTCBConst2: .word pxCurrentTCB             \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "xMAIR0Const2: .word 0xe000edc0                     \n"\r
-    "xRNRConst2: .word 0xe000ed98                       \n"\r
-    "xRBARConst2: .word 0xe000ed9c                      \n"\r
-    #endif /* configENABLE_MPU */\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       .syntax unified                                                                 \n"\r
+       "                                                                                                       \n"\r
+       "       ldr  r2, pxCurrentTCBConst2                                             \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
+       "       ldr  r1, [r2]                                                                   \n" /* Read pxCurrentTCB. */\r
+       "       ldr  r0, [r1]                                                                   \n" /* Read top of stack from TCB - The first item in pxCurrentTCB is the task top of stack. */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "       adds r1, #4                                                                             \n" /* r1 = r1 + 4. r1 now points to MAIR0 in TCB. */\r
+       "       ldr  r3, [r1]                                                                   \n" /* r3 = *r1 i.e. r3 = MAIR0. */\r
+       "       ldr  r2, xMAIR0Const2                                                   \n" /* r2 = 0xe000edc0 [Location of MAIR0]. */\r
+       "       str  r3, [r2]                                                                   \n" /* Program MAIR0. */\r
+       "       ldr  r2, xRNRConst2                                                             \n" /* r2 = 0xe000ed98 [Location of RNR]. */\r
+       "       movs r3, #4                                                                             \n" /* r3 = 4. */\r
+       "       str  r3, [r2]                                                                   \n" /* Program RNR = 4. */\r
+       "       adds r1, #4                                                                             \n" /* r1 = r1 + 4. r1 now points to first RBAR in TCB. */\r
+       "       ldr  r2, xRBARConst2                                                    \n" /* r2 = 0xe000ed9c [Location of RBAR]. */\r
+       "       ldmia r1!, {r4-r11}                                                             \n" /* Read 4 set of RBAR/RLAR registers from TCB. */\r
+       "       stmia r2!, {r4-r11}                                                             \n" /* Write 4 set of RBAR/RLAR registers using alias registers. */\r
+       #endif /* configENABLE_MPU */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "       ldm  r0!, {r1-r3}                                                               \n" /* Read from stack - r1 = PSPLIM, r2 = CONTROL and r3 = EXC_RETURN. */\r
+       "       msr  psplim, r1                                                                 \n" /* Set this task's PSPLIM value. */\r
+       "       msr  control, r2                                                                \n" /* Set this task's CONTROL value. */\r
+       "       adds r0, #32                                                                    \n" /* Discard everything up to r0. */\r
+       "       msr  psp, r0                                                                    \n" /* This is now the new top of stack to use in the task. */\r
+       "       isb                                                                                             \n"\r
+       "       bx   r3                                                                                 \n" /* Finally, branch to EXC_RETURN. */\r
+       #else /* configENABLE_MPU */\r
+       "       ldm  r0!, {r1-r2}                                                               \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */\r
+       "       msr  psplim, r1                                                                 \n" /* Set this task's PSPLIM value. */\r
+       "       movs r1, #2                                                                             \n" /* r1 = 2. */\r
+       "       msr  CONTROL, r1                                                                \n" /* Switch to use PSP in the thread mode. */\r
+       "       adds r0, #32                                                                    \n" /* Discard everything up to r0. */\r
+       "       msr  psp, r0                                                                    \n" /* This is now the new top of stack to use in the task. */\r
+       "       isb                                                                                             \n"\r
+       "       bx   r2                                                                                 \n" /* Finally, branch to EXC_RETURN. */\r
+       #endif /* configENABLE_MPU */\r
+       "                                                                                                       \n"\r
+       "       .align 4                                                                                \n"\r
+       "pxCurrentTCBConst2: .word pxCurrentTCB                         \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "xMAIR0Const2: .word 0xe000edc0                                         \n"\r
+       "xRNRConst2: .word 0xe000ed98                                           \n"\r
+       "xRBARConst2: .word 0xe000ed9c                                          \n"\r
+       #endif /* configENABLE_MPU */\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 BaseType_t xIsPrivileged( void ) /* __attribute__ (( naked )) */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    mrs r0, control                                \n" /* r0 = CONTROL. */\r
-    "    tst r0, #1                                     \n" /* Perform r0 & 1 (bitwise AND) and update the conditions flag. */\r
-    "    ite ne                                         \n"\r
-    "    movne r0, #0                                   \n" /* CONTROL[0]!=0. Return false to indicate that the processor is not privileged. */\r
-    "    moveq r0, #1                                   \n" /* CONTROL[0]==0. Return true to indicate that the processor is privileged. */\r
-    "    bx lr                                          \n" /* Return. */\r
-    "                                                   \n"\r
-    "    .align 4                                       \n"\r
-    ::: "r0", "memory"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       mrs r0, control                                                                 \n" /* r0 = CONTROL. */\r
+       "       tst r0, #1                                                                              \n" /* Perform r0 & 1 (bitwise AND) and update the conditions flag. */\r
+       "       ite ne                                                                                  \n"\r
+       "       movne r0, #0                                                                    \n" /* CONTROL[0]!=0. Return false to indicate that the processor is not privileged. */\r
+       "       moveq r0, #1                                                                    \n" /* CONTROL[0]==0. Return true to indicate that the processor is privileged. */\r
+       "       bx lr                                                                                   \n" /* Return. */\r
+       "                                                                                                       \n"\r
+       "       .align 4                                                                                \n"\r
+       ::: "r0", "memory"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vRaisePrivilege( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-     __asm volatile\r
-    (\r
-    "    mrs  r0, control                               \n" /* Read the CONTROL register. */\r
-    "    bic r0, #1                                     \n" /* Clear the bit 0. */\r
-    "    msr  control, r0                               \n" /* Write back the new CONTROL value. */\r
-    "    bx lr                                          \n" /* Return to the caller. */\r
-    ::: "r0", "memory"\r
-    );\r
+        __asm volatile\r
+       (\r
+       "       mrs  r0, control                                                                \n" /* Read the CONTROL register. */\r
+       "       bic r0, #1                                                                              \n" /* Clear the bit 0. */\r
+       "       msr  control, r0                                                                \n" /* Write back the new CONTROL value. */\r
+       "       bx lr                                                                                   \n" /* Return to the caller. */\r
+       ::: "r0", "memory"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vResetPrivilege( void ) /* __attribute__ (( naked )) */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    mrs r0, control                                \n" /* r0 = CONTROL. */\r
-    "    orr r0, #1                                     \n" /* r0 = r0 | 1. */\r
-    "    msr control, r0                                \n" /* CONTROL = r0. */\r
-    "    bx lr                                          \n" /* Return to the caller. */\r
-    :::"r0", "memory"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       mrs r0, control                                                                 \n" /* r0 = CONTROL. */\r
+       "       orr r0, #1                                                                              \n" /* r0 = r0 | 1. */\r
+       "       msr control, r0                                                                 \n" /* CONTROL = r0. */\r
+       "       bx lr                                                                                   \n" /* Return to the caller. */\r
+       :::"r0", "memory"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vStartFirstTask( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    ldr r0, xVTORConst                             \n" /* Use the NVIC offset register to locate the stack. */\r
-    "    ldr r0, [r0]                                   \n" /* Read the VTOR register which gives the address of vector table. */\r
-    "    ldr r0, [r0]                                   \n" /* The first entry in vector table is stack pointer. */\r
-    "    msr msp, r0                                    \n" /* Set the MSP back to the start of the stack. */\r
-    "    cpsie i                                        \n" /* Globally enable interrupts. */\r
-    "    cpsie f                                        \n"\r
-    "    dsb                                            \n"\r
-    "    isb                                            \n"\r
-    "    svc %0                                         \n" /* System call to start the first task. */\r
-    "    nop                                            \n"\r
-    "                                                   \n"\r
-    "   .align 4                                        \n"\r
-    "xVTORConst: .word 0xe000ed08                       \n"\r
-    :: "i" ( portSVC_START_SCHEDULER ) : "memory"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       ldr r0, xVTORConst                                                              \n" /* Use the NVIC offset register to locate the stack. */\r
+       "       ldr r0, [r0]                                                                    \n" /* Read the VTOR register which gives the address of vector table. */\r
+       "       ldr r0, [r0]                                                                    \n" /* The first entry in vector table is stack pointer. */\r
+       "       msr msp, r0                                                                             \n" /* Set the MSP back to the start of the stack. */\r
+       "       cpsie i                                                                                 \n" /* Globally enable interrupts. */\r
+       "       cpsie f                                                                                 \n"\r
+       "       dsb                                                                                             \n"\r
+       "       isb                                                                                             \n"\r
+       "       svc %0                                                                                  \n" /* System call to start the first task. */\r
+       "       nop                                                                                             \n"\r
+       "                                                                                                       \n"\r
+       "   .align 4                                                                            \n"\r
+       "xVTORConst: .word 0xe000ed08                                           \n"\r
+       :: "i" ( portSVC_START_SCHEDULER ) : "memory"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 uint32_t ulSetInterruptMaskFromISR( void ) /* __attribute__(( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    mrs r0, PRIMASK                                \n"\r
-    "    cpsid i                                        \n"\r
-    "    bx lr                                          \n"\r
-    ::: "memory"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       mrs r0, PRIMASK                                                                 \n"\r
+       "       cpsid i                                                                                 \n"\r
+       "       bx lr                                                                                   \n"\r
+       ::: "memory"\r
+       );\r
 \r
 #if !defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)\r
-    /* To avoid compiler warnings.  The return statement will never be reached,\r
-     * but some compilers warn if it is not included, while others won't compile\r
-     * if it is. */\r
-    return 0;\r
+       /* To avoid compiler warnings.  The return statement will never be reached,\r
+        * but some compilers warn if it is not included, while others won't compile\r
+        * if it is. */\r
+       return 0;\r
 #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vClearInterruptMaskFromISR( __attribute__( ( unused ) ) uint32_t ulMask ) /* __attribute__(( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    msr PRIMASK, r0                                \n"\r
-    "    bx lr                                          \n"\r
-    ::: "memory"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       msr PRIMASK, r0                                                                 \n"\r
+       "       bx lr                                                                                   \n"\r
+       ::: "memory"\r
+       );\r
 \r
 #if !defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)\r
-    /* Just to avoid compiler warning.  ulMask is used from the asm code but\r
-     * the compiler can't see that.  Some compilers generate warnings without\r
-     * the following line, while others generate warnings if the line is\r
-     * included. */\r
-    ( void ) ulMask;\r
+       /* Just to avoid compiler warning.  ulMask is used from the asm code but\r
+        * the compiler can't see that.  Some compilers generate warnings without\r
+        * the following line, while others generate warnings if the line is\r
+        * included. */\r
+       ( void ) ulMask;\r
 #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void PendSV_Handler( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "    .syntax unified                                \n"\r
-    "                                                   \n"\r
-    "    mrs r0, psp                                    \n" /* Read PSP in r0. */\r
-    #if( configENABLE_FPU == 1 )\r
-    "    tst lr, #0x10                                  \n" /* Test Bit[4] in LR. Bit[4] of EXC_RETURN is 0 if the FPU is in use. */\r
-    "    it eq                                          \n"\r
-    "    vstmdbeq r0!, {s16-s31}                        \n" /* Store the FPU registers which are not saved automatically. */\r
-    #endif /* configENABLE_FPU */\r
-    #if( configENABLE_MPU == 1 )\r
-    "    mrs r1, psplim                                 \n" /* r1 = PSPLIM. */\r
-    "    mrs r2, control                                \n" /* r2 = CONTROL. */\r
-    "    mov r3, lr                                     \n" /* r3 = LR/EXC_RETURN. */\r
-    "    stmdb r0!, {r1-r11}                            \n" /* Store on the stack - PSPLIM, CONTROL, LR and registers that are not automatically saved. */\r
-    #else /* configENABLE_MPU */\r
-    "    mrs r2, psplim                                 \n" /* r2 = PSPLIM. */\r
-    "    mov r3, lr                                     \n" /* r3 = LR/EXC_RETURN. */\r
-    "    stmdb r0!, {r2-r11}                            \n" /* Store on the stack - PSPLIM, LR and registers that are not automatically saved. */\r
-    #endif /* configENABLE_MPU */\r
-    "                                                   \n"\r
-    "    ldr r2, pxCurrentTCBConst                      \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
-    "    ldr r1, [r2]                                   \n" /* Read pxCurrentTCB. */\r
-    "    str r0, [r1]                                   \n" /* Save the new top of stack in TCB. */\r
-    "                                                   \n"\r
-    "    cpsid i                                        \n"\r
-    "    bl vTaskSwitchContext                          \n"\r
-    "    cpsie i                                        \n"\r
-    "                                                   \n"\r
-    "    ldr r2, pxCurrentTCBConst                      \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
-    "    ldr r1, [r2]                                   \n" /* Read pxCurrentTCB. */\r
-    "    ldr r0, [r1]                                   \n" /* The first item in pxCurrentTCB is the task top of stack. r0 now points to the top of stack. */\r
-    "                                                   \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "    adds r1, #4                                    \n" /* r1 = r1 + 4. r1 now points to MAIR0 in TCB. */\r
-    "    ldr r3, [r1]                                   \n" /* r3 = *r1 i.e. r3 = MAIR0. */\r
-    "    ldr r2, xMAIR0Const                            \n" /* r2 = 0xe000edc0 [Location of MAIR0]. */\r
-    "    str r3, [r2]                                   \n" /* Program MAIR0. */\r
-    "    ldr r2, xRNRConst                              \n" /* r2 = 0xe000ed98 [Location of RNR]. */\r
-    "    movs r3, #4                                    \n" /* r3 = 4. */\r
-    "    str r3, [r2]                                   \n" /* Program RNR = 4. */\r
-    "    adds r1, #4                                    \n" /* r1 = r1 + 4. r1 now points to first RBAR in TCB. */\r
-    "    ldr r2, xRBARConst                             \n" /* r2 = 0xe000ed9c [Location of RBAR]. */\r
-    "    ldmia r1!, {r4-r11}                            \n" /* Read 4 sets of RBAR/RLAR registers from TCB. */\r
-    "    stmia r2!, {r4-r11}                            \n" /* Write 4 set of RBAR/RLAR registers using alias registers. */\r
-    #endif /* configENABLE_MPU */\r
-    "                                                   \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "    ldmia r0!, {r1-r11}                            \n" /* Read from stack - r1 = PSPLIM, r2 = CONTROL, r3 = LR and r4-r11 restored. */\r
-    #else /* configENABLE_MPU */\r
-    "    ldmia r0!, {r2-r11}                            \n" /* Read from stack - r2 = PSPLIM, r3 = LR and r4-r11 restored. */\r
-    #endif /* configENABLE_MPU */\r
-    "                                                   \n"\r
-    #if( configENABLE_FPU == 1 )\r
-    "    tst r3, #0x10                                  \n" /* Test Bit[4] in LR. Bit[4] of EXC_RETURN is 0 if the FPU is in use. */\r
-    "    it eq                                          \n"\r
-    "    vldmiaeq r0!, {s16-s31}                        \n" /* Restore the FPU registers which are not restored automatically. */\r
-    #endif /* configENABLE_FPU */\r
-    "                                                   \n"\r
-    #if( configENABLE_MPU == 1 )\r
-    "    msr psplim, r1                                 \n" /* Restore the PSPLIM register value for the task. */\r
-    "    msr control, r2                                \n" /* Restore the CONTROL register value for the task. */\r
-    #else /* configENABLE_MPU */\r
-    "    msr psplim, r2                                 \n" /* Restore the PSPLIM register value for the task. */\r
-    #endif /* configENABLE_MPU */\r
-    "    msr psp, r0                                    \n" /* Remember the new top of stack for the task. */\r
-    "    bx r3                                          \n"\r
-    "                                                   \n"\r
-    "    .align 4                                       \n"\r
-    "pxCurrentTCBConst: .word pxCurrentTCB              \n"\r
-    "xMAIR0Const: .word 0xe000edc0                      \n"\r
-    "xRNRConst: .word 0xe000ed98                        \n"\r
-    "xRBARConst: .word 0xe000ed9c                       \n"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "       .syntax unified                                                                 \n"\r
+       "                                                                                                       \n"\r
+       "       mrs r0, psp                                                                             \n" /* Read PSP in r0. */\r
+       #if( configENABLE_FPU == 1 )\r
+       "       tst lr, #0x10                                                                   \n" /* Test Bit[4] in LR. Bit[4] of EXC_RETURN is 0 if the FPU is in use. */\r
+       "       it eq                                                                                   \n"\r
+       "       vstmdbeq r0!, {s16-s31}                                                 \n" /* Store the FPU registers which are not saved automatically. */\r
+       #endif /* configENABLE_FPU */\r
+       #if( configENABLE_MPU == 1 )\r
+       "       mrs r1, psplim                                                                  \n" /* r1 = PSPLIM. */\r
+       "       mrs r2, control                                                                 \n" /* r2 = CONTROL. */\r
+       "       mov r3, lr                                                                              \n" /* r3 = LR/EXC_RETURN. */\r
+       "       stmdb r0!, {r1-r11}                                                             \n" /* Store on the stack - PSPLIM, CONTROL, LR and registers that are not automatically saved. */\r
+       #else /* configENABLE_MPU */\r
+       "       mrs r2, psplim                                                                  \n" /* r2 = PSPLIM. */\r
+       "       mov r3, lr                                                                              \n" /* r3 = LR/EXC_RETURN. */\r
+       "       stmdb r0!, {r2-r11}                                                             \n" /* Store on the stack - PSPLIM, LR and registers that are not automatically saved. */\r
+       #endif /* configENABLE_MPU */\r
+       "                                                                                                       \n"\r
+       "       ldr r2, pxCurrentTCBConst                                               \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
+       "       ldr r1, [r2]                                                                    \n" /* Read pxCurrentTCB. */\r
+       "       str r0, [r1]                                                                    \n" /* Save the new top of stack in TCB. */\r
+       "                                                                                                       \n"\r
+       "       cpsid i                                                                                 \n"\r
+       "       bl vTaskSwitchContext                                                   \n"\r
+       "       cpsie i                                                                                 \n"\r
+       "                                                                                                       \n"\r
+       "       ldr r2, pxCurrentTCBConst                                               \n" /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */\r
+       "       ldr r1, [r2]                                                                    \n" /* Read pxCurrentTCB. */\r
+       "       ldr r0, [r1]                                                                    \n" /* The first item in pxCurrentTCB is the task top of stack. r0 now points to the top of stack. */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "       adds r1, #4                                                                             \n" /* r1 = r1 + 4. r1 now points to MAIR0 in TCB. */\r
+       "       ldr r3, [r1]                                                                    \n" /* r3 = *r1 i.e. r3 = MAIR0. */\r
+       "       ldr r2, xMAIR0Const                                                             \n" /* r2 = 0xe000edc0 [Location of MAIR0]. */\r
+       "       str r3, [r2]                                                                    \n" /* Program MAIR0. */\r
+       "       ldr r2, xRNRConst                                                               \n" /* r2 = 0xe000ed98 [Location of RNR]. */\r
+       "       movs r3, #4                                                                             \n" /* r3 = 4. */\r
+       "       str r3, [r2]                                                                    \n" /* Program RNR = 4. */\r
+       "       adds r1, #4                                                                             \n" /* r1 = r1 + 4. r1 now points to first RBAR in TCB. */\r
+       "       ldr r2, xRBARConst                                                              \n" /* r2 = 0xe000ed9c [Location of RBAR]. */\r
+       "       ldmia r1!, {r4-r11}                                                             \n" /* Read 4 sets of RBAR/RLAR registers from TCB. */\r
+       "       stmia r2!, {r4-r11}                                                             \n" /* Write 4 set of RBAR/RLAR registers using alias registers. */\r
+       #endif /* configENABLE_MPU */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "       ldmia r0!, {r1-r11}                                                             \n" /* Read from stack - r1 = PSPLIM, r2 = CONTROL, r3 = LR and r4-r11 restored. */\r
+       #else /* configENABLE_MPU */\r
+       "       ldmia r0!, {r2-r11}                                                             \n" /* Read from stack - r2 = PSPLIM, r3 = LR and r4-r11 restored. */\r
+       #endif /* configENABLE_MPU */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_FPU == 1 )\r
+       "       tst r3, #0x10                                                                   \n" /* Test Bit[4] in LR. Bit[4] of EXC_RETURN is 0 if the FPU is in use. */\r
+       "       it eq                                                                                   \n"\r
+       "       vldmiaeq r0!, {s16-s31}                                                 \n" /* Restore the FPU registers which are not restored automatically. */\r
+       #endif /* configENABLE_FPU */\r
+       "                                                                                                       \n"\r
+       #if( configENABLE_MPU == 1 )\r
+       "       msr psplim, r1                                                                  \n" /* Restore the PSPLIM register value for the task. */\r
+       "       msr control, r2                                                                 \n" /* Restore the CONTROL register value for the task. */\r
+       #else /* configENABLE_MPU */\r
+       "       msr psplim, r2                                                                  \n" /* Restore the PSPLIM register value for the task. */\r
+       #endif /* configENABLE_MPU */\r
+       "       msr psp, r0                                                                             \n" /* Remember the new top of stack for the task. */\r
+       "       bx r3                                                                                   \n"\r
+       "                                                                                                       \n"\r
+       "       .align 4                                                                                \n"\r
+       "pxCurrentTCBConst: .word pxCurrentTCB                          \n"\r
+       "xMAIR0Const: .word 0xe000edc0                                          \n"\r
+       "xRNRConst: .word 0xe000ed98                                            \n"\r
+       "xRBARConst: .word 0xe000ed9c                                           \n"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void SVC_Handler( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */\r
 {\r
-    __asm volatile\r
-    (\r
-    "     tst lr, #4                                    \n"\r
-    "     ite eq                                        \n"\r
-    "     mrseq r0, msp                                 \n"\r
-    "     mrsne r0, psp                                 \n"\r
-    "     ldr r1, svchandler_address_const              \n"\r
-    "     bx r1                                         \n"\r
-    "                                                   \n"\r
-    "     .align 4                                      \n"\r
-    "svchandler_address_const: .word vPortSVCHandler_C  \n"\r
-    );\r
+       __asm volatile\r
+       (\r
+       "        tst lr, #4                                                                             \n"\r
+       "        ite eq                                                                                 \n"\r
+       "        mrseq r0, msp                                                                  \n"\r
+       "        mrsne r0, psp                                                                  \n"\r
+       "        ldr r1, svchandler_address_const                               \n"\r
+       "        bx r1                                                                                  \n"\r
+       "                                                                                                       \n"\r
+       "        .align 4                                                                               \n"\r
+       "svchandler_address_const: .word vPortSVCHandler_C      \n"\r
+       );\r
 }\r
 /*-----------------------------------------------------------*/\r