packet.cc revision 10885
12568SN/A/*
210723Sandreas.hansson@arm.com * Copyright (c) 2011-2015 ARM Limited
38668Sgeoffrey.blake@arm.com * All rights reserved
48668Sgeoffrey.blake@arm.com *
58668Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall
68668Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual
78668Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating
88668Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software
98668Sgeoffrey.blake@arm.com * licensed hereunder.  You may use the software subject to the license
108668Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated
118668Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software,
128668Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form.
138668Sgeoffrey.blake@arm.com *
142568SN/A * Copyright (c) 2006 The Regents of The University of Michigan
157636Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
162568SN/A * All rights reserved.
172568SN/A *
182568SN/A * Redistribution and use in source and binary forms, with or without
192568SN/A * modification, are permitted provided that the following conditions are
202568SN/A * met: redistributions of source code must retain the above copyright
212568SN/A * notice, this list of conditions and the following disclaimer;
222568SN/A * redistributions in binary form must reproduce the above copyright
232568SN/A * notice, this list of conditions and the following disclaimer in the
242568SN/A * documentation and/or other materials provided with the distribution;
252568SN/A * neither the name of the copyright holders nor the names of its
262568SN/A * contributors may be used to endorse or promote products derived from
272568SN/A * this software without specific prior written permission.
282568SN/A *
292568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
432568SN/A */
442568SN/A
452568SN/A/**
462568SN/A * @file
472568SN/A * Definition of the Packet Class, a packet is a transaction occuring
482568SN/A * between a single level of the memory heirarchy (ie L1->L2).
492568SN/A */
503260Ssaidi@eecs.umich.edu
518229Snate@binkert.org#include <cstring>
523260Ssaidi@eecs.umich.edu#include <iostream>
538229Snate@binkert.org
545314Sstever@gmail.com#include "base/cprintf.hh"
552590SN/A#include "base/misc.hh"
563348Sbinkertn@umich.edu#include "base/trace.hh"
572568SN/A#include "mem/packet.hh"
582568SN/A
595735Snate@binkert.orgusing namespace std;
605735Snate@binkert.org
614022Sstever@eecs.umich.edu// The one downside to bitsets is that static initializers can get ugly.
624022Sstever@eecs.umich.edu#define SET1(a1)                     (1 << (a1))
634022Sstever@eecs.umich.edu#define SET2(a1, a2)                 (SET1(a1) | SET1(a2))
644022Sstever@eecs.umich.edu#define SET3(a1, a2, a3)             (SET2(a1, a2) | SET1(a3))
654022Sstever@eecs.umich.edu#define SET4(a1, a2, a3, a4)         (SET3(a1, a2, a3) | SET1(a4))
664022Sstever@eecs.umich.edu#define SET5(a1, a2, a3, a4, a5)     (SET4(a1, a2, a3, a4) | SET1(a5))
674022Sstever@eecs.umich.edu#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
682641Sstever@eecs.umich.edu
694022Sstever@eecs.umich.educonst MemCmd::CommandInfo
704022Sstever@eecs.umich.eduMemCmd::commandInfo[] =
712641Sstever@eecs.umich.edu{
724022Sstever@eecs.umich.edu    /* InvalidCmd */
734022Sstever@eecs.umich.edu    { 0, InvalidCmd, "InvalidCmd" },
7410885Sandreas.hansson@arm.com    /* ReadReq - Read issued by a non-caching agent such as a CPU or
7510885Sandreas.hansson@arm.com     * device, with no restrictions on alignment. */
764022Sstever@eecs.umich.edu    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
774473Sstever@eecs.umich.edu    /* ReadResp */
784473Sstever@eecs.umich.edu    { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
795319Sstever@gmail.com    /* ReadRespWithInvalidate */
805319Sstever@gmail.com    { SET4(IsRead, IsResponse, HasData, IsInvalidate),
815319Sstever@gmail.com            InvalidCmd, "ReadRespWithInvalidate" },
824022Sstever@eecs.umich.edu    /* WriteReq */
834626Sstever@eecs.umich.edu    { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
844022Sstever@eecs.umich.edu            WriteResp, "WriteReq" },
854022Sstever@eecs.umich.edu    /* WriteResp */
864626Sstever@eecs.umich.edu    { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
874022Sstever@eecs.umich.edu    /* Writeback */
884628Sstever@eecs.umich.edu    { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
894628Sstever@eecs.umich.edu            InvalidCmd, "Writeback" },
9010883Sali.jafri@arm.com    /* CleanEvict */
9110883Sali.jafri@arm.com    { SET2(IsWrite, IsRequest), InvalidCmd, "CleanEvict" },
924022Sstever@eecs.umich.edu    /* SoftPFReq */
934022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
944022Sstever@eecs.umich.edu            SoftPFResp, "SoftPFReq" },
954022Sstever@eecs.umich.edu    /* HardPFReq */
964022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
974022Sstever@eecs.umich.edu            HardPFResp, "HardPFReq" },
984022Sstever@eecs.umich.edu    /* SoftPFResp */
994022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
1004022Sstever@eecs.umich.edu            InvalidCmd, "SoftPFResp" },
1014022Sstever@eecs.umich.edu    /* HardPFResp */
1024022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
1034022Sstever@eecs.umich.edu            InvalidCmd, "HardPFResp" },
10410345SCurtis.Dunham@arm.com    /* WriteInvalidateReq */
1054626Sstever@eecs.umich.edu    { SET6(IsWrite, NeedsExclusive, IsInvalidate,
1064626Sstever@eecs.umich.edu           IsRequest, HasData, NeedsResponse),
1074022Sstever@eecs.umich.edu            WriteInvalidateResp, "WriteInvalidateReq" },
10810345SCurtis.Dunham@arm.com    /* WriteInvalidateResp */
1095319Sstever@gmail.com    { SET3(IsWrite, NeedsExclusive, IsResponse),
1104022Sstever@eecs.umich.edu            InvalidCmd, "WriteInvalidateResp" },
1114022Sstever@eecs.umich.edu    /* UpgradeReq */
1127465Ssteve.reinhardt@amd.com    { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
1134628Sstever@eecs.umich.edu            UpgradeResp, "UpgradeReq" },
1147465Ssteve.reinhardt@amd.com    /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
1157465Ssteve.reinhardt@amd.com    { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
1167465Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse),
1177465Ssteve.reinhardt@amd.com            UpgradeResp, "SCUpgradeReq" },
1184628Sstever@eecs.umich.edu    /* UpgradeResp */
1197465Ssteve.reinhardt@amd.com    { SET3(NeedsExclusive, IsUpgrade, IsResponse),
1207465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeResp" },
12110325Sgeoffrey.blake@arm.com    /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
12210325Sgeoffrey.blake@arm.com    { SET6(IsRead, NeedsExclusive, IsInvalidate,
12310325Sgeoffrey.blake@arm.com           IsLlsc, IsRequest, NeedsResponse),
1247465Ssteve.reinhardt@amd.com            UpgradeFailResp, "SCUpgradeFailReq" },
12510325Sgeoffrey.blake@arm.com    /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
12610325Sgeoffrey.blake@arm.com     * that it has failed, acquires line as Dirty*/
12710325Sgeoffrey.blake@arm.com    { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
1287465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeFailResp" },
12910885Sandreas.hansson@arm.com    /* ReadExReq - Read issues by a cache, always cache-line aligned,
13010885Sandreas.hansson@arm.com     * and the response is guaranteed to be writeable (exclusive or
13110885Sandreas.hansson@arm.com     * even modified) */
1324626Sstever@eecs.umich.edu    { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
1334022Sstever@eecs.umich.edu            ReadExResp, "ReadExReq" },
13410885Sandreas.hansson@arm.com    /* ReadExResp - Response matching a read exclusive, as we check
13510885Sandreas.hansson@arm.com     * the need for exclusive also on responses */
1365319Sstever@gmail.com    { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
1374040Ssaidi@eecs.umich.edu            InvalidCmd, "ReadExResp" },
13810885Sandreas.hansson@arm.com    /* ReadCleanReq - Read issued by a cache, always cache-line
13910885Sandreas.hansson@arm.com     * aligned, and the response is guaranteed to not contain dirty data
14010885Sandreas.hansson@arm.com     * (exclusive or shared).*/
14110885Sandreas.hansson@arm.com    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadCleanReq" },
14210885Sandreas.hansson@arm.com    /* ReadSharedReq - Read issued by a cache, always cache-line
14310885Sandreas.hansson@arm.com     * aligned, response is shared, possibly exclusive, owned or even
14410885Sandreas.hansson@arm.com     * modified. */
14510885Sandreas.hansson@arm.com    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadSharedReq" },
1465507Sstever@gmail.com    /* LoadLockedReq: note that we use plain ReadResp as response, so that
1475507Sstever@gmail.com     *                we can also use ReadRespWithInvalidate when needed */
1486076Sgblack@eecs.umich.edu    { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
1495507Sstever@gmail.com            ReadResp, "LoadLockedReq" },
1504626Sstever@eecs.umich.edu    /* StoreCondReq */
1516076Sgblack@eecs.umich.edu    { SET6(IsWrite, NeedsExclusive, IsLlsc,
1524626Sstever@eecs.umich.edu           IsRequest, NeedsResponse, HasData),
1534626Sstever@eecs.umich.edu            StoreCondResp, "StoreCondReq" },
15410325Sgeoffrey.blake@arm.com    /* StoreCondFailReq: generates failing StoreCondResp */
1557669Ssteve.reinhardt@amd.com    { SET6(IsWrite, NeedsExclusive, IsLlsc,
1567669Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse, HasData),
1577669Ssteve.reinhardt@amd.com            StoreCondResp, "StoreCondFailReq" },
1584626Sstever@eecs.umich.edu    /* StoreCondResp */
1596076Sgblack@eecs.umich.edu    { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
1604626Sstever@eecs.umich.edu            InvalidCmd, "StoreCondResp" },
1614040Ssaidi@eecs.umich.edu    /* SwapReq -- for Swap ldstub type operations */
1624626Sstever@eecs.umich.edu    { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
1634040Ssaidi@eecs.umich.edu        SwapResp, "SwapReq" },
1644040Ssaidi@eecs.umich.edu    /* SwapResp -- for Swap ldstub type operations */
1654626Sstever@eecs.umich.edu    { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
1664870Sstever@eecs.umich.edu            InvalidCmd, "SwapResp" },
1675650Sgblack@eecs.umich.edu    /* IntReq -- for interrupts */
1685650Sgblack@eecs.umich.edu    { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
1696063Sgblack@eecs.umich.edu        MessageResp, "MessageReq" },
1705650Sgblack@eecs.umich.edu    /* IntResp -- for interrupts */
1716063Sgblack@eecs.umich.edu    { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
1724870Sstever@eecs.umich.edu    /* InvalidDestError  -- packet dest field invalid */
1734986Ssaidi@eecs.umich.edu    { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
1744870Sstever@eecs.umich.edu    /* BadAddressError   -- memory address invalid */
1755314Sstever@gmail.com    { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
1768436SBrad.Beckmann@amd.com    /* FunctionalReadError */
1778436SBrad.Beckmann@amd.com    { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
1788436SBrad.Beckmann@amd.com    /* FunctionalWriteError */
1798436SBrad.Beckmann@amd.com    { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
1805314Sstever@gmail.com    /* PrintReq */
1818184Ssomayeh@cs.wisc.edu    { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
1828184Ssomayeh@cs.wisc.edu    /* Flush Request */
1838436SBrad.Beckmann@amd.com    { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
1848716Snilay@cs.wisc.edu    /* Invalidation Request */
1858716Snilay@cs.wisc.edu    { SET3(NeedsExclusive, IsInvalidate, IsRequest),
1868716Snilay@cs.wisc.edu      InvalidCmd, "InvalidationReq" },
1874022Sstever@eecs.umich.edu};
1882592SN/A
1893607Srdreslin@umich.edubool
19010028SGiacomo.Gabrielli@arm.comPacket::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
19110570Sandreas.hansson@arm.com                        uint8_t *_data)
1922641Sstever@eecs.umich.edu{
1934626Sstever@eecs.umich.edu    Addr func_start = getAddr();
1944626Sstever@eecs.umich.edu    Addr func_end   = getAddr() + getSize() - 1;
1954626Sstever@eecs.umich.edu    Addr val_start  = addr;
1964626Sstever@eecs.umich.edu    Addr val_end    = val_start + size - 1;
1973260Ssaidi@eecs.umich.edu
19810028SGiacomo.Gabrielli@arm.com    if (is_secure != _isSecure || func_start > val_end ||
19910028SGiacomo.Gabrielli@arm.com        val_start > func_end) {
2004626Sstever@eecs.umich.edu        // no intersection
2014626Sstever@eecs.umich.edu        return false;
2024626Sstever@eecs.umich.edu    }
2033260Ssaidi@eecs.umich.edu
2045314Sstever@gmail.com    // check print first since it doesn't require data
2055314Sstever@gmail.com    if (isPrint()) {
20610570Sandreas.hansson@arm.com        assert(!_data);
20710376Sandreas.hansson@arm.com        safe_cast<PrintReqState*>(senderState)->printObj(obj);
2085314Sstever@gmail.com        return false;
2095314Sstever@gmail.com    }
2105314Sstever@gmail.com
21110570Sandreas.hansson@arm.com    // we allow the caller to pass NULL to signify the other packet
21210570Sandreas.hansson@arm.com    // has no data
21310570Sandreas.hansson@arm.com    if (!_data) {
2145314Sstever@gmail.com        return false;
2155314Sstever@gmail.com    }
2165314Sstever@gmail.com
2174626Sstever@eecs.umich.edu    // offset of functional request into supplied value (could be
2184626Sstever@eecs.umich.edu    // negative if partial overlap)
2194626Sstever@eecs.umich.edu    int offset = func_start - val_start;
2203260Ssaidi@eecs.umich.edu
2214626Sstever@eecs.umich.edu    if (isRead()) {
2224626Sstever@eecs.umich.edu        if (func_start >= val_start && func_end <= val_end) {
22310570Sandreas.hansson@arm.com            memcpy(getPtr<uint8_t>(), _data + offset, getSize());
22410723Sandreas.hansson@arm.com            if (bytesValid.empty())
22510723Sandreas.hansson@arm.com                bytesValid.resize(getSize(), true);
22610570Sandreas.hansson@arm.com            // complete overlap, and as the current packet is a read
22710570Sandreas.hansson@arm.com            // we are done
2284626Sstever@eecs.umich.edu            return true;
2293260Ssaidi@eecs.umich.edu        } else {
2308668Sgeoffrey.blake@arm.com            // Offsets and sizes to copy in case of partial overlap
2318668Sgeoffrey.blake@arm.com            int func_offset;
2328668Sgeoffrey.blake@arm.com            int val_offset;
2338668Sgeoffrey.blake@arm.com            int overlap_size;
2348668Sgeoffrey.blake@arm.com
2358668Sgeoffrey.blake@arm.com            // calculate offsets and copy sizes for the two byte arrays
2368668Sgeoffrey.blake@arm.com            if (val_start < func_start && val_end <= func_end) {
23710723Sandreas.hansson@arm.com                // the one we are checking against starts before and
23810723Sandreas.hansson@arm.com                // ends before or the same
2398668Sgeoffrey.blake@arm.com                val_offset = func_start - val_start;
2408668Sgeoffrey.blake@arm.com                func_offset = 0;
2418668Sgeoffrey.blake@arm.com                overlap_size = val_end - func_start;
2428668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end > func_end) {
24310723Sandreas.hansson@arm.com                // the one we are checking against starts after or the
24410723Sandreas.hansson@arm.com                // same, and ends after
2458668Sgeoffrey.blake@arm.com                val_offset = 0;
2468668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2478668Sgeoffrey.blake@arm.com                overlap_size = func_end - val_start;
2488668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end <= func_end) {
24910723Sandreas.hansson@arm.com                // the one we are checking against is completely
25010723Sandreas.hansson@arm.com                // subsumed in the current packet, possibly starting
25110723Sandreas.hansson@arm.com                // and ending at the same address
2528668Sgeoffrey.blake@arm.com                val_offset = 0;
2538668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2548668Sgeoffrey.blake@arm.com                overlap_size = size;
25510723Sandreas.hansson@arm.com            } else if (val_start < func_start && val_end > func_end) {
25610723Sandreas.hansson@arm.com                // the current packet is completely subsumed in the
25710723Sandreas.hansson@arm.com                // one we are checking against
25810723Sandreas.hansson@arm.com                val_offset = func_start - val_start;
25910723Sandreas.hansson@arm.com                func_offset = 0;
26010723Sandreas.hansson@arm.com                overlap_size = func_end - func_start;
2618668Sgeoffrey.blake@arm.com            } else {
26210723Sandreas.hansson@arm.com                panic("Missed a case for checkFunctional with "
26310723Sandreas.hansson@arm.com                      " %s 0x%x size %d, against 0x%x size %d\n",
26410723Sandreas.hansson@arm.com                      cmdString(), getAddr(), getSize(), addr, size);
2658668Sgeoffrey.blake@arm.com            }
2668668Sgeoffrey.blake@arm.com
2678668Sgeoffrey.blake@arm.com            // copy partial data into the packet's data array
2688668Sgeoffrey.blake@arm.com            uint8_t *dest = getPtr<uint8_t>() + func_offset;
26910570Sandreas.hansson@arm.com            uint8_t *src = _data + val_offset;
2708668Sgeoffrey.blake@arm.com            memcpy(dest, src, overlap_size);
2718668Sgeoffrey.blake@arm.com
27210723Sandreas.hansson@arm.com            // initialise the tracking of valid bytes if we have not
27310723Sandreas.hansson@arm.com            // used it already
27410723Sandreas.hansson@arm.com            if (bytesValid.empty())
27510723Sandreas.hansson@arm.com                bytesValid.resize(getSize(), false);
27610723Sandreas.hansson@arm.com
27710723Sandreas.hansson@arm.com            // track if we are done filling the functional access
27810723Sandreas.hansson@arm.com            bool all_bytes_valid = true;
27910723Sandreas.hansson@arm.com
28010723Sandreas.hansson@arm.com            int i = 0;
28110723Sandreas.hansson@arm.com
28210723Sandreas.hansson@arm.com            // check up to func_offset
28310723Sandreas.hansson@arm.com            for (; all_bytes_valid && i < func_offset; ++i)
28410723Sandreas.hansson@arm.com                all_bytes_valid &= bytesValid[i];
28510723Sandreas.hansson@arm.com
28610723Sandreas.hansson@arm.com            // update the valid bytes
28710723Sandreas.hansson@arm.com            for (i = func_offset; i < func_offset + overlap_size; ++i)
28810723Sandreas.hansson@arm.com                bytesValid[i] = true;
28910723Sandreas.hansson@arm.com
29010723Sandreas.hansson@arm.com            // check the bit after the update we just made
29110723Sandreas.hansson@arm.com            for (; all_bytes_valid && i < getSize(); ++i)
29210723Sandreas.hansson@arm.com                all_bytes_valid &= bytesValid[i];
29310723Sandreas.hansson@arm.com
29410723Sandreas.hansson@arm.com            return all_bytes_valid;
2953260Ssaidi@eecs.umich.edu        }
2964626Sstever@eecs.umich.edu    } else if (isWrite()) {
2974626Sstever@eecs.umich.edu        if (offset >= 0) {
29810570Sandreas.hansson@arm.com            memcpy(_data + offset, getConstPtr<uint8_t>(),
2995735Snate@binkert.org                   (min(func_end, val_end) - func_start) + 1);
3005735Snate@binkert.org        } else {
3015735Snate@binkert.org            // val_start > func_start
30210570Sandreas.hansson@arm.com            memcpy(_data, getConstPtr<uint8_t>() - offset,
3035735Snate@binkert.org                   (min(func_end, val_end) - val_start) + 1);
3043260Ssaidi@eecs.umich.edu        }
3055314Sstever@gmail.com    } else {
3064626Sstever@eecs.umich.edu        panic("Don't know how to handle command %s\n", cmdString());
3075314Sstever@gmail.com    }
3085314Sstever@gmail.com
3095314Sstever@gmail.com    // keep going with request by default
3105314Sstever@gmail.com    return false;
3112641Sstever@eecs.umich.edu}
3123260Ssaidi@eecs.umich.edu
3135314Sstever@gmail.comvoid
3149542Sandreas.hansson@arm.comPacket::pushSenderState(Packet::SenderState *sender_state)
3159542Sandreas.hansson@arm.com{
3169542Sandreas.hansson@arm.com    assert(sender_state != NULL);
3179542Sandreas.hansson@arm.com    sender_state->predecessor = senderState;
3189542Sandreas.hansson@arm.com    senderState = sender_state;
3199542Sandreas.hansson@arm.com}
3209542Sandreas.hansson@arm.com
3219542Sandreas.hansson@arm.comPacket::SenderState *
3229542Sandreas.hansson@arm.comPacket::popSenderState()
3239542Sandreas.hansson@arm.com{
3249542Sandreas.hansson@arm.com    assert(senderState != NULL);
3259542Sandreas.hansson@arm.com    SenderState *sender_state = senderState;
3269542Sandreas.hansson@arm.com    senderState = sender_state->predecessor;
3279542Sandreas.hansson@arm.com    sender_state->predecessor = NULL;
3289542Sandreas.hansson@arm.com    return sender_state;
3299542Sandreas.hansson@arm.com}
3309542Sandreas.hansson@arm.com
3319542Sandreas.hansson@arm.comvoid
3325735Snate@binkert.orgPacket::print(ostream &o, const int verbosity, const string &prefix) const
3333260Ssaidi@eecs.umich.edu{
3345314Sstever@gmail.com    ccprintf(o, "%s[%x:%x] %s\n", prefix,
3355314Sstever@gmail.com             getAddr(), getAddr() + getSize() - 1, cmdString());
3363260Ssaidi@eecs.umich.edu}
3373260Ssaidi@eecs.umich.edu
3389663Suri.wiener@arm.comstd::string
3399663Suri.wiener@arm.comPacket::print() const {
3409663Suri.wiener@arm.com    ostringstream str;
3419663Suri.wiener@arm.com    print(str);
3429663Suri.wiener@arm.com    return str.str();
3439663Suri.wiener@arm.com}
3449663Suri.wiener@arm.com
3455735Snate@binkert.orgPacket::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
3465735Snate@binkert.org    : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
3475314Sstever@gmail.com{
3485314Sstever@gmail.com    labelStack.push_back(LabelStackEntry("", curPrefixPtr));
3495314Sstever@gmail.com}
3505314Sstever@gmail.com
3515314Sstever@gmail.comPacket::PrintReqState::~PrintReqState()
3525314Sstever@gmail.com{
3535314Sstever@gmail.com    labelStack.pop_back();
3545314Sstever@gmail.com    assert(labelStack.empty());
3555314Sstever@gmail.com    delete curPrefixPtr;
3565314Sstever@gmail.com}
3575314Sstever@gmail.com
3585314Sstever@gmail.comPacket::PrintReqState::
3595735Snate@binkert.orgLabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
3605314Sstever@gmail.com    : label(_label), prefix(_prefix), labelPrinted(false)
3615314Sstever@gmail.com{
3625314Sstever@gmail.com}
3635314Sstever@gmail.com
3645314Sstever@gmail.comvoid
3655735Snate@binkert.orgPacket::PrintReqState::pushLabel(const string &lbl, const string &prefix)
3665314Sstever@gmail.com{
3675314Sstever@gmail.com    labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
3685735Snate@binkert.org    curPrefixPtr = new string(*curPrefixPtr);
3695314Sstever@gmail.com    *curPrefixPtr += prefix;
3705314Sstever@gmail.com}
3715314Sstever@gmail.com
3725314Sstever@gmail.comvoid
3735314Sstever@gmail.comPacket::PrintReqState::popLabel()
3745314Sstever@gmail.com{
3755314Sstever@gmail.com    delete curPrefixPtr;
3765314Sstever@gmail.com    curPrefixPtr = labelStack.back().prefix;
3775314Sstever@gmail.com    labelStack.pop_back();
3785314Sstever@gmail.com    assert(!labelStack.empty());
3795314Sstever@gmail.com}
3805314Sstever@gmail.com
3815314Sstever@gmail.comvoid
3825314Sstever@gmail.comPacket::PrintReqState::printLabels()
3835314Sstever@gmail.com{
3845314Sstever@gmail.com    if (!labelStack.back().labelPrinted) {
3855314Sstever@gmail.com        LabelStack::iterator i = labelStack.begin();
3865314Sstever@gmail.com        LabelStack::iterator end = labelStack.end();
3875314Sstever@gmail.com        while (i != end) {
3885314Sstever@gmail.com            if (!i->labelPrinted) {
3895314Sstever@gmail.com                ccprintf(os, "%s%s\n", *(i->prefix), i->label);
3905314Sstever@gmail.com                i->labelPrinted = true;
3915314Sstever@gmail.com            }
3925314Sstever@gmail.com            i++;
3935314Sstever@gmail.com        }
3945314Sstever@gmail.com    }
3955314Sstever@gmail.com}
3965314Sstever@gmail.com
3975314Sstever@gmail.com
3985314Sstever@gmail.comvoid
3995314Sstever@gmail.comPacket::PrintReqState::printObj(Printable *obj)
4005314Sstever@gmail.com{
4015314Sstever@gmail.com    printLabels();
4025314Sstever@gmail.com    obj->print(os, verbosity, curPrefix());
4035314Sstever@gmail.com}
404