initial_mem=None, initial_msr=0,
initial_insns=None, respect_pc=False,
disassembly=None,
- initial_pc=0):
+ initial_pc=0,
+ bigendian=True):
+ self.bigendian = bigendian
self.halted = False
self.respect_pc = respect_pc
if initial_sprs is None:
print ("CIA NIA", self.respect_pc, self.pc.CIA.value, self.pc.NIA.value)
yield self.dec2.dec.raw_opcode_in.eq(ins & 0xffffffff)
- yield self.dec2.dec.bigendian.eq(0) # little / big?
+ yield self.dec2.dec.bigendian.eq(self.bigendian)
def execute_one(self):
"""execute one instruction
def elaborate(self, platform):
m = PowerDecoder.elaborate(self, platform)
comb = m.d.comb
+ # raw opcode in, byte-reverse it
raw_be = self.raw_opcode_in
l = []
for i in range(0, self.width, 8):
filedir = os.path.dirname(os.path.realpath(__file__))
memmap = os.path.join(filedir, "memmap")
-bigendian = True
-if bigendian:
- endian_fmt = "elf64-big"
- obj_fmt = "-be"
- ld_fmt = "-EB"
-else:
- ld_fmt = "-EL"
- endian_fmt = "elf64-little"
- obj_fmt = "-le"
-
class Program:
- def __init__(self, instructions):
+ def __init__(self, instructions, bigendian=True):
+ self.bigendian = bigendian
+ if self.bigendian:
+ self.endian_fmt = "elf64-big"
+ self.obj_fmt = "-be"
+ self.ld_fmt = "-EB"
+ else:
+ self.ld_fmt = "-EL"
+ self.endian_fmt = "elf64-little"
+ self.obj_fmt = "-le"
+
if isinstance(instructions, str): # filename
self.binfile = open(instructions, "rb")
self.assembly = '' # noo disassemble number fiiive
self.binfile = tempfile.NamedTemporaryFile(suffix=".bin")
args = ["powerpc64-linux-gnu-objcopy",
"-O", "binary",
- "-I", endian_fmt,
+ "-I", self.endian_fmt,
elffile.name,
self.binfile.name]
subprocess.check_output(args)
def _link(self, ofile):
with tempfile.NamedTemporaryFile(suffix=".elf") as elffile:
args = ["powerpc64-linux-gnu-ld",
- ld_fmt,
+ self.ld_fmt,
"-o", elffile.name,
"-T", memmap,
ofile.name]
with tempfile.NamedTemporaryFile(suffix=".o") as outfile:
args = ["powerpc64-linux-gnu-as",
'-mpower9',
- obj_fmt,
+ self.obj_fmt,
"-o",
outfile.name]
p = subprocess.Popen(args, stdin=subprocess.PIPE)
stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
self.gdb = GdbController(gdb_path='powerpc64-linux-gnu-gdb')
+ self.set_endian(bigendian)
def __enter__(self):
return self
def connect(self):
return self.gdb.write('-target-select remote localhost:1234')
+ def set_endian(self, bigendian):
+ if bigendian:
+ cmd = '-gdb-set endian big'
+ else:
+ cmd = '-gdb-set endian little'
+ return self.gdb.write(cmd)
+
def break_address(self, addr):
cmd = '-break-insert *0x{:x}'.format(addr)
return self.gdb.write(cmd)
"addis 12, 0, 0",
]
with Program(lst) as program:
- self.run_tst_program(program, [0, 12])
+ self.run_tst_program(program, [12])
def run_tst_program(self, prog, initial_regs=None, initial_sprs=None,
initial_mem=None):
gen = list(generator.generate_instructions())
insn_code = generator.assembly.splitlines()
instructions = list(zip(gen, insn_code))
+ bigendian = False
pdecode = create_pdecode()
m.submodules.pdecode2 = pdecode2 = PowerDecode2(pdecode)
simulator = ISA(pdecode2, [0] * 32, {}, 0, initial_mem, 0,
initial_insns=gen, respect_pc=True,
disassembly=insn_code,
- initial_pc=initial_pc)
+ initial_pc=initial_pc,
+ bigendian=bigendian)
sim = Simulator(m)
def process():
- yield pdecode2.dec.bigendian.eq(1)
+ #yield pdecode2.dec.bigendian.eq(1)
yield Settle()
while True: