3 if {[llength $argv] != 3} { error "need args: serial port, map file, picno" }
4 set port [lindex $argv 0]
5 set map [lindex $argv 1]
6 set slave [lindex $argv 2]
13 proc debug {s} { puts "$s" }
15 proc manyset {list args} {
16 foreach val $list var $args { upvar 1 $var my; set my $val }
19 proc inblk {bre hre} {
20 global inblk block headings
23 [regexp $bre $block] &&
24 [regexp $hre $headings]
28 proc wantlockind {lockind thing l} {
29 switch -exact $lockind program { return -1 } data { return 1 } \
30 default { error "unknown $thing lockind $lockind in $l" }
33 while {[gets $m l] >= 0} {
34 if {![regexp {\S} $l]} {
38 } elseif {$inblk==0 && [regexp {^\s+(\S.*\S)\s*$} $l dummy block]} {
40 } elseif {$inblk==1} {
41 set headings [string trim $l]
43 } elseif {$inblk==2 && [regexp {^[- \t]+$} $l]} {
45 } elseif {[inblk {^Section Info$} \
46 {^Section\s+Type\s+Address\s+Location\s+Size\(Bytes\)$}]} {
47 manyset $l sec type addr lockind size
48 switch -exact $type code { continue } udata { } \
49 default { error "unknown section type $type in $l" }
50 if {[wantlockind $lockind section $l]<=0} continue
51 set addr [format 0x%08x $addr]
52 lappend sections [list $addr $sec [format 0x%08x $size]]
53 } elseif {[inblk {^Symbols$} \
54 {^Name\s+Address\s+Location\s+Storage\s+File$}]} {
55 manyset $l sym addr lockind storage file
56 if {![wantlockind $lockind symbol $l]} continue
57 switch -exact $storage {
58 extern { set sym [list {} $sym] }
60 regexp {^(.*)\.asm$} $file dummy file
61 set sym [list $file: $sym]
63 default { error "unknown storage $storage in $l" }
65 set addr [format 0x%08x $addr]
66 if {[string compare $lockind data]} {
67 set sv symbolsbylockind($lockind)
71 lappend $sv [list $addr $sym]
72 } elseif {$inblk==3} {
74 error "unknown $inblk <$block> <$headings> $l"
80 OSCCON LVDCON WDTCON RCON
82 SSPADD SSPSTAT SSPCON1 SSPCON2
85 ECCPR1* ECCP1DEL ECCPAS
93 set h [open /usr/share/gputils/header/p18f458.inc]
96 while {[gets $h l]>=0} {
97 if {[regexp {^\;\-\-+\s+(\S.*\S)\s+\-\-+$} $l dummy section]} {
99 } elseif {![regexp {^Register Files$} $section]} {
101 } elseif {[regexp -nocase \
102 {^([a-z][a-z0-9]*)\s+equ\s+h\'0(f[0-9a-f]{2})\'\s*$} \
104 set addr [format 0x%08x 0x$loc]
106 if {[string match $pat $sym]} {
107 if {$addr != $lastaddr} {
108 lappend sections [list $addr =SFRs= 0x1]
111 lappend symbols [list $addr [list SFR $sym]]
114 } elseif {[regexp -nocase {^\;\s*reserved} $l]} {
115 } elseif {![regexp {\S} $l]} {
117 error "unknown <$section> $l"
121 lappend symbols {0x00000060 {=udata,!acs=}}
122 #lappend symbols {0x00000f00 {=SFRs,!acs=}}
123 lappend symbols {0x00000f60 {=SFRs,acs= {}}}
124 lappend sections {0x00000f00 {=SFRs=} 0}
125 #lappend sections {0x00000060 {==========UDATA,!ACS===========} 0}
126 #lappend sections {0x00000f60 {==========SFRs,ACS===========} 0}
128 lappend sections [list 0x1000 =END= 0]
129 set sections [lsort $sections]
130 set symbols [lsort $symbols]
133 proc addendlast {v ev evn} {
135 lappend syms [list [lindex [lindex $syms end] 0] [list {} (lastsymbol)]]
136 lappend syms [list [format 0x%08lx $ev] [list {} $evn]]
139 addendlast symbolsbylockind(program) 0x8000 (end)
141 set p [open $port {RDWR NONBLOCK} 0]
142 exec stty -F $port min 1 time 0 -istrip -ocrnl -onlcr -onocr -opost \
143 -ctlecho -echo -echoe -echok -echonl -iexten -isig \
145 9600 clocal cread -crtscts -hup -parenb cs8 -cstopb \
146 -ixoff bs0 cr0 ff0 nl0 -ofill -olcuc
148 fconfigure $p -blocking yes -buffering none \
149 -translation binary -encoding binary
151 fconfigure stdout -buffering none
163 set c [binary format c* $b]
164 puts -nonewline $p [format %c $b]
172 if {![llength $d]} { error "comms eof" }
179 proc selectslave_s {} {
190 proc setup_m {} { xmit 0; xmit 0; xmit 0 }
191 proc setup_s {} { setup_m; xmit_s 0; xmit_s 0 }
194 proc selectaddr_ms {xmit a} {
195 $xmit "($a >> 6) | 0x40"
196 $xmit "($a & 0x3f) | 0x40"
198 proc selectaddr_m {a} { selectaddr_ms xmit $a }
199 proc selectaddr_s {a} { selectaddr_ms xmit_s $a }
200 proc selectaddr_t {a} { global tsa; set tsa $a }
202 proc readbytes_m {n} {
206 proc readbytes_s {n} {
212 proc readbytes_t {n} {
216 lappend l [expr {$tsa - ($tsa >> 8)}]
225 proc readbytes {addr n} {
227 if {$readcursor != $addr} {
228 if {$addr & ~0x0fff} { error "bad addr $addr" }
229 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
232 set r [readbytes_$ms $n]
233 set readcursor [expr {$addr + $n}]
237 proc thingbynum {thing nnum} {
238 upvar #0 ${thing}num num
239 upvar #0 ${thing}s things
240 upvar #0 ${thing}info info
241 upvar #0 ${thing}addr addr
242 upvar #0 ${thing} name
244 if {$num < [llength $things]} {
245 set info [lindex $things $num]
247 set info {0x7fffffff =DUMMY-END= 1}
249 manyset $info addr name
250 if {![string compare $thing section]} {
251 global sectionsize sectionend
252 set sectionsize [lindex $info 2]
253 set sectionend [expr {$addr + $sectionsize}]
257 proc thingnext {thing} {
258 upvar #0 ${thing}num num
260 thingbynum $thing $num
274 proc p {s} { puts -nonewline $s }
278 proc queue_show {kind value} {
279 upvar #0 q_$kind queued
280 lappend queued $value
283 proc p_addr_symbol {a s} {
286 p [format "%08x %-15s %-20s" $a [lindex $s 0] [lindex $s 1]]
298 global addr inline insection q_symbol q_section shownss
300 #debug "do_show [format %x $addr] $insection $q_symbol $q_section"
301 if {$inline} { error "do_show inline $addr" }
302 foreach s $q_section {
303 if {![string compare $s $shownsection]} continue
304 p "---------- $s ----------\n"
308 foreach s $q_symbol {
309 p_addr_symbol $addr $s
310 set shownss [concat $s]
312 #debug "shownss>$shownss<"
313 if {!$insection && ![string compare =SFRs= $shownsection]} {
319 if {![llength $q_symbol]} { p_addr_symbol $addr {} }
322 # p "------------------------------\n"
329 foreach v {q_section q_symbol} {
336 global insection section displine addr shownsection inline shownss
338 if {$insection && [string compare $section $shownsection]} {
340 set shownsection $section
342 } elseif {!$insection && [string length $shownsection]} {
347 if {[string length $sym]} {
348 if {$displine && $inline && !($displine&3)} {
355 set shownss $shownsection-$sym
359 set stkptr {panic: psave_stkptr}
360 set stack {panic: panic_stack}
363 foreach ss [list $stkptr $stack] { set ccontents($ss) {} }
365 while {$sectionnum < [llength $sections]} {
366 # So what happens at this address ?
368 set now_section [expr {$sectionchange - $addr}]
369 if {!$now_section && !$insection} {
370 queue_show section $section
372 set sectionchange $sectionend
375 if {!$now_section && $insection} {
378 set sectionchange $sectionaddr
382 set now_symbol [expr {$symboladdr - $addr}]
384 queue_show symbol $symbol
389 # OK, that's all the things that we need to say
392 # Decide how much to do:
394 if {$now > $now_section} { set now $now_section }
406 if {$nownow > $now_max} { set nownow $now_max }
407 set bytes [readbytes $addr $nownow]
409 set h [format "%02x" [expr {$b & 0xff}]]
411 if {[info exists ccontents($shownss)]} {
412 append ccontents($shownss) $h
423 proc stack_chkptr {si} {
425 if {$si == $stkptr+1} { p " - - - - -\n" }
428 foreach v {stkptr stack} {
429 #debug ">$v|[set $v]|$ccontents([set $v])<"
430 set $v $ccontents([set $v])
434 p "---------- =Execution Stack= ----------\n"
435 set stkptr [expr "0x$stkptr & $stackdepth"]
437 for {set si 1} {$si <= $stackdepth} {incr si} {
439 for {set ch 2; set se 0x} {$ch >= 0} {incr ch -1} {
440 append se [string range $stack \
441 [expr ($si-1)*6+$ch*2] [expr ($si-1)*6+$ch*2+1]]
443 set symaddr 0; set symsym (start)
444 foreach symi $symbolsbylockind(program) {
445 if {[lindex $symi 0] > $se} break
446 manyset $symi symaddr symsym
448 p [format " 0d%02d %6x = %6x + %s\n" $si $se \
449 [expr {$se-$symaddr}] [join $symsym]]
451 stack_chkptr [expr {$stackdepth+1}]
453 p "---------- ========== ----------\n"