You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/23 17:47:01 UTC

[GitHub] ccollins476ad commented on a change in pull request #1476: os: Add option to restore registers state on crash

ccollins476ad commented on a change in pull request #1476: os: Add option to restore registers state on crash
URL: https://github.com/apache/mynewt-core/pull/1476#discussion_r227497196
 
 

 ##########
 File path: kernel/os/src/arch/cortex_m0/os_fault.c
 ##########
 @@ -153,6 +156,48 @@ os_default_irq(struct trap_frame *tf)
     trap_to_coredump(tf, &regs);
     coredump_dump(&regs, sizeof(regs));
 #endif
-    hal_system_reset();
+
+#if MYNEWT_VAL(OS_CRASH_RESTORE_REGS)
+    if ((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) < 16) {
+        console_printf("Use 'set $pc = 0x%08lx' to restore PC in gdb\n",
+                       tf->ef->pc);
+
+        orig_sp = &tf->ef->r0;
+        orig_sp += 8;
+        if (tf->ef->psr & SCB_CCR_STKALIGN_Msk) {
+            orig_sp++;
+        }
+
+        console_printf("Use 'set $pc = 0x%08lx' to restore PC in gdb\n",
+                       tf->ef->pc);
+
+        __asm volatile (
+            "mov sp,  %[stack_ptr]\n"
+            "mov r0,  %[regs1]\n"
+            "mov r1,  %[regs2]\n"
+            "mov r2,  r1\n"
+            "add r2,  r2, #16\n"
+            "ldm r2!, {r4-r7}\n"
+            "mov r8,  r4\n"
+            "mov r9,  r5\n"
+            "mov r10, r6\n"
+            "mov r11, r7\n"
+            "ldm r1!, {r4-r7}\n"
+            "ldr r1,  [r0, #16]\n"
+            "mov r12, r1\n"
+            "ldr r1,  [r0, #20]\n"
+            "mov lr,  r1\n"
+            "ldm r0!, {r0-r3}\n"
+            "bkpt"
+            :
+            : [regs1] "r" (tf->ef),
+              [regs2] "r" (&tf->r4),
+              [stack_ptr] "r" (orig_sp)
+            : "r0", "r1", "r2"
+        );
+    }
+#endif
+
+    NVIC_SystemReset();
 
 Review comment:
   Should this be `hal_system_reset()` (rather than `NVIC_SystemReset()`)?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services