]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/GCC/ARM_CA9/portASM.S
Demo application related:
[freertos] / FreeRTOS / Source / portable / GCC / ARM_CA9 / portASM.S
index f0ecbf97dba28e53694fcfe0d434ca434081537f..1d9368eabd26c791520fbd97c5db734162984666 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
 \r
     licensing and training services.\r
 */\r
 \r
-\r
-       .org 0\r
        .text\r
+       .arm\r
 \r
        .set SYS_MODE,  0x1f\r
        .set SVC_MODE,  0x13\r
        .set IRQ_MODE,  0x12\r
 \r
-       .extern _boot\r
-       .extern vTaskSwitchContext\r
+       /* Hardware registers. */\r
        .extern ulICCIAR\r
        .extern ulICCEOIR\r
+       .extern ulICCPMR\r
+\r
+       /* Variables and functions. */\r
+       .extern ulMaxAPIPriorityMask\r
+       .extern _freertos_vector_table\r
+       .extern pxCurrentTCB\r
+       .extern vTaskSwitchContext\r
+       .extern vApplicationIRQHandler\r
+       .extern ulPortInterruptNesting\r
+       .extern ulPortTaskHasFPUContext\r
 \r
-       .global _vector_table\r
-       .global FIQInterrupt\r
-       .global Undefined\r
-       .global PrefetchAbortHandler\r
-       .global DataAbortInterrupt\r
        .global FreeRTOS_IRQ_Handler\r
        .global FreeRTOS_SWI_Handler\r
+       .global vPortRestoreTaskContext\r
+       .global vPortInstallFreeRTOSVectorTable\r
+\r
+\r
+\r
+\r
+.macro portSAVE_CONTEXT\r
+\r
+       /* Save the LR and SPSR onto the system mode stack before switching to\r
+       system mode to save the remaining system mode registers. */\r
+       SRSDB   sp!, #SYS_MODE\r
+       CPS             #SYS_MODE\r
+       PUSH    {R0-R12, R14}\r
+\r
+       /* Push the critical nesting count. */\r
+       LDR             R2, ulCriticalNestingConst\r
+       LDR             R1, [R2]\r
+       PUSH    {R1}\r
+\r
+       /* Does the task have a floating point context that needs saving?  If\r
+       ulPortTaskHasFPUContext is 0 then no. */\r
+       LDR             R2, ulPortTaskHasFPUContextConst\r
+       LDR             R3, [R2]\r
+       CMP             R3, #0\r
+\r
+       /* Save the floating point context, if any. */\r
+       FMRXNE  R1,  FPSCR\r
+       VPUSHNE {D0-D15}\r
+       VPUSHNE {D16-D31}\r
+       PUSHNE  {R1}\r
+\r
+       /* Save ulPortTaskHasFPUContext itself. */\r
+       PUSH    {R3}\r
+\r
+       /* Save the stack pointer in the TCB. */\r
+       LDR             R0, pxCurrentTCBConst\r
+       LDR             R1, [R0]\r
+       STR             SP, [R1]\r
+\r
+       .endm\r
+\r
+; /**********************************************************************/\r
+\r
+.macro portRESTORE_CONTEXT\r
+\r
+       /* Set the SP to point to the stack of the task being restored. */\r
+       LDR             R0, pxCurrentTCBConst\r
+       LDR             R1, [R0]\r
+       LDR             SP, [R1]\r
+\r
+       /* Is there a floating point context to restore?  If the restored\r
+       ulPortTaskHasFPUContext is zero then no. */\r
+       LDR             R0, ulPortTaskHasFPUContextConst\r
+       POP             {R1}\r
+       STR             R1, [R0]\r
+       CMP             R1, #0\r
+\r
+       /* Restore the floating point context, if any. */\r
+       POPNE   {R0}\r
+       VPOPNE  {D16-D31}\r
+       VPOPNE  {D0-D15}\r
+       VMSRNE  FPSCR, R0\r
+\r
+       /* Restore the critical section nesting depth. */\r
+       LDR             R0, ulCriticalNestingConst\r
+       POP             {R1}\r
+       STR             R1, [R0]\r
+\r
+       /* Ensure the priority mask is correct for the critical nesting depth. */\r
+       LDR             R2, ulICCPMRConst\r
+       LDR             R2, [R2]\r
+       CMP             R1, #0\r
+       MOVEQ   R4, #255\r
+       LDRNE   R4, ulMaxAPIPriorityMaskConst\r
+       LDRNE   R4, [R4]\r
+       STR             R4, [R2]\r
+\r
+       /* Restore all system mode registers other than the SP (which is already\r
+       being used). */\r
+       POP             {R0-R12, R14}\r
+\r
+       /* Return to the task code, loading CPSR on the way. */\r
+       RFEIA   sp!\r
+\r
+       .endm\r
 \r
-       .section .vectors\r
 \r
-_vector_table:\r
-       B         _boot\r
-       B         Undefined\r
-       ldr   pc, _swi\r
-       B         PrefetchAbortHandler\r
-       B         DataAbortHandler\r
-       NOP       /* Placeholder for address exception vector*/\r
-       LDR   PC, _irq\r
-       B         FIQHandler\r
 \r
-_irq:   .word FreeRTOS_IRQ_Handler\r
-_swi:   .word FreeRTOS_SWI_Handler\r
 \r
 /******************************************************************************\r
- * SVC handler is used to start the scheduler and yield a task.\r
+ * SVC handler is used to start the scheduler.\r
  *****************************************************************************/\r
+.align 4\r
+.type FreeRTOS_SWI_Handler, %function\r
 FreeRTOS_SWI_Handler:\r
-\r
        /* Save the context of the current task and select a new task to run. */\r
-//     portSAVE_CONTEXT\r
-       LDR R0, =vTaskSwitchContext\r
+       portSAVE_CONTEXT\r
+       LDR R0, vTaskSwitchContextConst\r
        BLX     R0\r
+       portRESTORE_CONTEXT\r
 \r
+\r
+/******************************************************************************\r
+ * vPortRestoreTaskContext is used to start the scheduler.\r
+ *****************************************************************************/\r
+.type vPortRestoreTaskContext, %function\r
 vPortRestoreTaskContext:\r
-//     portRESTORE_CONTEXT\r
+       /* Switch to system mode. */\r
+       CPS             #SYS_MODE\r
+       portRESTORE_CONTEXT\r
 \r
+.align 4\r
+.type FreeRTOS_IRQ_Handler, %function\r
 FreeRTOS_IRQ_Handler:\r
        /* Return to the interrupted instruction. */\r
        SUB             lr, lr, #4\r
@@ -119,7 +206,7 @@ FreeRTOS_IRQ_Handler:
        /* Increment nesting count.  r3 holds the address of ulPortInterruptNesting\r
        for future use.  r1 holds the original ulPortInterruptNesting value for\r
        future use. */\r
-       LDR             r3, =ulPortInterruptNesting\r
+       LDR             r3, ulPortInterruptNestingConst\r
        LDR             r1, [r3]\r
        ADD             r4, r1, #1\r
        STR             r4, [r3]\r
@@ -127,6 +214,7 @@ FreeRTOS_IRQ_Handler:
        /* Read value from the interrupt acknowledge register, which is stored in r0\r
        for future parameter and interrupt clearing use. */\r
        LDR     r2, ulICCIARConst\r
+       LDR             r2, [r2]\r
        LDR             r0, [r2]\r
 \r
        /* Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\r
@@ -137,14 +225,18 @@ FreeRTOS_IRQ_Handler:
 \r
        /* Call the interrupt handler. */\r
        PUSH    {r0-r3, lr}\r
-       BL              vApplicationIRQHandler\r
+       LDR             r1, vApplicationIRQHandlerConst\r
+       BLX             r1\r
        POP             {r0-r3, lr}\r
        ADD             sp, sp, r2\r
 \r
        CPSID   i\r
+       DSB\r
+       ISB\r
 \r
        /* Write the value read from ICCIAR to ICCEOIR. */\r
        LDR     r4, ulICCEOIRConst\r
+       LDR             r4, [r4]\r
        STR             r0, [r4]\r
 \r
        /* Restore the old nesting count. */\r
@@ -185,33 +277,29 @@ switch_before_exit:
        POP             {LR}\r
        MSR             SPSR_cxsf, LR\r
        POP             {LR}\r
-//     portSAVE_CONTEXT\r
+       portSAVE_CONTEXT\r
 \r
        /* Call the function that selects the new task to execute.\r
        vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\r
        instructions, or 8 byte aligned stack allocated data.  LR does not need\r
        saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */\r
-       BL              vTaskSwitchContext\r
+       LDR             R0, vTaskSwitchContextConst\r
+       BLX             R0\r
 \r
        /* Restore the context of, and branch to, the task selected to execute\r
        next. */\r
-//     portRESTORE_CONTEXT\r
+       portRESTORE_CONTEXT\r
 \r
 ulICCIARConst: .word ulICCIAR\r
 ulICCEOIRConst:        .word ulICCEOIR\r
-\r
-\r
-Undefined:\r
-       B               .\r
-\r
-PrefetchAbortHandler:\r
-       B               .\r
-\r
-FIQHandler:\r
-       B               .\r
-\r
-DataAbortHandler:\r
-       B               .\r
+ulICCPMRConst: .word ulICCPMR\r
+pxCurrentTCBConst: .word pxCurrentTCB\r
+ulCriticalNestingConst: .word ulCriticalNesting\r
+ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext\r
+ulMaxAPIPriorityMaskConst: .word ulMaxAPIPriorityMask\r
+vTaskSwitchContextConst: .word vTaskSwitchContext\r
+vApplicationIRQHandlerConst: .word vApplicationIRQHandler\r
+ulPortInterruptNestingConst: .word ulPortInterruptNesting\r
 \r
 .end\r
 \r