portasm.s 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. .extern pxCurrentTCB
  29. .extern vTaskISRHandler
  30. .extern vTaskSwitchContext
  31. .extern uxCriticalNesting
  32. .extern pulISRStack
  33. .global __FreeRTOS_interrupt_handler
  34. .global VPortYieldASM
  35. .global vStartFirstTask
  36. .macro portSAVE_CONTEXT
  37. /* Make room for the context on the stack. */
  38. addik r1, r1, -132
  39. /* Save r31 so it can then be used. */
  40. swi r31, r1, 4
  41. /* Copy the msr into r31 - this is stacked later. */
  42. mfs r31, rmsr
  43. /* Stack general registers. */
  44. swi r30, r1, 12
  45. swi r29, r1, 16
  46. swi r28, r1, 20
  47. swi r27, r1, 24
  48. swi r26, r1, 28
  49. swi r25, r1, 32
  50. swi r24, r1, 36
  51. swi r23, r1, 40
  52. swi r22, r1, 44
  53. swi r21, r1, 48
  54. swi r20, r1, 52
  55. swi r19, r1, 56
  56. swi r18, r1, 60
  57. swi r17, r1, 64
  58. swi r16, r1, 68
  59. swi r15, r1, 72
  60. swi r13, r1, 80
  61. swi r12, r1, 84
  62. swi r11, r1, 88
  63. swi r10, r1, 92
  64. swi r9, r1, 96
  65. swi r8, r1, 100
  66. swi r7, r1, 104
  67. swi r6, r1, 108
  68. swi r5, r1, 112
  69. swi r4, r1, 116
  70. swi r3, r1, 120
  71. swi r2, r1, 124
  72. /* Stack the critical section nesting value. */
  73. lwi r3, r0, uxCriticalNesting
  74. swi r3, r1, 128
  75. /* Save the top of stack value to the TCB. */
  76. lwi r3, r0, pxCurrentTCB
  77. sw r1, r0, r3
  78. .endm
  79. .macro portRESTORE_CONTEXT
  80. /* Load the top of stack value from the TCB. */
  81. lwi r3, r0, pxCurrentTCB
  82. lw r1, r0, r3
  83. /* Restore the general registers. */
  84. lwi r31, r1, 4
  85. lwi r30, r1, 12
  86. lwi r29, r1, 16
  87. lwi r28, r1, 20
  88. lwi r27, r1, 24
  89. lwi r26, r1, 28
  90. lwi r25, r1, 32
  91. lwi r24, r1, 36
  92. lwi r23, r1, 40
  93. lwi r22, r1, 44
  94. lwi r21, r1, 48
  95. lwi r20, r1, 52
  96. lwi r19, r1, 56
  97. lwi r18, r1, 60
  98. lwi r17, r1, 64
  99. lwi r16, r1, 68
  100. lwi r15, r1, 72
  101. lwi r14, r1, 76
  102. lwi r13, r1, 80
  103. lwi r12, r1, 84
  104. lwi r11, r1, 88
  105. lwi r10, r1, 92
  106. lwi r9, r1, 96
  107. lwi r8, r1, 100
  108. lwi r7, r1, 104
  109. lwi r6, r1, 108
  110. lwi r5, r1, 112
  111. lwi r4, r1, 116
  112. lwi r2, r1, 124
  113. /* Load the critical nesting value. */
  114. lwi r3, r1, 128
  115. swi r3, r0, uxCriticalNesting
  116. /* Obtain the MSR value from the stack. */
  117. lwi r3, r1, 8
  118. /* Are interrupts enabled in the MSR? If so return using an return from
  119. interrupt instruction to ensure interrupts are enabled only once the task
  120. is running again. */
  121. andi r3, r3, 2
  122. beqid r3, 36
  123. or r0, r0, r0
  124. /* Reload the rmsr from the stack, clear the enable interrupt bit in the
  125. value before saving back to rmsr register, then return enabling interrupts
  126. as we return. */
  127. lwi r3, r1, 8
  128. andi r3, r3, ~2
  129. mts rmsr, r3
  130. lwi r3, r1, 120
  131. addik r1, r1, 132
  132. rtid r14, 0
  133. or r0, r0, r0
  134. /* Reload the rmsr from the stack, place it in the rmsr register, and
  135. return without enabling interrupts. */
  136. lwi r3, r1, 8
  137. mts rmsr, r3
  138. lwi r3, r1, 120
  139. addik r1, r1, 132
  140. rtsd r14, 0
  141. or r0, r0, r0
  142. .endm
  143. .text
  144. .align 2
  145. __FreeRTOS_interrupt_handler:
  146. portSAVE_CONTEXT
  147. /* Entered via an interrupt so interrupts must be enabled in msr. */
  148. ori r31, r31, 2
  149. /* Stack msr. */
  150. swi r31, r1, 8
  151. /* Stack the return address. As we entered via an interrupt we do
  152. not need to modify the return address prior to stacking. */
  153. swi r14, r1, 76
  154. /* Now switch to use the ISR stack. */
  155. lwi r3, r0, pulISRStack
  156. add r1, r3, r0
  157. bralid r15, vTaskISRHandler
  158. or r0, r0, r0
  159. portRESTORE_CONTEXT
  160. VPortYieldASM:
  161. portSAVE_CONTEXT
  162. /* Stack msr. */
  163. swi r31, r1, 8
  164. /* Modify the return address so we return to the instruction after the
  165. exception. */
  166. addi r14, r14, 8
  167. swi r14, r1, 76
  168. /* Now switch to use the ISR stack. */
  169. lwi r3, r0, pulISRStack
  170. add r1, r3, r0
  171. bralid r15, vTaskSwitchContext
  172. or r0, r0, r0
  173. portRESTORE_CONTEXT
  174. vStartFirstTask:
  175. portRESTORE_CONTEXT