没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论












ACPI Source Language (ASL) Tutorial
version 20190625
License
License: This work is licensed under a Creative Commons Attribution 4.0 International
License. Code samples contained in this work are licensed under BSD-3-Clause.
© Intel Corporation
0 Prerequisites
This tutorial assumes that the reader is familiar with ACPI concepts illustrated in the Introduction
to ACPI paper. If not, the reader is highly encouraged to read the paper available here:
https://acpica.org/sites/acpica/files/ACPI-Introduction.pdf.
1 Overview
1.1 Operating Systems and ACPI
One role of an operating system (OS) is to configure and manage the system’s hardware resources.
These resources could include timers, removable devices, and so on. In order to do so, the OS must
be able to correctly find and configure devices and system components.
Some components have a hardware infrastructure so that operating systems can easily enumerate
and configure certain devices. Other devices cannot be enumerated natively, and their configuration
may be dependent on the platform or motherboard. Devices that cannot be enumerated natively can
encode their platform-specific information in the Advanced Configuration and Power Interface
(ACPI) firmware so they can be enumerated by the OS. ACPI firmware helps the OS by providing
information about devices that cannot be enumerated natively.
1.2 ACPI Overview
Generally, ACPI development starts with datasheets that describe hardware components.
Firmware developers translate relevant portions of the hardware specification to a file containing
code written in ACPI source language (ASL). This ASL file is compiled to ACPI machine language
(AML) bytecode. AML is packaged along with other firmware code and stored in the platform’s
non-volatile read-only memory.
This tutorial introduces ASL, a programming language with syntax similar to C and also touches
on the basics of other components defined by the ACPI specification.
Once the operating system boots, the AML interpreter starts building the ACPI namespace from
AML tables (DSDT and SSDT) contained inside of the firmware package. The ACPI namespace is
a tree-like data structure that maps variable names to internal objects. When the OS queries the AML
interpreter, the interpreter searches the namespace for the requested variable, evaluates the object
associated with the variable, and returns the result of the computation. This is similar to the act of
loading a program file in an interpreter, like Python, and interactively invoking functions from the

program file. Another similar example is loading SQL files in a database management system and
submitting queries to the database from an interactive SQL prompt.
The ACPI namespace is owned by the AML interpreter that resides in kernel space. The
interpreter acts as a mediator between the ACPI namespace and other OS kernel components.
Operating systems are not allowed to directly alter the ACPI namespace. The primary operations
that the OS performs with the AML interpreter are to load firmware tables and to query the
interpreter to evaluate objects within the namespace.
The internal objects associated with the ACPI variable names represent data, device hierarchies,
and subroutines that are used for configuration and power management. These objects are evaluated
according to the ACPI specification, which may result in change to hardware registers owned by the
AML interpreter or the ACPI namespace.
1.2.1 Example
ASL files typically have content that looks like this:
DefinitionBlock ("", "DSDT", 2, "", "", 0x0)
{
Scope (\_SB)
{
Device (PCI0)
{
Name (INT1, 0x1234)
Name (_HID, EisaId ("PNP0A08") /* PCI Express Bus */)
Name (_CID, EisaId ("PNP0A03") /* PCI Bus */)
Method (^BN00, 0, NotSerialized)
{
Return (0x12 + INT1)
}
Method (_BBN, 0, NotSerialized)
{
Return (BN00 ())
}
Name (_UID, 0x00) // _UID: Unique ID
OperationRegion (MCHT, SystemMemory, 0xFED10000, 0x6000)
Field (MCHT, ByteAcc, NoLock, Preserve)
{
Offset (0x5994),
RPSL, 8,
Offset (0x5998),

RP0C, 8,
RP1C, 8,
RPNC, 8
}
}
}
}
Once a file containing ASL similar to this example is compiled, the file is packaged as firmware.
During the initialization of the OS, a namespace hierarchy is created and helps the OS find devices
and initialize drivers for them. The following diagram illustrates this concept.

2 ASL declarations
There are two kinds of operators in ASL: operators that create variables and data to populate the
ACPI namespace and operators that perform actions on data. This section provides an introduction
to the operators that create variables and data to populate the ACPI namespace.
2.1 ASL foundation: the DefinitionBlock
ASL’s syntax is similar to C, but there are notable semantic differences, like data types and scoping
rules. The fundamental language construct of ASL is the DefinitionBlock. All ASL code must reside
inside of DefinitionBlock declarations. ASL code found outside of any DefinitionBlock will be
regarded as invalid. Each DefinitionBlock is also called a "table".
The syntax to declare a DefinitionBlock is as follows:
DefinitionBlock (AMLFileName, TableSignature, ComplianceRevision,
OEMID, TableID, OEMRevision)
{
TermList // A list of ASL terms
}
The DefinitionBlock syntax definitions are:
• AMLFileName —Name of the AML file (string). Can be a null string.
• TableSignature —Signature of the AML file (could be DSDT or SSDT) (4-character
string)
• ComplianceRevision —A value of 2 or greater enables 64-bit arithmetic; a value of 1
or less enables 32-bit arithmetic (8 bit unsigned integer)
• OEMID —ID of the original equipment manufacturer (OEM) developing the ACPI table
(6-character string)
• TableID —A specific identifier for the table (8-character string)
• OEMRevision —Revision number set by the OEM (32-bit number)
A DefinitionBlock contains a list of ASL terms. In general, this list is comprised of ASL
code that adds variable names to the ACPI namespace. The AMLFileName, OEMID, TableID, and
OEMRevision parameters will not be explained in this tutorial. Consult the ACPI specification for
more information on these parameters. For simplicity, this tutorial this will use the following format
for DefinitionBlocks:
DefinitionBlock ("", DSDT, 2, "", "", 0x0)
{
// A list of ASL terms
}
2.2 Populating the ACPI Namespace with named objects
Previously, the ACPI namespace has been described as a mapping from variable names to internal
objects. However, in the ACPI specification those "variable names" are also referred to as "object
names," and the variables called by those object names can be referred to as "named objects". For
consistency with the ACPI specification, we will use that terminology in this tutorial from this point
onward.
The simplest way to add a named object to the namespace is by using the ASL Name keyword,
for example:
DefinitionBlock ("", DSDT, 2, "", "", 0x0)
{

Name(OBJ0, 0x1234)
Name(OBJ1, "Hello world")
}
This DefinitionBlock adds named objects called OBJ0 and OBJ1 to the ACPI namespace.
In the namespace, OBJ0 is bound to an object with a value of 0x1234 and OBJ1 is bound to a
string object with a value of "Hello world".
The Name keyword is defined in the ACPI specification as the following:
Name (ObjectName, Object)
The Name keyword creates a new object named ObjectName and attaches Object to ObjectName
in the global ACPI namespace.
ObjectName is a four-letter variable name (also called NameSeg) that starts with an alphabetical
letter or _ (underscore) and contains up to three or more additional letters, numbers, or underscores.
Lowercase letters are converted to uppercase during compilation. Although NameSegs shorter than
four characters are padded with additional underscores, this tutorial will use NameSegs that are four
characters. Only four characters are allowed in a NameSeg because four bytes fit nicely into a
DWORD. The following examples are valid named object declarations:
Name (lowr, 0x0) Name (UPPR, 0x0) Name (MiXd, 0x0)
Name (___A, 0x0) Name (X, 0x0) Name (ABC,0x0)
These next named object declarations are invalid:
Name (!@#~, 0x0) Name (TOOLONG, 0x0) Name (,0x0)
Named objects are bound to the types and values of objects in the ACPI namespace through the
use of specific keywords. Adding named objects to the ACPI namespace allows the OS to query the
AML interpreter to fetch the value of the given named object.
2.2.1 Introduction to iASL
The Intel ASL compiler (iASL) is used to translate ASL to AML bytecode. This short section
introduces how to use iASL tools. You can find information on how to build and install the ACPICA
tools in the appendix.
First, create a file called dsdt.asl in a text editor, and then enter the following:
剩余26页未读,继续阅读
资源评论

ensky.
- 粉丝: 29
- 资源: 47

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
