Example #1
0
        public override void Write(AcpiObject valueObj)
        {
            if ((startBitIndex % 8) != 0 || (numBits % 8) != 0)
            {
                throw new AmlTypeException("TODO: Non-byte-aligned buffer fields");
            }

            ulong value = valueObj.GetAsInt().Value;

            // We ignore high bits above the number of bits fitting in the field.
            // Used to check this, but some code actually depends on the behavior of
            // truncating high bits, like this from VPC:

            // Method (_CRS, 0, NotSerialized)
            // {
            //     CreateDWordField (CRS, \_SB.SYSM._Y10._BAS, BAS4)
            //     CreateDWordField (CRS, \_SB.SYSM._Y10._LEN, LEN4)
            //     Subtract (0x00, BAS4, LEN4)
            // }

            // NB write in little endian byte-order
            ulong end = startBitIndex / 8u + numBits / 8u;

            for (ulong idx = startBitIndex / 8u; idx < end; idx++)
            {
                sourceBuffer.SetIndex(idx, new Integer(value & 0xFF));
                value >>= 8;
            }
        }
        public override void Visit(Index node)
        {
            AcpiObject.AcpiObject container = thread.Pop().Read();
            ulong index = thread.Pop().Read().GetAsInt().Value;

            thread.Push(new ValueIoLocation(new AcpiObject.BufferField(container, index * 8, 8)));
        }
Example #3
0
 public override void Visit(AmlParser.DefVarPackage defVarPackage)
 {
     defVarPackage.varNumElements.integer.Accept(this);
     AcpiObject.AcpiObject numElementsObj = result;
     CheckObjectType(numElementsObj, AcpiObjectType.Integer);
     VisitPackage((byte)(((AcpiObject.Integer)(numElementsObj.GetTarget())).Value),
                  defVarPackage.packageElementList);
 }
        public override void Write(AcpiObject.AcpiObject value)
        {
#if SINGULARITY_KERNEL
            DebugStub.WriteLine("ACPI DEBUG: " + value.ToString());
#else
            Console.WriteLine("ACPI DEBUG: " + value.ToString());
#endif
        }
 public override void Visit(JumpIfNonZero node)
 {
     AcpiObject.AcpiObject predicate = thread.Pop().Read();
     if (predicate.GetAsInt().Value != 0)
     {
         Frame.JumpTo(node.ThenTarget - 1); // Minus one because IP will still advance
     }
 }
Example #6
0
 public override AcpiObject[] GetObjects()
 {
     AcpiObject[] result = new AcpiObject[objectList.Length];
     for (ulong index = 0; index < (ulong)objectList.Length; index++)
     {
         result[index] = this.Index(index);
     }
     return(result);
 }
Example #7
0
 public override void Visit(AmlParser.DefCreateField defCreateField)
 {
     AcpiObject.AcpiObject sizeObj = LoadTimeEvaluate(defCreateField.numBits.integer);
     CheckObjectType(sizeObj, AcpiObjectType.Integer);
     VisitField(defCreateField.sourceBuff,
                defCreateField.bitIndex.integer, 1,
                ((AcpiObject.Integer)(sizeObj.GetTarget())).Value,
                defCreateField.nameString.nodePath);
 }
 public void Exit(AcpiObject.AcpiObject exitValue)
 {
     exited         = true;
     this.exitValue = exitValue;
     if (callback != null)
     {
         callback(ExitValue);
     }
 }
Example #9
0
 public override void Write(AcpiObject value)
 {
     if (this == IntegerConstant.Zero ||
         this == IntegerConstant.One ||
         this == IntegerConstant.Ones)
     {
         throw new AmlTypeException("Cannot write to reserved integer constant objects");
     }
     this.value = value.GetAsInt().Value;
 }
Example #10
0
        public BufferField(AcpiObject sourceBuffer, ulong startBitIndex, ulong numBits)
        {
            if (numBits > sizeof(ulong) * 8)
            {
                throw new AmlTypeException("Tried to create field with more than maximum number of bits");
            }

            this.sourceBuffer  = sourceBuffer;
            this.startBitIndex = startBitIndex;
            this.numBits       = numBits;
        }
 public void Return(AcpiObject.AcpiObject result)
 {
     frameStack.Pop().Dispose();
     if (frameStack.IsEmpty())
     {
         Exit(result);
     }
     else
     {
         Push(new ValueIoLocation(result));
     }
 }
        public override void Visit(MethodCall node)
        {
            IoLocation methodLocation = thread.Pop();
            Method     method         = methodLocation.Read().GetAsMethod();

            AcpiObject.AcpiObject[] args = new AcpiObject.AcpiObject[method.ArgCount];
            for (int i = 0; i < method.ArgCount; i++)
            {
                args[i] = thread.Pop().Read();
            }

            thread.InvokeMethod(method, args);
        }
Example #13
0
            public override void Visit(AmlParser.DefOpRegion defOpRegion)
            {
                AcpiObject.AcpiObject startIndexObj = LoadTimeEvaluate(defOpRegion.regionOffset.integer);
                AcpiObject.AcpiObject lengthObj     = LoadTimeEvaluate(defOpRegion.regionLen.integer);
                CheckObjectType(lengthObj, AcpiObjectType.Integer);

                Node node = acpiNamespace.LookupNode(defOpRegion.nameString.nodePath, currentPath);

                node.Value = new AcpiObject.OperationRegion(loader.OperationRegionAccessor,
                                                            (RegionSpace)defOpRegion.regionSpace.byteData,
                                                            startIndexObj.GetAsInt().Value,
                                                            ((AcpiObject.Integer)(lengthObj.GetTarget())).Value);
            }
        public override void Visit(Concatenate node)
        {
            AcpiObject.AcpiObject leftObj  = thread.Pop().Read();
            AcpiObject.AcpiObject rightObj = thread.Pop().Read();

            if (leftObj is AcpiObject.String)
            {
                string leftStr  = leftObj.GetAsString().Value;
                string rightStr = rightObj.GetAsString().Value;
                thread.Push(new ValueIoLocation(new AcpiObject.String(leftStr + rightStr)));
            }
            else
            {
                throw new InterpretException("Concatenate only implemented for strings");
            }
        }
Example #15
0
            public void VisitField(AmlParser.SourceBuff sourceBuff,
                                   TermArg indexTermArg, ulong bitIndexMultiplier,
                                   ulong bitSize,
                                   NodePath fieldName)
            {
                AcpiObject.AcpiObject indexObj = LoadTimeEvaluate(indexTermArg);
                CheckObjectType(indexObj, AcpiObjectType.Integer);

                ulong index    = ((AcpiObject.Integer)(indexObj.GetTarget())).Value;
                ulong bitIndex = index * bitIndexMultiplier;

                AcpiObject.AcpiObject bufferObj = LoadTimeEvaluate(sourceBuff.buffer);
                CheckObjectType(bufferObj, AcpiObjectType.Buffer);

                Node node = acpiNamespace.LookupNode(fieldName, currentPath);

                node.Value = new BufferField((AcpiObject.Buffer)(bufferObj.GetTarget()), bitIndex, bitSize);
            }
 public Node FindValue(AcpiObject.AcpiObject value)
 {
     if (this.Value == value)
     {
         return(this);
     }
     else if (childByNameMap != null)
     {
         foreach (Node child in childByNameMap.Values)
         {
             Node result = child.FindValue(value);
             if (result != null)
             {
                 return(result);
             }
         }
     }
     return(null);
 }
Example #17
0
        /// <summary>
        /// This is currently just used by IndexField, will probably become accessible
        /// from AML when implementing stores.
        /// </summary>
        public override void Write(AcpiObject valueObj)
        {
            ulong value = valueObj.GetAsInt().Value;

            Debug.Assert(AcpiObjectUtils.GetNumBits(value) <= (ulong)numBits, "Writing value too large for field");

            if (numBits == 8 && (startBitIndex % 8) == 0)
            {
                operationRegion.Write8At((ulong)(startBitIndex / 8), (byte)value);
            }
            else if (numBits == 16 && (startBitIndex % 8) == 0)
            {
                operationRegion.Write16At((ulong)(startBitIndex / 8), (byte)value);
            }
            else if (numBits == 32 && (startBitIndex % 8) == 0)
            {
                operationRegion.Write32At((ulong)(startBitIndex / 8), (byte)value);
            }
            else
            {
                throw new Exception("Unimplemented operation region field size");
            }
        }
Example #18
0
        private static string HidObjectToDeviceId(AcpiObject.AcpiObject obj)
        {
            AcpiObject.AcpiObjectType type =
                (AcpiObject.AcpiObjectType)((AcpiObject.Integer)(obj.ObjectType())).Value;
            string hid;

            if (type == AcpiObject.AcpiObjectType.Integer)
            {
                // Swap byte order so that all fields are contiguous
                ulong eisaId = ByteOrder.Swap((uint)(((AcpiObject.Integer)obj).Value));
                hid = String.Format("{0}{1}{2}{3:X}{4:X}{5:X}{6:X}",
                                    (char)(((eisaId >> 26) & 0x1F) + '@'),
                                    (char)(((eisaId >> 21) & 0x1F) + '@'),
                                    (char)(((eisaId >> 16) & 0x1F) + '@'),
                                    (eisaId >> 12) & 0xF,
                                    (eisaId >> 8) & 0xF,
                                    (eisaId >> 4) & 0xF,
                                    (eisaId >> 0) & 0xF);
            }
            else if (type == AcpiObject.AcpiObjectType.String)
            {
                hid = ((AcpiObject.String)obj).Value;
            }
            else
            {
                throw new ArgumentException("_HID object was not an integer or string as expected");
            }

            if (hid.StartsWith("PNP"))
            {
                return("/pnp/" + hid);
            }
            else
            {
                return("/acpi/" + hid);
            }
        }
 public void SetLocal(int localNum, AcpiObject.AcpiObject value)
 {
     locals[localNum].Write(value);
 }
 public abstract void Write(AcpiObject.AcpiObject value);
Example #21
0
        private static AcpiDevice[] GetDeviceInfo(AcpiObject.IOperationRegionAccessor operationRegionAccessor)
        {
            ArrayList deviceInfo = new ArrayList();

            AmlInterpreter interpreter = new AmlInterpreter(acpiNamespace, operationRegionAccessor);

            foreach (AcpiNamespace.Node crsNode in acpiNamespace.GetAllNodes())
            {
                if (crsNode.Name != "_CRS")
                {
                    continue;
                }

                VerboseOut.Write("Loading resource descriptors for ACPI device ");
                foreach (string segment in crsNode.Path.RemoveSegment().NameSegments)
                {
                    VerboseOut.Write(segment + "\\");
                }
                VerboseOut.WriteLine();

                AcpiNamespace.Node hidNode =
                    acpiNamespace.LookupNode(crsNode.Path.RemoveSegmentAbsolute().AddSegmentAbsolute("_HID"));
                if (hidNode == null)
                {
                    throw new Exception("Found device with _CRS property but no matching _HID property");
                }

                AcpiObject.AcpiObject hidObject = hidNode.Value;
                if (hidObject is AcpiObject.BytecodeMethod)
                {
                    AmlInterpreterThread thread =
                        interpreter.InvokeMethodOnNewThread(null, hidNode.Path, new AcpiObject.AcpiObject[] { });
                    interpreter.Run();
                    hidObject = thread.ExitValue;
                }
                string deviceId = HidObjectToDeviceId(hidObject);

                AcpiObject.AcpiObject crsObject = crsNode.Value;
                if (crsObject is AcpiObject.BytecodeMethod)
                {
                    AmlInterpreterThread thread =
                        interpreter.InvokeMethodOnNewThread(null, crsNode.Path, new AcpiObject.AcpiObject[] { });
                    interpreter.Run();
                    crsObject = thread.ExitValue;
                }

                if (crsObject is AcpiObject.Buffer)
                {
                    byte[] crsBuffer = crsObject.GetAsBuffer().Contents;
                    ResourceDescriptor[] resourceDescriptors = ResourceDescriptorParser.Parse(crsBuffer);

                    VerboseOut.WriteLine("Loaded resource descriptor for device " + deviceId);

                    deviceInfo.Add(new AcpiDevice(deviceId, resourceDescriptors));
                }
                else
                {
                    VerboseOut.WriteLine("No resource descriptor for device " + deviceId);
                }
            }

            return((AcpiDevice[])deviceInfo.ToArray(typeof(AcpiDevice)));
        }
 public VariableIoLocation()
 {
     value = new UninitializedObject();
 }
 public override void Write(AcpiObject.AcpiObject value)
 {
     throw new InterpretException("Attempt to store to temporary object");
 }
 public ValueIoLocation(AcpiObject.AcpiObject acpiObject)
 {
     this.value = acpiObject;
 }