2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Definition of the Packet Class, a packet is a transaction occuring
35 * between a single level of the memory heirarchy (ie L1->L2).
40 #include "base/cprintf.hh"
41 #include "base/misc.hh"
42 #include "base/trace.hh"
43 #include "mem/packet.hh"
47 // The one downside to bitsets is that static initializers can get ugly.
48 #define SET1(a1) (1 << (a1))
49 #define SET2(a1, a2) (SET1(a1) | SET1(a2))
50 #define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
51 #define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
52 #define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
53 #define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
55 const MemCmd::CommandInfo
56 MemCmd::commandInfo
[] =
59 { 0, InvalidCmd
, "InvalidCmd" },
61 { SET3(IsRead
, IsRequest
, NeedsResponse
), ReadResp
, "ReadReq" },
63 { SET3(IsRead
, IsResponse
, HasData
), InvalidCmd
, "ReadResp" },
64 /* ReadRespWithInvalidate */
65 { SET4(IsRead
, IsResponse
, HasData
, IsInvalidate
),
66 InvalidCmd
, "ReadRespWithInvalidate" },
68 { SET5(IsWrite
, NeedsExclusive
, IsRequest
, NeedsResponse
, HasData
),
69 WriteResp
, "WriteReq" },
71 { SET3(IsWrite
, NeedsExclusive
, IsResponse
), InvalidCmd
, "WriteResp" },
73 { SET4(IsWrite
, NeedsExclusive
, IsRequest
, HasData
),
74 InvalidCmd
, "Writeback" },
76 { SET4(IsRead
, IsRequest
, IsSWPrefetch
, NeedsResponse
),
77 SoftPFResp
, "SoftPFReq" },
79 { SET4(IsRead
, IsRequest
, IsHWPrefetch
, NeedsResponse
),
80 HardPFResp
, "HardPFReq" },
82 { SET4(IsRead
, IsResponse
, IsSWPrefetch
, HasData
),
83 InvalidCmd
, "SoftPFResp" },
85 { SET4(IsRead
, IsResponse
, IsHWPrefetch
, HasData
),
86 InvalidCmd
, "HardPFResp" },
87 /* WriteInvalidateReq */
88 { SET6(IsWrite
, NeedsExclusive
, IsInvalidate
,
89 IsRequest
, HasData
, NeedsResponse
),
90 WriteInvalidateResp
, "WriteInvalidateReq" },
91 /* WriteInvalidateResp */
92 { SET3(IsWrite
, NeedsExclusive
, IsResponse
),
93 InvalidCmd
, "WriteInvalidateResp" },
95 { SET4(IsInvalidate
, NeedsExclusive
, IsRequest
, NeedsResponse
),
96 UpgradeResp
, "UpgradeReq" },
98 { SET2(NeedsExclusive
, IsResponse
),
99 InvalidCmd
, "UpgradeResp" },
101 { SET5(IsRead
, NeedsExclusive
, IsInvalidate
, IsRequest
, NeedsResponse
),
102 ReadExResp
, "ReadExReq" },
104 { SET4(IsRead
, NeedsExclusive
, IsResponse
, HasData
),
105 InvalidCmd
, "ReadExResp" },
106 /* LoadLockedReq: note that we use plain ReadResp as response, so that
107 * we can also use ReadRespWithInvalidate when needed */
108 { SET4(IsRead
, IsLlsc
, IsRequest
, NeedsResponse
),
109 ReadResp
, "LoadLockedReq" },
111 { SET6(IsWrite
, NeedsExclusive
, IsLlsc
,
112 IsRequest
, NeedsResponse
, HasData
),
113 StoreCondResp
, "StoreCondReq" },
115 { SET4(IsWrite
, NeedsExclusive
, IsLlsc
, IsResponse
),
116 InvalidCmd
, "StoreCondResp" },
117 /* SwapReq -- for Swap ldstub type operations */
118 { SET6(IsRead
, IsWrite
, NeedsExclusive
, IsRequest
, HasData
, NeedsResponse
),
119 SwapResp
, "SwapReq" },
120 /* SwapResp -- for Swap ldstub type operations */
121 { SET5(IsRead
, IsWrite
, NeedsExclusive
, IsResponse
, HasData
),
122 InvalidCmd
, "SwapResp" },
123 /* IntReq -- for interrupts */
124 { SET4(IsWrite
, IsRequest
, NeedsResponse
, HasData
),
125 MessageResp
, "MessageReq" },
126 /* IntResp -- for interrupts */
127 { SET2(IsWrite
, IsResponse
), InvalidCmd
, "MessageResp" },
128 /* NetworkNackError -- nacked at network layer (not by protocol) */
129 { SET2(IsResponse
, IsError
), InvalidCmd
, "NetworkNackError" },
130 /* InvalidDestError -- packet dest field invalid */
131 { SET2(IsResponse
, IsError
), InvalidCmd
, "InvalidDestError" },
132 /* BadAddressError -- memory address invalid */
133 { SET2(IsResponse
, IsError
), InvalidCmd
, "BadAddressError" },
135 { SET2(IsRequest
, IsPrint
), InvalidCmd
, "PrintReq" }
139 Packet::checkFunctional(Printable
*obj
, Addr addr
, int size
, uint8_t *data
)
141 Addr func_start
= getAddr();
142 Addr func_end
= getAddr() + getSize() - 1;
143 Addr val_start
= addr
;
144 Addr val_end
= val_start
+ size
- 1;
146 if (func_start
> val_end
|| val_start
> func_end
) {
151 // check print first since it doesn't require data
153 dynamic_cast<PrintReqState
*>(senderState
)->printObj(obj
);
157 // if there's no data, there's no need to look further
162 // offset of functional request into supplied value (could be
163 // negative if partial overlap)
164 int offset
= func_start
- val_start
;
167 if (func_start
>= val_start
&& func_end
<= val_end
) {
169 memcpy(getPtr
<uint8_t>(), data
+ offset
, getSize());
173 // In this case the timing packet only partially satisfies
174 // the request, so we would need more information to make
175 // this work. Like bytes valid in the packet or
176 // something, so the request could continue and get this
177 // bit of possibly newer data along with the older data
178 // not written to yet.
179 panic("Memory value only partially satisfies the functional "
180 "request. Now what?");
182 } else if (isWrite()) {
184 memcpy(data
+ offset
, getPtr
<uint8_t>(),
185 (min(func_end
, val_end
) - func_start
) + 1);
187 // val_start > func_start
188 memcpy(data
, getPtr
<uint8_t>() - offset
,
189 (min(func_end
, val_end
) - val_start
) + 1);
192 panic("Don't know how to handle command %s\n", cmdString());
195 // keep going with request by default
200 Packet::print(ostream
&o
, const int verbosity
, const string
&prefix
) const
202 ccprintf(o
, "%s[%x:%x] %s\n", prefix
,
203 getAddr(), getAddr() + getSize() - 1, cmdString());
206 Packet::PrintReqState::PrintReqState(ostream
&_os
, int _verbosity
)
207 : curPrefixPtr(new string("")), os(_os
), verbosity(_verbosity
)
209 labelStack
.push_back(LabelStackEntry("", curPrefixPtr
));
212 Packet::PrintReqState::~PrintReqState()
214 labelStack
.pop_back();
215 assert(labelStack
.empty());
219 Packet::PrintReqState::
220 LabelStackEntry::LabelStackEntry(const string
&_label
, string
*_prefix
)
221 : label(_label
), prefix(_prefix
), labelPrinted(false)
226 Packet::PrintReqState::pushLabel(const string
&lbl
, const string
&prefix
)
228 labelStack
.push_back(LabelStackEntry(lbl
, curPrefixPtr
));
229 curPrefixPtr
= new string(*curPrefixPtr
);
230 *curPrefixPtr
+= prefix
;
234 Packet::PrintReqState::popLabel()
237 curPrefixPtr
= labelStack
.back().prefix
;
238 labelStack
.pop_back();
239 assert(!labelStack
.empty());
243 Packet::PrintReqState::printLabels()
245 if (!labelStack
.back().labelPrinted
) {
246 LabelStack::iterator i
= labelStack
.begin();
247 LabelStack::iterator end
= labelStack
.end();
249 if (!i
->labelPrinted
) {
250 ccprintf(os
, "%s%s\n", *(i
->prefix
), i
->label
);
251 i
->labelPrinted
= true;
260 Packet::PrintReqState::printObj(Printable
*obj
)
263 obj
->print(os
, verbosity
, curPrefix());