inorder: treat SE mode syscalls as a trapping instruction
[gem5.git] / src / cpu / inorder / resources / execution_unit.cc
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
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 #include <list>
33 #include <vector>
34
35 #include "cpu/inorder/resources/execution_unit.hh"
36 #include "cpu/inorder/cpu.hh"
37 #include "cpu/inorder/resource_pool.hh"
38 #include "debug/InOrderExecute.hh"
39 #include "debug/InOrderStall.hh"
40
41 using namespace std;
42 using namespace ThePipeline;
43
44 ExecutionUnit::ExecutionUnit(string res_name, int res_id, int res_width,
45 int res_latency, InOrderCPU *_cpu,
46 ThePipeline::Params *params)
47 : Resource(res_name, res_id, res_width, res_latency, _cpu),
48 lastExecuteTick(0), lastControlTick(0), serializeTick(0)
49 { }
50
51 void
52 ExecutionUnit::regStats()
53 {
54 predictedTakenIncorrect
55 .name(name() + ".predictedTakenIncorrect")
56 .desc("Number of Branches Incorrectly Predicted As Taken.");
57
58 predictedNotTakenIncorrect
59 .name(name() + ".predictedNotTakenIncorrect")
60 .desc("Number of Branches Incorrectly Predicted As Not Taken).");
61
62 executions
63 .name(name() + ".executions")
64 .desc("Number of Instructions Executed.");
65
66
67 predictedIncorrect
68 .name(name() + ".mispredicted")
69 .desc("Number of Branches Incorrectly Predicted");
70
71 predictedCorrect
72 .name(name() + ".predicted")
73 .desc("Number of Branches Incorrectly Predicted");
74
75 mispredictPct
76 .name(name() + ".mispredictPct")
77 .desc("Percentage of Incorrect Branches Predicts")
78 .precision(6);
79 mispredictPct = (predictedIncorrect /
80 (predictedCorrect + predictedIncorrect)) * 100;
81
82 Resource::regStats();
83 }
84
85 void
86 ExecutionUnit::execute(int slot_num)
87 {
88 ResourceRequest* exec_req = reqs[slot_num];
89 DynInstPtr inst = reqs[slot_num]->inst;
90 Fault fault = NoFault;
91 Tick cur_tick = curTick();
92 unsigned stage_num = exec_req->getStageNum();
93 ThreadID tid = inst->readTid();
94 #if TRACING_ON
95 InstSeqNum seq_num = inst->seqNum;
96 #endif
97 if (cur_tick == serializeTick) {
98 DPRINTF(InOrderExecute, "Can not execute [tid:%i][sn:%i][PC:%s] %s. "
99 "All instructions are being serialized this cycle\n",
100 inst->readTid(), seq_num, inst->pcState(), inst->instName());
101 exec_req->done(false);
102 return;
103 }
104
105 switch (exec_req->cmd)
106 {
107 case ExecuteInst:
108 {
109 if (inst->isNop()) {
110 DPRINTF(InOrderExecute, "[tid:%i] [sn:%i] [PC:%s] Ignoring execution"
111 "of %s.\n", inst->readTid(), seq_num, inst->pcState(),
112 inst->instName());
113 inst->setExecuted();
114 exec_req->done();
115 return;
116 } else {
117 DPRINTF(InOrderExecute, "[tid:%i] Executing [sn:%i] [PC:%s] %s.\n",
118 inst->readTid(), seq_num, inst->pcState(), inst->instName());
119 }
120
121 if (cur_tick != lastExecuteTick) {
122 lastExecuteTick = cur_tick;
123 }
124
125 assert(!inst->isMemRef());
126
127 if (inst->isSerializeAfter()) {
128 serializeTick = cur_tick;
129 DPRINTF(InOrderExecute, "Serializing execution after [tid:%i] "
130 "[sn:%i] [PC:%s] %s.\n", inst->readTid(), seq_num,
131 inst->pcState(), inst->instName());
132 }
133
134 if (inst->isControl()) {
135 if (lastControlTick == cur_tick) {
136 DPRINTF(InOrderExecute, "Can not Execute More than One Control "
137 "Inst Per Cycle. Blocking Request.\n");
138 exec_req->done(false);
139 return;
140 }
141 lastControlTick = curTick();
142
143 // Evaluate Branch
144 fault = inst->execute();
145 executions++;
146
147 if (fault == NoFault) {
148 inst->setExecuted();
149
150 if (inst->mispredicted()) {
151 assert(inst->isControl());
152
153 // Set up Squash Generated By this Misprediction
154 TheISA::PCState pc = inst->pcState();
155 TheISA::advancePC(pc, inst->staticInst);
156 inst->setPredTarg(pc);
157 inst->setSquashInfo(stage_num);
158 setupSquash(inst, stage_num, tid);
159
160 DPRINTF(InOrderExecute, "[tid:%i]: [sn:%i] Squashing from "
161 "stage %i. Redirecting fetch to %s.\n", tid,
162 inst->seqNum, stage_num, pc);
163 DPRINTF(InOrderStall, "STALL: [tid:%i]: Branch"
164 " misprediction at %s\n", tid, inst->pcState());
165
166 if (inst->predTaken()) {
167 predictedTakenIncorrect++;
168 DPRINTF(InOrderExecute, "[tid:%i] [sn:%i] %s ..."
169 "PC %s ... Mispredicts! "
170 "(Prediction: Taken)\n",
171 tid, inst->seqNum,
172 inst->staticInst->disassemble(
173 inst->instAddr()),
174 inst->pcState());
175 } else {
176 predictedNotTakenIncorrect++;
177 DPRINTF(InOrderExecute, "[tid:%i] [sn:%i] %s ..."
178 "PC %s ... Mispredicts! "
179 "(Prediction: Not Taken)\n",
180 tid, inst->seqNum,
181 inst->staticInst->disassemble(
182 inst->instAddr()),
183 inst->pcState());
184 }
185 predictedIncorrect++;
186 } else {
187 DPRINTF(InOrderExecute, "[tid:%i]: [sn:%i]: Prediction"
188 "Correct.\n", inst->readTid(), seq_num);
189 predictedCorrect++;
190 }
191
192 exec_req->done();
193 } else {
194 DPRINTF(Fault, "[tid:%i]:[sn:%i]: Fault %s found\n",
195 inst->readTid(), inst->seqNum, fault->name());
196 inst->fault = fault;
197 exec_req->done();
198 }
199 } else {
200 // Regular ALU instruction
201 fault = inst->execute();
202 executions++;
203
204 if (fault == NoFault) {
205 inst->setExecuted();
206
207 DPRINTF(InOrderExecute, "[tid:%i]: [sn:%i]: The result "
208 "of execution is 0x%x.\n", inst->readTid(),
209 seq_num,
210 (inst->resultType(0) == InOrderDynInst::Float) ?
211 inst->readFloatResult(0) : inst->readIntResult(0));
212
213 #if !FULL_SYSTEM
214 // The Syscall might change the PC, so conservatively
215 // squash everything behing it
216 if (inst->isSyscall()) {
217 inst->setSquashInfo(stage_num);
218 setupSquash(inst, stage_num, tid);
219 }
220 #endif
221 } else {
222 DPRINTF(InOrderExecute, "[tid:%i]: [sn:%i]: had a %s "
223 "fault.\n", inst->readTid(), seq_num, fault->name());
224 DPRINTF(Fault, "[tid:%i]:[sn:%i]: Fault %s found\n",
225 inst->readTid(), inst->seqNum, fault->name());
226 inst->fault = fault;
227 }
228
229 exec_req->done();
230 }
231 }
232 break;
233
234 default:
235 fatal("Unrecognized command to %s", resName);
236 }
237 }
238
239