void ScrDB::Read(TARGETING::TargetHandle_t i_ptargetHandle, BitString & bs, uint64_t registerId) { //PRDF_DENTER( "ScrDB::Read() huid: 0x%X, addr: 0x%016X", // getHuid(i_ptargetHandle), registerId ); DataList data; unsigned int dataWordSize = bs.getBitLen()/32; dataWordSize += (bs.getBitLen() % 32) ? 1 : 0; // if the register has a predetermined value than get it if(pChipset.find(i_ptargetHandle) != pChipset.end()) { PreScrMap pscrmap = pChipset[i_ptargetHandle]; if(pscrmap.find(registerId) != pscrmap.end()) // we must have a predetermined value { SimScrDataSet pValues = pscrmap[registerId]; data = pValues.GetData(); // get next set of values // pValues has changed - copy it back pscrmap[registerId] = pValues; pChipset[i_ptargetHandle] = pscrmap; } } if(data.size() == 0) // use the last value written to this reg { // get a copy of the scrMap for this chip - if one does not exist it will be created ScrMap scrMap = chipset[i_ptargetHandle]; // get a copy of the data for this address from the scrMap for this chip // if data structure does not exist, it will be created, but will be empty data = scrMap[registerId]; if(data.size() == 0) // This is the first time this register has been accessed { while(data.size() < dataWordSize) data.push_back(0); // zero fill scrMap[registerId] = data; chipset[i_ptargetHandle] = scrMap; // update the persistent copy of the scrMap } } if(0 != data.size()) { for(unsigned int i = 0; i < data.size(); ++i) { bs.setFieldJustify((i*32), 32, data[i]); } PRDF_TRAC( "ScrDB::Read() huid: %X, addr: %016X, data: %08X %08X", getHuid(i_ptargetHandle), registerId, data[0], 2 == data.size() ? data[1] : 0 ); } //PRDF_DEXIT( "ScrDB::Read()" ); }
void BitString::setString( const BitString & i_sStr, uint32_t i_sPos, uint32_t i_sLen, uint32_t i_dPos ) { // Ensure the source parameters are valid. PRDF_ASSERT( nullptr != i_sStr.getBufAddr() ); PRDF_ASSERT( 0 < i_sLen ); // at least one bit to copy PRDF_ASSERT( i_sPos + i_sLen <= i_sStr.getBitLen() ); // Ensure the destination has at least one bit available to copy. PRDF_ASSERT( nullptr != getBufAddr() ); PRDF_ASSERT( i_dPos < getBitLen() ); // If the source length is greater than the destination length than the // extra source bits are ignored. uint32_t actLen = std::min( i_sLen, getBitLen() - i_dPos ); // The bit strings may be in overlapping memory spaces. So we need to copy // the data in the correct direction to prevent overlapping. uint32_t sRelOffset = 0, dRelOffset = 0; CPU_WORD * sRelAddr = i_sStr.getRelativePosition( sRelOffset, i_sPos ); CPU_WORD * dRelAddr = getRelativePosition( dRelOffset, i_dPos ); // Copy the data. if ( (dRelAddr == sRelAddr) && (dRelOffset == sRelOffset) ) { // Do nothing. The source and destination are the same. } else if ( (dRelAddr < sRelAddr) || ((dRelAddr == sRelAddr) && (dRelOffset < sRelOffset)) ) { // Copy the data forward. for ( uint32_t pos = 0; pos < actLen; pos += CPU_WORD_BIT_LEN ) { uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN ); CPU_WORD value = i_sStr.getField( i_sPos + pos, len ); setField( i_dPos + pos, len, value ); } } else // Copy the data backwards. { // Get the first position of the last chunk (CPU_WORD aligned). uint32_t lastPos = ((actLen-1) / CPU_WORD_BIT_LEN) * CPU_WORD_BIT_LEN; // Start with the last chunk and work backwards. for ( int32_t pos = lastPos; 0 <= pos; pos -= CPU_WORD_BIT_LEN ) { uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN ); CPU_WORD value = i_sStr.getField( i_sPos + pos, len ); setField( i_dPos + pos, len, value ); } } }
bool BitString::isEqual( const BitString & i_str ) const { if ( getBitLen() != i_str.getBitLen() ) return false; // size not equal for ( uint32_t pos = 0; pos < getBitLen(); pos += CPU_WORD_BIT_LEN ) { uint32_t len = std::min( getBitLen() - pos, CPU_WORD_BIT_LEN ); if ( getField(pos, len) != i_str.getField(pos, len) ) return false; // bit strings do not match } return true; // bit strings match }
void BitString::maskString( const BitString & i_mask ) { // Get the length of the smallest string. uint32_t actLen = std::min( getBitLen(), i_mask.getBitLen() ); for ( uint32_t pos = 0; pos < actLen; pos += CPU_WORD_BIT_LEN ) { uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN ); CPU_WORD dVal = getField( pos, len ); CPU_WORD sVal = i_mask.getField( pos, len ); setField( pos, len, dVal & ~sVal ); } }
BitStringBuffer BitString::operator|( const BitString & i_bs ) const { // Get the length of the smallest string. uint32_t actLen = std::min( getBitLen(), i_bs.getBitLen() ); BitStringBuffer bsb( actLen ); for ( uint32_t pos = 0; pos < actLen; pos += CPU_WORD_BIT_LEN ) { uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN ); CPU_WORD dVal = getField( pos, len ); CPU_WORD sVal = i_bs.getField( pos, len ); bsb.setField( pos, len, dVal | sVal ); } return bsb; }
void ScrDB::Write(TARGETING::TargetHandle_t i_ptargetHandle, BitString & bs, uint64_t registerId) { PRDF_TRAC( "ScrDB::Write() huid: %X, addr: %016X, data: %08X %08X", getHuid(i_ptargetHandle), registerId, bs.getFieldJustify(0,32), bs.getFieldJustify(32,32) ); unsigned int dataWordSize = bs.getBitLen()/32; // PRDF_TRAC("dataWordSize1: %d", dataWordSize); dataWordSize += (bs.getBitLen() % 32) ? 1 : 0; // PRDF_TRAC("dataWordSize2: %d", dataWordSize); DataList data; // parse all data given data.push_back(bs.getFieldJustify(0,32)); data.push_back(bs.getFieldJustify(32,32)); // PRDF_TRAC("parse all data given"); // look for expected data DataList expectedData; if(eChipset.find(i_ptargetHandle) != eChipset.end()) { PRDF_TRAC("found target"); PreScrMap escrmap = eChipset[i_ptargetHandle]; if(escrmap.find(registerId) != escrmap.end()) // we have expected data value { PRDF_TRAC("found scom reg"); SimScrDataSet eValues = escrmap[registerId]; expectedData = eValues.GetData(); // get next set of values escrmap[registerId] = eValues; eChipset[i_ptargetHandle] = escrmap; } } if(expectedData.size() > 0) { if((expectedData[0] != data[0]) || (expectedData[1] != data[1])) { PRDF_ERR("Verify SC register: %p", i_ptargetHandle); PRDF_ERR(" Address: 0x%016X", registerId); PRDF_ERR("SCR write Actual : %08X %08X", data[0], data[1]); PRDF_ERR("SCR write Expected: %08X %08X", expectedData[0], expectedData[1]); } else { PRDF_TRAC("Verify SC register: %p", i_ptargetHandle); PRDF_TRAC(" Address: 0x%016X", registerId); PRDF_TRAC("SCR write Actual: %08X %08X", data[0], data[1]); } } // PRDF_TRAC("get a copy"); // get a copy of the scrMap for this chip - if one does not exist it will be created ScrMap scrMap = chipset[i_ptargetHandle]; // PRDF_TRAC("update register value"); // update register value scrMap[registerId] = data; // copy the supplied value to the register // PRDF_TRAC("update the master"); chipset[i_ptargetHandle] = scrMap; // scrMap is only a copy so must update the master //PRDF_EXIT( "ScrDB::Write()" ); }