Added decoding of rrc-as debug annotations
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
aa883d3f87
commit
f5ce6a92ce
|
@ -232,6 +232,7 @@ void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
|
|||
break;
|
||||
}
|
||||
|
||||
state.setRegister((uint32_t)KnownRegisters::BSM_CTRL, (state.getRegister((uint32_t)KnownRegisters::BSM_CTRL) & 0xFF) | ((instruction->getEndAddress()) << 8)); // Set EepromAddr as next address
|
||||
auto possibleBranches = instruction->execute(state);
|
||||
|
||||
if ((instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP ||
|
||||
|
|
|
@ -64,6 +64,8 @@ std::string getRegisterName(KnownRegisters addr) {
|
|||
return "INTERRUPT_MASK_BSM";
|
||||
case KnownRegisters::CHIP_VERSION:
|
||||
return "CHIP_VERSION";
|
||||
case KnownRegisters::BSM_CTRL:
|
||||
return "BSM_CTRL";
|
||||
case KnownRegisters::BSM_ARGS:
|
||||
return "BSM_ARGS";
|
||||
case KnownRegisters::BSM_ADDR_OFFSET_0:
|
||||
|
|
|
@ -62,6 +62,7 @@ enum class KnownRegisters : uint32_t {
|
|||
BSM_SCRATCH_START = 0x800,
|
||||
BSM_SCRATCH_END = BSM_SCRATCH_START + 0x400 - 1,
|
||||
|
||||
BSM_CTRL = 0x000C00,
|
||||
BSM_ARGS = 0x000C01,
|
||||
|
||||
BSM_ADDR_OFFSET_0 = 0x000C04,
|
||||
|
|
|
@ -182,7 +182,7 @@ std::vector<Instruction::OutputFormat> Instruction::Load::toOutputFormat(const O
|
|||
dynamic_cast<std::stringstream &>(std::stringstream("") << " "
|
||||
<< context.getAddressRegisterName(
|
||||
address +
|
||||
offset - 2,
|
||||
(increment ? offset - 2 : 0),
|
||||
addressOffset)
|
||||
<< " = 0x" << std::hex
|
||||
<< std::setw(8)
|
||||
|
|
67
src/main.cpp
67
src/main.cpp
|
@ -34,6 +34,7 @@
|
|||
#include "Registers.h"
|
||||
#include "instructions/Load.h"
|
||||
#include "OutputContext.h"
|
||||
#include "instructions/End.h"
|
||||
|
||||
void decodeImage(const std::string &fileName) {
|
||||
|
||||
|
@ -264,6 +265,72 @@ void decodeImage(const std::string &fileName) {
|
|||
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool isKnownAssembler = false;
|
||||
if (imageObject.imageSignature.find("rrc-as") != std::string::npos) {
|
||||
//Known assembler
|
||||
isKnownAssembler = true;
|
||||
comments.clear();
|
||||
knownNames.clear();
|
||||
|
||||
for (auto& i : imageObject.getInstructions()){
|
||||
std::unique_ptr<Instruction::Instruction> decodedInstruction = nullptr;
|
||||
std::unique_ptr<Instruction::Instruction> decodedInstruction2 = nullptr;
|
||||
const Instruction::End* endPointer = nullptr;
|
||||
if(i.second->getCommand() == Instruction::Instruction::CommandOp::END){
|
||||
endPointer = reinterpret_cast<const Instruction::End*>(i.second.get());
|
||||
if(endPointer->reserved == 0 || endPointer->reserved == 0xFFFFFF){
|
||||
endPointer = nullptr;
|
||||
}
|
||||
}
|
||||
if(endPointer == nullptr && imageObject.findConstInstructionByAddress(i.second->getEndAddress(), false) == nullptr){
|
||||
decodedInstruction = Instruction::Instruction::decodeInstructionFromBytes(i.second->getEndAddress(), imageObject.getBaseImage());
|
||||
if(decodedInstruction != nullptr && decodedInstruction->getCommand() == Instruction::Instruction::CommandOp::END){
|
||||
endPointer = reinterpret_cast<const Instruction::End*>(decodedInstruction.get());
|
||||
if(endPointer->reserved == 0 || endPointer->reserved == 0xFFFFFF){
|
||||
endPointer = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(endPointer != nullptr){ //Found backwards pointer
|
||||
decodedInstruction2 = Instruction::Instruction::decodeInstructionFromBytes(endPointer->getEndAddress(), imageObject.getBaseImage());
|
||||
if(decodedInstruction2 != nullptr && decodedInstruction2->getCommand() == Instruction::Instruction::CommandOp::LOAD){
|
||||
auto loadPointer = reinterpret_cast<const Instruction::Load&>(*decodedInstruction2);
|
||||
if(!loadPointer.increment && loadPointer.addressOffset == 0 && loadPointer.address == endPointer->getAddress()){ //found Function name
|
||||
uint32_t functionStart = endPointer->reserved;
|
||||
uint32_t functionEnd = loadPointer.address - 4;
|
||||
std::string functionName;
|
||||
for(auto& d : loadPointer.data){
|
||||
uint8_t c = ((d >> 24) & 0xFF);
|
||||
if(c == 0){
|
||||
break;
|
||||
}
|
||||
functionName.push_back(c);
|
||||
c = ((d >> 16) & 0xFF);
|
||||
if(c == 0){
|
||||
break;
|
||||
}
|
||||
functionName.push_back(c);
|
||||
c = ((d >> 8) & 0xFF);
|
||||
if(c == 0){
|
||||
break;
|
||||
}
|
||||
functionName.push_back(c);
|
||||
c = (d & 0xFF);
|
||||
if(c == 0){
|
||||
break;
|
||||
}
|
||||
functionName.push_back(c);
|
||||
}
|
||||
knownNames[functionStart] = functionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &e : knownNames) {
|
||||
ctx.addMapping(e.first, e.second);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue