mirror of https://github.com/stella-emu/stella.git
Refactoring, fix external function pointers.
This commit is contained in:
parent
5a7a72c745
commit
a606d294a4
|
@ -71,7 +71,8 @@ namespace {
|
||||||
constexpr uInt32 ADDR_DATA_ODR = 0xf0000008;
|
constexpr uInt32 ADDR_DATA_ODR = 0xf0000008;
|
||||||
constexpr uInt32 ADDR_DATA_MODER = 0xf0000010;
|
constexpr uInt32 ADDR_DATA_MODER = 0xf0000010;
|
||||||
|
|
||||||
constexpr uInt32 ADDR_VCS_JSR6 = 0x1000;
|
constexpr uInt32 VCSLIB_BASE = 0x1001;
|
||||||
|
constexpr uInt32 ADDR_VCS_JSR6 = VCSLIB_BASE;
|
||||||
|
|
||||||
const vector<ElfLinker::ExternalSymbol> EXTERNAL_SYMBOLS = {
|
const vector<ElfLinker::ExternalSymbol> EXTERNAL_SYMBOLS = {
|
||||||
{"ADDR_IDR", ADDR_ADDR_IDR},
|
{"ADDR_IDR", ADDR_ADDR_IDR},
|
||||||
|
@ -127,7 +128,7 @@ namespace {
|
||||||
cout
|
cout
|
||||||
<< sections[i].name
|
<< sections[i].name
|
||||||
<< " @ 0x"<< std::setw(8) << (relocatedSections[i]->offset +
|
<< " @ 0x"<< std::setw(8) << (relocatedSections[i]->offset +
|
||||||
(relocatedSections[i]->type == ElfLinker::SectionType::text ? ADDR_TEXT_BASE : ADDR_DATA_BASE)
|
(relocatedSections[i]->segment == ElfLinker::SegmentType::text ? ADDR_TEXT_BASE : ADDR_DATA_BASE)
|
||||||
)
|
)
|
||||||
<< " size 0x" << std::setw(8) << sections[i].size << std::endl;
|
<< " size 0x" << std::setw(8) << sections[i].size << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -144,8 +145,8 @@ namespace {
|
||||||
<< symbols[i].name
|
<< symbols[i].name
|
||||||
<< " = 0x" << std::setw(8) << relocatedSymbols[i]->value;
|
<< " = 0x" << std::setw(8) << relocatedSymbols[i]->value;
|
||||||
|
|
||||||
if (relocatedSymbols[i]->section) {
|
if (relocatedSymbols[i]->segment) {
|
||||||
cout << (*relocatedSymbols[i]->section == ElfLinker::SectionType::text ? " (text)" : " (data)");
|
cout << (*relocatedSymbols[i]->segment == ElfLinker::SegmentType::text ? " (text)" : " (data)");
|
||||||
} else {
|
} else {
|
||||||
cout << " (abs)";
|
cout << " (abs)";
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ void ElfLinker::link(const vector<ExternalSymbol>& externalSymbols)
|
||||||
if (segmentSize % section.align)
|
if (segmentSize % section.align)
|
||||||
segmentSize = (segmentSize / section.align + 1) * section.align;
|
segmentSize = (segmentSize / section.align + 1) * section.align;
|
||||||
|
|
||||||
myRelocatedSections[i] = {isText ? SectionType::text : SectionType::data, segmentSize};
|
myRelocatedSections[i] = {isText ? SegmentType::text : SegmentType::data, segmentSize};
|
||||||
segmentSize += section.size;
|
segmentSize += section.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ void ElfLinker::link(const vector<ExternalSymbol>& externalSymbols)
|
||||||
if (myDataSize % section.align)
|
if (myDataSize % section.align)
|
||||||
myDataSize = (myDataSize / section.align + 1) * section.align;
|
myDataSize = (myDataSize / section.align + 1) * section.align;
|
||||||
|
|
||||||
myRelocatedSections[i] = {SectionType::data, myDataSize};
|
myRelocatedSections[i] = {SegmentType::data, myDataSize};
|
||||||
myDataSize += section.size;
|
myDataSize += section.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,11 @@ void ElfLinker::link(const vector<ExternalSymbol>& externalSymbols)
|
||||||
const auto& relocatedSection = myRelocatedSections[symbol.section];
|
const auto& relocatedSection = myRelocatedSections[symbol.section];
|
||||||
if (!relocatedSection) continue;
|
if (!relocatedSection) continue;
|
||||||
|
|
||||||
uInt32 value = relocatedSection->type == SectionType::text ? myTextBase : myDataBase;
|
uInt32 value = relocatedSection->segment == SegmentType::text ? myTextBase : myDataBase;
|
||||||
value += relocatedSection->offset;
|
value += relocatedSection->offset;
|
||||||
if (symbol.type != ElfParser::STT_SECTION) value += symbol.value;
|
if (symbol.type != ElfParser::STT_SECTION) value += symbol.value;
|
||||||
|
|
||||||
myRelocatedSymbols[i] = {relocatedSection->type, value};
|
myRelocatedSymbols[i] = {relocatedSection->segment, value};
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply relocations
|
// apply relocations
|
||||||
|
@ -220,7 +220,7 @@ void ElfLinker::applyRelocation(const ElfParser::Relocation& relocation, size_t
|
||||||
);
|
);
|
||||||
|
|
||||||
uInt8* target =
|
uInt8* target =
|
||||||
(targetSectionRelocated.type == SectionType::text ? myTextData : myDataData).get() +
|
(targetSectionRelocated.segment == SegmentType::text ? myTextData : myDataData).get() +
|
||||||
targetSectionRelocated.offset + relocation.offset;
|
targetSectionRelocated.offset + relocation.offset;
|
||||||
|
|
||||||
switch (relocation.type) {
|
switch (relocation.type) {
|
||||||
|
@ -239,7 +239,7 @@ void ElfLinker::applyRelocation(const ElfParser::Relocation& relocation, size_t
|
||||||
const uInt32 op = read32(target);
|
const uInt32 op = read32(target);
|
||||||
|
|
||||||
Int32 offset = relocatedSymbol->value + relocation.addend.value_or(elfUtil::decode_B_BL(op)) -
|
Int32 offset = relocatedSymbol->value + relocation.addend.value_or(elfUtil::decode_B_BL(op)) -
|
||||||
(targetSectionRelocated.type == SectionType::text ? myTextBase : myDataBase) -
|
(targetSectionRelocated.segment == SegmentType::text ? myTextBase : myDataBase) -
|
||||||
targetSectionRelocated.offset - relocation.offset - 4;
|
targetSectionRelocated.offset - relocation.offset - 4;
|
||||||
|
|
||||||
if ((offset >> 24) != -1 && (offset >> 24) != 0)
|
if ((offset >> 24) != -1 && (offset >> 24) != 0)
|
||||||
|
|
|
@ -57,15 +57,15 @@ class ElfLinker {
|
||||||
const string myReason;
|
const string myReason;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SectionType: uInt8 { text, data };
|
enum class SegmentType: uInt8 { text, data };
|
||||||
|
|
||||||
struct RelocatedSection {
|
struct RelocatedSection {
|
||||||
SectionType type;
|
SegmentType segment;
|
||||||
uInt32 offset;
|
uInt32 offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RelocatedSymbol {
|
struct RelocatedSymbol {
|
||||||
optional<SectionType> section;
|
optional<SegmentType> segment;
|
||||||
uInt32 value;
|
uInt32 value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue