isr_support.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /* Variables used by scheduler */
  29. .extern _pxCurrentTCB
  30. .extern _usCriticalNesting
  31. /*
  32. * portSAVE_CONTEXT MACRO
  33. * Saves the context of the general purpose registers, CS and ES (only in far
  34. * memory mode) registers the usCriticalNesting Value and the Stack Pointer
  35. * of the active Task onto the task stack
  36. */
  37. .macro portSAVE_CONTEXT
  38. SEL RB0
  39. /* Save AX Register to stack. */
  40. PUSH AX
  41. PUSH HL
  42. /* Save CS register. */
  43. MOV A, CS
  44. XCH A, X
  45. /* Save ES register. */
  46. MOV A, ES
  47. PUSH AX
  48. /* Save the remaining general purpose registers from bank 0. */
  49. PUSH DE
  50. PUSH BC
  51. /* Save the other register banks - only necessary in the GCC port. */
  52. SEL RB1
  53. PUSH AX
  54. PUSH BC
  55. PUSH DE
  56. PUSH HL
  57. SEL RB2
  58. PUSH AX
  59. PUSH BC
  60. PUSH DE
  61. PUSH HL
  62. /* Registers in bank 3 are for ISR use only so don't need saving. */
  63. SEL RB0
  64. /* Save the usCriticalNesting value. */
  65. MOVW AX, !_usCriticalNesting
  66. PUSH AX
  67. /* Save the Stack pointer. */
  68. MOVW AX, !_pxCurrentTCB
  69. MOVW HL, AX
  70. MOVW AX, SP
  71. MOVW [HL], AX
  72. /* Switch stack pointers. */
  73. movw sp,#_stack /* Set stack pointer */
  74. .endm
  75. /*
  76. * portRESTORE_CONTEXT MACRO
  77. * Restores the task Stack Pointer then use this to restore usCriticalNesting,
  78. * general purpose registers and the CS and ES (only in far memory mode)
  79. * of the selected task from the task stack
  80. */
  81. .macro portRESTORE_CONTEXT MACRO
  82. SEL RB0
  83. /* Restore the Stack pointer. */
  84. MOVW AX, !_pxCurrentTCB
  85. MOVW HL, AX
  86. MOVW AX, [HL]
  87. MOVW SP, AX
  88. /* Restore usCriticalNesting value. */
  89. POP AX
  90. MOVW !_usCriticalNesting, AX
  91. /* Restore the alternative register banks - only necessary in the GCC
  92. port. Register bank 3 is dedicated for interrupts use so is not saved or
  93. restored. */
  94. SEL RB2
  95. POP HL
  96. POP DE
  97. POP BC
  98. POP AX
  99. SEL RB1
  100. POP HL
  101. POP DE
  102. POP BC
  103. POP AX
  104. SEL RB0
  105. /* Restore the necessary general purpose registers. */
  106. POP BC
  107. POP DE
  108. /* Restore the ES register. */
  109. POP AX
  110. MOV ES, A
  111. /* Restore the CS register. */
  112. XCH A, X
  113. MOV CS, A
  114. /* Restore general purpose register HL. */
  115. POP HL
  116. /* Restore AX. */
  117. POP AX
  118. .endm