Manually write the DSDT series tutorials, and manually write the dsdt tutorials

Source: Internet
Author: User
Tags integer division

Manually write the DSDT series tutorials, and manually write the dsdt tutorials

Specification document. Therefore, there will inevitably be many incorrect understandings and incorrect ideas, and we hope you will understand and correct them.
First, you have to talk about DSDT (Differentiated System Description Table ). What is DSDT? In fact, ACPI is a table of ACPI, and ACPI is short for Advanced Configuration & Power Interface. It can be understood from the text that ACPI is a series of interfaces, this interface contains many tables, so DSDT is a table and some interfaces. Therefore, it is hard to imagine that the main function of ACPI is to provide some services of the operating system and provide some information for the operating system. DSDT is no exception. One feature of ACPI is to write the ACPI tables in a proprietary language. It is ASL (ACPI Source Language), which is the main character of this Article. After being compiled by the compiler, ASL becomes AML (ACPI Machine Language) and then executed by the operating system. Since ASL is a language, it has its principles.
ASL principles:
1. The variable name cannot exceed 4 characters and cannot start with a number. Think of the DSDT code you have seen. It will never exceed.
2. Scope forms a Scope. The concept is similar to the set {} in mathematics {}. There is only one root scope, so DSDT uses

DefinitionBlock ("xxxx", "DSDT", 0x02, "xxxx", "xxxx", xxxx)
{


Start

}

End. This is the root scope. The xxxx parameter indicates the output file name, OEMID, table ID, and OEM version in sequence. The third parameter is specified according to the second parameter, as shown above. If it is "DSDT", it must be 0x02, and other parameters can be freely modified.
3. Functions and variables starting with "_" are retained by the system. This is why _ T_X appears in the ASL after some AML decompilers, and a warning will appear during re-compilation.
4. Method-defined functions. functions can be defined under Device or Scope, but they cannot be separated from Scope-defined independent functions. This is not the case.

Method (xxxx, 0, NotSerialized)
{
......
}
DefinitionBlock ("xxxx", "DSDT", 0x02, "xxxx", "xxxx", xxxx)
{
......
}

5. The root scope has five scopes: \ _ GPE, \ _ PR, \ _ SB, \ _ SI, and \ _ TZ. \ _ GPE is the ACPI event processing, \ _ PR processor, \ _ SB all devices and bus. \ _ SI System indicator. _ Tz heat zone, used to read certain temperatures. Different attributes are stored in the corresponding scope. For example:
The Device (PCI0) is placed in Scope (\ _ SB ).

Scope (\ _ SB)
{
Device (PCI0)
{
....
}
....
}

CPU-related information is stored in Scope (_ PR)

Scope (_ PR)
{
Processor (CPU0, 0x00, 0x00000410, 0x06)
{
....
}
....
}

Scope (_ GPE) stores related event processing

Scope (_ GPE)
{
Method (_ L0D, 0, NotSerialized)
{
....
}
....
}

At first glance, isn't it a function? Of course, functions can also be placed here. Note that the function name starts with "_" and is a function reserved by the system.
6. Device (xxxx) can also be viewed as a scope.
7. the symbol "\" references the root scope, and "^" references the upper-level scope.
8. There is no operator in ASL, and +-*/= will not appear, but there are equivalent functions.
9. A function can transmit a maximum of eight parameters. In a function, Arg0 ~ Arg7 indicates that it cannot be customized.
10. A function can use a maximum of eight local variables, from Local0 ~ Local7 does not need to be defined, but must be initialized before use, that is, there must be a value assignment operation.

Common Data Types of ASL:
Integer, String, Event, Buffer, and Package)
ASL definition variables:
For example:
Name (TEST, 0) // defines an integer
Name (MSTR, "ASL") // defines a string

Name (_ PRW, Package (0x02)
{
0x0D,
0x03
})

// Define a Package
You can find that you do not need to explicitly declare its type when defining a variable.
ASL Assignment Method:
There is only one Store (a, B) such
Store (0, Local0) // Local0 = 0
Store (Local0, Local1) // Local0 = Local1

ASL operation functions:
As mentioned above, ASL does not have an operator number, but has an operation function.
Add integer addition
And is an integer in
Decrement integer auto-minus 1
Divide Integer Division
Increment integer auto-Increment 1
Mod integer Remainder
Multiply the Multiply Integers
ShiftLeft shifts left
Shift ShiftRight right
Subtract integer subtraction
Or
Not Inverse
Nor or
For more information, see ACPI Specification.
Example:

Add (1, 2, Local0) // Local0 = 1 + 2
And (0x11, 0x22, Local0) // Local0 = 0x11 & 0x22
Divide (10, 9, Local1, Local0) // Local0 = 10/9, Local1 = 10% 9
Mod (10, 9, Local0) // Local0 = 10% 9
Multiply (1, 2, Local0) // Local0 = 1*2
ShiftLeft (1, 20, Local0) // Local0 = 1 <20
ShiftRight (0x10000, 4, Local0) // Local0 = 0x10000> 4
Subtract (2, 1, Local0) // Local0 = 2-1
Or (0x01, 0x02, Local0) // Local0 = 0x01 | 0x02
Not (0x00, Local0) // Local0 = ~ (0x00)
Nor (0x11, 0x22, Local0) // Local0 = ~ (0x11 )&~ (0x22)

ASL logical operations:
LAnd logic and
LEqual logic equals
The LGreater logic is greater
LGreaterEqual logic greater than or equal
LLess Logic
The LLessEqual logic is less than or equal
LNot logic inversion
The LNotEqual logic is not equal
LOr logic or

Store (LAnd (1, 1), Local0) // Local0 = 1 & 1
Store (LEqual (1, 1), Local0) // Local0 = (1 = 1)
Store (LGreater (1, 2), Local0) // Local0 = (1> 2)
Store (LGreaterEqual (1, 2), Local0) // Local0 = (1> = 2)
Store (LLess (1, 2), Local0) // Local0 = (1 <2)
Store (LLessEqual (1, 2), Local0) // Local0 = (1 <= 2)
Store (LNot (0), Local0) // Local0 =! 0
Store (LNotEqual (0, 1), Local0) // Local0 = (0! = 1)
Store (LOR (0, 1), Local0) // Local0 = (0 | 1)

It is not difficult to find that the logical operation has only two results: 0 or 1.
ASL Function Definition:
1. define functions

Method (TEST)
{}

2. Define a function with two input parameters and use the local variable Local0 ~ Local7

Method (MADD, 2)
{
Store (Arg0, Local0)
Store (Arg1, Local1)
Add (Local0, Local1, Local0)
}

The addition operation of two parameters is implemented. Therefore, the input parameters must be implicitly integer.
3. define functions with return values

Method (MADD, 2)
{
Store (Arg0, Local0)
Store (Arg1, Local1)
Add (Local0, Local1, Local0)
Return (Local0)
}

The example is the implementation of custom addition. Function implementation is the same as adding a system function.
Store (MADD (1, 2), Local0) // Local0 = 1 + 2
4. Define serializable Functions

Method (MADD, 2, Serialized)
{
Store (Arg0, Local0)
Store (Arg1, Local1)
Add (Local0, Local1, Local0)
Return (Local0)
}

This is somewhat similar to the concept of multi-threaded synchronization. That is to say, when the function is declared as Serialized, only one instance can exist in the memory. Generally, an object is created in a function. Example:

Method (TEST, Serialized)
{
Name (MSTR, "I will sucess"
}

If you declare the TEST function in this way, you can call this function in two places at the same time.

Device (Dev1)
{
TEST ()
}
Device (Dev2)
{
TEST ()
}

If you run the TEST of Dev1, the TEST in Dev2 will wait until the TEST function in Dev1 is executed. If it is declared

Method (TEST, NotSerialized)
{
Name (MSTR, "I will sucess"
}

When one of the Devx calls TEST, the other call fails when it tries to create the same string MSTR.
ASL process control:
Like common advanced languages, ASL also has corresponding control flow statements.
Break
BreakPoint
Case
Continue
Default
Else
ElseIf
If
Return
Stall
Switch
While
(1) Branch Control: If, ElseIf, Else, Switch, Case
1. If usage
For example, the following statement checks whether the current system interface is Darwin.

If (_ OSI ("Darwin "))
{
Store (0x2710, OSYS)
}

2. ElseIf and Else usage introduction. If the system structure is not Darwin and the system is not Linux, OSYS = 0x07D0

If (_ OSI ("Darwin "))
{
Store (0x2710, OSYS)
}
ElseIf (_ OSI ("Linux "))
{
Store (0x03E8, OSYS)
}
Else
{
Store (0x07D0, OSYS)
}

3. Example of Switch, Case, Defaule, and BreakPoint

Switch (Arg2)
{
Case (1)
{
If (LEqual (1, Arg1)
{
Return (1)
}
BreakPoint
}
Case (2)
{
....
Return (2)
}
Default
{
BreakPoint
}
}

A Switch can be seen as a collection of If... Else. The BreakPoint is equivalent to a BreakPoint, meaning that the current Swtich is exited.
(2) Example of loop control While, Break, Continue, and Stall Suspension

Store (10, Local0)
While (LAnd (0x00, Local0 ))
{
Decrement (Local0)
Stall (32)
}

Local0 is equal to 10. If the logic of Local0 is not true at 0, Local0 minus 1, and 32us is suspended, the Code Delay is 10*32 = 320 us.
Tired, I wrote it here today. With these foundations, I feel that most Forum friends are not in a daze or daze when facing DSDT. At least I can understand some few statements.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.