Пример #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);
            }
        }
Пример #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));
 }
Пример #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));
 }
Пример #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
     });
Пример #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);
 }
Пример #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));
 }
Пример #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
     });
 }
Пример #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);
 }
Пример #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);
 }
Пример #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);
 }
Пример #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);
 }
Пример #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, ""));
     }
 }
Пример #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);
        }
Пример #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);
        }
Пример #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,
     });
 }
Пример #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);
        }
Пример #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()
     });
 }
Пример #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));
 }
Пример #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);
            }
Пример #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
                });
            }
Пример #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);
            }
Пример #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);
            }
Пример #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);
            }
Пример #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));
            }
Пример #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,
                    });
                }
            }
Пример #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,
                });
            }
Пример #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()
                });
            }
Пример #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);
 }
Пример #29
0
 private static bool Sw(uint b, Tlcs900Disassembler dasm)
 {
     dasm.ops.Add(new RegisterOperand(Tlcs900Registers.sr));
     return(true);
 }
Пример #30
0
 private static bool Jl(uint b, Tlcs900Disassembler dasm)
 {
     dasm.ops.Add(dasm.AbsoluteDestination(3));
     return(true);
 }