@@ -229,19 +229,22 @@ uint32_t z_check_thread_stack_fail(const uint32_t fault_addr,
229
229
static uint32_t mem_manage_fault (z_arch_esf_t * esf , int from_hard_fault ,
230
230
bool * recoverable )
231
231
{
232
- uint32_t reason = K_ERR_CPU_EXCEPTION ;
232
+ uint32_t reason = K_ERR_ARM_MEM_GENERIC ;
233
233
uint32_t mmfar = - EINVAL ;
234
234
235
235
PR_FAULT_INFO ("***** MPU FAULT *****" );
236
236
237
237
if ((SCB -> CFSR & SCB_CFSR_MSTKERR_Msk ) != 0 ) {
238
+ reason = K_ERR_ARM_MEM_STACKING ;
238
239
PR_FAULT_INFO (" Stacking error (context area might be"
239
240
" not valid)" );
240
241
}
241
242
if ((SCB -> CFSR & SCB_CFSR_MUNSTKERR_Msk ) != 0 ) {
243
+ reason = K_ERR_ARM_MEM_UNSTACKING ;
242
244
PR_FAULT_INFO (" Unstacking error" );
243
245
}
244
246
if ((SCB -> CFSR & SCB_CFSR_DACCVIOL_Msk ) != 0 ) {
247
+ reason = K_ERR_ARM_MEM_DATA_ACCESS ;
245
248
PR_FAULT_INFO (" Data Access Violation" );
246
249
/* In a fault handler, to determine the true faulting address:
247
250
* 1. Read and save the MMFAR value.
@@ -263,10 +266,12 @@ static uint32_t mem_manage_fault(z_arch_esf_t *esf, int from_hard_fault,
263
266
}
264
267
}
265
268
if ((SCB -> CFSR & SCB_CFSR_IACCVIOL_Msk ) != 0 ) {
269
+ reason = K_ERR_ARM_MEM_INSTRUCTION_ACCESS ;
266
270
PR_FAULT_INFO (" Instruction Access Violation" );
267
271
}
268
272
#if defined(CONFIG_ARMV7_M_ARMV8_M_FP )
269
273
if ((SCB -> CFSR & SCB_CFSR_MLSPERR_Msk ) != 0 ) {
274
+ reason = K_ERR_ARM_MEM_FP_LAZY_STATE_PRESERVATION ;
270
275
PR_FAULT_INFO (
271
276
" Floating-point lazy state preservation error" );
272
277
}
@@ -382,17 +387,20 @@ static uint32_t mem_manage_fault(z_arch_esf_t *esf, int from_hard_fault,
382
387
*/
383
388
static int bus_fault (z_arch_esf_t * esf , int from_hard_fault , bool * recoverable )
384
389
{
385
- uint32_t reason = K_ERR_CPU_EXCEPTION ;
390
+ uint32_t reason = K_ERR_ARM_BUS_GENERIC ;
386
391
387
392
PR_FAULT_INFO ("***** BUS FAULT *****" );
388
393
389
394
if (SCB -> CFSR & SCB_CFSR_STKERR_Msk ) {
395
+ reason = K_ERR_ARM_BUS_STACKING ;
390
396
PR_FAULT_INFO (" Stacking error" );
391
397
}
392
398
if (SCB -> CFSR & SCB_CFSR_UNSTKERR_Msk ) {
399
+ reason = K_ERR_ARM_BUS_UNSTACKING ;
393
400
PR_FAULT_INFO (" Unstacking error" );
394
401
}
395
402
if (SCB -> CFSR & SCB_CFSR_PRECISERR_Msk ) {
403
+ reason = K_ERR_ARM_BUS_PRECISE_DATA_BUS ;
396
404
PR_FAULT_INFO (" Precise data bus error" );
397
405
/* In a fault handler, to determine the true faulting address:
398
406
* 1. Read and save the BFAR value.
@@ -413,14 +421,17 @@ static int bus_fault(z_arch_esf_t *esf, int from_hard_fault, bool *recoverable)
413
421
}
414
422
}
415
423
if (SCB -> CFSR & SCB_CFSR_IMPRECISERR_Msk ) {
424
+ reason = K_ERR_ARM_BUS_IMPRECISE_DATA_BUS ;
416
425
PR_FAULT_INFO (" Imprecise data bus error" );
417
426
}
418
427
if ((SCB -> CFSR & SCB_CFSR_IBUSERR_Msk ) != 0 ) {
428
+ reason = K_ERR_ARM_BUS_INSTRUCTION_BUS ;
419
429
PR_FAULT_INFO (" Instruction bus error" );
420
430
#if !defined(CONFIG_ARMV7_M_ARMV8_M_FP )
421
431
}
422
432
#else
423
433
} else if (SCB -> CFSR & SCB_CFSR_LSPERR_Msk ) {
434
+ reason = K_ERR_ARM_BUS_FP_LAZY_STATE_PRESERVATION ;
424
435
PR_FAULT_INFO (" Floating-point lazy state preservation error" );
425
436
} else {
426
437
;
@@ -538,19 +549,22 @@ static int bus_fault(z_arch_esf_t *esf, int from_hard_fault, bool *recoverable)
538
549
*/
539
550
static uint32_t usage_fault (const z_arch_esf_t * esf )
540
551
{
541
- uint32_t reason = K_ERR_CPU_EXCEPTION ;
552
+ uint32_t reason = K_ERR_ARM_USAGE_GENERIC ;
542
553
543
554
PR_FAULT_INFO ("***** USAGE FAULT *****" );
544
555
545
556
/* bits are sticky: they stack and must be reset */
546
557
if ((SCB -> CFSR & SCB_CFSR_DIVBYZERO_Msk ) != 0 ) {
558
+ reason = K_ERR_ARM_USAGE_DIV_0 ;
547
559
PR_FAULT_INFO (" Division by zero" );
548
560
}
549
561
if ((SCB -> CFSR & SCB_CFSR_UNALIGNED_Msk ) != 0 ) {
562
+ reason = K_ERR_ARM_USAGE_UNALIGNED_ACCESS ;
550
563
PR_FAULT_INFO (" Unaligned memory access" );
551
564
}
552
565
#if defined(CONFIG_ARMV8_M_MAINLINE )
553
566
if ((SCB -> CFSR & SCB_CFSR_STKOF_Msk ) != 0 ) {
567
+ reason = K_ERR_ARM_USAGE_STACK_OVERFLOW ;
554
568
PR_FAULT_INFO (" Stack overflow (context area not valid)" );
555
569
#if defined(CONFIG_BUILTIN_STACK_GUARD )
556
570
/* Stack Overflows are always reported as stack corruption
@@ -565,15 +579,19 @@ static uint32_t usage_fault(const z_arch_esf_t *esf)
565
579
}
566
580
#endif /* CONFIG_ARMV8_M_MAINLINE */
567
581
if ((SCB -> CFSR & SCB_CFSR_NOCP_Msk ) != 0 ) {
582
+ reason = K_ERR_ARM_USAGE_NO_COPROCESSOR ;
568
583
PR_FAULT_INFO (" No coprocessor instructions" );
569
584
}
570
585
if ((SCB -> CFSR & SCB_CFSR_INVPC_Msk ) != 0 ) {
586
+ reason = K_ERR_ARM_USAGE_ILLEGAL_EXC_RETURN ;
571
587
PR_FAULT_INFO (" Illegal load of EXC_RETURN into PC" );
572
588
}
573
589
if ((SCB -> CFSR & SCB_CFSR_INVSTATE_Msk ) != 0 ) {
590
+ reason = K_ERR_ARM_USAGE_ILLEGAL_EPSR ;
574
591
PR_FAULT_INFO (" Illegal use of the EPSR" );
575
592
}
576
593
if ((SCB -> CFSR & SCB_CFSR_UNDEFINSTR_Msk ) != 0 ) {
594
+ reason = K_ERR_ARM_USAGE_UNDEFINED_INSTRUCTION ;
577
595
PR_FAULT_INFO (" Attempt to execute undefined instruction" );
578
596
}
579
597
@@ -590,9 +608,12 @@ static uint32_t usage_fault(const z_arch_esf_t *esf)
590
608
*
591
609
* See z_arm_fault_dump() for example.
592
610
*
611
+ * @return error code to identify the fatal error reason
593
612
*/
594
- static void secure_fault (const z_arch_esf_t * esf )
613
+ static uint32_t secure_fault (const z_arch_esf_t * esf )
595
614
{
615
+ uint32_t reason = K_ERR_ARM_SECURE_GENERIC ;
616
+
596
617
PR_FAULT_INFO ("***** SECURE FAULT *****" );
597
618
598
619
STORE_xFAR (sfar , SAU -> SFAR );
@@ -602,23 +623,32 @@ static void secure_fault(const z_arch_esf_t *esf)
602
623
603
624
/* bits are sticky: they stack and must be reset */
604
625
if ((SAU -> SFSR & SAU_SFSR_INVEP_Msk ) != 0 ) {
626
+ reason = K_ERR_ARM_SECURE_ENTRY_POINT ;
605
627
PR_FAULT_INFO (" Invalid entry point" );
606
628
} else if ((SAU -> SFSR & SAU_SFSR_INVIS_Msk ) != 0 ) {
629
+ reason = K_ERR_ARM_SECURE_INTEGRITY_SIGNATURE ;
607
630
PR_FAULT_INFO (" Invalid integrity signature" );
608
631
} else if ((SAU -> SFSR & SAU_SFSR_INVER_Msk ) != 0 ) {
632
+ reason = K_ERR_ARM_SECURE_EXCEPTION_RETURN ;
609
633
PR_FAULT_INFO (" Invalid exception return" );
610
634
} else if ((SAU -> SFSR & SAU_SFSR_AUVIOL_Msk ) != 0 ) {
635
+ reason = K_ERR_ARM_SECURE_ATTRIBUTION_UNIT ;
611
636
PR_FAULT_INFO (" Attribution unit violation" );
612
637
} else if ((SAU -> SFSR & SAU_SFSR_INVTRAN_Msk ) != 0 ) {
638
+ reason = K_ERR_ARM_SECURE_TRANSITION ;
613
639
PR_FAULT_INFO (" Invalid transition" );
614
640
} else if ((SAU -> SFSR & SAU_SFSR_LSPERR_Msk ) != 0 ) {
641
+ reason = K_ERR_ARM_SECURE_LAZY_STATE_PRESERVATION ;
615
642
PR_FAULT_INFO (" Lazy state preservation" );
616
643
} else if ((SAU -> SFSR & SAU_SFSR_LSERR_Msk ) != 0 ) {
644
+ reason = K_ERR_ARM_SECURE_LAZY_STATE_ERROR ;
617
645
PR_FAULT_INFO (" Lazy state error" );
618
646
}
619
647
620
648
/* clear SFSR sticky bits */
621
649
SAU -> SFSR |= 0xFF ;
650
+
651
+ return reason ;
622
652
}
623
653
#endif /* defined(CONFIG_ARM_SECURE_FIRMWARE) */
624
654
@@ -748,7 +778,7 @@ static uint32_t hard_fault(z_arch_esf_t *esf, bool *recoverable)
748
778
reason = usage_fault (esf );
749
779
#if defined(CONFIG_ARM_SECURE_FIRMWARE )
750
780
} else if (SAU -> SFSR != 0 ) {
751
- secure_fault (esf );
781
+ reason = secure_fault (esf );
752
782
#endif /* CONFIG_ARM_SECURE_FIRMWARE */
753
783
} else {
754
784
__ASSERT (0 ,
0 commit comments