Beispiel #1
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            int instrCodeSize = GetCodeSize(instr.CodeSize);

            if (instrCodeSize == 0 || (instrCodeSize & codeSize) != 0)
            {
                info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
            }
            else
            {
                info          = default;
                info.Mnemonic = "xchg";
                info.OpCount  = 2;
                info.Op0Kind  = InstrOpKind.Register;
                info.Op1Kind  = InstrOpKind.Register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op0Register = (byte)register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)register;
                if (instr.Op0Register == instr.Op1Register)
                {
                    info.Op0Index = OpAccess_None;
                    info.Op1Index = OpAccess_None;
                }
                else
                {
                    info.Op0Index = OpAccess_ReadWrite;
                    info.Op1Index = OpAccess_ReadWrite;
                }
            }
        }
Beispiel #2
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            int instrCodeSize = GetCodeSize(instr.CodeSize);
            var flags         = instrCodeSize == 0 || (instrCodeSize & codeSize) != 0 ? InstrOpInfoFlags.MemSize_Nothing : InstrOpInfoFlags.ShowNoMemSize_ForceSize;

            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #3
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
     if (options.UsePseudoOps)
     {
         int index;
         int imm = instr.Immediate8;
         if (imm == 0)
         {
             index = 0;
         }
         else if (imm == 1)
         {
             index = 1;
         }
         else if (imm == 0x10)
         {
             index = 2;
         }
         else if (imm == 0x11)
         {
             index = 3;
         }
         else
         {
             index = -1;
         }
         if (index >= 0)
         {
             info.Mnemonic = pseudo_ops[index];
             SimpleInstrInfo_pops.RemoveLastOp(ref info);
         }
     }
 }
Beispiel #4
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(info.Op1Register == (int)Register.ST0);
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op1Register = (byte)Registers.Register_ST;
 }
Beispiel #5
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags         = InstrOpInfoFlags.None;
            int instrCodeSize = GetCodeSize(instr.CodeSize);

            if (instrCodeSize == 64)
            {
                instrCodeSize = 32;
            }
            if (instrCodeSize != 0 && instrCodeSize != codeSize)
            {
                if (codeSize == 16)
                {
                    flags |= InstrOpInfoFlags.OpSize16;
                }
                else if (codeSize == 32)
                {
                    flags |= InstrOpInfoFlags.OpSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.OpSize64;
                }
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #6
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var      flags         = InstrOpInfoFlags.None;
            int      instrCodeSize = GetCodeSize(instr.CodeSize);
            Register expectedReg;

            switch (instrCodeSize)
            {
            case 0:
                expectedReg = reg;
                break;

            case 16:
                expectedReg = Register.CX;
                break;

            case 32:
                expectedReg = Register.ECX;
                break;

            case 64:
                expectedReg = Register.RCX;
                break;

            default:
                throw new InvalidOperationException();
            }
            if (instrCodeSize != 0 && instrCodeSize != codeSize)
            {
                if (codeSize == 16)
                {
                    flags |= InstrOpInfoFlags.OpSize16;
                }
                else if (codeSize == 32)
                {
                    flags |= InstrOpInfoFlags.OpSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.OpSize64;
                }
            }
            if (expectedReg != reg)
            {
                if (reg == Register.CX)
                {
                    flags |= InstrOpInfoFlags.AddrSize16;
                }
                else if (reg == Register.ECX)
                {
                    flags |= InstrOpInfoFlags.AddrSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.AddrSize64;
                }
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #7
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info         = new InstrOpInfo(mnemonic, ref instr, flags);
     info.OpCount = 1;
     info.Op0Kind = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op0Register = (byte)register;
 }
Beispiel #8
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     Debug.Assert(instr.OpCount == 1, "Instruction is fixed, remove this class");
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     info.OpCount++;
     info.Op1Kind = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op1Register = (byte)reg;
 }
Beispiel #9
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags = this.flags;

            if (instr.HasRepnePrefix)
            {
                flags |= InstrOpInfoFlags.BndPrefix;
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #10
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info         = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.MnemonicIsDirective);
     info.OpCount = (byte)instr.DeclareDataCount;
     info.Op0Kind = opKind;
     info.Op1Kind = opKind;
     info.Op2Kind = opKind;
     info.Op3Kind = opKind;
     info.Op4Kind = opKind;
 }
Beispiel #11
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(instr.OpCount == 1);
     info.OpCount = 2;
     info.Op1Kind = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op1Register = (byte)Registers.Register_ST;
     info.Op1Index    = OpAccess_Read;
 }
Beispiel #12
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(info.OpCount == 3);
     if (options.UsePseudoOps && info.Op0Kind == InstrOpKind.Register && info.Op1Kind == InstrOpKind.Register && info.Op0Register == info.Op1Register)
     {
         info.OpCount--;
         info.Op1Kind = info.Op2Kind;
     }
 }
Beispiel #13
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            info = new InstrOpInfo(mnemonic, ref instr, flags);
            int imm = instr.Immediate8;

            if (options.UsePseudoOps && (uint)imm < (uint)pseudo_ops.Length)
            {
                info.Mnemonic = pseudo_ops[imm];
                RemoveLastOp(ref info);
            }
        }
Beispiel #14
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            const InstrOpInfoFlags flags = InstrOpInfoFlags.None;

            info = new InstrOpInfo(mnemonic, ref instr, flags);
            if (Register.EAX <= (Register)info.Op0Register && (Register)info.Op0Register <= Register.R15D)
            {
                info.Op0Register = (byte)((Register)info.Op0Register - Register.EAX + Register.AX);
            }
            if (Register.EAX <= (Register)info.Op1Register && (Register)info.Op1Register <= Register.R15D)
            {
                info.Op1Register = (byte)((Register)info.Op1Register - Register.EAX + Register.AX);
            }
        }
Beispiel #15
0
        void Verify_default_formatter_options()
        {
            var options = new IntelFormatterOptions();

            Assert.False(options.UpperCasePrefixes);
            Assert.False(options.UpperCaseMnemonics);
            Assert.False(options.UpperCaseRegisters);
            Assert.False(options.UpperCaseKeywords);
            Assert.False(options.UpperCaseOther);
            Assert.False(options.UpperCaseAll);
            Assert.Equal(0, options.FirstOperandCharIndex);
            Assert.Equal(0, options.TabSize);
            Assert.False(options.SpaceAfterOperandSeparator);
            Assert.False(options.SpaceAfterMemoryOpenBracket);
            Assert.False(options.SpaceBeforeMemoryCloseBracket);
            Assert.False(options.SpacesBetweenMemoryAddOperators);
            Assert.False(options.SpacesBetweenMemoryMulOperators);
            Assert.False(options.ScaleBeforeIndex);
            Assert.False(options.AlwaysShowScale);
            Assert.False(options.AlwaysShowSegmentRegister);
            Assert.False(options.ShowZeroDisplacements);
            Assert.Null(options.HexPrefix);
            Assert.Equal("h", options.HexSuffix);
            Assert.Equal(4, options.HexDigitGroupSize);
            Assert.Null(options.DecimalPrefix);
            Assert.Null(options.DecimalSuffix);
            Assert.Equal(3, options.DecimalDigitGroupSize);
            Assert.Null(options.OctalPrefix);
            Assert.Equal("o", options.OctalSuffix);
            Assert.Equal(4, options.OctalDigitGroupSize);
            Assert.Null(options.BinaryPrefix);
            Assert.Equal("b", options.BinarySuffix);
            Assert.Equal(4, options.BinaryDigitGroupSize);
            Assert.Equal("_", options.DigitSeparator);
            Assert.False(options.AddDigitSeparators);
            Assert.True(options.ShortNumbers);
            Assert.True(options.UpperCaseHex);
            Assert.True(options.SmallHexNumbersInDecimal);
            Assert.True(options.AddLeadingZeroToHexNumbers);
            Assert.Equal(NumberBase.Hexadecimal, options.NumberBase);
            Assert.False(options.ShortBranchNumbers);
            Assert.False(options.SignedImmediateOperands);
            Assert.True(options.SignedMemoryDisplacements);
            Assert.False(options.SignExtendMemoryDisplacements);
            Assert.False(options.AlwaysShowMemorySize);
            Assert.False(options.RipRelativeAddresses);
            Assert.True(options.ShowBranchSize);
            Assert.True(options.UsePseudoOps);
        }
Beispiel #16
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            info = new InstrOpInfo(mnemonic, ref instr, flags);
            Debug.Assert(instr.OpCount == 1);
            var kreg = instr.OpMask;

            if (kreg != Register.None)
            {
                info.OpCount++;
                info.Op1Kind = InstrOpKind.Register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)kreg;
                info.Flags      |= InstrOpInfoFlags.IgnoreOpMask;
            }
        }
Beispiel #17
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(instr.OpCount == 0);
     info.OpCount = 1;
     info.Op0Kind = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op0Register = (byte)register;
     if (instr.Code == Code.Skinit)
     {
         info.Op0Index = OpAccess_ReadWrite;
     }
     else
     {
         info.Op0Index = OpAccess_Read;
     }
 }
Beispiel #18
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            const InstrOpInfoFlags flags = 0;

            if (options.UsePseudoOps && (instr.Op0Register == Register.ST1 || instr.Op1Register == Register.ST1))
            {
                info          = default;
                info.Mnemonic = mnemonic;
            }
            else
            {
                info = new InstrOpInfo(mnemonic, ref instr, flags);
                Debug.Assert(info.Op1Register == (int)Register.ST0);
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)Registers.Register_ST;
            }
        }
Beispiel #19
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags         = InstrOpInfoFlags.None;
            int instrCodeSize = GetCodeSize(instr.CodeSize);
            var opKind        = instr.GetOpKind(memOpNumber);
            int memSize;

            if (opKind == OpKind.Memory64)
            {
                memSize = 64;
            }
            else
            {
                Debug.Assert(opKind == OpKind.Memory);
                int displSize = instr.MemoryDisplSize;
                memSize = displSize == 2 ? 16 : 32;
            }
            if (instrCodeSize == 0)
            {
                instrCodeSize = memSize;
            }
            if (instrCodeSize != memSize)
            {
                if (memSize == 16)
                {
                    flags |= InstrOpInfoFlags.AddrSize16;
                }
                else if (memSize == 32)
                {
                    flags |= InstrOpInfoFlags.AddrSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.AddrSize64;
                }
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #20
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var  flags         = InstrOpInfoFlags.None;
            int  instrCodeSize = GetCodeSize(instr.CodeSize);
            bool hasMemOp      = instr.Op0Kind == OpKind.Memory || instr.Op1Kind == OpKind.Memory;

            if (hasMemOp && !(instrCodeSize == 0 || (instrCodeSize != 64 && instrCodeSize == codeSize) || (instrCodeSize == 64 && codeSize == 32)))
            {
                if (codeSize == 16)
                {
                    flags |= InstrOpInfoFlags.OpSize16;
                }
                else if (codeSize == 32)
                {
                    flags |= InstrOpInfoFlags.OpSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.OpSize64;
                }
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #21
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags         = this.flags;
            int instrCodeSize = GetCodeSize(instr.CodeSize);

            if (instrCodeSize != 0 && instrCodeSize != codeSize)
            {
                if (codeSize == 16)
                {
                    flags |= InstrOpInfoFlags.OpSize16;
                }
                else if (codeSize == 32)
                {
                    flags |= InstrOpInfoFlags.OpSize32;
                }
                else
                {
                    flags |= InstrOpInfoFlags.OpSize64;
                }
            }
            var prefixSeg = instr.SegmentPrefix;

            if (prefixSeg == Register.CS)
            {
                flags |= InstrOpInfoFlags.IgnoreSegmentPrefix | InstrOpInfoFlags.JccNotTaken;
            }
            else if (prefixSeg == Register.DS)
            {
                flags |= InstrOpInfoFlags.IgnoreSegmentPrefix | InstrOpInfoFlags.JccTaken;
            }
            if (instr.HasRepnePrefix)
            {
                flags |= InstrOpInfoFlags.BndPrefix;
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Beispiel #22
0
        public void TestOptions()
        {
            var options = new IntelFormatterOptions();

            TestOptionsBase(options);
        }
Beispiel #23
0
 public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info) =>
 info = new InstrOpInfo(mnemonic, ref instr, flags);
Beispiel #24
0
        public override void GetOpInfo(IntelFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            Debug.Assert(instr.OpCount == 3);

            var    opKind = instr.Op0Kind;
            OpKind shortFormOpKind;

            switch (instr.CodeSize)
            {
            case CodeSize.Unknown:
                shortFormOpKind = opKind;
                break;

            case CodeSize.Code16:
                shortFormOpKind = OpKind.MemorySegDI;
                break;

            case CodeSize.Code32:
                shortFormOpKind = OpKind.MemorySegEDI;
                break;

            case CodeSize.Code64:
                shortFormOpKind = OpKind.MemorySegRDI;
                break;

            default:
                throw new InvalidOperationException();
            }

            var flags = this.flags;

            if (opKind != shortFormOpKind)
            {
                if (opKind == OpKind.MemorySegDI)
                {
                    flags |= InstrOpInfoFlags.AddrSize16;
                }
                else if (opKind == OpKind.MemorySegEDI)
                {
                    flags |= InstrOpInfoFlags.AddrSize32;
                }
                else if (opKind == OpKind.MemorySegRDI)
                {
                    flags |= InstrOpInfoFlags.AddrSize64;
                }
            }
            info          = default;
            info.Flags    = flags;
            info.Mnemonic = mnemonic;
            info.OpCount  = 2;
            info.Op0Kind  = (InstrOpKind)instr.Op1Kind;
            info.Op0Index = 1;
            Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
            info.Op0Register = (byte)instr.Op1Register;
            info.Op1Kind     = (InstrOpKind)instr.Op2Kind;
            info.Op1Index    = 2;
            Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
            info.Op1Register = (byte)instr.Op2Register;
            var segReg = instr.SegmentPrefix;

            if (segReg != Register.None)
            {
                info.OpCount = 3;
                info.Op2Kind = InstrOpKind.Register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op2Register = (byte)segReg;
                info.Op2Index    = OpAccess_Read;
            }
        }