packet.cc revision 10376
12568SN/A/*
210325Sgeoffrey.blake@arm.com * Copyright (c) 2011-2014 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" },
744022Sstever@eecs.umich.edu    /* ReadReq */
754022Sstever@eecs.umich.edu    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
764473Sstever@eecs.umich.edu    /* ReadResp */
774473Sstever@eecs.umich.edu    { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
785319Sstever@gmail.com    /* ReadRespWithInvalidate */
795319Sstever@gmail.com    { SET4(IsRead, IsResponse, HasData, IsInvalidate),
805319Sstever@gmail.com            InvalidCmd, "ReadRespWithInvalidate" },
814022Sstever@eecs.umich.edu    /* WriteReq */
824626Sstever@eecs.umich.edu    { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
834022Sstever@eecs.umich.edu            WriteResp, "WriteReq" },
844022Sstever@eecs.umich.edu    /* WriteResp */
854626Sstever@eecs.umich.edu    { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
864022Sstever@eecs.umich.edu    /* Writeback */
874628Sstever@eecs.umich.edu    { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
884628Sstever@eecs.umich.edu            InvalidCmd, "Writeback" },
894022Sstever@eecs.umich.edu    /* SoftPFReq */
904022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
914022Sstever@eecs.umich.edu            SoftPFResp, "SoftPFReq" },
924022Sstever@eecs.umich.edu    /* HardPFReq */
934022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
944022Sstever@eecs.umich.edu            HardPFResp, "HardPFReq" },
954022Sstever@eecs.umich.edu    /* SoftPFResp */
964022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
974022Sstever@eecs.umich.edu            InvalidCmd, "SoftPFResp" },
984022Sstever@eecs.umich.edu    /* HardPFResp */
994022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
1004022Sstever@eecs.umich.edu            InvalidCmd, "HardPFResp" },
10110345SCurtis.Dunham@arm.com    /* WriteInvalidateReq */
1024626Sstever@eecs.umich.edu    { SET6(IsWrite, NeedsExclusive, IsInvalidate,
1034626Sstever@eecs.umich.edu           IsRequest, HasData, NeedsResponse),
1044022Sstever@eecs.umich.edu            WriteInvalidateResp, "WriteInvalidateReq" },
10510345SCurtis.Dunham@arm.com    /* WriteInvalidateResp */
1065319Sstever@gmail.com    { SET3(IsWrite, NeedsExclusive, IsResponse),
1074022Sstever@eecs.umich.edu            InvalidCmd, "WriteInvalidateResp" },
1084022Sstever@eecs.umich.edu    /* UpgradeReq */
1097465Ssteve.reinhardt@amd.com    { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
1104628Sstever@eecs.umich.edu            UpgradeResp, "UpgradeReq" },
1117465Ssteve.reinhardt@amd.com    /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
1127465Ssteve.reinhardt@amd.com    { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
1137465Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse),
1147465Ssteve.reinhardt@amd.com            UpgradeResp, "SCUpgradeReq" },
1154628Sstever@eecs.umich.edu    /* UpgradeResp */
1167465Ssteve.reinhardt@amd.com    { SET3(NeedsExclusive, IsUpgrade, IsResponse),
1177465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeResp" },
11810325Sgeoffrey.blake@arm.com    /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
11910325Sgeoffrey.blake@arm.com    { SET6(IsRead, NeedsExclusive, IsInvalidate,
12010325Sgeoffrey.blake@arm.com           IsLlsc, IsRequest, NeedsResponse),
1217465Ssteve.reinhardt@amd.com            UpgradeFailResp, "SCUpgradeFailReq" },
12210325Sgeoffrey.blake@arm.com    /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
12310325Sgeoffrey.blake@arm.com     * that it has failed, acquires line as Dirty*/
12410325Sgeoffrey.blake@arm.com    { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
1257465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeFailResp" },
1264022Sstever@eecs.umich.edu    /* ReadExReq */
1274626Sstever@eecs.umich.edu    { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
1284022Sstever@eecs.umich.edu            ReadExResp, "ReadExReq" },
1294022Sstever@eecs.umich.edu    /* ReadExResp */
1305319Sstever@gmail.com    { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
1314040Ssaidi@eecs.umich.edu            InvalidCmd, "ReadExResp" },
1325507Sstever@gmail.com    /* LoadLockedReq: note that we use plain ReadResp as response, so that
1335507Sstever@gmail.com     *                we can also use ReadRespWithInvalidate when needed */
1346076Sgblack@eecs.umich.edu    { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
1355507Sstever@gmail.com            ReadResp, "LoadLockedReq" },
1364626Sstever@eecs.umich.edu    /* StoreCondReq */
1376076Sgblack@eecs.umich.edu    { SET6(IsWrite, NeedsExclusive, IsLlsc,
1384626Sstever@eecs.umich.edu           IsRequest, NeedsResponse, HasData),
1394626Sstever@eecs.umich.edu            StoreCondResp, "StoreCondReq" },
14010325Sgeoffrey.blake@arm.com    /* StoreCondFailReq: generates failing StoreCondResp */
1417669Ssteve.reinhardt@amd.com    { SET6(IsWrite, NeedsExclusive, IsLlsc,
1427669Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse, HasData),
1437669Ssteve.reinhardt@amd.com            StoreCondResp, "StoreCondFailReq" },
1444626Sstever@eecs.umich.edu    /* StoreCondResp */
1456076Sgblack@eecs.umich.edu    { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
1464626Sstever@eecs.umich.edu            InvalidCmd, "StoreCondResp" },
1474040Ssaidi@eecs.umich.edu    /* SwapReq -- for Swap ldstub type operations */
1484626Sstever@eecs.umich.edu    { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
1494040Ssaidi@eecs.umich.edu        SwapResp, "SwapReq" },
1504040Ssaidi@eecs.umich.edu    /* SwapResp -- for Swap ldstub type operations */
1514626Sstever@eecs.umich.edu    { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
1524870Sstever@eecs.umich.edu            InvalidCmd, "SwapResp" },
1535650Sgblack@eecs.umich.edu    /* IntReq -- for interrupts */
1545650Sgblack@eecs.umich.edu    { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
1556063Sgblack@eecs.umich.edu        MessageResp, "MessageReq" },
1565650Sgblack@eecs.umich.edu    /* IntResp -- for interrupts */
1576063Sgblack@eecs.umich.edu    { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
1584870Sstever@eecs.umich.edu    /* InvalidDestError  -- packet dest field invalid */
1594986Ssaidi@eecs.umich.edu    { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
1604870Sstever@eecs.umich.edu    /* BadAddressError   -- memory address invalid */
1615314Sstever@gmail.com    { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
1628436SBrad.Beckmann@amd.com    /* FunctionalReadError */
1638436SBrad.Beckmann@amd.com    { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
1648436SBrad.Beckmann@amd.com    /* FunctionalWriteError */
1658436SBrad.Beckmann@amd.com    { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
1665314Sstever@gmail.com    /* PrintReq */
1678184Ssomayeh@cs.wisc.edu    { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
1688184Ssomayeh@cs.wisc.edu    /* Flush Request */
1698436SBrad.Beckmann@amd.com    { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
1708716Snilay@cs.wisc.edu    /* Invalidation Request */
1718716Snilay@cs.wisc.edu    { SET3(NeedsExclusive, IsInvalidate, IsRequest),
1728716Snilay@cs.wisc.edu      InvalidCmd, "InvalidationReq" },
1734022Sstever@eecs.umich.edu};
1742592SN/A
1753607Srdreslin@umich.edubool
17610028SGiacomo.Gabrielli@arm.comPacket::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
17710028SGiacomo.Gabrielli@arm.com                        uint8_t *data)
1782641Sstever@eecs.umich.edu{
1794626Sstever@eecs.umich.edu    Addr func_start = getAddr();
1804626Sstever@eecs.umich.edu    Addr func_end   = getAddr() + getSize() - 1;
1814626Sstever@eecs.umich.edu    Addr val_start  = addr;
1824626Sstever@eecs.umich.edu    Addr val_end    = val_start + size - 1;
1833260Ssaidi@eecs.umich.edu
18410028SGiacomo.Gabrielli@arm.com    if (is_secure != _isSecure || func_start > val_end ||
18510028SGiacomo.Gabrielli@arm.com        val_start > func_end) {
1864626Sstever@eecs.umich.edu        // no intersection
1874626Sstever@eecs.umich.edu        return false;
1884626Sstever@eecs.umich.edu    }
1893260Ssaidi@eecs.umich.edu
1905314Sstever@gmail.com    // check print first since it doesn't require data
1915314Sstever@gmail.com    if (isPrint()) {
19210376Sandreas.hansson@arm.com        safe_cast<PrintReqState*>(senderState)->printObj(obj);
1935314Sstever@gmail.com        return false;
1945314Sstever@gmail.com    }
1955314Sstever@gmail.com
1965314Sstever@gmail.com    // if there's no data, there's no need to look further
1975314Sstever@gmail.com    if (!data) {
1985314Sstever@gmail.com        return false;
1995314Sstever@gmail.com    }
2005314Sstever@gmail.com
2014626Sstever@eecs.umich.edu    // offset of functional request into supplied value (could be
2024626Sstever@eecs.umich.edu    // negative if partial overlap)
2034626Sstever@eecs.umich.edu    int offset = func_start - val_start;
2043260Ssaidi@eecs.umich.edu
2054626Sstever@eecs.umich.edu    if (isRead()) {
2064626Sstever@eecs.umich.edu        if (func_start >= val_start && func_end <= val_end) {
2074626Sstever@eecs.umich.edu            allocate();
2085735Snate@binkert.org            memcpy(getPtr<uint8_t>(), data + offset, getSize());
2094626Sstever@eecs.umich.edu            return true;
2103260Ssaidi@eecs.umich.edu        } else {
2118668Sgeoffrey.blake@arm.com            // Offsets and sizes to copy in case of partial overlap
2128668Sgeoffrey.blake@arm.com            int func_offset;
2138668Sgeoffrey.blake@arm.com            int val_offset;
2148668Sgeoffrey.blake@arm.com            int overlap_size;
2158668Sgeoffrey.blake@arm.com
2168668Sgeoffrey.blake@arm.com            // calculate offsets and copy sizes for the two byte arrays
2178668Sgeoffrey.blake@arm.com            if (val_start < func_start && val_end <= func_end) {
2188668Sgeoffrey.blake@arm.com                val_offset = func_start - val_start;
2198668Sgeoffrey.blake@arm.com                func_offset = 0;
2208668Sgeoffrey.blake@arm.com                overlap_size = val_end - func_start;
2218668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end > func_end) {
2228668Sgeoffrey.blake@arm.com                val_offset = 0;
2238668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2248668Sgeoffrey.blake@arm.com                overlap_size = func_end - val_start;
2258668Sgeoffrey.blake@arm.com            } else if (val_start >= func_start && val_end <= func_end) {
2268668Sgeoffrey.blake@arm.com                val_offset = 0;
2278668Sgeoffrey.blake@arm.com                func_offset = val_start - func_start;
2288668Sgeoffrey.blake@arm.com                overlap_size = size;
2298668Sgeoffrey.blake@arm.com            } else {
2308668Sgeoffrey.blake@arm.com                panic("BUG: Missed a case for a partial functional request");
2318668Sgeoffrey.blake@arm.com            }
2328668Sgeoffrey.blake@arm.com
2338668Sgeoffrey.blake@arm.com            // Figure out how much of the partial overlap should be copied
2348668Sgeoffrey.blake@arm.com            // into the packet and not overwrite previously found bytes.
2358668Sgeoffrey.blake@arm.com            if (bytesValidStart == 0 && bytesValidEnd == 0) {
2368668Sgeoffrey.blake@arm.com                // No bytes have been copied yet, just set indices
2378668Sgeoffrey.blake@arm.com                // to found range
2388668Sgeoffrey.blake@arm.com                bytesValidStart = func_offset;
2398668Sgeoffrey.blake@arm.com                bytesValidEnd = func_offset + overlap_size;
2408668Sgeoffrey.blake@arm.com            } else {
2418668Sgeoffrey.blake@arm.com                // Some bytes have already been copied. Use bytesValid
2428668Sgeoffrey.blake@arm.com                // indices and offset values to figure out how much data
2438668Sgeoffrey.blake@arm.com                // to copy and where to copy it to.
2448668Sgeoffrey.blake@arm.com
2458668Sgeoffrey.blake@arm.com                // Indice overlap conditions to check
2468668Sgeoffrey.blake@arm.com                int a = func_offset - bytesValidStart;
2478668Sgeoffrey.blake@arm.com                int b = (func_offset + overlap_size) - bytesValidEnd;
2488668Sgeoffrey.blake@arm.com                int c = func_offset - bytesValidEnd;
2498668Sgeoffrey.blake@arm.com                int d = (func_offset + overlap_size) - bytesValidStart;
2508668Sgeoffrey.blake@arm.com
2518668Sgeoffrey.blake@arm.com                if (a >= 0 && b <= 0) {
2528668Sgeoffrey.blake@arm.com                    // bytes already in pkt data array are superset of
2538668Sgeoffrey.blake@arm.com                    // found bytes, will not copy any bytes
2548668Sgeoffrey.blake@arm.com                    overlap_size = 0;
2558668Sgeoffrey.blake@arm.com                } else if (a < 0 && d >= 0 && b <= 0) {
2568668Sgeoffrey.blake@arm.com                    // found bytes will move bytesValidStart towards 0
2578668Sgeoffrey.blake@arm.com                    overlap_size = bytesValidStart - func_offset;
2588668Sgeoffrey.blake@arm.com                    bytesValidStart = func_offset;
2598668Sgeoffrey.blake@arm.com                } else if (b > 0 && c <= 0 && a >= 0) {
2608668Sgeoffrey.blake@arm.com                    // found bytes will move bytesValidEnd
2618668Sgeoffrey.blake@arm.com                    // towards end of pkt data array
2628668Sgeoffrey.blake@arm.com                    overlap_size =
2638668Sgeoffrey.blake@arm.com                        (func_offset + overlap_size) - bytesValidEnd;
2648668Sgeoffrey.blake@arm.com                    val_offset += bytesValidEnd - func_offset;
2658668Sgeoffrey.blake@arm.com                    func_offset = bytesValidEnd;
2668668Sgeoffrey.blake@arm.com                    bytesValidEnd += overlap_size;
2678668Sgeoffrey.blake@arm.com                } else if (a < 0 && b > 0) {
2688668Sgeoffrey.blake@arm.com                    // Found bytes are superset of copied range. Will move
2698668Sgeoffrey.blake@arm.com                    // bytesValidStart towards 0 and bytesValidEnd towards
2708668Sgeoffrey.blake@arm.com                    // end of pkt data array.  Need to break copy into two
2718668Sgeoffrey.blake@arm.com                    // pieces so as to not overwrite previously found data.
2728668Sgeoffrey.blake@arm.com
2738668Sgeoffrey.blake@arm.com                    // copy the first half
2748668Sgeoffrey.blake@arm.com                    uint8_t *dest = getPtr<uint8_t>() + func_offset;
2758668Sgeoffrey.blake@arm.com                    uint8_t *src = data + val_offset;
2768668Sgeoffrey.blake@arm.com                    memcpy(dest, src, (bytesValidStart - func_offset));
2778668Sgeoffrey.blake@arm.com
2788668Sgeoffrey.blake@arm.com                    // re-calc the offsets and indices to do the copy
2798668Sgeoffrey.blake@arm.com                    // required for the second half
2808668Sgeoffrey.blake@arm.com                    val_offset += (bytesValidEnd - func_offset);
2818668Sgeoffrey.blake@arm.com                    bytesValidStart = func_offset;
2828668Sgeoffrey.blake@arm.com                    overlap_size =
2838668Sgeoffrey.blake@arm.com                        (func_offset + overlap_size) - bytesValidEnd;
2848668Sgeoffrey.blake@arm.com                    func_offset = bytesValidEnd;
2858668Sgeoffrey.blake@arm.com                    bytesValidEnd += overlap_size;
2868668Sgeoffrey.blake@arm.com                } else if ((c > 0 && b > 0)
2878668Sgeoffrey.blake@arm.com                           || (a < 0 && d < 0)) {
2888668Sgeoffrey.blake@arm.com                    // region to be copied is discontiguous! Not supported.
2898668Sgeoffrey.blake@arm.com                    panic("BUG: Discontiguous bytes found"
2908668Sgeoffrey.blake@arm.com                          "for functional copying!");
2918668Sgeoffrey.blake@arm.com                }
2928668Sgeoffrey.blake@arm.com            }
2938692Ssaidi@eecs.umich.edu            assert(bytesValidEnd <= getSize());
2948668Sgeoffrey.blake@arm.com
2958668Sgeoffrey.blake@arm.com            // copy partial data into the packet's data array
2968668Sgeoffrey.blake@arm.com            uint8_t *dest = getPtr<uint8_t>() + func_offset;
2978668Sgeoffrey.blake@arm.com            uint8_t *src = data + val_offset;
2988668Sgeoffrey.blake@arm.com            memcpy(dest, src, overlap_size);
2998668Sgeoffrey.blake@arm.com
3008668Sgeoffrey.blake@arm.com            // check if we're done filling the functional access
3018668Sgeoffrey.blake@arm.com            bool done = (bytesValidStart == 0) && (bytesValidEnd == getSize());
3028668Sgeoffrey.blake@arm.com            return done;
3033260Ssaidi@eecs.umich.edu        }
3044626Sstever@eecs.umich.edu    } else if (isWrite()) {
3054626Sstever@eecs.umich.edu        if (offset >= 0) {
3065735Snate@binkert.org            memcpy(data + offset, getPtr<uint8_t>(),
3075735Snate@binkert.org                   (min(func_end, val_end) - func_start) + 1);
3085735Snate@binkert.org        } else {
3095735Snate@binkert.org            // val_start > func_start
3105735Snate@binkert.org            memcpy(data, getPtr<uint8_t>() - offset,
3115735Snate@binkert.org                   (min(func_end, val_end) - val_start) + 1);
3123260Ssaidi@eecs.umich.edu        }
3135314Sstever@gmail.com    } else {
3144626Sstever@eecs.umich.edu        panic("Don't know how to handle command %s\n", cmdString());
3155314Sstever@gmail.com    }
3165314Sstever@gmail.com
3175314Sstever@gmail.com    // keep going with request by default
3185314Sstever@gmail.com    return false;
3192641Sstever@eecs.umich.edu}
3203260Ssaidi@eecs.umich.edu
3215314Sstever@gmail.comvoid
3229542Sandreas.hansson@arm.comPacket::pushSenderState(Packet::SenderState *sender_state)
3239542Sandreas.hansson@arm.com{
3249542Sandreas.hansson@arm.com    assert(sender_state != NULL);
3259542Sandreas.hansson@arm.com    sender_state->predecessor = senderState;
3269542Sandreas.hansson@arm.com    senderState = sender_state;
3279542Sandreas.hansson@arm.com}
3289542Sandreas.hansson@arm.com
3299542Sandreas.hansson@arm.comPacket::SenderState *
3309542Sandreas.hansson@arm.comPacket::popSenderState()
3319542Sandreas.hansson@arm.com{
3329542Sandreas.hansson@arm.com    assert(senderState != NULL);
3339542Sandreas.hansson@arm.com    SenderState *sender_state = senderState;
3349542Sandreas.hansson@arm.com    senderState = sender_state->predecessor;
3359542Sandreas.hansson@arm.com    sender_state->predecessor = NULL;
3369542Sandreas.hansson@arm.com    return sender_state;
3379542Sandreas.hansson@arm.com}
3389542Sandreas.hansson@arm.com
3399542Sandreas.hansson@arm.comvoid
3405735Snate@binkert.orgPacket::print(ostream &o, const int verbosity, const string &prefix) const
3413260Ssaidi@eecs.umich.edu{
3425314Sstever@gmail.com    ccprintf(o, "%s[%x:%x] %s\n", prefix,
3435314Sstever@gmail.com             getAddr(), getAddr() + getSize() - 1, cmdString());
3443260Ssaidi@eecs.umich.edu}
3453260Ssaidi@eecs.umich.edu
3469663Suri.wiener@arm.comstd::string
3479663Suri.wiener@arm.comPacket::print() const {
3489663Suri.wiener@arm.com    ostringstream str;
3499663Suri.wiener@arm.com    print(str);
3509663Suri.wiener@arm.com    return str.str();
3519663Suri.wiener@arm.com}
3529663Suri.wiener@arm.com
3535735Snate@binkert.orgPacket::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
3545735Snate@binkert.org    : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
3555314Sstever@gmail.com{
3565314Sstever@gmail.com    labelStack.push_back(LabelStackEntry("", curPrefixPtr));
3575314Sstever@gmail.com}
3585314Sstever@gmail.com
3595314Sstever@gmail.comPacket::PrintReqState::~PrintReqState()
3605314Sstever@gmail.com{
3615314Sstever@gmail.com    labelStack.pop_back();
3625314Sstever@gmail.com    assert(labelStack.empty());
3635314Sstever@gmail.com    delete curPrefixPtr;
3645314Sstever@gmail.com}
3655314Sstever@gmail.com
3665314Sstever@gmail.comPacket::PrintReqState::
3675735Snate@binkert.orgLabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
3685314Sstever@gmail.com    : label(_label), prefix(_prefix), labelPrinted(false)
3695314Sstever@gmail.com{
3705314Sstever@gmail.com}
3715314Sstever@gmail.com
3725314Sstever@gmail.comvoid
3735735Snate@binkert.orgPacket::PrintReqState::pushLabel(const string &lbl, const string &prefix)
3745314Sstever@gmail.com{
3755314Sstever@gmail.com    labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
3765735Snate@binkert.org    curPrefixPtr = new string(*curPrefixPtr);
3775314Sstever@gmail.com    *curPrefixPtr += prefix;
3785314Sstever@gmail.com}
3795314Sstever@gmail.com
3805314Sstever@gmail.comvoid
3815314Sstever@gmail.comPacket::PrintReqState::popLabel()
3825314Sstever@gmail.com{
3835314Sstever@gmail.com    delete curPrefixPtr;
3845314Sstever@gmail.com    curPrefixPtr = labelStack.back().prefix;
3855314Sstever@gmail.com    labelStack.pop_back();
3865314Sstever@gmail.com    assert(!labelStack.empty());
3875314Sstever@gmail.com}
3885314Sstever@gmail.com
3895314Sstever@gmail.comvoid
3905314Sstever@gmail.comPacket::PrintReqState::printLabels()
3915314Sstever@gmail.com{
3925314Sstever@gmail.com    if (!labelStack.back().labelPrinted) {
3935314Sstever@gmail.com        LabelStack::iterator i = labelStack.begin();
3945314Sstever@gmail.com        LabelStack::iterator end = labelStack.end();
3955314Sstever@gmail.com        while (i != end) {
3965314Sstever@gmail.com            if (!i->labelPrinted) {
3975314Sstever@gmail.com                ccprintf(os, "%s%s\n", *(i->prefix), i->label);
3985314Sstever@gmail.com                i->labelPrinted = true;
3995314Sstever@gmail.com            }
4005314Sstever@gmail.com            i++;
4015314Sstever@gmail.com        }
4025314Sstever@gmail.com    }
4035314Sstever@gmail.com}
4045314Sstever@gmail.com
4055314Sstever@gmail.com
4065314Sstever@gmail.comvoid
4075314Sstever@gmail.comPacket::PrintReqState::printObj(Printable *obj)
4085314Sstever@gmail.com{
4095314Sstever@gmail.com    printLabels();
4105314Sstever@gmail.com    obj->print(os, verbosity, curPrefix());
4115314Sstever@gmail.com}
412