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" }
180 fconfigure $p -blocking no
181 while {[string length [read $p 1024]]} { }
182 fconfigure $p -blocking yes
185 proc selectslave_s {} {
198 catch { unset pause_var }
199 after $t {set pause_var y}
203 proc setup_m {} { xmit 0; xmit 0; xmit 0; pause 250; junkrecv }
204 proc setup_s {} { setup_m; xmit_s 0; xmit_s 0 }
207 proc selectaddr_ms {xmit a} {
208 $xmit "($a >> 6) | 0x40"
209 $xmit "($a & 0x3f) | 0x40"
211 proc selectaddr_m {a} { selectaddr_ms xmit $a }
212 proc selectaddr_s {a} { selectaddr_ms xmit_s $a }
213 proc selectaddr_t {a} { global tsa; set tsa $a }
215 proc readbytes_m {n} {
219 proc readbytes_s {n} {
225 proc readbytes_t {n} {
229 lappend l [expr {$tsa - ($tsa >> 8)}]
238 proc readbytes {addr n} {
240 if {$readcursor != $addr} {
241 if {$addr & ~0x0fff} { error "bad addr $addr" }
242 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
245 set r [readbytes_$ms $n]
246 set readcursor [expr {$addr + $n}]
250 proc thingbynum {thing nnum} {
251 upvar #0 ${thing}num num
252 upvar #0 ${thing}s things
253 upvar #0 ${thing}info info
254 upvar #0 ${thing}addr addr
255 upvar #0 ${thing} name
257 if {$num < [llength $things]} {
258 set info [lindex $things $num]
260 set info {0x7fffffff =DUMMY-END= 1}
262 manyset $info addr name
263 if {![string compare $thing section]} {
264 global sectionsize sectionend
265 set sectionsize [lindex $info 2]
266 set sectionend [expr {$addr + $sectionsize}]
270 proc thingnext {thing} {
271 upvar #0 ${thing}num num
273 thingbynum $thing $num
287 proc p {s} { puts -nonewline $s }
291 proc queue_show {kind value} {
292 upvar #0 q_$kind queued
293 lappend queued $value
296 proc p_addr_symbol {a s} {
299 p [format "%08x %-15s %-20s" $a [lindex $s 0] [lindex $s 1]]
311 global addr inline insection q_symbol q_section shownss
313 #debug "do_show [format %x $addr] $insection $q_symbol $q_section"
314 if {$inline} { error "do_show inline $addr" }
315 foreach s $q_section {
316 if {![string compare $s $shownsection]} continue
317 p "---------- $s ----------\n"
321 foreach s $q_symbol {
322 p_addr_symbol $addr $s
323 set shownss [concat $s]
325 #debug "shownss>$shownss<"
326 if {!$insection && ![string compare =SFRs= $shownsection]} {
332 if {![llength $q_symbol]} { p_addr_symbol $addr {} }
335 # p "------------------------------\n"
342 foreach v {q_section q_symbol} {
349 global insection section displine addr shownsection inline shownss
351 if {$insection && [string compare $section $shownsection]} {
353 set shownsection $section
355 } elseif {!$insection && [string length $shownsection]} {
360 if {[string length $sym]} {
361 if {$displine && $inline && !($displine&3)} {
368 set shownss $shownsection-$sym
372 set stkptr {panic: psave_stkptr}
373 set stack {panic: panic_stack}
376 foreach ss [list $stkptr $stack] { set ccontents($ss) {} }
378 while {$sectionnum < [llength $sections]} {
379 # So what happens at this address ?
381 set now_section [expr {$sectionchange - $addr}]
382 if {!$now_section && !$insection} {
383 queue_show section $section
385 set sectionchange $sectionend
388 if {!$now_section && $insection} {
391 set sectionchange $sectionaddr
395 set now_symbol [expr {$symboladdr - $addr}]
397 queue_show symbol $symbol
402 # OK, that's all the things that we need to say
405 # Decide how much to do:
407 if {$now > $now_section} { set now $now_section }
419 if {$nownow > $now_max} { set nownow $now_max }
420 set bytes [readbytes $addr $nownow]
422 set h [format "%02x" [expr {$b & 0xff}]]
424 if {[info exists ccontents($shownss)]} {
425 append ccontents($shownss) $h
436 proc stack_chkptr {si} {
438 if {$si == $stkptr+1} { p " - - - - -\n" }
441 foreach v {stkptr stack} {
442 #debug ">$v|[set $v]|$ccontents([set $v])<"
443 set $v $ccontents([set $v])
447 p "---------- =Execution Stack= ----------\n"
448 set stkptr [expr "0x$stkptr & $stackdepth"]
450 for {set si 1} {$si <= $stackdepth} {incr si} {
452 for {set ch 2; set se 0x} {$ch >= 0} {incr ch -1} {
453 append se [string range $stack \
454 [expr ($si-1)*6+$ch*2] [expr ($si-1)*6+$ch*2+1]]
456 set symaddr 0; set symsym (start)
457 foreach symi $symbolsbylockind(program) {
458 if {[lindex $symi 0] > $se} break
459 manyset $symi symaddr symsym
461 p [format " 0d%02d %6x = %6x + %s\n" $si $se \
462 [expr {$se-$symaddr}] [join $symsym]]
464 stack_chkptr [expr {$stackdepth+1}]
466 p "---------- ========== ----------\n"