changeset 183:302b8db5fd89

modified lwlink to merge contiguous sections in the DECB output file to avoid the explosion of preambles
author lost
date Sat, 21 Mar 2009 17:03:42 +0000
parents 833d392fec82
children 220a760ec654
files ChangeLog lwlink/output.c
diffstat 2 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 06 01:35:40 2009 +0000
+++ b/ChangeLog	Sat Mar 21 17:03:42 2009 +0000
@@ -7,6 +7,7 @@
 [+] new feature
 [-] feature removed
 [b] minor bugfix
+[ ] general improvement
 
 Also, the software affected may follow in [].
 
@@ -17,6 +18,10 @@
     LWLINK (they get prepended to the built in link script)
 [b] arranged for output files for lwasm/lwlink to be removed if the assembly
     or linking fails
+[ ] DECB output of LWLINK now collapses contiguous output blocks into single
+    single blocks in the output file; this eliminates the explosion of
+    preambles that previously occurred
+
 
 Version 2.2
 
--- a/lwlink/output.c	Fri Mar 06 01:35:40 2009 +0000
+++ b/lwlink/output.c	Sat Mar 21 17:03:42 2009 +0000
@@ -70,7 +70,8 @@
 
 void do_output_decb(FILE *of)
 {
-	int sn;
+	int sn, sn2;
+	int cloc, olen;
 	unsigned char buf[5];
 	
 	for (sn = 0; sn < nsects; sn++)
@@ -85,14 +86,40 @@
 			// don't generate output for a zero size section
 			continue;
 		}
+		
+		// calculate the length of this output block
+		cloc = sectlist[sn].ptr -> loadaddress;
+		olen = 0;
+		for (sn2 = sn; sn2 < nsects; sn2++)
+		{
+			// ignore BSS sections
+			if (sectlist[sn2].ptr -> flags & SECTION_BSS)
+				continue;
+			// ignore zero length sections
+			if (sectlist[sn2].ptr -> codesize == 0)
+				continue;
+			if (cloc != sectlist[sn2].ptr -> loadaddress)
+				break;
+			olen += sectlist[sn2].ptr -> codesize;
+			cloc += sectlist[sn2].ptr -> codesize;
+		}
+		
 		// write a preamble
 		buf[0] = 0x00;
-		buf[1] = sectlist[sn].ptr -> codesize >> 8;
-		buf[2] = sectlist[sn].ptr -> codesize & 0xff;
+		buf[1] = olen >> 8;
+		buf[2] = olen & 0xff;
 		buf[3] = sectlist[sn].ptr -> loadaddress >> 8;
 		buf[4] = sectlist[sn].ptr -> loadaddress & 0xff;
 		writebytes(buf, 1, 5, of);
-		writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
+		for (; sn < sn2; sn++)
+		{
+			if (sectlist[sn].ptr -> flags & SECTION_BSS)
+				continue;
+			if (sectlist[sn].ptr -> codesize == 0)
+				continue;
+			writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
+		}
+		sn--;
 	}
 	// write a postamble
 	buf[0] = 0xff;