Ejemplo n.º 1
0
from revelation.machine import RESET_ADDR
from revelation.sim import Revelation, new_memory
from revelation.test.machine import new_state

class MockRevelation(Revelation):
    """Revelation test harness.
    This class should only be used in unit tests.
    """

    def __init__(self):
        Revelation.__init__(self)
        self.debug = Debug()
        Debug.global_enabled = True

    def init_state(self, instructions, **args):
        """Load the program into a memory object.
        This function should ONLY be called by unit tests.
        """
        self.memory = new_memory(self.debug)
        written_so_far = 0
        for i, (data, width) in enumerate(instructions):
            num_bytes = width / 8
            self.memory.write(RESET_ADDR + written_so_far, num_bytes, data)
            written_so_far += num_bytes
        self.states[0x808] = new_state(mem=self.memory, debug=self.debug, **args)
        self.states[0x808].set_first_core(True)
        self.num_cores = len(self.states)
        self.max_insts = len(instructions)

init_sim(MockRevelation())
Ejemplo n.º 2
0
        # Load the program into a memory object

        mem = Memory(size=memory_size, byte_storage=False)
        entrypoint, breakpoint = load_program(exe_file, mem)

        # Insert bootstrapping code into memory and initialize processor state

        if testbin: self.state = test_init(mem, self.debug)
        else:
            self.state = syscall_init(mem, breakpoint, run_argv, run_envp,
                                      self.debug)

        self.state.testbin = testbin
        self.state.exe_name = exe_name

    #---------------------------------------------------------------------
    # run
    #---------------------------------------------------------------------
    # Override sim's run to print stat_num_insts on exit

    def run(self):
        Sim.run(self)
        print "Instructions Executed in Stat Region =", self.state.stat_num_insts


# this initializes similator and allows translation and python
# interpretation

init_sim(ParcSim())
Ejemplo n.º 3
0
            print ':: RD.CPSR = %s%s%s%s' % (
                'N' if self.state.N else '-', 'Z' if self.state.Z else '-',
                'C' if self.state.C else '-', 'V' if self.state.V else '-'),

    #-----------------------------------------------------------------------
    # init_state
    #-----------------------------------------------------------------------
    # This method is called to load the program and initialize architectural
    # state

    def init_state(self, exe_file, exe_name, run_argv, run_envp, testbin):

        # Load the program into a memory object

        mem = Memory(size=memory_size, byte_storage=False)
        entrypoint, breakpoint = load_program(
            #open( filename, 'rb' ),
            exe_file,
            mem,
            # TODO: GEM5 uses this alignment, remove?
            alignment=1 << 12)

        self.state = syscall_init(mem, entrypoint, breakpoint, run_argv,
                                  run_envp, self.debug)


# this initializes similator and allows translation and python
# interpretation

init_sim(ArmSim())
Ejemplo n.º 4
0
    entrypoint, breakpoint = load_program( exe_file, mem, is_64bit=True )

    # Insert bootstrapping code into memory and initialize processor state

    #if testbin: self.state = test_init   ( mem, self.debug )
    #else:       self.state = syscall_init( mem, breakpoint, run_argv,
    #                                       run_envp, self.debug )
    if testbin:
      self.state = test_init( mem, self.debug )
    else:
      self.state = syscall_init( mem, breakpoint, run_argv,
                                           run_envp, self.debug )

    self.state.testbin  = testbin
    self.state.exe_name = exe_name

  #---------------------------------------------------------------------
  # run
  #---------------------------------------------------------------------
  # Override sim's run to print stat_num_insts on exit

  def run( self ):
    Sim.run( self )

# this initializes similator and allows translation and python
# interpretation

init_sim( RiscVSim() )

Ejemplo n.º 5
0
from epiphany.isa import decode
from epiphany.machine import State, RESET_ADDR
from epiphany.instruction import Instruction

MEMORY_SIZE = 2**18  # 2^8 x 2^10 == 32kB.

def new_memory():
    return Memory(size=MEMORY_SIZE, byte_storage=True)


class Epiphany(Sim):

    def __init__(self):
        Sim.__init__(self, "Epiphany", jit_enabled=True)

    def decode(self, bits):
        inst_str, exec_fun = decode(bits)
        return Instruction(bits, inst_str), exec_fun

    def init_state(self, exe_file, filename, run_argv,
                   envp, testbin, is_test=False):
        if is_test:
            self.debug = Debug()
            Debug.global_enabled = True
        mem = new_memory()
        _, _ = load_program(exe_file, mem)
        self.state = State(mem, self.debug, reset_addr=RESET_ADDR)


init_sim(Epiphany())
Ejemplo n.º 6
0
        print
        print 'Program in memory just after writing:'
        # We are expecting to see a nop16 and a halt16, i.e.:
        #    1: 418      # 16bits
        #    2: 29492163 # 32bits
        #    3: 450      # 16bits
        read_so_far = 0
        for i, (_, width) in enumerate(instructions):
            num_bytes = width / 8
            read_so_far += num_bytes
            inst = mem.read(read_so_far, num_bytes)
            print "{0}: {1:016b} ({2})  # width={3}bits".format(i, inst, inst, width)
        print
        self.state = ExampleState(mem, Debug(flags=['insts', 'mem', 'rf', 'regdump']))

init_sim(ExampleMachine())


def test_16bit_instructions():
    instructions = [(0b0000000110100010, 16),                  # nop16
                    (0b0000000111000010, 16),                  # halt16
                    ]
    machine = ExampleMachine()
    machine.load_program(instructions)
    print
    print 'Program in memory just before simulation:'
    for i in range(4):
        inst = machine.state.mem.read(i, 1)
        print "{0}: {1:016b} ({2})  # width={3}bytes".format(i, inst, inst, 2),
        if (i + 1) % 2 == 0: print
    print
Ejemplo n.º 7
0
    return Instruction( bits, inst_str ), exec_fun

  #-----------------------------------------------------------------------
  # init_state
  #-----------------------------------------------------------------------
  # This method is called to load the program and initialize architectural
  # state

  def init_state( self, exe_file, exe_name, run_argv, run_envp, testbin ):

    # Load the program into a memory object

    mem = Memory( size=memory_size, byte_storage=False )
    entrypoint, breakpoint = load_program(
        #open( filename, 'rb' ),
        exe_file,
        mem,
        # TODO: GEM5 uses this alignment, remove?
        alignment = 1<<12
    )

    self.state = syscall_init( mem, entrypoint, breakpoint,
                               run_argv, run_envp, self.debug )


# this initializes similator and allows translation and python
# interpretation

init_sim( ArmSim() )

Ejemplo n.º 8
0
from pydgin.sim import init_sim

from epiphany.machine import RESET_ADDR
from epiphany.sim import Epiphany, new_memory
from epiphany.test.machine import new_state

class MockEpiphany(Epiphany):
    """Epiphany test harness.
    This class should only be used in unit tests.
    """

    def __init__(self):
        Epiphany.__init__(self)
        self.debug = Debug()
        Debug.global_enabled = True

    def init_state(self, instructions, **args):
        """Load the program into a memory object.
        This function should ONLY be called by unit tests.
        """
        mem = new_memory()
        written_so_far = 0
        for i, (data, width) in enumerate(instructions):
            num_bytes = width / 8
            mem.write(RESET_ADDR + written_so_far, num_bytes, data)
            written_so_far += num_bytes
        self.state = new_state(mem=mem, debug=self.debug, **args)
        self.max_insts = len(instructions)

init_sim(MockEpiphany())
Ejemplo n.º 9
0
        self.memory = new_memory(self.logger)
        if self.profile:
            timer = time.time()
            print 'Memory creation took: %fs' % (timer - self.timer)
            self.timer = timer
        f_row = (self.first_core >> 6) & 0x3f
        f_col = self.first_core & 0x3f
        elf = elf_reader(elf_file, is_64bit=False)
        coreids = []
        for row in xrange(self.rows):
            for col in xrange(self.cols):
                coreid = get_coreid_from_coords(f_row + row, f_col + col)
                coreids.append(coreid)
                print ('Loading program %s on to core %s (%s, %s)' %
                       (filename, hex(coreid), zfill(str(f_row + row), 2),
                        zfill(str(f_col + col), 2)))
                self.states[coreid] = State(self.memory, self.debug,
                                            logger=self.logger, coreid=coreid)
        code_blocks = load_program(elf, self.memory, coreids, ext_base=self.ext_base,
                                   ext_size=self.ext_size)
        for section in code_blocks:
            self.memory.code_blocks.append(section)
        self.states[coreids[0]].set_first_core(True)
        if self.profile:
            timer = time.time()
            print 'ELF file loader took: %fs' % (timer - self.timer)
            self.timer = timer


init_sim(Revelation())