📄 loadecofflib.c
字号:
sizeof(pScnHdr->s_nreloc)); swab ((char *) &pScnHdr->s_nlnno, (char *) &tempScnHdr.s_nlnno, sizeof(pScnHdr->s_nlnno)); swabLong ((char *) &pScnHdr->s_flags, (char *) &tempScnHdr.s_flags); bcopy ((char *) &tempScnHdr, (char *) pScnHdr, sizeof(SCNHDR)); }/********************************************************************************* swapCoffsymHdr - swap endianess of COFF symbolic header* */LOCAL void swapCoffsymHdr ( HDRR *pSymHdr /* module's ECOFF symbolic header */ ) { HDRR tempSymHdr; swab ((char *) &pSymHdr->magic, (char *) &tempSymHdr.magic, sizeof(pSymHdr->magic)); swab ((char *) &pSymHdr->vstamp, (char *) &tempSymHdr.vstamp, sizeof(pSymHdr->vstamp)); swabLong ((char *) &pSymHdr->ilineMax, (char *) &tempSymHdr.ilineMax); swabLong ((char *) &pSymHdr->cbLine, (char *) &tempSymHdr.cbLine); swabLong ((char *) &pSymHdr->cbLineOffset, (char *) &tempSymHdr.cbLineOffset); swabLong ((char *) &pSymHdr->idnMax, (char *) &tempSymHdr.idnMax); swabLong ((char *) &pSymHdr->cbDnOffset, (char *) &tempSymHdr.cbDnOffset); swabLong ((char *) &pSymHdr->ipdMax, (char *) &tempSymHdr.ipdMax); swabLong ((char *) &pSymHdr->cbPdOffset, (char *) &tempSymHdr.cbPdOffset); swabLong ((char *) &pSymHdr->isymMax, (char *) &tempSymHdr.isymMax); swabLong ((char *) &pSymHdr->cbSymOffset, (char *) &tempSymHdr.cbSymOffset); swabLong ((char *) &pSymHdr->ioptMax, (char *) &tempSymHdr.ioptMax); swabLong ((char *) &pSymHdr->cbOptOffset, (char *) &tempSymHdr.cbOptOffset); swabLong ((char *) &pSymHdr->iauxMax, (char *) &tempSymHdr.iauxMax); swabLong ((char *) &pSymHdr->cbAuxOffset, (char *) &tempSymHdr.cbAuxOffset); swabLong ((char *) &pSymHdr->issMax, (char *) &tempSymHdr.issMax); swabLong ((char *) &pSymHdr->cbSsOffset, (char *) &tempSymHdr.cbSsOffset); swabLong ((char *) &pSymHdr->issExtMax, (char *) &tempSymHdr.issExtMax); swabLong ((char *) &pSymHdr->cbSsExtOffset, (char *) &tempSymHdr.cbSsExtOffset); swabLong ((char *) &pSymHdr->ifdMax, (char *) &tempSymHdr.ifdMax); swabLong ((char *) &pSymHdr->cbFdOffset, (char *) &tempSymHdr.cbFdOffset); swabLong ((char *) &pSymHdr->crfd, (char *) &tempSymHdr.crfd); swabLong ((char *) &pSymHdr->cbRfdOffset, (char *) &tempSymHdr.cbRfdOffset); swabLong ((char *) &pSymHdr->iextMax, (char *) &tempSymHdr.iextMax); swabLong ((char *) &pSymHdr->cbExtOffset, (char *) &tempSymHdr.cbExtOffset); bcopy ((char *) &tempSymHdr, (char *) pSymHdr, sizeof(HDRR)); }/********************************************************************************* swapCoffsymbols - swap endianess of COFF symbols* */LOCAL void swapCoffsymbols ( EXTR *pSym, /* module's ECOFF symbol table */ int symCount /* number of symbols in table */ ) { EXTR tempExtSym; SYMR_LE tempSym; EXTR_LE tempRsvd; for(;symCount > 0; pSym++, symCount--) { /* swap short bitfield */ swab ((char *)pSym, (char *) &tempRsvd, sizeof(tempRsvd)); tempExtSym.jmptbl = tempRsvd.jmptbl; tempExtSym.cobol_main = tempRsvd.cobol_main; tempExtSym.reserved = tempRsvd.reserved; swab ((char *) &pSym->ifd, (char *) &tempExtSym.ifd, sizeof(pSym->ifd)); swabLong ((char *) &pSym->asym.iss, (char *) &tempExtSym.asym.iss); swabLong ((char *) &pSym->asym.value, (char *) &tempExtSym.asym.value);/* * The correct way to do the following swap would be to define a * union so the address of the bitfield could be taken. Doing this* would ripple changes through all of vxWorks so we are avioding* it at the moment. If any fields get added to the structure* SYMR after value and before the bitfield we will surely notice* it here.*/ /* swap long bitfield */ swabLong ((char *) ((long) &pSym->asym.value + sizeof(pSym->asym.value)), (char *) ((long) &tempSym.value + sizeof(tempSym.value))); tempExtSym.asym.st = tempSym.st; tempExtSym.asym.sc = tempSym.sc; tempExtSym.asym.reserved = tempSym.reserved; tempExtSym.asym.index = tempSym.index; bcopy ((char *) &tempExtSym, (char *) pSym, sizeof(EXTR)); } }/********************************************************************************* swapCoffrelocTbl - swap endianess of COFF relocation entries* */LOCAL void swapCoffrelocTbl ( RELOC *pReloc, /* module's ECOFF relocation table */ int relocCount /* number of relocation entries in table */ ) { RELOC tempReloc; RELOC_LE tempBits; for (;relocCount > 0; pReloc++, relocCount--) { swabLong ((char *) &pReloc->r_vaddr, (char *) &tempReloc.r_vaddr);/* * The correct way to do the following swap would be to define a * union so the address of the bitfield could be taken. Doing this* would ripple changes through all of vxWorks so we are avioding* it at the moment. If any fields get added to the structure* RELOC after r_vaddr and before the bitfield we will surely notice* it here.*/ /* swap long bitfield */ swabLong ((char *) ((long) &pReloc->r_vaddr + sizeof(pReloc->r_vaddr)), (char *) ((long) &tempBits + sizeof(tempBits.r_vaddr))); tempReloc.r_symndx = tempBits.r_symndx; tempReloc.r_reserved = tempBits.r_reserved; tempReloc.r_type = tempBits.r_type; tempReloc.r_extern = tempBits.r_extern; bcopy ((char *) &tempReloc, (char *) pReloc, sizeof(RELOC)); } }/********************************************************************************* ecoffSecHdrRead - read in COFF section header and swap if necessary* */LOCAL STATUS ecoffSecHdrRead ( int fd, SCNHDR *pScnHdr, FILHDR *pHdr, BOOL swapTables ) { int ix; /* check for correct section count */ if (pHdr->f_nscns < NO_SCNS || pHdr->f_nscns > MAX_SCNS) { return (ERROR); } for (ix = 0; ix < pHdr->f_nscns; ix++) { if (fioRead (fd, (char *)pScnHdr, sizeof(SCNHDR)) != sizeof(SCNHDR)) { return (ERROR); } if (swapTables) { swapCoffscnHdr (pScnHdr); } pScnHdr++; } return (OK); }/********************************************************************************* ecoffReadInSections - read in COFF sections* */LOCAL STATUS ecoffReadInSections ( int fd, char **pSectPtr, SCNHDR *pScnHdr, BOOL swapTables ) { FAST int ix; for (ix = 0; ix < MAX_SCNS; ix++) { if (pScnHdr->s_size != 0 && pScnHdr->s_scnptr != 0) { if ((*pSectPtr = (char *) malloc ((UINT)pScnHdr->s_size)) == NULL) { return (ERROR); } if ((softSeek (fd, pScnHdr->s_scnptr) == ERROR) || (fioRead (fd, *pSectPtr, (int) pScnHdr->s_size) != pScnHdr->s_size)) { return (ERROR); } } pScnHdr++; pSectPtr++; } return (OK); }/********************************************************************************* ecoffLdSections - write out sections to memory* */LOCAL STATUS ecoffLdSections ( char **pSectPtr, SCNHDR *pScnHdr, AOUTHDR *pOptHdr, char *pText, char *pData ) { int ix; int textCount = 0; int dataCount = 0; for (ix = 0; ix < MAX_SCNS; ix++) { if (strcmp (pScnHdr->s_name, _TEXT) == 0 || strcmp (pScnHdr->s_name, _INIT) == 0) { bcopy (*pSectPtr, pText, pScnHdr->s_size); pText = (char *) ((int) pText + pScnHdr->s_size); textCount += pScnHdr->s_size; } else if (strcmp (pScnHdr->s_name, _DATA) == 0 || strcmp (pScnHdr->s_name, _RDATA) == 0 || strcmp (pScnHdr->s_name, _SDATA) == 0 || strcmp (pScnHdr->s_name, _LIT4) == 0 || strcmp (pScnHdr->s_name, _LIT8) == 0) { bcopy (*pSectPtr, pData, pScnHdr->s_size); pData = (char *) ((int) pData + pScnHdr->s_size); dataCount += pScnHdr->s_size; } else { /* ignore all other sections */ } pScnHdr++; pSectPtr++; } /* did we copy it all ? */ if ((textCount != pOptHdr->tsize) || (dataCount != pOptHdr->dsize)) { return (ERROR); } return (OK); }/********************************************************************************* ecoffReadRelocInfo - read in COFF relocation information and swap if necessary* */LOCAL STATUS ecoffReadRelocInfo ( int fd, SCNHDR *pScnHdrFirst, RELOC *relsPtr[], BOOL swapTables ) { int relocSize; int position; /* present file position */ SCNHDR *pScnHdr; /* try to use array instead pScnHdr[MAX_SCNS] */ int ix; /* index thru reloc info sections */ int iy; /* index thru section headers */ for (ix = 0; ix < MAX_SCNS; ix++) { position = ioctl (fd, FIOWHERE, (int) 0); /* * look through each pScnHdr for relocation offset equal to * current position. should they be equal, then this relocation * data corresponds to that section header. Use the section header * array index so that the resulting relocation information will * be in the same order as the section headers. */ pScnHdr = pScnHdrFirst; for (iy = 0; iy < MAX_SCNS; iy++) { if ((pScnHdr->s_nreloc > 0) && (pScnHdr->s_relptr == position)) { relocSize = (int) pScnHdr->s_nreloc * RELSZ; /* use array instead of pRelPtr */ /* then use header index into array */ if ((relsPtr[iy] = (RELOC *)malloc (relocSize)) == NULL) { return (ERROR); } if (fioRead (fd, (char *) relsPtr[iy], relocSize) != relocSize) { return (ERROR); } if (swapTables) { swapCoffrelocTbl(relsPtr[iy], pScnHdr->s_nreloc); } break; /* found the right header, no need to look at the rest */ } else pScnHdr++; } } return (OK); }/********************************************************************************* ecoffReadSymHdr - read in COFF symbol header and swap if necessary* */LOCAL STATUS ecoffReadSymHdr ( int fd, HDRR *pSymHdr, FILHDR *pHdr, BOOL swapTables ) { if (pHdr->f_nsyms == 0) { return (ERROR); } else { if ((softSeek (fd, pHdr->f_symptr) == ERROR) || (fioRead (fd, (char *) pSymHdr, pHdr->f_nsyms) != pHdr->f_nsyms)) { return (ERROR); } if (swapTables) { swapCoffsymHdr (pSymHdr); } } return (OK); }/********************************************************************************* ecoffReadExtStrings - read in COFF external strings* */LOCAL STATUS ecoffReadExtStrings ( int fd, char **pStrBuf, HDRR *pSymHdr ) { if (pSymHdr->issExtMax > 0) /* is there a string table? */ { if ((*pStrBuf = (char *) malloc ((UINT) pSymHdr->issExtMax)) == NULL) { return (ERROR); } if ((softSeek (fd, pSymHdr->cbSsExtOffset) != OK) || (fioRead (fd, *pStrBuf, (int) pSymHdr->issExtMax) != pSymHdr->issExtMax)) { return (ERROR); } } return (OK); }/********************************************************************************* ecoffReadExtSyms - read in COFF external symbols and swap if necessary* */LOCAL STATUS ecoffReadExtSyms ( int fd, EXTR **pExtSyms, HDRR *pSymHdr, BOOL swapTables ) { int extSymSize = (int) (pSymHdr->iextMax * cbEXTR); if (extSymSize != 0) /* is there a symbol table? */ { if ((*pExtSyms = (EXTR *) malloc (extSymSize)) == NULL) { return (ERROR); } if (softSeek (fd, pSymHdr->cbExtOffset) == ERROR) { return (ERROR); } if (fioRead (fd, (char *) *pExtSyms, extSymSize) != extSymSize) { return (ERROR); } if (swapTables) { swapCoffsymbols (*pExtSyms, pSymHdr->iextMax); } } return (OK); }/********************************************************************************* sizeEcoffCommons - * * INTERNAL* All common external symbols are being tacked on to the end* of the BSS section. Each symbol is examined and placed at* the appropriate address. The appropriate address is determined* by examining the address of the previous common symbol and the* size of the current common symbol. (The size of the symbol is * contained in the U_SYM_VALUE field of the symbol entry) The * address of a symbol must be correctly aliged for data access. * For example, on the R3000 architecture word accesses must be word * aligned. The macro COMMON_ALIGNMENT is the base boundry size for the* architecture.*/LOCAL ULONG sizeEcoffCommons ( EXTR *pNextSym, ULONG alignBss ) { ULONG fixupBss; ULONG nbytes = 0; fixupBss = ((alignBss % (ULONG) pNextSym->U_SYM_VALUE) & (COMMON_ALIGNMENT - 1)); if (fixupBss != 0) { fixupBss = COMMON_ALIGNMENT - fixupBss; } nbytes = (ULONG) pNextSym->U_SYM_VALUE + fixupBss; return (nbytes); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -