/****************************************************************************** * Title : parseMap.c * Version 1.0 * * Description: Parse the entries in a TI DSP code mapping file to create a * list of routine locations and sizes. * * Douglas Ferguson LBNL/Univ. Wisconsin dpferguson@lbl.gov ******************************************************************************/ #include #include #include "genUtils.h" typedef unsigned int UINT32; typedef unsigned short UINT16; #define NSECT 20 int main(int argc, char *argv[]){ int status, nLines= 0, i, j; char found= false, foundPrev= false, iSect= 19, iPrev= 0, newSect; char sect[25], prevSect[3], badAddress; char inputFile[300], outputFile[300]; char origin[10], lenStr[10], used[10]; char line[100], out[100], word[50], str[50], address[50], object[50]; FILE *inFilePtr, *outFilePtr; char sectName[NSECT][20], sortChar; UINT32 addr, start, end, length; UINT32 nSect= 0, sectOrigin[NSECT], sectEnd[NSECT], sectLen[NSECT], foundSect; float totUsed[NSECT], percent; memset(inputFile, 0, 300); strcpy(inputFile,argv[1]); inFilePtr= fopen(inputFile, "r"); /* read-only */ if (inFilePtr == NULL) return(-1); memset(outputFile, 0, 300); strncpy(outputFile, inputFile, strlen(inputFile)-4); /* chop off .map */ strcat(outputFile, "_map.txt"); outFilePtr = fopen(outputFile, "w"); if (outFilePtr == NULL) return(-1); while (fgets(line, 100, inFilePtr)) { if (!found) { if (strstr(line, "GLOBAL SYMBOLS: SORTED BY Symbol Address")) ++found; else if ( (strstr(line, "FLASH")) ||(strstr(line, "IPRAM")) ||(strstr(line, "XPROG")) ||(strstr(line, "IDRAM")) ||(strstr(line, "IDATA")) ||(strstr(line, "IDREGS")) ||(strstr(line, "BURST")) ||(strstr(line, "MODULE")) ) { parse(line, sect, " \t\n\r"); parse(line, origin, " \t\n\r"); parse(line, lenStr, " \t\n\r"); parse(line, used, " \t\n\r"); start= getWord(origin, str, 16); end= getWord(used, str, 16); length= getWord(lenStr, str, 16); percent= 100.00*end/length; strcpy(sectName[nSect], sect); sectOrigin[nSect]= start; sectLen[nSect]= length; sectEnd[nSect]= end; totUsed[nSect++]= 0.0; strcpy(out, " "); strcat(out, sect); for (i= 0; i < (15 -strlen(sect)); ++i) strcat(out, " "); sprintf(word,"0x%s 0x%08x %7.4f\n", origin, end, percent); strcat(out, word); fputs(out, outFilePtr); ++nLines; } } else if (strstr(line, "symbols]")) break; else if ((found) && (found < 4)) { ++found; if (found == 3) { strcpy(out, ""); fputs("\n", outFilePtr); memset(sect, 0, 3); strcpy(prevSect, "00"); strcpy(word, "00000000"); nLines= 0; } } else if (!strstr(line, "cinit")) { parse(line, address, " \t\n\r"); parse(line, object, " \t\n\r"); //Do not process past the end of each code section: addr= getWord(address, str, 16); badAddress= ((addr >= 0x18000) && (addr < 0x30000)); badAddress|= ((addr >= 0x80008000) && (addr < 0x80010000)); badAddress|= ((addr >= 0x02080000) && (addr < 0x03000000)); badAddress|= (addr >= 0xa0040000); foundSect= 0; for (i= 0; i= sectOrigin[i]) && (addr < (sectOrigin[i] +sectLen[i]))) { foundSect= 1; break; } } if (!foundSect) { iPrev= iSect; //iSect= 19; newSect= true; } else if (i != iSect) { iPrev= iSect; iSect= i; newSect= true; } else newSect= false; if (newSect) { start= getWord(word, str, 16); if (foundPrev) end= sectOrigin[iPrev] +sectEnd[iPrev]; else end= start; } else { start= getWord(word, str, 16); end= getWord(address, str, 16); } foundPrev= foundSect; if (nLines > 0) { foundSect= 0; for (i= 0; i= sectOrigin[i]) && (start < (sectOrigin[i] +sectLen[i]))) { foundSect= 1; sortChar= '1'+i; break; } } if (foundSect) { percent= 100.00*(end -start)/sectLen[i]; totUsed[i]+= percent; } else { percent= 0.00; } strcat(out, " "); sprintf(str, "%c %06d 0x%05x %08.4f\n", sortChar, end -start, end -start, percent); strcat(out, str); if ( (start < 0x18000) ||((start >= 0x80000000)&&(start < 0x80008000)) ||((start >= 0x02000000)&&(start < 0x02080000)) ||((start >= 0xa0000000)&&(start < 0xa0040000)) ) fputs(out, outFilePtr); } if (object[0] == '_') leftShift(object, 1); strcpy(out, ""); if (newSect) strcat(out, "\n"); strcat(out, object); for (i= 0; i< (28 -strlen(object)); ++i) strcat(out, " "); sprintf(str, "0x%s", address); strcat(out, str); strcpy(word, address); ++nLines; } } //loop over lines in .map file fputs("\n\n Total & Calculated %%: \n", outFilePtr); for (i=0; i