base.cc (4156:a4667c990e12) base.cc (4181:6edaeff44647)
1/*
2 * Copyright (c) 2002-2005 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: Steve Reinhardt
29 */
30
31#include "arch/utility.hh"
32#include "arch/faults.hh"
33#include "base/cprintf.hh"
34#include "base/inifile.hh"
35#include "base/loader/symtab.hh"
36#include "base/misc.hh"
37#include "base/pollevent.hh"
38#include "base/range.hh"
39#include "base/stats/events.hh"
40#include "base/trace.hh"
41#include "cpu/base.hh"
42#include "cpu/exetrace.hh"
43#include "cpu/profile.hh"
44#include "cpu/simple/base.hh"
45#include "cpu/simple_thread.hh"
46#include "cpu/smt.hh"
47#include "cpu/static_inst.hh"
48#include "cpu/thread_context.hh"
49#include "mem/packet.hh"
50#include "sim/builder.hh"
51#include "sim/byteswap.hh"
52#include "sim/debug.hh"
53#include "sim/host.hh"
54#include "sim/sim_events.hh"
55#include "sim/sim_object.hh"
56#include "sim/stats.hh"
57#include "sim/system.hh"
58
59#if FULL_SYSTEM
60#include "arch/kernel_stats.hh"
61#include "arch/stacktrace.hh"
62#include "arch/tlb.hh"
63#include "arch/vtophys.hh"
64#include "base/remote_gdb.hh"
65#else // !FULL_SYSTEM
66#include "mem/mem_object.hh"
67#endif // FULL_SYSTEM
68
69using namespace std;
70using namespace TheISA;
71
72BaseSimpleCPU::BaseSimpleCPU(Params *p)
73 : BaseCPU(p), thread(NULL)
74{
75#if FULL_SYSTEM
76 thread = new SimpleThread(this, 0, p->system, p->itb, p->dtb);
77#else
78 thread = new SimpleThread(this, /* thread_num */ 0, p->process,
79 /* asid */ 0);
80#endif // !FULL_SYSTEM
81
82 thread->setStatus(ThreadContext::Suspended);
83
84 tc = thread->getTC();
85
86 numInst = 0;
87 startNumInst = 0;
88 numLoad = 0;
89 startNumLoad = 0;
90 lastIcacheStall = 0;
91 lastDcacheStall = 0;
92
93 threadContexts.push_back(tc);
94}
95
96BaseSimpleCPU::~BaseSimpleCPU()
97{
98}
99
100void
101BaseSimpleCPU::deallocateContext(int thread_num)
102{
103 // for now, these are equivalent
104 suspendContext(thread_num);
105}
106
107
108void
109BaseSimpleCPU::haltContext(int thread_num)
110{
111 // for now, these are equivalent
112 suspendContext(thread_num);
113}
114
115
116void
117BaseSimpleCPU::regStats()
118{
119 using namespace Stats;
120
121 BaseCPU::regStats();
122
123 numInsts
124 .name(name() + ".num_insts")
125 .desc("Number of instructions executed")
126 ;
127
128 numMemRefs
129 .name(name() + ".num_refs")
130 .desc("Number of memory references")
131 ;
132
133 notIdleFraction
134 .name(name() + ".not_idle_fraction")
135 .desc("Percentage of non-idle cycles")
136 ;
137
138 idleFraction
139 .name(name() + ".idle_fraction")
140 .desc("Percentage of idle cycles")
141 ;
142
143 icacheStallCycles
144 .name(name() + ".icache_stall_cycles")
145 .desc("ICache total stall cycles")
146 .prereq(icacheStallCycles)
147 ;
148
149 dcacheStallCycles
150 .name(name() + ".dcache_stall_cycles")
151 .desc("DCache total stall cycles")
152 .prereq(dcacheStallCycles)
153 ;
154
155 icacheRetryCycles
156 .name(name() + ".icache_retry_cycles")
157 .desc("ICache total retry cycles")
158 .prereq(icacheRetryCycles)
159 ;
160
161 dcacheRetryCycles
162 .name(name() + ".dcache_retry_cycles")
163 .desc("DCache total retry cycles")
164 .prereq(dcacheRetryCycles)
165 ;
166
167 idleFraction = constant(1.0) - notIdleFraction;
168}
169
170void
171BaseSimpleCPU::resetStats()
172{
173// startNumInst = numInst;
174 // notIdleFraction = (_status != Idle);
175}
176
177void
178BaseSimpleCPU::serialize(ostream &os)
179{
180 BaseCPU::serialize(os);
181// SERIALIZE_SCALAR(inst);
182 nameOut(os, csprintf("%s.xc.0", name()));
183 thread->serialize(os);
184}
185
186void
187BaseSimpleCPU::unserialize(Checkpoint *cp, const string &section)
188{
189 BaseCPU::unserialize(cp, section);
190// UNSERIALIZE_SCALAR(inst);
191 thread->unserialize(cp, csprintf("%s.xc.0", section));
192}
193
194void
195change_thread_state(int thread_number, int activate, int priority)
196{
197}
198
199Fault
200BaseSimpleCPU::copySrcTranslate(Addr src)
201{
202#if 0
203 static bool no_warn = true;
204 int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64;
205 // Only support block sizes of 64 atm.
206 assert(blk_size == 64);
207 int offset = src & (blk_size - 1);
208
209 // Make sure block doesn't span page
210 if (no_warn &&
211 (src & PageMask) != ((src + blk_size) & PageMask) &&
212 (src >> 40) != 0xfffffc) {
213 warn("Copied block source spans pages %x.", src);
214 no_warn = false;
215 }
216
217 memReq->reset(src & ~(blk_size - 1), blk_size);
218
219 // translate to physical address
220 Fault fault = thread->translateDataReadReq(req);
221
222 if (fault == NoFault) {
223 thread->copySrcAddr = src;
224 thread->copySrcPhysAddr = memReq->paddr + offset;
225 } else {
226 assert(!fault->isAlignmentFault());
227
228 thread->copySrcAddr = 0;
229 thread->copySrcPhysAddr = 0;
230 }
231 return fault;
232#else
233 return NoFault;
234#endif
235}
236
237Fault
238BaseSimpleCPU::copy(Addr dest)
239{
240#if 0
241 static bool no_warn = true;
242 int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64;
243 // Only support block sizes of 64 atm.
244 assert(blk_size == 64);
245 uint8_t data[blk_size];
246 //assert(thread->copySrcAddr);
247 int offset = dest & (blk_size - 1);
248
249 // Make sure block doesn't span page
250 if (no_warn &&
251 (dest & PageMask) != ((dest + blk_size) & PageMask) &&
252 (dest >> 40) != 0xfffffc) {
253 no_warn = false;
254 warn("Copied block destination spans pages %x. ", dest);
255 }
256
257 memReq->reset(dest & ~(blk_size -1), blk_size);
258 // translate to physical address
259 Fault fault = thread->translateDataWriteReq(req);
260
261 if (fault == NoFault) {
262 Addr dest_addr = memReq->paddr + offset;
263 // Need to read straight from memory since we have more than 8 bytes.
264 memReq->paddr = thread->copySrcPhysAddr;
265 thread->mem->read(memReq, data);
266 memReq->paddr = dest_addr;
267 thread->mem->write(memReq, data);
268 if (dcacheInterface) {
269 memReq->cmd = Copy;
270 memReq->completionEvent = NULL;
271 memReq->paddr = thread->copySrcPhysAddr;
272 memReq->dest = dest_addr;
273 memReq->size = 64;
274 memReq->time = curTick;
275 memReq->flags &= ~INST_READ;
276 dcacheInterface->access(memReq);
277 }
278 }
279 else
280 assert(!fault->isAlignmentFault());
281
282 return fault;
283#else
284 panic("copy not implemented");
285 return NoFault;
286#endif
287}
288
289#if FULL_SYSTEM
290Addr
291BaseSimpleCPU::dbg_vtophys(Addr addr)
292{
293 return vtophys(tc, addr);
294}
295#endif // FULL_SYSTEM
296
297#if FULL_SYSTEM
298void
299BaseSimpleCPU::post_interrupt(int int_num, int index)
300{
301 BaseCPU::post_interrupt(int_num, index);
302
303 if (thread->status() == ThreadContext::Suspended) {
304 DPRINTF(IPI,"Suspended Processor awoke\n");
305 thread->activate();
306 }
307}
308#endif // FULL_SYSTEM
309
310void
311BaseSimpleCPU::checkForInterrupts()
312{
313#if FULL_SYSTEM
314 if (check_interrupts(tc)) {
315 Fault interrupt = interrupts.getInterrupt(tc);
316
317 if (interrupt != NoFault) {
318 interrupts.updateIntrInfo(tc);
319 interrupt->invoke(tc);
320 }
321 }
322#endif
323}
324
325
326Fault
327BaseSimpleCPU::setupFetchRequest(Request *req)
328{
329 // set up memory request for instruction fetch
330#if ISA_HAS_DELAY_SLOT
331 DPRINTF(Fetch,"Fetch: PC:%08p NPC:%08p NNPC:%08p\n",thread->readPC(),
332 thread->readNextPC(),thread->readNextNPC());
333#else
334 DPRINTF(Fetch,"Fetch: PC:%08p NPC:%08p",thread->readPC(),
335 thread->readNextPC());
336#endif
337
338 req->setVirt(0, thread->readPC() & ~3, sizeof(MachInst),
339 (FULL_SYSTEM && (thread->readPC() & 1)) ? PHYSICAL : 0,
340 thread->readPC());
341
342 Fault fault = thread->translateInstReq(req);
343
344 return fault;
345}
346
347
348void
349BaseSimpleCPU::preExecute()
350{
351 // maintain $r0 semantics
352 thread->setIntReg(ZeroReg, 0);
353#if THE_ISA == ALPHA_ISA
354 thread->setFloatReg(ZeroReg, 0.0);
355#endif // ALPHA_ISA
356
357 // keep an instruction count
358 numInst++;
359 numInsts++;
360
361 thread->funcExeInst++;
362
363 // check for instruction-count-based events
364 comInstEventQueue[0]->serviceEvents(numInst);
365
366 // decode the instruction
367 inst = gtoh(inst);
368 //If we're not in the middle of a macro instruction
369 if (!curMacroStaticInst) {
1/*
2 * Copyright (c) 2002-2005 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: Steve Reinhardt
29 */
30
31#include "arch/utility.hh"
32#include "arch/faults.hh"
33#include "base/cprintf.hh"
34#include "base/inifile.hh"
35#include "base/loader/symtab.hh"
36#include "base/misc.hh"
37#include "base/pollevent.hh"
38#include "base/range.hh"
39#include "base/stats/events.hh"
40#include "base/trace.hh"
41#include "cpu/base.hh"
42#include "cpu/exetrace.hh"
43#include "cpu/profile.hh"
44#include "cpu/simple/base.hh"
45#include "cpu/simple_thread.hh"
46#include "cpu/smt.hh"
47#include "cpu/static_inst.hh"
48#include "cpu/thread_context.hh"
49#include "mem/packet.hh"
50#include "sim/builder.hh"
51#include "sim/byteswap.hh"
52#include "sim/debug.hh"
53#include "sim/host.hh"
54#include "sim/sim_events.hh"
55#include "sim/sim_object.hh"
56#include "sim/stats.hh"
57#include "sim/system.hh"
58
59#if FULL_SYSTEM
60#include "arch/kernel_stats.hh"
61#include "arch/stacktrace.hh"
62#include "arch/tlb.hh"
63#include "arch/vtophys.hh"
64#include "base/remote_gdb.hh"
65#else // !FULL_SYSTEM
66#include "mem/mem_object.hh"
67#endif // FULL_SYSTEM
68
69using namespace std;
70using namespace TheISA;
71
72BaseSimpleCPU::BaseSimpleCPU(Params *p)
73 : BaseCPU(p), thread(NULL)
74{
75#if FULL_SYSTEM
76 thread = new SimpleThread(this, 0, p->system, p->itb, p->dtb);
77#else
78 thread = new SimpleThread(this, /* thread_num */ 0, p->process,
79 /* asid */ 0);
80#endif // !FULL_SYSTEM
81
82 thread->setStatus(ThreadContext::Suspended);
83
84 tc = thread->getTC();
85
86 numInst = 0;
87 startNumInst = 0;
88 numLoad = 0;
89 startNumLoad = 0;
90 lastIcacheStall = 0;
91 lastDcacheStall = 0;
92
93 threadContexts.push_back(tc);
94}
95
96BaseSimpleCPU::~BaseSimpleCPU()
97{
98}
99
100void
101BaseSimpleCPU::deallocateContext(int thread_num)
102{
103 // for now, these are equivalent
104 suspendContext(thread_num);
105}
106
107
108void
109BaseSimpleCPU::haltContext(int thread_num)
110{
111 // for now, these are equivalent
112 suspendContext(thread_num);
113}
114
115
116void
117BaseSimpleCPU::regStats()
118{
119 using namespace Stats;
120
121 BaseCPU::regStats();
122
123 numInsts
124 .name(name() + ".num_insts")
125 .desc("Number of instructions executed")
126 ;
127
128 numMemRefs
129 .name(name() + ".num_refs")
130 .desc("Number of memory references")
131 ;
132
133 notIdleFraction
134 .name(name() + ".not_idle_fraction")
135 .desc("Percentage of non-idle cycles")
136 ;
137
138 idleFraction
139 .name(name() + ".idle_fraction")
140 .desc("Percentage of idle cycles")
141 ;
142
143 icacheStallCycles
144 .name(name() + ".icache_stall_cycles")
145 .desc("ICache total stall cycles")
146 .prereq(icacheStallCycles)
147 ;
148
149 dcacheStallCycles
150 .name(name() + ".dcache_stall_cycles")
151 .desc("DCache total stall cycles")
152 .prereq(dcacheStallCycles)
153 ;
154
155 icacheRetryCycles
156 .name(name() + ".icache_retry_cycles")
157 .desc("ICache total retry cycles")
158 .prereq(icacheRetryCycles)
159 ;
160
161 dcacheRetryCycles
162 .name(name() + ".dcache_retry_cycles")
163 .desc("DCache total retry cycles")
164 .prereq(dcacheRetryCycles)
165 ;
166
167 idleFraction = constant(1.0) - notIdleFraction;
168}
169
170void
171BaseSimpleCPU::resetStats()
172{
173// startNumInst = numInst;
174 // notIdleFraction = (_status != Idle);
175}
176
177void
178BaseSimpleCPU::serialize(ostream &os)
179{
180 BaseCPU::serialize(os);
181// SERIALIZE_SCALAR(inst);
182 nameOut(os, csprintf("%s.xc.0", name()));
183 thread->serialize(os);
184}
185
186void
187BaseSimpleCPU::unserialize(Checkpoint *cp, const string &section)
188{
189 BaseCPU::unserialize(cp, section);
190// UNSERIALIZE_SCALAR(inst);
191 thread->unserialize(cp, csprintf("%s.xc.0", section));
192}
193
194void
195change_thread_state(int thread_number, int activate, int priority)
196{
197}
198
199Fault
200BaseSimpleCPU::copySrcTranslate(Addr src)
201{
202#if 0
203 static bool no_warn = true;
204 int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64;
205 // Only support block sizes of 64 atm.
206 assert(blk_size == 64);
207 int offset = src & (blk_size - 1);
208
209 // Make sure block doesn't span page
210 if (no_warn &&
211 (src & PageMask) != ((src + blk_size) & PageMask) &&
212 (src >> 40) != 0xfffffc) {
213 warn("Copied block source spans pages %x.", src);
214 no_warn = false;
215 }
216
217 memReq->reset(src & ~(blk_size - 1), blk_size);
218
219 // translate to physical address
220 Fault fault = thread->translateDataReadReq(req);
221
222 if (fault == NoFault) {
223 thread->copySrcAddr = src;
224 thread->copySrcPhysAddr = memReq->paddr + offset;
225 } else {
226 assert(!fault->isAlignmentFault());
227
228 thread->copySrcAddr = 0;
229 thread->copySrcPhysAddr = 0;
230 }
231 return fault;
232#else
233 return NoFault;
234#endif
235}
236
237Fault
238BaseSimpleCPU::copy(Addr dest)
239{
240#if 0
241 static bool no_warn = true;
242 int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64;
243 // Only support block sizes of 64 atm.
244 assert(blk_size == 64);
245 uint8_t data[blk_size];
246 //assert(thread->copySrcAddr);
247 int offset = dest & (blk_size - 1);
248
249 // Make sure block doesn't span page
250 if (no_warn &&
251 (dest & PageMask) != ((dest + blk_size) & PageMask) &&
252 (dest >> 40) != 0xfffffc) {
253 no_warn = false;
254 warn("Copied block destination spans pages %x. ", dest);
255 }
256
257 memReq->reset(dest & ~(blk_size -1), blk_size);
258 // translate to physical address
259 Fault fault = thread->translateDataWriteReq(req);
260
261 if (fault == NoFault) {
262 Addr dest_addr = memReq->paddr + offset;
263 // Need to read straight from memory since we have more than 8 bytes.
264 memReq->paddr = thread->copySrcPhysAddr;
265 thread->mem->read(memReq, data);
266 memReq->paddr = dest_addr;
267 thread->mem->write(memReq, data);
268 if (dcacheInterface) {
269 memReq->cmd = Copy;
270 memReq->completionEvent = NULL;
271 memReq->paddr = thread->copySrcPhysAddr;
272 memReq->dest = dest_addr;
273 memReq->size = 64;
274 memReq->time = curTick;
275 memReq->flags &= ~INST_READ;
276 dcacheInterface->access(memReq);
277 }
278 }
279 else
280 assert(!fault->isAlignmentFault());
281
282 return fault;
283#else
284 panic("copy not implemented");
285 return NoFault;
286#endif
287}
288
289#if FULL_SYSTEM
290Addr
291BaseSimpleCPU::dbg_vtophys(Addr addr)
292{
293 return vtophys(tc, addr);
294}
295#endif // FULL_SYSTEM
296
297#if FULL_SYSTEM
298void
299BaseSimpleCPU::post_interrupt(int int_num, int index)
300{
301 BaseCPU::post_interrupt(int_num, index);
302
303 if (thread->status() == ThreadContext::Suspended) {
304 DPRINTF(IPI,"Suspended Processor awoke\n");
305 thread->activate();
306 }
307}
308#endif // FULL_SYSTEM
309
310void
311BaseSimpleCPU::checkForInterrupts()
312{
313#if FULL_SYSTEM
314 if (check_interrupts(tc)) {
315 Fault interrupt = interrupts.getInterrupt(tc);
316
317 if (interrupt != NoFault) {
318 interrupts.updateIntrInfo(tc);
319 interrupt->invoke(tc);
320 }
321 }
322#endif
323}
324
325
326Fault
327BaseSimpleCPU::setupFetchRequest(Request *req)
328{
329 // set up memory request for instruction fetch
330#if ISA_HAS_DELAY_SLOT
331 DPRINTF(Fetch,"Fetch: PC:%08p NPC:%08p NNPC:%08p\n",thread->readPC(),
332 thread->readNextPC(),thread->readNextNPC());
333#else
334 DPRINTF(Fetch,"Fetch: PC:%08p NPC:%08p",thread->readPC(),
335 thread->readNextPC());
336#endif
337
338 req->setVirt(0, thread->readPC() & ~3, sizeof(MachInst),
339 (FULL_SYSTEM && (thread->readPC() & 1)) ? PHYSICAL : 0,
340 thread->readPC());
341
342 Fault fault = thread->translateInstReq(req);
343
344 return fault;
345}
346
347
348void
349BaseSimpleCPU::preExecute()
350{
351 // maintain $r0 semantics
352 thread->setIntReg(ZeroReg, 0);
353#if THE_ISA == ALPHA_ISA
354 thread->setFloatReg(ZeroReg, 0.0);
355#endif // ALPHA_ISA
356
357 // keep an instruction count
358 numInst++;
359 numInsts++;
360
361 thread->funcExeInst++;
362
363 // check for instruction-count-based events
364 comInstEventQueue[0]->serviceEvents(numInst);
365
366 // decode the instruction
367 inst = gtoh(inst);
368 //If we're not in the middle of a macro instruction
369 if (!curMacroStaticInst) {
370#if THE_ISA == ALPHA_ISA
371 StaticInstPtr instPtr = StaticInst::decode(makeExtMI(inst, thread->readPC()));
372#elif THE_ISA == SPARC_ISA
373 StaticInstPtr instPtr = StaticInst::decode(makeExtMI(inst, thread->getTC()));
374#elif THE_ISA == X86_ISA
375 StaticInstPtr instPtr = StaticInst::decode(makeExtMI(inst, thread->getTC()));
376#elif THE_ISA == MIPS_ISA
377 //Mips doesn't do anything in it's MakeExtMI function right now,
378 //so it won't be called.
379 StaticInstPtr instPtr = StaticInst::decode(inst);
380#endif
381 if (instPtr->isMacroOp()) {
370 StaticInstPtr instPtr = NULL;
371
372 //Predecode, ie bundle up an ExtMachInst
373 unsigned int result =
374 predecode(extMachInst, thread->readPC(), inst, thread->getTC());
375 //If an instruction is ready, decode it
376 if (result & ExtMIReady)
377 instPtr = StaticInst::decode(extMachInst);
378
379 //If we decoded an instruction and it's microcoded, start pulling
380 //out micro ops
381 if (instPtr && instPtr->isMacroOp()) {
382 curMacroStaticInst = instPtr;
383 curStaticInst = curMacroStaticInst->
384 fetchMicroOp(thread->readMicroPC());
385 } else {
386 curStaticInst = instPtr;
387 }
388 } else {
389 //Read the next micro op from the macro op
390 curStaticInst = curMacroStaticInst->
391 fetchMicroOp(thread->readMicroPC());
392 }
393
382 curMacroStaticInst = instPtr;
383 curStaticInst = curMacroStaticInst->
384 fetchMicroOp(thread->readMicroPC());
385 } else {
386 curStaticInst = instPtr;
387 }
388 } else {
389 //Read the next micro op from the macro op
390 curStaticInst = curMacroStaticInst->
391 fetchMicroOp(thread->readMicroPC());
392 }
393
394 //If we decoded an instruction this "tick", record information about it.
395 if(curStaticInst)
396 {
397 traceData = Trace::getInstRecord(curTick, tc, curStaticInst,
398 thread->readPC());
394
399
395 traceData = Trace::getInstRecord(curTick, tc, curStaticInst,
396 thread->readPC());
400 DPRINTF(Decode,"Decode: Decoded %s instruction: 0x%x\n",
401 curStaticInst->getName(), curStaticInst->machInst);
397
402
398 DPRINTF(Decode,"Decode: Decoded %s instruction (opcode: 0x%x): 0x%x\n",
399 curStaticInst->getName(), curStaticInst->getOpcode(),
400 curStaticInst->machInst);
401
402#if FULL_SYSTEM
403#if FULL_SYSTEM
403 thread->setInst(inst);
404 thread->setInst(inst);
404#endif // FULL_SYSTEM
405#endif // FULL_SYSTEM
406 }
405}
406
407void
408BaseSimpleCPU::postExecute()
409{
410#if FULL_SYSTEM
411 if (thread->profile) {
412 bool usermode = TheISA::inUserMode(tc);
413 thread->profilePC = usermode ? 1 : thread->readPC();
414 ProfileNode *node = thread->profile->consume(tc, inst);
415 if (node)
416 thread->profileNode = node;
417 }
418#endif
419
420 if (curStaticInst->isMemRef()) {
421 numMemRefs++;
422 }
423
424 if (curStaticInst->isLoad()) {
425 ++numLoad;
426 comLoadEventQueue[0]->serviceEvents(numLoad);
427 }
428
429 traceFunctions(thread->readPC());
430
431 if (traceData) {
432 traceData->dump();
433 delete traceData;
434 traceData = NULL;
435 }
436}
437
438
439void
440BaseSimpleCPU::advancePC(Fault fault)
441{
442 if (fault != NoFault) {
443 curMacroStaticInst = StaticInst::nullStaticInstPtr;
444 fault->invoke(tc);
445 thread->setMicroPC(0);
446 thread->setNextMicroPC(1);
447 } else {
448 //If we're at the last micro op for this instruction
449 if (curStaticInst->isLastMicroOp()) {
450 //We should be working with a macro op
451 assert(curMacroStaticInst);
452 //Close out this macro op, and clean up the
453 //microcode state
454 curMacroStaticInst = StaticInst::nullStaticInstPtr;
455 thread->setMicroPC(0);
456 thread->setNextMicroPC(1);
457 }
458 //If we're still in a macro op
459 if (curMacroStaticInst) {
460 //Advance the micro pc
461 thread->setMicroPC(thread->readNextMicroPC());
462 //Advance the "next" micro pc. Note that there are no delay
463 //slots, and micro ops are "word" addressed.
464 thread->setNextMicroPC(thread->readNextMicroPC() + 1);
465 } else {
466 // go to the next instruction
467 thread->setPC(thread->readNextPC());
468#if ISA_HAS_DELAY_SLOT
469 thread->setNextPC(thread->readNextNPC());
470 thread->setNextNPC(thread->readNextNPC() + sizeof(MachInst));
471 assert(thread->readNextPC() != thread->readNextNPC());
472#else
473 thread->setNextPC(thread->readNextPC() + sizeof(MachInst));
474#endif
475 }
476 }
477
478#if FULL_SYSTEM
479 Addr oldpc;
480 do {
481 oldpc = thread->readPC();
482 system->pcEventQueue.service(tc);
483 } while (oldpc != thread->readPC());
484#endif
485}
486
407}
408
409void
410BaseSimpleCPU::postExecute()
411{
412#if FULL_SYSTEM
413 if (thread->profile) {
414 bool usermode = TheISA::inUserMode(tc);
415 thread->profilePC = usermode ? 1 : thread->readPC();
416 ProfileNode *node = thread->profile->consume(tc, inst);
417 if (node)
418 thread->profileNode = node;
419 }
420#endif
421
422 if (curStaticInst->isMemRef()) {
423 numMemRefs++;
424 }
425
426 if (curStaticInst->isLoad()) {
427 ++numLoad;
428 comLoadEventQueue[0]->serviceEvents(numLoad);
429 }
430
431 traceFunctions(thread->readPC());
432
433 if (traceData) {
434 traceData->dump();
435 delete traceData;
436 traceData = NULL;
437 }
438}
439
440
441void
442BaseSimpleCPU::advancePC(Fault fault)
443{
444 if (fault != NoFault) {
445 curMacroStaticInst = StaticInst::nullStaticInstPtr;
446 fault->invoke(tc);
447 thread->setMicroPC(0);
448 thread->setNextMicroPC(1);
449 } else {
450 //If we're at the last micro op for this instruction
451 if (curStaticInst->isLastMicroOp()) {
452 //We should be working with a macro op
453 assert(curMacroStaticInst);
454 //Close out this macro op, and clean up the
455 //microcode state
456 curMacroStaticInst = StaticInst::nullStaticInstPtr;
457 thread->setMicroPC(0);
458 thread->setNextMicroPC(1);
459 }
460 //If we're still in a macro op
461 if (curMacroStaticInst) {
462 //Advance the micro pc
463 thread->setMicroPC(thread->readNextMicroPC());
464 //Advance the "next" micro pc. Note that there are no delay
465 //slots, and micro ops are "word" addressed.
466 thread->setNextMicroPC(thread->readNextMicroPC() + 1);
467 } else {
468 // go to the next instruction
469 thread->setPC(thread->readNextPC());
470#if ISA_HAS_DELAY_SLOT
471 thread->setNextPC(thread->readNextNPC());
472 thread->setNextNPC(thread->readNextNPC() + sizeof(MachInst));
473 assert(thread->readNextPC() != thread->readNextNPC());
474#else
475 thread->setNextPC(thread->readNextPC() + sizeof(MachInst));
476#endif
477 }
478 }
479
480#if FULL_SYSTEM
481 Addr oldpc;
482 do {
483 oldpc = thread->readPC();
484 system->pcEventQueue.service(tc);
485 } while (oldpc != thread->readPC());
486#endif
487}
488