portasm.asm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. .thumb
  29. .ref pxCurrentTCB
  30. .ref vTaskSwitchContext
  31. .ref ulMaxSyscallInterruptPriority
  32. .def xPortPendSVHandler
  33. .def ulPortGetIPSR
  34. .def vPortSVCHandler
  35. .def vPortStartFirstTask
  36. NVICOffsetConst: .word 0xE000ED08
  37. CPACRConst: .word 0xE000ED88
  38. pxCurrentTCBConst: .word pxCurrentTCB
  39. ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority
  40. ; -----------------------------------------------------------
  41. .align 4
  42. ulPortGetIPSR: .asmfunc
  43. mrs r0, ipsr
  44. bx r14
  45. .endasmfunc
  46. ; -----------------------------------------------------------
  47. .align 4
  48. vPortSetInterruptMask: .asmfunc
  49. push {r0}
  50. ldr r0, ulMaxSyscallInterruptPriorityConst
  51. msr basepri, r0
  52. pop {r0}
  53. bx r14
  54. .endasmfunc
  55. ; -----------------------------------------------------------
  56. .align 4
  57. xPortPendSVHandler: .asmfunc
  58. mrs r0, psp
  59. isb
  60. ;/* Get the location of the current TCB. */
  61. ldr r3, pxCurrentTCBConst
  62. ldr r2, [r3]
  63. ;/* Save the core registers. */
  64. stmdb r0!, {r4-r11}
  65. ;/* Save the new top of stack into the first member of the TCB. */
  66. str r0, [r2]
  67. stmdb sp!, {r3, r14}
  68. ldr r0, ulMaxSyscallInterruptPriorityConst
  69. ldr r1, [r0]
  70. msr basepri, r1
  71. dsb
  72. isb
  73. bl vTaskSwitchContext
  74. mov r0, #0
  75. msr basepri, r0
  76. ldmia sp!, {r3, r14}
  77. ;/* The first item in pxCurrentTCB is the task top of stack. */
  78. ldr r1, [r3]
  79. ldr r0, [r1]
  80. ;/* Pop the core registers. */
  81. ldmia r0!, {r4-r11}
  82. msr psp, r0
  83. isb
  84. bx r14
  85. .endasmfunc
  86. ; -----------------------------------------------------------
  87. .align 4
  88. vPortSVCHandler: .asmfunc
  89. ;/* Get the location of the current TCB. */
  90. ldr r3, pxCurrentTCBConst
  91. ldr r1, [r3]
  92. ldr r0, [r1]
  93. ;/* Pop the core registers. */
  94. ldmia r0!, {r4-r11}
  95. msr psp, r0
  96. isb
  97. mov r0, #0
  98. msr basepri, r0
  99. orr r14, #0xd
  100. bx r14
  101. .endasmfunc
  102. ; -----------------------------------------------------------
  103. .align 4
  104. vPortStartFirstTask: .asmfunc
  105. ;/* Use the NVIC offset register to locate the stack. */
  106. ldr r0, NVICOffsetConst
  107. ldr r0, [r0]
  108. ldr r0, [r0]
  109. ;/* Set the msp back to the start of the stack. */
  110. msr msp, r0
  111. ;/* Clear the bit that indicates the FPU is in use in case the FPU was used
  112. ;before the scheduler was started - which would otherwise result in the
  113. ;unnecessary leaving of space in the SVC stack for lazy saving of FPU
  114. ;registers. */
  115. mov r0, #0
  116. msr control, r0
  117. ;/* Call SVC to start the first task. */
  118. cpsie i
  119. cpsie f
  120. dsb
  121. isb
  122. svc #0
  123. .endasmfunc
  124. ; -----------------------------------------------------------