static int avrdis (char *out, ut64 addr, cut8 *buf, int len) { formattingOptions opt = { 0 }; disassembledInstruction dins; assembledInstruction ins; AVR_Long_Instruction = 0; AVR_Long_Address = 0; ins.address = addr; ins.opcode = (buf[1]<<8) | buf[0] | (buf[2]<<16) | (buf[3]<<24); if (disassembleInstruction (&dins, ins)) { strcpy (out, "invalid"); return -1; } if (AVR_Long_Instruction) { ins.address = addr; ins.opcode = (buf[3]<<8) | (buf[2]); /* (buf[3]<<24) | (buf[2]<<16) | \ (buf[1]<<8) | (buf[0]); */ if (disassembleInstruction (&dins, ins)) { strcpy (out, "invalid"); return -1; } printDisassembledInstruction (out, dins, opt); return 4; } printDisassembledInstruction (out, dins, opt); //printf ("0x%08"PFMT64x" %s\n", addr, out); return 2; }
// Loop over all the instructions, in order, processing each. // Boiler plate for each is handled here directly, the rest is dispatched. void SpirvStream::processInstructions() { // Instructions while (word < size) { int instructionStart = word; // Instruction wordCount and opcode unsigned int firstWord = stream[word]; unsigned wordCount = firstWord >> WordCountShift; Op opCode = (Op)(firstWord & OpCodeMask); int nextInst = word + wordCount; ++word; // Presence of full instruction if (nextInst > size) Kill(out, "stream instruction terminated too early"); // Base for computing number of operands; will be updated as more is learned unsigned numOperands = wordCount - 1; // Type <id> Id typeId = 0; if (InstructionDesc[opCode].hasType()) { typeId = stream[word++]; --numOperands; } // Result <id> Id resultId = 0; if (InstructionDesc[opCode].hasResult()) { resultId = stream[word++]; --numOperands; // save instruction for future reference idInstruction[resultId] = instructionStart; } outputResultId(resultId); outputTypeId(typeId); outputIndent(); // Hand off the Op and all its operands disassembleInstruction(resultId, typeId, opCode, numOperands); if (word != nextInst) { out << " ERROR, incorrect number of operands consumed. At " << word << " instead of " << nextInst << " instruction start was " << instructionStart; word = nextInst; } out << std::endl; } }
int avrdis (char *out, ut64 addr, cut8 *buf, int len) { formattingOptions opt = { 0 }; disassembledInstruction dins; assembledInstruction ins; ins.address = addr; ins.opcode = (buf[1]<<8) | buf[0]; if (disassembleInstruction (&dins, ins)) { fprintf (stderr, "FAIL\n"); return -1; } printDisassembledInstruction (out, dins, opt); //printf ("0x%08"PFMT64x" %s\n", addr, out); return 2; }