Ejemplo n.º 1
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(b, dasm))
                    {
                        return new Tlcs900Instruction
                               {
                                   Opcode  = Opcode.invalid,
                                   iclass  = iclass,
                                   Address = dasm.addr
                               }
                    }
                    ;
                }
                var instr = new Tlcs900Instruction
                {
                    Opcode  = opcode,
                    iclass  = iclass,
                    Address = dasm.addr,
                    op1     = dasm.ops.Count > 0 ? dasm.ops[0] : null,
                    op2     = dasm.ops.Count > 1 ? dasm.ops[1] : null,
                    op3     = dasm.ops.Count > 2 ? dasm.ops[2] : null,
                };

                return(instr);
            }
        }
Ejemplo n.º 2
0
 public override Tlcs900Instruction Decode(uint bPrev, Tlcs900Disassembler dasm)
 {
     if (!mutator(bPrev, dasm) || !dasm.rdr.TryReadByte(out byte b))
     {
         return(dasm.CreateInvalidInstruction());
     }
     return(memDecoders[b].Decode(b, dasm));
 }
Ejemplo n.º 3
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     if (!mutator(b, dasm) || !dasm.rdr.TryReadByte(out b))
     {
         return(dasm.Invalid());
     }
     return(memOpRecs[b].Decode(b, dasm));
 }
Ejemplo n.º 4
0
 public override Tlcs900Instruction Decode(uint b, Tlcs900Disassembler dasm)
 {
     return(new Tlcs900Instruction
     {
         Mnemonic = dasm.opSize !.Size == 2 ? Mnemonic.ldirw : Mnemonic.ldir,
         InstructionClass = InstrClass.Linear,
         Operands = new MachineOperand[0],
         Address = dasm.addr
     });
Ejemplo n.º 5
0
 // Relative jump
 private static bool jb(uint b, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadByte(out byte o8))
     {
         return(false);
     }
     dasm.ops.Add(AddressOperand.Create(dasm.rdr.Address + (sbyte)o8));
     return(true);
 }
Ejemplo n.º 6
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     dasm.opSrc = dasm.DecodeOperand(b, this.fmt);
     if (dasm.opSrc == null || !dasm.rdr.TryReadByte(out b))
     {
         return(dasm.Decode(b, Opcode.invalid, ""));
     }
     return(memOpRecs[b].Decode(b, dasm));
 }
Ejemplo n.º 7
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     return(new Tlcs900Instruction
     {
         Opcode = dasm.opSize.Size == 2 ? Opcode.ldirw : Opcode.ldir,
         iclass = InstrClass.Linear,
         Address = dasm.addr
     });
 }
Ejemplo n.º 8
0
 // immediate
 private static bool Ib(uint u, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadByte(out byte b))
     {
         return(false);
     }
     dasm.ops.Add(ImmediateOperand.Byte(b));
     return(true);
 }
Ejemplo n.º 9
0
 private static bool Iw(uint u, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadLeUInt16(out ushort w))
     {
         return(false);
     }
     dasm.ops.Add(ImmediateOperand.Word16(w));
     return(true);
 }
Ejemplo n.º 10
0
 private static bool Ix(uint u, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadLeUInt32(out u))
     {
         return(false);
     }
     dasm.ops.Add(ImmediateOperand.Word32(u));
     return(true);
 }
Ejemplo n.º 11
0
 private static bool jw(uint b, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadLeInt16(out short o16))
     {
         return(false);
     }
     dasm.ops.Add(AddressOperand.Create(dasm.rdr.Address + o16));
     return(true);
 }
Ejemplo n.º 12
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     if (dasm.opSize == 'w')
     {
         return(dasm.Decode(b, Opcode.ldirw, ""));
     }
     else
     {
         return(dasm.Decode(b, Opcode.ldir, ""));
     }
 }
Ejemplo n.º 13
0
        private static bool Jl(uint b, Tlcs900Disassembler dasm)
        {
            var dst = dasm.AbsoluteDestination(3);

            if (dst is null)
            {
                return(false);
            }
            dasm.ops.Add(dst);
            return(true);
        }
Ejemplo n.º 14
0
        private static bool C(uint b, Tlcs900Disassembler dasm)
        {
            // condition code
            var cc = (CondCode)(b & 0xF);

            if (cc != CondCode.T)
            {
                dasm.ops.Add(new ConditionOperand(cc));
            }
            return(true);
        }
Ejemplo n.º 15
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     dasm.opDst = dasm.DecodeOperand(b, this.fmt);
     if (dasm.opDst == null)
     {
         return(dasm.Decode(b, Opcode.invalid, ""));
     }
     return(new Tlcs900Instruction
     {
         Opcode = this.opcode,
         Address = dasm.addr,
         op1 = dasm.opSrc,
         op2 = dasm.opDst,
     });
 }
Ejemplo n.º 16
0
        private static bool Iz(uint u, Tlcs900Disassembler dasm)
        {
            if (dasm.opSize == null)
            {
                return(false);
            }
            switch (dasm.opSize.Size)
            {
            case 1: return(Ib(u, dasm));

            case 2: return(Iw(u, dasm));

            case 4: return(Ix(u, dasm));
            }
            return(false);
        }
Ejemplo n.º 17
0
 public override Tlcs900Instruction Decode(uint b, Tlcs900Disassembler dasm)
 {
     foreach (var m in mutators)
     {
         if (!m(b, dasm))
         {
             return(dasm.CreateInvalidInstruction());
         }
     }
     dasm.ops.Reverse();
     return(new Tlcs900Instruction
     {
         Mnemonic = this.mnemonic,
         Address = dasm.addr,
         Operands = dasm.ops.ToArray()
     });
 }
Ejemplo n.º 18
0
 public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
 {
     if (!dasm.rdr.TryReadByte(out b))
     {
         return(null);
     }
     dasm.opSize = width[0];
     dasm.opSrc  = dasm.ExtraRegister(b, width);
     if (dasm.opSrc == null)
     {
         return(null);
     }
     if (!dasm.rdr.TryReadByte(out b))
     {
         return(null);
     }
     return(regOpRecs[b].Decode(b, dasm));
 }
Ejemplo n.º 19
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                if (!mutator(b, dasm) || !dasm.rdr.TryReadByte(out b))
                {
                    return(dasm.Invalid());
                }
                var instr = dstOpRecs[b].Decode(b, dasm);

                if (instr.op1 != null && instr.op2 != null)
                {
                    instr.op1.Width = instr.op2.Width;
                }
                if (instr.op2 != null && instr.op2.Width == null)
                {
                    //$HACK to get conditional calls/jumps to work
                    instr.op2.Width = PrimitiveType.Word32;
                }
                return(instr);
            }
Ejemplo n.º 20
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(b, dasm))
                    {
                        return(dasm.Invalid());
                    }
                }
                bool swap = dasm.ops.Count == 2;

                return(new Tlcs900Instruction
                {
                    Opcode = this.opcode,
                    Address = dasm.addr,
                    op1 = swap ? dasm.ops[1] : dasm.ops[0],
                    op2 = swap ? dasm.ops[0] : null
                });
            }
Ejemplo n.º 21
0
            public override Tlcs900Instruction Decode(uint b, Tlcs900Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(b, dasm))
                    {
                        return(dasm.CreateInvalidInstruction());
                    }
                }
                var instr = new Tlcs900Instruction
                {
                    Mnemonic         = opcode,
                    InstructionClass = iclass,
                    Address          = dasm.addr,
                    Operands         = dasm.ops.ToArray()
                };

                return(instr);
            }
Ejemplo n.º 22
0
            public override Tlcs900Instruction Decode(uint bPrev, Tlcs900Disassembler dasm)
            {
                if (!mutator(bPrev, dasm) || !dasm.rdr.TryReadByte(out byte b))
                {
                    return(dasm.CreateInvalidInstruction());
                }
                var instr = dstDecoders[b].Decode(b, dasm);

                if (instr.Operands.Length >= 2)
                {
                    instr.Operands[0].Width = instr.Operands[1].Width;
                }
                if (instr.Operands.Length >= 2 && instr.Operands[1].Width == null)
                {
                    //$HACK to get conditional calls/jumps to work
                    instr.Operands[1].Width = PrimitiveType.Word32;
                }
                return(instr);
            }
Ejemplo n.º 23
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                dasm.opSrc = dasm.DecodeOperand(b, this.fmt);
                if (dasm.opSrc == null || !dasm.rdr.TryReadByte(out b))
                {
                    return(dasm.Decode(b, Opcode.invalid, ""));
                }
                var instr = dstOpRecs[b].Decode(b, dasm);

                if (instr.op1 != null && instr.op2 != null)
                {
                    instr.op1.Width = instr.op2.Width;
                }
                if (instr.op2 != null && instr.op2.Width == null)
                {
                    //$HACK to get conditional calls/jumps to work
                    instr.op2.Width = PrimitiveType.Word32;
                }
                return(instr);
            }
Ejemplo n.º 24
0
            public override Tlcs900Instruction Decode(uint bPrev, Tlcs900Disassembler dasm)
            {
                if (!dasm.rdr.TryReadByte(out byte b))
                {
                    return(null);
                }
                dasm.opSize = width;
                var op = dasm.ExtraRegister(b);

                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                if (!dasm.rdr.TryReadByte(out b))
                {
                    return(dasm.CreateInvalidInstruction());
                }
                dasm.ops.Add(op);
                return(regDecoders[b].Decode(b, dasm));
            }
Ejemplo n.º 25
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                if (this.fmt.Length == 0)
                {
                    return(new Tlcs900Instruction
                    {
                        Opcode = this.opcode,
                        Address = dasm.addr,
                        op1 = dasm.opSrc
                    });
                }

                if (this.fmt[0] == 'Z')
                {
                    // Override the size of opSrc
                    dasm.opSrc.Width = dasm.Size(fmt[1]);
                    return(new Tlcs900Instruction
                    {
                        Opcode = this.opcode,
                        Address = dasm.addr,
                        op1 = dasm.opSrc,
                    });
                }
                else
                {
                    dasm.opDst = dasm.DecodeOperand(b, this.fmt);
                    if (dasm.opDst == null)
                    {
                        return(dasm.Decode(b, Opcode.invalid, ""));
                    }
                    return(new Tlcs900Instruction
                    {
                        Opcode = this.opcode,
                        Address = dasm.addr,
                        op1 = dasm.opDst,
                        op2 = dasm.opSrc,
                    });
                }
            }
Ejemplo n.º 26
0
            public override Tlcs900Instruction Decode(byte b, Tlcs900Disassembler dasm)
            {
                if (this.mutator == null)
                {
                    return(new Tlcs900Instruction
                    {
                        Opcode = this.opcode,
                        Address = dasm.addr,
                        op1 = dasm.ops[0]
                    });
                }

                if (!mutator(b, dasm))
                {
                    return(dasm.Invalid());
                }
                return(new Tlcs900Instruction
                {
                    Opcode = this.opcode,
                    Address = dasm.addr,
                    op1 = dasm.ops.Count > 1 ? dasm.ops[1] : dasm.ops[0],
                    op2 = dasm.ops.Count > 1 ? dasm.ops[0] : null,
                });
            }
Ejemplo n.º 27
0
            public override Tlcs900Instruction Decode(uint bPrev, Tlcs900Disassembler dasm)
            {
                if (this.mutator == null)
                {
                    return(new Tlcs900Instruction
                    {
                        Mnemonic = this.mnemonic,
                        Address = dasm.addr,
                        Operands = dasm.ops.ToArray()
                    });
                }

                if (!mutator(bPrev, dasm))
                {
                    return(dasm.CreateInvalidInstruction());
                }
                dasm.ops.Reverse();
                return(new Tlcs900Instruction
                {
                    Mnemonic = this.mnemonic,
                    Address = dasm.addr,
                    Operands = dasm.ops.ToArray()
                });
            }
Ejemplo n.º 28
0
 private static bool BW(uint b, Tlcs900Disassembler dasm)
 {
     // Opsize must be set to byte or word16.
     return(dasm.opSize.Size == 1 || dasm.opSize.Size == 2);
 }
Ejemplo n.º 29
0
 private static bool Sw(uint b, Tlcs900Disassembler dasm)
 {
     dasm.ops.Add(new RegisterOperand(Tlcs900Registers.sr));
     return(true);
 }
Ejemplo n.º 30
0
 private static bool Jl(uint b, Tlcs900Disassembler dasm)
 {
     dasm.ops.Add(dasm.AbsoluteDestination(3));
     return(true);
 }