portasm.s 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include <FreeRTOSConfig.h>
  29. RSEG CODE:CODE(2)
  30. thumb
  31. EXTERN vPortYieldFromISR
  32. EXTERN pxCurrentTCB
  33. EXTERN vTaskSwitchContext
  34. PUBLIC vSetMSP
  35. PUBLIC xPortPendSVHandler
  36. PUBLIC vPortSVCHandler
  37. PUBLIC vPortStartFirstTask
  38. PUBLIC ulSetInterruptMaskFromISR
  39. PUBLIC vClearInterruptMaskFromISR
  40. /*-----------------------------------------------------------*/
  41. vSetMSP
  42. msr msp, r0
  43. bx lr
  44. /*-----------------------------------------------------------*/
  45. xPortPendSVHandler:
  46. mrs r0, psp
  47. ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
  48. ldr r2, [r3]
  49. subs r0, r0, #32 /* Make space for the remaining low registers. */
  50. str r0, [r2] /* Save the new top of stack. */
  51. stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */
  52. mov r4, r8 /* Store the high registers. */
  53. mov r5, r9
  54. mov r6, r10
  55. mov r7, r11
  56. stmia r0!, {r4-r7}
  57. push {r3, r14}
  58. cpsid i
  59. bl vTaskSwitchContext
  60. cpsie i
  61. pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */
  62. ldr r1, [r2]
  63. ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
  64. adds r0, r0, #16 /* Move to the high registers. */
  65. ldmia r0!, {r4-r7} /* Pop the high registers. */
  66. mov r8, r4
  67. mov r9, r5
  68. mov r10, r6
  69. mov r11, r7
  70. msr psp, r0 /* Remember the new top of stack for the task. */
  71. subs r0, r0, #32 /* Go back for the low registers that are not automatically restored. */
  72. ldmia r0!, {r4-r7} /* Pop low registers. */
  73. bx r3
  74. /*-----------------------------------------------------------*/
  75. vPortSVCHandler;
  76. /* This function is no longer used, but retained for backward
  77. compatibility. */
  78. bx lr
  79. /*-----------------------------------------------------------*/
  80. vPortStartFirstTask
  81. /* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector
  82. table offset register that can be used to locate the initial stack value.
  83. Not all M0 parts have the application vector table at address 0. */
  84. ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */
  85. ldr r1, [r3]
  86. ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
  87. adds r0, #32 /* Discard everything up to r0. */
  88. msr psp, r0 /* This is now the new top of stack to use in the task. */
  89. movs r0, #2 /* Switch to the psp stack. */
  90. msr CONTROL, r0
  91. isb
  92. pop {r0-r5} /* Pop the registers that are saved automatically. */
  93. mov lr, r5 /* lr is now in r5. */
  94. pop {r3} /* The return address is now in r3. */
  95. pop {r2} /* Pop and discard the XPSR. */
  96. cpsie i /* The first task has its context and interrupts can be enabled. */
  97. bx r3 /* Jump to the user defined task code. */
  98. /*-----------------------------------------------------------*/
  99. ulSetInterruptMaskFromISR
  100. mrs r0, PRIMASK
  101. cpsid i
  102. bx lr
  103. /*-----------------------------------------------------------*/
  104. vClearInterruptMaskFromISR
  105. msr PRIMASK, r0
  106. bx lr
  107. END