#=========================================================================
# pisa_sb_test.py
#=========================================================================

import pytest
import random
import pisa_encoding

from pymtl import Bits
from PisaSim   import PisaSim

from pisa_inst_test_utils import *

#-------------------------------------------------------------------------
# gen_basic_test
#-------------------------------------------------------------------------

def gen_basic_test():
  return """
    mfc0 r1, mngr2proc < 0x00002000
    mfc0 r2, mngr2proc < 0xdeadbeef
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    sb   r2, 0(r1)
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    lw   r3, 0(r1)
    mtc0 r3, proc2mngr > 0x010203ef

    .data
    .word 0x01020304
  """

#-------------------------------------------------------------------------
# gen_dest_byp_test
#-------------------------------------------------------------------------

def gen_dest_byp_test():
  return [

    gen_st_dest_byp_test( 5, "sb", 0x30313233, 0x2000, 0x00010233 ),
    gen_st_dest_byp_test( 4, "sb", 0x34353637, 0x2004, 0x04050637 ),
    gen_st_dest_byp_test( 3, "sb", 0x38393a3b, 0x2008, 0x08090a3b ),
    gen_st_dest_byp_test( 2, "sb", 0x3c3d3e3f, 0x200c, 0x0c0d0e3f ),
    gen_st_dest_byp_test( 1, "sb", 0x40414243, 0x2010, 0x10111243 ),
    gen_st_dest_byp_test( 0, "sb", 0x44454647, 0x2014, 0x14151647 ),

    gen_word_data([
      0x00010203,
      0x04050607,
      0x08090a0b,
      0x0c0d0e0f,
      0x10111213,
      0x14151617,
    ])

  ]

#-------------------------------------------------------------------------
# gen_base_byp_test
#-------------------------------------------------------------------------

def gen_base_byp_test():
  return [

    gen_st_base_byp_test( 5, "sb", 0x30313233, 0x2000, 0x00010233 ),
    gen_st_base_byp_test( 4, "sb", 0x34353637, 0x2004, 0x04050637 ),
    gen_st_base_byp_test( 3, "sb", 0x38393a3b, 0x2008, 0x08090a3b ),
    gen_st_base_byp_test( 2, "sb", 0x3c3d3e3f, 0x200c, 0x0c0d0e3f ),
    gen_st_base_byp_test( 1, "sb", 0x40414243, 0x2010, 0x10111243 ),
    gen_st_base_byp_test( 0, "sb", 0x44454647, 0x2014, 0x14151647 ),

    gen_word_data([
      0x00010203,
      0x04050607,
      0x08090a0b,
      0x0c0d0e0f,
      0x10111213,
      0x14151617,
    ])

  ]


#-------------------------------------------------------------------------
# gen_src_byp_test
#-------------------------------------------------------------------------

def gen_src_byp_test():
  return [

    gen_st_src_byp_test( 5, "sb", 0x30313233, 0x2000, 0x00010233 ),
    gen_st_src_byp_test( 4, "sb", 0x34353637, 0x2004, 0x04050637 ),
    gen_st_src_byp_test( 3, "sb", 0x38393a3b, 0x2008, 0x08090a3b ),
    gen_st_src_byp_test( 2, "sb", 0x3c3d3e3f, 0x200c, 0x0c0d0e3f ),
    gen_st_src_byp_test( 1, "sb", 0x40414243, 0x2010, 0x10111243 ),