2 * Copyright (c) 2001-2005 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/exec_context.hh"
35 #include "base/callback.hh"
36 #include "base/cprintf.hh"
37 #include "base/output.hh"
38 #include "cpu/profile.hh"
39 #include "kern/kernel_stats.hh"
40 #include "sim/serialize.hh"
41 #include "sim/sim_exit.hh"
42 #include "sim/system.hh"
43 #include "targetarch/stacktrace.hh"
45 #include "sim/process.hh"
52 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
, System
*_sys
,
53 AlphaITB
*_itb
, AlphaDTB
*_dtb
,
54 FunctionalMemory
*_mem
)
55 : _status(ExecContext::Unallocated
), cpu(_cpu
), thread_num(_thread_num
),
56 cpu_id(-1), mem(_mem
), itb(_itb
), dtb(_dtb
), system(_sys
),
57 memctrl(_sys
->memctrl
), physmem(_sys
->physmem
),
58 kernelBinning(system
->kernelBinning
), bin(kernelBinning
->bin
),
59 fnbin(kernelBinning
->fnbin
), profile(NULL
),
60 func_exe_inst(0), storeCondFailures(0)
62 kernelStats
= new Kernel::Statistics(this);
63 memset(®s
, 0, sizeof(RegFile
));
65 if (cpu
->params
->profile
) {
66 profile
= new FunctionProfile(system
->kernelSymtab
);
68 new MakeCallback
<ExecContext
, &ExecContext::dumpFuncProfile
>(this);
69 registerExitCallback(cb
);
72 // let's fill with a dummy node for now so we don't get a segfault
73 // on the first cycle when there's no node available.
74 static ProfileNode dummyNode
;
75 profileNode
= &dummyNode
;
79 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
80 Process
*_process
, int _asid
)
81 : _status(ExecContext::Unallocated
),
82 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1),
83 process(_process
), mem(process
->getMemory()), asid(_asid
),
84 func_exe_inst(0), storeCondFailures(0)
86 memset(®s
, 0, sizeof(RegFile
));
89 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
90 FunctionalMemory
*_mem
, int _asid
)
91 : cpu(_cpu
), thread_num(_thread_num
), process(0), mem(_mem
), asid(_asid
),
92 func_exe_inst(0), storeCondFailures(0)
94 memset(®s
, 0, sizeof(RegFile
));
98 ExecContext::~ExecContext()
107 ExecContext::dumpFuncProfile()
109 std::ostream
*os
= simout
.create(csprintf("profile.%s.dat", cpu
->name()));
110 profile
->dump(this, *os
);
115 ExecContext::takeOverFrom(ExecContext
*oldContext
)
117 // some things should already be set up
118 assert(mem
== oldContext
->mem
);
120 assert(system
== oldContext
->system
);
122 assert(process
== oldContext
->process
);
125 // copy over functional state
126 _status
= oldContext
->_status
;
127 regs
= oldContext
->regs
;
128 cpu_id
= oldContext
->cpu_id
;
129 func_exe_inst
= oldContext
->func_exe_inst
;
131 storeCondFailures
= 0;
133 oldContext
->_status
= ExecContext::Unallocated
;
137 ExecContext::serialize(ostream
&os
)
139 SERIALIZE_ENUM(_status
);
141 // thread_num and cpu_id are deterministic from the config
142 SERIALIZE_SCALAR(func_exe_inst
);
143 SERIALIZE_SCALAR(inst
);
146 kernelStats
->serialize(os
);
152 ExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
154 UNSERIALIZE_ENUM(_status
);
155 regs
.unserialize(cp
, section
);
156 // thread_num and cpu_id are deterministic from the config
157 UNSERIALIZE_SCALAR(func_exe_inst
);
158 UNSERIALIZE_SCALAR(inst
);
161 kernelStats
->unserialize(cp
, section
);
167 ExecContext::activate(int delay
)
169 if (status() == Active
)
173 cpu
->activateContext(thread_num
, delay
);
177 ExecContext::suspend()
179 if (status() == Suspended
)
183 // Don't change the status from active if there are pending interrupts
184 if (cpu
->check_interrupts()) {
185 assert(status() == Active
);
191 cpu
->suspendContext(thread_num
);
195 ExecContext::deallocate()
197 if (status() == Unallocated
)
200 _status
= Unallocated
;
201 cpu
->deallocateContext(thread_num
);
207 if (status() == Halted
)
211 cpu
->haltContext(thread_num
);
216 ExecContext::regStats(const string
&name
)
219 kernelStats
->regStats(name
+ ".kern");
224 ExecContext::trap(Fault fault
)
226 //TheISA::trap(fault); //One possible way to do it...
228 /** @todo: Going to hack it for now. Do a true fixup later. */
232 fatal("fault (%d) detected @ PC 0x%08p", fault
, readPC());