Esempio n. 1
0
    def _createState(self):
        state = State()

        # The priorities are set in such a way as to enable floating point before loading the
        # floating point registers
        expected_sys_reg_state_data = []
        sys_reg_name = 'misa'
        (sys_reg_val, valid) = self.readRegister(sys_reg_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, sys_reg_name, valid)

        sys_reg_val |= 0x0000028
        state.addRegisterStateElement(sys_reg_name, (sys_reg_val, ),
                                      aPriority=1)
        expected_sys_reg_state_data.append((sys_reg_name, sys_reg_val))
        self._mExpectedStateData[
            EStateElementType.SystemRegister] = expected_sys_reg_state_data

        self._mExpectedStateData[
            EStateElementType.
            FloatingPointRegister] = state_transition_test_utils.addRandomFloatingPointRegisterStateElements(
                self,
                state,
                RandomUtils.random32(0, 10),
                aPriorityMin=2,
                aPriorityMax=4)

        return state
Esempio n. 2
0
    def _createVectorRegisterStateElements(self, aState):
        expected_vec_reg_state_data = {}

        vec_reg_count = RandomUtils.random32(0, 10)
        vec_reg_indices = self.sample(range(0, 32), vec_reg_count)
        max_reg_val_count = self.getLimitValue('MaxPhysicalVectorLen') // 64
        for vec_reg_index in vec_reg_indices:
            vec_reg_values = []

            state_elem_reg_val_count = RandomUtils.random32(
                1, max_reg_val_count)
            for val_index in range(state_elem_reg_val_count):
                vec_reg_values.append(RandomUtils.random64())

            vec_reg_name = 'v%d' % vec_reg_index
            self.randomInitializeRegister(vec_reg_name)
            aState.addRegisterStateElement(vec_reg_name, vec_reg_values)

            for val_index in range(state_elem_reg_val_count,
                                   max_reg_val_count):
                field_name = '%s_%d' % (vec_reg_name, val_index)
                (field_val, valid) = self.readRegister(vec_reg_name,
                                                       field=field_name)
                state_transition_test_utils.assertValidRegisterValue(
                    self, vec_reg_name, valid)
                vec_reg_values.append(field_val)

            expected_vec_reg_state_data[vec_reg_name] = vec_reg_values

        return expected_vec_reg_state_data
Esempio n. 3
0
    def _createStateC(self):
        state = State()

        self._mExpectedStateData = {}

        expected_sys_reg_state_data = []

        fcsr_name = 'fcsr'
        state.addSystemRegisterStateElementByField(fcsr_name, 'FRM', 1)
        (fcsr_val, valid) = self.readRegister(fcsr_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, fcsr_name, valid)
        fcsr_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, fcsr_name, fcsr_val, 'FRM', 1)

        # TODO(Noah): Enable verification of setting the fcsr register when the readRegister()
        # method reads the correct value for fcsr. Currently, the top 58 bits are being initialized
        # to a non-zero value by Force, which is not legal.
        #expected_sys_reg_state_data.append((fcsr_name, fcsr_val))

        expected_fp_reg_state_data = []
        for fp_reg_index in range(0, 32):
            fp_reg_val = RandomUtils.random64(0, 0x3FFFFFFFFFFFFFFF)
            state.addRegisterStateElement(('D%d' % fp_reg_index),
                                          (fp_reg_val, ))

        self._mExpectedStateData[
            EStateElementType.
            FloatingPointRegister] = expected_fp_reg_state_data

        sstatus_name = 'sstatus'
        fs_val = RandomUtils.random32(1, 3)
        state.addSystemRegisterStateElementByField(sstatus_name, 'FS', fs_val)
        (sstatus_val, valid) = self.readRegister(sstatus_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, sstatus_name, valid)
        sstatus_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, sstatus_name, sstatus_val, 'FS', fs_val)

        # Adjust expected value of SD bit according to architecture rules
        (xs_val, valid) = self.readRegister(sstatus_name, field='XS')
        state_transition_test_utils.assertValidRegisterValue(
            self, sstatus_name, valid)
        (vs_val, valid) = self.readRegister(sstatus_name, field='VS')
        state_transition_test_utils.assertValidRegisterValue(
            self, sstatus_name, valid)
        if (fs_val == 3) or (xs_val == 3) or (vs_val == 3):
            sstatus_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
                self, sstatus_name, sstatus_val, 'SD', 1)
        else:
            sstatus_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
                self, sstatus_name, sstatus_val, 'SD', 0)

        expected_sys_reg_state_data.append((sstatus_name, sstatus_val))

        self._mExpectedStateData[
            EStateElementType.SystemRegister] = expected_sys_reg_state_data

        return state
Esempio n. 4
0
    def _createSystemRegisterStateElements(self, aState):
        sys_reg_name = 'mstatus'
        aState.addSystemRegisterStateElementByField(sys_reg_name, 'MIE', 0x0)
        aState.addSystemRegisterStateElementByField(sys_reg_name, 'MPRV', 0x1)

        self.randomInitializeRegister(sys_reg_name)
        (sys_reg_val, valid) = self.readRegister(sys_reg_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, sys_reg_name, valid)

        sys_reg_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, sys_reg_name, sys_reg_val, 'MIE', 0x0)
        sys_reg_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, sys_reg_name, sys_reg_val, 'MPRV', 0x1)

        return {sys_reg_name: sys_reg_val}
Esempio n. 5
0
    def _createState(self):
        state = State()

        expected_sys_reg_state_data = []

        mcause_name = 'mcause'
        exception_code_var_val = RandomUtils.random32(0, 9)
        state.addSystemRegisterStateElementByField(mcause_name,
                                                   'EXCEPTION CODE_VAR',
                                                   exception_code_var_val)
        self.randomInitializeRegister(mcause_name)
        (mcause_val, valid) = self.readRegister(mcause_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, mcause_name, valid)
        mcause_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, mcause_name, mcause_val, 'EXCEPTION CODE_VAR',
            exception_code_var_val)
        expected_sys_reg_state_data.append((mcause_name, mcause_val))

        mtvec_name = 'mtvec'
        mode_val = RandomUtils.random32(0, 1)
        state.addSystemRegisterStateElementByField('mtvec', 'MODE', mode_val)
        self.randomInitializeRegister(mtvec_name)
        (mtvec_val, valid) = self.readRegister(mtvec_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, mtvec_name, valid)
        mtvec_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, mtvec_name, mtvec_val, 'MODE', mode_val)
        expected_sys_reg_state_data.append((mtvec_name, mtvec_val))

        self._mExpectedStateData[
            EStateElementType.SystemRegister] = expected_sys_reg_state_data

        self._mExpectedStateData[
            EStateElementType.
            GPR] = state_transition_test_utils.addRandomGprStateElements(
                self, state, RandomUtils.random32(0, 5))
        self._mExpectedStateData[
            EStateElementType.
            PC] = state_transition_test_utils.addRandomPcStateElement(
                self, state)

        return state
Esempio n. 6
0
    def generate(self, **kargs):
        # Disable floating point, so the StateTransition can enable it
        sys_reg_name = 'misa'
        (sys_reg_val, valid) = self.readRegister(sys_reg_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, sys_reg_name, valid)

        load_gpr64_seq = LoadGPR64(self.genThread)
        rand_gpr_index = self.getRandomGPR(exclude='0')
        load_gpr64_seq.load(rand_gpr_index, 0x0000028)
        self.genInstruction(
            'CSRRC#register#RISCV', {
                'rd': 0,
                'rs1': rand_gpr_index,
                'csr': self.getRegisterIndex(sys_reg_name)
            })

        state = self._createState()
        StateTransition.transitionToState(state,
                                          EStateTransitionOrderMode.ByPriority)

        state_transition_test_utils.verifyState(self, self._mExpectedStateData)
Esempio n. 7
0
    def _createState(self):
        state = State()

        expected_sys_reg_state_data = []

        mscratch_val = RandomUtils.random64()
        state.addRegisterStateElement('mscratch', (mscratch_val, ))
        expected_sys_reg_state_data.append(('mscratch', mscratch_val))

        scause_name = 'scause'
        exception_code_var_val = RandomUtils.random32(0, 9)
        state.addSystemRegisterStateElementByField(scause_name,
                                                   'EXCEPTION CODE_VAR',
                                                   exception_code_var_val)
        self.randomInitializeRegister(scause_name)
        (scause_val, valid) = self.readRegister(scause_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, scause_name, valid)
        scause_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, scause_name, scause_val, 'EXCEPTION CODE_VAR',
            exception_code_var_val)
        expected_sys_reg_state_data.append((scause_name, scause_val))

        stvec_name = 'stvec'
        mode_val = RandomUtils.random32(0, 1)
        state.addSystemRegisterStateElementByField(stvec_name, 'MODE',
                                                   mode_val)
        self.randomInitializeRegister(stvec_name)
        (stvec_val, valid) = self.readRegister(stvec_name)
        state_transition_test_utils.assertValidRegisterValue(
            self, stvec_name, valid)
        stvec_val = state_transition_test_utils.combineRegisterValueWithFieldValue(
            self, stvec_name, stvec_val, 'MODE', mode_val)
        expected_sys_reg_state_data.append((stvec_name, stvec_val))

        self._mExpectedStateData[
            EStateElementType.SystemRegister] = expected_sys_reg_state_data

        return state
Esempio n. 8
0
    def _createFloatingPointRegisterStateElements(self, aState):
        expected_fp_reg_state_data = {}

        fp_reg_count = RandomUtils.random32(0, 10)
        fp_reg_indices = self.sample(range(0, 32), fp_reg_count)
        for fp_reg_index in fp_reg_indices:
            fp_reg_name = 'S%d' % fp_reg_index
            fp_reg_val = RandomUtils.random32()
            aState.addRegisterStateElement(fp_reg_name, (fp_reg_val, ))

            containing_fp_reg_name = 'D%d' % fp_reg_index
            self.randomInitializeRegister(containing_fp_reg_name)
            (orig_fp_reg_val,
             valid) = self.readRegister(containing_fp_reg_name)
            state_transition_test_utils.assertValidRegisterValue(
                self, containing_fp_reg_name, valid)

            combined_fp_reg_val = (orig_fp_reg_val &
                                   (0xFFFFFFFF << 32)) | fp_reg_val
            expected_fp_reg_state_data[
                containing_fp_reg_name] = combined_fp_reg_val

        return expected_fp_reg_state_data