Mercurial > hg-old > index.cgi
comparison lwlink/output.c @ 252:4dc2a10997a6 2.x
Fixed LWEX binary output when BSS size > 0
author | lost |
---|---|
date | Sat, 28 Nov 2009 04:46:09 +0000 |
parents | bae1e3ecdce1 |
children |
comparison
equal
deleted
inserted
replaced
251:f6af5791472c | 252:4dc2a10997a6 |
---|---|
160 void do_output_lwex0(FILE *of) | 160 void do_output_lwex0(FILE *of) |
161 { | 161 { |
162 int nskips = 0; // used to output blanks for BSS inline | 162 int nskips = 0; // used to output blanks for BSS inline |
163 int sn; | 163 int sn; |
164 int codedatasize = 0; | 164 int codedatasize = 0; |
165 int coffs; | |
165 unsigned char buf[32]; | 166 unsigned char buf[32]; |
166 | 167 int fsize = 0; |
168 | |
167 // calculate items for the file header | 169 // calculate items for the file header |
168 for (sn = 0; sn < nsects; sn++) | 170 for (sn = 0; sn < nsects; sn++) |
169 { | 171 { |
172 // fprintf(stderr, "Counting: %s (%s) at %04X (%04X bytes), calc total = %04X\n", sectlist[sn].ptr -> name, sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> loadaddress, sectlist[sn].ptr -> codesize, codedatasize); | |
170 if (sectlist[sn].ptr -> flags & SECTION_BSS) | 173 if (sectlist[sn].ptr -> flags & SECTION_BSS) |
171 { | 174 { |
172 // no output for a BSS section | 175 // no output for a BSS section |
173 nskips += sectlist[sn].ptr -> codesize; | 176 nskips += sectlist[sn].ptr -> codesize; |
174 continue; | 177 continue; |
192 buf[10] = codedatasize / 256; | 195 buf[10] = codedatasize / 256; |
193 buf[11] = codedatasize & 0xff; | 196 buf[11] = codedatasize & 0xff; |
194 buf[12] = linkscript.execaddr / 256; | 197 buf[12] = linkscript.execaddr / 256; |
195 buf[13] = linkscript.execaddr & 0xff; | 198 buf[13] = linkscript.execaddr & 0xff; |
196 memset(buf + 14, 0, 18); | 199 memset(buf + 14, 0, 18); |
200 | |
201 // fprintf(stderr, "Exec addr %04X, stacksize %04X, codesize %04X, bss size %04X\n", linkscript.execaddr, linkscript.stacksize, codedatasize, nskips); | |
197 | 202 |
198 writebytes(buf, 1, 32, of); | 203 writebytes(buf, 1, 32, of); |
204 fsize = 32; | |
205 coffs = 0x100; | |
206 nskips = 0; | |
199 // output the data | 207 // output the data |
200 // NOTE: disjoint load addresses will not work correctly!!!!! | 208 // NOTE: disjoint load addresses will not work correctly!!!!! |
201 for (sn = 0; sn < nsects; sn++) | 209 for (sn = 0; sn < nsects; sn++) |
202 { | 210 { |
211 // fprintf(stderr, "Outputting: %s (%s) at %04X (%04X bytes), calc offset = %04X, file offset = %04X\n", sectlist[sn].ptr -> name, sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> loadaddress, sectlist[sn].ptr -> codesize, coffs, fsize); | |
203 if (sectlist[sn].ptr -> flags & SECTION_BSS) | 212 if (sectlist[sn].ptr -> flags & SECTION_BSS) |
204 { | 213 { |
205 // no output for a BSS section | 214 // no output for a BSS section |
206 nskips += sectlist[sn].ptr -> codesize; | 215 nskips += sectlist[sn].ptr -> codesize; |
216 coffs += sectlist[sn].ptr -> codesize; | |
207 continue; | 217 continue; |
208 } | 218 } |
209 while (nskips > 0) | 219 while (nskips > 0) |
210 { | 220 { |
211 // the "" is not an error - it turns into a single NUL byte! | 221 // the "" is not an error - it turns into a single NUL byte! |
212 writebytes("", 1, 1, of); | 222 writebytes("", 1, 1, of); |
213 nskips--; | 223 nskips--; |
224 fsize += 1; | |
214 } | 225 } |
215 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of); | 226 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of); |
216 } | 227 coffs += sectlist[sn].ptr -> codesize; |
217 } | 228 fsize += sectlist[sn].ptr -> codesize; |
229 } | |
230 } |