inorder: add a fetch buffer to fetch unit
[gem5.git] / src / cpu / inorder / resources / fetch_unit.hh
1 /*
2 * Copyright (c) 2011 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Korey Sewell
29 *
30 */
31
32 #ifndef __CPU_INORDER_FETCH_UNIT_HH__
33 #define __CPU_INORDER_FETCH_UNIT_HH__
34
35 #include <vector>
36 #include <list>
37 #include <string>
38
39 #include "arch/predecoder.hh"
40 #include "arch/tlb.hh"
41 #include "config/the_isa.hh"
42 #include "cpu/inorder/inorder_dyn_inst.hh"
43 #include "cpu/inorder/pipeline_traits.hh"
44 #include "cpu/inorder/resource.hh"
45 #include "cpu/inorder/resources/cache_unit.hh"
46 #include "mem/packet.hh"
47 #include "mem/packet_access.hh"
48 #include "mem/port.hh"
49 #include "params/InOrderCPU.hh"
50 #include "sim/sim_object.hh"
51
52 class FetchUnit : public CacheUnit
53 {
54 public:
55 FetchUnit(std::string res_name, int res_id, int res_width,
56 int res_latency, InOrderCPU *_cpu, ThePipeline::Params *params);
57
58 typedef ThePipeline::DynInstPtr DynInstPtr;
59 typedef TheISA::ExtMachInst ExtMachInst;
60
61 struct FetchBlock {
62 int asid;
63 Addr addr;
64 uint8_t *block;
65 short cnt;
66 bool valid;
67
68 FetchBlock(int _asid, Addr _addr)
69 : asid(_asid), addr(_addr), block(NULL), cnt(1), valid(false)
70 { }
71 };
72
73 /** Actions that this resource can take on an instruction */
74 enum Command {
75 InitiateFetch,
76 CompleteFetch
77 };
78
79
80 ResourceRequest* getRequest(DynInstPtr _inst, int stage_num,
81 int res_idx, int slot_num,
82 unsigned cmd);
83
84 int getSlot(DynInstPtr inst);
85
86 /** Executes one of the commands from the "Command" enum */
87 void execute(int slot_num);
88
89 private:
90 void squashCacheRequest(CacheReqPtr req_ptr);
91
92 void createMachInst(std::list<FetchBlock*>::iterator fetch_it,
93 DynInstPtr inst);
94
95 /** After memory request is completed, then turn the fetched data
96 into an instruction.
97 */
98 void processCacheCompletion(PacketPtr pkt);
99
100 /** Create request that will interface w/TLB and Memory objects */
101 virtual void setupMemRequest(DynInstPtr inst, CacheReqPtr cache_req,
102 int acc_size, int flags);
103
104 /** Align a PC to the start of an I-cache block. */
105 Addr cacheBlockAlignPC(Addr addr)
106 {
107 return (addr & ~(cacheBlkMask));
108 }
109
110 void removeAddrDependency(DynInstPtr inst);
111
112 std::list<FetchBlock*>::iterator findReplacementBlock();
113 std::list<FetchBlock*>::iterator findBlock(std::list<FetchBlock*>
114 &fetch_blocks, int asid,
115 Addr block_addr);
116
117 void markBlockUsed(std::list<FetchBlock*>::iterator block_it);
118
119 int instSize;
120
121 int fetchBuffSize;
122
123 TheISA::Predecoder predecoder;
124
125 /** Valid Cache Blocks*/
126 std::list<FetchBlock*> fetchBuffer;
127
128 /** Cache lines that are pending */
129 std::list<FetchBlock*> pendingFetch;
130 };
131
132 #endif //__CPU_FETCH_UNIT_HH__