Skip to content

Commit 13f269f

Browse files
committed
vmpu: Replace 0x04 and 0x82 with CMSIS definitions
Magic numbers are a bit hard to read. Use the standard CMSIS definitions for these fault status bits in an attempt to replace the magic number with something slightly more readable.
1 parent f32d5ed commit 13f269f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

core/vmpu/src/armv7m/vmpu_armv7m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int vmpu_fault_recovery_mpu(uint32_t pc, uint32_t sp, uint32_t fault_addr
9191
uint8_t mask, index, page;
9292

9393
/* No recovery is possible if the MPU syndrome register is not valid. */
94-
if (fault_status != 0x82) {
94+
if (fault_status == (SCB_CFSR_MMARVALID_Msk | SCB_CFSR_DACCVIOL_Msk)) {
9595
return 0;
9696
}
9797

core/vmpu/src/vmpu.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,25 @@ int vmpu_fault_recovery_bus(uint32_t pc, uint32_t sp, uint32_t fault_addr, uint3
368368
HALT_ERROR(NOT_ALLOWED, "This is not the PC (0x%08X) your were searching for", pc);
369369
}
370370

371-
/* Check fault register; the following two configurations are allowed:
372-
* 0x04 - imprecise data bus fault, no stacking/unstacking errors.
373-
* 0x82 - precise data bus fault, no stacking/unstacking errors. */
371+
/* Check fault register; the following two configurations are allowed.
372+
* - Precise data bus fault, no stacking/unstacking errors
373+
* - Imprecise data bus fault, no stacking/unstacking errors */
374374
/* Note: Currently the faulting address argument is not used, since it
375375
* is saved in r0 for managed bus faults. */
376376
switch (fault_status) {
377-
case 0x82:
377+
case (SCB_CFSR_MMARVALID_Msk | SCB_CFSR_DACCVIOL_Msk):
378+
/* Precise data bus fault, no stacking/unstacking errors */
378379
cnt_max = 0;
379380
break;
380-
case 0x04:
381+
382+
/* Shift right by a byte because our BFSR (read into fault_status) is
383+
* already shifted relative to CFSR. The CMSIS masks are CFSR relative,
384+
* so we need to shift the mask to align with our BFSR. */
385+
case (SCB_CFSR_IMPRECISERR_Msk >> 8):
386+
/* Imprecise data bus fault, no stacking/unstacking errors */
381387
cnt_max = UVISOR_NOP_CNT;
382388
break;
389+
383390
default:
384391
return -1;
385392
}

0 commit comments

Comments
 (0)