AML语法

368 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第18天,点击查看活动详情

简介

本章主要介绍了构成AML字节流的字节值。

一、语法定义?

AML的编码可以分为以下几组:

  • 表和表头编码
  • 名称对象编码
  • 数据对象编码
  • 包长度编码
  • 术语对象编码
  • 杂项对象编码

二、表和表头编码

表和表头编码的示例如下:


AMLCode     := DefBlockHeader TermList

DefBlockHeader      := TableSignature TableLength SpecCompliance CheckSum OemID

TableSignature      := DWordData        // As defineed insection 5.2.3
TableLength         := DWordData        // Length of the table in bytes including the block header.

SpecCompliance      := ByteData         // The revision of the structure.
CheckSum            := ByteData         // Byte checksum of the entire table.
OemID               := ByteData(6)      // OEM ID of up to 6 characters.If the OEM ID is shorter than 6 characters,itcan be terminated with a NULL character.

OemTableID          := ByteData(8)      // OEM Table ID of up to 8 characters.If the OEM Table ID is shorter than 8 characters,itcan be terminated with a NULL character.

OemRevision         := DWordData        // OEM Table Revision.

CreatorID           := DWordData        // Vendor ID of the ASL compiler.

CreatorRevision     := DWordData        // Revision of the ASL compiler.

三、名字对象编码

相关名字编码示例如下:

LeadNameChar := ‘A’-‘Z’ | ‘_’
DigitChar := ‘0’-‘9’
NameChar := DigitChar | LeadNameChar
RootChar := ‘\’
ParentPrefixChar := ‘^’
‘A’-‘Z’ := 0x41 - 0x5A
‘_’ := 0x5F0’-‘9’ := 0x30 - 0x39
‘\’ := 0x5C
‘^’ := 0x5E
NameSeg := <LeadNameChar NameChar NameChar NameChar>       // Notice that NameSegs shorter than 4 characters are filled with trailing underscores (‘_’s).
NameString := <RootChar NamePath> | <PrefixPath NamePath>
PrefixPath := Nothing | <‘^’ PrefixPath>
NamePath := NameSeg | DualNamePath | MultiNamePath | NullName
DualNamePath := DualNamePrefix NameSeg NameSeg
DualNamePrefix := 0x2E
MultiNamePath := MultiNamePrefix SegCount NameSeg(SegCount)
MultiNamePrefix := 0x2F
SegCount := ByteData

注意:SegCount可以从1到255。比如说。MultiNamePrefix(35)被编码为Ox2f 0x23和后面是35个NameSegs。所以,总的编码长度将是1+1+35*4=142。请注意DualNamePrefix NameSeg NameSeg的编码比以下编码要小。MultiNamePrefix(2) NameSeg NameSeg。

SimpleName := NameString | ArgObj | LocalObj
SuperName := SimpleName | DebugObj | Type6Opcode
NullName := 0x00
Target := SuperName | NullName

四、数据对象编码

数据对象编码的示例看下面的片段:

ComputationalData := ByteConst | WordConst | DWordConst | QWordConst | String |
ConstObj | RevisionOp | DefBuffer
DataObject := ComputationalData | DefPackage | DefVarPackage
DataRefObject := DataObject | ObjectReference | DDBHandle
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
ExtOpPrefix := 0x5B

五、完结

本章未完,待续。