m5: merged in hammer fix
[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 virtual ~FetchUnit();
59
60 typedef ThePipeline::DynInstPtr DynInstPtr;
61 typedef TheISA::ExtMachInst ExtMachInst;
62
63 struct FetchBlock {
64 int asid;
65 Addr addr;
66 uint8_t *block;
67 short cnt;
68 bool valid;
69
70 FetchBlock(int _asid, Addr _addr)
71 : asid(_asid), addr(_addr), block(NULL), cnt(1), valid(false)
72 { }
73 };
74
75 /** Actions that this resource can take on an instruction */
76 enum Command {
77 InitiateFetch,
78 CompleteFetch
79 };
80
81
82 ResourceRequest* getRequest(DynInstPtr _inst, int stage_num,
83 int res_idx, int slot_num,
84 unsigned cmd);
85
86 int getSlot(DynInstPtr inst);
87
88 /** Executes one of the commands from the "Command" enum */
89 void execute(int slot_num);
90
91 private:
92 void squashCacheRequest(CacheReqPtr req_ptr);
93
94 void createMachInst(std::list<FetchBlock*>::iterator fetch_it,
95 DynInstPtr inst);
96
97 /** After memory request is completed, then turn the fetched data
98 into an instruction.
99 */
100 void processCacheCompletion(PacketPtr pkt);
101
102 /** Create request that will interface w/TLB and Memory objects */
103 virtual void setupMemRequest(DynInstPtr inst, CacheReqPtr cache_req,
104 int acc_size, int flags);
105
106 /** Align a PC to the start of an I-cache block. */
107 Addr cacheBlockAlignPC(Addr addr)
108 {
109 return (addr & ~(cacheBlkMask));
110 }
111
112 void removeAddrDependency(DynInstPtr inst);
113
114 std::list<FetchBlock*>::iterator findReplacementBlock();
115 std::list<FetchBlock*>::iterator findBlock(std::list<FetchBlock*>
116 &fetch_blocks, int asid,
117 Addr block_addr);
118
119 void markBlockUsed(std::list<FetchBlock*>::iterator block_it);
120
121 int instSize;
122
123 int fetchBuffSize;
124
125 TheISA::Predecoder predecoder;
126
127 /** Valid Cache Blocks*/
128 std::list<FetchBlock*> fetchBuffer;
129
130 /** Cache lines that are pending */
131 std::list<FetchBlock*> pendingFetch;
132 };
133
134 #endif //__CPU_FETCH_UNIT_HH__