chiark / gitweb /
improved mergehex detect clashes
authorian <ian>
Sun, 4 Dec 2005 21:53:05 +0000 (21:53 +0000)
committerian <ian>
Sun, 4 Dec 2005 21:53:05 +0000 (21:53 +0000)
cebpic/intelhex.pdf [new file with mode: 0644]
cebpic/manypics.make
cebpic/merge-hex
detpic/Makefile
detpic/pindata.inc
iwjpictest/Makefile
pic.make

diff --git a/cebpic/intelhex.pdf b/cebpic/intelhex.pdf
new file mode 100644 (file)
index 0000000..bc67eaf
Binary files /dev/null and b/cebpic/intelhex.pdf differ
index 6ad265ac3990ebfd29a6949cb00409d4409ad95b..badc8821665d2fc31ef25b47a120f9dff1f02a46 100644 (file)
@@ -1,6 +1,15 @@
 
 default: all
 
+#---------- general definitions etc. ----------
+
+TARGETS += $(foreach i, $(PICNOS), idlocs$i.hex noncode$i.hex)
+MORSE_INCLUDE ?= common.inc
+INCLUDES += ../iwjpictest/insn-aliases.inc morse+auto.inc
+
+include ../common.make
+include ../pic.make
+
 #---------- bizarre macro arrangements for $(PROGRAMS) ----------
 
 define define_prog
@@ -11,10 +20,10 @@ TARGETS += $$(foreach i, $$(PICNOS), $(1)+entire$$i.hex)
 $(1)_CODEHEX= $$(foreach panel, $$(XCODEN_$(1)), $(1)+$$(panel).hex) \
                $$(foreach panel, $$(XCODE1_$(1)), $$(panel).hex)
 
-$(1)+code.hex: $(1)+program.hex $$($(1)_CODEHEX)
+$(1)+code.hex: $$(HEXMERGER) $(1)+program.hex $$($(1)_CODEHEX)
                $$(MERGEHEX)
 
-$(1)+entire%.hex: $(1)+program.hex $$($(1)_CODEHEX) idlocs%.hex config.hex
+$(1)+entire%.hex: $$(HEXMERGER) $(1)+program.hex $$($(1)_CODEHEX) idlocs%.hex config.hex
                $$(MERGEHEX)
 
 $(1)+program.hex: $(1).o $$(OBJS_$(prog)) $$(LIBS)
@@ -24,7 +33,7 @@ endef
 
 define define_directasm
 
-$(1).hex:      $(1).asm
+$(1).hex:      $(1).asm $$(INCLUDES)
                $$(ASSEMBLE) $$<
 endef
 
@@ -53,20 +62,11 @@ blank0.asm blank2.asm blank4.asm blank6.asm: blank%.asm: $(CEBPIC)manypics.make
                echo >>$@.new " end"
                mv -f $@.new $@
 
-#---------- general definitions etc. ----------
-
-TARGETS += $(foreach i, $(PICNOS), idlocs$i.hex noncode$i.hex)
-MORSE_INCLUDE ?= common.inc
-INCLUDES += ../iwjpictest/insn-aliases.inc morse+auto.inc
-
-include ../common.make
-include ../pic.make
-
 #---------- targets ----------
 
 all: $(TARGETS)
 
-noncode%.hex:  idlocs%.hex config.hex
+noncode%.hex:  $(HEXMERGER) idlocs%.hex config.hex
                $(MERGEHEX)
 
 morse+auto.inc:        $(CEBPIC)morse-generator morse.messages
index 03df2d310dbe86d8133922b6382f9e33802351c9..6a17761c44c2fa35bb17ecec8a053fd3e9cfb6f5 100755 (executable)
@@ -1,10 +1,97 @@
-#!/usr/bin/perl
-$end= ':00000001FF';
+#!/usr/bin/perl -w
+# See http://www.precma.it/download/intelhex.pdf
+
+use strict qw(refs vars);
+
+our ($lba,$sba,$loc,$eof,%once);
+
+$lba=$sba=0;
+
+sub once {
+    my ($r) = @_;
+    my ($o);
+    $o= \$once{$_[0]};
+    if (!defined $$o) { $$o= $loc; return; }
+    die sprintf("%s: %s: clash at 0x%x (1st)\n".
+               "%s: %s: clash at 0x%x (2nd)\n",
+               $0, $$o, $r, $0, $loc, $r);
+}
+
+sub bad ($) { my ($m)=@_; die "$0: $loc: $m\n"; }
+
+my ($drlo,$dri,$orgline,$la);
+
 while (<>) {
-    chomp;
-    next if uc $_ eq $end;
-    print or die $!;
-    print "\n" or die $!;
+    $orgline= $_;
+    $loc= "$ARGV:$.";
+    
+    chomp; # General Record Format, p5
+    s/^\:// or bad('no colon');
+    $_= lc $_;
+    m/[^0-9a-f]/ and bad("bad char ".ord($&));
+    length() & 1 and bad('odd length');
+
+    s/..$//; # chop checksum (we don't check this)
+    s/^..//; # chop reclen (we don't check this)
+
+    if (s/^000001//) { # End of File, p11
+       $eof= $orgline;
+       if ($lba)    { $orgline= ":020000040000f8"; $lba=0; }
+       elsif ($sba) { $orgline= ":020000020000fc"; $sba=0; }
+       else { next; }
+    } elsif (s/^000004(....)$//) { $lba= hex($1)<<16; } # Ext'd Linear Addr, p6
+    elsif (s/^000002(....)$//) { $sba= hex($1)<<4; } # Ext'd Seg. Addr., p7
+    elsif (s/^(....)00//) { # Data Record, p8
+       $drlo= hex $1;
+       for ($dri=0; s/^..//; $dri++) {
+           bad('both LBA and SBA') if $lba && $sba;
+           if ($lba) { $la= ($lba+$drlo+$dri) & 0x0ffffffff; }
+           elsif ($sba) { $la= $sba + (($drlo+$dri) & 0xffff); }
+           else { $la= $drlo+$dri; }
+#print STDERR ">$lba|$sba|$drlo|$dri|$la|$_<\n";
+           once($la);
+       }
+    }
+    elsif (s/^000005//) { once('start'); } # Start Linear Address, p9
+    elsif (s/^000003//) { once('start'); } # Start Segment Address, p10
+    else {
+       bad('unknown record or bad record');
+    }
+    print $orgline or die $!;
+}
+
+our ($lx,$ld);
+
+$lx= 0;
+$ld= '';
+sub pf {
+    my ($f) = shift @_;
+    my ($s) = sprintf $f, @_;
+    if ($s =~ m/^\s/ && length($ld.$s) > 70) {
+       print STDERR $ld,"\n" or die $!; $ld= " ";
+    }
+    $ld.= $s;
+}
+sub pf_end () {
+    print STDERR $ld,"\n" or die $!;
+}
+
+my ($ca,$a1);
+undef $la;
+foreach $ca (sort { $a <=> $b } keys %once) {
+    next if defined($la) && $ca == ++$la;
+    defined($la) and
+       --$la != $a1 and
+           pf("-%x", $la);
+    pf("  %x", $ca);
+    $la=$a1=$ca;
+}
+if (!defined($la)) {
+    pf("  empty");
+} elsif ($la != $a1) {
+    pf("-%x", $la);
 }
-print $end or die $!;
-print "\n" or die $!;
+pf_end();
+
+die "$0: no input files or missing EOF markers\n" unless defined $eof;
+print $eof or die $!;
index e3c731d8008ff6fd993c01e204d7390872fa5276..6f005e3beab2519bfa6ef3de2070adde26c63cd8 100644 (file)
@@ -18,6 +18,7 @@ INCLUDES=     common.inc                      \
                routines-led.fin                \
                ../iwjpictest/clockvaries.inc   \
                vectors.fin                     \
+               pindata.inc                     \
                detect.inc
 
 VARSFILES=     variables
index 2ffce54f5078767a6d61d7c1952436fea4924d71..d0c85bab11eb1ddc393b52a2a1b7de82594722f3 100644 (file)
@@ -1,9 +1,9 @@
 ;======================================================================
 
-picno2ptmap            equ     0x6000
-bkptix2portnumbitnum   equ     0x6100
-pic2detinfo            equ     0x6200
-picno2revbits          equ     0x6300
+picno2ptmap            equ     0x6100
+bkptix2portnumbitnum   equ     0x6000
+pic2detinfo            equ     0x6040
+picno2revbits          equ     0x6080
 
 maxpic_ln2             equ     5
 maxpic                 equ     1 << maxpic_ln2
index 3b42caf8af6d9656ca297eacfa4ba44f4b813db8..8fb14ae4f2795cc4e99b3fab4fed6adaa49f3169 100644 (file)
@@ -20,7 +20,7 @@ all:          $(TARGETS) $(PROGRAM_HEXES)
 
 include ../pic.make
 
-%+withcfg.hex: %.hex config.hex
+%+withcfg.hex: $(HEXMERGER) %.hex config.hex
                $(MERGEHEX)
 
 %.hex:         %.o $(LIBS) $(DEFLIBS)
index fb3149d4914e9e18710ac38f05f04a6180c391b0..e407dfad9b47260ac2808464792ab7f7be1d241b 100644 (file)
--- a/pic.make
+++ b/pic.make
 #ASFLAGS=      -Dmclock=20000 -Dsclock=20000
 ASFLAGS=       -Dmclock=20000 -Dsclock=5000
 
+HEXMERGER=     $(CEBPIC)merge-hex
+MERGEHEX=      ./$^ $o
+
 LINK=          gplink -m -o $@ $^
 ASSEMBLE=      gpasm -p 18f458 $(ASFLAGS)
-MERGEHEX=      $(CEBPIC)merge-hex $^ $o
 DOASSEMBLE=    $(ASSEMBLE) -c $< && mv $*.lst $*-asm.lst
 
 %.o:           %.asm $(INCLUDES)