Beispiel #1
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(string.Format("{0}{1}{2}",
         Opcode,
         Cond != Condition.al ? Cond.ToString() : "",
         OpFlags != OpFlags.None ? OpFlags.ToString().ToLower() : ""));
     if (Dst != null)
     {
         writer.Tab();
         Write(Dst, writer);
         if (Update) writer.Write("!");
         if (Src1 != null)
         {
             writer.Write(",");
             Write(Src1, writer);
             if (Src2 != null)
             {
                 writer.Write(",");
                 Write(Src2, writer);
                 if (Src3 != null)
                 {
                     writer.Write(",");
                     Write(Src3, writer);
                 }
             }
         }
     }
 }
Beispiel #2
0
 public override void Render(MachineInstructionWriter writer)
 {
     if (instruction == null)
     {
         writer.Write("Invalid");
         return;
     }
     writer.WriteOpcode(instruction.Mnemonic);
     var ops = instruction.ArchitectureDetail.Operands;
     if (ops.Length < 1)
         return;
     writer.Tab();
     if (WriteRegisterSetInstruction(writer))
         return;
     Write(ops[0], writer);
     if (ops.Length < 2)
         return;
     writer.Write(",");
     Write(ops[1], writer);
     if (ops.Length < 3)
         return;
     writer.Write(",");
     Write(ops[2], writer);
     if (ops.Length < 4)
         return;
     writer.Write(",");
     Write(ops[3], writer);
 }
Beispiel #3
0
 public override void Render(MachineInstructionWriter writer)
 {
     if (code == Opcode.illegal && op1 != null && writer.Platform != null)
     {
         var imm = op1 as M68kImmediateOperand;
         // MacOS uses invalid opcodes to invoke Macintosh Toolbox services. 
         // We may have to generalize the Platform API to allow specifying 
         // the opcode of the invoking instruction, to disambiguate from 
         // "legitimate" TRAP calls.
         var svc = writer.Platform.FindService((int)imm.Constant.ToUInt32(), null);
         if (svc != null)
         {
             writer.Write(svc.Name);
             return;
         }
     }
     if (dataWidth != null)
     {
         writer.WriteOpcode(string.Format("{0}{1}", code, DataSizeSuffix(dataWidth)));
     }
     else
     {
         writer.WriteOpcode(code.ToString());
     }
     writer.Tab();
     if (op1 != null)
     {
         op1.Write(false, writer);
         if (op2 != null)
         {
             writer.Write(',');
             op2.Write(false, writer);
         }
     }
 }
Beispiel #4
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(Code.ToString());
     if (Operand != null)
     {
         writer.Tab();
         Operand.Write(true, writer);
     }
 }
Beispiel #5
0
 public override void Render(MachineInstructionWriter writer)
 {
     if (Code == Opcode.ex_af)
     {
         writer.WriteOpcode("ex");
         writer.Tab();
         writer.Write("af,af'");
         return;
     }
     writer.WriteOpcode(Code.ToString());
     if (Op1 != null)
     {
         writer.Tab();
         Op1.Write(true, writer);
         if (Op2 != null)
         {
             writer.Write(",");
             Op2.Write(true, writer);
         }
     }
 }
Beispiel #6
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(Opcode.ToString());
     if (op1 != null)
     {
         writer.Tab();
         OpToString(op1, writer);
         if (op2 != null)
         {
             writer.Write(",");
             OpToString(op2, writer);
         }
     }
 }
Beispiel #7
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(opcode.ToString());
     if (operands.Length > 0)
     {
         writer.Tab();
         writer.Write(operands[0].ToString());
         if (operands.Length > 1)
         {
             writer.Write(",");
             writer.Write(operands[1].ToString());
         }
     }
 }
Beispiel #8
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(this.Opcode.ToString());
     writer.Tab();
     bool sep = false; 
     foreach (var op in Operands)
     {
         if (sep)
             writer.Write(',');
         sep = true;
         if (op is ImmediateOperand)
             writer.Write('#');
         op.Write(false, writer);
     }
 }
Beispiel #9
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(Opcode.ToString());
     if (op1 == null)
         return;
     writer.Tab();
     op1.Write(false, writer);
     if (op2 == null)
         return;
     writer.Write(",");
     op2.Write(false, writer);
     if (op3 == null)
         return;
     writer.Write(",");
     op3.Write(false, writer);
 }
Beispiel #10
0
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(opcode.ToString());
     if (op1 != null)
     {
         writer.Tab();
         op1.Write(true, writer);
         if (op2 != null)
         {
             writer.Write(',');
             op2.Write(true, writer);
             if (op3 != null)
             {
                 writer.Write(',');
                 op3.Write(true, writer);
             }
         }
     }
 }
Beispiel #11
0
 public override void Render(MachineInstructionWriter writer)
 {
     string instrName;
     if (!instrNames.TryGetValue(Opcode, out instrName))
     {
         instrName = Opcode.ToString();
     }
     writer.WriteOpcode(instrName);
     writer.Tab();
     var sep = "";
     if (this.Operands != null)
     {
         foreach (var op in this.Operands)
         {
             writer.Write(sep);
             op.Write(false, writer);
             sep = ",";
         }
     }
 }
 public override void Render(MachineInstructionWriter writer)
 {
     writer.WriteOpcode(instruction.Mnemonic);
     var ops = Internal.ArchitectureDetail.Operands;
     if (ops.Length < 1)
         return;
     writer.Tab();
     Write(ops[0], writer);
     if (ops.Length < 2)
         return;
     writer.Write(",");
     Write(ops[1], writer);
     if (ops.Length < 3)
         return;
     writer.Write(",");
     Write(ops[2], writer);
     if (ops.Length < 4)
         return;
     writer.Write(",");
     Write(ops[3], writer);
 }
Beispiel #13
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            string instrName;

            if (!instrNames.TryGetValue(Opcode, out instrName))
            {
                instrName = Opcode.ToString();
            }
            writer.WriteOpcode(instrName);
            writer.Tab();
            var sep = "";

            if (this.Operands != null)
            {
                foreach (var op in this.Operands)
                {
                    writer.Write(sep);
                    op.Write(writer, options);
                    sep = ",";
                }
            }
        }
Beispiel #14
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            var bankmem = Operands[0] as PICOperandBankedMemory ?? throw new InvalidOperationException($"Invalid memory operand: {Operands[0]}");
            var bitno   = Operands[1] as PICOperandMemBitNo ?? throw new InvalidOperationException($"Invalid bit number operand: {Operands[1]}");

            writer.WriteOpcode(Opcode.ToString());
            writer.Tab();

            if (PICRegisters.TryGetAlwaysAccessibleRegister(bankmem.Offset, out var reg))
            {
                writer.WriteString($"{reg.Name}");
                writer.WriteString(",");
                if (PICRegisters.TryGetBitField(reg, out var fld, bitno.BitNo, 1))
                {
                    writer.WriteString($"{fld.Name}");
                }
                else
                {
                    bitno.Write(writer, options);
                }
                return;
            }
Beispiel #15
0
 public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
 {
     writer.WriteOpcode(Opcode.ToString());
     if (Operand1 == null)
     {
         return;
     }
     writer.Tab();
     Operand1.Write(writer, options);
     if (Operand2 == null)
     {
         return;
     }
     writer.WriteString(",");
     Operand2.Write(writer, options);
     if (Operand3 == null)
     {
         return;
     }
     writer.WriteString(",");
     Operand3.Write(writer, options);
 }
Beispiel #16
0
 public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
 {
     writer.WriteOpcode(this.Opcode.ToString());
     if (op1 == null)
     {
         return;
     }
     writer.Tab();
     op1.Write(writer, options);
     if (op2 == null)
     {
         return;
     }
     writer.WriteChar(',');
     op2.Write(writer, options);
     if (op3 == null)
     {
         return;
     }
     writer.WriteChar(',');
     op3.Write(writer, options);
 }
Beispiel #17
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            if (instruction == null)
            {
                writer.Write("Invalid");
                return;
            }
            writer.WriteOpcode(instruction.Mnemonic);
            var ops = instruction.ArchitectureDetail.Operands;

            if (ops.Length < 1)
            {
                return;
            }
            writer.Tab();
            if (WriteRegisterSetInstruction(writer))
            {
                return;
            }
            Write(ops[0], writer, options);
            if (ops.Length < 2)
            {
                return;
            }
            writer.Write(",");
            Write(ops[1], writer, options);
            if (ops.Length < 3)
            {
                return;
            }
            writer.Write(",");
            Write(ops[2], writer, options);
            if (ops.Length < 4)
            {
                return;
            }
            writer.Write(",");
            Write(ops[3], writer, options);
        }
Beispiel #18
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            writer.WriteOpcode(this.Opcode.ToString());
            writer.Tab();
            bool sep = false;

            foreach (var op in Operands)
            {
                if (sep)
                {
                    writer.WriteChar(',');
                }
                sep = true;
                if (op is ImmediateOperand)
                {
                    writer.WriteChar('#');
                    op.Write(writer, options);
                }
                else if (op is MemoryOperand && ((MemoryOperand)op).Base == Registers.pc)
                {
                    var addr = this.Address + (this.Length + ((MemoryOperand)op).Offset.ToInt32());
                    if ((options & MachineInstructionWriterOptions.ResolvePcRelativeAddress) != 0)
                    {
                        writer.WriteAddress(addr.ToString(), addr);
                        writer.AddAnnotation(op.ToString());
                    }
                    else
                    {
                        op.Write(writer, options);
                        writer.AddAnnotation(addr.ToString());
                    }
                }
                else
                {
                    op.Write(writer, options);
                }
            }
        }
Beispiel #19
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            if (repeatReg != null)
            {
                writer.WriteOpcode("rpt");
                writer.WriteString(" ");
                writer.WriteString(repeatReg.Name);
                writer.WriteString(" ");
            }
            else if (repeatImm > 1)
            {
                writer.WriteOpcode("rpt");
                writer.WriteString(" #");
                writer.WriteString(repeatImm.ToString());
                writer.WriteString(" ");
            }
            var sb = new StringBuilder(opcode.ToString());

            if (dataWidth != null)
            {
                sb.AppendFormat(".{0}", dataWidth.BitSize == 8
                    ? "b"
                    : dataWidth.BitSize == 16
                        ? "w"
                        : "a");
            }
            writer.WriteOpcode(sb.ToString());
            if (op1 != null)
            {
                writer.Tab();
                Write(op1, writer, options);
                if (op2 != null)
                {
                    writer.WriteString(",");
                    Write(op2, writer, options);
                }
            }
        }
Beispiel #20
0
        public override void Render(MachineInstructionWriter writer)
        {
            writer.WriteOpcode(
                string.Format("{0}{1}",
                Opcode.ToString(),
                Annul ? ",a" : ""));

            if (Op1 != null)
            {
                writer.Tab();
                Write(Op1, writer);
                if (Op2 != null)
                {
                    writer.Write(',');
                    Write(Op2, writer);
                    if (Op3 != null)
                    {
                        writer.Write(',');
                        Write(Op3, writer);
                    }
                }
            }
        }
Beispiel #21
0
        public override void Render(MachineInstructionWriter writer)
        {
            writer.WriteOpcode(
                string.Format("{0}{1}",
                              Opcode.ToString(),
                              Annul ? ",a" : ""));

            if (Op1 != null)
            {
                writer.Tab();
                Write(Op1, writer);
                if (Op2 != null)
                {
                    writer.Write(',');
                    Write(Op2, writer);
                    if (Op3 != null)
                    {
                        writer.Write(',');
                        Write(Op3, writer);
                    }
                }
            }
        }
Beispiel #22
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            if (!instrNames.TryGetValue(opcode, out string name))
            {
                name = opcode.ToString();
            }
            writer.WriteOpcode(name);

            if (op1 != null)
            {
                writer.Tab();
                op1.Write(writer, options);
                if (op2 != null)
                {
                    writer.WriteChar(',');
                    op2.Write(writer, options);
                    if (op3 != null)
                    {
                        writer.WriteChar(',');
                        op3.Write(writer, options);
                    }
                }
            }
        }
Beispiel #23
0
 public override void Render(MachineInstructionWriter writer)
 {
     string name;
     if (!opcodeNames.TryGetValue(opcode, out name))
     {
         name = opcode.ToString();
     }
     writer.WriteOpcode(name);
     if (op1 == null)
         return;
     writer.Tab();
     WriteOp(op1, writer);
     if (op2 == null)
         return;
     writer.Write(',');
     WriteOp(op2, writer);
     if (op3 == null)
         return;
     writer.Write(',');
     WriteOp(op3, writer);
 }
Beispiel #24
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            if (repPrefix == 3)
            {
                writer.WriteOpcode("rep");
                writer.WriteChar(' ');
            }
            else if (repPrefix == 2)
            {
                writer.WriteOpcode("repne");
                writer.WriteChar(' ');
            }

            // Get opcode.

            string s = code.ToString();

            switch (code)
            {
            case Opcode.cwd:
                if (dataWidth == PrimitiveType.Word32)
                {
                    s = "cdq";
                }
                break;

            case Opcode.cbw:
                if (dataWidth == PrimitiveType.Word32)
                {
                    s = "cwde";
                }
                break;

            case Opcode.ins:
            case Opcode.outs:
            case Opcode.movs:
            case Opcode.cmps:
            case Opcode.stos:
            case Opcode.lods:
            case Opcode.scas:
                switch (dataWidth.Size)
                {
                case 1: s += 'b'; break;

                case 2: s += 'w'; break;

                case 4: s += 'd'; break;

                case 8: s += 'q'; break;

                default: throw new ArgumentOutOfRangeException();
                }
                break;
            }
            writer.WriteOpcode(s);

            if (NeedsExplicitMemorySize())
            {
                options |= MachineInstructionWriterOptions.ExplicitOperandSize;
            }

            if (Operands >= 1)
            {
                writer.Tab();
                Write(op1, writer, options);
                if (Operands >= 2)
                {
                    writer.WriteChar(',');
                    Write(op2, writer, options);
                    if (Operands >= 3)
                    {
                        writer.WriteString(",");
                        Write(op3, writer, options);
                    }
                }
            }
        }
Beispiel #25
0
 public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
 {
     writer.WriteOpcode(Mnemonic.ToString());
     writer.Tab();
     Operands[0].Write(writer, options);
 }
Beispiel #26
0
 public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
 {
     writer.WriteOpcode(Opcode.ToString());
     writer.Tab();
     op1.Write(writer, options);
 }
Beispiel #27
0
 public override void Render(MachineInstructionWriter writer)
 {
     var op = string.Format("{0}{1}", 
         opcode,
         setsCR0 ? "." : "");
     writer.WriteOpcode(op);
     if (op1 != null)
     {
         writer.Tab();
         op1.Write(true, writer);
         if (op2 != null)
         {
             writer.Write(',');
             op2.Write(true, writer);
             if (op3 != null)
             {
                 writer.Write(',');
                 op3.Write(true, writer);
                 if (op4 != null)
                 {
                     writer.Write(",");
                     op4.Write(true, writer);
                     if (op5 != null)
                     {
                         writer.Write(",");
                         op5.Write(true, writer);
                     }
                 }
             }
         }
     }
 }
Beispiel #28
0
        public override void Render(MachineInstructionWriter writer)
        {
            // Get opcode.

            string s = code.ToString();

            switch (code)
            {
            case Opcode.cwd:
                if (dataWidth == PrimitiveType.Word32)
                {
                    s = "cdq";
                }
                break;

            case Opcode.cbw:
                if (dataWidth == PrimitiveType.Word32)
                {
                    s = "cwde";
                }
                break;

            case Opcode.ins:
            case Opcode.outs:
            case Opcode.movs:
            case Opcode.cmps:
            case Opcode.stos:
            case Opcode.lods:
            case Opcode.scas:
                switch (dataWidth.Size)
                {
                case 1: s += 'b'; break;

                case 2: s += 'w'; break;

                case 4: s += 'd'; break;

                case 8: s += 'q'; break;

                default: throw new ArgumentOutOfRangeException();
                }
                break;
            }
            writer.WriteOpcode(s);
            writer.Tab();

            bool fExplicit = NeedsExplicitMemorySize();

            if (Operands >= 1)
            {
                op1.Write(fExplicit, writer);
                if (Operands >= 2)
                {
                    writer.Write(',');
                    op2.Write(fExplicit, writer);
                    if (Operands >= 3)
                    {
                        writer.Write(",");
                        op3.Write(fExplicit, writer);
                    }
                }
            }
        }
Beispiel #29
0
        public override void Render(MachineInstructionWriter writer)
        {
			// Get opcode. 

			string s = code.ToString();
			switch (code)
			{
			case Opcode.cwd:
				if (dataWidth == PrimitiveType.Word32)
				{
					s = "cdq";
				}
				break;
			case Opcode.cbw:
				if (dataWidth == PrimitiveType.Word32)
				{
					s = "cwde";
				}
				break;
			case Opcode.ins:
			case Opcode.outs:
			case Opcode.movs:
			case Opcode.cmps:
			case Opcode.stos:
			case Opcode.lods:
			case Opcode.scas:
				switch (dataWidth.Size)
				{
				case 1: s += 'b'; break;
				case 2: s += 'w'; break;
				case 4: s += 'd'; break;
				default: throw new ArgumentOutOfRangeException();
				}
				break;
			}
			writer.WriteOpcode(s);
			writer.Tab();

			bool fExplicit = NeedsExplicitMemorySize();

			if (Operands >= 1)
			{
				op1.Write(fExplicit, writer);
				if (Operands >= 2)
				{
					writer.Write(',');
					op2.Write(fExplicit, writer);
					if (Operands >= 3)
					{
						writer.Write(",");
						op3.Write(fExplicit, writer);
					}
				}
			}
		}