Example #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);
            }
        }
Example #2
0
 public Tlcs900Rewriter(Tlcs900Architecture arch, EndianImageReader rdr, ProcessorState state, IStorageBinder binder, IRewriterHost host)
 {
     this.arch   = arch;
     this.rdr    = rdr;
     this.state  = state;
     this.binder = binder;
     this.host   = host;
     this.dasm   = new Tlcs900Disassembler(this.arch, rdr).GetEnumerator();
     this.instr  = null !;
     this.m      = null !;
 }
Example #3
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);
            }
Example #4
0
        public IEnumerator <RtlInstructionCluster> GetEnumerator()
        {
            while (dasm.MoveNext())
            {
                iclass = InstrClass.Linear;
                var instrs = new List <RtlInstruction>();
                m          = new RtlEmitter(instrs);
                this.instr = dasm.Current;
                switch (instr.Mnemonic)
                {
                default:
                    host.Warn(
                        instr.Address,
                        string.Format(
                            "TLCS-900 instruction '{0}' not supported yet.",
                            instr.Mnemonic));
                    EmitUnitTest();
                    Invalid();
                    break;

                case Mnemonic.invalid:
                    Invalid();
                    break;

                case Mnemonic.adc: RewriteAdcSbc(m.IAdd, "****0*"); break;

                case Mnemonic.add: RewriteBinOp(m.IAdd, "***V0*"); break;

                case Mnemonic.and: RewriteBinOp(m.And, "**1*00"); break;

                case Mnemonic.bit: RewriteBit(); break;

                case Mnemonic.bs1b: RewriteBs1b(); break;

                case Mnemonic.call: RewriteCall(); break;

                case Mnemonic.calr: RewriteCall(); break;

                case Mnemonic.ccf: RewriteCcf(); break;

                case Mnemonic.chg: RewriteChg(); break;

                case Mnemonic.cp: RewriteCp("SZHV1C"); break;

                case Mnemonic.daa: RewriteDaa("****-*"); break;

                case Mnemonic.dec: RewriteIncDec(m.ISub, "****1-"); break;

                case Mnemonic.decf: RewriteDecf(); break;

                case Mnemonic.div: RewriteDiv(m.UDiv, "---V--"); break;

                case Mnemonic.divs: RewriteDiv(m.SDiv, "---V--"); break;

                case Mnemonic.djnz: RewriteDjnz(); break;

                case Mnemonic.ei: RewriteEi(); break;

                case Mnemonic.ex: RewriteEx(); break;

                case Mnemonic.halt: RewriteHalt(); break;

                case Mnemonic.inc: RewriteIncDec(m.IAdd, "****0-"); break;

                case Mnemonic.incf: RewriteIncf(); break;

                case Mnemonic.lda: RewriteLda(); break;

                case Mnemonic.jp: RewriteJp(); break;

                case Mnemonic.jr: RewriteJp(); break;

                case Mnemonic.ld: RewriteLd(); break;

                case Mnemonic.ldf: RewriteLdf(); break;

                case Mnemonic.ldir: RewriteLdir(PrimitiveType.Byte, "--000-"); break;

                case Mnemonic.ldirw: RewriteLdir(PrimitiveType.Word16, "--000-"); break;

                case Mnemonic.mul: RewriteMul(m.UMul); break;

                case Mnemonic.muls: RewriteMul(m.SMul); break;

                case Mnemonic.nop: m.Nop(); break;

                case Mnemonic.or: RewriteBinOp(m.Or, "**0*00"); break;

                case Mnemonic.pop: RewritePop(); break;

                case Mnemonic.push: RewritePush(); break;

                case Mnemonic.rcf: RewriteRcf(); break;

                case Mnemonic.res: RewriteRes(); break;

                case Mnemonic.ret: RewriteRet(); break;

                case Mnemonic.retd: RewriteRetd(); break;

                case Mnemonic.reti: RewriteReti(); break;

                case Mnemonic.sbc: RewriteAdcSbc(m.ISub, "****1*"); break;

                case Mnemonic.scc: RewriteScc(); break;

                case Mnemonic.scf: RewriteScf(); break;

                case Mnemonic.set: RewriteSet(); break;

                case Mnemonic.sla: RewriteShift(m.Shl, "**0*0*"); break;

                case Mnemonic.sll: RewriteShift(m.Shl, "**0*0*"); break;

                case Mnemonic.srl: RewriteShift(m.Shr, "**0*0*"); break;

                case Mnemonic.sub: RewriteBinOp(m.ISub, "***V1*"); break;

                case Mnemonic.swi: RewriteSwi(); break;

                case Mnemonic.xor: RewriteBinOp(m.Xor, "**0*00"); break;

                case Mnemonic.zcf: RewriteZcf(); break;
                }
                yield return(new RtlInstructionCluster(instr.Address, instr.Length, instrs.ToArray())
                {
                    Class = iclass
                });
            }
        }