@@ -355,11 +355,29 @@ impl ExceptionHandling for Processor {
355
355
let mut highestpri: i16 = 256 ;
356
356
let mut boostedpri: i16 = 256 ;
357
357
let subgroupshift = self . aircr . get_bits ( 8 ..11 ) ;
358
- let groupvalue = 2 << subgroupshift;
358
+ let mut groupvalue = 2 << subgroupshift;
359
359
360
360
for ( _, exp) in self . exceptions . iter ( ) . filter ( |& ( _, e) | e. active ) {
361
361
if exp. priority < highestpri {
362
362
highestpri = exp. priority ;
363
+
364
+ /*
365
+ ARMV7-M Arch Reference Manual. Version E. Page B1-527
366
+ Priority Grouping. The group priority for Reset, NMI
367
+ and HardFault are -3, -2 and -1 respectively, regardless
368
+ of the value of PRIGROUP. Note that we dont check reset because
369
+ after setting the reset pending flag, the simulator resets the
370
+ processor.
371
+ */
372
+
373
+ if exp. exception_number == Exception :: NMI . into ( ) {
374
+ groupvalue = -2 ;
375
+ }
376
+
377
+ if exp. exception_number == Exception :: HardFault . into ( ) {
378
+ groupvalue = -1 ;
379
+ }
380
+
363
381
let subgroupvalue = highestpri % groupvalue;
364
382
highestpri -= subgroupvalue;
365
383
}
@@ -645,6 +663,24 @@ mod tests {
645
663
assert ! ( core. exception_active( Exception :: BusFault ) ) ;
646
664
}
647
665
666
+ #[ test]
667
+ fn test_get_execution_priority ( ) {
668
+ let mut p = Processor :: new ( ) ;
669
+
670
+ p. reset ( ) . unwrap ( ) ;
671
+ p. msp = 0x2000_0400 ;
672
+ p. set_exception_pending ( Exception :: HardFault ) ;
673
+ p. check_exceptions ( ) ;
674
+
675
+ assert_eq ! ( p. get_execution_priority( ) , -1 ) ;
676
+
677
+ p. reset ( ) . unwrap ( ) ;
678
+ p. msp = 0x2000_0400 ;
679
+ p. set_exception_pending ( Exception :: NMI ) ;
680
+ p. check_exceptions ( ) ;
681
+ assert_eq ! ( p. get_execution_priority( ) , -2 ) ;
682
+ }
683
+
648
684
#[ test]
649
685
fn test_exception_priority ( ) {
650
686
// Arrange
0 commit comments