@@ -111,6 +111,10 @@ static void verify_callee_saved(const _callee_saved_t *src,
111
111
}
112
112
113
113
#if defined(CONFIG_FPU ) && defined(CONFIG_FPU_SHARING )
114
+
115
+ /* Create the alternative thread with K_FP_REGS options */
116
+ #define ALT_THREAD_OPTIONS K_FP_REGS
117
+
114
118
/* Arbitrary values for the floating-point callee-saved registers */
115
119
struct _preempt_float ztest_thread_fp_callee_saved_regs = {
116
120
.s16 = 0x11111111 , .s17 = 0x22222222 ,
@@ -194,6 +198,9 @@ static void verify_fp_callee_saved(const struct _preempt_float *src,
194
198
);
195
199
}
196
200
201
+ #else
202
+ /* No options passed */
203
+ #define ALT_THREAD_OPTIONS 0
197
204
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
198
205
199
206
static void alt_thread_entry (void )
@@ -246,6 +253,25 @@ static void alt_thread_entry(void)
246
253
"CONTROL.FPCA is not cleared at initialization: 0x%x\n" ,
247
254
__get_CONTROL ());
248
255
256
+ /* Verify that the _current_ (alt) thread is
257
+ * initialized with mode.FPCA cleared
258
+ */
259
+ zassert_true ((_current -> arch .mode & CONTROL_FPCA_Msk ) == 0 ,
260
+ "Alt thread FPCA flag not clear at initialization\n" );
261
+ #if defined(CONFIG_MPU_STACK_GUARD )
262
+ /* Alt thread is created with K_FP_REGS set, so we
263
+ * expect lazy stacking and long guard to be enabled.
264
+ */
265
+ zassert_true ((_current -> arch .mode &
266
+ Z_ARM_MODE_MPU_GUARD_FLOAT_Msk ) != 0 ,
267
+ "Alt thread MPU GUAR DFLOAT flag not set at initialization\n" );
268
+ zassert_true ((_current -> base .user_options & K_FP_REGS ) != 0 ,
269
+ "Alt thread K_FP_REGS not set at initialization\n" );
270
+ zassert_true ((FPU -> FPCCR & FPU_FPCCR_LSPEN_Msk ) != 0 ,
271
+ "Lazy FP Stacking not set at initialization\n" );
272
+ #endif
273
+
274
+
249
275
/* Verify that the _current_ (alt) thread is initialized with FPSCR cleared. */
250
276
zassert_true (__get_FPSCR () == 0 ,
251
277
"(Alt thread) FPSCR is not cleared at initialization: 0x%x\n" , __get_FPSCR ());
@@ -422,6 +448,15 @@ void test_arm_thread_swap(void)
422
448
*/
423
449
zassert_true ((_current -> arch .mode & CONTROL_FPCA_Msk ) == 0 ,
424
450
"Thread FPCA flag not clear at initialization\n" );
451
+ #if defined(CONFIG_MPU_STACK_GUARD )
452
+ zassert_true ((_current -> arch .mode &
453
+ Z_ARM_MODE_MPU_GUARD_FLOAT_Msk ) == 0 ,
454
+ "Thread MPU GUAR DFLOAT flag not clear at initialization\n" );
455
+ zassert_true ((_current -> base .user_options & K_FP_REGS ) == 0 ,
456
+ "Thread K_FP_REGS not clear at initialization\n" );
457
+ zassert_true ((FPU -> FPCCR & FPU_FPCCR_LSPEN_Msk ) == 0 ,
458
+ "Lazy FP Stacking not clear at initialization\n" );
459
+ #endif
425
460
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
426
461
427
462
/* Create an alternative (supervisor) testing thread */
@@ -430,7 +465,7 @@ void test_arm_thread_swap(void)
430
465
K_THREAD_STACK_SIZEOF (alt_thread_stack ),
431
466
(k_thread_entry_t )alt_thread_entry ,
432
467
NULL , NULL , NULL ,
433
- K_PRIO_COOP (PRIORITY ), 0 ,
468
+ K_PRIO_COOP (PRIORITY ), ALT_THREAD_OPTIONS ,
434
469
K_NO_WAIT );
435
470
436
471
/* Verify context-switch has not occurred. */
@@ -632,6 +667,20 @@ void test_arm_thread_swap(void)
632
667
zassert_true ((__get_FPSCR () & 0x1 ) == 0x1 ,
633
668
"FPSCR bit-0 not restored at swap: 0x%x\n" , __get_FPSCR ());
634
669
670
+ /* The main test thread is using the FP registers, and the .mode
671
+ * flag and MPU GUARD flag are now updated.
672
+ */
673
+ zassert_true ((_current -> arch .mode & CONTROL_FPCA_Msk ) != 0 ,
674
+ "Thread FPCA flag not set after main returned back\n" );
675
+ #if defined(CONFIG_MPU_STACK_GUARD )
676
+ zassert_true ((_current -> arch .mode &
677
+ Z_ARM_MODE_MPU_GUARD_FLOAT_Msk ) != 0 ,
678
+ "Thread MPU GUARD FLOAT flag not set\n" );
679
+ zassert_true ((_current -> base .user_options & K_FP_REGS ) != 0 ,
680
+ "Thread K_FPREGS not set after main returned back\n" );
681
+ zassert_true ((FPU -> FPCCR & FPU_FPCCR_LSPEN_Msk ) != 0 ,
682
+ "Lazy FP Stacking not set after main returned back\n" );
683
+ #endif
635
684
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
636
685
637
686
}
0 commit comments