}
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" }
}
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$} \
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"
}
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"
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
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"
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
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
bc_f INTCON, GIEH ; disable all interrupts
mov_ff BSR, psave_bsr
- banksel panic_vars
+ banksel flash_pattern
mov_ff LATC, psave_latc
; 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
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