Exemple #1
0
 public M6809Rewriter(M6809Architecture 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 M6809Disassembler(arch, rdr).GetEnumerator();
     this.instr  = null !;
     this.m      = null !;
 }
Exemple #2
0
            public override M6809Instruction Decode(uint wInstr, M6809Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(wInstr, dasm))
                    {
                        return(dasm.CreateInvalidInstruction());
                    }
                }
                var instr = new M6809Instruction
                {
                    InstructionClass = iclass,
                    Mnemonic         = mnemonic,
                    Operands         = dasm.ops.ToArray()
                };

                return(instr);
            }
Exemple #3
0
        public IEnumerator <RtlInstructionCluster> GetEnumerator()
        {
            var instrs = new List <RtlInstruction>();

            while (dasm.MoveNext())
            {
                this.instr  = dasm.Current;
                this.iclass = instr.InstructionClass;
                instrs.Clear();
                this.m = new RtlEmitter(instrs);
                switch (instr.Mnemonic)
                {
                default:
                    EmitUnitTest();
                    goto case Mnemonic.invalid;

                case Mnemonic.invalid:
                    iclass = InstrClass.Invalid;
                    m.Invalid();
                    break;

                case Mnemonic.abx: RewriteAbx(); break;

                case Mnemonic.adca: RewriteBinary(Registers.A, Adc, NZVC); break;

                case Mnemonic.adcb: RewriteBinary(Registers.B, Adc, NZVC); break;

                case Mnemonic.adda: RewriteBinary(Registers.A, m.IAdd, NZVC); break;

                case Mnemonic.addb: RewriteBinary(Registers.B, m.IAdd, NZVC); break;

                case Mnemonic.addd: RewriteBinary(Registers.D, m.IAdd, NZVC); break;

                case Mnemonic.anda: RewriteBinary(Registers.A, m.And, NZ0_); break;

                case Mnemonic.andb: RewriteBinary(Registers.B, m.And, NZ0_); break;

                case Mnemonic.andcc: RewriteModifyCc(m.And); break;

                case Mnemonic.asr: RewriteUnary(Shl1, NZ_C); break;

                case Mnemonic.beq: RewriteBranch(ConditionCode.EQ, FlagM.Z); break;

                case Mnemonic.bge: RewriteBranch(ConditionCode.GE, FlagM.N | FlagM.V); break;

                case Mnemonic.bgt: RewriteBranch(ConditionCode.GT, FlagM.N | FlagM.Z | FlagM.V); break;

                case Mnemonic.bhi: RewriteBranch(ConditionCode.UGT, FlagM.Z | FlagM.C); break;

                case Mnemonic.bhs: RewriteBranch(ConditionCode.UGE, FlagM.C); break;

                case Mnemonic.bita: RewriteBinaryTest(Registers.A, m.And, NZ0_); break;

                case Mnemonic.bitb: RewriteBinaryTest(Registers.A, m.And, NZ0_); break;

                case Mnemonic.ble: RewriteBranch(ConditionCode.LE, FlagM.N | FlagM.Z | FlagM.V); break;

                case Mnemonic.blo: RewriteBranch(ConditionCode.ULT, FlagM.C); break;

                case Mnemonic.bls: RewriteBranch(ConditionCode.ULE, FlagM.Z | FlagM.C); break;

                case Mnemonic.blt: RewriteBranch(ConditionCode.LT, FlagM.N | FlagM.V); break;

                case Mnemonic.bmi: RewriteBranch(ConditionCode.LT, FlagM.N); break;

                case Mnemonic.bne: RewriteBranch(ConditionCode.NE, FlagM.Z); break;

                case Mnemonic.bpl: RewriteBranch(ConditionCode.GE, FlagM.N); break;

                case Mnemonic.bra: RewriteBra(); break;

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

                case Mnemonic.bsr: RewriteBsr(); break;

                case Mnemonic.bvc: RewriteBranch(ConditionCode.NO, FlagM.V); break;

                case Mnemonic.bvs: RewriteBranch(ConditionCode.OV, FlagM.V); break;

                case Mnemonic.clr: RewriteUnary(Clr, ClrCc); break;

                case Mnemonic.cmpa: RewriteBinaryTest(Registers.A, m.ISub, NZVC); break;

                case Mnemonic.cmpb: RewriteBinaryTest(Registers.B, m.ISub, NZVC); break;

                case Mnemonic.cmpd: RewriteBinaryTest(Registers.D, m.ISub, NZVC); break;

                case Mnemonic.cmps: RewriteBinaryTest(Registers.S, m.ISub, NZVC); break;

                case Mnemonic.cmpu: RewriteBinaryTest(Registers.U, m.ISub, NZVC); break;

                case Mnemonic.cmpx: RewriteBinaryTest(Registers.X, m.ISub, NZVC); break;

                case Mnemonic.cmpy: RewriteBinaryTest(Registers.Y, m.ISub, NZVC); break;

                case Mnemonic.com: RewriteUnary(m.Comp, NZ01); break;

                case Mnemonic.cwai: RewriteCwai(); break;

                case Mnemonic.daa: RewriteDaa(); break;

                case Mnemonic.dec: RewriteUnary(Dec, NZV); break;

                case Mnemonic.eora: RewriteBinaryTest(Registers.A, m.Xor, NZ0_); break;

                case Mnemonic.eorb: RewriteBinaryTest(Registers.B, m.Xor, NZ0_); break;

                case Mnemonic.exg: RewriteExg(); break;

                case Mnemonic.inc: RewriteUnary(Inc, NZV); break;

                case Mnemonic.jmp: RewriteJmp(); break;

                case Mnemonic.jsr: RewriteJsr(); break;

                case Mnemonic.lbeq: RewriteBranch(ConditionCode.EQ, FlagM.Z); break;

                case Mnemonic.lbge: RewriteBranch(ConditionCode.GE, FlagM.N | FlagM.V); break;

                case Mnemonic.lbgt: RewriteBranch(ConditionCode.GT, FlagM.N | FlagM.Z | FlagM.V); break;

                case Mnemonic.lbhi: RewriteBranch(ConditionCode.UGT, FlagM.Z | FlagM.C); break;

                case Mnemonic.lbhs: RewriteBranch(ConditionCode.UGE, FlagM.C); break;

                case Mnemonic.lble: RewriteBranch(ConditionCode.LE, FlagM.N | FlagM.Z | FlagM.V); break;

                case Mnemonic.lblo: RewriteBranch(ConditionCode.ULT, FlagM.C); break;

                case Mnemonic.lbls: RewriteBranch(ConditionCode.ULE, FlagM.Z | FlagM.C); break;

                case Mnemonic.lblt: RewriteBranch(ConditionCode.LT, FlagM.N | FlagM.V); break;

                case Mnemonic.lbmi: RewriteBranch(ConditionCode.LT, FlagM.N); break;

                case Mnemonic.lbne: RewriteBranch(ConditionCode.NE, FlagM.Z); break;

                case Mnemonic.lbpl: RewriteBranch(ConditionCode.GE, FlagM.N); break;

                case Mnemonic.lbra: RewriteBra(); break;

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

                case Mnemonic.lbsr: RewriteBsr(); break;

                case Mnemonic.lbvc: RewriteBranch(ConditionCode.NO, FlagM.V); break;

                case Mnemonic.lbvs: RewriteBranch(ConditionCode.OV, FlagM.V); break;

                case Mnemonic.lda: RewriteBinary(Registers.A, Load, NZ0_); break;

                case Mnemonic.ldb: RewriteBinary(Registers.B, Load, NZ0_); break;

                case Mnemonic.ldd: RewriteBinary(Registers.D, Load, NZ0_); break;

                case Mnemonic.lds: RewriteBinary(Registers.S, Load, NZ0_); break;

                case Mnemonic.ldu: RewriteBinary(Registers.U, Load, NZ0_); break;

                case Mnemonic.ldx: RewriteBinary(Registers.X, Load, NZ0_); break;

                case Mnemonic.ldy: RewriteBinary(Registers.Y, Load, NZ0_); break;

                case Mnemonic.leas: RewriteLea(Registers.S, NoCc); break;

                case Mnemonic.leau: RewriteLea(Registers.U, NoCc); break;

                case Mnemonic.leax: RewriteLea(Registers.X, _Z__); break;

                case Mnemonic.leay: RewriteLea(Registers.Y, _Z__); break;

                case Mnemonic.lsl: RewriteUnary(Shl1, NZVC); break;

                case Mnemonic.lsr: RewriteUnary(Shr1, NZ_C); break;

                case Mnemonic.mul: RewriteMul(); break;

                case Mnemonic.neg: RewriteUnary(m.Neg, NZVC); break;

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

                case Mnemonic.ora: RewriteBinary(Registers.A, m.Or, NZ0_); break;

                case Mnemonic.orb: RewriteBinary(Registers.B, m.Or, NZ0_); break;

                case Mnemonic.orcc: RewriteModifyCc(m.Or); break;

                case Mnemonic.pshs: RewritePsh(Registers.S); break;

                case Mnemonic.pshu: RewritePsh(Registers.U); break;

                case Mnemonic.puls: RewritePul(Registers.S); break;

                case Mnemonic.pulu: RewritePul(Registers.U); break;

                case Mnemonic.rol: RewriteUnary(Rol1, NZVC); break;

                case Mnemonic.ror: RewriteUnary(Ror1, NZ_C); break;

                case Mnemonic.rti: RewriteRti(); break;

                case Mnemonic.rts: RewriteRts(); break;

                case Mnemonic.sbca: RewriteBinary(Registers.A, Sbc, NZVC); break;

                case Mnemonic.sbcb: RewriteBinary(Registers.B, Sbc, NZVC); break;

                case Mnemonic.sex: RewriteSex(); break;

                case Mnemonic.sta: RewriteUnary(Store(Registers.A), NZ0_); break;

                case Mnemonic.stb: RewriteUnary(Store(Registers.B), NZ0_); break;

                case Mnemonic.std: RewriteUnary(Store(Registers.D), NZ0_); break;

                case Mnemonic.sts: RewriteUnary(Store(Registers.S), NZ0_); break;

                case Mnemonic.stu: RewriteUnary(Store(Registers.U), NZ0_); break;

                case Mnemonic.stx: RewriteUnary(Store(Registers.X), NZ0_); break;

                case Mnemonic.sty: RewriteUnary(Store(Registers.Y), NZ0_); break;

                case Mnemonic.suba: RewriteBinary(Registers.A, m.ISub, NZVC); break;

                case Mnemonic.subb: RewriteBinary(Registers.B, m.ISub, NZVC); break;

                case Mnemonic.subd: RewriteBinary(Registers.D, m.ISub, NZVC); break;

                case Mnemonic.swi: RewriteSwi(0xFFFA); break;

                case Mnemonic.swi2: RewriteSwi(0xFFF4); break;

                case Mnemonic.swi3: RewriteSwi(0xFFF2); break;

                case Mnemonic.sync: RewriteSync(); break;

                case Mnemonic.tfr: RewriteTfr(); break;

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