@@ -44,6 +44,15 @@ enum class PsyqOpcode : uint8_t {
4444 FILENAME = 28 ,
4545 PROGRAMTYPE = 46 ,
4646 UNINITIALIZED = 48 ,
47+ INC_SLD_LINENUM = 50 ,
48+ INC_SLD_LINENUM_BY_BYTE = 52 ,
49+ SET_SLD_LINENUM = 56 ,
50+ SET_SLD_LINENUM_FILE = 58 ,
51+ END_SLD = 60 ,
52+ FUNCTION = 74 ,
53+ FUNCTION_END = 76 ,
54+ SECTION_DEF = 82 ,
55+ SECTION_DEF2 = 84 ,
4756};
4857
4958enum class PsyqRelocType : uint8_t {
@@ -409,6 +418,92 @@ std::unique_ptr<PsyqLnkFile> PsyqLnkFile::parse(PCSX::File* file, bool verbose)
409418 ret->symbols .insert (symbolIndex, symbol);
410419 break ;
411420 }
421+ case (uint8_t )PsyqOpcode::INC_SLD_LINENUM : {
422+ uint16_t offset = file->read <uint16_t >();
423+ vprint (" INC_SLD_LINENUM offset {}\n " , offset);
424+
425+ break ;
426+ }
427+ case (uint8_t )PsyqOpcode::INC_SLD_LINENUM_BY_BYTE : {
428+ uint16_t offset = file->read <uint16_t >();
429+ uint8_t _byte = file->read <uint8_t >();
430+ vprint (" INC_SLD_LINENUM_BY_BYTE offset {}, _byte {}\n " , offset, _byte);
431+
432+ break ;
433+ }
434+ case (uint8_t )PsyqOpcode::SET_SLD_LINENUM : {
435+ uint16_t offset = file->read <uint16_t >();
436+ uint32_t lineNum = file->read <uint32_t >();
437+ vprint (" SET_SLD_LINENUM lineNum {}, offset {}\n " , lineNum, offset);
438+ break ;
439+ }
440+ case (uint8_t )PsyqOpcode::SET_SLD_LINENUM_FILE : {
441+ uint16_t offset = file->read <uint16_t >();
442+ uint32_t lineNum = file->read <uint32_t >();
443+ uint16_t _file = file->read <uint16_t >();
444+ vprint (" SET_SLD_LINENUM_FILE lineNum {}, offset {}, _file {}\n " , lineNum, offset, _file);
445+ break ;
446+ }
447+ case (uint8_t )PsyqOpcode::END_SLD : {
448+ // 2 bytes of nothing
449+ uint16_t zero = file->read <uint16_t >();
450+ assert (zero == 0 );
451+ vprint (" END_SLD\n " );
452+ break ;
453+ }
454+ case (uint8_t )PsyqOpcode::FUNCTION : {
455+ uint16_t section = file->read <uint16_t >();
456+ uint32_t offset = file->read <uint32_t >();
457+ uint16_t _file = file->read <uint16_t >();
458+ uint32_t startLine = file->read <uint32_t >();
459+ uint16_t frameReg = file->read <uint16_t >();
460+ uint32_t frameSize = file->read <uint32_t >();
461+ uint16_t retnPcReg = file->read <uint16_t >();
462+ uint32_t mask = file->read <uint32_t >();
463+ uint32_t maskOffset = file->read <uint32_t >();
464+ std::string name = readPsyqString (file);
465+ vprint (" FUNCTION: section {}, offset {}, _file {}, startLine {}, frameReg {}, frameSize {}, retnPcReg {}, mask {}, maskOffset {}, name {}\n " ,
466+ section, offset, _file, startLine, frameReg, frameSize, retnPcReg, mask, maskOffset, name);
467+ break ;
468+ }
469+ case (uint8_t )PsyqOpcode::FUNCTION_END : {
470+ uint16_t section = file->read <uint16_t >();
471+ uint32_t offset = file->read <uint32_t >();
472+ uint32_t endLine = file->read <uint32_t >();
473+ vprint (" FUNCTION_END: section {}, offset {}, endLine {}\n " ,
474+ section, offset, endLine);
475+ break ;
476+ }
477+ case (uint8_t )PsyqOpcode::SECTION_DEF : {
478+ uint16_t section = file->read <uint16_t >();
479+ uint32_t value = file->read <uint32_t >();
480+ uint16_t _class = file->read <uint16_t >();
481+ uint16_t type = file->read <uint16_t >();
482+ uint32_t size = file->read <uint32_t >();
483+ std::string name = readPsyqString (file);
484+ vprint (" SECTION_DEF: section {}, value {}, _class {}, type {}, size {}\n " ,
485+ section, value, _class, type, size);
486+ break ;
487+ }
488+ case (uint8_t )PsyqOpcode::SECTION_DEF2 : {
489+ uint16_t section = file->read <uint16_t >();
490+ uint32_t value = file->read <uint32_t >();
491+ uint16_t _class = file->read <uint16_t >();
492+ uint16_t type = file->read <uint16_t >();
493+ uint32_t size = file->read <uint32_t >();
494+
495+ uint16_t dims = file->read <uint16_t >();
496+ while (dims-- > 0 ) {
497+ // ignore for now
498+ uint16_t dim = file->read <uint16_t >();
499+ }
500+
501+ std::string tag = readPsyqString (file);
502+ std::string name = readPsyqString (file);
503+ vprint (" SECTION_DEF2: section {}, value {}, _class {}, type {}, size {}, dims {}, tag {}, name {}\n " ,
504+ section, value, _class, type, size, dims, tag, name);
505+ break ;
506+ }
412507 default : {
413508 fmt::print (" Unknown opcode {}.\n " , opcode);
414509 return nullptr ;
@@ -708,6 +803,8 @@ bool PsyqLnkFile::writeElf(const std::string& prefix, const std::string& out, bo
708803bool PsyqLnkFile::Symbol::generateElfSymbol (PsyqLnkFile* psyq, ELFIO ::string_section_accessor& stra,
709804 ELFIO ::symbol_section_accessor& syma) {
710805 ELFIO ::Elf_Half elfSectionIndex = 0 ;
806+ bool isText = false ;
807+
711808 fmt::print (" :: Generating symbol {}\n " , name);
712809 if (symbolType != Type::IMPORTED ) {
713810 auto section = psyq->sections .find (sectionIndex);
@@ -717,9 +814,12 @@ bool PsyqLnkFile::Symbol::generateElfSymbol(PsyqLnkFile* psyq, ELFIO::string_sec
717814 return false ;
718815 }
719816 elfSectionIndex = section->section ->get_index ();
817+ isText = section->isText ();
720818 }
721819 elfSym = syma.add_symbol (stra, name.c_str (), getOffset (psyq), size,
722- symbolType == Type::LOCAL ? STB_LOCAL : STB_GLOBAL , STT_NOTYPE , 0 , elfSectionIndex);
820+ symbolType == Type::LOCAL ? STB_LOCAL : STB_GLOBAL ,
821+ isText ? STT_FUNC : STT_NOTYPE ,
822+ 0 , elfSectionIndex);
723823 return true ;
724824}
725825
@@ -803,7 +903,7 @@ bool PsyqLnkFile::Relocation::generateElf(ElfRelocationPass pass, const std::str
803903 {PsyqRelocType::LO16 , elf_mips_reloc_type::R_MIPS_LO16 },
804904 {PsyqRelocType::GPREL16 , elf_mips_reloc_type::R_MIPS_GPREL16 },
805905 };
806- auto simpleSymbolReloc = [&, this ](Expression* expr, ELFIO ::Elf_Word elfSym = 0 ) {
906+ auto simpleSymbolReloc = [&, this ](Expression* expr, ELFIO ::Elf_Word elfSym = 0 , uint16_t symbolOffset = 0 ) {
807907 if (psyq->twoPartsReloc ) {
808908 psyq->setElfConversionError (" Two-part relocation missing its second part" );
809909 return false ;
@@ -830,7 +930,7 @@ bool PsyqLnkFile::Relocation::generateElf(ElfRelocationPass pass, const std::str
830930 break ;
831931 }
832932 case PsyqRelocType::REL26 : {
833- sectionData[offset + 0 ] = 0 ;
933+ sectionData[offset + 0 ] = symbolOffset >> 2 ;
834934 sectionData[offset + 1 ] = 0 ;
835935 sectionData[offset + 2 ] = 0 ;
836936 sectionData[offset + 3 ] &= 0xfc ;
@@ -866,13 +966,13 @@ bool PsyqLnkFile::Relocation::generateElf(ElfRelocationPass pass, const std::str
866966 ELFIO ::Elf_Word elfSym;
867967 if (existing == psyq->localElfSymbols .end ()) {
868968 fmt::print (" :: Creating local symbol {}\n " , symbolName);
869- elfSym = syma.add_symbol (stra, symbolName.c_str (), symbolOffset, 0 , STB_LOCAL , STT_NOTYPE , 0 ,
969+ elfSym = syma.add_symbol (stra, symbolName.c_str (), symbolOffset, 0 , STB_LOCAL , STT_SECTION , 0 ,
870970 section->section ->get_index ());
871971 psyq->localElfSymbols .insert (std::make_pair (symbolName, elfSym));
872972 } else {
873973 elfSym = existing->second ;
874974 }
875- return simpleSymbolReloc (nullptr , elfSym);
975+ return simpleSymbolReloc (nullptr , elfSym, symbolOffset );
876976 };
877977 auto checkZero = [&, this ](Expression* expr) {
878978 switch (expr->type ) {
0 commit comments