Exemplo n.º 1
0
            public override Pdp11Instruction Decode(uint uInstr, Pdp11Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(uInstr, dasm))
                    {
                        return(dasm.CreateInvalidInstruction());
                    }
                }
                var instr = new Pdp11Instruction
                {
                    Mnemonic         = this.opcode,
                    InstructionClass = iclass,
                    DataWidth        = dasm.dataWidth,
                    Operands         = dasm.ops.ToArray()
                };

                return(instr);
            }
Exemplo n.º 2
0
            public override Pdp11Instruction Decode(ushort opcode, Pdp11Disassembler dasm)
            {
                foreach (var m in mutators)
                {
                    if (!m(opcode, dasm))
                    {
                        return(dasm.CreateInvalidInstruction());
                    }
                }
                var instr = new Pdp11Instruction
                {
                    Opcode           = this.opcode,
                    InstructionClass = iclass,
                    DataWidth        = dasm.dataWidth,
                    op1 = dasm.ops.Count > 0 ? dasm.ops[0] : null,
                    op2 = dasm.ops.Count > 1 ? dasm.ops[1] : null,
                };

                return(instr);
            }
Exemplo n.º 3
0
        private static Pdp11Instruction NonDoubleOperandInstruction(ushort opcode, Pdp11Disassembler dasm)
        {
            var iclass = InstrClass.Linear;

            switch ((opcode >> 8))
            {
            case 0x01: return(dasm.BranchInstruction(opcode, Mnemonic.br, InstrClass.Transfer));

            case 0x02: return(dasm.BranchInstruction(opcode, Mnemonic.bne));

            case 0x03: return(dasm.BranchInstruction(opcode, Mnemonic.beq));

            case 0x04: return(dasm.BranchInstruction(opcode, Mnemonic.bge));

            case 0x05: return(dasm.BranchInstruction(opcode, Mnemonic.blt));

            case 0x06: return(dasm.BranchInstruction(opcode, Mnemonic.bgt));

            case 0x07: return(dasm.BranchInstruction(opcode, Mnemonic.ble));

            case 0x80: return(dasm.BranchInstruction(opcode, Mnemonic.bpl));

            case 0x81: return(dasm.BranchInstruction(opcode, Mnemonic.bmi));

            case 0x82: return(dasm.BranchInstruction(opcode, Mnemonic.bhi));

            case 0x83: return(dasm.BranchInstruction(opcode, Mnemonic.blos));

            case 0x84: return(dasm.BranchInstruction(opcode, Mnemonic.bvc));

            case 0x85: return(dasm.BranchInstruction(opcode, Mnemonic.bvs));

            case 0x86: return(dasm.BranchInstruction(opcode, Mnemonic.bcc));

            case 0x87: return(dasm.BranchInstruction(opcode, Mnemonic.bcs));
            }

            var      dataWidth = dasm.DataWidthFromSizeBit(opcode & 0x8000u);
            var      ops       = new List <MachineOperand>();
            Mnemonic oc        = Mnemonic.illegal;

            switch ((opcode >> 6) & 0x3FF)
            {
            case 0x000:
                switch (opcode & 0x3F)
                {
                case 0x00: oc = Mnemonic.halt; iclass = InstrClass.Terminates | InstrClass.Zero; break;

                case 0x01: oc = Mnemonic.wait; break;

                case 0x02: oc = Mnemonic.rti; iclass = InstrClass.Transfer; break;

                case 0x03: oc = Mnemonic.bpt; break;

                case 0x04: oc = Mnemonic.iot; break;

                case 0x05: oc = Mnemonic.reset; iclass = InstrClass.Transfer; break;

                case 0x06: oc = Mnemonic.rtt; iclass = InstrClass.Transfer; break;

                case 0x07: oc = Mnemonic.illegal; break;
                }
                break;

            case 0x001:
                var op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                oc = Mnemonic.jmp; iclass = InstrClass.Transfer; break;

            case 0x002:
                switch (opcode & 0x38)
                {
                case 0:
                    ops.Add(dasm.DecodeOperand(opcode & 7u));
                    oc     = Mnemonic.rts;
                    iclass = InstrClass.Transfer; break;

                case 3:
                    op = dasm.DecodeOperand(opcode);
                    if (op == null)
                    {
                        return(dasm.CreateInvalidInstruction());
                    }
                    ops.Add(op);
                    oc = Mnemonic.spl; break;

                case 0x20:
                case 0x28:
                case 0x30:
                case 0x38:
                    return(dasm.DecodeCondCode(opcode));
                }
                break;

            case 0x003:
                oc = Mnemonic.swab;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                dataWidth = PrimitiveType.Byte;
                break;

            case 0x020:
            case 0x021:
            case 0x022:
            case 0x023:
            case 0x024:
            case 0x025:
            case 0x026:
            case 0x027:
                oc     = Mnemonic.jsr;
                iclass = InstrClass.Transfer | InstrClass.Call;
                ops.Add(Reg(opcode >> 6, dasm));
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                dataWidth = PrimitiveType.Word16;
                break;

            case 0x220:
            case 0x221:
            case 0x222:
            case 0x223:
                oc = Mnemonic.emt;
                ops.Add(new ImmediateOperand(Constant.Byte((byte)opcode)));
                break;

            case 0x224:
            case 0x225:
            case 0x226:
            case 0x227:
                oc     = Mnemonic.trap;
                iclass = InstrClass.Transfer;
                ops.Add(new ImmediateOperand(Constant.Byte((byte)opcode)));
                break;

            case 0x028:
            case 0x228:
                oc = dataWidth.Size == 1 ? Mnemonic.clrb : Mnemonic.clr;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x029:
            case 0x229:
                oc = Mnemonic.com;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02A:
            case 0x22A:
                oc = Mnemonic.inc;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02B:
            case 0x22B:
                oc = Mnemonic.dec;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02C:
            case 0x22C:
                oc = Mnemonic.neg;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02D:
            case 0x22D:
                oc = Mnemonic.adc;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02E:
            case 0x22E:
                oc = Mnemonic.sbc;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x02F:
            case 0x22F:
                oc = Mnemonic.tst;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x030:
            case 0x230:
                oc = Mnemonic.ror;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x031:
            case 0x231:
                oc = Mnemonic.rol;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x032:
            case 0x232:
                oc = Mnemonic.asr;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x033:
            case 0x233:
                oc = Mnemonic.asl;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x034:
                oc = Mnemonic.mark;
                ops.Add(new ImmediateOperand(Constant.Byte((byte)opcode)));
                break;

            case 0x234:
                oc = Mnemonic.mtps;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x035:
                oc = Mnemonic.mfpi;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x235:
                oc = Mnemonic.mfpd;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x036:
                oc = Mnemonic.mtpi;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x236:
                oc = Mnemonic.mtpd;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x037:
                oc = Mnemonic.sxt;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;

            case 0x237:
                oc = Mnemonic.mfps;
                op = dasm.DecodeOperand(opcode);
                if (op == null)
                {
                    return(dasm.CreateInvalidInstruction());
                }
                ops.Add(op);
                break;
            }
            return(new Pdp11Instruction
            {
                Mnemonic = oc,
                InstructionClass = iclass,
                DataWidth = dataWidth,
                Operands = ops.ToArray()
            });
        }