port_asm.s 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /* R1 to R15 - R0 is not included as it is the SP. */
  53. POPM R1-R15
  54. /* This pops the remaining registers. */
  55. RTE
  56. NOP
  57. NOP
  58. /*-----------------------------------------------------------*/
  59. /* The software interrupt - overwrite the default 'weak' definition. */
  60. ___interrupt_27:
  61. /* Re-enable interrupts. */
  62. SETPSW I
  63. /* Move the data that was automatically pushed onto the interrupt stack when
  64. the interrupt occurred from the interrupt stack to the user stack.
  65. R15 is saved before it is clobbered. */
  66. PUSH.L R15
  67. /* Read the user stack pointer. */
  68. MVFC USP, R15
  69. /* Move the address down to the data being moved. */
  70. SUB #12, R15
  71. MVTC R15, USP
  72. /* Copy the data across, R15, then PC, then PSW. */
  73. MOV.L [ R0 ], [ R15 ]
  74. MOV.L 4[ R0 ], 4[ R15 ]
  75. MOV.L 8[ R0 ], 8[ R15 ]
  76. /* Move the interrupt stack pointer to its new correct position. */
  77. ADD #12, R0
  78. /* All the rest of the registers are saved directly to the user stack. */
  79. SETPSW U
  80. /* Save the rest of the general registers (R15 has been saved already). */
  81. PUSHM R1-R14
  82. /* Save the accumulator. */
  83. MVFACHI R15
  84. PUSH.L R15
  85. /* Middle word. */
  86. MVFACMI R15
  87. /* Shifted left as it is restored to the low order word. */
  88. SHLL #16, R15
  89. PUSH.L R15
  90. /* Save the stack pointer to the TCB. */
  91. MOV.L #_pxCurrentTCB, R15
  92. MOV.L [ R15 ], R15
  93. MOV.L R0, [ R15 ]
  94. /* Ensure the interrupt mask is set to the syscall priority while the kernel
  95. structures are being accessed. */
  96. MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY
  97. /* Select the next task to run. */
  98. BSR.A _vTaskSwitchContext
  99. /* Reset the interrupt mask as no more data structure access is required. */
  100. MVTIPL #configKERNEL_INTERRUPT_PRIORITY
  101. /* Load the stack pointer of the task that is now selected as the Running
  102. state task from its TCB. */
  103. MOV.L #_pxCurrentTCB,R15
  104. MOV.L [ R15 ], R15
  105. MOV.L [ R15 ], R0
  106. /* Restore the context of the new task. The PSW (Program Status Word) and
  107. PC will be popped by the RTE instruction. */
  108. POP R15
  109. MVTACLO R15
  110. POP R15
  111. MVTACHI R15
  112. POPM R1-R15
  113. RTE
  114. NOP
  115. NOP
  116. /*-----------------------------------------------------------*/
  117. END