This class represents an x86 32-bit register
Inheritance: Register
Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Memory"/> class.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="_base">The _base.</param>
        /// <param name="index">The index.</param>
        /// <param name="scale">The scale.</param>
        public Memory(SegType segment, R32Type _base, R32Type index, byte scale)
        {
            this.segment = segment;
            this._base   = _base;
            this.index   = index;
            this.scale   = scale;

            Check32Values();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Memory"/> class.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="_base">The _base.</param>
        /// <param name="index">The index.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="displacement">The displacement.</param>
        public Memory(SegType segment, R32Type _base, R32Type index, byte scale, Int32 displacement)
        {
            this.segment      = segment;
            this._base        = _base;
            this.index        = index;
            this.scale        = scale;
            this.Displacement = displacement;

            Check32Values();
        }
Exemple #3
0
		/// <summary>
		/// Utility used to implement null reference checking for the 'ldfld' family of instructions
		/// as well as for the implementation of 'call' for non-static methods. The method will
		/// encode a call to the runtime's null reference handler (marked with
		/// SharpOS.AOT.Attributes.NullReferenceHandlerAttribute), which is executed if the value
		/// in the 32-bit x86 register <paramref name="reg" /> is zero (null).
		/// </summary>
		private void NullCheck (R32Type reg)
		{
			string okLabel = this.assembly.GetCMPLabel;

			this.assembly.CMP (reg, 0);
			this.assembly.JNE (okLabel);
			this.assembly.CALL (this.assembly.Engine.NullReferenceHandler.AssemblyLabel);

			this.assembly.LABEL (okLabel);
		}
Exemple #4
0
		/// <summary>
		/// SUB mem32,reg32
		/// </summary>
		public static void SUB (DWordMemory target, R32Type source)
		{
		}
Exemple #5
0
		/// <summary>
		/// SHRD rmreg32,reg32,CL
		/// </summary>
		public static void SHRD___CL (R32Type target, R32Type source)
		{
		}
Exemple #6
0
		/// <summary>
		/// SHRD mem32,reg32,CL
		/// </summary>
		public unsafe static void SHRD___CL (UInt32* target, R32Type source)
		{
		}
Exemple #7
0
		/// <summary>
		/// SHRD mem32,reg32,imm8
		/// </summary>
		public unsafe static void SHRD (UInt32* target, R32Type source, Byte value)
		{
		}
Exemple #8
0
		/// <summary>
		/// MOVZX reg32,mem16
		/// </summary>
		public unsafe static void MOVZX (R32Type target, UInt16* source)
		{
		}
Exemple #9
0
		/// <summary>
		/// BOUND reg32,mem
		/// </summary>
		public static void BOUND (R32Type target, Memory source)
		{
		}
Exemple #10
0
		/// <summary>
		/// POP reg32
		/// </summary>
		public static void POP (R32Type target)
		{
		}
Exemple #11
0
		/// <summary>
		/// NOT rmreg32
		/// </summary>
		public static void NOT (R32Type target)
		{
		}
Exemple #12
0
		/// <summary>
		/// NEG rmreg32
		/// </summary>
		public static void NEG (R32Type target)
		{
		}
Exemple #13
0
		/// <summary>
		/// MUL rmreg32
		/// </summary>
		public static void MUL (R32Type target)
		{
		}
Exemple #14
0
		/// <summary>
		/// MOVZX reg32,rmreg16
		/// </summary>
		public static void MOVZX (R32Type target, R16Type source)
		{
		}
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QWordMemory"/> class.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="_base">The _base.</param>
 /// <param name="index">The index.</param>
 /// <param name="scale">The scale.</param>
 /// <param name="displacement">The displacement.</param>
 public QWordMemory(SegType segment, R32Type _base, R32Type index, byte scale, Int32 displacement)
     : base(segment, _base, index, scale, displacement)
 {
 }
Exemple #16
0
		/// <summary>
		/// Initializes a new instance of the <see cref="QWordMemory"/> class.
		/// </summary>
		/// <param name="segment">The segment.</param>
		/// <param name="_base">The _base.</param>
		/// <param name="index">The index.</param>
		/// <param name="scale">The scale.</param>
		/// <param name="displacement">The displacement.</param>
		public QWordMemory (SegType segment, R32Type _base, R32Type index, byte scale, Int32 displacement)
			: base (segment, _base, index, scale, displacement)
		{
		}
Exemple #17
0
		/// <summary>
		/// BOUND reg32,mem
		/// </summary>
		public unsafe static void BOUND (R32Type target, byte* source)
		{
		}
Exemple #18
0
		/// <summary>
		/// SHRD mem32,reg32,imm8
		/// </summary>
		public static void SHRD (DWordMemory target, R32Type source, Byte value)
		{
		}
Exemple #19
0
		/// <summary>
		/// PUSH reg32
		/// </summary>
		public static void PUSH (R32Type target)
		{
		}
Exemple #20
0
		/// <summary>
		/// SHRD mem32,reg32,CL
		/// </summary>
		public static void SHRD___CL (DWordMemory target, R32Type source)
		{
		}
Exemple #21
0
		/// <summary>
		/// ROL rmreg32,CL
		/// </summary>
		public static void ROL__CL (R32Type target)
		{
		}
Exemple #22
0
		/// <summary>
		/// SHRD rmreg32,reg32,imm8
		/// </summary>
		public static void SHRD (R32Type target, R32Type source, Byte value)
		{
		}
Exemple #23
0
		/// <summary>
		/// BSWAP reg32
		/// </summary>
		public static void BSWAP (R32Type target)
		{
		}
Exemple #24
0
		/// <summary>
		/// BTC rmreg32,reg32
		/// </summary>
		public static void BTC (R32Type target, R32Type source)
		{
		}
Exemple #25
0
		/// <summary>
		/// SBB reg32,mem32
		/// </summary>
		public static void SBB (R32Type target, DWordMemory source)
		{
		}
Exemple #26
0
		/// <summary>
		/// SUB mem32,reg32
		/// </summary>
		public unsafe static void SUB (UInt32* target, R32Type source)
		{
		}
Exemple #27
0
		/// <summary>
		/// SBB reg32,mem32
		/// </summary>
		public unsafe static void SBB (R32Type target, UInt32* source)
		{
		}
Exemple #28
0
		/// <summary>
		/// SBB rmreg32,reg32
		/// </summary>
		public static void SBB (R32Type target, R32Type source)
		{
		}
Exemple #29
0
		/// <summary>
		/// SBB rmreg32,imm32
		/// </summary>
		public static void SBB (R32Type target, UInt32 source)
		{
		}
Exemple #30
0
        /// <summary>
        /// Encodes the specified bits32.
        /// </summary>
        /// <param name="bits32">if set to <c>true</c> [bits32].</param>
        /// <param name="spareRegister">The spare register.</param>
        /// <param name="binaryWriter">The binary writer.</param>
        /// <returns></returns>
        public bool Encode(bool bits32, byte spareRegister, BinaryWriter binaryWriter)
        {
            byte value = (byte)(spareRegister * 8);

            if (bits32 != this.bits32Address && (this._base != null || this.index != null))
            {
                throw new EngineException("Wrong kind of address. (16bit/32bit mix not allowed)");
            }

            if (bits32)
            {
                R32Type _base = (R32Type)this._base, index = (R32Type)this.index;
                Int32   displacement    = this.displacement;
                bool    displacementSet = this.displacementSet;
                byte    scale           = this.scale;

                if ((this._base == null && this.index != null && this.scale == 0) ||
                    this.index == R32.ESP)
                {
                    _base = (R32Type)this.index;
                    index = (R32Type)this._base;
                }

                if (_base == null && index != null && scale == 1)
                {
                    _base = index;
                    scale = 0;
                }

                bool fixEBP = false;

                if (!displacementSet && _base == R32.EBP)                 // && index == null) || (_base == null && index == R32.EBP)))
                {
                    fixEBP          = true;
                    displacementSet = true;
                    displacement    = 0;
                }

                bool shortDisplacement = false;

                if (displacementSet != false)
                {
                    if (_base == null && index == null)
                    {
                        value += 5;

                        binaryWriter.Write(value);

                        binaryWriter.Write((UInt32)displacement);

                        return(true);
                    }
                    else if (_base != null)
                    {
                        if (fixEBP || (displacement >= -0x80 && displacement <= 0x7f))
                        {
                            shortDisplacement = true;
                            value            += 1 * 64;                  // 8bit
                        }
                        else
                        {
                            value += 2 * 64;                             // 32bit
                        }
                    }
                }

                if (_base != R32.ESP && index == null)
                {
                    value += _base.Index;
                }
                else
                {
                    value += 0x04;
                }

                binaryWriter.Write(value);

                if (_base == R32.ESP || index != null)
                {
                    value = (byte)(scale * 64);

                    if (index != null)
                    {
                        value += (byte)(index.Index * 8);
                    }
                    else
                    {
                        value += 0x20;
                    }

                    if (_base != null)
                    {
                        value += _base.Index;
                    }
                    else
                    {
                        value += 0x05;
                    }

                    binaryWriter.Write(value);

                    if (!this.displacementSet && _base == null)
                    {
                        binaryWriter.Write((UInt32)0);
                    }
                }

                if (displacementSet)
                {
                    if (fixEBP || shortDisplacement)                     //(displacement >= -0x80 && displacement <= 0x7f))
                    {
                        binaryWriter.Write((byte)displacement);
                    }

                    else
                    {
                        binaryWriter.Write((UInt32)displacement);
                    }
                }
            }
            else
            {
                byte  rm;
                Int16 displacement = (Int16)this.displacement;

                if (this._base == R16.BX && this.index == R16.SI)
                {
                    rm = 0;
                }
                else if (this._base == R16.BX && this.index == R16.DI)
                {
                    rm = 1;
                }
                else if (this._base == R16.BP && this.index == R16.SI)
                {
                    rm = 2;
                }
                else if (this._base == R16.BP && this.index == R16.DI)
                {
                    rm = 3;
                }
                else if (this._base == R16.SI && this.index == null)
                {
                    rm = 4;
                }
                else if (this._base == R16.DI && this.index == null)
                {
                    rm = 5;
                }
                else if (this._base == R16.BP && this.index == null)
                {
                    rm = 6;

                    if (!displacementSet)
                    {
                        value += 0x46;
                        binaryWriter.Write(value);
                        binaryWriter.Write((byte)0);
                        return(true);
                    }
                }
                else if (this._base == R16.BX && this.index == null)
                {
                    rm = 7;
                }
                else
                {
                    rm = 6;
                }

                value += rm;

                if (this._base != null || this.index != null)
                {
                    if (displacementSet != false)
                    {
                        if (displacement >= -0x80 && displacement <= 0x7f)
                        {
                            value += 0x40;                             // 8Bit
                        }
                        else
                        {
                            value += 0x80;                             // 16Bit
                        }
                    }
                }

                binaryWriter.Write(value);

                if (displacementSet != false)
                {
                    if (displacement >= -0x80 && displacement <= 0x7f)
                    {
                        binaryWriter.Write((byte)displacement);
                    }
                    else
                    {
                        binaryWriter.Write((UInt16)displacement);
                    }
                }
            }

            return(true);
        }
Exemple #31
0
		/// <summary>
		/// SHR rmreg32,CL
		/// </summary>
		public static void SHR__CL (R32Type target)
		{
		}
Exemple #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QWordMemory"/> class.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="_base">The _base.</param>
 /// <param name="index">The index.</param>
 /// <param name="scale">The scale.</param>
 public QWordMemory(SegType segment, R32Type _base, R32Type index, byte scale)
     : base(segment, _base, index, scale)
 {
 }
Exemple #33
0
		/// <summary>
		/// SHR rmreg32,imm8
		/// </summary>
		public static void SHR (R32Type target, Byte source)
		{
		}
Exemple #34
0
		/// <summary>
		/// Initializes a new instance of the <see cref="QWordMemory"/> class.
		/// </summary>
		/// <param name="segment">The segment.</param>
		/// <param name="_base">The _base.</param>
		/// <param name="index">The index.</param>
		/// <param name="scale">The scale.</param>
		public QWordMemory (SegType segment, R32Type _base, R32Type index, byte scale)
			: base (segment, _base, index, scale)
		{
		}
Exemple #35
0
		/// <summary>
		/// MOVZX reg32,mem16
		/// </summary>
		public static void MOVZX (R32Type target, WordMemory source)
		{
		}