ISR_Support.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 pxCurrentTCB
  29. EXTERN ulCriticalNesting
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ; Context save and restore macro definitions
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. portSAVE_CONTEXT MACRO
  34. ; Push R0 as we are going to use the register.
  35. STMDB SP!, {R0}
  36. ; Set R0 to point to the task stack pointer.
  37. STMDB SP, {SP}^
  38. NOP
  39. SUB SP, SP, #4
  40. LDMIA SP!, {R0}
  41. ; Push the return address onto the stack.
  42. STMDB R0!, {LR}
  43. ; Now we have saved LR we can use it instead of R0.
  44. MOV LR, R0
  45. ; Pop R0 so we can save it onto the system mode stack.
  46. LDMIA SP!, {R0}
  47. ; Push all the system mode registers onto the task stack.
  48. STMDB LR, {R0-LR}^
  49. NOP
  50. SUB LR, LR, #60
  51. ; Push the SPSR onto the task stack.
  52. MRS R0, SPSR
  53. STMDB LR!, {R0}
  54. LDR R0, =ulCriticalNesting
  55. LDR R0, [R0]
  56. STMDB LR!, {R0}
  57. ; Store the new top of stack for the task.
  58. LDR R1, =pxCurrentTCB
  59. LDR R0, [R1]
  60. STR LR, [R0]
  61. ENDM
  62. portRESTORE_CONTEXT MACRO
  63. ; Set the LR to the task stack.
  64. LDR R1, =pxCurrentTCB
  65. LDR R0, [R1]
  66. LDR LR, [R0]
  67. ; The critical nesting depth is the first item on the stack.
  68. ; Load it into the ulCriticalNesting variable.
  69. LDR R0, =ulCriticalNesting
  70. LDMFD LR!, {R1}
  71. STR R1, [R0]
  72. ; Get the SPSR from the stack.
  73. LDMFD LR!, {R0}
  74. MSR SPSR_cxsf, R0
  75. ; Restore all system mode registers for the task.
  76. LDMFD LR, {R0-R14}^
  77. NOP
  78. ; Restore the return address.
  79. LDR LR, [LR, #+60]
  80. ; And return - correcting the offset in the LR to obtain the
  81. ; correct address.
  82. SUBS PC, LR, #4
  83. ENDM