From 5bd4f4e9a50bf0c3c94943a39162ab6fef6c85b0 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 9 Mar 2023 21:04:56 +0100 Subject: [PATCH] Add local labels to listings --- oscar64/Disassembler.cpp | 37 +++++++++++++++++++++++---------- oscar64/Disassembler.h | 2 +- oscar64/Linker.cpp | 22 ++++++++++++++++++++ oscar64/NativeCodeGenerator.cpp | 13 ++++++++++++ 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/oscar64/Disassembler.cpp b/oscar64/Disassembler.cpp index 31f7346..030841a 100644 --- a/oscar64/Disassembler.cpp +++ b/oscar64/Disassembler.cpp @@ -684,6 +684,15 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba AsmInsData d = DecInsData[opcode]; int addr = 0; + if (proc && proc->mLinkerObject) + { + int i = 0; + while (i < proc->mLinkerObject->mRanges.Size() && iip - start != proc->mLinkerObject->mRanges[i].mOffset) + i++; + if (i < proc->mLinkerObject->mRanges.Size()) + fprintf(file, ".%s:\n", proc->mLinkerObject->mRanges[i].mIdent->mString); + } + if (bank) fprintf(file, "%02x:", bank); @@ -698,29 +707,29 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba break; case ASMIM_ZERO_PAGE: addr = memory[ip++]; - fprintf(file, "%04x : %02x %02x __ %s %s %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x __ %s %s %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker)); break; case ASMIM_ZERO_PAGE_X: addr = memory[ip++]; - fprintf(file, "%04x : %02x %02x __ %s %s,x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x __ %s %s,x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker)); break; case ASMIM_ZERO_PAGE_Y: addr = memory[ip++]; - fprintf(file, "%04x : %02x %02x __ %s %s,y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x __ %s %s,y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker)); break; case ASMIM_ABSOLUTE: addr = memory[ip] + 256 * memory[ip + 1]; - fprintf(file, "%04x : %02x %02x %02x %s $%04x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x %02x %s $%04x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker)); ip += 2; break; case ASMIM_ABSOLUTE_X: addr = memory[ip] + 256 * memory[ip + 1]; - fprintf(file, "%04x : %02x %02x %02x %s $%04x,x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x %02x %s $%04x,x %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker)); ip += 2; break; case ASMIM_ABSOLUTE_Y: addr = memory[ip] + 256 * memory[ip + 1]; - fprintf(file, "%04x : %02x %02x %02x %s $%04x,y %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x %02x %s $%04x,y %s\n", iip, memory[iip], memory[iip + 1], memory[iip + 2], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker)); ip += 2; break; case ASMIM_INDIRECT: @@ -730,11 +739,11 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba break; case ASMIM_INDIRECT_X: addr = memory[ip++]; - fprintf(file, "%04x : %02x %02x __ %s (%s,x) %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x __ %s (%s,x) %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker)); break; case ASMIM_INDIRECT_Y: addr = memory[ip++]; - fprintf(file, "%04x : %02x %02x __ %s (%s),y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, linker)); + fprintf(file, "%04x : %02x %02x __ %s (%s),y %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], TempName(addr, tbuffer, proc, linker), AddrName(addr, abuffer, proc, linker)); break; case ASMIM_RELATIVE: addr = memory[ip++]; @@ -742,18 +751,24 @@ void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int ba addr = addr + ip - 256; else addr = addr + ip; - fprintf(file, "%04x : %02x %02x __ %s $%04x\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], addr); + fprintf(file, "%04x : %02x %02x __ %s $%04x %s\n", iip, memory[iip], memory[iip + 1], AsmInstructionNames[d.mType], addr, AddrName(addr, abuffer, proc, linker)); break; } } } -const char* NativeCodeDisassembler::AddrName(int addr, char* buffer, Linker* linker) +const char* NativeCodeDisassembler::AddrName(int addr, char* buffer, InterCodeProcedure* proc, Linker* linker) { if (linker) { - LinkerObject* obj = linker->FindObjectByAddr(addr); + LinkerObject* obj; + + if (proc && proc->mLinkerObject && addr >= proc->mLinkerObject->mAddress && addr < proc->mLinkerObject->mAddress + proc->mLinkerObject->mSize) + obj = proc->mLinkerObject; + else + obj = linker->FindObjectByAddr(addr); + if (obj && obj->mIdent) { int i = 0; diff --git a/oscar64/Disassembler.h b/oscar64/Disassembler.h index 87ceb54..68a764e 100644 --- a/oscar64/Disassembler.h +++ b/oscar64/Disassembler.h @@ -31,7 +31,7 @@ public: void DumpMemory(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker, LinkerObject * lobj); protected: const char* TempName(uint8 tmp, char* buffer, InterCodeProcedure* proc, Linker* linker); - const char* AddrName(int addr, char* buffer, Linker* linker); + const char* AddrName(int addr, char* buffer, InterCodeProcedure* proc, Linker* linker); }; diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index ff226f0..482a2ce 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -965,16 +965,38 @@ bool Linker::WriteMlbFile(const char* filename) if ((obj->mFlags & LOBJF_REFERENCED) && obj->mIdent && obj->mSize > 0) { if (obj->mSection->mType == LST_BSS) + { + if (obj->mRanges.Size() > 0) + { + for(int i=0; imRanges.Size(); i++) + fprintf(file, "R:%04x-%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset, obj->mAddress + obj->mRanges[i].mOffset + obj->mRanges[i].mSize - 1, obj->mIdent->mString, obj->mRanges[i].mIdent->mString); + } fprintf(file, "R:%04x-%04x:%s\n", obj->mAddress, obj->mAddress + obj->mSize - 1, obj->mIdent->mString); + } else if (obj->mType == LOT_DATA) { if (!obj->mRegion->mCartridgeBanks) + { + if (obj->mRanges.Size() > 0) + { + for (int i = 0; i < obj->mRanges.Size(); i++) + fprintf(file, "P:%04x-%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset - 0x8000, obj->mAddress + obj->mRanges[i].mOffset + obj->mRanges[i].mSize - 0x8000 - 1, obj->mIdent->mString, obj->mRanges[i].mIdent->mString); + } fprintf(file, "P:%04x-%04x:%s\n", obj->mAddress - 0x8000, obj->mAddress - 0x8000 + obj->mSize - 1, obj->mIdent->mString); + } } else if (obj->mType == LOT_NATIVE_CODE) { if (!obj->mRegion->mCartridgeBanks) + { + if (obj->mRanges.Size() > 0) + { + for (int i = 0; i < obj->mRanges.Size(); i++) + fprintf(file, "P:%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset - 0x8000, obj->mIdent->mString, obj->mRanges[i].mIdent->mString); + } + fprintf(file, "P:%04x:%s\n", obj->mAddress - 0x8000, obj->mIdent->mString); + } } } } diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 3a6fcce..0b4bccf 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -37227,7 +37227,20 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) uint8* data = proc->mLinkerObject->AddSpace(total); for (int i = 0; i < placement.Size(); i++) + { + LinkerObjectRange range; + char buffer[100]; + if (placement[i]->mLoopHead) + sprintf_s(buffer, "l%d", placement[i]->mIndex); + else + sprintf_s(buffer, "s%d", placement[i]->mIndex); + + range.mIdent = Ident::Unique(buffer); + range.mOffset = placement[i]->mOffset; + range.mSize = placement[i]->mSize; + proc->mLinkerObject->mRanges.Push(range); placement[i]->CopyCode(this, data); + } for (int i = 0; i < mRelocations.Size(); i++)