1 /* 2 * FreeRTOS Kernel V11.1.0 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 29 EXTERN pxCurrentTCB 30 EXTERN usCriticalNesting 31 32 #include "FreeRTOSConfig.h" 33 34 ; 35 Context save and restore macro definitions 36 ; 37 38 portSAVE_CONTEXT MACRO 39 40 add - 0x0C, sp; 41 prepare stack to save necessary values 42 st.w lp, 8[ sp ]; 43 store LP to stack 44 stsr 0, r31 45 st.w lp, 4[ sp ]; 46 store EIPC to stack 47 stsr 1, lp 48 st.w lp, 0[ sp ]; 49 store EIPSW to stack 50 #if configDATA_MODE == 1; Using the Tiny data model 51 prepare { 52 r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30 53 }, 76, sp; 54 save general purpose registers 55 sst.w r19, 72[ ep ] 56 sst.w r18, 68[ ep ] 57 sst.w r17, 64[ ep ] 58 sst.w r16, 60[ ep ] 59 sst.w r15, 56[ ep ] 60 sst.w r14, 52[ ep ] 61 sst.w r13, 48[ ep ] 62 sst.w r12, 44[ ep ] 63 sst.w r11, 40[ ep ] 64 sst.w r10, 36[ ep ] 65 sst.w r9, 32[ ep ] 66 sst.w r8, 28[ ep ] 67 sst.w r7, 24[ ep ] 68 sst.w r6, 20[ ep ] 69 sst.w r5, 16[ ep ] 70 sst.w r4, 12[ ep ] 71 #else; Using the Small / Large data model 72 prepare { 73 r20, r21, r22, r23, r24, r26, r27, r28, r29, r30 74 }, 72, sp; 75 save general purpose registers 76 sst.w r19, 68[ ep ] 77 sst.w r18, 64[ ep ] 78 sst.w r17, 60[ ep ] 79 sst.w r16, 56[ ep ] 80 sst.w r15, 52[ ep ] 81 sst.w r14, 48[ ep ] 82 sst.w r13, 44[ ep ] 83 sst.w r12, 40[ ep ] 84 sst.w r11, 36[ ep ] 85 sst.w r10, 32[ ep ] 86 sst.w r9, 28[ ep ] 87 sst.w r8, 24[ ep ] 88 sst.w r7, 20[ ep ] 89 sst.w r6, 16[ ep ] 90 sst.w r5, 12[ ep ] 91 #endif /* configDATA_MODE */ 92 sst.w r2, 8[ ep ] 93 sst.w r1, 4[ ep ] 94 MOVHI hi1( usCriticalNesting ), r0, r1; 95 save usCriticalNesting value to stack 96 ld.w lw1( usCriticalNesting )[ r1 ], r2 97 sst.w r2, 0[ ep ] 98 MOVHI hi1( pxCurrentTCB ), r0, r1; 99 save SP to top of current TCB 100 ld.w lw1( pxCurrentTCB )[ r1 ], r2 101 st.w sp, 0[ r2 ] 102 ENDM 103 104 105 portRESTORE_CONTEXT MACRO 106 107 MOVHI hi1( pxCurrentTCB ), r0, r1; 108 get Stackpointer address 109 ld.w lw1( pxCurrentTCB )[ r1 ], sp 110 MOV sp, r1 111 ld.w 0[ r1 ], sp; 112 load stackpointer 113 MOV sp, ep; 114 set stack pointer to element pointer 115 sld.w 0[ ep ], r1; 116 load usCriticalNesting value from stack 117 MOVHI hi1( usCriticalNesting ), r0, r2 118 st.w r1, lw1( usCriticalNesting )[ r2 ] 119 sld.w 4[ ep ], r1; 120 restore general purpose registers 121 sld.w 8[ ep ], r2 122 #if configDATA_MODE == 1; Using Tiny data model 123 sld.w 12[ ep ], r4 124 sld.w 16[ ep ], r5 125 sld.w 20[ ep ], r6 126 sld.w 24[ ep ], r7 127 sld.w 28[ ep ], r8 128 sld.w 32[ ep ], r9 129 sld.w 36[ ep ], r10 130 sld.w 40[ ep ], r11 131 sld.w 44[ ep ], r12 132 sld.w 48[ ep ], r13 133 sld.w 52[ ep ], r14 134 sld.w 56[ ep ], r15 135 sld.w 60[ ep ], r16 136 sld.w 64[ ep ], r17 137 sld.w 68[ ep ], r18 138 sld.w 72[ ep ], r19 139 dispose 76, { 140 r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30 141 } 142 #else; Using Small / Large data model 143 sld.w 12[ ep ], r5 144 sld.w 16[ ep ], r6 145 sld.w 20[ ep ], r7 146 sld.w 24[ ep ], r8 147 sld.w 28[ ep ], r9 148 sld.w 32[ ep ], r10 149 sld.w 36[ ep ], r11 150 sld.w 40[ ep ], r12 151 sld.w 44[ ep ], r13 152 sld.w 48[ ep ], r14 153 sld.w 52[ ep ], r15 154 sld.w 56[ ep ], r16 155 sld.w 60[ ep ], r17 156 sld.w 64[ ep ], r18 157 sld.w 68[ ep ], r19 158 dispose 72, { 159 r20, r21, r22, r23, r24, r26, r27, r28, r29, r30 160 } 161 #endif /* configDATA_MODE */ 162 ld.w 0[ sp ], lp; 163 restore EIPSW from stack 164 ldsr lp, 1 165 ld.w 4[ sp ], lp; 166 restore EIPC from stack 167 ldsr lp, 0 168 ld.w 8[ sp ], lp; 169 restore LP from stack 170 add 0x0C, sp; 171 set SP to right position 172 173 RETI 174 175 ENDM 176