portmacro.inc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. IMPORT ulCriticalNesting ;
  29. IMPORT pxCurrentTCB ;
  30. MACRO
  31. portRESTORE_CONTEXT
  32. LDR R0, =pxCurrentTCB ; Set the LR to the task stack. The location was...
  33. LDR R0, [R0] ; ... stored in pxCurrentTCB
  34. LDR LR, [R0]
  35. LDR R0, =ulCriticalNesting ; The critical nesting depth is the first item on...
  36. LDMFD LR!, {R1} ; ...the stack. Load it into the ulCriticalNesting var.
  37. STR R1, [R0] ;
  38. LDMFD LR!, {R0} ; Get the SPSR from the stack.
  39. MSR SPSR_cxsf, R0 ;
  40. LDMFD LR, {R0-R14}^ ; Restore all system mode registers for the task.
  41. NOP ;
  42. LDR LR, [LR, #+60] ; Restore the return address
  43. ; And return - correcting the offset in the LR to obtain ...
  44. SUBS PC, LR, #4 ; ...the correct address.
  45. MEND
  46. ; /**********************************************************************/
  47. MACRO
  48. portSAVE_CONTEXT
  49. STMDB SP!, {R0} ; Store R0 first as we need to use it.
  50. STMDB SP,{SP}^ ; Set R0 to point to the task stack pointer.
  51. NOP ;
  52. SUB SP, SP, #4 ;
  53. LDMIA SP!,{R0} ;
  54. STMDB R0!, {LR} ; Push the return address onto the stack.
  55. MOV LR, R0 ; Now we have saved LR we can use it instead of R0.
  56. LDMIA SP!, {R0} ; Pop R0 so we can save it onto the system mode stack.
  57. STMDB LR,{R0-LR}^ ; Push all the system mode registers onto the task stack.
  58. NOP ;
  59. SUB LR, LR, #60 ;
  60. MRS R0, SPSR ; Push the SPSR onto the task stack.
  61. STMDB LR!, {R0} ;
  62. LDR R0, =ulCriticalNesting ;
  63. LDR R0, [R0] ;
  64. STMDB LR!, {R0} ;
  65. LDR R0, =pxCurrentTCB ; Store the new top of stack for the task.
  66. LDR R1, [R0] ;
  67. STR LR, [R1] ;
  68. MEND
  69. END