diff --git a/src/emucore/CartELF.cxx b/src/emucore/CartELF.cxx index 8ddf2cf90..080a26693 100644 --- a/src/emucore/CartELF.cxx +++ b/src/emucore/CartELF.cxx @@ -71,7 +71,8 @@ namespace { constexpr uInt32 ADDR_DATA_ODR = 0xf0000008; 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 EXTERNAL_SYMBOLS = { {"ADDR_IDR", ADDR_ADDR_IDR}, @@ -127,7 +128,7 @@ namespace { cout << sections[i].name << " @ 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; } @@ -144,8 +145,8 @@ namespace { << symbols[i].name << " = 0x" << std::setw(8) << relocatedSymbols[i]->value; - if (relocatedSymbols[i]->section) { - cout << (*relocatedSymbols[i]->section == ElfLinker::SectionType::text ? " (text)" : " (data)"); + if (relocatedSymbols[i]->segment) { + cout << (*relocatedSymbols[i]->segment == ElfLinker::SegmentType::text ? " (text)" : " (data)"); } else { cout << " (abs)"; } diff --git a/src/emucore/elf/ElfLinker.cxx b/src/emucore/elf/ElfLinker.cxx index e3c2299ec..83055771d 100644 --- a/src/emucore/elf/ElfLinker.cxx +++ b/src/emucore/elf/ElfLinker.cxx @@ -47,7 +47,7 @@ void ElfLinker::link(const vector& externalSymbols) if (segmentSize % 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; } } @@ -60,7 +60,7 @@ void ElfLinker::link(const vector& externalSymbols) if (myDataSize % section.align) myDataSize = (myDataSize / section.align + 1) * section.align; - myRelocatedSections[i] = {SectionType::data, myDataSize}; + myRelocatedSections[i] = {SegmentType::data, myDataSize}; myDataSize += section.size; } } @@ -119,11 +119,11 @@ void ElfLinker::link(const vector& externalSymbols) const auto& relocatedSection = myRelocatedSections[symbol.section]; if (!relocatedSection) continue; - uInt32 value = relocatedSection->type == SectionType::text ? myTextBase : myDataBase; + uInt32 value = relocatedSection->segment == SegmentType::text ? myTextBase : myDataBase; value += relocatedSection->offset; if (symbol.type != ElfParser::STT_SECTION) value += symbol.value; - myRelocatedSymbols[i] = {relocatedSection->type, value}; + myRelocatedSymbols[i] = {relocatedSection->segment, value}; } // apply relocations @@ -220,7 +220,7 @@ void ElfLinker::applyRelocation(const ElfParser::Relocation& relocation, size_t ); uInt8* target = - (targetSectionRelocated.type == SectionType::text ? myTextData : myDataData).get() + + (targetSectionRelocated.segment == SegmentType::text ? myTextData : myDataData).get() + targetSectionRelocated.offset + relocation.offset; switch (relocation.type) { @@ -239,7 +239,7 @@ void ElfLinker::applyRelocation(const ElfParser::Relocation& relocation, size_t const uInt32 op = read32(target); 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; if ((offset >> 24) != -1 && (offset >> 24) != 0) diff --git a/src/emucore/elf/ElfLinker.hxx b/src/emucore/elf/ElfLinker.hxx index d805c7854..2182b33d0 100644 --- a/src/emucore/elf/ElfLinker.hxx +++ b/src/emucore/elf/ElfLinker.hxx @@ -57,15 +57,15 @@ class ElfLinker { const string myReason; }; - enum class SectionType: uInt8 { text, data }; + enum class SegmentType: uInt8 { text, data }; struct RelocatedSection { - SectionType type; + SegmentType segment; uInt32 offset; }; struct RelocatedSymbol { - optional section; + optional segment; uInt32 value; };