comparison lwlink/output.c @ 151:3b58d76ea032

Fix up some minor thinkos in handling the module layout and header
author lost@l-w.ca
date Fri, 26 Aug 2011 23:44:44 -0600
parents 08fb11004df9
children 11b710d231bd
comparison
equal deleted inserted replaced
150:244f1227f2b5 151:3b58d76ea032
242 void do_output_os9(FILE *of) 242 void do_output_os9(FILE *of)
243 { 243 {
244 int sn; 244 int sn;
245 int codedatasize = 0; 245 int codedatasize = 0;
246 int bsssize = 0; 246 int bsssize = 0;
247 int nameoff;
247 int i; 248 int i;
248 249
249 unsigned char buf[16]; 250 unsigned char buf[16];
250 unsigned char crc[3]; 251 unsigned char crc[3];
251 252
263 264
264 // now bss size is the data size for the module 265 // now bss size is the data size for the module
265 // and codesize is the length of the module minus the module header 266 // and codesize is the length of the module minus the module header
266 // and CRC 267 // and CRC
267 268
268 codedatasize += 16; // add in headers 269 codedatasize += 13; // add in headers
270 nameoff = codedatasize; // we'll put the name at the end
271 codedatasize += 3; // add in CRC
269 codedatasize += strlen(linkscript.name); // add in name length 272 codedatasize += strlen(linkscript.name); // add in name length
270 273
271 // output the file header 274 // output the file header
272 buf[0] = 0x87; 275 buf[0] = 0x87;
273 buf[1] = 0xCD; 276 buf[1] = 0xCD;
274 buf[2] = (codedatasize >> 8) & 0xff; 277 buf[2] = (codedatasize >> 8) & 0xff;
275 buf[3] = codedatasize & 0xff; 278 buf[3] = codedatasize & 0xff;
276 buf[4] = 0; 279 buf[4] = (nameoff >> 8) & 0xff;
277 buf[5] = 13; 280 buf[5] = nameoff & 0xff;
278 buf[6] = (linkscript.modtype << 4) | (linkscript.modlang); 281 buf[6] = (linkscript.modtype << 4) | (linkscript.modlang);
279 buf[7] = (linkscript.modattr << 4) | (linkscript.modrev); 282 buf[7] = (linkscript.modattr << 4) | (linkscript.modrev);
280 buf[8] = (~(buf[0] ^ buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7])) & 0xff; 283 buf[8] = (~(buf[0] ^ buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7])) & 0xff;
281 buf[9] = (linkscript.execaddr >> 8) & 0xff; 284 buf[9] = (linkscript.execaddr >> 8) & 0xff;
282 buf[10] = linkscript.execaddr & 0xff; 285 buf[10] = linkscript.execaddr & 0xff;
302 os9crc(crc, buf[12]); 305 os9crc(crc, buf[12]);
303 306
304 307
305 writebytes(buf, 1, 13, of); 308 writebytes(buf, 1, 13, of);
306 309
310 // output the data
311 // NOTE: disjoint load addresses will not work correctly!!!!!
312 for (sn = 0; sn < nsects; sn++)
313 {
314 if (sectlist[sn].ptr -> flags & SECTION_BSS)
315 {
316 // no output for a BSS section
317 continue;
318 }
319 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
320 for (i = 0; i < sectlist[sn].ptr -> codesize; i++)
321 os9crc(crc, sectlist[sn].ptr -> code[i]);
322 }
323
307 // output the name 324 // output the name
308 for (i = 0; linkscript.name[i + 1]; i++) 325 for (i = 0; linkscript.name[i + 1]; i++)
309 { 326 {
310 writebytes(linkscript.name + i, 1, 1, of); 327 writebytes(linkscript.name + i, 1, 1, of);
311 os9crc(crc, linkscript.name[i]); 328 os9crc(crc, linkscript.name[i]);
312 } 329 }
313 buf[0] = linkscript.name[i] | 0x80; 330 buf[0] = linkscript.name[i] | 0x80;
314 writebytes(buf, 1, 1, of); 331 writebytes(buf, 1, 1, of);
315 os9crc(crc, buf[0]); 332 os9crc(crc, buf[0]);
316
317 // output the data
318 // NOTE: disjoint load addresses will not work correctly!!!!!
319 for (sn = 0; sn < nsects; sn++)
320 {
321 if (sectlist[sn].ptr -> flags & SECTION_BSS)
322 {
323 // no output for a BSS section
324 continue;
325 }
326 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
327 for (i = 0; i < sectlist[sn].ptr -> codesize; i++)
328 os9crc(crc, sectlist[sn].ptr -> code[i]);
329 }
330 333
331 crc[0] ^= 0xff; 334 crc[0] ^= 0xff;
332 crc[1] ^= 0xff; 335 crc[1] ^= 0xff;
333 crc[2] ^= 0xff; 336 crc[2] ^= 0xff;
334 writebytes(crc, 1, 3, of); 337 writebytes(crc, 1, 3, of);