X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=debug%2Flibb43.py;h=c8b953372a18ba2bedb2f76fbd22e2181b486f9d;hb=1907804cab2799ae52ee09adffb64ec37fef7372;hp=e5c563823a5f67aea30587a22e0eabab063358fb;hpb=29d379ca5d8011793052099783fd4bd70b4a368f;p=b43-tools.git diff --git a/debug/libb43.py b/debug/libb43.py index e5c5638..c8b9533 100644 --- a/debug/libb43.py +++ b/debug/libb43.py @@ -1,7 +1,7 @@ """ # b43 debugging library # -# Copyright (C) 2008 Michael Buesch +# Copyright (C) 2008-2010 Michael Buesch # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 @@ -19,7 +19,7 @@ import sys import os import re -import md5 +import hashlib from tempfile import * @@ -62,7 +62,7 @@ class B43PsmDebug: class B43: """Hardware access layer. This accesses the hardware through the debugfs interface.""" - def __init__(self, phy): + def __init__(self, phy=None): debugfs_path = self.__debugfs_find() # Construct the debugfs b43 path to the device @@ -343,7 +343,7 @@ class TextPatcher: self.deleted = False def __init__(self, text, expected_md5sum): - sum = md5.md5(text).hexdigest() + sum = hashlib.md5(text).hexdigest() if sum != expected_md5sum: print "Patcher: The text does not match the expected MD5 sum" print "Expected: " + expected_md5sum @@ -533,17 +533,26 @@ class B43AsmLine: def getLine(self): return self.text + def __repr__(self): + return self.getLine() + def isInstruction(self): return False class B43AsmInstruction(B43AsmLine): def __init__(self, opcode): - self.opcode = opcode - self.operands = [] + self.setOpcode(opcode) + self.clearOperands() def getOpcode(self): return self.opcode + def setOpcode(self, opcode): + self.opcode = opcode + + def clearOperands(self): + self.operands = [] + def addOperand(self, operand): self.operands.append(operand) @@ -622,13 +631,15 @@ class B43Beautifier(B43AsmParser): def __init__(self, asm_code, headers_dir): """asm_code is the assembly code. headers_dir is a full path to the directory containing the symbolic SPR,SHM,etc... definitions""" + if headers_dir.endswith("/"): + headers_dir = headers_dir[:-1] B43AsmParser.__init__(self, asm_code) self.symSpr = B43SymbolicSpr(headers_dir + "/spr.inc") self.symShm = B43SymbolicShm(headers_dir + "/shm.inc") self.symCond = B43SymbolicCondition(headers_dir + "/cond.inc") - self.preamble = "#include <%s/spr.inc>\n" % headers_dir - self.preamble += "#include <%s/shm.inc>\n" % headers_dir - self.preamble += "#include <%s/cond.inc>\n" % headers_dir + self.preamble = "#include \"%s/spr.inc\"\n" % headers_dir + self.preamble += "#include \"%s/shm.inc\"\n" % headers_dir + self.preamble += "#include \"%s/cond.inc\"\n" % headers_dir self.preamble += "\n" self.__process_code() @@ -641,15 +652,38 @@ class B43Beautifier(B43AsmParser): continue opcode = line.getOpcode() operands = line.getOperands() + # Transform unconditional jump + if opcode == "jext" and int(operands[0], 16) == 0x7F: + label = operands[1] + line.setOpcode("jmp") + line.clearOperands() + line.addOperand(label) + continue + # Transform external conditions if opcode == "jext" or opcode == "jnext": operands[0] = self.symCond.get(int(operands[0], 16)) continue + # Transform orx 7,8,imm,imm,target to mov + if opcode == "orx" and \ + int(operands[0], 16) == 7 and int(operands[1], 16) == 8 and\ + operands[2].startswith("0x") and operands[3].startswith("0x"): + value = int(operands[3], 16) & 0xFF + value |= (int(operands[2], 16) & 0xFF) << 8 + target = operands[4] + line.setOpcode("mov") + line.clearOperands() + line.addOperand("0x%X" % value) + line.addOperand(target) + opcode = line.getOpcode() + operands = line.getOperands() for i in range(0, len(operands)): o = operands[i] + # Transform SPR operands m = spr_re.match(o) if m: operands[i] = self.symSpr.get(o) continue + # Transform SHM operands m = shm_re.match(o) if m: offset = int(m.group(1), 16) @@ -658,7 +692,7 @@ class B43Beautifier(B43AsmParser): def getAsm(self): """Returns the beautified asm code.""" - ret = self.preamble + ret = [ self.preamble ] for line in self.codelines: - ret += line.getLine() + "\n" - return ret + ret.append(str(line)) + return "\n".join(ret)