comparison lwlink/output.c @ 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 106c2fe3c9d9
children 857cb407229e
comparison
equal deleted inserted replaced
182:833d392fec82 183:302b8db5fd89
68 fclose(of); 68 fclose(of);
69 } 69 }
70 70
71 void do_output_decb(FILE *of) 71 void do_output_decb(FILE *of)
72 { 72 {
73 int sn; 73 int sn, sn2;
74 int cloc, olen;
74 unsigned char buf[5]; 75 unsigned char buf[5];
75 76
76 for (sn = 0; sn < nsects; sn++) 77 for (sn = 0; sn < nsects; sn++)
77 { 78 {
78 if (sectlist[sn].ptr -> flags & SECTION_BSS) 79 if (sectlist[sn].ptr -> flags & SECTION_BSS)
83 if (sectlist[sn].ptr -> codesize == 0) 84 if (sectlist[sn].ptr -> codesize == 0)
84 { 85 {
85 // don't generate output for a zero size section 86 // don't generate output for a zero size section
86 continue; 87 continue;
87 } 88 }
89
90 // calculate the length of this output block
91 cloc = sectlist[sn].ptr -> loadaddress;
92 olen = 0;
93 for (sn2 = sn; sn2 < nsects; sn2++)
94 {
95 // ignore BSS sections
96 if (sectlist[sn2].ptr -> flags & SECTION_BSS)
97 continue;
98 // ignore zero length sections
99 if (sectlist[sn2].ptr -> codesize == 0)
100 continue;
101 if (cloc != sectlist[sn2].ptr -> loadaddress)
102 break;
103 olen += sectlist[sn2].ptr -> codesize;
104 cloc += sectlist[sn2].ptr -> codesize;
105 }
106
88 // write a preamble 107 // write a preamble
89 buf[0] = 0x00; 108 buf[0] = 0x00;
90 buf[1] = sectlist[sn].ptr -> codesize >> 8; 109 buf[1] = olen >> 8;
91 buf[2] = sectlist[sn].ptr -> codesize & 0xff; 110 buf[2] = olen & 0xff;
92 buf[3] = sectlist[sn].ptr -> loadaddress >> 8; 111 buf[3] = sectlist[sn].ptr -> loadaddress >> 8;
93 buf[4] = sectlist[sn].ptr -> loadaddress & 0xff; 112 buf[4] = sectlist[sn].ptr -> loadaddress & 0xff;
94 writebytes(buf, 1, 5, of); 113 writebytes(buf, 1, 5, of);
95 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of); 114 for (; sn < sn2; sn++)
115 {
116 if (sectlist[sn].ptr -> flags & SECTION_BSS)
117 continue;
118 if (sectlist[sn].ptr -> codesize == 0)
119 continue;
120 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
121 }
122 sn--;
96 } 123 }
97 // write a postamble 124 // write a postamble
98 buf[0] = 0xff; 125 buf[0] = 0xff;
99 buf[1] = 0x00; 126 buf[1] = 0x00;
100 buf[2] = 0x00; 127 buf[2] = 0x00;