mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-27 07:31:35 +00:00
MakePEF: some cleanup
This commit is contained in:
parent
92f168555f
commit
4851123ac6
@ -130,35 +130,18 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
in.read((char*)&aoutHeader, sizeof(aoutHeader));
|
in.read((char*)&aoutHeader, sizeof(aoutHeader));
|
||||||
in.seekg(get(xcoffHeader.f_opthdr) - sizeof(aoutHeader),std::ios_base::cur);
|
in.seekg(get(xcoffHeader.f_opthdr) - sizeof(aoutHeader),std::ios_base::cur);
|
||||||
|
|
||||||
if(verboseFlag)
|
|
||||||
std::cerr << "flags: " << std::hex << get(xcoffHeader.f_flags) << std::dec << std::endl;
|
|
||||||
if(verboseFlag)
|
if(verboseFlag)
|
||||||
{
|
{
|
||||||
|
std::cerr << "flags: " << std::hex << get(xcoffHeader.f_flags) << std::dec << std::endl;
|
||||||
std::cerr << "symptr: " << get(xcoffHeader.f_symptr) << std::endl;
|
std::cerr << "symptr: " << get(xcoffHeader.f_symptr) << std::endl;
|
||||||
std::cerr << "nsyms: " << get(xcoffHeader.f_nsyms) << std::endl;
|
std::cerr << "nsyms: " << get(xcoffHeader.f_nsyms) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nSections = get(xcoffHeader.f_nscns);
|
|
||||||
|
|
||||||
PEFContainerHeader pefHeader;
|
|
||||||
|
|
||||||
memset(&pefHeader,0,sizeof(pefHeader));
|
|
||||||
|
|
||||||
pefHeader.tag1 = kPEFTag1;
|
|
||||||
pefHeader.tag2 = kPEFTag2;
|
|
||||||
pefHeader.architecture = 'pwpc';
|
|
||||||
pefHeader.formatVersion = kPEFVersion;
|
|
||||||
pefHeader.sectionCount = 3; // .text, .data, .loader
|
|
||||||
pefHeader.instSectionCount = 2; // .text, .data
|
|
||||||
|
|
||||||
std::map<std::string,external_scnhdr> xcoffSections;
|
std::map<std::string,external_scnhdr> xcoffSections;
|
||||||
std::map<std::string, int> xcoffSectionNumbers;
|
std::map<std::string, int> xcoffSectionNumbers;
|
||||||
std::map<int, std::string> xcoffSectionNames;
|
|
||||||
std::map<std::string, int> pefSectionNumbers;
|
int nSections = get(xcoffHeader.f_nscns);
|
||||||
|
|
||||||
pefSectionNumbers[".text"] = 0;
|
|
||||||
pefSectionNumbers[".data"] = 1;
|
|
||||||
|
|
||||||
for(int i=0;i<nSections;i++)
|
for(int i=0;i<nSections;i++)
|
||||||
{
|
{
|
||||||
external_scnhdr xcoffSection;
|
external_scnhdr xcoffSection;
|
||||||
@ -173,26 +156,15 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
}
|
}
|
||||||
xcoffSections[xcoffSection.s_name] = xcoffSection;
|
xcoffSections[xcoffSection.s_name] = xcoffSection;
|
||||||
xcoffSectionNumbers[xcoffSection.s_name] = i+1;
|
xcoffSectionNumbers[xcoffSection.s_name] = i+1;
|
||||||
xcoffSectionNames[i+1] = xcoffSection.s_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PEFLoaderInfoHeader loaderInfoHeader;
|
|
||||||
memset(&loaderInfoHeader, 0, sizeof(loaderInfoHeader));
|
|
||||||
|
|
||||||
loaderInfoHeader.mainSection = -1;
|
|
||||||
loaderInfoHeader.initSection = -1;
|
|
||||||
loaderInfoHeader.termSection = -1;
|
|
||||||
|
|
||||||
loaderInfoHeader.mainSection = 1;
|
|
||||||
loaderInfoHeader.mainOffset = get(aoutHeader.entry);
|
|
||||||
|
|
||||||
std::vector<ImportLib> importLibs;
|
std::vector<ImportLib> importLibs;
|
||||||
std::vector<unsigned short> relocInstructions;
|
|
||||||
std::map<std::string, int> importSources;
|
|
||||||
std::map<std::string, int> importedSymbolIndicesByName;
|
|
||||||
std::set<std::string> importedSymbolSet;
|
|
||||||
std::vector<int> importedSymbolIndices;
|
std::vector<int> importedSymbolIndices;
|
||||||
int totalImportedSyms = 0;
|
int totalImportedSyms = 0;
|
||||||
|
|
||||||
|
std::vector<unsigned short> relocInstructions;
|
||||||
|
|
||||||
{
|
{
|
||||||
external_scnhdr xcoffLoaderSection = xcoffSections[".loader"];
|
external_scnhdr xcoffLoaderSection = xcoffSections[".loader"];
|
||||||
external_ldhdr xcoffLoaderHeader;
|
external_ldhdr xcoffLoaderHeader;
|
||||||
@ -240,8 +212,6 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
std::cerr << "... from file: " << get(sym.l_ifile) << std::endl;
|
std::cerr << "... from file: " << get(sym.l_ifile) << std::endl;
|
||||||
importLibs[get(sym.l_ifile)].imports.push_back(name);
|
importLibs[get(sym.l_ifile)].imports.push_back(name);
|
||||||
importLibs[get(sym.l_ifile)].xcoffImportIndices.push_back(i);
|
importLibs[get(sym.l_ifile)].xcoffImportIndices.push_back(i);
|
||||||
importSources[name] = totalImportedSyms;
|
|
||||||
importedSymbolSet.insert(name);
|
|
||||||
totalImportedSyms++;
|
totalImportedSyms++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,9 +220,8 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
int symbolIndex = 0;
|
int symbolIndex = 0;
|
||||||
for(unsigned i=1;i<importLibs.size();i++)
|
for(unsigned i=1;i<importLibs.size();i++)
|
||||||
{
|
{
|
||||||
for(unsigned j=0;j<importLibs[i].imports.size();j++)
|
for(unsigned j=0;j<importLibs[i].xcoffImportIndices.size();j++)
|
||||||
{
|
{
|
||||||
importedSymbolIndicesByName[importLibs[i].imports[j]] = symbolIndex;
|
|
||||||
importedSymbolIndices[importLibs[i].xcoffImportIndices[j]] = symbolIndex;
|
importedSymbolIndices[importLibs[i].xcoffImportIndices[j]] = symbolIndex;
|
||||||
symbolIndex++;
|
symbolIndex++;
|
||||||
}
|
}
|
||||||
@ -294,6 +263,28 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PEFContainerHeader pefHeader;
|
||||||
|
|
||||||
|
memset(&pefHeader,0,sizeof(pefHeader));
|
||||||
|
|
||||||
|
pefHeader.tag1 = kPEFTag1;
|
||||||
|
pefHeader.tag2 = kPEFTag2;
|
||||||
|
pefHeader.architecture = 'pwpc';
|
||||||
|
pefHeader.formatVersion = kPEFVersion;
|
||||||
|
pefHeader.sectionCount = 3; // .text, .data, .loader
|
||||||
|
pefHeader.instSectionCount = 2; // .text, .data
|
||||||
|
|
||||||
|
PEFLoaderInfoHeader loaderInfoHeader;
|
||||||
|
memset(&loaderInfoHeader, 0, sizeof(loaderInfoHeader));
|
||||||
|
|
||||||
|
loaderInfoHeader.mainSection = -1;
|
||||||
|
loaderInfoHeader.initSection = -1;
|
||||||
|
loaderInfoHeader.termSection = -1;
|
||||||
|
|
||||||
|
loaderInfoHeader.mainSection = 1;
|
||||||
|
loaderInfoHeader.mainOffset = get(aoutHeader.entry);
|
||||||
|
|
||||||
|
|
||||||
PEFSectionHeader textSectionHeader, dataSectionHeader, loaderSectionHeader;
|
PEFSectionHeader textSectionHeader, dataSectionHeader, loaderSectionHeader;
|
||||||
memset(&textSectionHeader, 0, sizeof(textSectionHeader));
|
memset(&textSectionHeader, 0, sizeof(textSectionHeader));
|
||||||
memset(&dataSectionHeader, 0, sizeof(dataSectionHeader));
|
memset(&dataSectionHeader, 0, sizeof(dataSectionHeader));
|
||||||
@ -321,13 +312,6 @@ void mkpef(const std::string& inFn, const std::string& outFn)
|
|||||||
dataSectionHeader.shareKind = kPEFProcessShare;
|
dataSectionHeader.shareKind = kPEFProcessShare;
|
||||||
dataSectionHeader.alignment = 2;
|
dataSectionHeader.alignment = 2;
|
||||||
|
|
||||||
if(verboseFlag)
|
|
||||||
{
|
|
||||||
std::cerr << get(xcoffSections[".text"].s_size) << std::endl;
|
|
||||||
std::cerr << get(xcoffSections[".data"].s_size) << std::endl;
|
|
||||||
std::cerr << get(xcoffSections[".bss"].s_size) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> loaderStringTable;
|
std::vector<std::string> loaderStringTable;
|
||||||
int loaderStringTableSize = 0;
|
int loaderStringTableSize = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user