]> begriffs open source - freertos/blob - portable/RVDS/ARM_CA9/portmacro.inc
Add SPDX-License-Identifier: MIT to MIT licensed files.
[freertos] / portable / RVDS / ARM_CA9 / portmacro.inc
1 ;/*\r
2 ; * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3 ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4 ; *\r
5 ; * SPDX-License-Identifier: MIT
6 ; *
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 SYS_MODE                        EQU             0x1f\r
30 SVC_MODE                        EQU             0x13\r
31 IRQ_MODE                        EQU             0x12\r
32 \r
33         IMPORT  ulCriticalNesting\r
34         IMPORT  pxCurrentTCB\r
35         IMPORT  ulPortTaskHasFPUContext\r
36         IMPORT  ulAsmAPIPriorityMask\r
37         IMPORT  ulICCPMR\r
38 \r
39 \r
40         MACRO\r
41         portSAVE_CONTEXT\r
42 \r
43         ; Save the LR and SPSR onto the system mode stack before switching to\r
44         ; system mode to save the remaining system mode registers\r
45         SRSDB   sp!, #SYS_MODE\r
46         CPS             #SYS_MODE\r
47         PUSH    {R0-R12, R14}\r
48 \r
49         ; Push the critical nesting count\r
50         LDR             R2, =ulCriticalNesting\r
51         LDR             R1, [R2]\r
52         PUSH    {R1}\r
53 \r
54         ; Does the task have a floating point context that needs saving?  If\r
55         ; ulPortTaskHasFPUContext is 0 then no.\r
56         LDR             R2, =ulPortTaskHasFPUContext\r
57         LDR             R3, [R2]\r
58         CMP             R3, #0\r
59 \r
60         ; Save the floating point context, if any\r
61         FMRXNE  R1,  FPSCR\r
62         VPUSHNE {D0-D15}\r
63         VPUSHNE {D16-D31}\r
64         PUSHNE  {R1}\r
65 \r
66         ; Save ulPortTaskHasFPUContext itself\r
67         PUSH    {R3}\r
68 \r
69         ; Save the stack pointer in the TCB\r
70         LDR             R0, =pxCurrentTCB\r
71         LDR             R1, [R0]\r
72         STR             SP, [R1]\r
73 \r
74         MEND\r
75 \r
76 ; /**********************************************************************/\r
77 \r
78         MACRO\r
79         portRESTORE_CONTEXT\r
80 \r
81         ; Set the SP to point to the stack of the task being restored.\r
82         LDR             R0, =pxCurrentTCB\r
83         LDR             R1, [R0]\r
84         LDR             SP, [R1]\r
85 \r
86         ; Is there a floating point context to restore?  If the restored\r
87         ; ulPortTaskHasFPUContext is zero then no.\r
88         LDR             R0, =ulPortTaskHasFPUContext\r
89         POP             {R1}\r
90         STR             R1, [R0]\r
91         CMP             R1, #0\r
92 \r
93         ; Restore the floating point context, if any\r
94         POPNE   {R0}\r
95         VPOPNE  {D16-D31}\r
96         VPOPNE  {D0-D15}\r
97         VMSRNE  FPSCR, R0\r
98 \r
99         ; Restore the critical section nesting depth\r
100         LDR             R0, =ulCriticalNesting\r
101         POP             {R1}\r
102         STR             R1, [R0]\r
103 \r
104         ; Ensure the priority mask is correct for the critical nesting depth\r
105         LDR             R2, =ulICCPMR\r
106         CMP             R1, #0\r
107         MOVEQ   R4, #255\r
108         LDRNE   R4, =ulAsmAPIPriorityMask\r
109         STR             R4, [r2]\r
110 \r
111         ; Restore all system mode registers other than the SP (which is already\r
112         ; being used)\r
113         POP             {R0-R12, R14}\r
114 \r
115         ; Return to the task code, loading CPSR on the way.\r
116         RFEIA   sp!\r
117 \r
118         MEND\r
119 \r
120         END\r
121 \r