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 -nonewline $p [format %c $b]
140 xmit [expr {$b | 0x80}]
141 xmit [expr {$slave ^ 0x30}]
144 proc setup_m {} { xmit 0 }
145 proc setup_s {} { xmit 0; xmit_s 0 }
148 proc selectaddr_m {a} { error }
149 proc selectaddr_s {a} { error }
150 proc selectaddr_t {a} { global tsa; set tsa $a }
152 proc readbytes_m {n} { error }
153 proc readbytes_s {n} { error }
154 proc readbytes_t {n} {
158 lappend l [expr {$tsa - ($tsa >> 8)}]
167 proc readbytes {addr n} {
169 if {$readcursor != $addr} {
170 if {$addr & ~0x0fff} { error "bad addr $addr" }
171 if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" }
173 set readcursor [expr {$addr + $n}]
175 return [readbytes_$ms $n]
178 proc thingbynum {thing nnum} {
179 upvar #0 ${thing}num num
180 upvar #0 ${thing}s things
181 upvar #0 ${thing}info info
182 upvar #0 ${thing}addr addr
183 upvar #0 ${thing} name
185 if {$num < [llength $things]} {
186 set info [lindex $things $num]
188 set info {0x7fffffff =DUMMY-END= 1}
190 manyset $info addr name
191 if {![string compare $thing section]} {
192 global sectionsize sectionend
193 set sectionsize [lindex $info 2]
194 set sectionend [expr {$addr + $sectionsize}]
198 proc thingnext {thing} {
199 upvar #0 ${thing}num num
201 thingbynum $thing $num
217 global inline displine
218 if {$inline} { puts -nonewline "\n"; incr displine }
223 global insection section displine addr shownsection inline
224 if {$insection && [string compare $section $shownsection]} {
226 puts "---------- $section ----------"
227 set shownsection $section
229 } elseif {!$insection && [string length $shownsection]} {
231 puts "------------------------------"
235 if {[string length $sym]} {
236 if {$displine && $inline && !($displine&3)} {
242 puts -nonewline [format "%08x %-15s %-20s" $addr \
243 [lindex $sym 0] [lindex $sym 1]]
248 while {$sectionnum < [llength $sections]} {
249 set now_section [expr {$sectionchange - $addr}]
250 if {!$now_section && !$insection} {
252 set sectionchange $sectionend
255 set now_symbol [expr {$symboladdr - $addr}]
261 if {!$now_section && $insection} {
262 if {[string compare $section =SFRs=]} {
267 set sectionchange $sectionaddr
270 if {$now > $now_section} { set now $now_section }
275 if {$now > $now_max} { set now $now_max }
277 set bytes [readbytes $addr $now]
279 puts -nonewline [format " %02x" [expr {$b & 0xff}]]