~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/seabios/scripts/transdump.py

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# This script is useful for taking the output of memdump() and
 
4
# converting it back into binary output.  This can be useful, for
 
5
# example, when one wants to push that data into other tools like
 
6
# objdump or hexdump.
 
7
#
 
8
# (C) Copyright 2010 Kevin O'Connor <kevin@koconnor.net>
 
9
#
 
10
# This file may be distributed under the terms of the GNU GPLv3 license.
 
11
 
 
12
import sys
 
13
import struct
 
14
 
 
15
def unhex(str):
 
16
    return int(str, 16)
 
17
 
 
18
def parseMem(filehdl):
 
19
    mem = []
 
20
    for line in filehdl:
 
21
        parts = line.split(':')
 
22
        if len(parts) < 2:
 
23
            continue
 
24
        try:
 
25
            vaddr = unhex(parts[0])
 
26
            parts = parts[1].split()
 
27
            mem.extend([unhex(v) for v in parts])
 
28
        except ValueError:
 
29
            continue
 
30
    return mem
 
31
 
 
32
def printUsage():
 
33
    sys.stderr.write("Usage:\n %s <file | ->\n"
 
34
                     % (sys.argv[0],))
 
35
    sys.exit(1)
 
36
 
 
37
def main():
 
38
    if len(sys.argv) != 2:
 
39
        printUsage()
 
40
    filename = sys.argv[1]
 
41
    if filename == '-':
 
42
        filehdl = sys.stdin
 
43
    else:
 
44
        filehdl = open(filename, 'r')
 
45
    mem = parseMem(filehdl)
 
46
    for i in mem:
 
47
        if (sys.version_info > (3, 0)):
 
48
            sys.stdout.buffer.write(struct.pack("<I", i))
 
49
        else:
 
50
            sys.stdout.write(struct.pack("<I", i))
 
51
 
 
52
if __name__ == '__main__':
 
53
    main()