本文将介绍ACPI中的ASL、AML以及两者的关系。本文部分内容源于:ACPI Table基本知识

1.overview


ASL is ACPI source language. It is a more human-readable form of the byte code that is AML. This difference is similar to that between assembly code and the actual binary machine code.

ASL类似于汇编语言,AML类似与机器语言。

  1. 将编写好的ASL编译为AML;
  2. 将生成的AML刷新到BIOS的ROM中;
  3. firmware 将ROM中的AML加载入内存;
  4. OS利用AML interpreter去解析AML,然后去执行他们。

2. demo

下图截自windows 设备管理器,他显示了系统下有哪些device。

如果你想把RTC设备隐藏起来,那么,你的做法将是:

  1. 在ASL code中找到RTC;
  2. 修改ASL code以隐藏RTC;
  3. 编译ASL code,将生成的AML刷新到BIOS的ROM中。

最终,在windows 设备管理器,你将看不到RTC设备。

3.OS如何寻找ACPI table

如上所述,ACPI Table最终会以AML的形式存放在BIOS ROM中,那么,OS如何找到这些ACPI table呢?

The first step in retrieving the ACPI tables is finding the Root System Description Pointer, or RSDP.

BIOS在开机过程中会把包在BIOS ROM中的ACPI Table 载入到RAM中,然后留下一些信息给OS来找到他们。最简单的例子就是RSDP Structure会放在1M以下的某个位置(一般是E0000h~FFFFh),然后OS就可以通过搜寻signature(某个标记字)的方式来找到其他的ACPI Table entry point。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*******************************************************************************
*
* FUNCTION: Acpi_tb_scan_memory_for_rsdp
*
* PARAMETERS: Start_address - Starting pointer for search
* Length - Maximum length to search
*
* RETURN: Pointer to the RSDP if found, otherwise NULL.
*
* DESCRIPTION: Search a block of memory for the RSDP signature
*
******************************************************************************/

u8 *
acpi_tb_scan_memory_for_rsdp (u8 *start_address, u32 length)
{
u32 offset;
u8 *mem_rover;

/* Search from given start addr for the requested length */
for (offset = 0, mem_rover = start_address;
offset < length;
offset += RSDP_SCAN_STEP, mem_rover += RSDP_SCAN_STEP)
{
/* The signature and checksum must both be correct */
if (STRNCMP ((NATIVE_CHAR *) mem_rover,
RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 &&
acpi_tb_checksum (mem_rover, RSDP_CHECKSUM_LENGTH) == 0)
{
/* If so, we have found the RSDP */
return (mem_rover);
}
}
/* Searched entire block, no RSDP was found */
return (NULL);
}


参考资料:

  1. ACPI Table基本知识
  2. How does the Linux kernel retrieve ACPI tables from the system firmware?
  3. Upgrading ACPI tables via initrd
  4. AML
  5. asl tutorial