From 44bec4cf8e90f9cd553e690a5a775970305ab1fa Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 25 Jan 2022 15:54:36 +0200 Subject: [PATCH] RISC-V: Add missing code to dumpstate Just add the kernel stack dumping for completeness --- arch/risc-v/src/common/riscv_assert.c | 37 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/risc-v/src/common/riscv_assert.c b/arch/risc-v/src/common/riscv_assert.c index 25e4b4bec23..39b6a2b4932 100644 --- a/arch/risc-v/src/common/riscv_assert.c +++ b/arch/risc-v/src/common/riscv_assert.c @@ -318,6 +318,9 @@ static void riscv_dumpstate(void) uintptr_t istackbase; uintptr_t istacksize; #endif +#ifdef CONFIG_ARCH_KERNEL_STACK + uintptr_t kstackbase = 0; +#endif /* Show back trace */ @@ -395,18 +398,46 @@ static void riscv_dumpstate(void) _alert("stack size: %" PRIxREG "\n", ustacksize); #endif +#ifdef CONFIG_ARCH_KERNEL_STACK + /* Does this thread have a kernel stack allocated? */ + + if (rtcb->xcp.kstack) + { + kstackbase = (uintptr_t)rtcb->xcp.kstack; + + _alert("Kernel stack:\n"); + _alert(" base: %" PRIxREG "\n", kstackbase); + _alert(" size: %" PRIxREG "\n", CONFIG_ARCH_KERNEL_STACKSIZE); + } +#endif + /* Dump the user stack if the stack pointer lies within the allocated user * stack memory. */ if (sp >= ustackbase && sp < ustackbase + ustacksize) { - _alert("ERROR: Stack pointer is not within allocated stack\n"); - riscv_stackdump(ustackbase, ustackbase + ustacksize); + _alert("User Stack\n"); + riscv_stackdump(sp, ustackbase + ustacksize); } + +#ifdef CONFIG_ARCH_KERNEL_STACK + /* Dump the kernel stack if the stack pointer lies within the allocated + * kernel stack memory. + */ + + else if (kstackbase != 0 && + sp >= kstackbase && + sp < kstackbase + CONFIG_ARCH_KERNEL_STACKSIZE) + { + _alert("Kernel Stack\n"); + riscv_stackdump(sp, kstackbase + CONFIG_ARCH_KERNEL_STACKSIZE); + } +#endif else { - riscv_stackdump(sp, ustackbase + ustacksize); + _alert("ERROR: Stack pointer is not within allocated stack\n"); + riscv_stackdump(ustackbase, ustackbase + ustacksize); } } #else