e28c34f88fa735adb88b6feb2bad8cf134738345
2 * Copyright (c) 2001-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 #include "cpu/base.hh"
32 #include "cpu/cpu_exec_context.hh"
33 #include "cpu/exec_context.hh"
36 #include "base/callback.hh"
37 #include "base/cprintf.hh"
38 #include "base/output.hh"
39 #include "base/trace.hh"
40 #include "cpu/profile.hh"
41 #include "cpu/quiesce_event.hh"
42 #include "kern/kernel_stats.hh"
43 #include "sim/serialize.hh"
44 #include "sim/sim_exit.hh"
45 #include "sim/system.hh"
46 #include "arch/stacktrace.hh"
48 #include "sim/process.hh"
55 CPUExecContext::CPUExecContext(BaseCPU
*_cpu
, int _thread_num
, System
*_sys
,
56 AlphaITB
*_itb
, AlphaDTB
*_dtb
,
57 FunctionalMemory
*_mem
,
58 bool use_kernel_stats
)
59 : _status(ExecContext::Unallocated
), cpu(_cpu
), thread_num(_thread_num
),
60 cpu_id(-1), lastActivate(0), lastSuspend(0), mem(_mem
), itb(_itb
),
61 dtb(_dtb
), system(_sys
), memctrl(_sys
->memctrl
), physmem(_sys
->physmem
),
62 profile(NULL
), func_exe_inst(0), storeCondFailures(0)
64 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
66 quiesceEvent
= new EndQuiesceEvent(proxy
);
68 memset(®s
, 0, sizeof(RegFile
));
70 if (cpu
->params
->profile
) {
71 profile
= new FunctionProfile(system
->kernelSymtab
);
73 new MakeCallback
<CPUExecContext
,
74 &CPUExecContext::dumpFuncProfile
>(this);
75 registerExitCallback(cb
);
78 // let's fill with a dummy node for now so we don't get a segfault
79 // on the first cycle when there's no node available.
80 static ProfileNode dummyNode
;
81 profileNode
= &dummyNode
;
84 if (use_kernel_stats
) {
85 kernelStats
= new Kernel::Statistics(system
);
91 CPUExecContext::CPUExecContext(BaseCPU
*_cpu
, int _thread_num
,
92 Process
*_process
, int _asid
)
93 : _status(ExecContext::Unallocated
),
94 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1), lastActivate(0),
95 lastSuspend(0), process(_process
), mem(process
->getMemory()), asid(_asid
),
96 func_exe_inst(0), storeCondFailures(0)
98 memset(®s
, 0, sizeof(RegFile
));
99 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
102 CPUExecContext::CPUExecContext(BaseCPU
*_cpu
, int _thread_num
,
103 FunctionalMemory
*_mem
, int _asid
)
104 : cpu(_cpu
), thread_num(_thread_num
), process(0), mem(_mem
), asid(_asid
),
105 func_exe_inst(0), storeCondFailures(0)
107 memset(®s
, 0, sizeof(RegFile
));
108 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
111 CPUExecContext::CPUExecContext(RegFile
*regFile
)
112 : cpu(NULL
), thread_num(-1), process(NULL
), mem(NULL
), asid(-1),
113 func_exe_inst(0), storeCondFailures(0)
116 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
121 CPUExecContext::~CPUExecContext()
128 CPUExecContext::dumpFuncProfile()
130 std::ostream
*os
= simout
.create(csprintf("profile.%s.dat", cpu
->name()));
131 profile
->dump(proxy
, *os
);
135 CPUExecContext::profileClear()
142 CPUExecContext::profileSample()
145 profile
->sample(profileNode
, profilePC
);
151 CPUExecContext::takeOverFrom(ExecContext
*oldContext
)
153 // some things should already be set up
154 assert(mem
== oldContext
->getMemPtr());
156 assert(system
== oldContext
->getSystemPtr());
158 assert(process
== oldContext
->getProcessPtr());
161 // copy over functional state
162 _status
= oldContext
->status();
163 copyArchRegs(oldContext
);
164 cpu_id
= oldContext
->readCpuId();
166 func_exe_inst
= oldContext
->readFuncExeInst();
168 EndQuiesceEvent
*quiesce
= oldContext
->getQuiesceEvent();
170 // Point the quiesce event's XC at this XC so that it wakes up
175 quiesceEvent
->xc
= proxy
;
179 storeCondFailures
= 0;
181 oldContext
->setStatus(ExecContext::Unallocated
);
185 CPUExecContext::serialize(ostream
&os
)
187 SERIALIZE_ENUM(_status
);
189 // thread_num and cpu_id are deterministic from the config
190 SERIALIZE_SCALAR(func_exe_inst
);
191 SERIALIZE_SCALAR(inst
);
194 Tick quiesceEndTick
= 0;
195 if (quiesceEvent
->scheduled())
196 quiesceEndTick
= quiesceEvent
->when();
197 SERIALIZE_SCALAR(quiesceEndTick
);
199 kernelStats
->serialize(os
);
205 CPUExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
207 UNSERIALIZE_ENUM(_status
);
208 regs
.unserialize(cp
, section
);
209 // thread_num and cpu_id are deterministic from the config
210 UNSERIALIZE_SCALAR(func_exe_inst
);
211 UNSERIALIZE_SCALAR(inst
);
215 UNSERIALIZE_SCALAR(quiesceEndTick
);
217 quiesceEvent
->schedule(quiesceEndTick
);
219 kernelStats
->unserialize(cp
, section
);
225 CPUExecContext::activate(int delay
)
227 if (status() == ExecContext::Active
)
230 lastActivate
= curTick
;
232 if (status() == ExecContext::Unallocated
) {
233 cpu
->activateWhenReady(thread_num
);
237 _status
= ExecContext::Active
;
239 // status() == Suspended
240 cpu
->activateContext(thread_num
, delay
);
244 CPUExecContext::suspend()
246 if (status() == ExecContext::Suspended
)
249 lastActivate
= curTick
;
250 lastSuspend
= curTick
;
253 // Don't change the status from active if there are pending interrupts
254 if (cpu->check_interrupts()) {
255 assert(status() == ExecContext::Active);
260 _status
= ExecContext::Suspended
;
261 cpu
->suspendContext(thread_num
);
265 CPUExecContext::deallocate()
267 if (status() == ExecContext::Unallocated
)
270 _status
= ExecContext::Unallocated
;
271 cpu
->deallocateContext(thread_num
);
275 CPUExecContext::halt()
277 if (status() == ExecContext::Halted
)
280 _status
= ExecContext::Halted
;
281 cpu
->haltContext(thread_num
);
286 CPUExecContext::regStats(const string
&name
)
290 kernelStats
->regStats(name
+ ".kern");
295 CPUExecContext::copyArchRegs(ExecContext
*xc
)
297 // First loop through the integer registers.
298 for (int i
= 0; i
< AlphaISA::NumIntRegs
; ++i
) {
299 setIntReg(i
, xc
->readIntReg(i
));
302 // Then loop through the floating point registers.
303 for (int i
= 0; i
< AlphaISA::NumFloatRegs
; ++i
) {
304 setFloatRegDouble(i
, xc
->readFloatRegDouble(i
));
305 setFloatRegInt(i
, xc
->readFloatRegInt(i
));
308 // Copy misc. registers
309 TheISA::copyMiscRegs(xc
, proxy
);
311 // Lastly copy PC/NPC
313 setNextPC(xc
->readNextPC());