96 tpef_(tpef), out_(out), onlyLogicalInfo_(
false) {
114 std::map<std::string, Word> organizedSections;
121 for (std::map<std::string, Word>::iterator
122 iter = organizedSections.begin();
123 iter != organizedSections.end();
185 std::string strIndexString;
187 if (strSectionIndex != -1) {
190 strIndexString =
"No strings section defined";
192 strIndexString =
"INVALID TPEF: String section was not found.";
200 << std::setw(20) <<
"File architecture: "
203 << std::endl << std::endl;
221 <<
"B = Bytes. U = MAUs. E = SectionElements."
234 out_ <<
"Minimum sizes for address spaces:" << std::endl << std::endl;
237 std::map<ASpaceElement*, std::pair<int, int> > neededMAUsOfASpace;
239 std::map<ASpaceElement*, std::pair<bool, bool> > typeOfMemNeeded;
247 if (neededMAUsOfASpace.find(currSect.
aSpace()) ==
248 neededMAUsOfASpace.end()) {
250 neededMAUsOfASpace[currSect.
aSpace()] = std::pair<int,int>(0,0);
251 typeOfMemNeeded[currSect.
aSpace()] = std::pair<bool,bool>(
false,
false);
254 std::pair<int,int> currentLimits = neededMAUsOfASpace[currSect.
aSpace()];
256 int currMax = currMin;
257 std::pair<bool,bool> currentMemtypes = typeOfMemNeeded[currSect.
aSpace()];
259 if (currSect.
type() == Section::ST_CODE) {
262 (&currSect)->instructionCount();
263 currentMemtypes.first =
true;
265 }
else if (currSect.
type() == Section::ST_DATA ||
266 currSect.
type() == Section::ST_UDATA ||
267 currSect.
type() == Section::ST_LEDATA) {
270 &currSect)->lengthInMAUs();
271 currentMemtypes.second =
true;
274 assert(
false &&
"Unknown program section type");
278 if (currMin < currentLimits.first) {
279 currentLimits.first = currMin;
282 if (currMax > currentLimits.second) {
283 currentLimits.second = currMax;
286 neededMAUsOfASpace[currSect.
aSpace()] = currentLimits;
287 typeOfMemNeeded[currSect.
aSpace()] = currentMemtypes;
298 if (neededMAUsOfASpace.find(aSpace) != neededMAUsOfASpace.end()) {
300 neededMAUsOfASpace[aSpace].second -
301 neededMAUsOfASpace[aSpace].first;
304 if (typeOfMemNeeded[aSpace].first)
out_ <<
" CODE";
305 if (typeOfMemNeeded[aSpace].second)
out_ <<
" DATA";
306 out_ <<
": " << aSpaceSize <<
" MAU(s)" << std::endl;
309 out_ << i <<
": not used for data nor instructions."
326 if (currSect.
type() == Section::ST_RELOC) {
341 if (currSect.
type() == Section::ST_SYMTAB) {
358 out_ <<
"There is no section with index: " << sectionIndex
359 << std::endl << std::endl;
370 std::stringstream retVal;
372 retVal << std::setw(6) << std::left <<
"index"
373 << std::setw(15)<< std::right <<
"type"
374 << std::setw(12) <<
"address"
375 << std::setw(17) <<
"address space"
376 << std::setw(9) <<
"flags"
377 << std::setw(12) <<
"link"
378 << std::setw(15) <<
"size(B/U/E)"
379 << std::left <<
"\tname";
393 std::string nameString;
395 nameString =
"No section name defined.";
400 std::string elementsOrMAUs;
403 if (sect.
type() == Section::ST_STRTAB) {
408 dynamic_cast<UDataSection&
>(sect).lengthInMAUs()) +
" U";
417 std::stringstream retVal;
421 retVal << std::setw(6)
423 << std::setw(15) << std::right;
431 << std::setw(15) << elementsOrMAUs
432 << std::left <<
"\t" + nameString;
470 std::set<std::string> organizedElements;
472 switch (sect.
type()) {
473 case Section::ST_SYMTAB: {
474 out_ <<
"Symbol table:" << std::endl << std::endl;
478 out_ << std::endl << std::left;
481 out_ << std::setw(6) <<
"index" << std::right;
484 out_ << std::setw(17) <<
"type" << std::right
485 << std::setw(15) <<
"binding"
486 << std::setw(10) <<
"absolute"
487 << std::setw(12) <<
"owner"
488 << std::setw(15) <<
"value"
489 << std::left <<
"\tname"
490 << std::endl << std::endl;
498 std::string isAbso = (sym->
absolute()) ? (
"yes") : (
"no");
501 std::string symValue;
502 switch (sym->
type()) {
503 case SymbolElement::STT_NOTYPE: {
507 case SymbolElement::STT_SECTION: {
512 case SymbolElement::STT_FILE: {
517 case SymbolElement::STT_DATA: {
520 assert(uDataSect != NULL);
532 case SymbolElement::STT_CODE:
533 case SymbolElement::STT_PROCEDURE: {
550 symValue =
"Unknown symbol type!";
553 std::stringstream elemStr;
554 elemStr << std::left;
557 elemStr << std::setw(6)
566 << std::setw(10) << isAbso
569 << std::setw(15) << symValue
574 organizedElements.insert(elemStr.str());
576 out_ << elemStr.str() << std::endl;
585 <<
"U = Minimum allocateable unit index. "
586 <<
"E = Section element index. "
590 case Section::ST_RELOC: {
594 out_ <<
"Relocation table: " << std::endl;
595 out_ <<
"Referenced section: "
597 << std::endl << std::endl;
602 out_ << std::endl << std::left;
605 out_ << std::setw(6) <<
"index" << std::right;
608 out_ << std::setw(17) <<
"type"
610 << std::setw(6) <<
"size"
611 << std::setw(18) <<
"location"
612 << std::setw(18) <<
"destination"
613 << std::setw(17) <<
"address space"
614 << std::left <<
"\tsymbol"
615 << std::endl << std::endl;
622 std::string locationAddress;
651 " be DATA or CODE.");
654 std::string destinationAddress;
663 if (dstSection.
type() == Section::ST_CODE) {
670 }
else if (dstSection.
type() == Section::ST_DATA ||
671 dstSection.
type() == Section::ST_LEDATA ||
672 dstSection.
type() == Section::ST_UDATA) {
684 "UDATA or CODE section.");
690 std::stringstream elemStr;
691 elemStr << std::left;
700 << std::setw(6) <<
static_cast<Word
>(reloc->
size())
701 << std::setw(18) << locationAddress;
704 elemStr << std::setw(18)
707 elemStr << std::setw(18)
716 organizedElements.insert(elemStr.str());
718 out_ << elemStr.str() << std::endl;
725 <<
"E = Section element index. "
726 <<
"U = Minimum allocateable unit Index. "
727 <<
"A = Address of the address space."
728 << std::endl << std::endl;
732 case Section::ST_ADDRSP: {
733 out_ <<
"Address space table:"
734 << std::endl << std::endl;
740 out_ << std::endl << std::left;
742 out_ << std::setw(6) <<
"index" << std::right;
745 out_ << std::setw(6) <<
"MAU"
747 << std::setw(10) <<
"alignment"
748 << std::setw(10) <<
"word size"
749 << std::left <<
"\tname"
750 << std::endl << std::endl;
758 std::stringstream elemStr;
760 elemStr << std::left;
766 elemStr << std::setw(6) << static_cast<Word>(aSpace->
MAU())
768 << std::setw(10) <<
static_cast<Word
>(aSpace->
align())
769 << std::setw(10) <<
static_cast<Word
>(aSpace->
wordSize())
774 organizedElements.insert(elemStr.str());
776 out_ << elemStr.str() << std::endl;
785 case Section::ST_MR: {
786 out_ <<
"Machine resource table:"
787 << std::endl << std::endl;
793 out_ << std::endl << std::left
794 << std::setw(12) <<
"type"
796 << std::setw(8) <<
"info"
797 << std::left <<
"\tname"
798 << std::endl << std::endl;
800 out_ << std::endl << std::left
801 << std::setw(6) <<
"index"
802 << std::setw(12) << std::right <<
"type"
803 << std::setw(17) <<
"id"
804 << std::setw(8) <<
"info"
805 << std::left <<
"\tname"
806 << std::endl << std::endl;
815 std::stringstream elemStr;
822 << std::setw(8) << res->
info()
826 organizedElements.insert(elemStr.str());
831 << std::setw(12) << std::right
835 << std::setw(8) << res->
info()
847 case Section::ST_CODE: {
848 out_ <<
"Code section:"
849 << std::endl << std::endl;
861 out_ << std::left << std::setw(10)
873 case Section::ST_DATA: {
874 out_ <<
"Data section:"
875 << std::endl << std::endl;
885 out_ << std::endl << std::setw(9) <<
897 case Section::ST_LEDATA: {
898 out_ <<
"Low Endian Data section:"
899 << std::endl << std::endl;
909 out_ << std::endl << std::setw(9) <<
922 case Section::ST_STRTAB: {
923 out_ <<
"String section:"
924 << std::endl << std::endl;
929 out_ << std::endl << std::left;
932 out_ << std::setw(10) <<
"offset";
935 out_ << std::left <<
"string "
936 << std::endl << std::endl;
940 for (Word i = 0; i < strings.
length(); i++) {
941 std::stringstream elemStr;
944 elemStr << std::setw(10) << std::left
948 while (strings.
byte(i) != 0) {
949 elemStr << strings.
byte(i++);
953 organizedElements.insert(elemStr.str());
955 out_ << elemStr.str() << std::endl;
964 case Section::ST_DEBUG: {
965 out_ <<
"Debug section:"
966 << std::endl << std::endl;
971 out_ << std::endl << std::left;
973 out_ << std::setw(10) <<
"type";
974 out_ << std::left <<
"data "
975 << std::endl << std::endl;
979 std::stringstream elemStr;
983 elemStr << std::setw(10) << std::left
986 for (
unsigned int j = 0; j < elem->
length(); j++) {
987 elemStr << std::hex << std::setw(3)
988 <<
static_cast<int>(elem->
byte(j));
996 organizedElements.insert(elemStr.str());
998 out_ << elemStr.str() << std::endl;
1008 <<
" is not implemented." << std::endl;
1056 while (
static_cast<Word
>(index) < sect.
elementCount() &&
1057 sect.
element(index) != &elem) {
1077 Section::SectionType type,
bool shortForm) {
1079 std::string typeStr;
1082 case Section::ST_NULL: typeStr =
"NULL";
break;
1083 case Section::ST_STRTAB: typeStr =
"STRTAB";
break;
1084 case Section::ST_SYMTAB: typeStr =
"SYMTAB";
break;
1085 case Section::ST_DEBUG: typeStr =
"DEBUG";
break;
1086 case Section::ST_RELOC: typeStr =
"RELOC";
break;
1087 case Section::ST_LINENO: typeStr =
"LINENO";
break;
1088 case Section::ST_NOTE: typeStr =
"NOTE";
break;
1089 case Section::ST_ADDRSP: typeStr =
"ADDRSP";
break;
1090 case Section::ST_MR: typeStr =
"MR";
break;
1091 case Section::ST_CODE: typeStr =
"CODE";
break;
1092 case Section::ST_DATA: typeStr =
"DATA";
break;
1093 case Section::ST_UDATA: typeStr =
"UDATA";
break;
1094 case Section::ST_LEDATA: typeStr =
"LEDATA";
break;
1095 case Section::ST_DUMMY: typeStr =
"DUMMY";
break;
1096 default: typeStr =
"UNKNOWN";
1118 case Binary::FA_NOARCH: str =
"NOARCH";
break;
1119 case Binary::FA_TTA_MOVE:str =
"TTA_MOVE";
break;
1120 case Binary::FA_TTA_TUT: str =
"TTA_TUT";
break;
1121 case Binary::FA_TDS_TI: str =
"TDS_TI";
break;
1122 default: str =
"UNKNOWN";
1140 case DebugElement::DE_STAB: str =
"STAB";
break;
1141 default: str =
"UNKNOWN";
1159 case Binary::FT_NULL: str =
"UNDEF";
break;
1160 case Binary::FT_OBJSEQ: str =
"OBJSEQ";
break;
1161 case Binary::FT_PURESEQ: str =
"PURESEQ";
break;
1162 case Binary::FT_LIBSEQ: str =
"LIBSEQ";
break;
1163 case Binary::FT_MIXED: str =
"MIXED";
break;
1164 case Binary::FT_PARALLEL:str =
"PARALLEL";
break;
1165 default: str =
"UNKNOWN";
1183 case SymbolElement::STT_NOTYPE: str =
"NOTYPE";
break;
1184 case SymbolElement::STT_CODE: str =
"CODE";
break;
1185 case SymbolElement::STT_DATA: str =
"DATA";
break;
1186 case SymbolElement::STT_FILE: str =
"FILE";
break;
1187 case SymbolElement::STT_SECTION: str =
"SECTION";
break;
1188 case SymbolElement::STT_PROCEDURE: str =
"PROCEDURE";
break;
1189 default: str =
"UNKNOWN";
1207 case SymbolElement::STB_LOCAL: str =
"LOCAL";
break;
1208 case SymbolElement::STB_GLOBAL: str =
"GLOBAL";
break;
1209 case SymbolElement::STB_WEAK: str =
"WEAK";
break;
1210 default: str =
"UNKNOWN";
1228 case RelocElement::RT_NOREL: str =
"NOREL";
break;
1229 case RelocElement::RT_SELF: str =
"SELF";
break;
1230 case RelocElement::RT_PAGE: str =
"PAGE";
break;
1231 case RelocElement::RT_PCREL: str =
"PCREL";
break;
1232 default: str =
"UNKNOWN";
1248 case ResourceElement::MRT_NULL:str =
"NULL";
break;
1249 case ResourceElement::MRT_BUS: str =
"BUS";
break;
1250 case ResourceElement::MRT_UNIT:str =
"UNIT";
break;
1251 case ResourceElement::MRT_RF: str =
"RF";
break;
1252 case ResourceElement::MRT_OP: str =
"OP";
break;
1253 case ResourceElement::MRT_IMM: str =
"IMM";
break;
1254 case ResourceElement::MRT_SR: str =
"SR";
break;
1255 case ResourceElement::MRT_PORT:str =
"PORT";
break;
1256 default: str =
"UNKNOWN";
1274 case ResourceElement::MRT_UNIT:
1275 case ResourceElement::MRT_BUS: {
1281 case ResourceElement::MRT_RF: {
1284 }
else if (
id == ResourceElement::INT_RF) {
1286 }
else if (
id == ResourceElement::BOOL_RF) {
1288 }
else if (
id == ResourceElement::FP_RF) {
1290 }
else if ((
id&ResourceElement::UNIVERSAL_RF_MASK) != 0) {
1291 str =
"UNIV_UNKNWN";
1295 case ResourceElement::MRT_IMM: {
1296 if (
id == ResourceElement::INLINE_IMM) {
1337 assert(aSpaceIndex != -1);
1386 typedef std::set<std::string>::iterator StrSetIter;
1387 for (StrSetIter iter = aSet.begin(); iter != aSet.end(); iter++) {
1388 out_ << *iter << std::endl;