portASM.h 3.2 KB

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