portmacro.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. SYS_MODE EQU 0x1f
  29. SVC_MODE EQU 0x13
  30. IRQ_MODE EQU 0x12
  31. IMPORT ulCriticalNesting
  32. IMPORT pxCurrentTCB
  33. IMPORT ulPortTaskHasFPUContext
  34. IMPORT ulAsmAPIPriorityMask
  35. IMPORT ulICCPMR
  36. MACRO
  37. portSAVE_CONTEXT
  38. ; Save the LR and SPSR onto the system mode stack before switching to
  39. ; system mode to save the remaining system mode registers
  40. SRSDB sp!, #SYS_MODE
  41. CPS #SYS_MODE
  42. PUSH {R0-R12, R14}
  43. ; Push the critical nesting count
  44. LDR R2, =ulCriticalNesting
  45. LDR R1, [R2]
  46. PUSH {R1}
  47. ; Does the task have a floating point context that needs saving? If
  48. ; ulPortTaskHasFPUContext is 0 then no.
  49. LDR R2, =ulPortTaskHasFPUContext
  50. LDR R3, [R2]
  51. CMP R3, #0
  52. ; Save the floating point context, if any
  53. FMRXNE R1, FPSCR
  54. VPUSHNE {D0-D15}
  55. VPUSHNE {D16-D31}
  56. PUSHNE {R1}
  57. ; Save ulPortTaskHasFPUContext itself
  58. PUSH {R3}
  59. ; Save the stack pointer in the TCB
  60. LDR R0, =pxCurrentTCB
  61. LDR R1, [R0]
  62. STR SP, [R1]
  63. MEND
  64. ; /**********************************************************************/
  65. MACRO
  66. portRESTORE_CONTEXT
  67. ; Set the SP to point to the stack of the task being restored.
  68. LDR R0, =pxCurrentTCB
  69. LDR R1, [R0]
  70. LDR SP, [R1]
  71. ; Is there a floating point context to restore? If the restored
  72. ; ulPortTaskHasFPUContext is zero then no.
  73. LDR R0, =ulPortTaskHasFPUContext
  74. POP {R1}
  75. STR R1, [R0]
  76. CMP R1, #0
  77. ; Restore the floating point context, if any
  78. POPNE {R0}
  79. VPOPNE {D16-D31}
  80. VPOPNE {D0-D15}
  81. VMSRNE FPSCR, R0
  82. ; Restore the critical section nesting depth
  83. LDR R0, =ulCriticalNesting
  84. POP {R1}
  85. STR R1, [R0]
  86. ; Ensure the priority mask is correct for the critical nesting depth
  87. LDR R2, =ulICCPMR
  88. CMP R1, #0
  89. MOVEQ R4, #255
  90. LDRNE R4, =ulAsmAPIPriorityMask
  91. STR R4, [r2]
  92. ; Restore all system mode registers other than the SP (which is already
  93. ; being used)
  94. POP {R0-R12, R14}
  95. ; Return to the task code, loading CPSR on the way.
  96. RFEIA sp!
  97. MEND
  98. END