示例#1
0
        private AcpiData AmlLEqualAction(AmlOp amlOp)
        {
            AcpiData data1   = null;
            AcpiData data2   = null;
            AcpiData amlData = new AcpiData();

            amlData.Name = "Result";
            amlData.Type = AcpiDataType.Int;
            if (amlOp.amlDatas.Count + amlOp.SubOp.Count != 2)
            {
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("");
            }
            if (amlOp.amlDatas.Count == 2)
            {
                data1 = amlOp.amlDatas[0];
                data2 = amlOp.amlDatas[1];
            }
            else if (amlOp.SubOp.Count == 2)
            {
                data1 = actions[amlOp.SubOp[0].OpCode].Invoke(amlOp.SubOp[0]);
                data2 = actions[amlOp.SubOp[1].OpCode].Invoke(amlOp.SubOp[1]);
            }
            else
            {
                data1 = actions[amlOp.SubOp[0].OpCode].Invoke(amlOp.SubOp[0]);
                data2 = amlOp.amlDatas[0];
            }
            //System.Diagnostics.Debug.Assert(false);
            amlData.PutValue(CompareAcpiData(data1, data2));
            return(amlData);
        }
示例#2
0
        private AcpiData AmlNotAction(AmlOp amlOp)
        {
            AcpiData data1   = null;
            AcpiData amlData = new AcpiData();

            amlData.Name = "Result";
            amlData.Type = AcpiDataType.Int;
            if (amlOp.amlDatas.Count + amlOp.SubOp.Count != 1)
            {
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("");
            }
            if (amlOp.amlDatas.Count == 1)
            {
                data1 = amlOp.amlDatas[0];
            }
            else
            {
                data1 = actions[amlOp.SubOp[0].OpCode].Invoke(amlOp.SubOp[0]);
            }
            if (data1 == null)
            {
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("");
            }
            amlData.PutValue(0);
            if (data1.Value == 0)
            {
                amlData.PutValue(1);
            }
            return(amlData);
        }
示例#3
0
        public AcpiData ToBCD()
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this);

            data.Type = AcpiDataType.Int;
            byte[] bytes  = new byte[8];
            string Value  = data.Value.ToString();
            int    Length = Value.Length < 8 ? (int)Value.Length : 8;

            for (int Index = 0; Index < 8; Index++)
            {
                // fill the bytes
                if (Index % 1 == 0)
                {
                    bytes[Index / 2] = (byte)(Value[Index] - 0x30);
                }
                else
                {
                    bytes[Index / 2] = (byte)((Value[Index] - 0x30) << 4);
                }
            }
            data.Value = BitConverter.ToUInt64(bytes, 0);
            return(data);
        }
示例#4
0
        public AcpiData Index(int Index)
        {
            AcpiData data = new AcpiData(this);

            if (this.Type == AcpiDataType.String)
            {
                data.Type  = AcpiDataType.Int;
                data.Value = (UInt64)data.strValue[Index];
            }
            else if (this.Type == AcpiDataType.Packge)
            {
                // TODO, Package may be different type of data
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("public AcpiData Index(int Index)");
                data.Type  = AcpiDataType.Int;
                data.Value = (UInt64)data.bpValue[Index];
            }
            else if (this.Type == AcpiDataType.Buffer)
            {
                data.Type  = AcpiDataType.Int;
                data.Value = (UInt64)data.bpValue[Index];
            }
            else
            {
                return(null);
            }
            return(data);
        }
示例#5
0
        /// <summary>
        /// Add a mixed type of arg/integer or string
        /// </summary>
        /// <param name="Name">name of arg</param>
        /// <param name="arg">string value represent the arg</param>
        public void AddArgs(string Name, string arg)
        {
            // what kind of data...
            AcpiData amlData = new AcpiData();

            amlData.Name = Name;
            if (Name.Equals("Zero"))
            {
                amlData.Type  = AcpiDataType.Int;
                amlData.Value = 0;
            }
            else if (Name.Equals("One"))
            {
                amlData.Type  = AcpiDataType.Int;
                amlData.Value = 1;
            }
            else if (Name.Equals("Ones"))
            {
                amlData.Type  = AcpiDataType.Int;
                amlData.Value = 0xFFFFFFFFFFFFFFFF;
            }
            else
            {
                amlData.Type     = AcpiDataType.String;
                amlData.strValue = arg;
            }
            amlDatas.Add(amlData);
        }
示例#6
0
        public AcpiData ToBuffer()
        {
            if (this.Type != AcpiDataType.Buffer)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this);

            //data.Type = DataType.String;
            if (this.Type == AcpiDataType.Int)
            {
                if (data.Value < 0x100)
                {
                    data.bpValue = BitConverter.GetBytes((byte)data.Value);
                }
                else if (data.Value < 0x10000)
                {
                    data.bpValue = BitConverter.GetBytes((UInt32)data.Value);
                }
                else
                {
                    data.bpValue = BitConverter.GetBytes(data.Value);
                }
            }
            else if (this.Type == AcpiDataType.String)
            {
                data.bpValue = ASCIIEncoding.ASCII.GetBytes(data.strValue);
            }

            data.Type = AcpiDataType.Buffer;
            return(data);
        }
示例#7
0
        private AcpiData AmlDefaultNonLogicalAction(AmlOp amlOp)
        {
            AcpiData amlData = new AcpiData();

            amlData.Name = "Result";
            amlData.Type = AcpiDataType.Int;
            amlData.PutValue(1);
            return(amlData);
        }
示例#8
0
        /// <summary>
        /// Add a integer arg
        /// </summary>
        /// <param name="Name">name of arg</param>
        /// <param name="arg">value of arg</param>
        public void AddArgs(string Name, UInt64 arg)
        {
            // what kind of data...
            AcpiData amlData = new AcpiData();

            amlData.Name  = Name;
            amlData.Type  = AcpiDataType.String;
            amlData.Value = arg;
            amlDatas.Add(amlData);
        }
示例#9
0
 public void ResetDebug()
 {
     // reset all data
     for (int i = 0; i < 8; i++)
     {
         Arg[i]   = null;
         Local[i] = null;
     }
     Result = null;
     amlOps.Clear();
 }
示例#10
0
        public AcpiData Copy(AcpiData amlData)
        {
            AcpiData data = new AcpiData();

            if (this.Type != amlData.Type)
            {
                return(null);
            }
            this.Assign(amlData);
            return(this);
        }
示例#11
0
        public AcpiData Or(AcpiData amlData)
        {
            if (this.Type != amlData.Type || this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this.Value);

            data.Value = data.Value | amlData.Value;
            return(data);
        }
示例#12
0
        public Boolean RunConditionCode(AmlOp amlOp)
        {
            AcpiData bRc = actions[amlOp.OpCode].Invoke(amlOp);

            if (bRc == null || bRc.Type != AcpiDataType.Int)
            {
                // skip to next block.....
                return(false);
            }
            return(bRc.Value != 0);
        }
示例#13
0
        public AcpiData LOp(AcpiData amlData, string OpName)
        {
            if (OpName == "LNot" && this.Type == AcpiDataType.Int)
            {
                AcpiData data = new AcpiData(this.Value);
                data.Value = BoolToUint64(amlData.Value == 0);
                return(data);
            }
            if (this.Type != amlData.Type || this.Type != AcpiDataType.Int)
            {
                return(null);
            }

            if (this.Type == AcpiDataType.Int)
            {
                AcpiData data = new AcpiData(this);
                byte[]   src  = amlData.ToBytes();
                byte[]   dst  = data.ToBytes();
                if (OpName == "LEqual")
                {
                    data.Value = BoolToUint64(amlData.Value == data.Value);
                }
                else if (OpName == "LNotEqual")
                {
                    data.Value = BoolToUint64(amlData.Value != data.Value);
                }
                else if (OpName == "LGreater")
                {
                    data.Value = BoolToUint64(amlData.Value > data.Value);
                }
                else if (OpName == "LGreaterEqual")
                {
                    data.Value = BoolToUint64(amlData.Value >= data.Value);
                }
                else if (OpName == "LLess")
                {
                    data.Value = BoolToUint64(amlData.Value < data.Value);
                }
                else if (OpName == "LLessEqual")
                {
                    data.Value = BoolToUint64(amlData.Value <= data.Value);
                }
                else if (OpName == "LOr")
                {
                    data.Value = BoolToUint64((amlData.Value | data.Value) > 0);
                }
                else if (OpName == "LAnd")
                {
                    data.Value = BoolToUint64((amlData.Value & data.Value) > 0);
                }
                return(data);
            }
            return(null);
        }
示例#14
0
        public AcpiData ShiftRight(int bits)
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this);

            data.Value = data.Value >> bits;
            return(data);
        }
示例#15
0
        public AcpiData ShiftLeft(int bits)
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData();

            data.Assign(this);
            data.Value = data.Value << bits;
            return(data);
        }
示例#16
0
 /// <summary>
 /// To launch the debug view
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void aslText_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F10)
     {
         if (acpiView.SelectedNode.ToolTipText.Equals("Method"))
         {
             List <AcpiData> method_data = null;
             UInt64          args        = 0;
             if (acpiLib.GetMethodArgCount((string)acpiView.SelectedNode.Tag, ref args))
             {
                 if (args == 0)
                 {
                     method_data = new List <AcpiData>();
                 }
                 else
                 {
                     formArgInput.SetArgCount((int)args);
                     formArgInput.ShowDialog();
                     if (formArgInput.GetEvalState())
                     {
                         List <AcpiMethodArg> methodargs = formArgInput.Args;
                         method_data = new List <AcpiData>();
                         foreach (AcpiMethodArg arg in methodargs)
                         {
                             AcpiData amlData = new AcpiData(arg);
                             method_data.Add(amlData);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Canceled method simulation");
                         return;
                     }
                 }
             }
             if (method_data != null)
             {
                 DebugViewForm debugViewForm = new DebugViewForm();
                 debugViewForm.acpiLib     = acpiLib;
                 debugViewForm.MethodArgs  = method_data;
                 debugViewForm.strAcpiPath = (string)acpiView.SelectedNode.Tag;
                 debugViewForm.strAslCode  = (string)aslText.Text;
                 debugViewForm.ShowDialog();
             }
         }
     }
     else if (e.KeyCode == Keys.F12)
     {
         ResizeLayout();
     }
 }
示例#17
0
 public void AslAnalyze(string aslCode, AcpiData[] Args)
 {
     for (int i = 0; i < 8; i++)
     {
         if (aslCode.ToLower().Contains("local" + i.ToString()))
         {
             Local[i]      = new AcpiData();
             Local[i].Name = "Local" + i.ToString();
         }
     }
     for (int i = 0; i < Args.Length; i++)
     {
         Arg[i] = Args[i];
     }
     // parse the used name space one by one now.....
 }
示例#18
0
 //public object Get()
 //{
 //    switch (Type)
 //    {
 //        case AcpiDataType.Int:
 //            return Value;
 //        case AcpiDataType.String:
 //            return strValue;
 //        case AcpiDataType.Buffer:
 //            return bpValue;
 //        case AcpiDataType.Packge:
 //            return Pkg;
 //        default:
 //            return null;
 //    }
 //}
 /// <summary>
 /// Duplicate a acpi data
 /// </summary>
 /// <param name="acpiData">acpi data</param>
 private void Duplicate(AcpiData acpiData)
 {
     this.Type  = acpiData.Type;
     this.Value = acpiData.Value;
     if (acpiData.strValue != null)
     {
         this.strValue = new string(acpiData.strValue.ToArray());
     }
     if (acpiData.bpValue != null)
     {
         this.bpValue = new byte[acpiData.bpValue.Length];
         Array.Copy(acpiData.bpValue, 0,
                    this.bpValue, 0, acpiData.bpValue.Length);
     }
     this.Pkg = acpiData.Pkg;
 }
示例#19
0
        public AcpiData ToString(int Length)
        {
            if (this.Type != AcpiDataType.Buffer)
            {
                return(null);
            }
            if (Length > this.bpValue.Length)
            {
                return(null);
            }
            AcpiData data = new AcpiData();

            data.Assign(this);
            data.Type     = AcpiDataType.String;
            data.strValue = BitConverter.ToString(data.bpValue, 0, Length);
            return(data);
        }
示例#20
0
        //public Boolean IfMethod(AmlOp amlop)
        //{
        //    // only one subs... or one data
        //    if (amlop.SubOp.Count + amlop.amlDatas.Count == 1)
        //    {
        //        if (amlop.amlDatas.Count == 1)
        //        {
        //            if (amlop.amlDatas[0].Type != AcpiDataType.Int)
        //            {
        //                return false;
        //            }
        //            UInt64 value = 0;
        //            amlop.amlDatas[0].Data.GetValue(ref value);
        //            return value != 0;
        //            // check the data
        //        } else
        //        {
        //            // must a logical operation
        //            try
        //            {
        //                return actions[amlop.SubOp[0].OpCode].Invoke(amlop.SubOp[0]);
        //            }catch(Exception)
        //            {
        //                return false;
        //            }
        //        }
        //    }
        //    return false;
        //}
        //public Boolean LAndMethod(AmlOp amlop)
        //{
        //    return false;
        //}

        //public Boolean LEqualMethod(AmlOp amlop)
        //{
        //    // must be
        //    if (amlop.SubOp.Count + amlop.amlDatas.Count != 2)
        //    {
        //        return false;
        //    }

        //    // 2 Data or method from data
        //    if (amlop.SubOp.Count > 0)
        //    {
        //        // Not ready yet
        //        return false;
        //    }
        //    else
        //    {
        //        if (amlop.amlDatas[0].Type == AcpiDataType.Int)
        //        {
        //            // int compare
        //            if (amlop.amlDatas[1].Type == AcpiDataType.Int)
        //            {
        //                return amlop.amlDatas[1].Value == amlop.amlDatas[0].Value;
        //            } else
        //            {
        //                // Not ready yet
        //                return false;
        //            }
        //        } else
        //        {
        //            // Not ready yet
        //            return false;
        //        }
        //    }
        //    return false;
        //}
        //public Boolean LOrMethod(AmlOp amlop)
        //{

        //}

        //public Boolean LNotMethod(AmlOp amlop)
        //{
        //    if (amlop.amlDatas.Count == 1)
        //    {
        //        // it's a data
        //        if (amlop.amlDatas[0].Type != AcpiDataType.Int)
        //        {
        //            return false;
        //        }
        //        return amlop.amlDatas[0].Value == 0;
        //    } else if(amlop.SubOp.Count == 1)
        //    {
        //        return actions[amlop.SubOp[0].OpCode].Invoke(amlop.SubOp[0]);
        //    }
        //    //amlop.
        //    return false;
        //}
        private UInt64 CompareAcpiData(AcpiData data1, AcpiData data2)
        {
            if (data1 == null || data2 == null)
            {
                return(0);
            }
            if (data1.Type != data2.Type)
            {
                return(0);
            }
            if (data1.strValue.Equals(data2.strValue))
            {
                return(1);
            }
            return(0);
            //if (amlOp.amlDatas.Count == 2)
            //{
            //    // both data
            //    if (amlOp.amlDatas[0].Type != amlOp.amlDatas[1].Type)
            //    {
            //        // compare differetnt type
            //        // System.Diagnostics.Debug.Assert(false);
            //        amlData.PutValue(0);
            //        return amlData;
            //    }
            //    else
            //    {
            //        // compare the data....
            //        if (amlOp.amlDatas[0].Data.strVal.Equals(amlOp.amlDatas[1].Data.strVal))
            //        {
            //            amlData.PutValue(1);
            //        }
            //        else
            //        {
            //            amlData.Data.PutValue(0);
            //        }
            //        return amlData;
            //    }
            //}
            //else
            //{

            //}
        }
示例#21
0
        public AcpiData Size()
        {
            if (this.Type == AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this);

            if (this.Type == AcpiDataType.String)
            {
                data.Value = (UInt64)data.strValue.Length;
            }
            else
            {
                data.Value = (UInt64)data.bpValue.Length;
            }
            data.Type = AcpiDataType.Int;
            return(data);
        }
示例#22
0
        private AcpiData AmlLNotEqualAction(AmlOp amlOp)
        {
            AcpiData amlData = AmlLEqualAction(amlOp);

            if (amlData.Type != AcpiDataType.Int)
            {
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("");
            }
            if (amlData.Value != 0)
            {
                amlData.Value = 0;
            }
            else
            {
                amlData.Value = 1;
            }
            return(amlData);
        }
示例#23
0
        public AcpiData Concat(AcpiData amlData)
        {
            AcpiData data = new AcpiData();

            if (this.Type != amlData.Type)
            {
                return(null);
            }
            if (this.Type == AcpiDataType.Buffer)
            {
                data.Assign(this);
                //data.Value = amlData.Value & data.Value;
                byte[] bytes = new byte[data.bpValue.Length + amlData.bpValue.Length];
                data.bpValue.CopyTo(bytes, 0);
                amlData.bpValue.CopyTo(bytes, data.bpValue.Length);
                data.bpValue = bytes;
            }
            return(data);
        }
示例#24
0
        public AcpiData FromBCD()
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data = new AcpiData(this.Value);
            UInt64   bcd  = 0;
            UInt64   mul  = 1;

            byte[] bytes = BitConverter.GetBytes(data.Value);
            foreach (byte bt in bytes)
            {
                bcd *= 100;
                bcd += (10 * ((UInt64)(bt >> 4)));
                bcd += (UInt64)(bt & 0xf);
            }
            data.Value = bcd;
            return(data);
        }
示例#25
0
 public Boolean Equal(AcpiData amlData)
 {
     if (Type != amlData.Type)
     {
         return(false);
     }
     if (Type == AcpiDataType.Int)
     {
         return(Value == amlData.Value);
     }
     else if (Type == AcpiDataType.String)
     {
         return(strValue == amlData.strValue);
     }
     else if (Type == AcpiDataType.Buffer)
     {
         return(bpValue == amlData.bpValue);
     }
     return(false);
 }
示例#26
0
        public AcpiData Mid(int Index, int Length)
        {
            AcpiData data = new AcpiData(this);

            if (this.Type == AcpiDataType.String)
            {
                data.strValue = data.strValue.Substring(Index, Length);
            }
            else if (this.Type == AcpiDataType.Buffer)
            {
                byte[] bytes = new byte[Length];
                Array.Copy(data.bpValue, Index, bytes, 0, Length);
                data.bpValue = bytes;
            }
            else
            {
                return(null);
            }
            return(data);
        }
示例#27
0
        /// <summary>
        /// find the first non zero bit from right to left
        /// </summary>
        /// <returns>most right non zero bit</returns>
        public AcpiData FindRight()
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data  = new AcpiData(this.Value);
            UInt64   value = data.Value;
            int      index = 0;

            for (index = 63; index >= 0; index--)
            {
                if ((value & ((UInt64)(1 << (int)index))) != 0)
                {
                    break;
                }
            }
            data.Value = (UInt64)index;
            return(data);
        }
示例#28
0
        /// <summary>
        /// find the first non zero bit from left to right
        /// </summary>
        /// <returns>most left non zero bit</returns>
        public AcpiData FindLeft()
        {
            if (this.Type != AcpiDataType.Int)
            {
                return(null);
            }
            AcpiData data  = new AcpiData(this.Value);
            UInt64   value = data.Value;
            UInt64   index = 0;

            for (index = 0; index < 64; index++)
            {
                if (((value >> (int)index) & 0x1) != 0)
                {
                    break;
                }
            }
            data.Value = index;
            return(data);
        }
示例#29
0
 /// <summary>
 /// assign the new value of acpi data
 /// </summary>
 /// <param name="acpiData">data</param>
 public void Assign(AcpiData acpiData)
 {
     if (acpiData == null)
     {
         return;
     }
     if (this.Name != null)
     {
         if (this.Name == "Result" ||
             this.Name.StartsWith("InternalLocalData") ||
             this.Name.StartsWith("InternalMethodArg"))
         {
             // set the value normally
             Duplicate(acpiData);
         }
     }
     else
     {
         Duplicate(acpiData);
     }
 }
示例#30
0
        public AcpiData Op(AcpiData amlData, string OpName)
        {
            AcpiData data = new AcpiData();

            if (OpName == "Not")
            {
                data.Assign(this);
                data.Value = ~amlData.Value;
                return(data);
            }
            if (this.Type != amlData.Type)
            {
                return(null);
            }
            if (this.Type == AcpiDataType.Int)
            {
                data.Assign(this);

                if (OpName == "Or")
                {
                    data.Value = amlData.Value | data.Value;
                }
                else if (OpName == "And")
                {
                    data.Value = amlData.Value & data.Value;
                }
                else if (OpName == "NAnd")
                {
                    data.Value = ~(amlData.Value & data.Value);
                }
                else if (OpName == "XOr")
                {
                    data.Value = amlData.Value ^ data.Value;
                }
            }
            return(data);
        }