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.
31 #ifndef __CPU_OZONE_INORDER_BACK_END_HH__
32 #define __CPU_OZONE_INORDER_BACK_END_HH__
36 #include "sim/faults.hh"
37 #include "base/timebuf.hh"
38 #include "cpu/thread_context.hh"
39 #include "cpu/inst_seq.hh"
40 #include "cpu/ozone/rename_table.hh"
41 #include "cpu/ozone/thread_state.hh"
42 #include "mem/request.hh"
43 #include "sim/eventq.hh"
49 typedef typename Impl::Params Params;
50 typedef typename Impl::DynInstPtr DynInstPtr;
51 typedef typename Impl::FullCPU FullCPU;
52 typedef typename Impl::FrontEnd FrontEnd;
54 typedef typename FullCPU::OzoneTC OzoneTC;
55 typedef typename Impl::FullCPU::CommStruct CommStruct;
57 InorderBackEnd(Params *params);
59 std::string name() const;
61 void setCPU(FullCPU *cpu_ptr)
64 void setFrontEnd(FrontEnd *front_end_ptr)
65 { frontEnd = front_end_ptr; }
67 void setCommBuffer(TimeBuffer<CommStruct> *_comm)
70 void setTC(ThreadContext *tc_ptr);
72 void setThreadState(OzoneThreadState<Impl> *thread_ptr);
77 void checkInterrupts();
82 void squash(const InstSeqNum &squash_num, const Addr &next_PC);
85 void generateXCEvent() { }
87 bool robEmpty() { return instList.empty(); }
89 bool isFull() { return false; }
90 bool isBlocked() { return status == DcacheMissStoreStall ||
91 status == DcacheMissLoadStall ||
94 void fetchFault(Fault &fault);
101 void setSquashInfoFromTC();
104 InstSeqNum squashSeqNum;
107 Fault faultFromFetch;
109 bool interruptBlocked;
113 Fault read(Addr addr, T &data, unsigned flags);
116 Fault read(RequestPtr req, T &data, int load_idx);
119 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
122 Fault write(RequestPtr req, T &data, int store_idx);
124 Addr readCommitPC() { return commitPC; }
128 void switchOut() { panic("Not implemented!"); }
129 void doSwitchOut() { panic("Not implemented!"); }
130 void takeOverFrom(ThreadContext *old_tc = NULL) { panic("Not implemented!"); }
139 OzoneThreadState<Impl> *thread;
141 RenameTable<Impl> renameTable;
148 DcacheMissStoreStall,
155 class DCacheCompletionEvent : public Event
161 DCacheCompletionEvent(InorderBackEnd *_be);
163 virtual void process();
164 virtual const char *description() const;
169 friend class DCacheCompletionEvent;
171 DCacheCompletionEvent cacheCompletionEvent;
173 // MemInterface *dcacheInterface;
178 typedef typename std::list<DynInstPtr>::iterator InstListIt;
180 std::list<DynInstPtr> instList;
182 // General back end width. Used if the more specific isn't given.
189 TimeBuffer<int> numInstsToWB;
190 TimeBuffer<int>::wire instsAdded;
191 TimeBuffer<int>::wire instsToExecute;
193 TimeBuffer<CommStruct> *comm;
194 // number of cycles stalled for D-cache misses
195 Stats::Scalar<> dcacheStallCycles;
196 Counter lastDcacheStall;
199 template <class Impl>
202 InorderBackEnd<Impl>::read(Addr addr, T &data, unsigned flags)
204 memReq->reset(addr, sizeof(T), flags);
206 // translate to physical address
207 Fault fault = cpu->translateDataReadReq(memReq);
209 // if we have a cache, do cache access too
210 if (fault == NoFault && dcacheInterface) {
212 memReq->completionEvent = NULL;
213 memReq->time = curTick;
214 memReq->flags &= ~INST_READ;
215 MemAccessResult result = dcacheInterface->access(memReq);
217 // Ugly hack to get an event scheduled *only* if the access is
218 // a miss. We really should add first-class support for this
220 if (result != MA_HIT) {
221 // Fix this hack for keeping funcExeInst correct with loads that
222 // are executed twice.
223 memReq->completionEvent = &cacheCompletionEvent;
224 lastDcacheStall = curTick;
225 // unscheduleTickEvent();
226 status = DcacheMissLoadStall;
227 DPRINTF(IBE, "Dcache miss stall!\n");
229 // do functional access
230 DPRINTF(IBE, "Dcache hit!\n");
234 if (!dcacheInterface && (memReq->isUncacheable()))
235 recordEvent("Uncached Read");
240 template <class Impl>
243 InorderBackEnd<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
245 memReq->reset(addr, sizeof(T), flags);
247 // translate to physical address
248 Fault fault = cpu->translateDataWriteReq(memReq);
250 if (fault == NoFault && dcacheInterface) {
252 // memcpy(memReq->data,(uint8_t *)&data,memReq->size);
253 memReq->completionEvent = NULL;
254 memReq->time = curTick;
255 memReq->flags &= ~INST_READ;
256 MemAccessResult result = dcacheInterface->access(memReq);
258 // Ugly hack to get an event scheduled *only* if the access is
259 // a miss. We really should add first-class support for this
261 if (result != MA_HIT) {
262 memReq->completionEvent = &cacheCompletionEvent;
263 lastDcacheStall = curTick;
264 // unscheduleTickEvent();
265 status = DcacheMissStoreStall;
266 DPRINTF(IBE, "Dcache miss stall!\n");
268 DPRINTF(IBE, "Dcache hit!\n");
272 if (res && (fault == NoFault))
273 *res = memReq->result;
275 if (!dcacheInterface && (memReq->isUncacheable()))
276 recordEvent("Uncached Write");
281 template <class Impl>
284 InorderBackEnd<Impl>::read(MemReqPtr &req, T &data, int load_idx)
286 // panic("Unimplemented!");
287 // memReq->reset(addr, sizeof(T), flags);
289 // translate to physical address
290 // Fault fault = cpu->translateDataReadReq(req);
292 req->completionEvent = NULL;
295 req->data = new uint8_t[64];
296 req->flags &= ~INST_READ;
297 Fault fault = cpu->read(req, data);
298 memcpy(req->data, &data, sizeof(T));
300 // if we have a cache, do cache access too
301 if (dcacheInterface) {
302 MemAccessResult result = dcacheInterface->access(req);
304 // Ugly hack to get an event scheduled *only* if the access is
305 // a miss. We really should add first-class support for this
307 if (result != MA_HIT) {
308 req->completionEvent = &cacheCompletionEvent;
309 lastDcacheStall = curTick;
310 // unscheduleTickEvent();
311 status = DcacheMissLoadStall;
312 DPRINTF(IBE, "Dcache miss load stall!\n");
314 DPRINTF(IBE, "Dcache hit!\n");
320 if (!dcacheInterface && (req->isUncacheable()))
321 recordEvent("Uncached Read");
326 template <class Impl>
329 InorderBackEnd<Impl>::write(MemReqPtr &req, T &data, int store_idx)
331 // req->reset(addr, sizeof(T), flags);
333 // translate to physical address
334 // Fault fault = cpu->translateDataWriteReq(req);
337 req->completionEvent = NULL;
340 req->data = new uint8_t[64];
341 memcpy(req->data, (uint8_t *)&data, req->size);
345 cpu->write(req, (uint8_t &)data);
348 cpu->write(req, (uint16_t &)data);
351 cpu->write(req, (uint32_t &)data);
354 cpu->write(req, (uint64_t &)data);
357 panic("Unexpected store size!\n");
360 if (dcacheInterface) {
362 req->data = new uint8_t[64];
363 memcpy(req->data,(uint8_t *)&data,req->size);
364 req->completionEvent = NULL;
366 req->flags &= ~INST_READ;
367 MemAccessResult result = dcacheInterface->access(req);
369 // Ugly hack to get an event scheduled *only* if the access is
370 // a miss. We really should add first-class support for this
372 if (result != MA_HIT) {
373 req->completionEvent = &cacheCompletionEvent;
374 lastDcacheStall = curTick;
375 // unscheduleTickEvent();
376 status = DcacheMissStoreStall;
377 DPRINTF(IBE, "Dcache miss store stall!\n");
379 DPRINTF(IBE, "Dcache hit!\n");
384 if (req->isLocked()) {
385 if (req->isUncacheable()) {
386 // Don't update result register (see stq_c in isa_desc)
394 if (res && (fault == NoFault))
398 if (!dcacheInterface && (req->isUncacheable()))
399 recordEvent("Uncached Write");
404 #endif // __CPU_OZONE_INORDER_BACK_END_HH__