private void RunTest(params string[] bitStrings) { var bytes = bitStrings.Select(bits => base.ParseBitPattern(bits)) .SelectMany(u => new byte[] { (byte) (u >> 24), (byte) (u >> 16), (byte) (u >> 8), (byte) u }) .ToArray(); dasm = new MipsDisassembler(arch, new BeImageReader(new LoadedImage(Address.Ptr32(0x00100000), bytes), 0)); }
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { var instr = base.Decode(wInstr, dasm); var imm = instr.op3 as ImmediateOperand; if (imm != null && imm.Value.IsIntegerZero) return new MipsInstruction { Address = instr.Address, Length = instr.Length, opcode = Opcode.nop }; else return instr; }
protected override MemoryArea RewriteCode(uint[] words) { byte[] bytes = words.SelectMany(w => new byte[] { (byte) (w >> 24), (byte) (w >> 16), (byte) (w >> 8), (byte) w }).ToArray(); var image = new MemoryArea(LoadAddress, bytes); dasm = new MipsDisassembler(arch, image.CreateBeReader(LoadAddress)); return image; }
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { return dasm.DecodeOperands(opcode, wInstr, format); }
internal abstract MipsInstruction Decode(uint wInstr, MipsDisassembler dasm);
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { var opcode = opcodes[(wInstr >> 16) & 0x1F]; return dasm.DecodeOperands(opcode, wInstr, "R1,j"); }
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { Debug.Assert(specialOpRecs.Length == 64, specialOpRecs.Length.ToString()); var opRec = specialOpRecs[wInstr & 0x3F]; Debug.Print(" SpecialOpRec {0:X8} => oprec {1} {2}", wInstr, wInstr & 0x3F, opRec == null ? "(null!)" : ""); return opRec.Decode(wInstr, dasm); }
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { return oprecs[(wInstr>>21) & 0x1F].Decode(wInstr, dasm); }
internal override MipsInstruction Decode(uint wInstr, MipsDisassembler dasm) { var opcode = ((wInstr & (1u << 16)) != 0) ? opTrue : opFalse; return dasm.DecodeOperands(opcode, wInstr, "c18,j"); }
private void UpdateText() { if (PcListBox.SelectedItem != null) { var PCItem = (PCItem)PcListBox.SelectedItem; var MethodCacheInfo = PCItem.MethodCacheInfo; var MinPC = MethodCacheInfo.MinPc; var MaxPC = MethodCacheInfo.MaxPc; var Memory = CpuProcessor.Memory; AstNodeStm Node = null; if (MethodCacheInfo.AstTree != null) { Node = MethodCacheInfo.AstTree.Optimize(CpuProcessor); } var InfoLines = new List <string>(); InfoLines.Add($"Name: {MethodCacheInfo.Name}"); InfoLines.Add($"TotalInstructions: {MethodCacheInfo.TotalInstructions}"); InfoLines.Add($"DisableOptimizations: {MethodCacheInfo.DynarecFunction.DisableOptimizations}"); InfoLines.Add($"EntryPC: 0x{MethodCacheInfo.EntryPc:X8}"); InfoLines.Add($"MinPC: 0x{MethodCacheInfo.MinPc:X8}"); InfoLines.Add($"MaxPC: 0x{MethodCacheInfo.MaxPc:X8}"); InfoLines.Add( $"TimeAnalyzeBranches: {MethodCacheInfo.DynarecFunction.TimeAnalyzeBranches.TotalMilliseconds}"); InfoLines.Add($"TimeGenerateAst: {MethodCacheInfo.DynarecFunction.TimeGenerateAst.TotalMilliseconds}"); InfoLines.Add($"TimeOptimize: {MethodCacheInfo.DynarecFunction.TimeOptimize.TotalMilliseconds}"); InfoLines.Add($"TimeGenerateIL: {MethodCacheInfo.DynarecFunction.TimeGenerateIl.TotalMilliseconds}"); InfoLines.Add( $"TimeCreateDelegate: {MethodCacheInfo.DynarecFunction.TimeCreateDelegate.TotalMilliseconds}"); InfoLines.Add($"TimeLinking: {MethodCacheInfo.DynarecFunction.TimeLinking.TotalMilliseconds}"); InfoLines.Add($"TimeTotal: {MethodCacheInfo.DynarecFunction.TimeTotal.TotalMilliseconds}"); InfoLines.Add(string.Format("")); foreach (var Item in MethodCacheInfo.DynarecFunction.InstructionStats.OrderBy(Pair => Pair.Value)) { InfoLines.Add($"{Item.Key}: {Item.Value}"); } InfoTextBox.Text = string.Join("\r\n", InfoLines); var OutString = ""; switch (LanguageComboBox.SelectedItem.ToString()) { case "C#": if (Node != null) { OutString = Node.ToCSharpString().Replace("CpuThreadState.", ""); } break; case "IL": if (Node != null) { OutString = Node.ToIlString <Action <CpuThreadState> >(); } break; case "Ast": if (Node != null) { OutString = AstSerializer.SerializeAsXml(Node); } break; case "Mips": { var MipsDisassembler = new MipsDisassembler(); try { for (uint PC = MinPC; PC <= MaxPC; PC += 4) { var Instruction = Memory.ReadSafe <Instruction>(PC); var Result = MipsDisassembler.Disassemble(PC, Instruction); OutString += $"0x{PC:X8}: {Result.ToString()}\r\n"; } } catch (Exception Exception) { Console.Error.WriteLine(Exception); } } break; default: break; } ViewTextBox.Text = OutString.Replace("\n", "\r\n"); } }