Mercurial > hg > index.cgi
diff lwlink/output.c @ 548:cde1a5a48636
Add IHEX output format to lwlink
At the request of Craig Iannello who provided a small bribe, IHEX output
format is now available in lwlink. At least a first pass version of it.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 16 Mar 2023 16:59:50 -0600 |
parents | 1744f2d1a821 |
children |
line wrap: on
line diff
--- a/lwlink/output.c Thu Mar 16 16:18:13 2023 -0600 +++ b/lwlink/output.c Thu Mar 16 16:59:50 2023 -0600 @@ -39,6 +39,7 @@ void do_output_raw2(FILE *of); void do_output_lwex0(FILE *of); void do_output_srec(FILE *of); +void do_output_ihex(FILE *of); void do_output(void) { @@ -77,6 +78,10 @@ case OUTPUT_SREC: do_output_srec(of); break; + + case OUTPUT_IHEX: + do_output_ihex(of); + break; default: fprintf(stderr, "Unknown output format doing output!\n"); @@ -241,6 +246,58 @@ fprintf(of,"S903%04X%02X\r\n",linkscript.execaddr,(unsigned char)(~recsum)); } +void do_output_ihex(FILE *of) +{ + const int IRECLEN = 16; + + int sn; + int remainingcodebytes; + + int codeaddr; + int i; + int recaddr = 0; + int recdlen = 0; + int recsum; + int reccnt = -1; + unsigned char* sectcode; + // no header yet; unnecessary + + for (sn = 0; sn < nsects; sn++) // check all sections + { + if (sectlist[sn].ptr -> flags & SECTION_BSS) // ignore BSS sections + continue; + if (sectlist[sn].ptr -> codesize == 0) // ignore empty sections + continue; + + recaddr = sectlist[sn].ptr -> loadaddress; + remainingcodebytes = sectlist[sn].ptr -> codesize; + sectcode = sectlist[sn].ptr -> code; + + while (remainingcodebytes) + { + recdlen = (IRECLEN>remainingcodebytes)?remainingcodebytes:IRECLEN; + recsum = recdlen; + codeaddr = recaddr - sectlist[sn].ptr -> loadaddress; + fprintf(of, ":%02X%04X00", recdlen, recaddr & 0xffff); + for (i = 0; i < recdlen; i++) + { + fprintf(of, "%02X", sectcode[codeaddr+i]); + recsum += sectcode[codeaddr+i]; + } + recsum += (recaddr >> 8) & 0xFF; + recsum += recaddr & 0xFF; + fprintf(of, "%02X\r\n", (unsigned char)(256 - recsum)); + reccnt += 1; + remainingcodebytes -= recdlen; + recaddr += recdlen; + } + } + if (reccnt > 0) + { + fprintf(of, ":00%04X01FF\r\n", linkscript.execaddr); + } +} + void do_output_lwex0(FILE *of) { int nskips = 0; // used to output blanks for BSS inline