Beispiel #1
0
 def decode(self, bits):
     # TODO add decode inside instruction:
     #return decode( bits )
     inst_str, exec_fun = decode(bits)
     return Instruction(bits, inst_str), exec_fun
Beispiel #2
0
 def decode( self, bits ):
   inst_str, exec_fun = decode( bits )
   return Instruction( bits, inst_str ), exec_fun
Beispiel #3
0
def run(state, max_insts=0):
    s = state

    while s.status == 0:

        jitdriver.jit_merge_point(
            pc=s.fetch_pc(),
            max_insts=max_insts,
            state=s,
        )

        # constant-fold pc and mem
        pc = hint(s.fetch_pc(), promote=True)
        old = pc
        mem = hint(s.mem, promote=True)

        if s.debug.enabled("insts"):
            print pad("%x" % pc, 6, " ", False),

        # the print statement in memcheck conflicts with @elidable in iread.
        # So we use normal read if memcheck is enabled which includes the
        # memory checks

        if s.debug.enabled("memcheck"):
            inst = mem.read(pc, 4)
        else:
            # we use trace elidable iread instead of just read
            inst = mem.iread(pc, 4)

        inst_str, exec_fun = decode(inst)

        if s.debug.enabled("insts"):
            print "%s %s %s" % (
                pad_hex(inst),
                pad(inst_str, 8),
                pad("%d" % s.ncycles, 8),
            ),

        try:
            exec_fun(s, Instruction(inst))
        except FatalError as error:
            # TODO: maybe we can add a command line arg to just give a warning
            # and not terminate execution
            print "Exception in execution, aborting!"
            print "Exception message: %s" % error.msg
            break

        s.ncycles += 1  # TODO: should this be done inside instruction definition?
        if s.stats_en: s.stat_ncycles += 1

        if s.debug.enabled("insts"):
            print
        if s.debug.enabled("regdump"):
            s.rf.print_regs(per_row=4)
            print '%s%s%s%s' % ('N' if s.N else '-', 'Z' if s.Z else '-',
                                'C' if s.C else '-', 'V' if s.V else '-')

        # check if we have reached the end of the maximum instructions and
        # exit if necessary
        if max_insts != 0 and s.ncycles >= max_insts:
            print "Reached the max_insts (%d), exiting." % max_insts
            break

        if s.fetch_pc() < old:
            jitdriver.can_enter_jit(
                pc=s.fetch_pc(),
                max_insts=max_insts,
                state=s,
            )

    print 'DONE! Status =', s.status
    print 'Instructions Executed =', s.ncycles
Beispiel #4
0
 def decode( self, bits ):
   # TODO add decode inside instruction:
   #return decode( bits )
   inst_str, exec_fun = decode( bits )
   return Instruction( bits, inst_str ), exec_fun
Beispiel #5
0
def run(state, max_insts=0):
    s = state

    while s.running:

        jitdriver.jit_merge_point(
            pc=s.pc,
            max_insts=max_insts,
            state=s,
        )

        # constant fold the pc
        pc = hint(s.pc, promote=True)
        old = pc

        # We constant fold the s.mem object. This is important because
        # otherwise the trace elidable iread doesn't work (assumes s.mem might
        # have changed)
        mem = hint(s.mem, promote=True)

        if s.debug.enabled("insts"):
            print pad("%x" % s.pc, 6, " ", False),

        # the print statement in memcheck conflicts with @elidable in iread.
        # So we use normal read if memcheck is enabled which includes the
        # memory checks

        if s.debug.enabled("memcheck"):
            inst = mem.read(pc, 4)
        else:
            # we use trace elidable iread instead of just read
            inst = mem.iread(pc, 4)

        inst_str, exec_fun = decode(inst)

        if s.debug.enabled("insts"):
            print "%s %s %s" % (
                pad_hex(inst),
                pad(inst_str, 8),
                pad("%d" % s.ncycles, 8),
            ),

        exec_fun(s, Instruction(inst))

        s.ncycles += 1  # TODO: should this be done inside instruction definition?
        if s.stats_en: s.stat_ncycles += 1

        if s.debug.enabled("insts"):
            print
        if s.debug.enabled("regdump"):
            s.rf.print_regs()

        # check if we have reached the end of the maximum instructions and
        # exit if necessary
        if max_insts != 0 and s.ncycles >= max_insts:
            print "Reached the max_insts (%d), exiting." % max_insts
            break

        if s.pc < old:
            jitdriver.can_enter_jit(
                pc=s.pc,
                max_insts=max_insts,
                state=s,
            )

    print 'DONE! Status =', s.status
    print 'Instructions Executed =', s.ncycles