Exemple #1
0
 def __init__(self):
     self.comment = ""
     self.exception = vsc.rand_enum_t(illegal_instr_type_e)
     self.reserved_c = vsc.rand_enum_t(reserved_c_instr_e)
     self.instr_bin = vsc.rand_bit_t(32)
     self.opcode = vsc.rand_bit_t(7)
     self.compressed = vsc.rand_bit_t(1)
     self.func3 = vsc.rand_bit_t(3)
     self.func7 = vsc.rand_bit_t(7)
     self.has_func3 = vsc.rand_bit_t(1)
     self.has_func7 = vsc.rand_bit_t(1)
     self.c_op = vsc.rand_bit_t(2)
     self.c_msb = vsc.rand_bit_t(3)
     self.csrs = []
     # Default legal self.opcode for RV32I instructions
     self.legal_opcode = vsc.list_t(vsc.bit_t(7))
     self.legal_opcode = [3, 15, 19, 23, 35, 55, 99, 51, 103, 115, 111]
     # Default legal self.opcode for RV32C instructions
     self.legal_c00_opcode = vsc.list_t(vsc.bit_t(3))
     self.legal_c00_opcode = [0, 2, 6]
     self.legal_c10_opcode = vsc.list_t(vsc.bit_t(3))
     self.legal_c10_opcode = [0, 2, 4, 6]
     self.xlen = vsc.uint8_t(0)
     self.xlen = rcs.XLEN
     self.temp_1 = vsc.bit_t(6)
 def __init__(self):
     super().__init__()
     self.fs1 = vsc.rand_enum_t(riscv_fpr_t)
     self.fs2 = vsc.rand_enum_t(riscv_fpr_t)
     self.fs3 = vsc.rand_enum_t(riscv_fpr_t)
     self.fd = vsc.rand_enum_t(riscv_fpr_t)
     self.has_fs1 = vsc.bit_t(1, 1)
     self.has_fs2 = vsc.bit_t(1, 1)
     self.has_fs3 = vsc.bit_t(1)
     self.has_fd = vsc.bit_t(1, 1)
    def test_simple_intenum2(self):
        class my_e(IntEnum):
            A = auto()
            B = auto()
            
        a = vsc.rand_enum_t(my_e)
        b = vsc.rand_enum_t(my_e)

        for i in range(10): 
            with vsc.randomize_with(a, b):
                a != b
            self.assertNotEqual(a.get_val(), b.get_val())
Exemple #4
0
 def __init__(self):
     super().__init__()
     self.num_load_store = vsc.rand_uint32_t()
     self.num_mixed_instr = vsc.rand_uint32_t()
     self.base = vsc.rand_int32_t()
     self.offset = []
     self.addr = []
     self.load_store_instr = []
     self.data_page_id = vsc.rand_uint32_t()
     self.rs1_reg = vsc.rand_enum_t(riscv_reg_t)
     self.locality = vsc.rand_enum_t(locality_e)
     self.max_load_store_offset = vsc.rand_int32_t()
     self.use_sp_as_rs1 = vsc.rand_bit_t()
    def test_setval_intenum(self):
        class my_e(IntEnum):
            A = auto()
            B = auto()
            
        a = vsc.rand_enum_t(my_e)
        b = vsc.rand_enum_t(my_e)
        
        a.val = my_e.A
        b.val = my_e.B

        self.assertNotEqual(a.get_val(), b.get_val())
        self.assertEqual(a.val, a.get_val())
        self.assertEqual(a.val, my_e.A)
        self.assertEqual(b.val, b.get_val())
        self.assertEqual(b.val, my_e.B)
 def generate_return_routine(self, prefix):
     routine_str = ''
     jump_instr = [riscv_instr_name_t.JALR]
     rand_lsb = random.randrange(0, 1)
     ra = vsc.rand_enum_t(riscv_reg_t)
     try:
         with vsc.randomize_with(ra):
             ra.not_inside(vsc.rangelist(cfg.reserved_regs))
             ra != riscv_reg_t.ZERO
     except Exception:
         logging.critical("Cannot randomize ra")
         sys.exit(1)
     routine_str = prefix + "addi x{} x{} {}".format(
         ra.get_val(), cfg.ra, rand_lsb)
     self.instr_string_list.append(routine_str)
     if not cfg.disable_compressed_instr:
         jump_instr.append(riscv_instr_name_t.C_JR)
         if not (riscv_reg_t.RA in cfg.reserved_regs):
             jump_instr.append(riscv_instr_name_t.C_JALR)
     i = random.randrange(0, len(jump_instr) - 1)
     if jump_instr[i] == riscv_instr_name_t.C_JALR:
         routine_str = prefix + "c.jalr x{}".format(ra.get_val())
     elif jump_instr[i] == riscv_instr_name_t.C_JR:
         routine_str = prefix + "c.jr x{}".format(ra.get_val())
     elif jump_instr[i] == riscv_instr_name_t.JALR:
         routine_str = prefix + "jalr x{} x{} 0".format(
             ra.get_val(), ra.get_val())
     else:
         logging.critical("Unsupported jump_instr: {}".format(
             jump_instr[i]))
         sys.exit(1)
     self.instr_string_list.append(routine_str)
 def generate_return_routine(self, prefix):
     string = ''
     jump_instr = [riscv_instr_name_t.JALR]
     rand_lsb = random.randrange(0, 1)
     ra = vsc.rand_enum_t(riscv_reg_t)
     try:
         with vsc.randomize_with(ra):
             ra.not_inside(vsc.rangelist(cfg.reserved_regs))
             ra != riscv_reg_t.ZERO
     except Exception:
         logging.critical("Cannot randomize ra")
         sys.exit(1)
     string = (prefix + pkg_ins.format_string("{}addi x{} x{} {}".format(
         ra.name, cfg.ra.name, rand_lsb)))
     self.instr_string_list.append(string)
     if (not cfg.disable_compressed_instr):
         jump_instr.append(riscv_instr_name_t.C_JR)
         if (not (riscv_reg_t.RA in {cfg.reserved_regs})):
             jump_instr.append(riscv_instr_name_t.C_JALR)
     i = random.randrange(0, len(jump_instr) - 1)
     if (jump_instr[i] == riscv_instr_name_t.C_JAL):
         string = prefix + pkg_ins.format_string("{}c.jalr x{}".format(
             ra.name))
     elif (jump_instr[i] == riscv_instr_name_t.C_JR):
         string = prefix + pkg_ins.format_string("{}c.jr x{}".format(
             ra.name))
     elif (jump_instr[i] == riscv_instr_name_t.JALR):
         string = prefix + pkg_ins.format_string(
             "{}c.jalr x{} x{} 0".format(ra.name, ra.name))
     else:
         logging.critical("Unsupported jump_instr: %0s" % (jump_instr[i]))
         sys.exit(1)
         self.instr_string_list.append(string)
Exemple #8
0
    def __init__(self):
        # Instruction attributes
        self.group = vsc.enum_t(riscv_instr_group_t)
        self.format = vsc.enum_t(riscv_instr_format_t)
        self.category = vsc.enum_t(riscv_instr_category_t)
        self.instr_name = vsc.enum_t(riscv_instr_name_t)
        self.imm_type = vsc.enum_t(imm_t)
        self.imm_len = vsc.bit_t(5)

        # Operands
        self.csr = vsc.rand_bit_t(12)
        self.rs2 = vsc.rand_enum_t(riscv_reg_t)
        self.rs1 = vsc.rand_enum_t(riscv_reg_t)
        self.rd = vsc.rand_enum_t(riscv_reg_t)
        self.imm = vsc.rand_bit_t(32)

        # Helper Fields
        self.imm_mask = vsc.uint32_t(0xffffffff)
        self.is_branch_target = None
        self.has_label = 1
        self.atomic = 0
        self.branch_assigned = None
        self.process_load_store = 1
        self.is_compressed = None
        self.is_illegal_instr = None
        self.is_hint_instr = None
        self.is_floating_point = None
        self.imm_str = None
        self.comment = ""
        self.label = ""
        self.is_local_numeric_label = None
        self.idx = -1
        self.has_rs1 = vsc.bit_t(1)
        self.has_rs2 = vsc.bit_t(1)
        self.has_rd = vsc.bit_t(1)
        self.has_imm = vsc.bit_t(1)
        self.has_rs1 = 1
        self.has_rs2 = 1
        self.has_rd = 1
        self.has_imm = 1
        self.shift_t = vsc.uint32_t(0xffffffff)
        self.mask = 32
        self.XLEN = vsc.uint32_t(
            32)  # XLEN is used in constraint throughout the generator.
        # Hence, XLEN should be of PyVSC type in order to use it in a constraint block
        self.XLEN = rcs.XLEN
Exemple #9
0
    def __init__(self):
        self.instr_names = []
        self.instr_group = defaultdict(list)
        self.instr_category = defaultdict(list)
        self.basic_instr = []
        self.instr_template = {}

        self.exclude_reg = []
        self.include_reg = []

        self.group = None
        self.format = None
        self.category = None
        self.instr_name = None
        self.imm_type = None
        self.imm_len = 0

        self.csr = vsc.rand_bit_t(12)
        self.rs2 = vsc.rand_enum_t(riscv_reg_t)
        self.rs1 = vsc.rand_enum_t(riscv_reg_t)
        self.rd = vsc.rand_enum_t(riscv_reg_t)
        self.imm = vsc.rand_bit_t(32)

        self.imm_mask = vsc.uint32_t(0xffffffff)
        self.is_branch_target = None
        self.has_label = 1
        self.atomic = 0
        self.branch_assigned = None
        self.process_load_store = 1
        self.is_compressed = None
        self.is_illegal_instr = None
        self.is_hint_instr = None
        self.is_floating_point = None
        self.imm_str = None
        self.comment = ""
        self.label = ""
        self.is_local_numeric_label = None
        self.idx = -1
        self.has_rs1 = 1
        self.has_rs2 = 1
        self.has_rd = 1
        self.has_imm = 1
        self.shift_t = vsc.uint32_t(0xffffffff)
Exemple #10
0
 def __init__(self):
     self.a = vsc.rand_list_t(vsc.enum_t(my_e),
                              sz=3)  # self.a is a list of size 3
     self.b = vsc.rand_enum_t(my_e)
     self.c = vsc.rand_enum_t(my_e)
Exemple #11
0
    def __init__(self):
        # TODO Support for command line argument
        self.main_program_instr_cnt = 100  # count of main_prog
        self.sub_program_instr_cnt = []  # count of sub_prog
        self.debug_program_instr_cnt = 0  # count of debug_rom
        self.debug_sub_program_instr_cnt = []  # count of debug sub_progrms
        self.max_directed_instr_stream_seq = 20
        self.data_page_pattern = vsc.rand_enum_t(data_pattern_t)
        self.argv = self.parse_args()
        self.args_dict = vars(self.argv)

        global rcs
        rcs = import_module("pygen_src.target." + self.argv.target + ".riscv_core_setting")

        self.m_mode_exception_delegation = {}
        self.s_mode_exception_delegation = {}
        self.m_mode_interrupt_delegation = {}
        self.s_mode_interrupt_delegation = {}

        # init_privileged_mode default to MACHINE_MODE
        self.init_privileged_mode = privileged_mode_t.MACHINE_MODE

        self.mstatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.mie = vsc.rand_bit_t(rcs.XLEN - 1)
        self.sstatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.sie = vsc.rand_bit_t(rcs.XLEN - 1)
        self.ustatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.uie = vsc.rand_bit_t(rcs.XLEN - 1)

        self.mstatus_mprv = vsc.rand_bit_t(1)
        self.mstatus_mxr = vsc.rand_bit_t(1)
        self.mstatus_sum = vsc.rand_bit_t(1)
        self.mstatus_tvm = vsc.rand_bit_t(1)
        self.mstatus_fs = vsc.rand_bit_t(2)
        self.mstatus_vs = vsc.rand_bit_t(2)
        self.mtvec_mode = vsc.rand_enum_t(mtvec_mode_t)

        self.tvec_alignment = vsc.rand_uint8_t(self.argv.tvec_alignment)

        self.fcsr_rm = vsc.rand_enum_t(f_rounding_mode_t)
        self.enable_sfence = vsc.rand_bit_t(1)
        self.gpr = []

        # Helper fields for gpr
        self.gpr0 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr1 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr2 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr3 = vsc.rand_enum_t(riscv_reg_t)

        self.scratch_reg = vsc.rand_enum_t(riscv_reg_t)
        self.pmp_reg = vsc.rand_enum_t(riscv_reg_t)
        self.sp = vsc.rand_enum_t(riscv_reg_t)
        self.tp = vsc.rand_enum_t(riscv_reg_t)
        self.ra = vsc.rand_enum_t(riscv_reg_t)
        self.check_misa_init_val = 0
        self.check_xstatus = 1
        self.virtual_addr_translation_on = 0

        # Commenting out for now
        # vector_cfg = riscv_vector_cfg # TODO
        # pmp_cfg = riscv_pmp_cfg  # TODO
        self.mem_region = {
            0: {'name': "region_0", 'size_in_bytes': 4096, 'xwr': 8},
            1: {'name': "region_1", 'size_in_bytes': 4096 * 16, 'xwr': 8}
        }
        self.amo_region = {
            0: {'name': "amo_0", 'size_in_bytes': 64, 'xwr': 8}
        }
        self.stack_len = 5000
        self.s_mem_region = {
            0: {'name': "s_region_0", 'size_in_bytes': 4096, 'xwr': 8},
            1: {'name': "s_region_1", 'size_in_bytes': 4096, 'xwr': 8}
        }

        self.kernel_stack_len = 4000
        self.kernel_program_instr_cnt = 400
        # list of main implemented CSRs
        self.invalid_priv_mode_csrs = []
        self.num_of_sub_program = self.argv.num_of_sub_program
        self.instr_cnt = self.argv.instr_cnt
        self.num_of_tests = self.argv.num_of_tests
        self.no_data_page = self.argv.no_data_page
        self.no_branch_jump = self.argv.no_branch_jump
        self.no_load_store = self.argv.no_load_store
        self.no_csr_instr = self.argv.no_csr_instr
        self.no_ebreak = self.argv.no_ebreak
        self.no_dret = self.argv.no_dret
        self.no_fence = self.argv.no_fence
        self.no_wfi = self.argv.no_wfi
        self.enable_unaligned_load_store = self.argv.enable_unaligned_load_store
        self.illegal_instr_ratio = self.argv.illegal_instr_ratio
        self.hint_instr_ratio = self.argv.hint_instr_ratio
        self.num_of_harts = self.argv.num_of_harts
        self.fix_sp = self.argv.fix_sp
        self.use_push_data_section = self.argv.use_push_data_section
        self.boot_mode_opts = self.argv.boot_mode
        # self.isa = self.argv.isa

        if self.boot_mode_opts:
            logging.info("Got boot mode option - %0s", self.boot_mode_opts)
            if self.boot_mode_opts == "m":
                self.init_privileged_mode = privileged_mode_t.MACHINE_MODE
            elif self.boot_mode_opts == "s":
                self.init_privileged_mode = privileged_mode_t.SUPERVISOR_MODE
            elif self.boot_mode_opts == "u":
                self.init_privileged_mode = privileged_mode_t.USER_MODE
            else:
                logging.error("Illegal boot mode option - %0s", self.boot_mode_opts)

        self.enable_page_table_exception = self.argv.enable_page_table_exception
        self.no_directed_instr = self.argv.no_directed_instr
        self.asm_test_suffix = self.argv.asm_test_suffix
        self.enable_interrupt = self.argv.enable_interrupt
        self.enable_nested_interrupt = self.argv.enable_nested_interrupt
        self.enable_timer_irq = self.argv.enable_timer_irq
        self.bare_program_mode = self.argv.bare_program_mode
        self.enable_illegal_csr_instruction = self.argv.enable_illegal_csr_instruction
        self.enable_access_invalid_csr_level = self.argv.enable_access_invalid_csr_level
        self.enable_misaligned_instr = self.argv.enable_misaligned_instr
        self.enable_dummy_csr_write = self.argv.enable_dummy_csr_write
        self.randomize_csr = self.argv.randomize_csr
        self.allow_sfence_exception = self.argv.allow_sfence_exception
        self.no_delegation = self.argv.no_delegation
        self.force_m_delegation = self.argv.force_m_delegation
        self.force_s_delegation = self.argv.force_s_delegation
        self.support_supervisor_mode = 0
        self.disable_compressed_instr = self.argv.disable_compressed_instr
        self.require_signature_addr = self.argv.require_signature_addr

        if self.require_signature_addr:
            self.signature_addr = int(self.argv.signature_addr, 16)
        else:
            self.signature_addr = 0xdeadbeef

        self.gen_debug_section = self.argv.gen_debug_section
        self.enable_ebreak_in_debug_rom = self.argv.enable_ebreak_in_debug_rom
        self.set_dcsr_ebreak = self.argv.set_dcsr_ebreak
        self.num_debug_sub_program = self.argv.num_debug_sub_program
        self.enable_debug_single_step = self.argv.enable_debug_single_step
        self.single_step_iterations = 0
        self.set_mstatus_tw = self.argv.set_mstatus_tw
        self.set_mstatus_mprv = self.argv.set_mstatus_mprv
        self.min_stack_len_per_program = 10 * (rcs.XLEN / 8)
        self.max_stack_len_per_program = 16 * (rcs.XLEN / 8)
        self.max_branch_step = 20
        self.reserved_regs = vsc.list_t(vsc.enum_t(riscv_reg_t))
        self.enable_floating_point = self.argv.enable_floating_point
        self.enable_vector_extension = self.argv.enable_vector_extension
        self.enable_b_extension = self.argv.enable_b_extension
        self.enable_bitmanip_groups = self.argv.enable_bitmanip_groups
        self.dist_control_mode = 0
        self.category_dist = {}
        self.march_isa = self.argv.march_isa

        if len(self.march_isa) != 0:
            rcs.supported_isa = self.march_isa
        if "RV32C" not in rcs.supported_isa:
            self.disable_compressed_instr = 1
Exemple #12
0
 def __init__(self, name, def_value):
     self.name = name
     self.enum_test = vsc.rand_enum_t(level_e)
     self.value = vsc.rand_uint8_t(def_value)
Exemple #13
0
    def __init__(self):
        # ---------------------------------------------------------------------------
        # Random instruction generation settings
        # ---------------------------------------------------------------------------

        # Instruction count of the main program
        self.main_program_instr_cnt = vsc.rand_int32_t()

        # Instruction count of each sub-program
        self.sub_program_instr_cnt = []

        # Instruction count of the debug rom
        self.debug_program_instr_cnt = 0

        # Instruction count of debug sub-programs
        self.debug_sub_program_instr_cnt = []

        # Pattern of data section: RAND_DATA, ALL_ZERO, INCR_VAL
        self.data_page_pattern = vsc.rand_enum_t(data_pattern_t)

        # Initialization of the vregs
        # SAME_VALUES_ALL_ELEMS - Using vmv.v.x to fill all the elements of the vreg with
        # the same value as the one in the GPR selected
        # RANDOM_VALUES_VMV     - Using vmv.v.x + vslide1up.vx to randomize the contents
        # of each vector element
        # RANDOM_VALUES_LOAD    - Using vle.v, same approach as RANDOM_VALUES_VMV but more
        # efficient for big VLEN
        self.vreg_init_method = vreg_init_method_t.RANDOM_VALUES_VMV

        # Maximum directed instruction stream sequence count
        self.max_directed_instr_stream_seq = 20

        self.init_delegation()
        self.argv = self.parse_args()
        self.args_dict = vars(self.argv)

        global rcs
        rcs = import_module("pygen_src.target." + self.argv.target +
                            ".riscv_core_setting")

        # Dict for delegation configuration for each exception and interrupt
        # When the bit is 1, the corresponding delegation is enabled.
        # TODO
        self.m_mode_exception_delegation = {}
        self.s_mode_exception_delegation = {}
        self.m_mode_interrupt_delegation = {}
        self.s_mode_interrupt_delegation = {}

        # init_privileged_mode default to MACHINE_MODE
        # TODO: remove defult machine_mode once all modes get supported
        self.init_privileged_mode = privileged_mode_t.MACHINE_MODE

        self.mstatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.mie = vsc.rand_bit_t(rcs.XLEN - 1)
        self.sstatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.sie = vsc.rand_bit_t(rcs.XLEN - 1)
        self.ustatus = vsc.rand_bit_t(rcs.XLEN - 1)
        self.uie = vsc.rand_bit_t(rcs.XLEN - 1)

        # Key fields in xSTATUS
        # Memory protection bits
        self.mstatus_mprv = vsc.rand_bit_t(1)
        self.mstatus_mxr = vsc.rand_bit_t(1)
        self.mstatus_sum = vsc.rand_bit_t(1)
        self.mstatus_tvm = vsc.rand_bit_t(1)
        self.mstatus_fs = vsc.rand_bit_t(2)
        self.mstatus_vs = vsc.rand_bit_t(2)
        self.mtvec_mode = vsc.rand_enum_t(mtvec_mode_t)

        # TVEC alignment
        # This value is the log_2 of the byte-alignment of TVEC.BASE field
        # As per RISC-V privileged spec, default will be set to 2 (4-byte aligned)
        self.tvec_alignment = vsc.rand_uint32_t(self.argv.tvec_alignment)

        # Floating point rounding mode
        self.fcsr_rm = vsc.rand_enum_t(f_rounding_mode_t)

        # Enable sfence.vma instruction
        self.enable_sfence = vsc.rand_bit_t(1)

        # Reserved register
        # Reserved for various hardcoded routines
        self.gpr = vsc.rand_list_t(vsc.enum_t(riscv_reg_t), sz=4)

        # Used by any DCSR operations inside of the debug rom.
        # Also used by the PMP generation.
        self.scratch_reg = vsc.rand_enum_t(riscv_reg_t)

        # Reg used exclusively by the PMP exception handling routine.
        # Can overlap with the other GPRs used in the random generation,
        # as PMP exception handler is hardcoded and does not include any
        # random instructions.
        self.pmp_reg = vsc.rand_enum_t(riscv_reg_t)

        # Use a random register for stack pointer/thread pointer
        self.sp = vsc.rand_enum_t(riscv_reg_t)
        self.tp = vsc.rand_enum_t(riscv_reg_t)
        self.ra = vsc.rand_enum_t(riscv_reg_t)

        # Options for privileged mode CSR checking
        # Below checking can be made optional as the ISS implementation
        # could be different with the processor.
        self.check_misa_init_val = 0
        self.check_xstatus = 1

        # Virtual address translation is on for this test
        self.virtual_addr_translation_on = vsc.rand_bit_t(1)

        # Commenting out for now
        # vector_cfg = riscv_vector_cfg  # TODO
        # pmp_cfg = riscv_pmp_cfg  # TODO

        # Stack section word length
        self.stack_len = 5000

        # -----------------------------------------------------------------------------
        # User space memory region and stack setting
        # -----------------------------------------------------------------------------
        self.mem_region = vsc.list_t(mem_region_t())
        self.amo_region = vsc.list_t(mem_region_t())
        self.s_mem_region = vsc.list_t(mem_region_t())
        self.mem_region.extend([
            mem_region_t(name="region_0", size_in_bytes=4096, xwr=8),
            mem_region_t(name="region_1", size_in_bytes=4096, xwr=8)
        ])
        self.amo_region.extend(
            [mem_region_t(name="amo_0", size_in_bytes=64, xwr=8)])
        self.s_mem_region.extend([
            mem_region_t(name="s_region_0", size_in_bytes=4096, xwr=8),
            mem_region_t(name="s_region_1", size_in_bytes=4096, xwr=8)
        ])
        # Kernel Stack section word length
        self.kernel_stack_len = 4000

        # Number of instructions for each kernel program
        self.kernel_program_instr_cnt = 400

        # List of all the main implemented CSRs that the boot privilege mode cannot access
        # e.g. these CSRs are in higher privilege modes - access should raise an exception
        self.invalid_priv_mode_csrs = []

        # -----------------------------------------------------------------------------
        # Command line options or control knobs
        # -----------------------------------------------------------------------------
        # Main options for RISC-V assembly program generation
        # Number of sub-programs per test
        self.num_of_sub_program = self.argv.num_of_sub_program
        self.instr_cnt = self.argv.instr_cnt
        self.num_of_tests = self.argv.num_of_tests
        # For tests doesn't involve load/store, the data section generation could be skipped
        self.no_data_page = self.argv.no_data_page
        # Options to turn off some specific types of instructions
        self.no_branch_jump = self.argv.no_branch_jump  # No branch/jump instruction
        self.no_load_store = self.argv.no_load_store  # No load/store instruction
        self.no_csr_instr = self.argv.no_csr_instr  # No csr instruction
        self.no_ebreak = self.argv.no_ebreak  # No ebreak instruction
        self.no_dret = self.argv.no_dret  # No dret instruction
        self.no_fence = self.argv.no_fence  # No fence instruction
        self.no_wfi = self.argv.no_wfi  # No WFI instruction
        self.enable_unaligned_load_store = self.argv.enable_unaligned_load_store
        self.illegal_instr_ratio = self.argv.illegal_instr_ratio
        self.hint_instr_ratio = self.argv.hint_instr_ratio
        # Number of harts to be simulated, must be <= NUM_HARTS
        if self.argv.num_of_harts is None:
            self.num_of_harts = rcs.NUM_HARTS
        else:
            self.num_of_harts = self.argv.num_of_harts
        # Use SP as stack pointer
        self.fix_sp = vsc.bit_t(1)
        self.fix_sp = self.argv.fix_sp
        # Use push/pop section for data pages
        self.use_push_data_section = self.argv.use_push_data_section
        # Directed boot privileged mode, u, m, s
        self.boot_mode_opts = self.argv.boot_mode
        # self.isa = self.argv.isa
        if self.boot_mode_opts:
            logging.info("Got boot mode option - {}".format(
                self.boot_mode_opts))
            if self.boot_mode_opts == "m":
                self.init_privileged_mode = privileged_mode_t.MACHINE_MODE
            elif self.boot_mode_opts == "s":
                self.init_privileged_mode = privileged_mode_t.SUPERVISOR_MODE
            elif self.boot_mode_opts == "u":
                self.init_privileged_mode = privileged_mode_t.USER_MODE
            else:
                logging.error("Illegal boot mode option - {}".format(
                    self.boot_mode_opts))
        self.enable_page_table_exception = self.argv.enable_page_table_exception
        self.no_directed_instr = self.argv.no_directed_instr
        self.asm_test_suffix = self.argv.asm_test_suffix
        # Enable interrupt bit in MSTATUS (MIE, SIE, UIE)
        self.enable_interrupt = self.argv.enable_interrupt
        self.enable_nested_interrupt = self.argv.enable_nested_interrupt
        # We need a separate control knob for enabling timer interrupts, as Spike
        # throws an exception if xIE.xTIE is enabled
        self.enable_timer_irq = self.argv.enable_timer_irq
        # Generate a bare program without any init/exit/error handling/page table routines
        # The generated program can be integrated with a larger program.
        # Note that the bare mode program is not expected to run in standalone mode
        self.bare_program_mode = self.argv.bare_program_mode
        # Enable accessing illegal CSR instruction
        # - Accessing non-existence CSR
        # - Accessing CSR with wrong privileged mode
        self.enable_illegal_csr_instruction = self.argv.enable_illegal_csr_instruction
        # Enable accessing CSRs at an invalid privilege level
        self.enable_access_invalid_csr_level = self.argv.enable_access_invalid_csr_level
        # Enable misaligned instruction (caused by JALR instruction)
        self.enable_misaligned_instr = self.argv.enable_misaligned_instr
        # Enable some dummy writes to main system CSRs (xSTATUS/xIE) at beginning of test
        # to check repeated writes
        self.enable_dummy_csr_write = self.argv.enable_dummy_csr_write
        self.randomize_csr = self.argv.randomize_csr
        # sfence support
        self.allow_sfence_exception = self.argv.allow_sfence_exception
        # Interrupt/Exception Delegation
        self.no_delegation = self.argv.no_delegation
        self.force_m_delegation = self.argv.force_m_delegation
        self.force_s_delegation = self.argv.force_s_delegation
        self.support_supervisor_mode = 0  # TODO
        self.disable_compressed_instr = self.argv.disable_compressed_instr
        self.require_signature_addr = self.argv.require_signature_addr
        if self.require_signature_addr:
            self.signature_addr = int(self.argv.signature_addr, 16)
        else:
            self.signature_addr = 0xdeadbeef
        # Enable a full or empty debug_rom section.
        # Full debug_rom will contain random instruction streams.
        # Empty debug_rom will contain just dret instruction and will return immediately.
        # Will be empty by default.
        self.gen_debug_section = self.argv.gen_debug_section
        # Enable generation of a directed sequence of instructions containing
        # ebreak inside the debug_rom.
        # Disabled by default.
        self.enable_ebreak_in_debug_rom = self.argv.enable_ebreak_in_debug_rom
        # Enable setting dcsr.ebreak(m/s/u)
        self.set_dcsr_ebreak = self.argv.set_dcsr_ebreak
        # Number of sub programs in the debug rom
        self.num_debug_sub_program = self.argv.num_debug_sub_program
        # Enable debug single stepping
        self.enable_debug_single_step = self.argv.enable_debug_single_step
        # Number of single stepping iterations
        self.single_step_iterations = vsc.rand_uint32_t()
        # Enable mstatus.tw bit - causes u-mode WFI to raise illegal instruction exceptions
        self.set_mstatus_tw = self.argv.set_mstatus_tw
        # Enable users to set mstatus.mprv to enable privilege checks on memory accesses.
        self.set_mstatus_mprv = vsc.bit_t(1)
        self.set_mstatus_mprv = self.argv.set_mstatus_mprv
        # Stack space allocated to each program, need to be enough to store necessary context
        # Example: RA, SP, T0
        self.min_stack_len_per_program = 10 * (rcs.XLEN // 8)
        self.max_stack_len_per_program = 16 * (rcs.XLEN // 8)
        # Maximum branch distance, avoid skipping large portion of the code
        self.max_branch_step = 20
        # Reserved registers
        self.reserved_regs = vsc.list_t(vsc.enum_t(riscv_reg_t))
        # Floating point support
        self.enable_floating_point = vsc.bit_t(1)
        self.enable_floating_point = self.argv.enable_floating_point
        # Vector extension support
        self.enable_vector_extension = self.argv.enable_vector_extension
        # Only generate vector instructions
        self.vector_instr_only = vsc.bit_t(1)
        # Bit manipulation extension support
        self.enable_b_extension = self.argv.enable_b_extension
        self.enable_bitmanip_groups = self.argv.enable_bitmanip_groups

        # -----------------------------------------------------------------------------
        # Command line options for instruction distribution control
        # -----------------------------------------------------------------------------
        self.dist_control_mode = 0
        self.category_dist = {}
        self.march_isa = self.argv.march_isa

        if len(self.march_isa) != 0:
            rcs.supported_isa.append(self.march_isa)
        if riscv_instr_group_t.RV32C not in rcs.supported_isa:
            self.disable_compressed_instr = 1
        self.setup_instr_distribution()
        self.get_invalid_priv_lvl_csr()
        # Helpers fields to build the vsc constraints
        self.supported_interrupt_mode = vsc.list_t(vsc.enum_t(mtvec_mode_t))
        self.XLEN = vsc.uint32_t()
        self.SATP_MODE = vsc.enum_t(satp_mode_t)
        self.init_privil_mode = vsc.enum_t(privileged_mode_t)
        self.init_privil_mode = self.init_privileged_mode
        self.supported_interrupt_mode = rcs.supported_interrupt_mode
        self.XLEN = rcs.XLEN
        self.SATP_MODE = rcs.SATP_MODE
        self.tvec_ceil = vsc.uint32_t()
        self.tvec_ceil = math.ceil(math.log2((self.XLEN * 4) / 8))
Exemple #14
0
 def __init__(self): 
     self.a = vsc.rand_enum_t(my_e)
Exemple #15
0
 def __init__(self):
     self.a = vsc.rand_enum_t(my_e)
     self.b = vsc.enum_t(my_e)
     self.c = vsc.rand_uint8_t()
    def __init__(self):
        # TODO Support for command line argument
        self.main_program_instr_cnt = 100  # count of main_prog
        self.sub_program_instr_cnt = []  # count of sub_prog
        self.debug_program_instr_cnt = 0  # count of debug_rom
        self.debug_sub_program_instr_cnt = []  # count of debug sub_progrms
        # Commenting out for now
        # self.data_page_pattern = list(
        # map(lambda dta_pg: dta_pg.name, data_pattern_t))
        # dicts for exception_cause_t & interrupt_cause_t Enum classes

        self.m_mode_exception_delegation = {}
        self.s_mode_exception_delegation = {}
        self.m_mode_interrupt_delegation = {}
        self.s_mode_interrupt_delegation = {}

        # init_privileged_mode default to MACHINE_MODE
        self.init_privileged_mode = privileged_mode_t.MACHINE_MODE

        self.mstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.mie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.ustatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.uie = BitArray(bin(0b0), length=rcs.XLEN - 1)

        self.mstatus_mprv = 0
        self.mstatus_mxr = 0
        self.mstatus_sum = 0
        self.mstatus_tvm = 0
        self.mstatus_fs = BitArray(bin(0b0), length=2)
        self.mstatus_vs = BitArray(bin(0b0), length=2)
        self.mtvec_mode = vsc.rand_enum_t(mtvec_mode_t)

        self.tvec_alignment = 2

        self.fcsr_rm = list(map(lambda csr_rm: csr_rm.name, f_rounding_mode_t))
        self.enable_sfence = 0
        self.gpr = vsc.rand_list_t(vsc.enum_t(riscv_reg_t), sz=4)
        self.scratch_reg = vsc.rand_enum_t(riscv_reg_t)
        self.pmp_reg = vsc.rand_enum_t(riscv_reg_t)
        self.sp = vsc.rand_enum_t(riscv_reg_t)
        self.tp = vsc.rand_enum_t(riscv_reg_t)
        self.ra = vsc.rand_enum_t(riscv_reg_t)
        self.check_misa_init_val = 0
        self.check_xstatus = 1
        self.virtual_addr_translation_on = 0

        # Commenting out for now
        # vector_cfg = riscv_vector_cfg # TODO
        # pmp_cfg = riscv_pmp_cfg  # TODO
        # self.mem_region = [] # TODO
        # Self.amo_region = [] # TODO

        self.stack_len = 5000

        # Self.s_mem_region = [] # TODO

        self.kernel_stack_len = 4000
        self.kernel_program_instr_cnt = 400
        # list of main implemented CSRs
        self.invalid_priv_mode_csrs = []
        self.num_of_sub_program = 5
        self.instr_cnt = 200
        self.num_of_tests = 1
        self.no_data_page = 0
        self.no_branch_jump = 1
        self.no_load_store = 0
        self.no_csr_instr = 0
        self.no_ebreak = 1
        self.no_dret = 1
        self.no_fence = 1
        self.no_wfi = 1
        self.enable_unaligned_load_store = 0
        self.illegal_instr_ratio = 0
        self.hint_instr_ratio = 0
        self.num_of_harts = rcs.NUM_HARTS
        self.fix_sp = 0
        self.use_push_data_section = 0
        self.boot_mode_opts = ""
        self.enable_page_table_exception = 0
        self.no_directed_instr = 0
        self.asm_test_suffix = ""
        self.enable_interrupt = 0
        self.enable_nested_interrupt = 0
        self.enable_timer_irq = 0
        self.bare_program_mode = 0
        self.enable_illegal_csr_instruction = 0
        self.enable_access_invalid_csr_level = 0
        self.enable_misaligned_instr = 0
        self.enable_dummy_csr_write = 0
        self.randomize_csr = 0
        self.allow_sfence_exception = 0
        self.no_delegation = 1
        self.force_m_delegation = 0
        self.force_s_delegation = 0
        self.support_supervisor_mode = 0
        self.disable_compressed_instr = 0
        self.signature_addr = 0xdeadbeef
        self.require_signature_addr = 0
        self.gen_debug_section = 0
        self.enable_ebreak_in_debug_rom = 0
        self.set_dcsr_ebreak = 0
        self.num_debug_sub_program = 0
        self.enable_debug_single_step = 0
        self.single_step_iterations = 0
        self.set_mstatus_tw = 0
        self.set_mstatus_mprv = 0
        self.min_stack_len_per_program = 10 * (rcs.XLEN / 8)
        self.max_stack_len_per_program = 16 * (rcs.XLEN / 8)
        self.max_branch_step = 20
        self.max_directed_instr_stream_seq = 20
        self.reserved_regs = vsc.list_t(vsc.enum_t(riscv_reg_t))
        self.enable_floating_point = 0
        self.enable_vector_extension = 0
        self.enable_b_extension = 0
        # Commenting out for now
        # self.enable_bitmanip_groups = ['ZBB', 'ZBS', 'ZBP', 'ZBE', 'ZBF',
        # 'ZBC', 'ZBR', 'ZBM', 'ZBT', 'ZB_TMP']
        self.dist_control_mode = 0
        self.category_dist = {}
Exemple #17
0
 def __init__(self):
     super().__init__()
     self.a = vsc.rand_enum_t(my_e)
     self.b = vsc.rand_enum_t(my_e)
Exemple #18
0
 def __init__(self):
     self.ef = vsc.rand_enum_t(my_e)
     self.arr = vsc.rand_list_t(vsc.enum_t(my_e), 10)
 def __init__(self):
     self.b = vsc.rand_enum_t(my_e);
     self.temp = vsc.list_t(vsc.enum_t(my_e))
Exemple #20
0
 def __init__(self):
     super().__init__()
     self.process_load_store = 0
     self.format = riscv_instr_format_t.I_FORMAT
     self.pseudo_instr_name = vsc.rand_enum_t(riscv_pseudo_instr_name_t)
 def __init__(self):
     super().__init__()
     self.rs3 = vsc.rand_enum_t(riscv_reg_t)
     self.has_rs3 = vsc.bit_t(1)
Exemple #22
0
    def __init__(self, argv):
        # TODO Support for command line argument
        self.main_program_instr_cnt = 100  # count of main_prog
        self.sub_program_instr_cnt = []  # count of sub_prog
        self.debug_program_instr_cnt = 0  # count of debug_rom
        self.debug_sub_program_instr_cnt = []  # count of debug sub_progrms
        # Commenting out for now
        # self.data_page_pattern = list(
        # map(lambda dta_pg: dta_pg.name, data_pattern_t))
        # dicts for exception_cause_t & interrupt_cause_t Enum classes

        self.m_mode_exception_delegation = {}
        self.s_mode_exception_delegation = {}
        self.m_mode_interrupt_delegation = {}
        self.s_mode_interrupt_delegation = {}

        # init_privileged_mode default to MACHINE_MODE
        self.init_privileged_mode = privileged_mode_t.MACHINE_MODE

        self.mstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.mie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.ustatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.uie = BitArray(bin(0b0), length=rcs.XLEN - 1)

        self.mstatus_mprv = 0
        self.mstatus_mxr = 0
        self.mstatus_sum = 0
        self.mstatus_tvm = 0
        self.mstatus_fs = BitArray(bin(0b0), length=2)
        self.mstatus_vs = BitArray(bin(0b0), length=2)
        self.mtvec_mode = vsc.rand_enum_t(mtvec_mode_t)

        self.tvec_alignment = argv.tvec_alignment

        self.fcsr_rm = list(map(lambda csr_rm: csr_rm.name, f_rounding_mode_t))
        self.enable_sfence = 0
        self.gpr = []

        # Helper fields for gpr
        self.gpr0 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr1 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr2 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr3 = vsc.rand_enum_t(riscv_reg_t)

        self.scratch_reg = vsc.rand_enum_t(riscv_reg_t)
        self.pmp_reg = vsc.rand_enum_t(riscv_reg_t)
        self.sp = vsc.rand_enum_t(riscv_reg_t)
        self.tp = vsc.rand_enum_t(riscv_reg_t)
        self.ra = vsc.rand_enum_t(riscv_reg_t)
        self.check_misa_init_val = 0
        self.check_xstatus = 1
        self.virtual_addr_translation_on = 0

        # Commenting out for now
        # vector_cfg = riscv_vector_cfg # TODO
        # pmp_cfg = riscv_pmp_cfg  # TODO
        # self.mem_region = [] # TODO
        # Self.amo_region = [] # TODO

        self.stack_len = 5000

        # Self.s_mem_region = [] # TODO

        self.kernel_stack_len = 4000
        self.kernel_program_instr_cnt = 400
        # list of main implemented CSRs
        self.invalid_priv_mode_csrs = []
        self.num_of_sub_program = argv.num_of_sub_program
        self.instr_cnt = argv.instr_cnt
        self.num_of_tests = argv.num_of_tests
        self.no_data_page = argv.no_data_page
        self.no_branch_jump = argv.no_branch_jump
        self.no_load_store = argv.no_load_store
        self.no_csr_instr = argv.no_csr_instr
        self.no_ebreak = argv.no_ebreak
        self.no_dret = argv.no_dret
        self.no_fence = argv.no_fence
        self.no_wfi = argv.no_wfi
        self.enable_unaligned_load_store = argv.enable_unaligned_load_store
        self.illegal_instr_ratio = argv.illegal_instr_ratio
        self.hint_instr_ratio = argv.hint_instr_ratio
        self.num_of_harts = argv.num_of_harts
        self.fix_sp = argv.fix_sp
        self.use_push_data_section = argv.use_push_data_section
        self.boot_mode_opts = argv.boot_mode_opts

        if(self.boot_mode_opts):
            logging.info("Got boot mode option - %0s", self.boot_mode_opts)
            if(self.boot_mode_opts == "m"):
                self.init_privileged_mode = privileged_mode_t.MACHINE_MODE.name
            elif(self.boot_mode_opts == "s"):
                self.init_privileged_mode = privileged_mode_t.SUPERVISOR_MODE.name
            elif(self.boot_mode_opts == "u"):
                self.init_privileged_mode = privileged_mode_t.USER_MODE.name
            else:
                logging.error("Illegal boot mode option - %0s", self.boot_mode_opts)

        self.enable_page_table_exception = argv.enable_page_table_exception
        self.no_directed_instr = argv.no_directed_instr
        self.asm_test_suffix = argv.asm_test_suffix
        self.enable_interrupt = argv.enable_interrupt
        self.enable_nested_interrupt = argv.enable_nested_interrupt
        self.enable_timer_irq = argv.enable_timer_irq
        self.bare_program_mode = argv.bare_program_mode
        self.enable_illegal_csr_instruction = argv.enable_illegal_csr_instruction
        self.enable_access_invalid_csr_level = argv.enable_access_invalid_csr_level
        self.enable_misaligned_instr = argv.enable_misaligned_instr
        self.enable_dummy_csr_write = argv.enable_dummy_csr_write
        self.randomize_csr = argv.randomize_csr
        self.allow_sfence_exception = argv.allow_sfence_exception
        self.no_delegation = argv.no_delegation
        self.force_m_delegation = argv.force_m_delegation
        self.force_s_delegation = argv.force_s_delegation
        self.support_supervisor_mode = 0
        self.disable_compressed_instr = argv.disable_compressed_instr
        self.require_signature_addr = argv.require_signature_addr

        if(self.require_signature_addr):
            self.signature_addr = int(argv.signature_addr, 16)
        else:
            self.signature_addr = 0xdeadbeef

        self.gen_debug_section = argv.gen_debug_section
        self.enable_ebreak_in_debug_rom = argv.enable_ebreak_in_debug_rom
        self.set_dcsr_ebreak = argv.set_dcsr_ebreak
        self.num_debug_sub_program = argv.num_debug_sub_program
        self.enable_debug_single_step = argv.enable_debug_single_step
        self.single_step_iterations = 0
        self.set_mstatus_tw = argv.set_mstatus_tw
        self.set_mstatus_mprv = argv.set_mstatus_mprv
        self.min_stack_len_per_program = 10 * (rcs.XLEN / 8)
        self.max_stack_len_per_program = 16 * (rcs.XLEN / 8)
        self.max_branch_step = 20
        self.max_directed_instr_stream_seq = 20
        self.reserved_regs = vsc.list_t(vsc.enum_t(riscv_reg_t))
        self.enable_floating_point = argv.enable_floating_point
        self.enable_vector_extension = argv.enable_vector_extension
        self.enable_b_extension = argv.enable_b_extension
        self.enable_bitmanip_groups = argv.enable_bitmanip_groups
        self.dist_control_mode = 0
        self.category_dist = {}
        self.march_isa = argv.march_isa

        if(len(self.march_isa) != 0):
            rcs.supported_isa = self.march_isa

        if(rcs.supported_isa != 'RV32C'):
            self.disable_compressed_instr = 1
Exemple #23
0
 def __init__(self):
     self.num = vsc.rand_bit_t(8)
     self.level = vsc.rand_enum_t(level_t)
     self.addr = []
     self.offset = []