X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=debug%2Fb43-fwdump;h=6ac7aa0f01c6d8c7140555614a41f0a5e34ddd04;hb=1a43ed005f3ffe10b0ca3d6f2975870c8d505b92;hp=928634abd7c56a1a0163f81adc6a7f09e8b41413;hpb=1542e8b171362b8c85af4d3cac2e30946ee7f3bf;p=b43-tools.git diff --git a/debug/b43-fwdump b/debug/b43-fwdump index 928634a..6ac7aa0 100755 --- a/debug/b43-fwdump +++ b/debug/b43-fwdump @@ -21,6 +21,7 @@ import getopt from libb43 import * from sys import stdout from tempfile import * +import re def usage(): @@ -32,25 +33,32 @@ def usage(): print "Usage: b43-fwdump [OPTIONS]" print "" print "-h|--help Print this help text" - print "-p|--phy PHY The PHY to use. For example phy0" + print "-p|--phy WIPHY The WIPHY to use. For example phy0." + print " Can be omitted, if there is only one device in the system." print "-b|--binary BIN The firmware binary. This is required for" print " an instruction dump." print "-d|--dasmopt OPT Additional options to the disassembler." + print "-s|--shm Also dump SHM." + print "-S|--shmbin Do a binary SHM dump, only." return def parseArgs(): global phy global binary global dasmopt + global dumpShm + global dumpShmBin phy = None # Autodetect binary = None # No instruction dump dasmopt = "" + dumpShm = False + dumpShmBin = False try: (opts, args) = getopt.getopt(sys.argv[1:], - "hp:b:d:", - [ "help", "phy=", "binary=", "dasmopt=" ]) + "hp:b:d:sS", + [ "help", "phy=", "binary=", "dasmopt=", "shm", "shmbin" ]) except getopt.GetoptError: usage() sys.exit(1) @@ -65,6 +73,10 @@ def parseArgs(): binary = v if o in ("-d", "--dasmopt"): dasmopt = v + if o in ("-s", "--shm"): + dumpShm = True + if o in ("-S", "--shmbin"): + dumpShmBin = True return @@ -80,36 +92,38 @@ def dump_regs(prefix, regs): stdout.write("\n") return -def disassembleText(text): - input = NamedTemporaryFile() - output = NamedTemporaryFile() - - input.write(text) - input.flush() - os.system("b43-dasm %s %s %s --paddr" % (input.name, dasmopt, output.name)) - - return output.read() +def dasmLineIsPC(line, pc): + m = re.match(r'.*/\*\s+([0-9a-fA-F]+)\s+\*/.*', line, re.DOTALL) + if not m: + return False + linePC = int(m.group(1), 16) + return pc == linePC def makeShortDump(dasm, pc): dasm = dasm.splitlines() i = 0 for line in dasm: - if "/* %03X */" % pc in line: + if dasmLineIsPC(line, pc): break i += 1 - if i >= len(dasm): + else: return "" ret = "" pos = max(i - 8, 0) end = min(i + 8, len(dasm) - 1) while pos != end: ret += dasm[pos] - if "/* %03X */" % pc in dasm[pos]: + if dasmLineIsPC(dasm[pos], pc): ret += "\t\t<<<<<<<<<<<" ret += "\n" pos += 1 return ret +def toAscii(char): + if char >= 32 and char <= 126: + return chr(char) + return "." + def main(): parseArgs() @@ -120,11 +134,17 @@ def main(): gpr = b43.getGprs() lr = b43.getLinkRegs() off = b43.getOffsetRegs() - shm = b43.shmSharedRead() + if dumpShm or dumpShmBin: + shm = b43.shmSharedRead() dbg = b43.getPsmDebug() psmcond = b43.getPsmConditions() b43.ucodeStart() + if dumpShmBin: + # Only do a binary SHM dump + stdout.write(shm) + sys.exit(0) + print "--- B43 microcode state dump ---" print "PC: %03X PSM-COND: %04X" % (dbg.getPc(), psmcond) print "Link registers:" @@ -141,10 +161,26 @@ def main(): except IOError, e: print "Could not read binary file %s: %s" % (binary, e.strerror) sys.exit(1) - dasm = disassembleText(bintext) + dasm = Disassembler(bintext, dasmopt + "--paddr").getAsm() print makeShortDump(dasm, dbg.getPc()) else: print "" + + if dumpShm: + print "Shared memory:" + ascii = "" + for i in range(0, len(shm)): + if i % 16 == 0 and i != 0: + stdout.write(" " + ascii + "\n") + ascii = "" + if i % 16 == 0: + stdout.write("0x%04X: " % i) + c = ord(shm[i]) + stdout.write("%02X" % c) + if (i % 2 != 0): + stdout.write(" ") + ascii += toAscii(c) + stdout.write(" " + ascii + "\n") return