# HG changeset patch # User lost@l-w.ca # Date 1314423884 21600 # Node ID 3b58d76ea0324f7c61b93af47b45d27ded9d295b # Parent 244f1227f2b576d722664745f1bf56c6af7b024c Fix up some minor thinkos in handling the module layout and header diff -r 244f1227f2b5 -r 3b58d76ea032 lwlink/output.c --- a/lwlink/output.c Fri Aug 26 23:36:13 2011 -0600 +++ b/lwlink/output.c Fri Aug 26 23:44:44 2011 -0600 @@ -244,6 +244,7 @@ int sn; int codedatasize = 0; int bsssize = 0; + int nameoff; int i; unsigned char buf[16]; @@ -265,7 +266,9 @@ // and codesize is the length of the module minus the module header // and CRC - codedatasize += 16; // add in headers + codedatasize += 13; // add in headers + nameoff = codedatasize; // we'll put the name at the end + codedatasize += 3; // add in CRC codedatasize += strlen(linkscript.name); // add in name length // output the file header @@ -273,8 +276,8 @@ buf[1] = 0xCD; buf[2] = (codedatasize >> 8) & 0xff; buf[3] = codedatasize & 0xff; - buf[4] = 0; - buf[5] = 13; + buf[4] = (nameoff >> 8) & 0xff; + buf[5] = nameoff & 0xff; buf[6] = (linkscript.modtype << 4) | (linkscript.modlang); buf[7] = (linkscript.modattr << 4) | (linkscript.modrev); buf[8] = (~(buf[0] ^ buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7])) & 0xff; @@ -304,16 +307,6 @@ writebytes(buf, 1, 13, of); - // output the name - for (i = 0; linkscript.name[i + 1]; i++) - { - writebytes(linkscript.name + i, 1, 1, of); - os9crc(crc, linkscript.name[i]); - } - buf[0] = linkscript.name[i] | 0x80; - writebytes(buf, 1, 1, of); - os9crc(crc, buf[0]); - // output the data // NOTE: disjoint load addresses will not work correctly!!!!! for (sn = 0; sn < nsects; sn++) @@ -328,6 +321,16 @@ os9crc(crc, sectlist[sn].ptr -> code[i]); } + // output the name + for (i = 0; linkscript.name[i + 1]; i++) + { + writebytes(linkscript.name + i, 1, 1, of); + os9crc(crc, linkscript.name[i]); + } + buf[0] = linkscript.name[i] | 0x80; + writebytes(buf, 1, 1, of); + os9crc(crc, buf[0]); + crc[0] ^= 0xff; crc[1] ^= 0xff; crc[2] ^= 0xff; diff -r 244f1227f2b5 -r 3b58d76ea032 lwlink/script.c --- a/lwlink/script.c Fri Aug 26 23:36:13 2011 -0600 +++ b/lwlink/script.c Fri Aug 26 23:44:44 2011 -0600 @@ -33,13 +33,15 @@ #include "lwlink.h" // the built-in OS9 script +// the 000D bit is to handle the module header! static char *os9_script = - "section code load 0000\n" + "section code load 000D\n" "section .text\n" "section data\n" "section .data\n" "section bss,bss load 0000\n" "section .bss,bss\n" + "entry __start\n" ; // the built-in DECB target linker script