port_asm.s 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include "PriorityDefinitions.h"
  29. PUBLIC _prvStartFirstTask
  30. PUBLIC ___interrupt_27
  31. EXTERN _pxCurrentTCB
  32. EXTERN _vTaskSwitchContext
  33. RSEG CODE:CODE(4)
  34. _prvStartFirstTask:
  35. /* When starting the scheduler there is nothing that needs moving to the
  36. interrupt stack because the function is not called from an interrupt.
  37. Just ensure the current stack is the user stack. */
  38. SETPSW U
  39. /* Obtain the location of the stack associated with which ever task
  40. pxCurrentTCB is currently pointing to. */
  41. MOV.L #_pxCurrentTCB, R15
  42. MOV.L [R15], R15
  43. MOV.L [R15], R0
  44. /* Restore the registers from the stack of the task pointed to by
  45. pxCurrentTCB. */
  46. POP R15
  47. /* Accumulator low 32 bits. */
  48. MVTACLO R15
  49. POP R15
  50. /* Accumulator high 32 bits. */
  51. MVTACHI R15
  52. POP R15
  53. /* Floating point status word. */
  54. MVTC R15, FPSW
  55. /* R1 to R15 - R0 is not included as it is the SP. */
  56. POPM R1-R15
  57. /* This pops the remaining registers. */
  58. RTE
  59. NOP
  60. NOP
  61. /*-----------------------------------------------------------*/
  62. /* The software interrupt - overwrite the default 'weak' definition. */
  63. ___interrupt_27:
  64. /* Re-enable interrupts. */
  65. SETPSW I
  66. /* Move the data that was automatically pushed onto the interrupt stack when
  67. the interrupt occurred from the interrupt stack to the user stack.
  68. R15 is saved before it is clobbered. */
  69. PUSH.L R15
  70. /* Read the user stack pointer. */
  71. MVFC USP, R15
  72. /* Move the address down to the data being moved. */
  73. SUB #12, R15
  74. MVTC R15, USP
  75. /* Copy the data across, R15, then PC, then PSW. */
  76. MOV.L [ R0 ], [ R15 ]
  77. MOV.L 4[ R0 ], 4[ R15 ]
  78. MOV.L 8[ R0 ], 8[ R15 ]
  79. /* Move the interrupt stack pointer to its new correct position. */
  80. ADD #12, R0
  81. /* All the rest of the registers are saved directly to the user stack. */
  82. SETPSW U
  83. /* Save the rest of the general registers (R15 has been saved already). */
  84. PUSHM R1-R14
  85. /* Save the FPSW and accumulator. */
  86. MVFC FPSW, R15
  87. PUSH.L R15
  88. MVFACHI R15
  89. PUSH.L R15
  90. /* Middle word. */
  91. MVFACMI R15
  92. /* Shifted left as it is restored to the low order word. */
  93. SHLL #16, R15
  94. PUSH.L R15
  95. /* Save the stack pointer to the TCB. */
  96. MOV.L #_pxCurrentTCB, R15
  97. MOV.L [ R15 ], R15
  98. MOV.L R0, [ R15 ]
  99. /* Ensure the interrupt mask is set to the syscall priority while the kernel
  100. structures are being accessed. */
  101. MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY
  102. /* Select the next task to run. */
  103. BSR.A _vTaskSwitchContext
  104. /* Reset the interrupt mask as no more data structure access is required. */
  105. MVTIPL #configKERNEL_INTERRUPT_PRIORITY
  106. /* Load the stack pointer of the task that is now selected as the Running
  107. state task from its TCB. */
  108. MOV.L #_pxCurrentTCB,R15
  109. MOV.L [ R15 ], R15
  110. MOV.L [ R15 ], R0
  111. /* Restore the context of the new task. The PSW (Program Status Word) and
  112. PC will be popped by the RTE instruction. */
  113. POP R15
  114. MVTACLO R15
  115. POP R15
  116. MVTACHI R15
  117. POP R15
  118. MVTC R15, FPSW
  119. POPM R1-R15
  120. RTE
  121. NOP
  122. NOP
  123. /*-----------------------------------------------------------*/
  124. END