OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [tools/] [pyelf/] [burn.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
from aistruct import AIStruct
2
import elf, sys
3
from optparse import OptionParser
4
 
5
 
6
class AfterBurner(AIStruct):
7
        def __init__(self, *args, **kwargs):
8
                AIStruct.__init__(self, AIStruct.SIZE32)
9
                self.setup(
10
                        ('UINT32', 'addr')
11
                )
12
 
13
        def __str__(self):
14
            return "0x%x" % self.ai.addr.get()
15
 
16
 
17
def arch_perms(rwx):
18
    # ia32 doesn't support read-noexec
19
    if rwx & (1 << 2):
20
        rwx |= 1
21
    return rwx
22
 
23
def align_up(value, align):
24
    mod = value % align
25
    if mod != 0:
26
        value += (align - mod)
27
    return value
28
 
29
def gen_pheaders(elf):
30
    old_rwx = 0
31
    old_offset = 0
32
    old_addr = 0
33
    old_bits = 0
34
    old_size = 0
35
    new_addr = 0
36
    new_offset = 0
37
    new_size = 0
38
    for section in [section for section in elf.sheaders if section.allocable()]:
39
        # Test - can we add this section to the current program header?
40
        new = 0
41
        rwx = arch_perms(section.get_perms())
42
        addr = section.ai.sh_addr.get()
43
        offset = section.ai.sh_offset.get()
44
        al = section.ai.sh_addralign.get()
45
        size = section.ai.sh_size.get()
46
 
47
        if old_rwx != rwx:
48
            new = 1
49
        if addr != align_up(old_size + old_addr, al):
50
            new = 2
51
        if offset != align_up(old_size + old_offset, al):
52
            new = 3
53
 
54
        if new != 0:
55
            #print hex(new_offset), hex(new_addr), hex(new_size)
56
            new_size = size
57
            new_addr = addr
58
            new_offset = offset
59
        else:
60
            new_size = (addr + size) - new_addr
61
 
62
        old_rwx = rwx
63
        old_size = size
64
        old_bits = 0
65
        old_offset = offset
66
        old_addr = addr
67
        #print section.ai.sh_name, section.ai.sh_addr, section.ai.sh_offset, section.ai.sh_size, section.ai.sh_flags, rwx
68
    print hex(new_offset), hex(new_addr), hex(new_size)
69
 
70
def main():
71
    wedge = elf.ElfFile.from_file(sys.argv[1])
72
    guest = elf.ElfFile.from_file(sys.argv[2])
73
    print wedge.pheaders
74
    for section in wedge.sheaders:
75
        print section.name
76
        section.name += ".linux"
77
        print section.name
78
    #del wedge.pheaders[:]
79
    #print wedge.pheaders
80
    wedge.write_file("foobar")
81
    gen_pheaders(wedge)
82
 
83
if __name__ == "__main__":
84
    main()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.