6 filedir
= os
.path
.dirname(os
.path
.realpath(__file__
))
7 memmap
= os
.path
.join(filedir
, "memmap")
10 endian_fmt
= "elf64-big"
14 def __init__(self
, instructions
):
15 if isinstance(instructions
, list):
16 instructions
= '\n'.join(instructions
)
17 self
.assembly
= instructions
20 def _get_binary(self
, elffile
):
21 self
.binfile
= tempfile
.NamedTemporaryFile(suffix
=".bin")
22 #self.binfile = open("kernel.bin", "wb+")
23 args
= ["powerpc64-linux-gnu-objcopy",
28 subprocess
.check_output(args
)
30 def _link(self
, ofile
):
31 with tempfile
.NamedTemporaryFile(suffix
=".elf") as elffile
:
32 #with open("kernel.elf", "wb+") as elffile:
33 args
= ["powerpc64-linux-gnu-ld",
37 subprocess
.check_output(args
)
38 self
._get
_binary
(elffile
)
41 with tempfile
.NamedTemporaryFile(suffix
=".o") as outfile
:
42 args
= ["powerpc64-linux-gnu-as",
46 p
= subprocess
.Popen(args
, stdin
=subprocess
.PIPE
)
47 p
.communicate(self
.assembly
.encode('utf-8'))
51 def generate_instructions(self
):
53 data
= self
.binfile
.read(4)
56 yield struct
.unpack('<i', data
)[0]