Esempio n. 1
0
        public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction)
        {
            const FlagsRegister flagsAffected = FlagsRegister.Sign | FlagsRegister.Zero | FlagsRegister.Auxiliary | FlagsRegister.Parity | FlagsRegister.Carry;

            cpu.Flags &= ~flagsAffected;
            cpu.Flags |= (FlagsRegister)(cpu.GetRegister(Register.AH) & (ushort)flagsAffected);
        }
Esempio n. 2
0
        public void TestJZZeroEnabled()
        {
            SignalBus     signals = new SignalBus();
            FlagBus       flagBus = new FlagBus();
            FlagsRegister flags   = new FlagsRegister(null, signals, flagBus);

            flags.Value = FlagsRegister.ZERO;
            Operation op = new JZ(null, signals, flags);

            signals.Reset();
            op.Step0();
            Assert.IsTrue(signals.MI);
            Assert.IsTrue(signals.CO);

            signals.Reset();
            op.Step1();
            Assert.IsTrue(signals.RO);
            Assert.IsTrue(signals.II);
            Assert.IsTrue(signals.CE);

            signals.Reset();
            op.Step2();
            Assert.IsTrue(signals.IO);
            Assert.IsTrue(signals.J);
        }
Esempio n. 3
0
        public CPUx86()
        {
            EIP    = new Register32Bit("EIP", 0, RegisterType.InstructionPointer, false);
            EFLAGS = new FlagsRegister();

            EAX = new GeneralPurposeRegister("EAX", 0);
            EBX = new GeneralPurposeRegister("EBX", 1);
            ECX = new GeneralPurposeRegister("ECX", 2);
            EDX = new GeneralPurposeRegister("EDX", 3);
            ESP = new GeneralPurposeRegister("ESP", 4);
            EBP = new GeneralPurposeRegister("EBP", 5);
            ESI = new GeneralPurposeRegister("ESI", 6);
            EDI = new GeneralPurposeRegister("EDI", 7);

            CR0 = new CR0();
            CR2 = new ControlRegister("CR2", 2);
            CR3 = new ControlRegister("CR3", 3);
            CR4 = new ControlRegister("CR3", 4);

            AX = new Legacy16BitRegister("AX", EAX);
            BX = new Legacy16BitRegister("BX", EBX);
            CX = new Legacy16BitRegister("CX", ECX);
            DX = new Legacy16BitRegister("DX", EDX);
            SI = new Legacy16BitRegister("SI", ESI);
            DI = new Legacy16BitRegister("DI", EDI);
            BP = new Legacy16BitRegister("BP", EBP);

            AL = new Legacy8BitLowRegister("AL", EAX);
            BL = new Legacy8BitLowRegister("BL", EBX);
            CL = new Legacy8BitLowRegister("CL", ECX);
            DL = new Legacy8BitLowRegister("DL", EDX);

            AH = new Legacy8BitHighRegister("AH", EAX);
            BH = new Legacy8BitHighRegister("BH", EBX);
            CH = new Legacy8BitHighRegister("CH", ECX);
            DH = new Legacy8BitHighRegister("DH", EDX);

            XMM0 = new RegisterFloatingPoint("XMM0", 0, RegisterType.FloatingPoint);
            XMM1 = new RegisterFloatingPoint("XMM1", 1, RegisterType.FloatingPoint);
            XMM2 = new RegisterFloatingPoint("XMM2", 2, RegisterType.FloatingPoint);
            XMM3 = new RegisterFloatingPoint("XMM3", 3, RegisterType.FloatingPoint);
            XMM4 = new RegisterFloatingPoint("XMM4", 4, RegisterType.FloatingPoint);
            XMM5 = new RegisterFloatingPoint("XMM5", 5, RegisterType.FloatingPoint);
            XMM6 = new RegisterFloatingPoint("XMM6", 6, RegisterType.FloatingPoint);
            XMM7 = new RegisterFloatingPoint("XMM7", 7, RegisterType.FloatingPoint);

            ST0 = new RegisterFloatingPoint("ST0", -1, RegisterType.FloatingPoint);

            CS = new SegmentRegister("CS", 0);
            DS = new SegmentRegister("DS", 1);
            ES = new SegmentRegister("ES", 2);
            FS = new SegmentRegister("FS", 3);
            GS = new SegmentRegister("GS", 4);
            SS = new SegmentRegister("SS", 5);

            Reset();
        }
Esempio n. 4
0
        public CPUx86()
        {
            EIP = new Register32Bit("EIP", 0, RegisterType.InstructionPointer, false);
            EFLAGS = new FlagsRegister();

            EAX = new GeneralPurposeRegister("EAX", 0);
            EBX = new GeneralPurposeRegister("EBX", 1);
            ECX = new GeneralPurposeRegister("ECX", 2);
            EDX = new GeneralPurposeRegister("EDX", 3);
            ESP = new GeneralPurposeRegister("ESP", 4);
            EBP = new GeneralPurposeRegister("EBP", 5);
            ESI = new GeneralPurposeRegister("ESI", 6);
            EDI = new GeneralPurposeRegister("EDI", 7);

            CR0 = new CR0();
            CR2 = new ControlRegister("CR2", 2);
            CR3 = new ControlRegister("CR3", 3);
            CR4 = new ControlRegister("CR3", 4);

            AX = new Legacy16BitRegister("AX", EAX);
            BX = new Legacy16BitRegister("BX", EBX);
            CX = new Legacy16BitRegister("CX", ECX);
            DX = new Legacy16BitRegister("DX", EDX);
            SI = new Legacy16BitRegister("SI", ESI);
            DI = new Legacy16BitRegister("DI", EDI);
            BP = new Legacy16BitRegister("BP", EBP);

            AL = new Legacy8BitLowRegister("AL", EAX);
            BL = new Legacy8BitLowRegister("BL", EBX);
            CL = new Legacy8BitLowRegister("CL", ECX);
            DL = new Legacy8BitLowRegister("DL", EDX);

            AH = new Legacy8BitHighRegister("AH", EAX);
            BH = new Legacy8BitHighRegister("BH", EBX);
            CH = new Legacy8BitHighRegister("CH", ECX);
            DH = new Legacy8BitHighRegister("DH", EDX);

            XMM0 = new RegisterFloatingPoint("XMM0", 0, RegisterType.FloatingPoint);
            XMM1 = new RegisterFloatingPoint("XMM1", 1, RegisterType.FloatingPoint);
            XMM2 = new RegisterFloatingPoint("XMM2", 2, RegisterType.FloatingPoint);
            XMM3 = new RegisterFloatingPoint("XMM3", 3, RegisterType.FloatingPoint);
            XMM4 = new RegisterFloatingPoint("XMM4", 4, RegisterType.FloatingPoint);
            XMM5 = new RegisterFloatingPoint("XMM5", 5, RegisterType.FloatingPoint);
            XMM6 = new RegisterFloatingPoint("XMM6", 6, RegisterType.FloatingPoint);
            XMM7 = new RegisterFloatingPoint("XMM7", 7, RegisterType.FloatingPoint);

            ST0 = new RegisterFloatingPoint("ST0", -1, RegisterType.FloatingPoint);

            CS = new SegmentRegister("CS", 0);
            DS = new SegmentRegister("DS", 1);
            ES = new SegmentRegister("ES", 2);
            FS = new SegmentRegister("FS", 3);
            GS = new SegmentRegister("GS", 4);
            SS = new SegmentRegister("SS", 5);

            Reset();
        }
Esempio n. 5
0
        public void SetRegister(Register register, ushort value)
        {
            if (((uint)register & 0x80000000) == 0)
            {
                registers[(int)register] = value;
            }
            else
            {
                switch (register)
                {
                case Register.AL:
                    registers[(int)Register.AX] = (ushort)((GetRegister(Register.AX) & 0xFF00) | value);
                    break;

                case Register.CL:
                    registers[(int)Register.CX] = (ushort)((GetRegister(Register.CX) & 0xFF00) | value);
                    break;

                case Register.DL:
                    registers[(int)Register.DX] = (ushort)((GetRegister(Register.DX) & 0xFF00) | value);
                    break;

                case Register.BL:
                    registers[(int)Register.BX] = (ushort)((GetRegister(Register.BX) & 0xFF00) | value);
                    break;

                case Register.AH:
                    registers[(int)Register.AX] = (ushort)((GetRegister(Register.AX) & 0x00FF) | (value << 8));
                    break;

                case Register.CH:
                    registers[(int)Register.CX] = (ushort)((GetRegister(Register.CX) & 0x00FF) | (value << 8));
                    break;

                case Register.DH:
                    registers[(int)Register.DX] = (ushort)((GetRegister(Register.DX) & 0x00FF) | (value << 8));
                    break;

                case Register.BH:
                    registers[(int)Register.BX] = (ushort)((GetRegister(Register.BX) & 0x00FF) | (value << 8));
                    break;

                case Register.FLAGS:
                    Flags = (FlagsRegister)value & FLAGS_MASK;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(register));
                }
            }
        }
Esempio n. 6
0
        public void ParsesFlags()
        {
            FlagsRegister flagsRegister = new FlagsRegister(null, null, null);

            flagsRegister.Value = 0;

            Assert.IsFalse(flagsRegister.Zero);
            Assert.IsFalse(flagsRegister.Carry);

            flagsRegister.Value = 3;

            Assert.IsTrue(flagsRegister.Zero);
            Assert.IsTrue(flagsRegister.Carry);
        }
Esempio n. 7
0
        public void StoresFlags()
        {
            SignalBus signals = new SignalBus();
            FlagBus   flagBus = new FlagBus();

            FlagsRegister flagsRegister = new FlagsRegister(null, signals, flagBus);

            flagBus.Carry = true;
            flagBus.Zero  = true;
            signals.FI    = true;

            flagsRegister.ReadFromBus();

            Assert.AreEqual(3, flagsRegister.Value);
        }
Esempio n. 8
0
        public void FlagsRegisterInputs()
        {
            DataBus   bus     = new DataBus();
            FlagBus   flagBus = new FlagBus();
            SignalBus signals = new SignalBus();

            Register flags = new FlagsRegister(bus, signals, flagBus);

            flagBus.Carry = true;
            flagBus.Zero  = true;
            signals.FI    = true;

            flags.ReadFromBus();
            Assert.AreEqual(FlagsRegister.CARRY + FlagsRegister.ZERO, flags.Value);
        }
Esempio n. 9
0
        public void TestJMP()
        {
            SignalBus     signals = new SignalBus();
            FlagsRegister flags   = new FlagsRegister(null, signals, null);

            flags.Value = FlagsRegister.CARRY;
            Operation op = new JMP(null, signals, null);

            signals.Reset();
            op.Step0();
            Assert.IsTrue(signals.MI);
            Assert.IsTrue(signals.CO);

            signals.Reset();
            op.Step1();
            Assert.IsTrue(signals.RO);
            Assert.IsTrue(signals.II);
            Assert.IsTrue(signals.CE);

            signals.Reset();
            op.Step2();
            Assert.IsTrue(signals.IO);
            Assert.IsTrue(signals.J);
        }
Esempio n. 10
0
        public void TestJCCarryDisabled()
        {
            SignalBus     signals = new SignalBus();
            FlagsRegister flags   = new FlagsRegister(null, signals, null);

            flags.Value = 0;
            Operation op = new JC(null, signals, flags);

            signals.Reset();
            op.Step0();
            Assert.IsTrue(signals.MI);
            Assert.IsTrue(signals.CO);

            signals.Reset();
            op.Step1();
            Assert.IsTrue(signals.RO);
            Assert.IsTrue(signals.II);
            Assert.IsTrue(signals.CE);

            signals.Reset();
            op.Step2();
            Assert.IsFalse(signals.IO);
            Assert.IsFalse(signals.J);
        }
Esempio n. 11
0
 public Operation(InstructionCounter instructionCounter, SignalBus signals, FlagsRegister flags)
 {
     this.instructionCounter = instructionCounter;
     this.signals            = signals;
     this.flags = flags;
 }
Esempio n. 12
0
 public LDI(InstructionCounter instructionCounter, SignalBus signals, FlagsRegister flags) : base(instructionCounter, signals, flags)
 {
 }
Esempio n. 13
0
 public ModRmExecutor8(Registers regs, FlagsRegister flags, byte[] mem, ModRMDecoder modRm) : base(regs, flags,
                                                                                                   mem, modRm)
 {
 }
Esempio n. 14
0
 public static bool Has(this FlagsRegister flag, FlagsRegister testFlag) =>
 (flag & testFlag) != 0;
Esempio n. 15
0
 public void SetFlags(FlagsRegister value) => SetRegister(Register.FLAGS, (ushort)value);