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 0 } 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]} 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 lappend symbols [list $addr $sym]
65 } elseif {$inblk==3} {
67 error "unknown $inblk <$block> <$headings> $l"
73 OSCCON LVDCON WDTCON RCON
75 SSPADD SSPSTAT SSPCON1 SSPCON2
78 ECCPR1* ECCP1DEL ECCPAS
86 set h [open /usr/share/gputils/header/p18f458.inc]
89 while {[gets $h l]>=0} {
90 if {[regexp {^\;\-\-+\s+(\S.*\S)\s+\-\-+$} $l dummy section]} {
92 } elseif {![regexp {^Register Files$} $section]} {
94 } elseif {[regexp -nocase \
95 {^([a-z][a-z0-9]*)\s+equ\s+h\'0(f[0-9a-f]{2})\'\s*$} \
97 set addr [format 0x%08x 0x$loc]
99 if {[string match $pat $sym]} {
100 if {$addr != $lastaddr} {
101 lappend sections [list $addr =SFRs= 0x1]
104 lappend symbols [list $addr [list SFR $sym]]
107 } elseif {[regexp -nocase {^\;\s*reserved} $l]} {
108 } elseif {![regexp {\S} $l]} {
110 error "unknown <$section> $l"
114 lappend sections [list 0x1000 =END= 0]
115 set sections [lsort $sections]
116 set symbols [lsort $symbols]
118 set p [open $port {RDWR NONBLOCK} 0]
119 exec stty -F $port min 1 time 0 -istrip -ocrnl -onlcr -onocr -opost \
120 -ctlecho -echo -echoe -echok -echonl -iexten -isig \
122 9600 clocal cread -crtscts -hup -parenb cs8 -cstopb \
123 -ixoff bs0 cr0 ff0 nl0 -ofill -olcuc
125 fconfigure $p -blocking yes -buffering none \
126 -translation binary -encoding binary
136 #puts stderr >xmit|$b<
138 set c [binary format c* $b]
139 puts -nonewline $p [format %c $b]
147 if {![llength $d]} { error "comms eof" }
154 proc selectslave_s {} {
165 proc setup_m {} { xmit 0 }
166 proc setup_s {} { xmit 0; xmit_s 0 }
169 proc selectaddr_ms {xmit a} {
170 $xmit "($a >> 6) | 0x40"
171 $xmit "($a & 0x3c) | 0x40"
173 proc selectaddr_m {a} { selectaddr_ms xmit $a }
174 proc selectaddr_s {a} { selectaddr_ms xmit_s $a }
175 proc selectaddr_t {a} { global tsa; set tsa $a }
177 proc readbytes_m {n} {
181 proc readbytes_s {n} {
187 proc readbytes_t {n} {
191 lappend l [expr {$tsa - ($tsa >> 8)}]
200 proc readbytes {addr n} {
202 if {$readcursor != $addr} {
203 if {$addr & ~0x0fff} { error "bad addr $addr" }
204 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
207 set r [readbytes_$ms $n]
208 set readcursor [expr {$addr + $n}]
212 proc thingbynum {thing nnum} {
213 upvar #0 ${thing}num num
214 upvar #0 ${thing}s things
215 upvar #0 ${thing}info info
216 upvar #0 ${thing}addr addr
217 upvar #0 ${thing} name
219 if {$num < [llength $things]} {
220 set info [lindex $things $num]
222 set info {0x7fffffff =DUMMY-END= 1}
224 manyset $info addr name
225 if {![string compare $thing section]} {
226 global sectionsize sectionend
227 set sectionsize [lindex $info 2]
228 set sectionend [expr {$addr + $sectionsize}]
232 proc thingnext {thing} {
233 upvar #0 ${thing}num num
235 thingbynum $thing $num
248 proc p {s} { puts -nonewline $s }
253 global inline displine
254 if {$inline} { p "\n"; incr displine }
259 global insection section displine addr shownsection inline
260 if {$insection && [string compare $section $shownsection]} {
262 p "---------- $section ----------\n"
263 set shownsection $section
265 } elseif {!$insection && [string length $shownsection]} {
267 p "------------------------------\n"
271 if {[string length $sym]} {
272 if {$displine && $inline && !($displine&3)} {
278 p [format "%08x %-15s %-20s" $addr \
279 [lindex $sym 0] [lindex $sym 1]]
284 while {$sectionnum < [llength $sections]} {
285 set now_section [expr {$sectionchange - $addr}]
286 if {!$now_section && !$insection} {
288 set sectionchange $sectionend
291 set now_symbol [expr {$symboladdr - $addr}]
297 if {!$now_section && $insection} {
298 if {[string compare $section =SFRs=]} {
303 set sectionchange $sectionaddr
306 if {$now > $now_section} { set now $now_section }
311 if {$now > $now_max} { set now $now_max }
313 set bytes [readbytes $addr $now]
315 p [format " %02x" [expr {$b & 0xff}]]