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 manyset {list args} {
14 foreach val $list var $args { upvar 1 $var my; set my $val }
17 proc inblk {bre hre} {
18 global inblk block headings
21 [regexp $bre $block] &&
22 [regexp $hre $headings]
26 proc wantlockind {lockind thing l} {
27 switch -exact $lockind program { return -1 } data { return 1 } \
28 default { error "unknown $thing lockind $lockind in $l" }
31 while {[gets $m l] >= 0} {
32 if {![regexp {\S} $l]} {
36 } elseif {$inblk==0 && [regexp {^\s+(\S.*\S)\s*$} $l dummy block]} {
38 } elseif {$inblk==1} {
39 set headings [string trim $l]
41 } elseif {$inblk==2 && [regexp {^[- \t]+$} $l]} {
43 } elseif {[inblk {^Section Info$} \
44 {^Section\s+Type\s+Address\s+Location\s+Size\(Bytes\)$}]} {
45 manyset $l sec type addr lockind size
46 switch -exact $type code { continue } udata { } \
47 default { error "unknown section type $type in $l" }
48 if {[wantlockind $lockind section $l]<=0} continue
49 set addr [format 0x%08x $addr]
50 lappend sections [list $addr $sec [format 0x%08x $size]]
51 } elseif {[inblk {^Symbols$} \
52 {^Name\s+Address\s+Location\s+Storage\s+File$}]} {
53 manyset $l sym addr lockind storage file
54 if {![wantlockind $lockind symbol $l]} continue
55 switch -exact $storage {
56 extern { set sym [list {} $sym] }
58 regexp {^(.*)\.asm$} $file dummy file
59 set sym [list $file: $sym]
61 default { error "unknown storage $storage in $l" }
63 set addr [format 0x%08x $addr]
64 if {[string compare $lockind data]} {
65 set sv symbolsbylockind($lockind)
69 lappend $sv [list $addr $sym]
70 } elseif {$inblk==3} {
72 error "unknown $inblk <$block> <$headings> $l"
78 OSCCON LVDCON WDTCON RCON
80 SSPADD SSPSTAT SSPCON1 SSPCON2
83 ECCPR1* ECCP1DEL ECCPAS
91 set h [open /usr/share/gputils/header/p18f458.inc]
94 while {[gets $h l]>=0} {
95 if {[regexp {^\;\-\-+\s+(\S.*\S)\s+\-\-+$} $l dummy section]} {
97 } elseif {![regexp {^Register Files$} $section]} {
99 } elseif {[regexp -nocase \
100 {^([a-z][a-z0-9]*)\s+equ\s+h\'0(f[0-9a-f]{2})\'\s*$} \
102 set addr [format 0x%08x 0x$loc]
104 if {[string match $pat $sym]} {
105 if {$addr != $lastaddr} {
106 lappend sections [list $addr =SFRs= 0x1]
109 lappend symbols [list $addr [list SFR $sym]]
112 } elseif {[regexp -nocase {^\;\s*reserved} $l]} {
113 } elseif {![regexp {\S} $l]} {
115 error "unknown <$section> $l"
119 lappend sections [list 0x1000 =END= 0]
120 set sections [lsort $sections]
121 set symbols [lsort $symbols]
123 set p [open $port {RDWR NONBLOCK} 0]
124 exec stty -F $port min 1 time 0 -istrip -ocrnl -onlcr -onocr -opost \
125 -ctlecho -echo -echoe -echok -echonl -iexten -isig \
127 9600 clocal cread -crtscts -hup -parenb cs8 -cstopb \
128 -ixoff bs0 cr0 ff0 nl0 -ofill -olcuc
130 fconfigure $p -blocking yes -buffering none \
131 -translation binary -encoding binary
141 #puts stderr >xmit|$b<
143 set c [binary format c* $b]
144 puts -nonewline $p [format %c $b]
152 if {![llength $d]} { error "comms eof" }
159 proc selectslave_s {} {
170 proc setup_m {} { xmit 0 }
171 proc setup_s {} { xmit 0; xmit_s 0 }
174 proc selectaddr_ms {xmit a} {
175 $xmit "($a >> 6) | 0x40"
176 $xmit "($a & 0x3c) | 0x40"
178 proc selectaddr_m {a} { selectaddr_ms xmit $a }
179 proc selectaddr_s {a} { selectaddr_ms xmit_s $a }
180 proc selectaddr_t {a} { global tsa; set tsa $a }
182 proc readbytes_m {n} {
186 proc readbytes_s {n} {
192 proc readbytes_t {n} {
196 lappend l [expr {$tsa - ($tsa >> 8)}]
205 proc readbytes {addr n} {
207 if {$readcursor != $addr} {
208 if {$addr & ~0x0fff} { error "bad addr $addr" }
209 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
212 set r [readbytes_$ms $n]
213 set readcursor [expr {$addr + $n}]
217 proc thingbynum {thing nnum} {
218 upvar #0 ${thing}num num
219 upvar #0 ${thing}s things
220 upvar #0 ${thing}info info
221 upvar #0 ${thing}addr addr
222 upvar #0 ${thing} name
224 if {$num < [llength $things]} {
225 set info [lindex $things $num]
227 set info {0x7fffffff =DUMMY-END= 1}
229 manyset $info addr name
230 if {![string compare $thing section]} {
231 global sectionsize sectionend
232 set sectionsize [lindex $info 2]
233 set sectionend [expr {$addr + $sectionsize}]
237 proc thingnext {thing} {
238 upvar #0 ${thing}num num
240 thingbynum $thing $num
253 proc p {s} { puts -nonewline $s }
258 global inline displine
259 if {$inline} { p "\n"; incr displine }
264 global insection section displine addr shownsection inline shownss
266 if {$insection && [string compare $section $shownsection]} {
268 p "---------- $section ----------\n"
269 set shownsection $section
271 } elseif {!$insection && [string length $shownsection]} {
273 p "------------------------------\n"
277 if {[string length $sym]} {
278 if {$displine && $inline && !($displine&3)} {
284 p [format "%08x %-15s %-20s" $addr \
285 [lindex $sym 0] [lindex $sym 1]]
287 set shownss $shownsection-$sym
291 set stkptr {panic_vars_section-panic: psave_stkptr}
292 set stack {panic_vars_section-panic: panic_stack}
294 foreach ss [list $stkptr $stack] { set ccontents($ss) {} }
296 while {$sectionnum < [llength $sections]} {
297 set now_section [expr {$sectionchange - $addr}]
298 set now_symbol [expr {$symboladdr - $addr}]
299 if {!$now_section && !$insection} {
301 set sectionchange $sectionend
309 if {!$now_section && $insection} {
310 if {[string compare $section =SFRs=]} {
315 set sectionchange $sectionaddr
318 if {$now > $now_section} { set now $now_section }
323 if {$now > $now_max} { set now $now_max }
325 set bytes [readbytes $addr $now]
327 set h [format "%02x" [expr {$b & 0xff}]]
329 if {[info exists ccontents($shownss)]} {
330 append ccontents($shownss) $h
340 proc stack_chkptr {si} {
342 if {$si == $stkptr+1} { p " - - - - -\n" }
345 foreach v {stkptr stack} { set $v $ccontents([set $v]) }
347 p "\n---------- =Execution Stack= ----------\n"
348 set stkptr [expr "0x$stkptr & $stackdepth"]
350 for {set si 1} {$si <= $stackdepth} {incr si} {
352 for {set ch 2; set se 0x} {$ch >= 0} {incr ch -1} {
353 append se [string range $stack \
354 [expr ($si-1)*6+$ch*2] [expr ($si-1)*6+$ch*2+1]]
357 foreach symi $symbolsbylockind(program) {
358 if {[lindex $symi 0] > $se} break
360 manyset $symi symaddr symsym
361 p [format " 0d%02d %6x = %6x + %s\n" $si $se \
362 [expr {$se-$symaddr}] $symsym]
364 stack_chkptr [expr {$stackdepth+1}]
366 p "---------- ========== ----------\n"