DataBlock.cc revision 10563
17008Snate@binkert.org/* 27008Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 37008Snate@binkert.org * All rights reserved. 47008Snate@binkert.org * 57008Snate@binkert.org * Redistribution and use in source and binary forms, with or without 67008Snate@binkert.org * modification, are permitted provided that the following conditions are 77008Snate@binkert.org * met: redistributions of source code must retain the above copyright 87008Snate@binkert.org * notice, this list of conditions and the following disclaimer; 97008Snate@binkert.org * redistributions in binary form must reproduce the above copyright 107008Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 117008Snate@binkert.org * documentation and/or other materials provided with the distribution; 127008Snate@binkert.org * neither the name of the copyright holders nor the names of its 137008Snate@binkert.org * contributors may be used to endorse or promote products derived from 147008Snate@binkert.org * this software without specific prior written permission. 157008Snate@binkert.org * 167008Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177008Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187008Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197008Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207008Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217008Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227008Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237008Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247008Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257008Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267008Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277008Snate@binkert.org */ 286285Snate@binkert.org 296285Snate@binkert.org#include "mem/ruby/common/DataBlock.hh" 306285Snate@binkert.org#include "mem/ruby/system/System.hh" 316285Snate@binkert.org 326285Snate@binkert.orgDataBlock::DataBlock(const DataBlock &cp) 336285Snate@binkert.org{ 346467Sdrh5@cs.wisc.edu m_data = new uint8_t[RubySystem::getBlockSizeBytes()]; 356467Sdrh5@cs.wisc.edu memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes()); 366285Snate@binkert.org m_alloc = true; 376285Snate@binkert.org} 386888SBrad.Beckmann@amd.com 396888SBrad.Beckmann@amd.comvoid 406888SBrad.Beckmann@amd.comDataBlock::alloc() 416888SBrad.Beckmann@amd.com{ 426876Ssteve.reinhardt@amd.com m_data = new uint8_t[RubySystem::getBlockSizeBytes()]; 436876Ssteve.reinhardt@amd.com m_alloc = true; 446285Snate@binkert.org clear(); 456285Snate@binkert.org} 466285Snate@binkert.org 476876Ssteve.reinhardt@amd.comvoid 486285Snate@binkert.orgDataBlock::clear() 496888SBrad.Beckmann@amd.com{ 506285Snate@binkert.org memset(m_data, 0, RubySystem::getBlockSizeBytes()); 516368Sdrh5@cs.wisc.edu} 526285Snate@binkert.org 536285Snate@binkert.orgbool 546922SBrad.Beckmann@amd.comDataBlock::equal(const DataBlock& obj) const 556285Snate@binkert.org{ 566285Snate@binkert.org return !memcmp(m_data, obj.m_data, RubySystem::getBlockSizeBytes()); 576285Snate@binkert.org} 586285Snate@binkert.org 596285Snate@binkert.orgvoid 606285Snate@binkert.orgDataBlock::print(std::ostream& out) const 616285Snate@binkert.org{ 626285Snate@binkert.org using namespace std; 636285Snate@binkert.org 646285Snate@binkert.org int size = RubySystem::getBlockSizeBytes(); 656285Snate@binkert.org out << "[ "; 666285Snate@binkert.org for (int i = 0; i < size; i++) { 676285Snate@binkert.org out << setw(2) << setfill('0') << hex << "0x" << (int)m_data[i] << " "; 686285Snate@binkert.org out << setfill(' '); 696350Spdudnik@gmail.com } 706350Spdudnik@gmail.com out << dec << "]" << flush; 716355Spdudnik@gmail.com} 726355Spdudnik@gmail.com 736433Sdrh5@cs.wisc.educonst uint8_t* 746922SBrad.Beckmann@amd.comDataBlock::getData(int offset, int len) const 756922SBrad.Beckmann@amd.com{ 766285Snate@binkert.org assert(offset + len <= RubySystem::getBlockSizeBytes()); 776285Snate@binkert.org return &m_data[offset]; 786368Sdrh5@cs.wisc.edu} 796285Snate@binkert.org 806285Snate@binkert.orgvoid 816285Snate@binkert.orgDataBlock::setData(const uint8_t *data, int offset, int len) 826285Snate@binkert.org{ 836285Snate@binkert.org assert(offset + len <= RubySystem::getBlockSizeBytes()); 846285Snate@binkert.org memcpy(&m_data[offset], data, len); 856285Snate@binkert.org} 866285Snate@binkert.org 876922SBrad.Beckmann@amd.comDataBlock & 886285Snate@binkert.orgDataBlock::operator=(const DataBlock & obj) 896467Sdrh5@cs.wisc.edu{ 906285Snate@binkert.org memcpy(m_data, obj.m_data, RubySystem::getBlockSizeBytes()); 916368Sdrh5@cs.wisc.edu return *this; 926467Sdrh5@cs.wisc.edu} 936467Sdrh5@cs.wisc.edu