chiark / gitweb /
crash dumps with stack traces, need real testing. slightly strange display of sectio...
authorian <ian>
Wed, 14 Dec 2005 02:04:55 +0000 (02:04 +0000)
committerian <ian>
Wed, 14 Dec 2005 02:04:55 +0000 (02:04 +0000)
detpic/crashread
detpic/panic.asm

index 70b97d80b8608a63b6f04887d020bab5c4453257..0e1cc15d93349c3f222c931345df1313e818ee52 100755 (executable)
@@ -24,7 +24,7 @@ proc inblk {bre hre} {
 }
 
 proc wantlockind {lockind thing l} {
-    switch -exact $lockind  program { return 0 }  data { return 1 }  \
+    switch -exact $lockind  program { return -1 }  data { return 1 }  \
        default { error "unknown $thing lockind $lockind in $l" }
 }
 
@@ -45,7 +45,7 @@ while {[gets $m l] >= 0} {
        manyset $l sec type addr lockind size
        switch -exact $type  code { continue }  udata { } \
                default { error "unknown section type $type in $l" }
-       if {![wantlockind $lockind section $l]} continue
+       if {[wantlockind $lockind section $l]<=0} continue
        set addr [format 0x%08x $addr]
        lappend sections [list $addr $sec [format 0x%08x $size]]
     } elseif {[inblk {^Symbols$} \
@@ -61,7 +61,12 @@ while {[gets $m l] >= 0} {
            default { error "unknown storage $storage in $l" }
        }
        set addr [format 0x%08x $addr]
-       lappend symbols [list $addr $sym]
+       if {[string compare $lockind data]} {
+           set sv symbolsbylockind($lockind)
+       } else {
+           set sv symbols
+       }
+       lappend $sv [list $addr $sym]
     } elseif {$inblk==3} {
     } else {
        error "unknown $inblk <$block> <$headings> $l"
@@ -256,7 +261,8 @@ proc endline {} {
 }
 
 proc show {sym} {
-    global insection section displine addr shownsection inline
+    global insection section displine addr shownsection inline shownss
+    set showsectionend 0
     if {$insection && [string compare $section $shownsection]} {
        endline
        p "---------- $section ----------\n"
@@ -278,17 +284,23 @@ proc show {sym} {
        p [format "%08x %-15s %-20s" $addr \
                [lindex $sym 0] [lindex $sym 1]]
        set inline 1
+       set shownss $shownsection-$sym
     }
 }
 
+set stkptr {panic_vars_section-panic: psave_stkptr}
+set stack {panic_vars_section-panic: panic_stack}
+
+foreach ss [list $stkptr $stack] { set ccontents($ss) {} }
+
 while {$sectionnum < [llength $sections]} {
     set now_section [expr {$sectionchange - $addr}]
+    set now_symbol [expr {$symboladdr - $addr}]
     if {!$now_section && !$insection} {
        set insection 1
        set sectionchange $sectionend
        continue
     }
-    set now_symbol [expr {$symboladdr - $addr}]
     if {!$now_symbol} {
        show $symbol
        thingnext symbol
@@ -312,9 +324,43 @@ while {$sectionnum < [llength $sections]} {
     show {}
     set bytes [readbytes $addr $now]
     foreach b $bytes {
-       p [format " %02x" [expr {$b & 0xff}]]
+       set h [format "%02x" [expr {$b & 0xff}]]
+       p " $h"
+       if {[info exists ccontents($shownss)]} {
+           append ccontents($shownss) $h
+       }
        incr addr
     }
     set inline 1
 }
 endline
+
+set stackdepth 31
+
+proc stack_chkptr {si} {
+    global stkptr
+    if {$si == $stkptr+1} { p " - - - - -\n" }
+}
+
+foreach v {stkptr stack} { set $v $ccontents([set $v]) }
+
+p "\n---------- =Execution Stack= ----------\n"
+set stkptr [expr "0x$stkptr & $stackdepth"]
+
+for {set si 1} {$si <= $stackdepth} {incr si} {
+    stack_chkptr $si
+    for {set ch 2; set se 0x} {$ch >= 0} {incr ch -1} {
+       append se [string range $stack \
+               [expr ($si-1)*6+$ch*2] [expr ($si-1)*6+$ch*2+1]]
+    }
+    set symi {0 (start)}
+    foreach symi $symbolsbylockind(program) {
+       if {[lindex $symi 0] > $se} break
+    }
+    manyset $symi symaddr symsym
+    p [format " 0d%02d  %6x = %6x + %s\n" $si $se \
+           [expr {$se-$symaddr}] $symsym]
+}
+stack_chkptr [expr {$stackdepth+1}]
+
+p "---------- ========== ----------\n"
index 23f6a8cf11ce4e36ea5d160ab56bdffd7384fd9a..4893fcc451bc56e08dc5278cf1124d9a6e60c236 100644 (file)
 
  udata_acs
 
-psave_w                res     1
-psave_t                res     1
 psave_intcon   res     1
 psave_bsr      res     1
-psave_latc     res     1
-psave_tablat   res     1
-psave_tblptr   res     3
-psave_fsr0     res     2
-psave_fsr1     res     2
-psave_prod     res     2
 
 panicst                                res     1
 panicst_restart_i2c            equ     7
 panicst_acked                  equ     5
 
 panic_vars_section udata 0x060 ; not available via access bank
-panic_vars
 ; used in panic routine for temporary storage:
 
 flash_pattern          res     1
@@ -43,12 +34,26 @@ panic_regs  res     1       ; # registers in panic readout
 t0l_count      res     1
 t0h_count      res     1
 
+psave_latc     res     1
+psave_w                res     1
+psave_t                res     1
+psave_tablat   res     1
+psave_tblptr   res     3
+psave_fsr0     res     2
+psave_fsr1     res     2
+psave_prod     res     2
+psave_stkptr   res     1
+
+stack_depth    equ     31
+panic_stack    res     stack_depth*3
+
 ;****************************************************************************
 
         code
 
 ;****************************************************************************
 
+
 panic_routine
 ; switch off interrupts and power
 ; reconfigure timer0 for writing diagnostic msg to the LED
@@ -57,7 +62,7 @@ panic_routine
        bc_f    INTCON, GIEH   ; disable all interrupts
 
        mov_ff  BSR, psave_bsr
-       banksel panic_vars
+       banksel flash_pattern
 
        mov_ff  LATC, psave_latc
 
@@ -68,7 +73,6 @@ panic_routine
 ;  panicing which would be bad because we might forget to panic).
 
         mov_wf   panic_address
-       clr_f    STKPTR         ; avoids stack overruns
 
        mov_ff  t, psave_t
        mov_ff  TABLAT, psave_tablat
@@ -81,7 +85,19 @@ panic_routine
        mov_ff  FSR1H, psave_fsr1+1
        mov_ff  PRODL, psave_prod
        mov_ff  PRODH, psave_prod+1
+       mov_ff  STKPTR, psave_stkptr
+
+       mov_lfsr panic_stack + stack_depth*3 - 1, 0
+       mov_lw  stack_depth
+       mov_wf  STKPTR
+stacksave_loop
+       mov_ff  TOSU, POSTDEC0
+       mov_ff  TOSH, POSTDEC0
+       mov_ff  TOSL, POSTDEC0
+       dec_f_ifnz STKPTR
+       bra     stacksave_loop
 
+       clr_f    STKPTR         ; avoids stack overruns
        clr_f   panicst
        bs_f    picno, picno_panicd