Subversion Repositories HelenOS-historic

Rev

Rev 270 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
268 palkovsky 1
#!/usr/bin/env python
2
 
3
import sys
4
import struct
5
import re
6
 
7
symline = re.compile(r'(0x[a-f0-9]+)\s+([^\s]+)$')
8
symtabfmt = "<Q32s"
9
MAXSTRING=31
10
 
11
def read_symbols(inp):
12
    while 1:
13
        line = inp.readline()
14
        if not line:
15
            return
16
        if 'memory map' in line:
17
            break        
18
 
19
    symtable = {}
20
    while 1:
21
        line = inp.readline()
22
        if not line.strip():
23
            continue
24
        if line[0] not in (' ','.'):
25
            break
26
        line = line.strip()
27
        # Search only for symbols
28
        res = symline.match(line)
29
        if res:
30
            symtable[int(res.group(1),16)] = res.group(2)
31
    return symtable
32
 
33
def generate(inp, out):
34
    symtab = read_symbols(inp)
35
    if not symtab:
36
        print "Bad kernel.map format, empty."
37
        sys.exit(1)
38
    addrs = symtab.keys()
39
    addrs.sort()
40
    for addr in addrs:
41
        # Do not write address 0, it indicates end of data
42
        if addr == 0:
43
            continue
44
        data = struct.pack(symtabfmt,addr,symtab[addr][:MAXSTRING])
45
        out.write(data)
46
    out.write(struct.pack(symtabfmt,0,''))
47
 
48
def main():
49
    if len(sys.argv) != 3:
50
        print "Usage: %s <kernel.map> <output.bin>" % sys.argv[0]
51
        sys.exit(1)
52
 
53
    inp = open(sys.argv[1],'r')
54
    out = open(sys.argv[2],'w')
55
    generate(inp,out)
56
    inp.close()
57
    out.close()
58
 
59
if __name__ == '__main__':
60
    main()