3 proc debug {s} { puts "$s" }
5 proc manyset {list args} {
6 foreach val $list var $args { upvar 1 $var my; set my $val }
10 global inblk block headings
13 [regexp $bre $block] &&
14 [regexp $hre $headings]
18 proc wantlockind {lockind thing l} {
19 switch -exact $lockind program { return -1 } data { return 1 } \
20 default { error "unknown $thing lockind $lockind in $l" }
23 proc addendlast {v ev evn} {
25 lappend syms [list [lindex [lindex $syms end] 0] [list {} (lastsymbol)]]
26 lappend syms [list [format 0x%08lx $ev] [list {} $evn]]
33 set c [binary format c* $b]
34 puts -nonewline $p [format %c $b]
42 if {![llength $d]} { error "comms eof" }
43 lappend l [expr {$d & 0x0ff}]
50 fconfigure $p -blocking no
51 while {[string length [read $p 1024]]} { }
52 fconfigure $p -blocking yes
55 proc selectslave_slave {slave} {
59 proc selectslave_s {} {
61 selectslave_slave $slave
64 proc xmit_slave {slave b} {
66 selectslave_slave $slave
77 catch { unset pause_var }
78 after $t {set pause_var y}
82 proc setup_m {} { xmit 0; xmit 0; xmit 0; pause 250; junkrecv }
83 proc setup_s {} { setup_m; xmit 128; pause 256; junkrecv; xmit_s 0; xmit_s 0 }
86 proc selectaddr_ms {xmit a} {
87 $xmit "($a >> 6) | 0x40"
88 $xmit "($a & 0x3f) | 0x40"
90 proc selectaddr_m {a} { selectaddr_ms xmit $a }
91 proc selectaddr_s {a} { selectaddr_ms xmit_s $a }
92 proc selectaddr_t {a} { global tsa; set tsa $a }
94 proc readbytes_m {n} {
98 proc readbytes_s {n} {
104 proc readbytes_t {n} {
108 lappend l [expr {$tsa - ($tsa >> 8)}]
115 proc readbytes {addr n} {
117 if {$readcursor != $addr} {
118 if {$addr & ~0x0fff} { error "bad addr $addr" }
119 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
122 set r [readbytes_$ms $n]
123 set readcursor [expr {$addr + $n}]
127 proc thingbynum {thing nnum} {
128 upvar #0 ${thing}num num
129 upvar #0 ${thing}s things
130 upvar #0 ${thing}info info
131 upvar #0 ${thing}addr addr
132 upvar #0 ${thing} name
134 if {$num < [llength $things]} {
135 set info [lindex $things $num]
137 set info {0x7fffffff =DUMMY-END= 1}
139 manyset $info addr name
140 if {![string compare $thing section]} {
141 global sectionsize sectionend
142 set sectionsize [lindex $info 2]
143 set sectionend [expr {$addr + $sectionsize}]
147 proc thingnext {thing} {
148 upvar #0 ${thing}num num
150 thingbynum $thing $num
154 proc p {s} { puts -nonewline $s }
156 proc reset_s {val min max} {
157 for {set slave $min} {$slave < $max} {incr slave} {
158 xmit_slave $slave $val
163 if {[regexp {^(\d+)\.(\d+)} $arg min max]} {
164 } elseif {[regexp {^(\d+)} $arg max]} {
167 error "--reset arg $arg wrong"
170 reset_s 0x00 $min $max
171 reset_s 0x00 $min $max
172 reset_s 0x09 $min $max
177 set m "bad usage: $m"
179 usage: .../crashread <port> <map-file> <picno>
180 pass `-1' for <picno> for test (data memory map) mode only
181 pass `reset' for <map-file> to reset pics (then
182 <picno> should be <lastpicno+1> or <firstslave>-<lastpicno+1>)
187 if {[llength $argv] != 3} { badusage "wrong # args" }
189 set port [lindex $argv 0]
190 set map [lindex $argv 1]
191 set slave [lindex $argv 2]
193 set p [open $port {RDWR NONBLOCK} 0]
194 exec stty -F $port min 1 time 0 -istrip -ocrnl -onlcr -onocr -opost \
195 -ctlecho -echo -echoe -echok -echonl -iexten -isig \
197 9600 clocal cread -crtscts -hup -parenb cs8 -cstopb \
198 -ixoff bs0 cr0 ff0 nl0 -ofill -olcuc
200 fconfigure $p -blocking yes -buffering none \
201 -translation binary -encoding binary
203 fconfigure stdout -buffering none
205 if {![string compare reset $map]} {
215 while {[gets $m l] >= 0} {
216 if {![regexp {\S} $l]} {
220 } elseif {$inblk==0 && [regexp {^\s+(\S.*\S)\s*$} $l dummy block]} {
222 } elseif {$inblk==1} {
223 set headings [string trim $l]
225 } elseif {$inblk==2 && [regexp {^[- \t]+$} $l]} {
227 } elseif {[inblk {^Section Info$} \
228 {^Section\s+Type\s+Address\s+Location\s+Size\(Bytes\)$}]} {
229 manyset $l sec type addr lockind size
230 switch -exact $type code { continue } udata { } \
231 default { error "unknown section type $type in $l" }
232 if {[wantlockind $lockind section $l]<=0} continue
233 set addr [format 0x%08x $addr]
234 lappend sections [list $addr $sec [format 0x%08x $size]]
235 } elseif {[inblk {^Symbols$} \
236 {^Name\s+Address\s+Location\s+Storage\s+File$}]} {
237 manyset $l sym addr lockind storage file
238 if {![wantlockind $lockind symbol $l]} continue
239 switch -exact $storage {
240 extern { set sym [list {} $sym] }
242 regexp {^(.*)\.asm$} $file dummy file
243 set sym [list $file: $sym]
245 default { error "unknown storage $storage in $l" }
247 set addr [format 0x%08x $addr]
248 if {[string compare $lockind data]} {
249 set sv symbolsbylockind($lockind)
254 lappend $sv [list $addr $sym]
255 } elseif {$inblk==3} {
257 error "unknown $inblk <$block> <$headings> $l"
263 OSCCON LVDCON WDTCON RCON
265 SSPADD SSPSTAT SSPCON1 SSPCON2
268 ECCPR1* ECCP1DEL ECCPAS
276 set h [open /usr/share/gputils/header/p18f458.inc]
279 while {[gets $h l]>=0} {
280 if {[regexp {^\;\-\-+\s+(\S.*\S)\s+\-\-+$} $l dummy section]} {
282 } elseif {![regexp {^Register Files$} $section]} {
284 } elseif {[regexp -nocase \
285 {^([a-z][a-z0-9]*)\s+equ\s+h\'0(f[0-9a-f]{2})\'\s*$} \
287 set addr [format 0x%08x 0x$loc]
289 if {[string match $pat $sym]} {
290 if {$addr != $lastaddr} {
291 lappend sections [list $addr =SFRs= 0x1]
294 lappend symbols [list $addr [list SFR $sym]]
297 } elseif {[regexp -nocase {^\;\s*reserved} $l]} {
298 } elseif {![regexp {\S} $l]} {
300 error "unknown <$section> $l"
304 lappend symbols {0x00000060 {=udata,!acs=}}
305 #lappend symbols {0x00000f00 {=SFRs,!acs=}}
306 lappend symbols {0x00000f60 {=SFRs,acs= {}}}
307 lappend sections {0x00000f00 {=SFRs=} 0}
308 #lappend sections {0x00000060 {==========UDATA,!ACS===========} 0}
309 #lappend sections {0x00000f60 {==========SFRs,ACS===========} 0}
311 lappend sections [list 0x1000 =END= 0]
314 foreach tosort {sections symbols symbolsbylockind(program)} {
316 set ts [lsort [set ts]]
340 proc queue_show {kind value} {
341 upvar #0 q_$kind queued
342 lappend queued $value
345 proc p_addr_symbol {a s} {
348 p [format "%08x %-15s %-20s" $a [lindex $s 0] [lindex $s 1]]
360 global addr inline insection q_symbol q_section shownss
362 #debug "do_show [format %x $addr] $insection $q_symbol $q_section"
363 if {$inline} { error "do_show inline $addr" }
364 foreach s $q_section {
365 if {![string compare $s $shownsection]} continue
366 p "---------- $s ----------\n"
370 foreach s $q_symbol {
371 p_addr_symbol $addr $s
372 set shownss [concat $s]
374 #debug "shownss>$shownss<"
375 if {!$insection && ![string compare =SFRs= $shownsection]} {
381 if {![llength $q_symbol]} { p_addr_symbol $addr {} }
384 # p "------------------------------\n"
391 foreach v {q_section q_symbol} {
398 global insection section displine addr shownsection inline shownss
400 if {$insection && [string compare $section $shownsection]} {
402 set shownsection $section
404 } elseif {!$insection && [string length $shownsection]} {
409 if {[string length $sym]} {
410 if {$displine && $inline && !($displine&3)} {
417 set shownss $shownsection-$sym
421 if {[info exists smap(misc:\ debugp)] && [info exists smap(misc:\ debug)]} {
422 set debugpval [readbytes $smap(misc:\ debugp) 1]
424 # puts y2-$smap(misc:\ debug)
425 set debugpaddr [format 0x%08x [expr {$debugpval+$smap(misc:\ debug)}]]
426 # puts y3-$debugpaddr
427 lappend symbols [list $debugpaddr [list "" (debugp)]]
431 addendlast symbolsbylockind(program) 0x8000 (end)
433 set stkptr {panic: psave_stkptr}
434 set stack {panic: panic_stack}
437 foreach ss [list $stkptr $stack] { set ccontents($ss) {} }
439 while {$sectionnum < [llength $sections]} {
440 # So what happens at this address ?
442 set now_section [expr {$sectionchange - $addr}]
443 if {!$now_section && !$insection} {
444 queue_show section $section
446 set sectionchange $sectionend
449 if {!$now_section && $insection} {
452 set sectionchange $sectionaddr
456 set now_symbol [expr {$symboladdr - $addr}]
458 queue_show symbol $symbol
463 # OK, that's all the things that we need to say
466 # Decide how much to do:
468 if {$now > $now_section} { set now $now_section }
480 if {$nownow > $now_max} { set nownow $now_max }
481 set bytes [readbytes $addr $nownow]
483 set h [format "%02x" [expr {$b & 0xff}]]
485 if {[info exists ccontents($shownss)]} {
486 append ccontents($shownss) $h
497 proc stack_chkptr {si} {
499 if {$si == $stkptr+1} { p " - - - - -\n" }
502 foreach v {stkptr stack} {
503 #debug ">$v|[set $v]|$ccontents([set $v])<"
504 set $v $ccontents([set $v])
508 p "---------- =Execution Stack= ----------\n"
509 set stkptr [expr "0x$stkptr & $stackdepth"]
511 for {set si 1} {$si <= $stackdepth} {incr si} {
513 for {set ch 2; set se 0x} {$ch >= 0} {incr ch -1} {
514 append se [string range $stack \
515 [expr ($si-1)*6+$ch*2] [expr ($si-1)*6+$ch*2+1]]
517 set symaddr 0; set symsym (start)
518 foreach symi $symbolsbylockind(program) {
519 if {[lindex $symi 0] > $se} break
520 manyset $symi symaddr symsym
522 p [format " 0d%02d %6x = %6x + %s\n" $si $se \
523 [expr {$se-$symaddr}] [join $symsym]]
525 stack_chkptr [expr {$stackdepth+1}]
527 p "---------- ========== ----------\n"