2 * Copyright (c) 2003 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_cpu.hh"
32 #include "cpu/exec_context.hh"
35 #include "sim/system.hh"
37 #include "sim/process.hh"
44 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
, System
*_sys
,
45 AlphaITB
*_itb
, AlphaDTB
*_dtb
,
46 FunctionalMemory
*_mem
)
47 : _status(ExecContext::Unallocated
),
48 kernelStats(this, _cpu
), cpu(_cpu
), thread_num(_thread_num
),
49 cpu_id(-1), mem(_mem
), itb(_itb
), dtb(_dtb
), system(_sys
),
50 memCtrl(_sys
->memCtrl
), physmem(_sys
->physmem
),
51 swCtx(NULL
), func_exe_inst(0), storeCondFailures(0)
53 memset(®s
, 0, sizeof(RegFile
));
56 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
57 Process
*_process
, int _asid
)
58 : _status(ExecContext::Unallocated
),
59 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1),
60 process(_process
), mem(process
->getMemory()), asid(_asid
),
61 func_exe_inst(0), storeCondFailures(0)
63 memset(®s
, 0, sizeof(RegFile
));
66 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
67 FunctionalMemory
*_mem
, int _asid
)
68 : cpu(_cpu
), thread_num(_thread_num
), process(0), mem(_mem
), asid(_asid
),
69 func_exe_inst(0), storeCondFailures(0)
71 memset(®s
, 0, sizeof(RegFile
));
77 ExecContext::takeOverFrom(ExecContext
*oldContext
)
79 // some things should already be set up
80 assert(mem
== oldContext
->mem
);
82 assert(system
== oldContext
->system
);
84 assert(process
== oldContext
->process
);
87 // copy over functional state
88 _status
= oldContext
->_status
;
90 kernelStats
= oldContext
->kernelStats
;
92 regs
= oldContext
->regs
;
93 cpu_id
= oldContext
->cpu_id
;
94 func_exe_inst
= oldContext
->func_exe_inst
;
96 storeCondFailures
= 0;
98 oldContext
->_status
= ExecContext::Unallocated
;
103 ExecContext::serialize(ostream
&os
)
105 SERIALIZE_ENUM(_status
);
107 // thread_num and cpu_id are deterministic from the config
108 SERIALIZE_SCALAR(func_exe_inst
);
114 SERIALIZE_SCALAR(ctx
);
115 SERIALIZE_SCALAR(swCtx
->calls
);
116 std::stack
<fnCall
*> *stack
= &(swCtx
->callStack
);
118 int size
= stack
->size();
119 SERIALIZE_SCALAR(size
);
121 for (int j
=0; j
<size
; ++j
) {
123 paramOut(os
, csprintf("stackpos[%d]",j
), top
->name
);
128 SERIALIZE_SCALAR(ctx
);
131 Statistics::MainBin
*cur
= Statistics::MainBin::curBin();
132 string bin_name
= cur
->name();
133 SERIALIZE_SCALAR(bin_name
);
140 ExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
142 UNSERIALIZE_ENUM(_status
);
143 regs
.unserialize(cp
, section
);
144 // thread_num and cpu_id are deterministic from the config
145 UNSERIALIZE_SCALAR(func_exe_inst
);
149 UNSERIALIZE_SCALAR(ctx
);
151 swCtx
= new SWContext
;
152 UNSERIALIZE_SCALAR(swCtx
->calls
);
154 UNSERIALIZE_SCALAR(size
);
156 vector
<fnCall
*> calls
;
158 for (int i
=0; i
<size
; ++i
) {
160 paramIn(cp
, section
, csprintf("stackpos[%d]",i
), call
->name
);
161 call
->myBin
= system
->getBin(call
->name
);
162 calls
.push_back(call
);
165 for (int i
=size
-1; i
>=0; --i
) {
166 swCtx
->callStack
.push(calls
[i
]);
173 UNSERIALIZE_SCALAR(bin_name
);
174 system
->getBin(bin_name
)->activate();
181 ExecContext::activate(int delay
)
183 if (status() == Active
)
187 cpu
->activateContext(thread_num
, delay
);
191 ExecContext::suspend()
193 if (status() == Suspended
)
197 // Don't change the status from active if there are pending interrupts
198 if (cpu
->check_interrupts()) {
199 assert(status() == Active
);
205 cpu
->suspendContext(thread_num
);
209 ExecContext::deallocate()
211 if (status() == Unallocated
)
214 _status
= Unallocated
;
215 cpu
->deallocateContext(thread_num
);
221 if (status() == Halted
)
225 cpu
->haltContext(thread_num
);
230 ExecContext::regStats(const string
&name
)
233 kernelStats
.regStats(name
+ ".kern");