packet.cc revision 2641
12568SN/A/*
22568SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32568SN/A * All rights reserved.
42568SN/A *
52568SN/A * Redistribution and use in source and binary forms, with or without
62568SN/A * modification, are permitted provided that the following conditions are
72568SN/A * met: redistributions of source code must retain the above copyright
82568SN/A * notice, this list of conditions and the following disclaimer;
92568SN/A * redistributions in binary form must reproduce the above copyright
102568SN/A * notice, this list of conditions and the following disclaimer in the
112568SN/A * documentation and/or other materials provided with the distribution;
122568SN/A * neither the name of the copyright holders nor the names of its
132568SN/A * contributors may be used to endorse or promote products derived from
142568SN/A * this software without specific prior written permission.
152568SN/A *
162568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272568SN/A */
282568SN/A
292568SN/A/**
302568SN/A * @file
312568SN/A * Definition of the Packet Class, a packet is a transaction occuring
322568SN/A * between a single level of the memory heirarchy (ie L1->L2).
332568SN/A */
342590SN/A#include "base/misc.hh"
352568SN/A#include "mem/packet.hh"
362568SN/A
372641Sstever@eecs.umich.edustatic const std::string ReadReqString("ReadReq");
382641Sstever@eecs.umich.edustatic const std::string WriteReqString("WriteReq");
392641Sstever@eecs.umich.edustatic const std::string WriteReqNoAckString("WriteReqNoAck");
402641Sstever@eecs.umich.edustatic const std::string ReadRespString("ReadResp");
412641Sstever@eecs.umich.edustatic const std::string WriteRespString("WriteResp");
422641Sstever@eecs.umich.edustatic const std::string OtherCmdString("<other>");
432641Sstever@eecs.umich.edu
442641Sstever@eecs.umich.educonst std::string &
452641Sstever@eecs.umich.eduPacket::cmdString() const
462641Sstever@eecs.umich.edu{
472641Sstever@eecs.umich.edu    switch (cmd) {
482641Sstever@eecs.umich.edu      case ReadReq:         return ReadReqString;
492641Sstever@eecs.umich.edu      case WriteReq:        return WriteReqString;
502641Sstever@eecs.umich.edu      case WriteReqNoAck:   return WriteReqNoAckString;
512641Sstever@eecs.umich.edu      case ReadResp:        return ReadRespString;
522641Sstever@eecs.umich.edu      case WriteResp:       return WriteRespString;
532641Sstever@eecs.umich.edu      default:              return OtherCmdString;
542641Sstever@eecs.umich.edu    }
552641Sstever@eecs.umich.edu}
562592SN/A
572592SN/A/** delete the data pointed to in the data pointer. Ok to call to matter how
582592SN/A * data was allocted. */
592592SN/Avoid
602641Sstever@eecs.umich.eduPacket::deleteData()
612641Sstever@eecs.umich.edu{
622592SN/A    assert(staticData || dynamicData);
632592SN/A    if (staticData)
642592SN/A        return;
652592SN/A
662592SN/A    if (arrayData)
672592SN/A        delete [] data;
682592SN/A    else
692592SN/A        delete data;
702592SN/A}
712592SN/A
722592SN/A/** If there isn't data in the packet, allocate some. */
732592SN/Avoid
742641Sstever@eecs.umich.eduPacket::allocate()
752641Sstever@eecs.umich.edu{
762592SN/A    if (data)
772592SN/A        return;
782592SN/A    assert(!staticData);
792592SN/A    dynamicData = true;
802592SN/A    arrayData = true;
812641Sstever@eecs.umich.edu    data = new uint8_t[getSize()];
822592SN/A}
832592SN/A
842592SN/A/** Do the packet modify the same addresses. */
852592SN/Abool
862641Sstever@eecs.umich.eduPacket::intersect(Packet *p)
872641Sstever@eecs.umich.edu{
882641Sstever@eecs.umich.edu    Addr s1 = getAddr();
892641Sstever@eecs.umich.edu    Addr e1 = getAddr() + getSize();
902641Sstever@eecs.umich.edu    Addr s2 = p->getAddr();
912641Sstever@eecs.umich.edu    Addr e2 = p->getAddr() + p->getSize();
922592SN/A
932592SN/A    if (s1 >= s2 && s1 < e2)
942592SN/A        return true;
952592SN/A    if (e1 >= s2 && e1 < e2)
962592SN/A        return true;
972592SN/A    return false;
982592SN/A}
992592SN/A
1002592SN/A/** Minimally reset a packet so something like simple cpu can reuse it. */
1012592SN/Avoid
1022641Sstever@eecs.umich.eduPacket::reset()
1032641Sstever@eecs.umich.edu{
1042592SN/A    result = Unknown;
1052592SN/A    if (dynamicData) {
1062592SN/A       deleteData();
1072592SN/A       dynamicData = false;
1082592SN/A       arrayData = false;
1092592SN/A       time = curTick;
1102592SN/A    }
1112592SN/A}
1122592SN/A
1132592SN/A
1142641Sstever@eecs.umich.edubool
1152641Sstever@eecs.umich.edufixPacket(Packet *func, Packet *timing)
1162641Sstever@eecs.umich.edu{
1172641Sstever@eecs.umich.edu    panic("Need to implement!");
1182641Sstever@eecs.umich.edu}
119