Exemple #1
0
def test_fields_reg():

    # Create the memory image

    mem_image = pisa_encoding.assemble("""
    mfc0 r2, mngr2proc < 1
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    mtc0 r2, proc2mngr > 1
    nop
    nop
    nop
    nop
    nop
    nop
    nop
  """)

    sim = PisaSim()
    sim.load(mem_image)
    sim.run()
Exemple #2
0
def test_assemble_without_ctrl():

    # Create the assembly code string

    asm = \
    """
    ori  r1, r0, 0x2000  # address of src0
    ori  r2, r0, 0x2004  # address of src1
    ori  r3, r0, 0x2008  # address of dest
    lw   r4, 0(r1)       # load src0
    lw   r5, 0(r2)       # load src1
    addu r6, r4, r5      # add two elements together
    sw   r6, 0(r3)       # store dest

    .data
    .word 13             # src0
    .word 15             # src1
    .word 0              # dest
  """

    # Assemble code into a memory image

    mem_image = pisa_encoding.assemble(asm)

    # Create a reference text section by using binutils

    text_section = mk_section(
        ".text",
        0x0400,
        [
            0x34012000,  # li   at, 0x2000
            0x34022004,  # li   v0, 0x2004
            0x34032008,  # li   v1, 0x2008
            0x8c240000,  # lw   a0, 0(at)
            0x8c450000,  # lw   a1, 0(v0)
            0x00853021,  # addu a2, a0, a1
            0xac660000,  # sw   a2, 0(v1)
        ])

    # Create a reference data section manually

    data_section = mk_section(
        ".data",
        0x2000,
        [
            0x0000000d,  # .word 13
            0x0000000f,  # .word 13
            0x00000000,  # .word 0
        ])

    # Build a sparse memory image

    mem_image_ref = SparseMemoryImage()
    mem_image_ref.add_section(text_section)
    mem_image_ref.add_section(data_section)

    # Check that both sparse memory image are equal

    assert mem_image == mem_image_ref
def test_assemble_without_ctrl():

  # Create the assembly code string

  asm = \
  """
    ori  r1, r0, 0x2000  # address of src0
    ori  r2, r0, 0x2004  # address of src1
    ori  r3, r0, 0x2008  # address of dest
    lw   r4, 0(r1)       # load src0
    lw   r5, 0(r2)       # load src1
    addu r6, r4, r5      # add two elements together
    sw   r6, 0(r3)       # store dest

    .data
    .word 13             # src0
    .word 15             # src1
    .word 0              # dest
  """

  # Assemble code into a memory image

  mem_image = pisa_encoding.assemble( asm )

  # Create a reference text section by using binutils

  text_section = mk_section( ".text", 0x0400,
  [
    0x34012000, # li   at, 0x2000
    0x34022004, # li   v0, 0x2004
    0x34032008, # li   v1, 0x2008
    0x8c240000, # lw   a0, 0(at)
    0x8c450000, # lw   a1, 0(v0)
    0x00853021, # addu a2, a0, a1
    0xac660000, # sw   a2, 0(v1)
  ])

  # Create a reference data section manually

  data_section = mk_section( ".data", 0x2000,
  [
    0x0000000d, # .word 13
    0x0000000f, # .word 13
    0x00000000, # .word 0
  ])

  # Build a sparse memory image

  mem_image_ref = SparseMemoryImage()
  mem_image_ref.add_section( text_section )
  mem_image_ref.add_section( data_section )

  # Check that both sparse memory image are equal

  assert mem_image == mem_image_ref
Exemple #4
0
def test(gen_test):
    sim = PisaSim(trace_en=True)
    sim.load(pisa_encoding.assemble(gen_test()))
    sim.run()
def test( name, test ):
  sim = PisaSim( trace_en=True )
  sim.load( pisa_encoding.assemble( test() ) )
  sim.run()
def test_assemble_with_prog_mngr():

  # Create the assembly code string

  asm = \
  """
    mfc0 r1, mngr2proc < 0x13
    mfc0 r2, mngr2proc < 0x57
    addu r3, r1, r2    # add two elements together
    mtc0 r3, proc2mngr > 0x6a
    nop
    mfc0 r1, mngr2proc < 0x65
    mfc0 r2, mngr2proc < 0x42
    addu r3, r1, r2    # add two elements together
    mtc0 r3, proc2mngr > 0xa7
  """

  # Assemble code into a memory image

  mem_image = pisa_encoding.assemble( asm )

  # Create a reference text section by using binutils

  text_section = mk_section( ".text", 0x0400,
  [
    0x40010800, # mfc0 at, mngr2proc
    0x40020800, # mfc0 v0, mngr2proc
    0x00221821, # addu v1, at,v0
    0x40831000, # mtc0 v1, proc2mngr
    0x00000000, # nop
    0x40010800, # mfc0 at, mngr2proc
    0x40020800, # mfc0 v0, mngr2proc
    0x00221821, # addu v1, at,v0
    0x40831000, # mtc0 v1, proc2mngr
  ])

  # Create a reference mngr2proc section manually

  mngr2proc_section = mk_section( ".mngr2proc", 0x3000,
  [
    0x00000013,
    0x00000057,
    0x00000065,
    0x00000042,
  ])

  # Create a reference proc2mngr section manually

  proc2mngr_section = mk_section( ".proc2mngr", 0x4000,
  [
    0x0000006a,
    0x000000a7,
  ])

  # Build a sparse memory image

  mem_image_ref = SparseMemoryImage()
  mem_image_ref.add_section( text_section      )
  mem_image_ref.add_section( mngr2proc_section )
  mem_image_ref.add_section( proc2mngr_section )

  # Check that both sparse memory image are equal

  assert mem_image == mem_image_ref
def test_assemble_with_ctrl():

  # Create the assembly code string

  asm = \
  """
    addiu r1, r0, 4       # array size
    ori   r2, r0, 0x2000  # src0 base pointer
    ori   r3, r0, 0x2010  # src1 base pointer
    ori   r4, r0, 0x2020  # dest base pointer
    addiu r5, r0, 0       # induction variable
  loop:
    lw    r6, 0(r2)       # load src0
    lw    r7, 0(r3)       # load src1
    addu  r8, r6, r7      # addition
    sw    r8, 0(r4)       # store dest
    addiu r2, r2, 4       # pointer bump for src0
    addiu r3, r3, 4       # pointer bump for src1
    addiu r4, r4, 4       # pointer bump for dest
    addiu r5, r5, 1       # increment induction variable
    bne   r5, r1, loop    # loop branch

    .data # addr = 0x2000

    # src0 array
    .word 89320
    .word 30239
    .word  1329
    .word 89021

    # src1 array
    .word 30411
    .word 64198
    .word  4210
    .word 20199

    # dest array
    .word 0
    .word 0
    .word 0
    .word 0
  """

  # Assemble code into a memory image

  mem_image = pisa_encoding.assemble( asm )

  # Create a reference text section by using binutils

  text_section = mk_section( ".text", 0x0400,
  [
    0x24010004, # li    at, 4
    0x34022000, # li    v0, 0x2000
    0x34032010, # li    v1, 0x2010
    0x34042020, # li    a0, 0x2020
    0x24050000, # li    a1, 0
    0x8c460000, # lw    a2, 0(v0)
    0x8c670000, # lw    a3, 0(v1)
    0x00c74021, # addu  a4, a2, a3
    0xac880000, # sw    a4, 0(a0)
    0x24420004, # addiu v0, v0, 4
    0x24630004, # addiu v1, v1, 4
    0x24840004, # addiu a0, a0, 4
    0x24a50001, # addiu a1, a1, 1
    0x14a1fff7, # bne   a1, at, 1154 <loop>
  ])

  # Create a reference data section manually

  data_section = mk_section( ".data", 0x2000,
  [
    0x00015ce8, # .word  89320
    0x0000761f, # .word  30239
    0x00000531, # .word   1329
    0x00015bbd, # .word  89021
    0x000076cb, # .word  30411
    0x0000fac6, # .word  64198
    0x00001072, # .word   4210
    0x00004ee7, # .word  20199
    0x00000000, # .word      0
    0x00000000, # .word      0
    0x00000000, # .word      0
    0x00000000, # .word      0
  ])

  # Build a sparse memory image

  mem_image_ref = SparseMemoryImage()
  mem_image_ref.add_section( text_section )
  mem_image_ref.add_section( data_section )

  # Check that both sparse memory image are equal

  assert mem_image == mem_image_ref
Exemple #8
0
def test_assemble_with_prog_mngr():

    # Create the assembly code string

    asm = \
    """
    mfc0 r1, mngr2proc < 0x13
    mfc0 r2, mngr2proc < 0x57
    addu r3, r1, r2    # add two elements together
    mtc0 r3, proc2mngr > 0x6a
    nop
    mfc0 r1, mngr2proc < 0x65
    mfc0 r2, mngr2proc < 0x42
    addu r3, r1, r2    # add two elements together
    mtc0 r3, proc2mngr > 0xa7
  """

    # Assemble code into a memory image

    mem_image = pisa_encoding.assemble(asm)

    # Create a reference text section by using binutils

    text_section = mk_section(
        ".text",
        0x0400,
        [
            0x40010800,  # mfc0 at, mngr2proc
            0x40020800,  # mfc0 v0, mngr2proc
            0x00221821,  # addu v1, at,v0
            0x40831000,  # mtc0 v1, proc2mngr
            0x00000000,  # nop
            0x40010800,  # mfc0 at, mngr2proc
            0x40020800,  # mfc0 v0, mngr2proc
            0x00221821,  # addu v1, at,v0
            0x40831000,  # mtc0 v1, proc2mngr
        ])

    # Create a reference mngr2proc section manually

    mngr2proc_section = mk_section(".mngr2proc", 0x3000, [
        0x00000013,
        0x00000057,
        0x00000065,
        0x00000042,
    ])

    # Create a reference proc2mngr section manually

    proc2mngr_section = mk_section(".proc2mngr", 0x4000, [
        0x0000006a,
        0x000000a7,
    ])

    # Build a sparse memory image

    mem_image_ref = SparseMemoryImage()
    mem_image_ref.add_section(text_section)
    mem_image_ref.add_section(mngr2proc_section)
    mem_image_ref.add_section(proc2mngr_section)

    # Check that both sparse memory image are equal

    assert mem_image == mem_image_ref
Exemple #9
0
def test_assemble_with_ctrl():

    # Create the assembly code string

    asm = \
    """
    addiu r1, r0, 4       # array size
    ori   r2, r0, 0x2000  # src0 base pointer
    ori   r3, r0, 0x2010  # src1 base pointer
    ori   r4, r0, 0x2020  # dest base pointer
    addiu r5, r0, 0       # induction variable
  loop:
    lw    r6, 0(r2)       # load src0
    lw    r7, 0(r3)       # load src1
    addu  r8, r6, r7      # addition
    sw    r8, 0(r4)       # store dest
    addiu r2, r2, 4       # pointer bump for src0
    addiu r3, r3, 4       # pointer bump for src1
    addiu r4, r4, 4       # pointer bump for dest
    addiu r5, r5, 1       # increment induction variable
    bne   r5, r1, loop    # loop branch

    .data # addr = 0x2000

    # src0 array
    .word 89320
    .word 30239
    .word  1329
    .word 89021

    # src1 array
    .word 30411
    .word 64198
    .word  4210
    .word 20199

    # dest array
    .word 0
    .word 0
    .word 0
    .word 0
  """

    # Assemble code into a memory image

    mem_image = pisa_encoding.assemble(asm)

    # Create a reference text section by using binutils

    text_section = mk_section(
        ".text",
        0x0400,
        [
            0x24010004,  # li    at, 4
            0x34022000,  # li    v0, 0x2000
            0x34032010,  # li    v1, 0x2010
            0x34042020,  # li    a0, 0x2020
            0x24050000,  # li    a1, 0
            0x8c460000,  # lw    a2, 0(v0)
            0x8c670000,  # lw    a3, 0(v1)
            0x00c74021,  # addu  a4, a2, a3
            0xac880000,  # sw    a4, 0(a0)
            0x24420004,  # addiu v0, v0, 4
            0x24630004,  # addiu v1, v1, 4
            0x24840004,  # addiu a0, a0, 4
            0x24a50001,  # addiu a1, a1, 1
            0x14a1fff7,  # bne   a1, at, 1154 <loop>
        ])

    # Create a reference data section manually

    data_section = mk_section(
        ".data",
        0x2000,
        [
            0x00015ce8,  # .word  89320
            0x0000761f,  # .word  30239
            0x00000531,  # .word   1329
            0x00015bbd,  # .word  89021
            0x000076cb,  # .word  30411
            0x0000fac6,  # .word  64198
            0x00001072,  # .word   4210
            0x00004ee7,  # .word  20199
            0x00000000,  # .word      0
            0x00000000,  # .word      0
            0x00000000,  # .word      0
            0x00000000,  # .word      0
        ])

    # Build a sparse memory image

    mem_image_ref = SparseMemoryImage()
    mem_image_ref.add_section(text_section)
    mem_image_ref.add_section(data_section)

    # Check that both sparse memory image are equal

    assert mem_image == mem_image_ref