16288Snate@binkert.org/* 26288Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36288Snate@binkert.org * All rights reserved. 46288Snate@binkert.org * 56288Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66288Snate@binkert.org * modification, are permitted provided that the following conditions are 76288Snate@binkert.org * met: redistributions of source code must retain the above copyright 86288Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96288Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106288Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116288Snate@binkert.org * documentation and/or other materials provided with the distribution; 126288Snate@binkert.org * neither the name of the copyright holders nor the names of its 136288Snate@binkert.org * contributors may be used to endorse or promote products derived from 146288Snate@binkert.org * this software without specific prior written permission. 156288Snate@binkert.org * 166288Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176288Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186288Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196288Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206288Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216288Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226288Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236288Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246288Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256288Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266288Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276288Snate@binkert.org */ 286145Snate@binkert.org 296154Snate@binkert.org#include "mem/ruby/common/DataBlock.hh" 3011307Santhony.gutierrez@amd.com 3111307Santhony.gutierrez@amd.com#include "mem/ruby/common/WriteMask.hh" 3211108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 338090Snilay@cs.wisc.edu 348090Snilay@cs.wisc.eduDataBlock::DataBlock(const DataBlock &cp) 358090Snilay@cs.wisc.edu{ 369208Snilay@cs.wisc.edu m_data = new uint8_t[RubySystem::getBlockSizeBytes()]; 378090Snilay@cs.wisc.edu memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes()); 388090Snilay@cs.wisc.edu m_alloc = true; 398090Snilay@cs.wisc.edu} 408090Snilay@cs.wisc.edu 418090Snilay@cs.wisc.eduvoid 428090Snilay@cs.wisc.eduDataBlock::alloc() 438090Snilay@cs.wisc.edu{ 449208Snilay@cs.wisc.edu m_data = new uint8_t[RubySystem::getBlockSizeBytes()]; 458090Snilay@cs.wisc.edu m_alloc = true; 468090Snilay@cs.wisc.edu clear(); 478090Snilay@cs.wisc.edu} 488090Snilay@cs.wisc.edu 498090Snilay@cs.wisc.eduvoid 508090Snilay@cs.wisc.eduDataBlock::clear() 518090Snilay@cs.wisc.edu{ 528090Snilay@cs.wisc.edu memset(m_data, 0, RubySystem::getBlockSizeBytes()); 538090Snilay@cs.wisc.edu} 548090Snilay@cs.wisc.edu 558090Snilay@cs.wisc.edubool 568090Snilay@cs.wisc.eduDataBlock::equal(const DataBlock& obj) const 578090Snilay@cs.wisc.edu{ 588090Snilay@cs.wisc.edu return !memcmp(m_data, obj.m_data, RubySystem::getBlockSizeBytes()); 598090Snilay@cs.wisc.edu} 608090Snilay@cs.wisc.edu 618090Snilay@cs.wisc.eduvoid 6211307Santhony.gutierrez@amd.comDataBlock::copyPartial(const DataBlock &dblk, const WriteMask &mask) 6311307Santhony.gutierrez@amd.com{ 6411307Santhony.gutierrez@amd.com for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) { 6511307Santhony.gutierrez@amd.com if (mask.getMask(i, 1)) { 6611307Santhony.gutierrez@amd.com m_data[i] = dblk.m_data[i]; 6711307Santhony.gutierrez@amd.com } 6811307Santhony.gutierrez@amd.com } 6911307Santhony.gutierrez@amd.com} 7011307Santhony.gutierrez@amd.com 7111307Santhony.gutierrez@amd.comvoid 7211307Santhony.gutierrez@amd.comDataBlock::atomicPartial(const DataBlock &dblk, const WriteMask &mask) 7311307Santhony.gutierrez@amd.com{ 7411307Santhony.gutierrez@amd.com for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) { 7511307Santhony.gutierrez@amd.com m_data[i] = dblk.m_data[i]; 7611307Santhony.gutierrez@amd.com } 7711307Santhony.gutierrez@amd.com mask.performAtomic(m_data); 7811307Santhony.gutierrez@amd.com} 7911307Santhony.gutierrez@amd.com 8011307Santhony.gutierrez@amd.comvoid 818090Snilay@cs.wisc.eduDataBlock::print(std::ostream& out) const 828090Snilay@cs.wisc.edu{ 838090Snilay@cs.wisc.edu using namespace std; 848090Snilay@cs.wisc.edu 858090Snilay@cs.wisc.edu int size = RubySystem::getBlockSizeBytes(); 868090Snilay@cs.wisc.edu out << "[ "; 878090Snilay@cs.wisc.edu for (int i = 0; i < size; i++) { 888090Snilay@cs.wisc.edu out << setw(2) << setfill('0') << hex << "0x" << (int)m_data[i] << " "; 898090Snilay@cs.wisc.edu out << setfill(' '); 908090Snilay@cs.wisc.edu } 918090Snilay@cs.wisc.edu out << dec << "]" << flush; 928090Snilay@cs.wisc.edu} 938090Snilay@cs.wisc.edu 949208Snilay@cs.wisc.educonst uint8_t* 958090Snilay@cs.wisc.eduDataBlock::getData(int offset, int len) const 968090Snilay@cs.wisc.edu{ 978090Snilay@cs.wisc.edu assert(offset + len <= RubySystem::getBlockSizeBytes()); 988090Snilay@cs.wisc.edu return &m_data[offset]; 998090Snilay@cs.wisc.edu} 1008090Snilay@cs.wisc.edu 10111307Santhony.gutierrez@amd.comuint8_t* 10211307Santhony.gutierrez@amd.comDataBlock::getDataMod(int offset) 10311307Santhony.gutierrez@amd.com{ 10411307Santhony.gutierrez@amd.com return &m_data[offset]; 10511307Santhony.gutierrez@amd.com} 10611307Santhony.gutierrez@amd.com 1078090Snilay@cs.wisc.eduvoid 10810563Sandreas.hansson@arm.comDataBlock::setData(const uint8_t *data, int offset, int len) 1098090Snilay@cs.wisc.edu{ 1108090Snilay@cs.wisc.edu assert(offset + len <= RubySystem::getBlockSizeBytes()); 1118090Snilay@cs.wisc.edu memcpy(&m_data[offset], data, len); 1128090Snilay@cs.wisc.edu} 1136145Snate@binkert.org 1146285Snate@binkert.orgDataBlock & 1156285Snate@binkert.orgDataBlock::operator=(const DataBlock & obj) 1166145Snate@binkert.org{ 1179181Spower.jg@gmail.com memcpy(m_data, obj.m_data, RubySystem::getBlockSizeBytes()); 1187039Snate@binkert.org return *this; 1196145Snate@binkert.org} 120