[SeaBIOS] [PATCH RFC] acpi: extract aml from .lst

Michael S. Tsirkin mst at redhat.com
Wed Oct 26 23:28:02 CEST 2011


Add ACPI_EXTRACT_ALL_CODE directive, to support extracting
AML code from listing into a named array. Use that instead including C
file generated by iasl, this makes it possible to include multiple AML
tables without resorting to preprocessor tricks.

Signed-off-by: Michael S. Tsirkin <mst at redhat.com>

---

Kevin, you suggested something like the below, I think?  Seems to work
but RFC since I didn't have time to test this properly.

diff --git a/Makefile b/Makefile
index 91d9b77..200a07a 100644
--- a/Makefile
+++ b/Makefile
@@ -198,7 +198,7 @@ src/%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py
 	$(Q)./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
 	$(Q)iasl -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
 	$(Q)./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
-	$(Q)cat $(OUT)$*.hex $(OUT)$*.off > $@
+	$(Q)cat $(OUT)$*.off > $@
 
 $(OUT)ccode32flat.o: src/acpi-dsdt.hex src/ssdt-proc.hex
 
diff --git a/src/acpi-dsdt.dsl b/src/acpi-dsdt.dsl
index a5f0a4d..b9b06f2 100644
--- a/src/acpi-dsdt.dsl
+++ b/src/acpi-dsdt.dsl
@@ -16,6 +16,9 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+ACPI_EXTRACT_ALL_CODE AmlCode
+
 DefinitionBlock (
     "acpi-dsdt.aml",    // Output Filename
     "DSDT",             // Signature
diff --git a/src/acpi.c b/src/acpi.c
index 27a939e..f743bdd 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -366,9 +366,7 @@ encodeLen(u8 *ssdt_ptr, int length, int bytes)
     return ssdt_ptr + bytes;
 }
 
-#define AmlCode static ssdp_proc_aml
 #include "ssdt-proc.hex"
-#undef AmlCode
 
 /* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
 #define SD_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
diff --git a/src/ssdt-proc.dsl b/src/ssdt-proc.dsl
index a461636..0339422 100644
--- a/src/ssdt-proc.dsl
+++ b/src/ssdt-proc.dsl
@@ -14,6 +14,9 @@
  * and a CPON array with the list of active and inactive cpus:
  *     Name(CPON, Package() { One, One, ..., Zero, Zero, ... })
  */
+
+ACPI_EXTRACT_ALL_CODE ssdp_proc_aml
+
 DefinitionBlock ("ssdt-proc.aml", "SSDT", 0x01, "BXPC", "BXSSDT", 0x1)
 {
     ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
diff --git a/tools/acpi_extract.py b/tools/acpi_extract.py
index 9083cff..5f613e4 100755
--- a/tools/acpi_extract.py
+++ b/tools/acpi_extract.py
@@ -29,6 +29,8 @@
 # ACPI_EXTRACT_PROCESSOR_START - start of Processor() block
 # ACPI_EXTRACT_PROCESSOR_STRING - extract a NameString from Processor()
 # ACPI_EXTRACT_PROCESSOR_END - offset at last byte of Processor() + 1
+#
+# ACPI_EXTRACT_ALL_CODE - create an array storing the generated AML bytecode
 # 
 # ACPI_EXTRACT is not allowed anywhere else in code, except in comments.
 
@@ -240,6 +242,11 @@ for i in range(len(asl)):
     array = mext.group(2)
     offset = asl[i].aml_offset
 
+    if (directive == "ACPI_EXTRACT_ALL_CODE"):
+        if array in output:
+            die("%s directive used more than once" % directive)
+        output[array] = aml
+        continue
     if (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
@@ -261,21 +268,25 @@ for i in range(len(asl)):
 
     if array not in output:
         output[array] = []
-    output[array].append("0x%x" % offset)
+    output[array].append(offset)
 
 debug = "at end of file"
 
-#Use type large enough to fit the table
-if (len(aml) >= 0x10000):
-	offsettype = "int"
-elif (len(aml) >= 0x100):
-	offsettype = "short"
-else:
-	offsettype = "char"
+def get_value_type(maxvalue):
+    #Use type large enough to fit the table
+    if (maxvalue >= 0x10000):
+            return "int"
+    elif (maxvalue >= 0x100):
+            return "short"
+    else:
+            return "char"
 
 # Pretty print output
 for array in output.keys():
-    
-    sys.stdout.write("static unsigned %s %s[] = {\n" % (offsettype, array))
-    sys.stdout.write(",\n".join(output[array]))
+    otype = get_value_type(max(output[array]))
+    odata = []
+    for value in output[array]:
+        odata.append("0x%x" % value)
+    sys.stdout.write("static unsigned %s %s[] = {\n" % (otype, array))
+    sys.stdout.write(",\n".join(odata))
     sys.stdout.write('\n};\n');



More information about the SeaBIOS mailing list