@@ -111,6 +111,10 @@ static void verify_callee_saved(const _callee_saved_t *src,
111111}
112112
113113#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+
114118/* Arbitrary values for the floating-point callee-saved registers */
115119struct _preempt_float ztest_thread_fp_callee_saved_regs = {
116120 .s16 = 0x11111111 , .s17 = 0x22222222 ,
@@ -194,6 +198,9 @@ static void verify_fp_callee_saved(const struct _preempt_float *src,
194198 );
195199}
196200
201+ #else
202+ /* No options passed */
203+ #define ALT_THREAD_OPTIONS 0
197204#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
198205
199206static void alt_thread_entry (void )
@@ -246,6 +253,25 @@ static void alt_thread_entry(void)
246253 "CONTROL.FPCA is not cleared at initialization: 0x%x\n" ,
247254 __get_CONTROL ());
248255
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+
249275 /* Verify that the _current_ (alt) thread is initialized with FPSCR cleared. */
250276 zassert_true (__get_FPSCR () == 0 ,
251277 "(Alt thread) FPSCR is not cleared at initialization: 0x%x\n" , __get_FPSCR ());
@@ -422,6 +448,15 @@ void test_arm_thread_swap(void)
422448 */
423449 zassert_true ((_current -> arch .mode & CONTROL_FPCA_Msk ) == 0 ,
424450 "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
425460#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
426461
427462 /* Create an alternative (supervisor) testing thread */
@@ -430,7 +465,7 @@ void test_arm_thread_swap(void)
430465 K_THREAD_STACK_SIZEOF (alt_thread_stack ),
431466 (k_thread_entry_t )alt_thread_entry ,
432467 NULL , NULL , NULL ,
433- K_PRIO_COOP (PRIORITY ), 0 ,
468+ K_PRIO_COOP (PRIORITY ), ALT_THREAD_OPTIONS ,
434469 K_NO_WAIT );
435470
436471 /* Verify context-switch has not occurred. */
@@ -632,6 +667,20 @@ void test_arm_thread_swap(void)
632667 zassert_true ((__get_FPSCR () & 0x1 ) == 0x1 ,
633668 "FPSCR bit-0 not restored at swap: 0x%x\n" , __get_FPSCR ());
634669
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
635684#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
636685
637686}
0 commit comments