示例#1
0
        private void Inst_Lhu(MipsInstruction inst)
        {
            try
            {
                Int64 address = ComputeAddress(inst);

                if ((address & 1) != 0)
                {
                    CauseException = ExceptionCode.AddressErrorLoad;
                    return;
                }

                if (!MipsState.Operating64BitMode)
                {
                    MipsState.WriteGPR32Unsigned(inst.Rt, DataManipulator.LoadHalfwordUnsigned(address));
                }
                else
                {
                    MipsState.WriteGPRUnsigned(inst.Rt, DataManipulator.LoadHalfwordUnsigned(address));
                }
            }
            catch (TLBException tlbe)
            {
                switch (tlbe.ExceptionType)
                {
                case TLBExceptionType.Invalid: CauseException = ExceptionCode.Invalid; break;

                case TLBExceptionType.Mod: CauseException = ExceptionCode.TlbMod; break;

                case TLBExceptionType.Refill: CauseException = ExceptionCode.TlbStore; break;

                default: break;
                }
            }
        }
示例#2
0
 private void Inst_Subu(MipsInstruction inst)
 {
     unchecked
     {
         MipsState.WriteGPR32Unsigned(inst.Rd, MipsState.ReadGPR32Unsigned(inst.Rs) - MipsState.ReadGPR32Unsigned(inst.Rt));
     }
 }
示例#3
0
 private void Inst_Xor(MipsInstruction inst)
 {
     if (!MipsState.Operating64BitMode)
     {
         MipsState.WriteGPR32Unsigned(inst.Rd, MipsState.ReadGPR32Unsigned(inst.Rs) ^ MipsState.ReadGPR32Unsigned(inst.Rt));
     }
     else
     {
         MipsState.WriteGPRUnsigned(inst.Rd, MipsState.ReadGPRUnsigned(inst.Rs) ^ MipsState.ReadGPRUnsigned(inst.Rt));
     }
 }
示例#4
0
 private void Inst_Andi(MipsInstruction inst)
 {
     if (!MipsState.Operating64BitMode)
     {
         MipsState.WriteGPR32Unsigned(inst.Rt, MipsState.ReadGPR32Unsigned(inst.Rs) & (UInt32)inst.Immediate);
     }
     else
     {
         MipsState.WriteGPRUnsigned(inst.Rt, MipsState.ReadGPRUnsigned(inst.Rs) & (UInt64)inst.Immediate);
     }
 }
示例#5
0
        private void Inst_Srvl(MipsInstruction inst)
        {
            UInt32 result = MipsState.ReadGPR32Unsigned(inst.Rt) >> MipsState.ReadGPR32Signed(inst.Rs) & 0x1F;

            if (!MipsState.Operating64BitMode)
            {
                MipsState.WriteGPR32Unsigned(inst.Rd, result);
            }
            else
            {
                MipsState.WriteGPRUnsigned(inst.Rd, (UInt32)(Int32)result);
            }
        }
示例#6
0
        private void Inst_Srl(MipsInstruction inst)
        {
            UInt32 result = MipsState.ReadGPR32Unsigned(inst.Rt) >> inst.ShiftAmount;

            if (!MipsState.Operating64BitMode)
            {
                MipsState.WriteGPR32Unsigned(inst.Rd, result);
            }
            else
            {
                MipsState.WriteGPRUnsigned(inst.Rd, (UInt64)(Int64)(Int16)result);
            }
        }
示例#7
0
 private void Inst_Sltiu(MipsInstruction inst)
 {
     if (!MipsState.Operating64BitMode)
     {
         Boolean condition = MipsState.ReadGPR32Unsigned(inst.Rs) < ((UInt32)(Int32)(Int16)inst.Immediate);
         MipsState.WriteGPR32Unsigned(inst.Rt, condition ? 1U : 0U);
     }
     else
     {
         Boolean condition = MipsState.ReadGPRUnsigned(inst.Rs) < ((UInt64)(Int64)(Int16)inst.Immediate);
         MipsState.WriteGPRUnsigned(inst.Rt, condition ? 1UL : 0UL);
     }
 }
示例#8
0
        private void Inst_Lui(MipsInstruction inst)
        {
            UInt32 word = ((UInt32)inst.Immediate) << 16;

            if (!MipsState.Operating64BitMode)
            {
                MipsState.WriteGPR32Unsigned(inst.Rt, word);
            }
            else
            {
                MipsState.WriteGPRUnsigned(inst.Rt, (UInt64)(Int64)(Int32)word);
            }
        }
示例#9
0
 private void Inst_Addiu(MipsInstruction inst)
 {
     unchecked
     {
         if (!MipsState.Operating64BitMode)
         {
             MipsState.WriteGPR32Unsigned(inst.Rt, MipsState.ReadGPR32Unsigned(inst.Rs) + (UInt32)(Int32)(Int16)inst.Immediate);
         }
         else
         {
             if (MipsState.ReadGPRUnsigned(inst.Rs).IsSigned32())
             {
                 MipsState.WriteGPRUnsigned(inst.Rt, MipsState.ReadGPRUnsigned(inst.Rs) + (UInt64)(Int64)(Int16)inst.Immediate);
             }
         }
     }
 }
示例#10
0
 private void Inst_Addu(MipsInstruction inst)
 {
     unchecked
     {
         if (!MipsState.Operating64BitMode)
         {
             MipsState.WriteGPR32Unsigned(inst.Rd, MipsState.ReadGPR32Unsigned(inst.Rs) + MipsState.ReadGPR32Unsigned(inst.Rt));
         }
         else
         {
             if (MipsState.ReadGPRUnsigned(inst.Rs).IsSigned32() && MipsState.ReadGPRUnsigned(inst.Rt).IsSigned32())
             {
                 MipsState.WriteGPRUnsigned(inst.Rd, MipsState.ReadGPRUnsigned(inst.Rs) + MipsState.ReadGPRUnsigned(inst.Rt));
             }
         }
     }
 }
示例#11
0
        private void Inst_Mfc1(MipsInstruction inst)
        {
            if (!CheckCop1Usable())
            {
                CauseException = ExceptionCode.CopUnstable;
                return;
            }

            if (!MipsState.Operating64BitMode)
            {
                MipsState.WriteGPR32Unsigned(inst.Rt, MipsState.Fpr.ReadFPR32Unsigned(inst.Fs));
            }
            else
            {
                MipsState.WriteGPRUnsigned(inst.Rt, MipsState.Fpr.ReadFPR32Unsigned(inst.Fs));
            }
        }
示例#12
0
        private void Inst_Sllv(MipsInstruction inst)
        {
            Int32 shiftAmount = MipsState.ReadGPR32Signed(inst.Rs) & 0x1F;

            if (!MipsState.Operating64BitMode)
            {
                MipsState.WriteGPR32Unsigned(inst.Rd, MipsState.ReadGPR32Unsigned(inst.Rt) << shiftAmount);
            }
            else
            {
                UInt64 result = MipsState.ReadGPRUnsigned(inst.Rt) << shiftAmount;

                /* Truncate */
                if (shiftAmount == 0)
                {
                    MipsState.WriteGPRSigned(inst.Rd, (Int32)(UInt32)result);
                }
                else
                {
                    MipsState.WriteGPRUnsigned(inst.Rd, result);
                }
            }
        }
示例#13
0
        private void Inst_Mfc0(MipsInstruction inst)
        {
            if (MipsState.CP0Regs.StatusReg.CopUsable0)
            {
                if (!MipsState.Operating64BitMode)
                {
                    MipsState.WriteGPR32Unsigned(inst.Rt, (UInt32)MipsState.CP0Regs[inst.Rd]);

                    /* Count register */
                    if (inst.Rt == 9)
                    {
                        MupenHelper.UpdateCount();
                    }
                }
                else
                {
                    MipsState.WriteGPRUnsigned(inst.Rt, MipsState.CP0Regs[inst.Rd]);
                }
            }
            else
            {
                CauseException = ExceptionCode.CopUnstable;
            }
        }