thread_context_impl.hh (8208:45331a355c38) thread_context_impl.hh (8232:b28d06a175be)
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Kevin Lim
41 * Korey Sewell
42 */
43
44#include "arch/registers.hh"
45#include "config/the_isa.hh"
46#include "cpu/o3/thread_context.hh"
47#include "cpu/quiesce_event.hh"
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Kevin Lim
41 * Korey Sewell
42 */
43
44#include "arch/registers.hh"
45#include "config/the_isa.hh"
46#include "cpu/o3/thread_context.hh"
47#include "cpu/quiesce_event.hh"
48#include "debug/O3CPU.hh"
48
49#if FULL_SYSTEM
50template <class Impl>
51VirtualPort *
52O3ThreadContext<Impl>::getVirtPort()
53{
54 return thread->getVirtPort();
55}
56
57template <class Impl>
58void
59O3ThreadContext<Impl>::dumpFuncProfile()
60{
61 thread->dumpFuncProfile();
62}
63#endif
64
65template <class Impl>
66void
67O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
68{
69 // some things should already be set up
70#if FULL_SYSTEM
71 assert(getSystemPtr() == old_context->getSystemPtr());
72#else
73 assert(getProcessPtr() == old_context->getProcessPtr());
74#endif
75
76 // copy over functional state
77 setStatus(old_context->status());
78 copyArchRegs(old_context);
79 setContextId(old_context->contextId());
80 setThreadId(old_context->threadId());
81
82#if !FULL_SYSTEM
83 thread->funcExeInst = old_context->readFuncExeInst();
84#else
85 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
86 if (other_quiesce) {
87 // Point the quiesce event's TC at this TC so that it wakes up
88 // the proper CPU.
89 other_quiesce->tc = this;
90 }
91 if (thread->quiesceEvent) {
92 thread->quiesceEvent->tc = this;
93 }
94
95 // Transfer kernel stats from one CPU to the other.
96 thread->kernelStats = old_context->getKernelStats();
97// storeCondFailures = 0;
98 cpu->lockFlag = false;
99#endif
100
101 old_context->setStatus(ThreadContext::Halted);
102
103 thread->inSyscall = false;
104 thread->trapPending = false;
105}
106
107template <class Impl>
108void
109O3ThreadContext<Impl>::activate(int delay)
110{
111 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
112 threadId());
113
114 if (thread->status() == ThreadContext::Active)
115 return;
116
117#if FULL_SYSTEM
118 thread->lastActivate = curTick();
119#endif
120
121 thread->setStatus(ThreadContext::Active);
122
123 // status() == Suspended
124 cpu->activateContext(thread->threadId(), delay);
125}
126
127template <class Impl>
128void
129O3ThreadContext<Impl>::suspend(int delay)
130{
131 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
132 threadId());
133
134 if (thread->status() == ThreadContext::Suspended)
135 return;
136
137#if FULL_SYSTEM
138 thread->lastActivate = curTick();
139 thread->lastSuspend = curTick();
140#endif
141/*
142#if FULL_SYSTEM
143 // Don't change the status from active if there are pending interrupts
144 if (cpu->checkInterrupts()) {
145 assert(status() == ThreadContext::Active);
146 return;
147 }
148#endif
149*/
150 thread->setStatus(ThreadContext::Suspended);
151 cpu->suspendContext(thread->threadId());
152}
153
154template <class Impl>
155void
156O3ThreadContext<Impl>::halt(int delay)
157{
158 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n",
159 threadId());
160
161 if (thread->status() == ThreadContext::Halted)
162 return;
163
164 thread->setStatus(ThreadContext::Halted);
165 cpu->haltContext(thread->threadId());
166}
167
168template <class Impl>
169void
170O3ThreadContext<Impl>::regStats(const std::string &name)
171{
172#if FULL_SYSTEM
173 thread->kernelStats = new TheISA::Kernel::Statistics(cpu->system);
174 thread->kernelStats->regStats(name + ".kern");
175#endif
176}
177
178template <class Impl>
179void
180O3ThreadContext<Impl>::serialize(std::ostream &os)
181{
182#if FULL_SYSTEM
183 if (thread->kernelStats)
184 thread->kernelStats->serialize(os);
185#endif
186
187}
188
189template <class Impl>
190void
191O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string &section)
192{
193#if FULL_SYSTEM
194 if (thread->kernelStats)
195 thread->kernelStats->unserialize(cp, section);
196#endif
197
198}
199
200#if FULL_SYSTEM
201template <class Impl>
202Tick
203O3ThreadContext<Impl>::readLastActivate()
204{
205 return thread->lastActivate;
206}
207
208template <class Impl>
209Tick
210O3ThreadContext<Impl>::readLastSuspend()
211{
212 return thread->lastSuspend;
213}
214
215template <class Impl>
216void
217O3ThreadContext<Impl>::profileClear()
218{
219 thread->profileClear();
220}
221
222template <class Impl>
223void
224O3ThreadContext<Impl>::profileSample()
225{
226 thread->profileSample();
227}
228#endif
229
230template <class Impl>
231void
232O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
233{
234 // Prevent squashing
235 thread->inSyscall = true;
236 TheISA::copyRegs(tc, this);
237 thread->inSyscall = false;
238
239#if !FULL_SYSTEM
240 this->thread->funcExeInst = tc->readFuncExeInst();
241#endif
242}
243
244template <class Impl>
245void
246O3ThreadContext<Impl>::clearArchRegs()
247{
248 cpu->isa[thread->threadId()].clear();
249}
250
251template <class Impl>
252uint64_t
253O3ThreadContext<Impl>::readIntReg(int reg_idx)
254{
255 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
256 return cpu->readArchIntReg(reg_idx, thread->threadId());
257}
258
259template <class Impl>
260TheISA::FloatReg
261O3ThreadContext<Impl>::readFloatReg(int reg_idx)
262{
263 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
264 return cpu->readArchFloatReg(reg_idx, thread->threadId());
265}
266
267template <class Impl>
268TheISA::FloatRegBits
269O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
270{
271 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
272 return cpu->readArchFloatRegInt(reg_idx, thread->threadId());
273}
274
275template <class Impl>
276void
277O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
278{
279 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
280 cpu->setArchIntReg(reg_idx, val, thread->threadId());
281
282 // Squash if we're not already in a state update mode.
283 if (!thread->trapPending && !thread->inSyscall) {
284 cpu->squashFromTC(thread->threadId());
285 }
286}
287
288template <class Impl>
289void
290O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
291{
292 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
293 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
294
295 if (!thread->trapPending && !thread->inSyscall) {
296 cpu->squashFromTC(thread->threadId());
297 }
298}
299
300template <class Impl>
301void
302O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
303{
304 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
305 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId());
306
307 // Squash if we're not already in a state update mode.
308 if (!thread->trapPending && !thread->inSyscall) {
309 cpu->squashFromTC(thread->threadId());
310 }
311}
312
313template <class Impl>
314void
315O3ThreadContext<Impl>::pcState(const TheISA::PCState &val)
316{
317 cpu->pcState(val, thread->threadId());
318
319 // Squash if we're not already in a state update mode.
320 if (!thread->trapPending && !thread->inSyscall) {
321 cpu->squashFromTC(thread->threadId());
322 }
323}
324
325template <class Impl>
326int
327O3ThreadContext<Impl>::flattenIntIndex(int reg)
328{
329 return cpu->isa[thread->threadId()].flattenIntIndex(reg);
330}
331
332template <class Impl>
333int
334O3ThreadContext<Impl>::flattenFloatIndex(int reg)
335{
336 return cpu->isa[thread->threadId()].flattenFloatIndex(reg);
337}
338
339template <class Impl>
340void
341O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
342{
343 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
344
345 // Squash if we're not already in a state update mode.
346 if (!thread->trapPending && !thread->inSyscall) {
347 cpu->squashFromTC(thread->threadId());
348 }
349}
350
351template <class Impl>
352void
353O3ThreadContext<Impl>::setMiscReg(int misc_reg,
354 const MiscReg &val)
355{
356 cpu->setMiscReg(misc_reg, val, thread->threadId());
357
358 // Squash if we're not already in a state update mode.
359 if (!thread->trapPending && !thread->inSyscall) {
360 cpu->squashFromTC(thread->threadId());
361 }
362}
363
49
50#if FULL_SYSTEM
51template <class Impl>
52VirtualPort *
53O3ThreadContext<Impl>::getVirtPort()
54{
55 return thread->getVirtPort();
56}
57
58template <class Impl>
59void
60O3ThreadContext<Impl>::dumpFuncProfile()
61{
62 thread->dumpFuncProfile();
63}
64#endif
65
66template <class Impl>
67void
68O3ThreadContext<Impl>::takeOverFrom(ThreadContext *old_context)
69{
70 // some things should already be set up
71#if FULL_SYSTEM
72 assert(getSystemPtr() == old_context->getSystemPtr());
73#else
74 assert(getProcessPtr() == old_context->getProcessPtr());
75#endif
76
77 // copy over functional state
78 setStatus(old_context->status());
79 copyArchRegs(old_context);
80 setContextId(old_context->contextId());
81 setThreadId(old_context->threadId());
82
83#if !FULL_SYSTEM
84 thread->funcExeInst = old_context->readFuncExeInst();
85#else
86 EndQuiesceEvent *other_quiesce = old_context->getQuiesceEvent();
87 if (other_quiesce) {
88 // Point the quiesce event's TC at this TC so that it wakes up
89 // the proper CPU.
90 other_quiesce->tc = this;
91 }
92 if (thread->quiesceEvent) {
93 thread->quiesceEvent->tc = this;
94 }
95
96 // Transfer kernel stats from one CPU to the other.
97 thread->kernelStats = old_context->getKernelStats();
98// storeCondFailures = 0;
99 cpu->lockFlag = false;
100#endif
101
102 old_context->setStatus(ThreadContext::Halted);
103
104 thread->inSyscall = false;
105 thread->trapPending = false;
106}
107
108template <class Impl>
109void
110O3ThreadContext<Impl>::activate(int delay)
111{
112 DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
113 threadId());
114
115 if (thread->status() == ThreadContext::Active)
116 return;
117
118#if FULL_SYSTEM
119 thread->lastActivate = curTick();
120#endif
121
122 thread->setStatus(ThreadContext::Active);
123
124 // status() == Suspended
125 cpu->activateContext(thread->threadId(), delay);
126}
127
128template <class Impl>
129void
130O3ThreadContext<Impl>::suspend(int delay)
131{
132 DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
133 threadId());
134
135 if (thread->status() == ThreadContext::Suspended)
136 return;
137
138#if FULL_SYSTEM
139 thread->lastActivate = curTick();
140 thread->lastSuspend = curTick();
141#endif
142/*
143#if FULL_SYSTEM
144 // Don't change the status from active if there are pending interrupts
145 if (cpu->checkInterrupts()) {
146 assert(status() == ThreadContext::Active);
147 return;
148 }
149#endif
150*/
151 thread->setStatus(ThreadContext::Suspended);
152 cpu->suspendContext(thread->threadId());
153}
154
155template <class Impl>
156void
157O3ThreadContext<Impl>::halt(int delay)
158{
159 DPRINTF(O3CPU, "Calling halt on Thread Context %d\n",
160 threadId());
161
162 if (thread->status() == ThreadContext::Halted)
163 return;
164
165 thread->setStatus(ThreadContext::Halted);
166 cpu->haltContext(thread->threadId());
167}
168
169template <class Impl>
170void
171O3ThreadContext<Impl>::regStats(const std::string &name)
172{
173#if FULL_SYSTEM
174 thread->kernelStats = new TheISA::Kernel::Statistics(cpu->system);
175 thread->kernelStats->regStats(name + ".kern");
176#endif
177}
178
179template <class Impl>
180void
181O3ThreadContext<Impl>::serialize(std::ostream &os)
182{
183#if FULL_SYSTEM
184 if (thread->kernelStats)
185 thread->kernelStats->serialize(os);
186#endif
187
188}
189
190template <class Impl>
191void
192O3ThreadContext<Impl>::unserialize(Checkpoint *cp, const std::string &section)
193{
194#if FULL_SYSTEM
195 if (thread->kernelStats)
196 thread->kernelStats->unserialize(cp, section);
197#endif
198
199}
200
201#if FULL_SYSTEM
202template <class Impl>
203Tick
204O3ThreadContext<Impl>::readLastActivate()
205{
206 return thread->lastActivate;
207}
208
209template <class Impl>
210Tick
211O3ThreadContext<Impl>::readLastSuspend()
212{
213 return thread->lastSuspend;
214}
215
216template <class Impl>
217void
218O3ThreadContext<Impl>::profileClear()
219{
220 thread->profileClear();
221}
222
223template <class Impl>
224void
225O3ThreadContext<Impl>::profileSample()
226{
227 thread->profileSample();
228}
229#endif
230
231template <class Impl>
232void
233O3ThreadContext<Impl>::copyArchRegs(ThreadContext *tc)
234{
235 // Prevent squashing
236 thread->inSyscall = true;
237 TheISA::copyRegs(tc, this);
238 thread->inSyscall = false;
239
240#if !FULL_SYSTEM
241 this->thread->funcExeInst = tc->readFuncExeInst();
242#endif
243}
244
245template <class Impl>
246void
247O3ThreadContext<Impl>::clearArchRegs()
248{
249 cpu->isa[thread->threadId()].clear();
250}
251
252template <class Impl>
253uint64_t
254O3ThreadContext<Impl>::readIntReg(int reg_idx)
255{
256 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
257 return cpu->readArchIntReg(reg_idx, thread->threadId());
258}
259
260template <class Impl>
261TheISA::FloatReg
262O3ThreadContext<Impl>::readFloatReg(int reg_idx)
263{
264 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
265 return cpu->readArchFloatReg(reg_idx, thread->threadId());
266}
267
268template <class Impl>
269TheISA::FloatRegBits
270O3ThreadContext<Impl>::readFloatRegBits(int reg_idx)
271{
272 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
273 return cpu->readArchFloatRegInt(reg_idx, thread->threadId());
274}
275
276template <class Impl>
277void
278O3ThreadContext<Impl>::setIntReg(int reg_idx, uint64_t val)
279{
280 reg_idx = cpu->isa[thread->threadId()].flattenIntIndex(reg_idx);
281 cpu->setArchIntReg(reg_idx, val, thread->threadId());
282
283 // Squash if we're not already in a state update mode.
284 if (!thread->trapPending && !thread->inSyscall) {
285 cpu->squashFromTC(thread->threadId());
286 }
287}
288
289template <class Impl>
290void
291O3ThreadContext<Impl>::setFloatReg(int reg_idx, FloatReg val)
292{
293 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
294 cpu->setArchFloatReg(reg_idx, val, thread->threadId());
295
296 if (!thread->trapPending && !thread->inSyscall) {
297 cpu->squashFromTC(thread->threadId());
298 }
299}
300
301template <class Impl>
302void
303O3ThreadContext<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
304{
305 reg_idx = cpu->isa[thread->threadId()].flattenFloatIndex(reg_idx);
306 cpu->setArchFloatRegInt(reg_idx, val, thread->threadId());
307
308 // Squash if we're not already in a state update mode.
309 if (!thread->trapPending && !thread->inSyscall) {
310 cpu->squashFromTC(thread->threadId());
311 }
312}
313
314template <class Impl>
315void
316O3ThreadContext<Impl>::pcState(const TheISA::PCState &val)
317{
318 cpu->pcState(val, thread->threadId());
319
320 // Squash if we're not already in a state update mode.
321 if (!thread->trapPending && !thread->inSyscall) {
322 cpu->squashFromTC(thread->threadId());
323 }
324}
325
326template <class Impl>
327int
328O3ThreadContext<Impl>::flattenIntIndex(int reg)
329{
330 return cpu->isa[thread->threadId()].flattenIntIndex(reg);
331}
332
333template <class Impl>
334int
335O3ThreadContext<Impl>::flattenFloatIndex(int reg)
336{
337 return cpu->isa[thread->threadId()].flattenFloatIndex(reg);
338}
339
340template <class Impl>
341void
342O3ThreadContext<Impl>::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
343{
344 cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
345
346 // Squash if we're not already in a state update mode.
347 if (!thread->trapPending && !thread->inSyscall) {
348 cpu->squashFromTC(thread->threadId());
349 }
350}
351
352template <class Impl>
353void
354O3ThreadContext<Impl>::setMiscReg(int misc_reg,
355 const MiscReg &val)
356{
357 cpu->setMiscReg(misc_reg, val, thread->threadId());
358
359 // Squash if we're not already in a state update mode.
360 if (!thread->trapPending && !thread->inSyscall) {
361 cpu->squashFromTC(thread->threadId());
362 }
363}
364