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
),
54 func_exe_insn(0), storeCondFailures(0)
56 memset(®s
, 0, sizeof(RegFile
));
59 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
60 Process
*_process
, int _asid
)
61 : _status(ExecContext::Unallocated
),
62 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1),
63 process(_process
), mem(process
->getMemory()), asid(_asid
),
64 func_exe_insn(0), storeCondFailures(0)
68 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
69 FunctionalMemory
*_mem
, int _asid
)
70 : cpu(_cpu
), thread_num(_thread_num
), process(0), mem(_mem
), asid(_asid
),
71 func_exe_insn(0), storeCondFailures(0)
78 ExecContext::takeOverFrom(ExecContext
*oldContext
)
80 // some things should already be set up
81 assert(mem
== oldContext
->mem
);
83 assert(system
== oldContext
->system
);
85 assert(process
== oldContext
->process
);
88 // copy over functional state
89 _status
= oldContext
->_status
;
91 kernelStats
= oldContext
->kernelStats
;
93 regs
= oldContext
->regs
;
94 cpu_id
= oldContext
->cpu_id
;
95 func_exe_insn
= oldContext
->func_exe_insn
;
97 storeCondFailures
= 0;
99 oldContext
->_status
= ExecContext::Unallocated
;
104 ExecContext::serialize(ostream
&os
)
106 SERIALIZE_ENUM(_status
);
108 // thread_num and cpu_id are deterministic from the config
109 SERIALIZE_SCALAR(func_exe_insn
);
114 ExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
116 UNSERIALIZE_ENUM(_status
);
117 regs
.unserialize(cp
, section
);
118 // thread_num and cpu_id are deterministic from the config
119 UNSERIALIZE_SCALAR(func_exe_insn
);
124 ExecContext::activate(int delay
)
126 if (status() == Active
)
130 cpu
->activateContext(thread_num
, delay
);
134 ExecContext::suspend()
136 if (status() == Suspended
)
140 // Don't change the status from active if there are pending interrupts
141 if (cpu
->check_interrupts()) {
142 assert(status() == Active
);
148 cpu
->suspendContext(thread_num
);
152 ExecContext::deallocate()
154 if (status() == Unallocated
)
157 _status
= Unallocated
;
158 cpu
->deallocateContext(thread_num
);
164 if (status() == Halted
)
168 cpu
->haltContext(thread_num
);
173 ExecContext::regStats(const string
&name
)
176 kernelStats
.regStats(name
+ ".kern");