Skip to content

Commit

Permalink
arch/arm: Correct exception location "LR - 4" when PC invalid fault case
Browse files Browse the repository at this point in the history
If PC becomes invalid causing a fault, we replace the system_exception_location with the address at LR.

However, since the value of LR is the address to execute after returning,
the actual address that caused the fault is the address -4.

Therefore, when replacing LR with exception location, it is corrected to address - 4.
This will help avoid confusion for developers working on debugging applications such as TRAP.

Signed-off-by: eunwoo.nam <[email protected]>
  • Loading branch information
ewoodev committed Feb 3, 2025
1 parent 2781f32 commit 3c569ec
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion os/arch/arm/src/armv7-m/up_memfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int up_memfault(int irq, FAR void *context, FAR void *arg)
uint32_t mmfar = getreg32(NVIC_MEMMANAGE_ADDR);
system_exception_location = regs[REG_R15];
if (cfsr & IACCVIOL) {
system_exception_location = regs[REG_R14]; /* The PC value might be invalid, so use LR */
system_exception_location = regs[REG_R14] - 4; /* The PC value might be invalid, so use LR */
}

if (!IS_SECURE_STATE()) {
Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/armv7-m/up_usagefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int up_usagefault(int irq, FAR void *context, FAR void *arg)
if (cfsr & INVPC) {
/* As PC value might be invalid use LR value to determine if
* the crash occurred in the kernel space or in the user space */
system_exception_location = regs[REG_R14];
system_exception_location = regs[REG_R14] - 4;
}

/* Add new line to distinguish between normal log and assert log.*/
Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/armv8-m/up_memfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int up_memfault(int irq, FAR void *context, FAR void *arg)
uint32_t mmfar = getreg32(NVIC_MEMMANAGE_ADDR);
system_exception_location = regs[REG_R15];
if (cfsr & IACCVIOL) {
system_exception_location = regs[REG_R14]; /* The PC value might be invalid, so use LR */
system_exception_location = regs[REG_R14] - 4; /* The PC value might be invalid, so use LR */
}

/* Add new line to distinguish between normal log and assert log.*/
Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/armv8-m/up_usagefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int up_usagefault(int irq, FAR void *context, FAR void *arg)
if (cfsr & INVPC) {
/* As PC value might be invalid use LR value to determine if
* the crash occurred in the kernel space or in the user space */
system_exception_location = regs[REG_R14];
system_exception_location = regs[REG_R14] - 4;
}

/* Add new line to distinguish between normal log and assert log.*/
Expand Down

0 comments on commit 3c569ec

Please sign in to comment.