2 * Copyright (c) 2001-2004 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 "base/cprintf.hh"
36 #include "kern/kernel_stats.hh"
37 #include "sim/serialize.hh"
38 #include "sim/system.hh"
40 #include "sim/process.hh"
47 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
, System
*_sys
,
48 AlphaITB
*_itb
, AlphaDTB
*_dtb
,
49 FunctionalMemory
*_mem
)
50 : _status(ExecContext::Unallocated
), cpu(_cpu
), thread_num(_thread_num
),
51 cpu_id(-1), mem(_mem
), itb(_itb
), dtb(_dtb
), system(_sys
),
52 memctrl(_sys
->memctrl
), physmem(_sys
->physmem
),
53 kernelBinning(system
->kernelBinning
), bin(kernelBinning
->bin
),
54 fnbin(kernelBinning
->fnbin
), func_exe_inst(0), storeCondFailures(0)
56 kernelStats
= new Kernel::Statistics(this);
57 memset(®s
, 0, sizeof(RegFile
));
60 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
61 Process
*_process
, int _asid
)
62 : _status(ExecContext::Unallocated
),
63 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1),
64 process(_process
), mem(process
->getMemory()), asid(_asid
),
65 func_exe_inst(0), storeCondFailures(0)
67 memset(®s
, 0, sizeof(RegFile
));
70 ExecContext::ExecContext(BaseCPU
*_cpu
, int _thread_num
,
71 FunctionalMemory
*_mem
, int _asid
)
72 : cpu(_cpu
), thread_num(_thread_num
), process(0), mem(_mem
), asid(_asid
),
73 func_exe_inst(0), storeCondFailures(0)
75 memset(®s
, 0, sizeof(RegFile
));
79 ExecContext::~ExecContext()
88 ExecContext::takeOverFrom(ExecContext
*oldContext
)
90 // some things should already be set up
91 assert(mem
== oldContext
->mem
);
93 assert(system
== oldContext
->system
);
95 assert(process
== oldContext
->process
);
98 // copy over functional state
99 _status
= oldContext
->_status
;
100 regs
= oldContext
->regs
;
101 cpu_id
= oldContext
->cpu_id
;
102 func_exe_inst
= oldContext
->func_exe_inst
;
104 storeCondFailures
= 0;
106 oldContext
->_status
= ExecContext::Unallocated
;
111 ExecContext::execute(const StaticInstBase
*inst
)
114 system
->kernelBinning
->execute(this, inst
);
119 ExecContext::serialize(ostream
&os
)
121 SERIALIZE_ENUM(_status
);
123 // thread_num and cpu_id are deterministic from the config
124 SERIALIZE_SCALAR(func_exe_inst
);
125 SERIALIZE_SCALAR(inst
);
128 kernelStats
->serialize(os
);
134 ExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
136 UNSERIALIZE_ENUM(_status
);
137 regs
.unserialize(cp
, section
);
138 // thread_num and cpu_id are deterministic from the config
139 UNSERIALIZE_SCALAR(func_exe_inst
);
140 UNSERIALIZE_SCALAR(inst
);
143 kernelStats
->unserialize(cp
, section
);
149 ExecContext::activate(int delay
)
151 if (status() == Active
)
155 cpu
->activateContext(thread_num
, delay
);
159 ExecContext::suspend()
161 if (status() == Suspended
)
165 // Don't change the status from active if there are pending interrupts
166 if (cpu
->check_interrupts()) {
167 assert(status() == Active
);
173 cpu
->suspendContext(thread_num
);
177 ExecContext::deallocate()
179 if (status() == Unallocated
)
182 _status
= Unallocated
;
183 cpu
->deallocateContext(thread_num
);
189 if (status() == Halted
)
193 cpu
->haltContext(thread_num
);
198 ExecContext::regStats(const string
&name
)
201 kernelStats
->regStats(name
+ ".kern");
206 ExecContext::trap(Fault fault
)
208 //TheISA::trap(fault); //One possible way to do it...
210 /** @todo: Going to hack it for now. Do a true fixup later. */
214 fatal("fault (%d) detected @ PC 0x%08p", fault
, readPC());