SubBlock.hh revision 11049
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"
376145Snate@binkert.org
387039Snate@binkert.orgclass SubBlock
397039Snate@binkert.org{
407039Snate@binkert.org  public:
417039Snate@binkert.org    SubBlock() { }
4211025Snilay@cs.wisc.edu    SubBlock(Addr addr, int size);
437039Snate@binkert.org    ~SubBlock() { }
446145Snate@binkert.org
4511025Snilay@cs.wisc.edu    Addr getAddress() const { return m_address; }
4611025Snilay@cs.wisc.edu    void setAddress(Addr addr) { m_address = addr; }
476145Snate@binkert.org
487039Snate@binkert.org    int getSize() const { return m_data.size(); }
497454Snate@binkert.org    void resize(int size) {  m_data.resize(size); }
509208Snilay@cs.wisc.edu    uint8_t getByte(int offset) const { return m_data[offset]; }
519208Snilay@cs.wisc.edu    void setByte(int offset, uint8_t data) { m_data[offset] = data; }
526145Snate@binkert.org
537039Snate@binkert.org    // Shorthands
549208Snilay@cs.wisc.edu    uint8_t readByte() const { return getByte(0); }
559208Snilay@cs.wisc.edu    void writeByte(uint8_t data) { setByte(0, data); }
566145Snate@binkert.org
577039Snate@binkert.org    // Merging to and from DataBlocks - We only need to worry about
587039Snate@binkert.org    // updates when we are using DataBlocks
5911049Snilay@cs.wisc.edu    void mergeTo(DataBlock& data) const { internalMergeTo(data); }
6011049Snilay@cs.wisc.edu    void mergeFrom(const DataBlock& data) { internalMergeFrom(data); }
616145Snate@binkert.org
627055Snate@binkert.org    void print(std::ostream& out) const;
636145Snate@binkert.org
647039Snate@binkert.org  private:
6511049Snilay@cs.wisc.edu    void internalMergeTo(DataBlock& data) const;
6611049Snilay@cs.wisc.edu    void internalMergeFrom(const DataBlock& data);
6711049Snilay@cs.wisc.edu
687039Snate@binkert.org    // Data Members (m_ prefix)
6911025Snilay@cs.wisc.edu    Addr m_address;
707454Snate@binkert.org    std::vector<uint8_t> m_data;
716145Snate@binkert.org};
726145Snate@binkert.org
737055Snate@binkert.orginline std::ostream&
747055Snate@binkert.orgoperator<<(std::ostream& out, const SubBlock& obj)
756145Snate@binkert.org{
767039Snate@binkert.org    obj.print(out);
777055Snate@binkert.org    out << std::flush;
787039Snate@binkert.org    return out;
796145Snate@binkert.org}
806145Snate@binkert.org
817039Snate@binkert.org#endif // __MEM_RUBY_COMMON_SUBBLOCK_HH__
82