Trait Parse

Source
pub trait Parse<'a>
where Self: Sized,
{ // Required method fn parse<E: AMLParseError<'a>>( i: ParserState<'a>, ) -> AMLParseResult<'a, Self, E>; }
Expand description

An object that can be parsed from AML bytecode

Required Methods§

Source

fn parse<E: AMLParseError<'a>>( i: ParserState<'a>, ) -> AMLParseResult<'a, Self, E>

Try to parse an object of this type from the given input and state.

§Errors

Returns an error if the data cannot be parsed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> Parse<'a> for ComputationalData<'a>

Grammar:

ComputationalData := ByteConst | WordConst | DWordConst | QWordConst | String |
                     ConstObj | RevisionOp | DefBuffer

ByteConst         := BytePrefix ByteData
BytePrefix        := 0x0A
WordConst         := WordPrefix WordData
WordPrefix        := 0x0B
DWordConst        := DWordPrefix DWordData
DWordPrefix       := 0x0C
QWordConst        := QWordPrefix QWordData
QWordPrefix       := 0x0E
String            := StringPrefix AsciiCharList NullChar
StringPrefix      := 0x0D

ConstObj          := ZeroOp | OneOp | OnesOp
ByteList          := Nothing | <ByteData ByteList>
ByteData          := 0x00 - 0xFF
WordData          := ByteData[0:7] ByteData[8:15]
    // 0x0000-0xFFFF
DWordData         := WordData[0:15] WordData[16:31]
    // 0x00000000-0xFFFFFFFF
QWordData         := DWordData[0:31] DWordData[32:63]
    // 0x0000000000000000-0xFFFFFFFFFFFFFFFF
AsciiCharList     := Nothing | <AsciiChar AsciiCharList>
AsciiChar         := 0x01 - 0x7F
NullChar          := 0x00
ZeroOp            := 0x00
OneOp             := 0x01
OnesOp            := 0xFF
RevisionOp        := ExtOpPrefix 0x30
Source§

impl<'a> Parse<'a> for DataObject<'a>

Grammar:

DataObject := ComputationalData | DefPackage | DefVarPackage
Source§

impl<'a> Parse<'a> for DataRefObject<'a>

Grammar:

DataRefObject := DataObject | ??ObjectReference | ??DDBHandle

From ASL grammar (§19.2.4):

DDBHandle       := Integer
ObjectReference := Integer

However, it is unclear how these two types would be encoded in AML and how they would be distinguished from each other, or from the integral constants under ComputationalData. Consequently, they aren’t implemented

TODO: Figure out why this production exists, and get rid of it if it is no different than DataObject.

Source§

impl<'a> Parse<'a> for PackageElement<'a>

Grammar:

PackageElementList := Nothing | <PackageElement PackageElementList>
PackageElement     := DataRefObject | NameString
Source§

impl<'a> Parse<'a> for ArgObject

Grammar:

ArgObj := Arg0Op | Arg1Op | Arg2Op | Arg3Op | Arg4Op | Arg5Op | Arg6Op
Arg0Op := 0x68
Arg1Op := 0x69
Arg2Op := 0x6A
Arg3Op := 0x6B
Arg4Op := 0x6C
Arg5Op := 0x6D
Arg6Op := 0x6E
Source§

impl<'a> Parse<'a> for LocalObject

Grammar:

LocalObj := Local0Op | Local1Op | Local2Op | Local3Op | Local4Op | Local5Op |
            Local6Op | Local7Op
Local0Op := 0x60
Local1Op := 0x61
Local2Op := 0x62
Local3Op := 0x63
Local4Op := 0x64
Local5Op := 0x65
Local6Op := 0x66
Local7Op := 0x67
Source§

impl<'a> Parse<'a> for PathAnchor

See grammar for NameString.

Source§

impl<'a> Parse<'a> for SimpleName

Grammar:

SimpleName := NameString | ArgObj | LocalObj
Source§

impl<'a> Parse<'a> for SuperName<'a>

Grammar:

SuperName := SimpleName | DebugObj | Type6Opcode

Despite the order given in the grammar, we have to try Type6Opcode before SimpleName. Type6Opcode includes method calls, which would never be reached if SimpleName slurped up the method name first.

Source§

impl<'a> Parse<'a> for ExpressionOpcode<'a>

Grammar:

Type2Opcode := DefAcquire | DefAdd | DefAnd | DefBuffer | DefConcat |
               DefConcatRes | DefCondRefOf | DefCopyObject | DefDecrement |
               DefDerefOf | DefDivide | DefFindSetLeftBit | DefFindSetRightBit |
               DefFromBCD | DefIncrement | DefIndex | DefLAnd | DefLEqual |
               DefLGreater | DefLGreaterEqual | DefLLess | DefLLessEqual | DefMid |
               DefLNot | DefLNotEqual | DefLoadTable | DefLOr | DefMatch | DefMod |
               DefMultiply | DefNAnd | DefNOr | DefNot | DefObjectType | DefOr |
               DefPackage | DefVarPackage | DefRefOf | DefShiftLeft |
               DefShiftRight | DefSizeOf | DefStore | DefSubtract | DefTimer |
               DefToBCD | DefToBuffer | DefToDecimalString | DefToHexString |
               DefToInteger | DefToString | DefWait | DefXOr | MethodInvocation
Source§

impl<'a> Parse<'a> for FieldElement<'a>

Grammar:

FieldList     := Nothing | <FieldElement FieldList>
FieldElement  := NamedField | ReservedField | AccessField | ExtendedAccessField |
                 ConnectField

NamedField    := NameSeg PkgLength
ReservedField := 0x00 PkgLength
ConnectField  := <0x02 NameString> | <0x02 ??BufferData>

Notes:

  • Although the ASL Offset grammar uses an absolute byte offset, the ACPICA compiler seems to translate it into relative bit offset when it outputs the ReservedField op in AML.
  • AccessField and ExtendedAccessField encode the same information and are merged into one enum variant. See access_field and extended_access_field.
  • The ACPICA parser expects BufferData to be a DefBuffer op.
  • The ConnectField op in split into two enum variants to avoid another level of indirection.
Source§

impl<'a> Parse<'a> for MatchOpcode

Grammar:

MatchOpcode := ByteData
    // 0 MTR
    // 1 MEQ
    // 2 MLE
    // 3 MLT
    // 4 MGE
    // 5 MGT
Source§

impl<'a> Parse<'a> for NameSpaceModifier<'a>

Grammar:

NameSpaceModifierObj := DefAlias | DefName | DefScope
Source§

impl<'a> Parse<'a> for NamedObject<'a>

Grammar:

NamedObj := DefBankField | DefCreateBitField | DefCreateByteField |
    DefCreateDWordField | DefCreateField | DefCreateQWordField |
    DefCreateWordField | DefDataRegion | DefExternal | DefOpRegion | DefPowerRes |
    DefProcessor | DefThermalZone

NOTE: The AML grammar does not list the following alternatives as part of NamedObj, but they are defined in the same place as the others. They are also valid alternatives for the NamedObject production in the ASL grammar, so it is reasonable to assume they were omitted by mistake:

  • DefDevice
  • DefEvent
  • DefField
  • DefIndexField
  • DefMethod
  • DefMutex
Source§

impl<'a> Parse<'a> for ObjectType

Values from Table 19-433:

  0   Uninitialized
  1   Integer
  2   String
  3   Buffer
  4   Package
  5   Field Unit
  6   Device
  7   Event
  8   Method
  9   Mutex
  10  Operation Region
  11  Power Resource
  12  Processor
  13  Thermal Zone
  14  Buffer Field
  15  DDB Handle
  16  Debug Object
  >16 Reserved
Source§

impl<'a> Parse<'a> for ReferenceExpressionOpcode<'a>

Grammar:

Type6Opcode := DefRefOf | DefDerefOf | DefIndex | ??UserTermObj

An explanation in the ASL grammar seems to indicate that UserTermObj is synonymous with MethodInvocation.

Source§

impl<'a> Parse<'a> for RegionSpace

Grammar:

RegionSpace          := ByteData
    // 0x00       SystemMemory
    // 0x01       SystemIO
    // 0x02       PCI_Config
    // 0x03       EmbeddedControl
    // 0x04       SMBus
    // 0x05       SystemCMOS
    // 0x06       PciBarTarget
    // 0x07       IPMI
    // 0x08       GeneralPurposeIO
    // 0x09       GenericSerialBus
    // 0x0A       PCC
    // 0x80-0xFF: OEM Defined
Source§

impl<'a> Parse<'a> for StatementOpcode<'a>

Grammar:

Type1Opcode := DefBreak | DefBreakPoint | DefContinue | DefFatal | DefIfElse |
               DefLoad | DefNoop | DefNotify | DefRelease | DefReset | DefReturn |
               DefSignal | DefSleep | DefStall | DefWhile
Source§

impl<'a> Parse<'a> for TermArg<'a>

Grammar:

TermArg     := Type2Opcode | DataObject | ArgObj | LocalObject
TermArgList := Nothing | <TermArg TermArgList>

Note that this syntax does not list NameStrings as valid TermArgs, except as part of MethodInvocation under Type6Opcode. However, it’s abundantly clear that names can be used as references to their values anywhere a term argument is expected. Tests with the ACPICA compiler confirm this. However, bare names are not allowed in TermObj positions, so it isn’t appropriate to add them to Type2Opcode (ExpressionOpcode), and we have to add it to TermArg instead.

Source§

impl<'a> Parse<'a> for TermObject<'a>

Grammar:

TermObj  := Object | Type1Opcode | Type2Opcode
TermList := Nothing | <TermObj TermList>
Object   := NameSpaceModifierObj | NamedObj
Source§

impl<'a> Parse<'a> for Buffer<'a>

Grammar:

DefBuffer  := BufferOp PkgLength BufferSize ByteList
BufferOp   := 0x11
BufferSize := TermArg => Integer
Source§

impl<'a> Parse<'a> for Package<'a>

Grammar:

DefPackage  := PackageOp PkgLength NumElements PackageElementList
PackageOp   := 0x12
NumElements := ByteData
Source§

impl<'a> Parse<'a> for VarPackage<'a>

Grammar:

DefVarPackage  := VarPackageOp PkgLength VarNumElements PackageElementList
VarPackageOp   := 0x13
VarNumElements := TermArg => Integer
Source§

impl<'a> Parse<'a> for DebugObject

Grammar:

DebugObj := DebugOp
DebugOp  := ExtOpPrefix 0x31
Source§

impl<'a> Parse<'a> for NameSeg

Grammar:

NameSeg      := <LeadNameChar NameChar NameChar NameChar>
LeadNameChar := ‘A’-‘Z’ | ‘_’
DigitChar    := ‘0’-‘9’
NameChar     := DigitChar | LeadNameChar
Source§

impl<'a> Parse<'a> for NameString

Grammar:

NameString       := <RootChar NamePath> | <PrefixPath NamePath>
PrefixPath       := Nothing | <‘^’ PrefixPath>
NamePath         := NameSeg | DualNamePath | MultiNamePath | NullName

RootChar         := ‘\’
ParentPrefixChar := ‘^’

NullName         := 0x00
DualNamePath     := DualNamePrefix NameSeg NameSeg
DualNamePrefix   := 0x2E
MultiNamePath    := MultiNamePrefix SegCount NameSeg(SegCount)
MultiNamePrefix  := 0x2F

SegCount         := ByteData
Source§

impl<'a> Parse<'a> for FieldFlags

Grammar:

FieldFlags := ByteData
    // bit 0-3: AccessType
    //          0    AnyAcc
    //          1    ByteAcc
    //          2    WordAcc
    //          3    DWordAcc
    //          4    QWordAcc
    //          5    BufferAcc
    //          6    Reserved
    //          7-15 Reserved
    // bit 4:   LockRule
    //          0    NoLock
    //          1    Lock
    // bit 5-6: UpdateRule
    //          0    Preserve
    //          1    WriteAsOnes
    //          2    WriteAsZeros
    // bit 7:   Reserved (must be 0)
Source§

impl<'a> Parse<'a> for MethodFlags

Grammar:

MethodFlags          := ByteData
    // bit 0-2: ArgCount (0-7)
    // bit 3:   SerializeFlag
    //          0 NotSerialized
    //          1 Serialized
    // bit 4-7: SyncLevel (0x00-0x0f)