@@ -184,62 +184,65 @@ vClearInterruptMask:
184
184
/ *-----------------------------------------------------------* /
185
185
186
186
PendSV_Handler:
187
- mrs r1 , psp / * Read PSP in r1. * /
188
- ldr r2 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
189
- ldr r0 , [ r2 ] / * Read xSecureContext - Value of xSecureContext must be in r0 as it is used as a parameter later. * /
187
+ ldr r3 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
188
+ ldr r0 , [ r3 ] / * Read xSecureContext - Value of xSecureContext must be in r0 as it is used as a parameter later. * /
189
+ ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
190
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB - Value of pxCurrentTCB must be in r1 as it is used as a parameter later. * /
191
+ mrs r2 , psp / * Read PSP in r2. * /
190
192
191
193
cbz r0 , save_ns_context / * No secure context to save. * /
192
194
push {r0 - r2 , r14 }
193
- bl SecureContext_SaveContext
195
+ bl SecureContext_SaveContext / * Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. * /
194
196
pop {r0 - r3} / * LR is now in r3. * /
195
197
mov lr , r3 / * LR = r3. * /
196
- lsls r2 , r3 , # 25 / * r2 = r3 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
197
- bpl save_ns_context / * bpl - branch if positive or zero. If r2 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
198
+ lsls r1 , r3 , # 25 / * r1 = r3 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
199
+ bpl save_ns_context / * bpl - branch if positive or zero. If r1 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
200
+
198
201
ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
199
- ldr r2 , [ r3 ] / * Read pxCurrentTCB. * /
202
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB. * /
200
203
#if ( configENABLE_MPU == 1 )
201
- subs r1 , r1 , # 16 / * Make space for xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
202
- str r1 , [ r2 ] / * Save the new top of stack in TCB. * /
203
- mrs r2 , psplim / * r2 = PSPLIM. * /
204
+ subs r2 , r2 , # 16 / * Make space for xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
205
+ str r2 , [ r1 ] / * Save the new top of stack in TCB. * /
206
+ mrs r1 , psplim / * r1 = PSPLIM. * /
204
207
mrs r3 , control / * r3 = CONTROL. * /
205
208
mov r4 , lr / * r4 = LR/EXC_RETURN. * /
206
- stmia r1 ! , {r0 , r2 - r4} / * Store xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
209
+ stmia r2 ! , {r0 , r1 , r3 , r4} /* Store xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
207
210
#else / * configENABLE_MPU * /
208
- subs r1 , r1 , # 12 / * Make space for xSecureContext , PSPLIM and LR on the stack. * /
209
- str r1 , [ r2 ] / * Save the new top of stack in TCB. * /
210
- mrs r2 , psplim / * r2 = PSPLIM. * /
211
+ subs r2 , r2 , # 12 / * Make space for xSecureContext , PSPLIM and LR on the stack. * /
212
+ str r2 , [ r1 ] / * Save the new top of stack in TCB. * /
213
+ mrs r1 , psplim / * r1 = PSPLIM. * /
211
214
mov r3 , lr / * r3 = LR/EXC_RETURN. * /
212
- stmia r1 ! , {r0 , r2 - r3} / * Store xSecureContext , PSPLIM and LR on the stack. * /
215
+ stmia r2 ! , {r0 , r1 , r3} /* Store xSecureContext , PSPLIM and LR on the stack. * /
213
216
#endif / * configENABLE_MPU * /
214
217
b select_next_task
215
218
216
219
save_ns_context:
217
220
ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
218
- ldr r2 , [ r3 ] / * Read pxCurrentTCB. * /
221
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB. * /
219
222
#if ( configENABLE_FPU == 1 )
220
223
tst lr , # 0x10 / * Test Bit [ 4 ] in LR. Bit [ 4 ] of EXC_RETURN is 0 if the FPU is in use. * /
221
224
it eq
222
- vstmdbeq r1 ! , {s16 - s31} / * Store the FPU registers which are not saved automatically. * /
225
+ vstmdbeq r2 ! , {s16 - s31} / * Store the FPU registers which are not saved automatically. * /
223
226
#endif / * configENABLE_FPU * /
224
227
#if ( configENABLE_MPU == 1 )
225
- subs r1 , r1 , # 48 / * Make space for xSecureContext , PSPLIM , CONTROL , LR and the remaining registers on the stack. * /
226
- str r1 , [ r2 ] / * Save the new top of stack in TCB. * /
227
- adds r1 , r1 , # 16 / * r1 = r1 + 16 . * /
228
- stm r1 , {r4 - r11 } / * Store the registers th at are not saved automatically. * /
229
- mrs r2 , psplim / * r2 = PSPLIM. * /
228
+ subs r2 , r2 , # 48 / * Make space for xSecureContext , PSPLIM , CONTROL , LR and the remaining registers on the stack. * /
229
+ str r2 , [ r1 ] / * Save the new top of stack in TCB. * /
230
+ adds r2 , r2 , # 16 / * r2 = r2 + 16 . * /
231
+ stm r2 , {r4 - r11 } / * Store the registers th at are not saved automatically. * /
232
+ mrs r1 , psplim / * r1 = PSPLIM. * /
230
233
mrs r3 , control / * r3 = CONTROL. * /
231
234
mov r4 , lr / * r4 = LR/EXC_RETURN. * /
232
- subs r1 , r1 , # 16 / * r1 = r1 - 16 . * /
233
- stm r1 , {r0 , r2 - r4} / * Store xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
235
+ subs r2 , r2 , # 16 / * r2 = r2 - 16 . * /
236
+ stmia r2! , {r0 , r1 , r3 , r4} /* Store xSecureContext , PSPLIM , CONTROL and LR on the stack. * /
234
237
#else / * configENABLE_MPU * /
235
- subs r1 , r1 , # 44 / * Make space for xSecureContext , PSPLIM , LR and the remaining registers on the stack. * /
236
- str r1 , [ r2 ] / * Save the new top of stack in TCB. * /
237
- adds r1 , r1 , # 12 / * r1 = r1 + 12 . * /
238
- stm r1 , {r4 - r11 } / * Store the registers th at are not saved automatically. * /
239
- mrs r2 , psplim / * r2 = PSPLIM. * /
238
+ subs r2 , r2 , # 44 / * Make space for xSecureContext , PSPLIM , LR and the remaining registers on the stack. * /
239
+ str r2 , [ r1 ] / * Save the new top of stack in TCB. * /
240
+ adds r2 , r2 , # 12 / * r2 = r2 + 12 . * /
241
+ stm r2 , {r4 - r11 } / * Store the registers th at are not saved automatically. * /
242
+ mrs r1 , psplim / * r1 = PSPLIM. * /
240
243
mov r3 , lr / * r3 = LR/EXC_RETURN. * /
241
- subs r1 , r1 , # 12 / * r1 = r1 - 12 . * /
242
- stmia r1 ! , {r0 , r2 - r3} / * Store xSecureContext , PSPLIM and LR on the stack. * /
244
+ subs r2 , r2 , # 12 / * r2 = r2 - 12 . * /
245
+ stmia r2 ! , {r0 , r1 , r3} /* Store xSecureContext , PSPLIM and LR on the stack. * /
243
246
#endif / * configENABLE_MPU * /
244
247
245
248
select_next_task:
@@ -251,77 +254,81 @@ PendSV_Handler:
251
254
mov r0 , # 0 / * r0 = 0 . * /
252
255
msr basepri , r0 / * Enable interrupts. * /
253
256
254
- ldr r2 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
255
- ldr r3 , [ r2 ] / * Read pxCurrentTCB. * /
256
- ldr r1 , [ r3 ] / * The first item in pxCurrentTCB is the task top of stack. r1 now points to the top of stack. * /
257
+ ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
258
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB. * /
259
+ ldr r2 , [ r1 ] / * The first item in pxCurrentTCB is the task top of stack. r2 now points to the top of stack. * /
257
260
258
261
#if ( configENABLE_MPU == 1 )
259
262
dmb / * Complete outstanding transfers before disabling MPU. * /
260
- ldr r2 , = 0xe000ed94 / * r2 = 0xe000ed94 [ Location of MPU_CTRL ] . * /
261
- ldr r4 , [ r2 ] / * Read the value of MPU_CTRL. * /
263
+ ldr r3 , = 0xe000ed94 / * r3 = 0xe000ed94 [ Location of MPU_CTRL ] . * /
264
+ ldr r4 , [ r3 ] / * Read the value of MPU_CTRL. * /
262
265
bic r4 , r4 , # 1 / * r4 = r4 & ~ 1 i.e. Clear the bit 0 in r4. * /
263
- str r4 , [ r2 ] / * Disable MPU. * /
266
+ str r4 , [ r3 ] / * Disable MPU. * /
264
267
265
- adds r3 , # 4 / * r3 = r3 + 4 . r3 now points to MAIR0 in TCB. * /
266
- ldr r4 , [ r3 ] / * r4 = * r3 i.e. r4 = MAIR0. * /
267
- ldr r2 , = 0xe000edc0 / * r2 = 0xe000edc0 [ Location of MAIR0 ] . * /
268
- str r4 , [ r2 ] / * Program MAIR0. * /
269
- ldr r2 , = 0xe000ed98 / * r2 = 0xe000ed98 [ Location of RNR ] . * /
268
+ adds r1 , # 4 / * r1 = r1 + 4 . r1 now points to MAIR0 in TCB. * /
269
+ ldr r4 , [ r1 ] / * r4 = * r1 i.e. r4 = MAIR0. * /
270
+ ldr r3 , = 0xe000edc0 / * r3 = 0xe000edc0 [ Location of MAIR0 ] . * /
271
+ str r4 , [ r3 ] / * Program MAIR0. * /
272
+ ldr r3 , = 0xe000ed98 / * r3 = 0xe000ed98 [ Location of RNR ] . * /
270
273
movs r4 , # 4 / * r4 = 4 . * /
271
- str r4 , [ r2 ] / * Program RNR = 4 . * /
272
- adds r3 , # 4 / * r3 = r3 + 4 . r3 now points to first RBAR in TCB. * /
273
- ldr r2 , = 0xe000ed9c / * r2 = 0xe000ed9c [ Location of RBAR ] . * /
274
- ldmia r3 ! , {r4 - r11 } / * Read 4 sets of RBAR/RLAR registers from TCB. * /
275
- stmia r2 ! , {r4 - r11 } / * Write 4 set of RBAR/RLAR registers using alias registers. * /
276
-
277
- ldr r2 , = 0xe000ed94 / * r2 = 0xe000ed94 [ Location of MPU_CTRL ] . * /
278
- ldr r4 , [ r2 ] / * Read the value of MPU_CTRL. * /
274
+ str r4 , [ r3 ] / * Program RNR = 4 . * /
275
+ adds r1 , # 4 / * r1 = r1 + 4 . r1 now points to first RBAR in TCB. * /
276
+ ldr r3 , = 0xe000ed9c / * r3 = 0xe000ed9c [ Location of RBAR ] . * /
277
+ ldmia r1 ! , {r4 - r11 } / * Read 4 sets of RBAR/RLAR registers from TCB. * /
278
+ stmia r3 ! , {r4 - r11 } / * Write 4 set of RBAR/RLAR registers using alias registers. * /
279
+
280
+ ldr r3 , = 0xe000ed94 / * r3 = 0xe000ed94 [ Location of MPU_CTRL ] . * /
281
+ ldr r4 , [ r3 ] / * Read the value of MPU_CTRL. * /
279
282
orr r4 , r4 , # 1 / * r4 = r4 | 1 i.e. Set the bit 0 in r4. * /
280
- str r4 , [ r2 ] / * Enable MPU. * /
283
+ str r4 , [ r3 ] / * Enable MPU. * /
281
284
dsb / * Force memory writes before continuing. * /
282
285
#endif / * configENABLE_MPU * /
283
286
284
287
#if ( configENABLE_MPU == 1 )
285
- ldmia r1 ! , {r0 , r2 - r4} / * Read from stack - r0 = xSecureContext , r2 = PSPLIM , r3 = CONTROL and r4 = LR. * /
286
- msr psplim , r2 / * Restore the PSPLIM register value for the task. * /
288
+ ldmia r2 ! , {r0 , r1 , r3 , r4} /* Read from stack - r0 = xSecureContext , r1 = PSPLIM , r3 = CONTROL and r4 = LR. * /
289
+ msr psplim , r1 / * Restore the PSPLIM register value for the task. * /
287
290
msr control , r3 / * Restore the CONTROL register value for the task. * /
288
291
mov lr , r4 / * LR = r4. * /
289
- ldr r2 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
290
- str r0 , [ r2 ] / * Restore the task's xSecureContext. * /
292
+ ldr r3 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
293
+ str r0 , [ r3 ] / * Restore the task's xSecureContext. * /
291
294
cbz r0 , restore_ns_context / * If there is no secure context for the task , restore the non - secure context. * /
292
- push {r1 , r4}
293
- bl SecureContext_LoadContext / * Restore the secure context. * /
294
- pop {r1 , r4}
295
+ ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
296
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB. * /
297
+ push {r2 , r4}
298
+ bl SecureContext_LoadContext / * Restore the secure context. Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. * /
299
+ pop {r2 , r4}
295
300
mov lr , r4 / * LR = r4. * /
296
- lsls r2 , r4 , # 25 / * r2 = r4 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
297
- bpl restore_ns_context / * bpl - branch if positive or zero. If r2 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
298
- msr psp , r1 / * Remember the new top of stack for the task. * /
301
+ lsls r1 , r4 , # 25 / * r1 = r4 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
302
+ bpl restore_ns_context / * bpl - branch if positive or zero. If r1 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
303
+ msr psp , r2 / * Remember the new top of stack for the task. * /
299
304
bx lr
300
305
#else / * configENABLE_MPU * /
301
- ldmia r1 ! , {r0 , r2 - r3 } /* Read from stack - r0 = xSecureContext , r2 = PSPLIM and r3 = LR. * /
302
- msr psplim , r2 / * Restore the PSPLIM register value for the task. * /
303
- mov lr , r3 / * LR = r3 . * /
304
- ldr r2 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
305
- str r0 , [ r2 ] / * Restore the task's xSecureContext. * /
306
+ ldmia r2 ! , {r0 , r1 , r4 } /* Read from stack - r0 = xSecureContext , r1 = PSPLIM and r4 = LR. * /
307
+ msr psplim , r1 / * Restore the PSPLIM register value for the task. * /
308
+ mov lr , r4 / * LR = r4 . * /
309
+ ldr r3 , =xSecureContext / * Read the location of xSecureContext i.e. &( xSecureContext ). * /
310
+ str r0 , [ r3 ] / * Restore the task's xSecureContext. * /
306
311
cbz r0 , restore_ns_context / * If there is no secure context for the task , restore the non - secure context. * /
307
- push {r1 , r3}
308
- bl SecureContext_LoadContext / * Restore the secure context. * /
309
- pop {r1 , r3}
310
- mov lr , r3 / * LR = r3. * /
311
- lsls r2 , r3 , # 25 / * r2 = r3 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
312
- bpl restore_ns_context / * bpl - branch if positive or zero. If r2 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
313
- msr psp , r1 / * Remember the new top of stack for the task. * /
312
+ ldr r3 , =pxCurrentTCB / * Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). * /
313
+ ldr r1 , [ r3 ] / * Read pxCurrentTCB. * /
314
+ push {r2 , r4}
315
+ bl SecureContext_LoadContext / * Restore the secure context. Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. * /
316
+ pop {r2 , r4}
317
+ mov lr , r4 / * LR = r4. * /
318
+ lsls r1 , r4 , # 25 / * r1 = r4 << 25 . Bit [ 6 ] of EXC_RETURN is 1 if secure stack was used , 0 if non - secure stack was used to store stack frame. * /
319
+ bpl restore_ns_context / * bpl - branch if positive or zero. If r1 >= 0 ==> Bit [ 6 ] in EXC_RETURN is 0 i.e. non - secure stack was used. * /
320
+ msr psp , r2 / * Remember the new top of stack for the task. * /
314
321
bx lr
315
322
#endif / * configENABLE_MPU * /
316
323
317
324
restore_ns_context:
318
- ldmia r1 ! , {r4 - r11 } / * Restore the registers th at are not automatically restored. * /
325
+ ldmia r2 ! , {r4 - r11 } / * Restore the registers th at are not automatically restored. * /
319
326
#if ( configENABLE_FPU == 1 )
320
327
tst lr , # 0x10 / * Test Bit [ 4 ] in LR. Bit [ 4 ] of EXC_RETURN is 0 if the FPU is in use. * /
321
328
it eq
322
- vldmiaeq r1 ! , {s16 - s31} / * Restore the FPU registers which are not restored automatically. * /
329
+ vldmiaeq r2 ! , {s16 - s31} / * Restore the FPU registers which are not restored automatically. * /
323
330
#endif / * configENABLE_FPU * /
324
- msr psp , r1 / * Remember the new top of stack for the task. * /
331
+ msr psp , r2 / * Remember the new top of stack for the task. * /
325
332
bx lr
326
333
/ *-----------------------------------------------------------* /
327
334
@@ -335,9 +342,9 @@ SVC_Handler:
335
342
336
343
vPortFreeSecureContext:
337
344
/ * r0 = uint32_t * pulTCB. * /
338
- ldr r1 , [ r0 ] / * The first item in the TCB is the top of the stack. * /
339
- ldr r0 , [ r1 ] / * The first item on the stack is the task's xSecureContext. * /
340
- cmp r0 , # 0 / * Raise svc if task's xSecureContext is not NULL. * /
345
+ ldr r2 , [ r0 ] / * The first item in the TCB is the top of the stack. * /
346
+ ldr r1 , [ r2 ] / * The first item on the stack is the task's xSecureContext. * /
347
+ cmp r1 , # 0 / * Raise svc if task's xSecureContext is not NULL. * /
341
348
it ne
342
349
svcne 1 / * Secure context is freed in the supervisor call . portSVC_FREE_SECURE_CONTEXT = 1 . * /
343
350
bx lr / * Return. * /
0 commit comments