Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/arm/armv7-a: Modify to printing LR when NULL executing fault #6654

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion os/arch/arm/src/armv7-a/arm_prefetchabort.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
#ifdef CONFIG_APP_BINARY_SEPARATION
#include "mmu.h"
#endif

#include <tinyara/arch.h>
#include <tinyara/binfmt/elf.h>

/****************************************************************************
* Public Variables
****************************************************************************/
Expand All @@ -80,7 +84,7 @@ static inline void print_prefetchabort_detail(uint32_t *regs, uint32_t ifar, uin
lldbg_noarg("\n");
_alert("#########################################################################\n");
_alert("PANIC!!! Prefetch Abort at instruction : 0x%08x\n", regs[REG_PC]);
_alert("PC: %08x IFAR: %08x IFSR: %08x\n", regs[REG_PC], ifar, ifsr);
_alert("PC: %08x LR: %08x IFAR: %08x IFSR: %08x\n", regs[REG_PC], regs[REG_LR], ifar, ifsr);
_alert("#########################################################################\n\n\n");
}

Expand Down Expand Up @@ -178,6 +182,13 @@ uint32_t *arm_prefetchabort(uint32_t *regs, uint32_t ifar, uint32_t ifsr)
CURRENT_REGS = regs;

system_exception_location = regs[REG_R15];
if (!is_kernel_text_space(system_exception_location)
#ifdef CONFIG_APP_BINARY_SEPARATION
&& !elf_is_text_addr(system_exception_location)
#endif
) {
system_exception_location = regs[REG_R14] - 4;
}

#ifdef CONFIG_SYSTEM_REBOOT_REASON
up_reboot_reason_write(REBOOT_SYSTEM_PREFETCHABORT);
Expand Down
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
17 changes: 17 additions & 0 deletions os/binfmt/libelf/libelf_sections.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ void elf_show_all_bin_section_addr(void)
}
}
}

bool elf_is_text_addr(void *addr)
{
int bin_idx;
void *start_addr;
void *end_addr;
for (bin_idx = 0; bin_idx <= CONFIG_NUM_APPS; bin_idx++) {
if (g_bin_addr_list[bin_idx].text_addr != 0) {
start_addr = g_bin_addr_list[bin_idx].text_addr;
end_addr = start_addr + g_bin_addr_list[bin_idx].text_size;
if (start_addr <= addr && addr <= end_addr) {
return true;
}
}
}
return false;
}
#endif /* CONFIG_APP_BINARY_SEPARATION */

/****************************************************************************
Expand Down
20 changes: 19 additions & 1 deletion os/binfmt/libxipelf/xipelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ typedef struct bin_addr_info_s bin_addr_info_t;
#ifdef CONFIG_APP_BINARY_SEPARATION
/* The list for a common binary and user binaries(CONFIG_NUM_APPS) */
static bin_addr_info_t g_bin_addr_list[CONFIG_NUM_APPS + 1];
#endif


bin_addr_info_t *get_bin_addr_list(void)
{
Expand Down Expand Up @@ -257,3 +257,21 @@ void *elf_find_text_section_addr(int bin_idx)
}
return NULL;
}

bool elf_is_text_addr(void *addr)
{
int bin_idx;
void *start_addr;
void *end_addr;
for (bin_idx = 0; bin_idx <= CONFIG_NUM_APPS; bin_idx++) {
if (g_bin_addr_list[bin_idx].text_addr != 0) {
start_addr = g_bin_addr_list[bin_idx].text_addr;
end_addr = start_addr + g_bin_addr_list[bin_idx].text_size;
if (start_addr < addr && addr < end_addr) {
Copy link
Contributor

@abhishek-samsung abhishek-samsung Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar function for elf checks <= . Please match it here too.

return true;
}
}
}
return false;
}
#endif
1 change: 1 addition & 0 deletions os/include/tinyara/binfmt/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ bin_addr_info_t *get_bin_addr_list(void);

void *elf_find_text_section_addr(int bin_idx);
void elf_show_all_bin_section_addr(void);
bool elf_is_text_addr(void *addr);
#endif

#undef EXTERN
Expand Down