SubBlock.hh revision 9208
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
327055Snate@binkert.org#include <iostream>
337454Snate@binkert.org#include <vector>
347055Snate@binkert.org
356154Snate@binkert.org#include "mem/ruby/common/Address.hh"
366154Snate@binkert.org#include "mem/ruby/common/DataBlock.hh"
377039Snate@binkert.org#include "mem/ruby/common/Global.hh"
386145Snate@binkert.org
397039Snate@binkert.orgclass SubBlock
407039Snate@binkert.org{
417039Snate@binkert.org  public:
427039Snate@binkert.org    SubBlock() { }
437039Snate@binkert.org    SubBlock(const Address& addr, int size);
447039Snate@binkert.org    ~SubBlock() { }
456145Snate@binkert.org
467039Snate@binkert.org    const Address& getAddress() const { return m_address; }
477039Snate@binkert.org    void setAddress(const Address& addr) { m_address = addr; }
486145Snate@binkert.org
497039Snate@binkert.org    int getSize() const { return m_data.size(); }
507454Snate@binkert.org    void resize(int size) {  m_data.resize(size); }
519208Snilay@cs.wisc.edu    uint8_t getByte(int offset) const { return m_data[offset]; }
529208Snilay@cs.wisc.edu    void setByte(int offset, uint8_t data) { m_data[offset] = data; }
536145Snate@binkert.org
547039Snate@binkert.org    // Shorthands
559208Snilay@cs.wisc.edu    uint8_t readByte() const { return getByte(0); }
569208Snilay@cs.wisc.edu    void writeByte(uint8_t data) { setByte(0, data); }
576145Snate@binkert.org
587039Snate@binkert.org    // Merging to and from DataBlocks - We only need to worry about
597039Snate@binkert.org    // updates when we are using DataBlocks
607039Snate@binkert.org    void mergeTo(DataBlock& data) const { internalMergeTo(data); }
617039Snate@binkert.org    void mergeFrom(const DataBlock& data) { internalMergeFrom(data); }
626145Snate@binkert.org
637055Snate@binkert.org    void print(std::ostream& out) const;
646145Snate@binkert.org
657039Snate@binkert.org  private:
667039Snate@binkert.org    void internalMergeTo(DataBlock& data) const;
677039Snate@binkert.org    void internalMergeFrom(const DataBlock& data);
686145Snate@binkert.org
697039Snate@binkert.org    // Data Members (m_ prefix)
707039Snate@binkert.org    Address m_address;
717454Snate@binkert.org    std::vector<uint8_t> m_data;
726145Snate@binkert.org};
736145Snate@binkert.org
747055Snate@binkert.orginline std::ostream&
757055Snate@binkert.orgoperator<<(std::ostream& out, const SubBlock& obj)
766145Snate@binkert.org{
777039Snate@binkert.org    obj.print(out);
787055Snate@binkert.org    out << std::flush;
797039Snate@binkert.org    return out;
806145Snate@binkert.org}
816145Snate@binkert.org
827039Snate@binkert.org#endif // __MEM_RUBY_COMMON_SUBBLOCK_HH__
83