Example #1
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);
        }
Example #2
0
 private AcpiData AmlLIfAction(AmlOp amlOp)
 {
     if (amlOp.amlDatas.Count + amlOp.SubOp.Count != 1)
     {
         //System.Diagnostics.Debug.Assert(false);
         Log.Logs("");
     }
     if (amlOp.amlDatas.Count == 1)
     {
         if (amlOp.amlDatas[0].Type != AcpiDataType.Int)
         {
             //System.Diagnostics.Debug.Assert(false);
             Log.Logs("");
         }
         return(amlOp.amlDatas[0]);
     }
     else
     {
         // it's a operation, do a operation then
         return(actions[amlOp.SubOp[0].OpCode].Invoke(amlOp.SubOp[0]));
     }
     //System.Diagnostics.Debug.Assert(false);
     Log.Logs("");
     return(null);
 }
Example #3
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);
        }
Example #4
0
 public Boolean RunOpCode(AmlOp amlOp, ref Boolean isLocical)
 {
     if (IsConditionCode(amlOp))
     {
         try
         {
             Boolean bRC = RunConditionCode(amlOp);
             isLocical = true;
             return(bRC);
         }
         catch (Exception e)
         {
             Log.Logs(e.Message);
             //System.Diagnostics.Debug.Assert(false);
         }
     }
     else
     {
         try
         {
             actions[amlOp.OpCode].Invoke(amlOp);
             isLocical = false;
         }
         catch (Exception e)
         {
             Log.Logs(e.Message);
         }
     }
     return(true);
 }
Example #5
0
        public void ScanForDefinedNS(AcpiLib acpiLib, string aslCode)
        {
            string[] Lines = aslCode.Split(new char[] { '\n' });

            for (int i = 4; i < Lines.Length; i++)
            {
                // parse every line
                // Lines[i] // what is this line
                string line   = Lines[i].Trim();
                string opCode = GetOpCode(ref line);
                if (opCode != null && line.Length > 0 && ValidArgString(line))
                {
                    //AmlOp amlOp = new AmlOp(opCode, i);
                    //amlCurrent = amlOp;
                    AmlOp amlCurrent = new AmlOp(opCode, i);
                    if (!GetArgs(opCode, ref line, ref amlCurrent))
                    {
                        //
                        // TODO: debug assert
                    }
                    amlOps.Add(amlCurrent);
                    //amlCurrent = amlOps.Last();
                }
            }
            InitializeData(acpiLib);
            return;
        }
Example #6
0
        private AcpiData AmlDefaultNonLogicalAction(AmlOp amlOp)
        {
            AcpiData amlData = new AcpiData();

            amlData.Name = "Result";
            amlData.Type = AcpiDataType.Int;
            amlData.PutValue(1);
            return(amlData);
        }
Example #7
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);
        }
Example #8
0
        private Boolean BuildArgs(ref string Line, ref AmlOp amlOp)
        {
            string strInner = Line.Trim();

            strInner = strInner.Substring(strInner.IndexOf("(") + 1).Trim();
            strInner = strInner.Substring(0, strInner.LastIndexOf(")")).Trim();
            int nSubArgs = NumOfChar(strInner, '(');

            // number of Sub Args....
            // string Subs = strInner;
            string[] Subs       = GetWords(strInner);
            AmlOp    currentArg = amlOp;

            for (int idx = 0; idx < Subs.Length; idx++)
            {
                if (Subs[idx].Equals(" "))
                {
                    break;
                }

                if (Subs[idx].Equals(")") && idx + 2 == Subs.Length)
                {
                    break;
                }
                if (Subs[idx + 1].Equals("("))
                {
                    // this word is a operation
                    AmlOp subOp = new AmlOp(Subs[idx]);
                    //subOp.AddSubOp.
                    currentArg.AddSubOp(subOp);
                    currentArg = subOp;
                    idx++;
                }
                else if (Subs[idx + 1].Equals(")"))
                {
                    // End of sub operations
                    currentArg.AddArgs(Subs[idx], Subs[idx]);
                    currentArg = currentArg.ParentOp;
                    idx++;
                }
                else
                {
                    // this word is a args
                    currentArg.AddArgs(Subs[idx], Subs[idx]);
                }
            }
            return(true);
        }
Example #9
0
 private void AddSubData(List <AcpiData> AcpiDatas, AmlOp amlOp)
 {
     if (amlOp.amlDatas.Count > 0)
     {
         foreach (AcpiData amlData in amlOp.amlDatas)
         {
             AcpiDatas.Add(amlData);
         }
     }
     if (amlOp.SubOp.Count > 0)
     {
         foreach (AmlOp subOp in amlOp.SubOp)
         {
             AddSubData(AcpiDatas, subOp);
         }
     }
 }
Example #10
0
        private Boolean GetArgs(string Word, ref string Line, ref AmlOp amlOp)
        {
            int Min, Max;

            Min = 0;
            Max = 0;
            if (!GetMaxMin(Word, ref Min, ref Max))
            {
                return(false);
            }
            if (Max == -2)
            {
                // simple operation without brackets such as Noop, Debug, Break etc
                return(true);
            }

            return(BuildArgs(ref Line, ref amlOp));
        }
Example #11
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);
        }
Example #12
0
 private void UpdateData(AmlOp amlOp)
 {
     if (amlMethod != null)
     {
         List <AcpiData>      args       = amlMethod.ViewArgData();
         List <AcpiData>      locals     = amlMethod.ViewLocalData();
         List <AcpiData>      datas      = amlMethod.ViewDefinedData();
         List <AmlMethodData> methodData = new List <AmlMethodData>();
         // convert to method args data...
         if (args.Count > 0)
         {
             foreach (AcpiData amlData in args)
             {
                 methodData.Add(new AmlMethodData(amlData));
             }
         }
         if (locals.Count > 0)
         {
             foreach (AcpiData amlData in locals)
             {
                 methodData.Add(new AmlMethodData(amlData));
             }
         }
         if (datas.Count > 0)
         {
             foreach (AcpiData amlData in datas)
             {
                 methodData.Add(new AmlMethodData(amlData));
             }
         }
         if (amlOp != null && amlOp.OpCode == "Return")
         {
             amlOp.Result.Name = "Return";
             methodData.Add(new AmlMethodData(amlOp.Result));
         }
         dataGridView1.DataSource = methodData;
         dataGridView1.Update();
         dataGridView1.Refresh();
         dataGridView1.IsAccessible = false;
     }
 }
Example #13
0
        private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.F10 && e.KeyCode != Keys.F12)
            {
                return;
            }
            if (e.KeyCode == Keys.F12)
            {
                if (MethodDone)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                return;
            }
            // check status
            AmlOp amlOp = null;

            if (amlMethod == null || MethodDone == true)
            {
                if (MethodDone)
                {
                    MessageBox.Show("Code running done, Press F12 to return");
                }
                return;
            }
            // run step code
            amlOp = amlMethod.RunStep();
            if (amlMethod.HasError())
            {
                MessageBox.Show("Aml code debug encount an error, code may not run correct if continue running");
            }
            if (amlOp == null)
            {
                // finish or failed to run code mark method done
                MethodDone = true;
            }
            else
            {
                if (amlOp.OpCode == "Return")
                {
                    // there is a return code from method, mark its done
                    MethodDone = true;
                    Result     = amlOp.Result;
                    UpdateData(amlOp);
                    List <AmlMethodData> methodDatas = (List <AmlMethodData>)dataGridView1.DataSource;
                    if (methodDatas != null)
                    {
                        methodDatas.Add(new AmlMethodData(amlOp.Result));
                        dataGridView1.DataSource = methodDatas;
                        dataGridView1.Update();
                        dataGridView1.Refresh();
                        dataGridView1.IsAccessible = false;
                    }
                }
                else
                {
                    UpdateData(null);
                }
                richTextBox2.Text = amlMethod.NextCode();
            }
            if (!MethodDone)
            {
                //int nHightLine
                DeactiveLine(nHightLine);
                int hLine = amlMethod.GetLine();
                if (hLine > 2)
                {
                    nHightLine = hLine;
                    ActiveLine(hLine);
                }
                if (hLine == 0)
                {
                    ActiveLine(-1);
                }
            }
            else
            {
                MessageBox.Show("Code running done, Press F12 to return");
            }
        }
Example #14
0
 private AcpiData AmlDefaultAction(AmlOp amlOp)
 {
     //System.Diagnostics.Debug.Assert(false);
     Log.Logs("");
     return(null);
 }
Example #15
0
        private void ParseSubData(List <AcpiData> AcpiDatas, AmlOp amlOp)
        {
            if (amlOp.amlDatas.Count > 0)
            {
                foreach (AcpiData amlData in amlOp.amlDatas)
                {
                    try
                    {
                        if (amlLocalDataMap[amlData.Name] == 1)
                        {
                            continue;   // if the name is already exiting
                        }
                    } catch (Exception e) {
                        if (amlData.Name.Equals("Zero"))
                        {
                            continue;
                        }
                        if (amlData.Name.Equals("One"))
                        {
                            continue;
                        }
                        if (amlData.Name.Equals("Ones"))
                        {
                            continue;
                        }
                        if (IsIntString(amlData.Name))
                        {
                            continue;
                        }
                        // test is it a hex or decimal code
                        if (amlData.Type != AcpiDataType.Int)
                        {
                            amlData.QueryData(AcpiNS, amlData.Name);
                            //if (localAcpiLib != null)
                            //{
                            //    string Path = AcpiNS;
                            //    int nType = localAcpiLib.GetType(Path + amlData.Name);
                            //    while (nType == -1)
                            //    {
                            //        Path = Path.Substring(0, Path.Length - 4);
                            //        if (Path.Length < 4)
                            //        {
                            //            break;
                            //        }
                            //        nType = localAcpiLib.GetType(Path + amlData.Name);
                            //    }
                            //    if (nType != -1)
                            //    {
                            //        ushort Type = (ushort)nType;
                            //        amlData.Type = (AcpiDataType)nType;
                            //        // get the data directory
                            //        amlData.QueryData(Path, amlData.Name);
                            //        //IntPtr intPtr = localAcpiLib.GetValue(Path + amlData.Name, ref Type);
                            //        //if (intPtr != IntPtr.Zero)
                            //        //{
                            //        //    if (Type == (ushort)AcpiDataType.Int)
                            //        //    {                                        // get the data..
                            //        //        amlData.Value = ((UInt64)Marshal.ReadInt64(intPtr + 0x10));

                            //        //    }
                            //        //    else
                            //        //    {
                            //        //        // TODO ....
                            //        //        amlData.Value = ((UInt64)Marshal.ReadInt64(intPtr + 0x10));
                            //        //    }
                            //        //    localAcpiLib.FreeArg(intPtr);
                            //        //}
                            //    }
                            //}
                        }
                        AcpiDatas.Add(amlData);
                        amlLocalDataMap[amlData.Name] = 1;
                    }
                }
            }
            if (amlOp.SubOp.Count > 0)
            {
                foreach (AmlOp subOp in amlOp.SubOp)
                {
                    ParseSubData(AcpiDatas, subOp);
                }
            }
        }
Example #16
0
 /// <summary>
 /// Add a sub AmlOp
 /// </summary>
 /// <param name="amlSubOp">sub operation</param>
 public void AddSubOp(AmlOp amlSubOp)
 {
     amlSubOp.ParentOp = this;
     SubOp.Add(amlSubOp);
 }
Example #17
0
 public Boolean IsConditionCode(AmlOp amlOp)
 {
     return(ConditionOpCode.IndexOf(amlOp.OpCode) >= 0);
 }