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