change the path that i track from two separate paths to one.
[gem5.git] / cpu / exec_context.cc
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 #include <string>
30
31 #include "cpu/base_cpu.hh"
32 #include "cpu/exec_context.hh"
33
34 #ifdef FULL_SYSTEM
35 #include "sim/system.hh"
36 #else
37 #include "sim/prog.hh"
38 #endif
39
40 using namespace std;
41
42 // constructor
43 #ifdef FULL_SYSTEM
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 #ifdef FS_MEASURE
52 swCtx(NULL),
53 #endif
54 func_exe_insn(0), storeCondFailures(0)
55 {
56 memset(&regs, 0, sizeof(RegFile));
57 }
58 #else
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)
65 {
66 }
67
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)
72 {
73 }
74 #endif
75
76
77 void
78 ExecContext::takeOverFrom(ExecContext *oldContext)
79 {
80 // some things should already be set up
81 assert(mem == oldContext->mem);
82 #ifdef FULL_SYSTEM
83 assert(system == oldContext->system);
84 #else
85 assert(process == oldContext->process);
86 #endif
87
88 // copy over functional state
89 _status = oldContext->_status;
90 #ifdef FULL_SYSTEM
91 kernelStats = oldContext->kernelStats;
92 #endif
93 regs = oldContext->regs;
94 cpu_id = oldContext->cpu_id;
95 func_exe_insn = oldContext->func_exe_insn;
96
97 storeCondFailures = 0;
98
99 oldContext->_status = ExecContext::Unallocated;
100 }
101
102
103 void
104 ExecContext::serialize(ostream &os)
105 {
106 SERIALIZE_ENUM(_status);
107 regs.serialize(os);
108 // thread_num and cpu_id are deterministic from the config
109 SERIALIZE_SCALAR(func_exe_insn);
110 }
111
112
113 void
114 ExecContext::unserialize(Checkpoint *cp, const std::string &section)
115 {
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);
120 }
121
122
123 void
124 ExecContext::setStatus(Status new_status)
125 {
126 #ifdef FULL_SYSTEM
127 if (status() == new_status)
128 return;
129
130 // Don't change the status from active if there are pending interrupts
131 if (new_status == Suspended && cpu->check_interrupts()) {
132 assert(status() == Active);
133 return;
134 }
135 #endif
136
137 _status = new_status;
138 cpu->execCtxStatusChg(thread_num);
139 }
140
141 void
142 ExecContext::regStats(const string &name)
143 {
144 #ifdef FULL_SYSTEM
145 kernelStats.regStats(name + ".kern");
146 #endif
147 }