portASM.s 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. ;/*
  2. ; FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
  3. ; All rights reserved
  4. ;
  5. ;
  6. ; ***************************************************************************
  7. ; * *
  8. ; * FreeRTOS tutorial books are available in pdf and paperback. *
  9. ; * Complete, revised, and edited pdf reference manuals are also *
  10. ; * available. *
  11. ; * *
  12. ; * Purchasing FreeRTOS documentation will not only help you, by *
  13. ; * ensuring you get running as quickly as possible and with an *
  14. ; * in-depth knowledge of how to use FreeRTOS, it will also help *
  15. ; * the FreeRTOS project to continue with its mission of providing *
  16. ; * professional grade, cross platform, de facto standard solutions *
  17. ; * for microcontrollers - completely free of charge! *
  18. ; * *
  19. ; * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
  20. ; * *
  21. ; * Thank you for using FreeRTOS, and thank you for your support! *
  22. ; * *
  23. ; ***************************************************************************
  24. ;
  25. ;
  26. ; This file is part of the FreeRTOS distribution.
  27. ;
  28. ; FreeRTOS is free software; you can redistribute it and/or modify it under
  29. ; the terms of the GNU General Public License (version 2) as published by the
  30. ; Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  31. ; >>>NOTE<<< The modification to the GPL is included to allow you to
  32. ; distribute a combined work that includes FreeRTOS without being obliged to
  33. ; provide the source code for proprietary components outside of the FreeRTOS
  34. ; kernel. FreeRTOS is distributed in the hope that it will be useful, but
  35. ; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  36. ; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  37. ; more details. You should have received a copy of the GNU General Public
  38. ; License and the FreeRTOS license exception along with FreeRTOS; if not it
  39. ; can be viewed here: http://www.freertos.org/a00114.html and also obtained
  40. ; by writing to Richard Barry, contact details for whom are available on the
  41. ; FreeRTOS WEB site.
  42. ;
  43. ; 1 tab == 4 spaces!
  44. ;
  45. ; http://www.FreeRTOS.org - Documentation, latest information, license and
  46. ; contact details.
  47. ;
  48. ; http://www.SafeRTOS.com - A version that is certified for use in safety
  49. ; critical systems.
  50. ;
  51. ; http://www.OpenRTOS.com - Commercial support, development, porting,
  52. ; licensing and training services.
  53. ;*/
  54. INCLUDE portmacro.inc
  55. IMPORT vApplicationIRQHandler
  56. IMPORT vTaskSwitchContext
  57. IMPORT ulPortYieldRequired
  58. IMPORT ulPortInterruptNesting
  59. IMPORT vTaskSwitchContext
  60. IMPORT ulICCIAR
  61. IMPORT ulICCEOIR
  62. EXPORT FreeRTOS_SWI_Handler
  63. EXPORT FreeRTOS_IRQ_Handler
  64. EXPORT vPortRestoreTaskContext
  65. ARM
  66. AREA PORT_ASM, CODE, READONLY
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68. ; SVC handler is used to yield a task.
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. FreeRTOS_SWI_Handler
  71. PRESERVE8
  72. ; Save the context of the current task and select a new task to run.
  73. portSAVE_CONTEXT
  74. LDR R0, =vTaskSwitchContext
  75. BLX R0
  76. portRESTORE_CONTEXT
  77. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78. ; vPortRestoreTaskContext is used to start the scheduler.
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. vPortRestoreTaskContext
  81. ; Switch to system mode
  82. CPS #SYS_MODE
  83. portRESTORE_CONTEXT
  84. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  85. ; PL390 GIC interrupt handler
  86. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. FreeRTOS_IRQ_Handler
  88. ; Return to the interrupted instruction.
  89. SUB lr, lr, #4
  90. ; Push the return address and SPSR
  91. PUSH {lr}
  92. MRS lr, SPSR
  93. PUSH {lr}
  94. ; Change to supervisor mode to allow reentry.
  95. CPS #SVC_MODE
  96. ; Push used registers.
  97. PUSH {r0-r4, r12}
  98. ; Increment nesting count. r3 holds the address of ulPortInterruptNesting
  99. ; for future use. r1 holds the original ulPortInterruptNesting value for
  100. ; future use.
  101. LDR r3, =ulPortInterruptNesting
  102. LDR r1, [r3]
  103. ADD r4, r1, #1
  104. STR r4, [r3]
  105. ; Read value from the interrupt acknowledge register, which is stored in r0
  106. ; for future parameter and interrupt clearing use.
  107. LDR r2, =ulICCIAR
  108. LDR r0, [r2]
  109. ; Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
  110. ; future use.
  111. MOV r2, sp
  112. AND r2, r2, #4
  113. SUB sp, sp, r2
  114. ; Call the interrupt handler
  115. PUSH {r0-r3, lr}
  116. LDR r1, =vApplicationIRQHandler
  117. BLX r1
  118. POP {r0-r3, lr}
  119. ADD sp, sp, r2
  120. CPSID i
  121. ; Write the value read from ICCIAR to ICCEOIR
  122. LDR r4, =ulICCEOIR
  123. STR r0, [r4]
  124. ; Restore the old nesting count
  125. STR r1, [r3]
  126. ; A context switch is never performed if the nesting count is not 0
  127. CMP r1, #0
  128. BNE exit_without_switch
  129. ; Did the interrupt request a context switch? r1 holds the address of
  130. ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
  131. ; use.
  132. LDR r1, =ulPortYieldRequired
  133. LDR r0, [r1]
  134. CMP r0, #0
  135. BNE switch_before_exit
  136. exit_without_switch
  137. ; No context switch. Restore used registers, LR_irq and SPSR before
  138. ; returning.
  139. POP {r0-r4, r12}
  140. CPS #IRQ_MODE
  141. POP {LR}
  142. MSR SPSR_cxsf, LR
  143. POP {LR}
  144. MOVS PC, LR
  145. switch_before_exit
  146. ; A context swtich is to be performed. Clear the context switch pending
  147. ; flag.
  148. MOV r0, #0
  149. STR r0, [r1]
  150. ; Restore used registers, LR-irq and SPSR before saving the context
  151. ; to the task stack.
  152. POP {r0-r4, r12}
  153. CPS #IRQ_MODE
  154. POP {LR}
  155. MSR SPSR_cxsf, LR
  156. POP {LR}
  157. portSAVE_CONTEXT
  158. ; Call the function that selects the new task to execute.
  159. ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
  160. ; instructions, or 8 byte aligned stack allocated data. LR does not need
  161. ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.
  162. LDR r0, =vTaskSwitchContext
  163. BLX r0
  164. ; Restore the context of, and branch to, the task selected to execute next.
  165. portRESTORE_CONTEXT
  166. END