packet.cc revision 12334
12568SN/A/*
211600Sandreas.hansson@arm.com * Copyright (c) 2011-2016 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
1510975Sdavid.hashe@amd.com * Copyright (c) 2010,2015 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
5111793Sbrandon.potter@amd.com#include "mem/packet.hh"
5211793Sbrandon.potter@amd.com
538229Snate@binkert.org#include <cstring>
543260Ssaidi@eecs.umich.edu#include <iostream>
558229Snate@binkert.org
565314Sstever@gmail.com#include "base/cprintf.hh"
5712334Sgabeblack@google.com#include "base/logging.hh"
583348Sbinkertn@umich.edu#include "base/trace.hh"
592568SN/A
605735Snate@binkert.orgusing namespace std;
615735Snate@binkert.org
624022Sstever@eecs.umich.edu// The one downside to bitsets is that static initializers can get ugly.
634022Sstever@eecs.umich.edu#define SET1(a1)                     (1 << (a1))
644022Sstever@eecs.umich.edu#define SET2(a1, a2)                 (SET1(a1) | SET1(a2))
654022Sstever@eecs.umich.edu#define SET3(a1, a2, a3)             (SET2(a1, a2) | SET1(a3))
664022Sstever@eecs.umich.edu#define SET4(a1, a2, a3, a4)         (SET3(a1, a2, a3) | SET1(a4))
674022Sstever@eecs.umich.edu#define SET5(a1, a2, a3, a4, a5)     (SET4(a1, a2, a3, a4) | SET1(a5))
684022Sstever@eecs.umich.edu#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
6911600Sandreas.hansson@arm.com#define SET7(a1, a2, a3, a4, a5, a6, a7) (SET6(a1, a2, a3, a4, a5, a6) | \
7011600Sandreas.hansson@arm.com                                          SET1(a7))
712641Sstever@eecs.umich.edu
724022Sstever@eecs.umich.educonst MemCmd::CommandInfo
734022Sstever@eecs.umich.eduMemCmd::commandInfo[] =
742641Sstever@eecs.umich.edu{
754022Sstever@eecs.umich.edu    /* InvalidCmd */
764022Sstever@eecs.umich.edu    { 0, InvalidCmd, "InvalidCmd" },
7710885Sandreas.hansson@arm.com    /* ReadReq - Read issued by a non-caching agent such as a CPU or
7810885Sandreas.hansson@arm.com     * device, with no restrictions on alignment. */
794022Sstever@eecs.umich.edu    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
804473Sstever@eecs.umich.edu    /* ReadResp */
814473Sstever@eecs.umich.edu    { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
825319Sstever@gmail.com    /* ReadRespWithInvalidate */
835319Sstever@gmail.com    { SET4(IsRead, IsResponse, HasData, IsInvalidate),
845319Sstever@gmail.com            InvalidCmd, "ReadRespWithInvalidate" },
854022Sstever@eecs.umich.edu    /* WriteReq */
8611284Sandreas.hansson@arm.com    { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData),
874022Sstever@eecs.umich.edu            WriteResp, "WriteReq" },
884022Sstever@eecs.umich.edu    /* WriteResp */
8911287Sandreas.hansson@arm.com    { SET2(IsWrite, IsResponse), InvalidCmd, "WriteResp" },
9011199Sandreas.hansson@arm.com    /* WritebackDirty */
9111600Sandreas.hansson@arm.com    { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache),
9211199Sandreas.hansson@arm.com            InvalidCmd, "WritebackDirty" },
9311199Sandreas.hansson@arm.com    /* WritebackClean - This allows the upstream cache to writeback a
9411199Sandreas.hansson@arm.com     * line to the downstream cache without it being considered
9511199Sandreas.hansson@arm.com     * dirty. */
9611600Sandreas.hansson@arm.com    { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache),
9711199Sandreas.hansson@arm.com            InvalidCmd, "WritebackClean" },
9810883Sali.jafri@arm.com    /* CleanEvict */
9911600Sandreas.hansson@arm.com    { SET3(IsRequest, IsEviction, FromCache), InvalidCmd, "CleanEvict" },
1004022Sstever@eecs.umich.edu    /* SoftPFReq */
1014022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
1024022Sstever@eecs.umich.edu            SoftPFResp, "SoftPFReq" },
1034022Sstever@eecs.umich.edu    /* HardPFReq */
10411600Sandreas.hansson@arm.com    { SET5(IsRead, IsRequest, IsHWPrefetch, NeedsResponse, FromCache),
1054022Sstever@eecs.umich.edu            HardPFResp, "HardPFReq" },
1064022Sstever@eecs.umich.edu    /* SoftPFResp */
1074022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
1084022Sstever@eecs.umich.edu            InvalidCmd, "SoftPFResp" },
1094022Sstever@eecs.umich.edu    /* HardPFResp */
1104022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
1114022Sstever@eecs.umich.edu            InvalidCmd, "HardPFResp" },
11210886Sandreas.hansson@arm.com    /* WriteLineReq */
11311284Sandreas.hansson@arm.com    { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData),
11410886Sandreas.hansson@arm.com            WriteResp, "WriteLineReq" },
1154022Sstever@eecs.umich.edu    /* UpgradeReq */
11611600Sandreas.hansson@arm.com    { SET6(IsInvalidate, NeedsWritable, IsUpgrade, IsRequest, NeedsResponse,
11711600Sandreas.hansson@arm.com            FromCache),
1184628Sstever@eecs.umich.edu            UpgradeResp, "UpgradeReq" },
1197465Ssteve.reinhardt@amd.com    /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
12011600Sandreas.hansson@arm.com    { SET7(IsInvalidate, NeedsWritable, IsUpgrade, IsLlsc,
12111600Sandreas.hansson@arm.com           IsRequest, NeedsResponse, FromCache),
1227465Ssteve.reinhardt@amd.com            UpgradeResp, "SCUpgradeReq" },
1234628Sstever@eecs.umich.edu    /* UpgradeResp */
12411287Sandreas.hansson@arm.com    { SET2(IsUpgrade, IsResponse),
1257465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeResp" },
12610325Sgeoffrey.blake@arm.com    /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
12711600Sandreas.hansson@arm.com    { SET7(IsRead, NeedsWritable, IsInvalidate,
12811600Sandreas.hansson@arm.com           IsLlsc, IsRequest, NeedsResponse, FromCache),
1297465Ssteve.reinhardt@amd.com            UpgradeFailResp, "SCUpgradeFailReq" },
13010325Sgeoffrey.blake@arm.com    /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
13110325Sgeoffrey.blake@arm.com     * that it has failed, acquires line as Dirty*/
13211287Sandreas.hansson@arm.com    { SET3(IsRead, IsResponse, HasData),
1337465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeFailResp" },
13410885Sandreas.hansson@arm.com    /* ReadExReq - Read issues by a cache, always cache-line aligned,
13510885Sandreas.hansson@arm.com     * and the response is guaranteed to be writeable (exclusive or
13610885Sandreas.hansson@arm.com     * even modified) */
13711600Sandreas.hansson@arm.com    { SET6(IsRead, NeedsWritable, IsInvalidate, IsRequest, NeedsResponse,
13811600Sandreas.hansson@arm.com            FromCache),
1394022Sstever@eecs.umich.edu            ReadExResp, "ReadExReq" },
14010885Sandreas.hansson@arm.com    /* ReadExResp - Response matching a read exclusive, as we check
14110885Sandreas.hansson@arm.com     * the need for exclusive also on responses */
14211287Sandreas.hansson@arm.com    { SET3(IsRead, IsResponse, HasData),
1434040Ssaidi@eecs.umich.edu            InvalidCmd, "ReadExResp" },
14410885Sandreas.hansson@arm.com    /* ReadCleanReq - Read issued by a cache, always cache-line
14510885Sandreas.hansson@arm.com     * aligned, and the response is guaranteed to not contain dirty data
14610885Sandreas.hansson@arm.com     * (exclusive or shared).*/
14711600Sandreas.hansson@arm.com    { SET4(IsRead, IsRequest, NeedsResponse, FromCache),
14811600Sandreas.hansson@arm.com            ReadResp, "ReadCleanReq" },
14910885Sandreas.hansson@arm.com    /* ReadSharedReq - Read issued by a cache, always cache-line
15010885Sandreas.hansson@arm.com     * aligned, response is shared, possibly exclusive, owned or even
15110885Sandreas.hansson@arm.com     * modified. */
15211600Sandreas.hansson@arm.com    { SET4(IsRead, IsRequest, NeedsResponse, FromCache),
15311600Sandreas.hansson@arm.com            ReadResp, "ReadSharedReq" },
1545507Sstever@gmail.com    /* LoadLockedReq: note that we use plain ReadResp as response, so that
1555507Sstever@gmail.com     *                we can also use ReadRespWithInvalidate when needed */
1566076Sgblack@eecs.umich.edu    { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
1575507Sstever@gmail.com            ReadResp, "LoadLockedReq" },
1584626Sstever@eecs.umich.edu    /* StoreCondReq */
15911284Sandreas.hansson@arm.com    { SET6(IsWrite, NeedsWritable, IsLlsc,
1604626Sstever@eecs.umich.edu           IsRequest, NeedsResponse, HasData),
1614626Sstever@eecs.umich.edu            StoreCondResp, "StoreCondReq" },
16210325Sgeoffrey.blake@arm.com    /* StoreCondFailReq: generates failing StoreCondResp */
16311284Sandreas.hansson@arm.com    { SET6(IsWrite, NeedsWritable, IsLlsc,
1647669Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse, HasData),
1657669Ssteve.reinhardt@amd.com            StoreCondResp, "StoreCondFailReq" },
1664626Sstever@eecs.umich.edu    /* StoreCondResp */
16711287Sandreas.hansson@arm.com    { SET3(IsWrite, IsLlsc, IsResponse),
1684626Sstever@eecs.umich.edu            InvalidCmd, "StoreCondResp" },
1694040Ssaidi@eecs.umich.edu    /* SwapReq -- for Swap ldstub type operations */
17011284Sandreas.hansson@arm.com    { SET6(IsRead, IsWrite, NeedsWritable, IsRequest, HasData, NeedsResponse),
1714040Ssaidi@eecs.umich.edu        SwapResp, "SwapReq" },
1724040Ssaidi@eecs.umich.edu    /* SwapResp -- for Swap ldstub type operations */
17311287Sandreas.hansson@arm.com    { SET4(IsRead, IsWrite, IsResponse, HasData),
1744870Sstever@eecs.umich.edu            InvalidCmd, "SwapResp" },
1755650Sgblack@eecs.umich.edu    /* IntReq -- for interrupts */
1765650Sgblack@eecs.umich.edu    { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
1776063Sgblack@eecs.umich.edu        MessageResp, "MessageReq" },
1785650Sgblack@eecs.umich.edu    /* IntResp -- for interrupts */
1796063Sgblack@eecs.umich.edu    { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
18011256Santhony.gutierrez@amd.com    /* MemFenceReq -- for synchronization requests */
18111256Santhony.gutierrez@amd.com    {SET2(IsRequest, NeedsResponse), MemFenceResp, "MemFenceReq"},
18211256Santhony.gutierrez@amd.com    /* MemFenceResp -- for synchronization responses */
18311256Santhony.gutierrez@amd.com    {SET1(IsResponse), InvalidCmd, "MemFenceResp"},
1844870Sstever@eecs.umich.edu    /* InvalidDestError  -- packet dest field invalid */
1854986Ssaidi@eecs.umich.edu    { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
1864870Sstever@eecs.umich.edu    /* BadAddressError   -- memory address invalid */
1875314Sstever@gmail.com    { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
1888436SBrad.Beckmann@amd.com    /* FunctionalReadError */
1898436SBrad.Beckmann@amd.com    { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
1908436SBrad.Beckmann@amd.com    /* FunctionalWriteError */
1918436SBrad.Beckmann@amd.com    { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
1925314Sstever@gmail.com    /* PrintReq */
1938184Ssomayeh@cs.wisc.edu    { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
1948184Ssomayeh@cs.wisc.edu    /* Flush Request */
19511284Sandreas.hansson@arm.com    { SET3(IsRequest, IsFlush, NeedsWritable), InvalidCmd, "FlushReq" },
1968716Snilay@cs.wisc.edu    /* Invalidation Request */
19711600Sandreas.hansson@arm.com    { SET5(IsInvalidate, IsRequest, NeedsWritable, NeedsResponse, FromCache),
19810886Sandreas.hansson@arm.com      InvalidateResp, "InvalidateReq" },
19910886Sandreas.hansson@arm.com    /* Invalidation Response */
20011287Sandreas.hansson@arm.com    { SET2(IsInvalidate, IsResponse),
20110886Sandreas.hansson@arm.com      InvalidCmd, "InvalidateResp" }
2024022Sstever@eecs.umich.edu};
2032592SN/A
2043607Srdreslin@umich.edubool
20510028SGiacomo.Gabrielli@arm.comPacket::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
20610570Sandreas.hansson@arm.com                        uint8_t *_data)
2072641Sstever@eecs.umich.edu{
2084626Sstever@eecs.umich.edu    Addr func_start = getAddr();
2094626Sstever@eecs.umich.edu    Addr func_end   = getAddr() + getSize() - 1;
2104626Sstever@eecs.umich.edu    Addr val_start  = addr;
2114626Sstever@eecs.umich.edu    Addr val_end    = val_start + size - 1;
2123260Ssaidi@eecs.umich.edu
21310028SGiacomo.Gabrielli@arm.com    if (is_secure != _isSecure || func_start > val_end ||
21410028SGiacomo.Gabrielli@arm.com        val_start > func_end) {
2154626Sstever@eecs.umich.edu        // no intersection
2164626Sstever@eecs.umich.edu        return false;
2174626Sstever@eecs.umich.edu    }
2183260Ssaidi@eecs.umich.edu
2195314Sstever@gmail.com    // check print first since it doesn't require data
2205314Sstever@gmail.com    if (isPrint()) {
22110570Sandreas.hansson@arm.com        assert(!_data);
22210376Sandreas.hansson@arm.com        safe_cast<PrintReqState*>(senderState)->printObj(obj);
2235314Sstever@gmail.com        return false;
2245314Sstever@gmail.com    }
2255314Sstever@gmail.com
22610570Sandreas.hansson@arm.com    // we allow the caller to pass NULL to signify the other packet
22710570Sandreas.hansson@arm.com    // has no data
22810570Sandreas.hansson@arm.com    if (!_data) {
2295314Sstever@gmail.com        return false;
2305314Sstever@gmail.com    }
2315314Sstever@gmail.com
2324626Sstever@eecs.umich.edu    // offset of functional request into supplied value (could be
2334626Sstever@eecs.umich.edu    // negative if partial overlap)
2344626Sstever@eecs.umich.edu    int offset = func_start - val_start;
2353260Ssaidi@eecs.umich.edu
2364626Sstever@eecs.umich.edu    if (isRead()) {
2374626Sstever@eecs.umich.edu        if (func_start >= val_start && func_end <= val_end) {
23810570Sandreas.hansson@arm.com            memcpy(getPtr<uint8_t>(), _data + offset, getSize());
23910723Sandreas.hansson@arm.com            if (bytesValid.empty())
24010723Sandreas.hansson@arm.com                bytesValid.resize(getSize(), true);
24110570Sandreas.hansson@arm.com            // complete overlap, and as the current packet is a read
24210570Sandreas.hansson@arm.com            // we are done
2434626Sstever@eecs.umich.edu            return true;
2443260Ssaidi@eecs.umich.edu        } else {
2458668Sgeoffrey.blake@arm.com            // Offsets and sizes to copy in case of partial overlap
2468668Sgeoffrey.blake@arm.com            int func_offset;
2478668Sgeoffrey.blake@arm.com            int val_offset;
2488668Sgeoffrey.blake@arm.com            int overlap_size;
2498668Sgeoffrey.blake@arm.com
2508668Sgeoffrey.blake@arm.com            // calculate offsets and copy sizes for the two byte arrays
2518668Sgeoffrey.blake@arm.com            if (val_start < func_start && val_end <= func_end) {
25210723Sandreas.hansson@arm.com                // the one we are checking against starts before and
25310723Sandreas.hansson@arm.com                // ends before or the same
2548668Sgeoffrey.blake@arm.com                val_offset = func_start - val_start;
2558668Sgeoffrey.blake@arm.com                func_offset = 0;
2568668Sgeoffrey.blake@arm.com                overlap_size = val_end - func_start;
2578668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end > func_end) {
25810723Sandreas.hansson@arm.com                // the one we are checking against starts after or the
25910723Sandreas.hansson@arm.com                // same, and ends after
2608668Sgeoffrey.blake@arm.com                val_offset = 0;
2618668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2628668Sgeoffrey.blake@arm.com                overlap_size = func_end - val_start;
2638668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end <= func_end) {
26410723Sandreas.hansson@arm.com                // the one we are checking against is completely
26510723Sandreas.hansson@arm.com                // subsumed in the current packet, possibly starting
26610723Sandreas.hansson@arm.com                // and ending at the same address
2678668Sgeoffrey.blake@arm.com                val_offset = 0;
2688668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2698668Sgeoffrey.blake@arm.com                overlap_size = size;
27010723Sandreas.hansson@arm.com            } else if (val_start < func_start && val_end > func_end) {
27110723Sandreas.hansson@arm.com                // the current packet is completely subsumed in the
27210723Sandreas.hansson@arm.com                // one we are checking against
27310723Sandreas.hansson@arm.com                val_offset = func_start - val_start;
27410723Sandreas.hansson@arm.com                func_offset = 0;
27510723Sandreas.hansson@arm.com                overlap_size = func_end - func_start;
2768668Sgeoffrey.blake@arm.com            } else {
27710723Sandreas.hansson@arm.com                panic("Missed a case for checkFunctional with "
27810723Sandreas.hansson@arm.com                      " %s 0x%x size %d, against 0x%x size %d\n",
27910723Sandreas.hansson@arm.com                      cmdString(), getAddr(), getSize(), addr, size);
2808668Sgeoffrey.blake@arm.com            }
2818668Sgeoffrey.blake@arm.com
2828668Sgeoffrey.blake@arm.com            // copy partial data into the packet's data array
2838668Sgeoffrey.blake@arm.com            uint8_t *dest = getPtr<uint8_t>() + func_offset;
28410570Sandreas.hansson@arm.com            uint8_t *src = _data + val_offset;
2858668Sgeoffrey.blake@arm.com            memcpy(dest, src, overlap_size);
2868668Sgeoffrey.blake@arm.com
28710723Sandreas.hansson@arm.com            // initialise the tracking of valid bytes if we have not
28810723Sandreas.hansson@arm.com            // used it already
28910723Sandreas.hansson@arm.com            if (bytesValid.empty())
29010723Sandreas.hansson@arm.com                bytesValid.resize(getSize(), false);
29110723Sandreas.hansson@arm.com
29210723Sandreas.hansson@arm.com            // track if we are done filling the functional access
29310723Sandreas.hansson@arm.com            bool all_bytes_valid = true;
29410723Sandreas.hansson@arm.com
29510723Sandreas.hansson@arm.com            int i = 0;
29610723Sandreas.hansson@arm.com
29710723Sandreas.hansson@arm.com            // check up to func_offset
29810723Sandreas.hansson@arm.com            for (; all_bytes_valid && i < func_offset; ++i)
29910723Sandreas.hansson@arm.com                all_bytes_valid &= bytesValid[i];
30010723Sandreas.hansson@arm.com
30110723Sandreas.hansson@arm.com            // update the valid bytes
30210723Sandreas.hansson@arm.com            for (i = func_offset; i < func_offset + overlap_size; ++i)
30310723Sandreas.hansson@arm.com                bytesValid[i] = true;
30410723Sandreas.hansson@arm.com
30510723Sandreas.hansson@arm.com            // check the bit after the update we just made
30610723Sandreas.hansson@arm.com            for (; all_bytes_valid && i < getSize(); ++i)
30710723Sandreas.hansson@arm.com                all_bytes_valid &= bytesValid[i];
30810723Sandreas.hansson@arm.com
30910723Sandreas.hansson@arm.com            return all_bytes_valid;
3103260Ssaidi@eecs.umich.edu        }
3114626Sstever@eecs.umich.edu    } else if (isWrite()) {
3124626Sstever@eecs.umich.edu        if (offset >= 0) {
31310570Sandreas.hansson@arm.com            memcpy(_data + offset, getConstPtr<uint8_t>(),
3145735Snate@binkert.org                   (min(func_end, val_end) - func_start) + 1);
3155735Snate@binkert.org        } else {
3165735Snate@binkert.org            // val_start > func_start
31710570Sandreas.hansson@arm.com            memcpy(_data, getConstPtr<uint8_t>() - offset,
3185735Snate@binkert.org                   (min(func_end, val_end) - val_start) + 1);
3193260Ssaidi@eecs.umich.edu        }
3205314Sstever@gmail.com    } else {
3214626Sstever@eecs.umich.edu        panic("Don't know how to handle command %s\n", cmdString());
3225314Sstever@gmail.com    }
3235314Sstever@gmail.com
3245314Sstever@gmail.com    // keep going with request by default
3255314Sstever@gmail.com    return false;
3262641Sstever@eecs.umich.edu}
3273260Ssaidi@eecs.umich.edu
3285314Sstever@gmail.comvoid
3299542Sandreas.hansson@arm.comPacket::pushSenderState(Packet::SenderState *sender_state)
3309542Sandreas.hansson@arm.com{
3319542Sandreas.hansson@arm.com    assert(sender_state != NULL);
3329542Sandreas.hansson@arm.com    sender_state->predecessor = senderState;
3339542Sandreas.hansson@arm.com    senderState = sender_state;
3349542Sandreas.hansson@arm.com}
3359542Sandreas.hansson@arm.com
3369542Sandreas.hansson@arm.comPacket::SenderState *
3379542Sandreas.hansson@arm.comPacket::popSenderState()
3389542Sandreas.hansson@arm.com{
3399542Sandreas.hansson@arm.com    assert(senderState != NULL);
3409542Sandreas.hansson@arm.com    SenderState *sender_state = senderState;
3419542Sandreas.hansson@arm.com    senderState = sender_state->predecessor;
3429542Sandreas.hansson@arm.com    sender_state->predecessor = NULL;
3439542Sandreas.hansson@arm.com    return sender_state;
3449542Sandreas.hansson@arm.com}
3459542Sandreas.hansson@arm.com
3469542Sandreas.hansson@arm.comvoid
3475735Snate@binkert.orgPacket::print(ostream &o, const int verbosity, const string &prefix) const
3483260Ssaidi@eecs.umich.edu{
34911744Snikos.nikoleris@arm.com    ccprintf(o, "%s%s [%x:%x]%s%s%s%s", prefix, cmdString(),
35011744Snikos.nikoleris@arm.com             getAddr(), getAddr() + getSize() - 1,
35111744Snikos.nikoleris@arm.com             req->isSecure() ? " (s)" : "",
35211744Snikos.nikoleris@arm.com             req->isInstFetch() ? " IF" : "",
35311744Snikos.nikoleris@arm.com             req->isUncacheable() ? " UC" : "",
35411744Snikos.nikoleris@arm.com             isExpressSnoop() ? " ES" : "");
3553260Ssaidi@eecs.umich.edu}
3563260Ssaidi@eecs.umich.edu
3579663Suri.wiener@arm.comstd::string
3589663Suri.wiener@arm.comPacket::print() const {
3599663Suri.wiener@arm.com    ostringstream str;
3609663Suri.wiener@arm.com    print(str);
3619663Suri.wiener@arm.com    return str.str();
3629663Suri.wiener@arm.com}
3639663Suri.wiener@arm.com
3645735Snate@binkert.orgPacket::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
3655735Snate@binkert.org    : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
3665314Sstever@gmail.com{
3675314Sstever@gmail.com    labelStack.push_back(LabelStackEntry("", curPrefixPtr));
3685314Sstever@gmail.com}
3695314Sstever@gmail.com
3705314Sstever@gmail.comPacket::PrintReqState::~PrintReqState()
3715314Sstever@gmail.com{
3725314Sstever@gmail.com    labelStack.pop_back();
3735314Sstever@gmail.com    assert(labelStack.empty());
3745314Sstever@gmail.com    delete curPrefixPtr;
3755314Sstever@gmail.com}
3765314Sstever@gmail.com
3775314Sstever@gmail.comPacket::PrintReqState::
3785735Snate@binkert.orgLabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
3795314Sstever@gmail.com    : label(_label), prefix(_prefix), labelPrinted(false)
3805314Sstever@gmail.com{
3815314Sstever@gmail.com}
3825314Sstever@gmail.com
3835314Sstever@gmail.comvoid
3845735Snate@binkert.orgPacket::PrintReqState::pushLabel(const string &lbl, const string &prefix)
3855314Sstever@gmail.com{
3865314Sstever@gmail.com    labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
3875735Snate@binkert.org    curPrefixPtr = new string(*curPrefixPtr);
3885314Sstever@gmail.com    *curPrefixPtr += prefix;
3895314Sstever@gmail.com}
3905314Sstever@gmail.com
3915314Sstever@gmail.comvoid
3925314Sstever@gmail.comPacket::PrintReqState::popLabel()
3935314Sstever@gmail.com{
3945314Sstever@gmail.com    delete curPrefixPtr;
3955314Sstever@gmail.com    curPrefixPtr = labelStack.back().prefix;
3965314Sstever@gmail.com    labelStack.pop_back();
3975314Sstever@gmail.com    assert(!labelStack.empty());
3985314Sstever@gmail.com}
3995314Sstever@gmail.com
4005314Sstever@gmail.comvoid
4015314Sstever@gmail.comPacket::PrintReqState::printLabels()
4025314Sstever@gmail.com{
4035314Sstever@gmail.com    if (!labelStack.back().labelPrinted) {
4045314Sstever@gmail.com        LabelStack::iterator i = labelStack.begin();
4055314Sstever@gmail.com        LabelStack::iterator end = labelStack.end();
4065314Sstever@gmail.com        while (i != end) {
4075314Sstever@gmail.com            if (!i->labelPrinted) {
4085314Sstever@gmail.com                ccprintf(os, "%s%s\n", *(i->prefix), i->label);
4095314Sstever@gmail.com                i->labelPrinted = true;
4105314Sstever@gmail.com            }
4115314Sstever@gmail.com            i++;
4125314Sstever@gmail.com        }
4135314Sstever@gmail.com    }
4145314Sstever@gmail.com}
4155314Sstever@gmail.com
4165314Sstever@gmail.com
4175314Sstever@gmail.comvoid
4185314Sstever@gmail.comPacket::PrintReqState::printObj(Printable *obj)
4195314Sstever@gmail.com{
4205314Sstever@gmail.com    printLabels();
4215314Sstever@gmail.com    obj->print(os, verbosity, curPrefix());
4225314Sstever@gmail.com}
423