@@ -361,93 +361,92 @@ osRtxContextSwitch:
361
361
362
362
// R0 = osRtxInfo.thread.run.curr
363
363
// R1 = osRtxInfo.thread.run.next
364
- // R12 = &osRtxInfo.thread.run
364
+ // R12 = &osRtxInfo.thread.run
365
365
366
- CMP R0 , # 0 // Is osRtxInfo.thread.run.curr == 0
367
- ADDEQ SP , SP , # 32 // Equal , curr deleted , adjust current SP
368
- BEQ osRtxContextRestore // Restore context , run.curr = run.next ;
366
+ CMP R0 , # 0 // Is osRtxInfo.thread.run.curr == 0
367
+ ADDEQ SP , SP , # 32 // Equal , curr deleted , adjust current SP
368
+ BEQ osRtxContextRestore // Restore context , run.curr = run.next ;
369
369
370
370
osRtxContextSave:
371
371
SUB SP , SP , # 4
372
- STM SP , { SP }^ // Save SP_usr to current stack
373
- POP {R3} // Pop SP_usr into R3
372
+ STM SP , { SP }^ // Save SP_usr to current stack
373
+ POP {R3} // Pop SP_usr into R3
374
374
375
- SUB R3 , R3 , # 64 // Adjust user sp to end of basic frame (R4)
376
- STMIA R3! , {R4 - R11 } // Save R4 - R11 to user
377
- POP {R4 - R8 } // Pop current R0 - R12 into R4 - R8
378
- STMIA R3! , {R4 - R8 } // Store them to user stack
379
- STM R3 , {LR}^ // Store LR_usr directly
380
- ADD R3 , R3 , # 4 // Adjust user sp to PC
381
- POP {R4 - R6} // Pop current LR , PC , CPSR
382
- STMIA R3! , {R5 - R6} // Restore user PC and CPSR
375
+ SUB R3 , R3 , # 64 // Adjust user sp to end of basic frame (R4)
376
+ STMIA R3! , {R4 - R11 } // Save R4 - R11 to user
377
+ POP {R4 - R8 } // Pop current R0 - R12 into R4 - R8
378
+ STMIA R3! , {R4 - R8 } // Store them to user stack
379
+ STM R3 , {LR}^ // Store LR_usr directly
380
+ ADD R3 , R3 , # 4 // Adjust user sp to PC
381
+ POP {R4 - R6} // Pop current LR , PC , CPSR
382
+ STMIA R3! , {R5 - R6} // Restore user PC and CPSR
383
383
384
- SUB R3 , R3 , # 64 // Adjust user sp to R4
384
+ SUB R3 , R3 , # 64 // Adjust user sp to R4
385
385
386
386
// Check if VFP state need to be saved
387
- MRC p15 , 0 , R2 , c1 , c0 , 2 // VFP/NEON access enabled? (CPACR)
387
+ MRC p15 , 0 , R2 , c1 , c0 , 2 // VFP/NEON access enabled? (CPACR)
388
388
AND R2 , R2 , # 0x00F00000
389
389
CMP R2 , # 0x00F00000
390
- BNE osRtxContextSave1 // Continue , no VFP
390
+ BNE osRtxContextSave1 // Continue , no VFP
391
391
392
392
VMRS R2 , FPSCR
393
- STMDB R3! , {R2 , R12 } // Push FPSCR , maintain 8 - byte alignment
394
- #if TARGET_FEATURE_EXTENSION_REGISTER_COUNT == 16
395
- VSTMDB R3! , {D0 - D15}
396
- LDRB R2 , [ R0 , #TCB_SP_FRAME ] // Record in TCB th at VFP/D16 state is stacked
397
- ORR R2 , R2 , # 2
398
- STRB R2 , [ R0 , #TCB_SP_FRAME ]
393
+ STMDB R3! , {R2 , R12 } // Push FPSCR , maintain 8 - byte alignment
394
+
395
+ VSTMDB R3! , {D0 - D15} // Save D0 - D15
396
+ #if __ARM_NEON == 1
397
+ VSTMDB R3! , {D16 - D31} // Save D16 - D31
399
398
#endif
400
- #if TARGET_FEATURE_EXTENSION_REGISTER_COUNT == 32
401
- VSTMDB R3! , {D0 - D15}
402
- VSTMDB R3! , {D16 - D31}
403
- LDRB R2 , [ R0 , #TCB_SP_FRAME ] // Record in TCB th at NEON/D32 state is stacked
404
- ORR R2 , R2 , # 4
405
- STRB R2 , [ R0 , #TCB_SP_FRAME ]
399
+ LDRB R2 , [ R0 , #TCB_SP_FRAME ]
400
+ #if __ARM_NEON == 1
401
+ ORR R2 , R2 , # 4 // NEON state
402
+ #else
403
+ ORR R2 , R2 , # 2 // VFP state
406
404
#endif
405
+ STRB R2 , [ R0 , #TCB_SP_FRAME ] // Record VFP/NEON state
407
406
408
407
osRtxContextSave1:
409
- STR R3 , [ R0 , #TCB_SP_OFS ] // Store user sp to osRtxInfo.thread.run.curr
408
+ STR R3 , [ R0 , #TCB_SP_OFS ] // Store user sp to osRtxInfo.thread.run.curr
410
409
411
410
osRtxContextRestore:
412
- STR R1 , [ R12 ] // Store run.next to run.curr
413
- LDR R3 , [ R1 , #TCB_SP_OFS ] // Load next osRtxThread_t. sp
414
- LDRB R2 , [ R1 , #TCB_SP_FRAME ] // Load next osRtxThread_t.stack_frame
415
-
416
- ANDS R2 , R2 , # 0x6 // Check stack frame for VFP context
417
- MRC p15 , 0 , R2 , c1 , c0 , 2 // Read CPACR
418
- ANDEQ R2 , R2 , # 0xFF0FFFFF // Disable VFP/NEON access if incoming task does not have stacked VFP/NEON state
419
- ORRNE R2 , R2 , # 0x00F00000 // Enable VFP/NEON access if incoming task does have stacked VFP/NEON state
420
- MCR p15 , 0 , R2 , c1 , c0 , 2 // Write CPACR
421
- BEQ osRtxContextRestore1 // No VFP
422
- ISB // Only sync if we enabled VFP , otherwise we will context switch before next VFP instruction anyway
423
- #if TARGET_FEATURE_EXTENSION_REGISTER_COUNT == 32
424
- VLDMIA R3! , {D16 - D31}
411
+ STR R1 , [ R12 ] // Store run.next to run.curr
412
+ LDR R3 , [ R1 , #TCB_SP_OFS ] // Load next osRtxThread_t. sp
413
+ LDRB R2 , [ R1 , #TCB_SP_FRAME ] // Load next osRtxThread_t.stack_frame
414
+
415
+ ANDS R2 , R2 , # 0x6 // Check stack frame for VFP context
416
+ MRC p15 , 0 , R2 , c1 , c0 , 2 // Read CPACR
417
+ ANDEQ R2 , R2 , # 0xFF0FFFFF // Disable VFP/NEON access if incoming task does not have stacked VFP/NEON state
418
+ ORRNE R2 , R2 , # 0x00F00000 // Enable VFP/NEON access if incoming task does have stacked VFP/NEON state
419
+ MCR p15 , 0 , R2 , c1 , c0 , 2 // Write CPACR
420
+ BEQ osRtxContextRestore1 // No VFP
421
+ ISB // Only sync if we enabled VFP , otherwise we will context switch before next VFP instruction anyway
422
+ #if __ARM_NEON == 1
423
+ VLDMIA R3! , {D16 - D31} // Restore D16 - D31
425
424
#endif
426
- VLDMIA R3! , {D0 - D15}
425
+ VLDMIA R3! , {D0 - D15} // Restore D0 - D15
427
426
LDR R2 , [ R3 ]
428
- VMSR FPSCR , R2
427
+ VMSR FPSCR , R2 // Restore FPSCR
429
428
ADD R3 , R3 , # 8
430
429
431
430
osRtxContextRestore1:
432
- LDMIA R3! , {R4 - R11 } // Restore R4 - R11
433
- MOV R12 , R3 // Move sp pointer to R12
434
- ADD R3 , R3 , # 32 // Adjust sp
435
- PUSH {R3} // Push sp onto stack
436
- LDMIA SP , { SP }^ // Restore SP_usr
437
- ADD SP , SP , # 4 // Adjust SP_svc
438
- LDMIA R12 ! , {R0 - R3} // Restore User R0 - R3
439
- LDR LR , [ R12 , # 12 ] // Load SPSR into LR
440
- MSR SPSR_cxsf , LR // Restore SPSR
441
- ADD R12 , R12 , # 4 // Adjust pointer to LR
442
- LDM R12 , {LR}^ // Restore LR_usr directly into LR
443
- LDR LR , [ R12 , # 4 ] // Restore LR
444
- LDR R12 , [ R12 , # - 4 ] // Restore R12
445
-
446
- MOVS PC , LR // Return from exception
431
+ LDMIA R3! , {R4 - R11 } // Restore R4 - R11
432
+ MOV R12 , R3 // Move sp pointer to R12
433
+ ADD R3 , R3 , # 32 // Adjust sp
434
+ PUSH {R3} // Push sp onto stack
435
+ LDMIA SP , { SP }^ // Restore SP_usr
436
+ ADD SP , SP , # 4 // Adjust SP_svc
437
+ LDMIA R12 ! , {R0 - R3} // Restore User R0 - R3
438
+ LDR LR , [ R12 , # 12 ] // Load SPSR into LR
439
+ MSR SPSR_cxsf , LR // Restore SPSR
440
+ ADD R12 , R12 , # 4 // Adjust pointer to LR
441
+ LDM R12 , {LR}^ // Restore LR_usr directly into LR
442
+ LDR LR , [ R12 , # 4 ] // Restore LR
443
+ LDR R12 , [ R12 , # - 4 ] // Restore R12
444
+
445
+ MOVS PC , LR // Return from exception
447
446
448
447
osRtxContextExit:
449
- POP {R0 - R3 , R12 , LR} // Restore stacked APCS registers
450
- RFEFD SP ! // Return from exception
448
+ POP {R0 - R3 , R12 , LR} // Restore stacked APCS registers
449
+ RFEFD SP ! // Return from exception
451
450
452
451
.fnend
453
452
.size osRtxContextSwitch , . - osRtxContextSwitch
0 commit comments