portASM.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ;/*
  2. ; * FreeRTOS Kernel V10.4.3
  3. ; * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. ; *
  5. ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. ; * this software and associated documentation files (the "Software"), to deal in
  7. ; * the Software without restriction, including without limitation the rights to
  8. ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. ; * the Software, and to permit persons to whom the Software is furnished to do so,
  10. ; * subject to the following conditions:
  11. ; *
  12. ; * The above copyright notice and this permission notice shall be included in all
  13. ; * copies or substantial portions of the Software.
  14. ; *
  15. ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. ; *
  22. ; * https://www.FreeRTOS.org
  23. ; * https://github.com/FreeRTOS
  24. ; *
  25. ; * 1 tab == 4 spaces!
  26. ; */
  27. EXTERN vTaskSwitchContext
  28. EXTERN ulCriticalNesting
  29. EXTERN pxCurrentTCB
  30. EXTERN ulPortTaskHasFPUContext
  31. EXTERN ulAsmAPIPriorityMask
  32. portSAVE_CONTEXT macro
  33. ; Save the LR and SPSR onto the system mode stack before switching to
  34. ; system mode to save the remaining system mode registers
  35. SRSDB sp!, #SYS_MODE
  36. CPS #SYS_MODE
  37. PUSH {R0-R12, R14}
  38. ; Push the critical nesting count
  39. LDR R2, =ulCriticalNesting
  40. LDR R1, [R2]
  41. PUSH {R1}
  42. ; Does the task have a floating point context that needs saving? If
  43. ; ulPortTaskHasFPUContext is 0 then no.
  44. LDR R2, =ulPortTaskHasFPUContext
  45. LDR R3, [R2]
  46. CMP R3, #0
  47. ; Save the floating point context, if any
  48. FMRXNE R1, FPSCR
  49. VPUSHNE {D0-D15}
  50. #if configFPU_D32 == 1
  51. VPUSHNE {D16-D31}
  52. #endif ; configFPU_D32
  53. PUSHNE {R1}
  54. ; Save ulPortTaskHasFPUContext itself
  55. PUSH {R3}
  56. ; Save the stack pointer in the TCB
  57. LDR R0, =pxCurrentTCB
  58. LDR R1, [R0]
  59. STR SP, [R1]
  60. endm
  61. ; /**********************************************************************/
  62. portRESTORE_CONTEXT macro
  63. ; Set the SP to point to the stack of the task being restored.
  64. LDR R0, =pxCurrentTCB
  65. LDR R1, [R0]
  66. LDR SP, [R1]
  67. ; Is there a floating point context to restore? If the restored
  68. ; ulPortTaskHasFPUContext is zero then no.
  69. LDR R0, =ulPortTaskHasFPUContext
  70. POP {R1}
  71. STR R1, [R0]
  72. CMP R1, #0
  73. ; Restore the floating point context, if any
  74. POPNE {R0}
  75. #if configFPU_D32 == 1
  76. VPOPNE {D16-D31}
  77. #endif ; configFPU_D32
  78. VPOPNE {D0-D15}
  79. VMSRNE FPSCR, R0
  80. ; Restore the critical section nesting depth
  81. LDR R0, =ulCriticalNesting
  82. POP {R1}
  83. STR R1, [R0]
  84. ; Restore all system mode registers other than the SP (which is already
  85. ; being used)
  86. POP {R0-R12, R14}
  87. ; Return to the task code, loading CPSR on the way. CPSR has the interrupt
  88. ; enable bit set appropriately for the task about to execute.
  89. RFEIA sp!
  90. endm