SubBlock.hh revision 7039
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297039Snate@binkert.org#ifndef __MEM_RUBY_COMMON_SUBBLOCK_HH__ 307039Snate@binkert.org#define __MEM_RUBY_COMMON_SUBBLOCK_HH__ 316145Snate@binkert.org 327039Snate@binkert.org#include "mem/gems_common/Vector.hh" 336154Snate@binkert.org#include "mem/ruby/common/Address.hh" 346154Snate@binkert.org#include "mem/ruby/common/DataBlock.hh" 357039Snate@binkert.org#include "mem/ruby/common/Global.hh" 366145Snate@binkert.org 377039Snate@binkert.orgclass SubBlock 387039Snate@binkert.org{ 397039Snate@binkert.org public: 407039Snate@binkert.org SubBlock() { } 417039Snate@binkert.org SubBlock(const Address& addr, int size); 427039Snate@binkert.org ~SubBlock() { } 436145Snate@binkert.org 447039Snate@binkert.org const Address& getAddress() const { return m_address; } 457039Snate@binkert.org void setAddress(const Address& addr) { m_address = addr; } 466145Snate@binkert.org 477039Snate@binkert.org int getSize() const { return m_data.size(); } 487039Snate@binkert.org void setSize(int size) { m_data.setSize(size); } 497039Snate@binkert.org uint8 getByte(int offset) const { return m_data[offset]; } 507039Snate@binkert.org void setByte(int offset, uint8 data) { m_data[offset] = data; } 516145Snate@binkert.org 527039Snate@binkert.org // Shorthands 537039Snate@binkert.org uint8 readByte() const { return getByte(0); } 547039Snate@binkert.org void writeByte(uint8 data) { setByte(0, data); } 556145Snate@binkert.org 567039Snate@binkert.org // Merging to and from DataBlocks - We only need to worry about 577039Snate@binkert.org // updates when we are using DataBlocks 587039Snate@binkert.org void mergeTo(DataBlock& data) const { internalMergeTo(data); } 597039Snate@binkert.org void mergeFrom(const DataBlock& data) { internalMergeFrom(data); } 606145Snate@binkert.org 617039Snate@binkert.org void print(ostream& out) const; 626145Snate@binkert.org 637039Snate@binkert.org private: 647039Snate@binkert.org void internalMergeTo(DataBlock& data) const; 657039Snate@binkert.org void internalMergeFrom(const DataBlock& data); 666145Snate@binkert.org 677039Snate@binkert.org // Data Members (m_ prefix) 687039Snate@binkert.org Address m_address; 697039Snate@binkert.org Vector<uint8_t> m_data; 706145Snate@binkert.org}; 716145Snate@binkert.org 727039Snate@binkert.orginline ostream& 737039Snate@binkert.orgoperator<<(ostream& out, const SubBlock& obj) 746145Snate@binkert.org{ 757039Snate@binkert.org obj.print(out); 767039Snate@binkert.org out << flush; 777039Snate@binkert.org return out; 786145Snate@binkert.org} 796145Snate@binkert.org 807039Snate@binkert.org#endif // __MEM_RUBY_COMMON_SUBBLOCK_HH__ 81