From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" , "Kevin O'Connor" Subject: Re: [PATCH 2/4] acpi: add aml/asl parsing script Date: Wed, 21 Sep 2011 21:10:46 +0300 Message-ID: <20110921181045.GA24243@redhat.com> References: <408bb38ea26e509cbabc83df910e8fc804b2b7ec.1316608551.git.mst@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, jasowang@redhat.com, seabios@seabios.org, alex williamson , Amos Kong To: "Michael S. Tsirkin" Return-path: Content-Disposition: inline In-Reply-To: <408bb38ea26e509cbabc83df910e8fc804b2b7ec.1316608551.git.mst@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: seabios-bounces@seabios.org Sender: seabios-bounces@seabios.org List-Id: kvm.vger.kernel.org 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
) + 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