From: "Michael S. Tsirkin" <mst@redhat.com>, "Kevin O'Connor" <kevin@koconnor.net>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org, jasowang@redhat.com, seabios@seabios.org,
alex williamson <alex.williamson@redhat.com>,
Amos Kong <akong@redhat.com>
Subject: Re: [PATCH 2/4] acpi: add aml/asl parsing script
Date: Wed, 21 Sep 2011 21:10:46 +0300 [thread overview]
Message-ID: <20110921181045.GA24243@redhat.com> (raw)
In-Reply-To: <408bb38ea26e509cbabc83df910e8fc804b2b7ec.1316608551.git.mst@redhat.com>
I've rewritten the script in python. Seems to work but
I didn't have time to test - only compiled for now -
and needs to move to tools - but I hope this makes
review easier.
Thanks,
---
src/find_ej0.py | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 140 insertions(+), 0 deletions(-)
create mode 100755 src/find_ej0.py
diff --git a/src/find_ej0.py b/src/find_ej0.py
new file mode 100755
index 0000000..75e5491
--- /dev/null
+++ b/src/find_ej0.py
@@ -0,0 +1,140 @@
+#!/usr/bin/python
+
+# Process mixed ASL/AML listing (.lst file) produced by iasl -l
+# Locate all occurences of Name _ADR followed by Method EJ0_
+# Output slot info from _ADR and offset of method name in AML
+
+import re;
+import sys;
+import fileinput;
+
+aml = []
+asl = []
+output = []
+lineno = 0
+debug = ""
+
+class asl_line:
+ line = None
+ lineno = None
+ aml_offset = None
+
+def die(diag):
+ sys.stderr.write("Error: %s; %s\n" % (diag, debug))
+ sys.exit(1)
+
+#Store an ASL command, matching AML offset, and input line (for debugging)
+def add_asl(line):
+ l = asl_line()
+ l.line = line
+ l.lineno = lineno
+ l.aml_offset = len(aml)
+ asl.append(l)
+
+#Store an AML byte sequence
+#Verify that offset output by iasl matches # of bytes so far
+def add_aml(offset, line):
+ o = int(offset, 16);
+ # Sanity check: offset must match size of code so far
+ if (o != len(aml)):
+ die("Offset 0x%x != 0x%x" % (o, len(aml)))
+ # Strip any trailing dots and ASCII dump after "
+ line = re.sub(r'\s*\.*\s*".*$',"", line)
+ # Strip traling whitespace
+ line = re.sub(r'\s+$',"", line)
+ # Strip leading whitespace
+ line = re.sub(r'^\s+',"", line)
+ # Split on whitespace
+ code = re.split(r'\s+', line)
+ for c in code:
+ # Require a legal hex number, two digits
+ if (not(re.search(r'^[0-9A-Fa-f][0-9A-Fa-f]$', c))):
+ die("Unexpected octet %s" % c);
+ aml.append(int(c, 16));
+
+# Process aml bytecode array, decoding AML
+# Given method offset, find its name offset
+def aml_method_name(lineno, offset):
+ #0x14 MethodOp PkgLength NameString MethodFlags TermList
+ if (aml[offset] != 0x14):
+ die( "Method after input line $lineno offset $offset: "
+ " expected 0x14 actual 0x%x" % aml[offset]);
+ offset += 1;
+ # PkgLength can be multibyte. Bits 8-7 give the # of extra bytes.
+ pkglenbytes = aml[offset] >> 6;
+ offset += 1 + pkglenbytes;
+ return offset;
+
+for line in fileinput.input():
+ # Strip trailing newline
+ line.rstrip();
+ # line number and debug string to output in case of errors
+ lineno = lineno + 1
+ debug = "input line %d: %s" % (lineno, line)
+ #ASL listing: space, then line#, then ...., then code
+ pasl = re.compile('^\s+([0-9]+)\.\.\.\.\s*')
+ m = pasl.search(line)
+ if (m):
+ add_asl(pasl.sub("", line));
+ # AML listing: offset in hex, then ...., then code
+ paml = re.compile('^([0-9A-Fa-f]+)\.\.\.\.\s*')
+ m = paml.search(line)
+ if (m):
+ add_aml(m.group(1), paml.sub("", line))
+
+# Now go over code, look for EJ0_ methods
+# For each such method, output slot mask from the
+# preceding _ADR line, as well as the method name offset.
+
+for i in range(len(asl)):
+ l = asl[i].line
+ debug = "input line %d: %s" % (asl[i].lineno, asl[i].line)
+ # match: Method (EJ0_,1)
+ if (not(re.search(r'^Method\s*\(\s*EJ0_\s*[,)]', l))):
+ # Make sure we do not miss any EJ0_:
+ # die if EJ0_ is found anywhere else in source code
+ if (re.search(r'EJ0_', l)):
+ die("Stray EJ0_ detected");
+ continue
+ # EJ0_ found. Previous line must be _ADR
+ p = asl[i - 1].line
+ # match: Name (_ADR, 0x<address>)
+ padr = re.compile('Name\s*\(\s*_ADR\s*,\s*0x([0-9A-Fa-f]+)\s*\)')
+ m = padr.search(p);
+ if (not m):
+ die("_ADR not found before EJ0_ ")
+
+ adr = int(m.group(1), 16)
+ slot = adr >> 16;
+ if (slot > 31):
+ die("_ADR device out of range: actual %d expected 0 to 31" % slot)
+
+ # We have offset of EJ0_ method in code
+ # Now find EJ0_ itself
+ ej0 = aml_method_name(asl[i].lineno, asl[i].aml_offset)
+ # Verify AML: name must be EJ0_:
+ if ((aml[ej0 + 0] != ord('E')) or
+ (aml[ej0 + 1] != ord('J')) or
+ (aml[ej0 + 2] != ord('0')) or
+ (aml[ej0 + 3] != ord('_'))):
+ die("AML offset 0x%x does not match EJ0_" % ej0)
+
+ # OK we are done. Output slot mask and offset
+ output.append(" {.slot_mask = 0x%x, .offset = 0x%x}" %
+ (0x1 << slot, ej0))
+
+debug = "at end of file"
+
+# Pretty print output
+if (not len(output)):
+ die("No EJ0_ Method found!")
+
+print '''
+static struct aml_ej0_data {
+ unsigned slot_mask;
+ unsigned offset;
+} aml_ej0_data[] = {'''
+
+print ",\n".join(output)
+print '};\n'
+
--
1.7.5.53.gc233e
next prev parent reply other threads:[~2011-09-21 18:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 12:44 [PATCH 0/4] acpi: fix up EJ0 in DSDT Michael S. Tsirkin
2011-09-21 12:44 ` [PATCH 1/4] acpi: generate mixed asl/aml listing Michael S. Tsirkin
2011-09-21 12:47 ` Michael S. Tsirkin
2011-09-21 12:44 ` [PATCH 2/4] acpi: add aml/asl parsing script Michael S. Tsirkin
2011-09-21 14:27 ` Gleb Natapov
2011-09-21 15:46 ` Michael S. Tsirkin
2011-09-21 18:10 ` Michael S. Tsirkin, Kevin O'Connor [this message]
2011-09-21 12:44 ` [PATCH 3/4] acpi: EJ0 method name patching Michael S. Tsirkin
2011-09-21 12:44 ` [PATCH 4/4] acpi: remove _RMV Michael S. Tsirkin
2011-09-22 4:35 ` [PATCH 0/4] acpi: fix up EJ0 in DSDT Kevin O'Connor
2011-09-22 6:09 ` Michael S. Tsirkin
2011-09-22 12:39 ` Kevin O'Connor
2011-09-26 4:40 ` Kevin O'Connor
2011-09-26 7:03 ` [SeaBIOS] " Rudolf Marek
2011-09-26 7:04 ` Michael S. Tsirkin
2011-09-26 11:36 ` Marcelo Tosatti
2011-09-26 13:13 ` Michael S. Tsirkin
2011-09-27 0:04 ` Kevin O'Connor
2011-09-27 13:04 ` Michael S. Tsirkin
2011-09-27 15:23 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110921181045.GA24243@redhat.com \
--to=mst@redhat.com \
--cc=akong@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=jasowang@redhat.com \
--cc=kevin@koconnor.net \
--cc=kvm@vger.kernel.org \
--cc=seabios@seabios.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.