thread_context.hh (4172:141705d83494) thread_context.hh (4997:e7380529bd2d)
1/*
2 * Copyright (c) 2004-2006 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 * Authors: Kevin Lim
29 */
30
31#ifndef __CPU_O3_THREAD_CONTEXT_HH__
32#define __CPU_O3_THREAD_CONTEXT_HH__
33
34#include "cpu/thread_context.hh"
35#include "cpu/o3/isa_specific.hh"
36
37class EndQuiesceEvent;
38namespace Kernel {
39 class Statistics;
40};
41
42class TranslatingPort;
43
44/**
45 * Derived ThreadContext class for use with the O3CPU. It
46 * provides the interface for any external objects to access a
47 * single thread's state and some general CPU state. Any time
48 * external objects try to update state through this interface,
49 * the CPU will create an event to squash all in-flight
50 * instructions in order to ensure state is maintained correctly.
51 * It must be defined specifically for the O3CPU because
52 * not all architectural state is located within the O3ThreadState
53 * (such as the commit PC, and registers), and specific actions
54 * must be taken when using this interface (such as squashing all
55 * in-flight instructions when doing a write to this interface).
56 */
57template <class Impl>
58class O3ThreadContext : public ThreadContext
59{
60 public:
61 typedef typename Impl::O3CPU O3CPU;
62
63 /** Pointer to the CPU. */
64 O3CPU *cpu;
65
66 /** Pointer to the thread state that this TC corrseponds to. */
67 O3ThreadState<Impl> *thread;
68
1/*
2 * Copyright (c) 2004-2006 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 * Authors: Kevin Lim
29 */
30
31#ifndef __CPU_O3_THREAD_CONTEXT_HH__
32#define __CPU_O3_THREAD_CONTEXT_HH__
33
34#include "cpu/thread_context.hh"
35#include "cpu/o3/isa_specific.hh"
36
37class EndQuiesceEvent;
38namespace Kernel {
39 class Statistics;
40};
41
42class TranslatingPort;
43
44/**
45 * Derived ThreadContext class for use with the O3CPU. It
46 * provides the interface for any external objects to access a
47 * single thread's state and some general CPU state. Any time
48 * external objects try to update state through this interface,
49 * the CPU will create an event to squash all in-flight
50 * instructions in order to ensure state is maintained correctly.
51 * It must be defined specifically for the O3CPU because
52 * not all architectural state is located within the O3ThreadState
53 * (such as the commit PC, and registers), and specific actions
54 * must be taken when using this interface (such as squashing all
55 * in-flight instructions when doing a write to this interface).
56 */
57template <class Impl>
58class O3ThreadContext : public ThreadContext
59{
60 public:
61 typedef typename Impl::O3CPU O3CPU;
62
63 /** Pointer to the CPU. */
64 O3CPU *cpu;
65
66 /** Pointer to the thread state that this TC corrseponds to. */
67 O3ThreadState<Impl> *thread;
68
69#if FULL_SYSTEM
70 /** Returns a pointer to the ITB. */
71 TheISA::ITB *getITBPtr() { return cpu->itb; }
72
73 /** Returns a pointer to the DTB. */
74 TheISA::DTB *getDTBPtr() { return cpu->dtb; }
69 /** Returns a pointer to the ITB. */
70 TheISA::ITB *getITBPtr() { return cpu->itb; }
71
72 /** Returns a pointer to the DTB. */
73 TheISA::DTB *getDTBPtr() { return cpu->dtb; }
75#endif
76
77 /** Returns a pointer to this CPU. */
78 virtual BaseCPU *getCpuPtr() { return cpu; }
79
80 /** Sets this CPU's ID. */
81 virtual void setCpuId(int id) { cpu->setCpuId(id); }
82
83 /** Reads this CPU's ID. */
84 virtual int readCpuId() { return cpu->readCpuId(); }
85
86#if FULL_SYSTEM
87 /** Returns a pointer to the system. */
88 virtual System *getSystemPtr() { return cpu->system; }
89
90 /** Returns a pointer to physical memory. */
91 virtual PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
92
93 /** Returns a pointer to this thread's kernel statistics. */
94 virtual TheISA::Kernel::Statistics *getKernelStats()
95 { return thread->kernelStats; }
96
97 virtual FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
98
99 virtual VirtualPort *getVirtPort(ThreadContext *src_tc = NULL);
100
101 void delVirtPort(VirtualPort *vp);
102
103 virtual void connectMemPorts() { thread->connectMemPorts(); }
104#else
105 virtual TranslatingPort *getMemPort() { return thread->getMemPort(); }
106
107 /** Returns a pointer to this thread's process. */
108 virtual Process *getProcessPtr() { return thread->getProcessPtr(); }
109#endif
110 /** Returns this thread's status. */
111 virtual Status status() const { return thread->status(); }
112
113 /** Sets this thread's status. */
114 virtual void setStatus(Status new_status)
115 { thread->setStatus(new_status); }
116
117 /** Set the status to Active. Optional delay indicates number of
118 * cycles to wait before beginning execution. */
119 virtual void activate(int delay = 1);
120
121 /** Set the status to Suspended. */
122 virtual void suspend();
123
124 /** Set the status to Unallocated. */
125 virtual void deallocate(int delay = 0);
126
127 /** Set the status to Halted. */
128 virtual void halt();
129
130#if FULL_SYSTEM
131 /** Dumps the function profiling information.
132 * @todo: Implement.
133 */
134 virtual void dumpFuncProfile();
135#endif
136 /** Takes over execution of a thread from another CPU. */
137 virtual void takeOverFrom(ThreadContext *old_context);
138
139 /** Registers statistics associated with this TC. */
140 virtual void regStats(const std::string &name);
141
142 /** Serializes state. */
143 virtual void serialize(std::ostream &os);
144 /** Unserializes state. */
145 virtual void unserialize(Checkpoint *cp, const std::string &section);
146
147#if FULL_SYSTEM
148 /** Reads the last tick that this thread was activated on. */
149 virtual Tick readLastActivate();
150 /** Reads the last tick that this thread was suspended on. */
151 virtual Tick readLastSuspend();
152
153 /** Clears the function profiling information. */
154 virtual void profileClear();
155 /** Samples the function profiling information. */
156 virtual void profileSample();
157#endif
158 /** Returns this thread's ID number. */
159 virtual int getThreadNum() { return thread->readTid(); }
160
161 /** Returns the instruction this thread is currently committing.
162 * Only used when an instruction faults.
163 */
164 virtual TheISA::MachInst getInst();
165
166 /** Copies the architectural registers from another TC into this TC. */
167 virtual void copyArchRegs(ThreadContext *tc);
168
169 /** Resets all architectural registers to 0. */
170 virtual void clearArchRegs();
171
172 /** Reads an integer register. */
173 virtual uint64_t readIntReg(int reg_idx);
174
175 virtual FloatReg readFloatReg(int reg_idx, int width);
176
177 virtual FloatReg readFloatReg(int reg_idx);
178
179 virtual FloatRegBits readFloatRegBits(int reg_idx, int width);
180
181 virtual FloatRegBits readFloatRegBits(int reg_idx);
182
183 /** Sets an integer register to a value. */
184 virtual void setIntReg(int reg_idx, uint64_t val);
185
186 virtual void setFloatReg(int reg_idx, FloatReg val, int width);
187
188 virtual void setFloatReg(int reg_idx, FloatReg val);
189
190 virtual void setFloatRegBits(int reg_idx, FloatRegBits val, int width);
191
192 virtual void setFloatRegBits(int reg_idx, FloatRegBits val);
193
194 /** Reads this thread's PC. */
195 virtual uint64_t readPC()
196 { return cpu->readPC(thread->readTid()); }
197
198 /** Sets this thread's PC. */
199 virtual void setPC(uint64_t val);
200
201 /** Reads this thread's next PC. */
202 virtual uint64_t readNextPC()
203 { return cpu->readNextPC(thread->readTid()); }
204
205 /** Sets this thread's next PC. */
206 virtual void setNextPC(uint64_t val);
207
208 /** Reads a miscellaneous register. */
209 virtual MiscReg readMiscRegNoEffect(int misc_reg)
210 { return cpu->readMiscRegNoEffect(misc_reg, thread->readTid()); }
211
212 /** Reads a misc. register, including any side-effects the
213 * read might have as defined by the architecture. */
214 virtual MiscReg readMiscReg(int misc_reg)
215 { return cpu->readMiscReg(misc_reg, thread->readTid()); }
216
217 /** Sets a misc. register. */
218 virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
219
220 /** Sets a misc. register, including any side-effects the
221 * write might have as defined by the architecture. */
222 virtual void setMiscReg(int misc_reg, const MiscReg &val);
223
224 /** Returns the number of consecutive store conditional failures. */
225 // @todo: Figure out where these store cond failures should go.
226 virtual unsigned readStCondFailures()
227 { return thread->storeCondFailures; }
228
229 /** Sets the number of consecutive store conditional failures. */
230 virtual void setStCondFailures(unsigned sc_failures)
231 { thread->storeCondFailures = sc_failures; }
232
233 // Only really makes sense for old CPU model. Lots of code
234 // outside the CPU still checks this function, so it will
235 // always return false to keep everything working.
236 /** Checks if the thread is misspeculating. Because it is
237 * very difficult to determine if the thread is
238 * misspeculating, this is set as false. */
239 virtual bool misspeculating() { return false; }
240
241#if !FULL_SYSTEM
242 /** Gets a syscall argument by index. */
243 virtual IntReg getSyscallArg(int i);
244
245 /** Sets a syscall argument. */
246 virtual void setSyscallArg(int i, IntReg val);
247
248 /** Sets the syscall return value. */
249 virtual void setSyscallReturn(SyscallReturn return_value);
250
251 /** Executes a syscall in SE mode. */
252 virtual void syscall(int64_t callnum)
253 { return cpu->syscall(callnum, thread->readTid()); }
254
255 /** Reads the funcExeInst counter. */
256 virtual Counter readFuncExeInst() { return thread->funcExeInst; }
257#endif
258};
259
260#endif
74
75 /** Returns a pointer to this CPU. */
76 virtual BaseCPU *getCpuPtr() { return cpu; }
77
78 /** Sets this CPU's ID. */
79 virtual void setCpuId(int id) { cpu->setCpuId(id); }
80
81 /** Reads this CPU's ID. */
82 virtual int readCpuId() { return cpu->readCpuId(); }
83
84#if FULL_SYSTEM
85 /** Returns a pointer to the system. */
86 virtual System *getSystemPtr() { return cpu->system; }
87
88 /** Returns a pointer to physical memory. */
89 virtual PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
90
91 /** Returns a pointer to this thread's kernel statistics. */
92 virtual TheISA::Kernel::Statistics *getKernelStats()
93 { return thread->kernelStats; }
94
95 virtual FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
96
97 virtual VirtualPort *getVirtPort(ThreadContext *src_tc = NULL);
98
99 void delVirtPort(VirtualPort *vp);
100
101 virtual void connectMemPorts() { thread->connectMemPorts(); }
102#else
103 virtual TranslatingPort *getMemPort() { return thread->getMemPort(); }
104
105 /** Returns a pointer to this thread's process. */
106 virtual Process *getProcessPtr() { return thread->getProcessPtr(); }
107#endif
108 /** Returns this thread's status. */
109 virtual Status status() const { return thread->status(); }
110
111 /** Sets this thread's status. */
112 virtual void setStatus(Status new_status)
113 { thread->setStatus(new_status); }
114
115 /** Set the status to Active. Optional delay indicates number of
116 * cycles to wait before beginning execution. */
117 virtual void activate(int delay = 1);
118
119 /** Set the status to Suspended. */
120 virtual void suspend();
121
122 /** Set the status to Unallocated. */
123 virtual void deallocate(int delay = 0);
124
125 /** Set the status to Halted. */
126 virtual void halt();
127
128#if FULL_SYSTEM
129 /** Dumps the function profiling information.
130 * @todo: Implement.
131 */
132 virtual void dumpFuncProfile();
133#endif
134 /** Takes over execution of a thread from another CPU. */
135 virtual void takeOverFrom(ThreadContext *old_context);
136
137 /** Registers statistics associated with this TC. */
138 virtual void regStats(const std::string &name);
139
140 /** Serializes state. */
141 virtual void serialize(std::ostream &os);
142 /** Unserializes state. */
143 virtual void unserialize(Checkpoint *cp, const std::string &section);
144
145#if FULL_SYSTEM
146 /** Reads the last tick that this thread was activated on. */
147 virtual Tick readLastActivate();
148 /** Reads the last tick that this thread was suspended on. */
149 virtual Tick readLastSuspend();
150
151 /** Clears the function profiling information. */
152 virtual void profileClear();
153 /** Samples the function profiling information. */
154 virtual void profileSample();
155#endif
156 /** Returns this thread's ID number. */
157 virtual int getThreadNum() { return thread->readTid(); }
158
159 /** Returns the instruction this thread is currently committing.
160 * Only used when an instruction faults.
161 */
162 virtual TheISA::MachInst getInst();
163
164 /** Copies the architectural registers from another TC into this TC. */
165 virtual void copyArchRegs(ThreadContext *tc);
166
167 /** Resets all architectural registers to 0. */
168 virtual void clearArchRegs();
169
170 /** Reads an integer register. */
171 virtual uint64_t readIntReg(int reg_idx);
172
173 virtual FloatReg readFloatReg(int reg_idx, int width);
174
175 virtual FloatReg readFloatReg(int reg_idx);
176
177 virtual FloatRegBits readFloatRegBits(int reg_idx, int width);
178
179 virtual FloatRegBits readFloatRegBits(int reg_idx);
180
181 /** Sets an integer register to a value. */
182 virtual void setIntReg(int reg_idx, uint64_t val);
183
184 virtual void setFloatReg(int reg_idx, FloatReg val, int width);
185
186 virtual void setFloatReg(int reg_idx, FloatReg val);
187
188 virtual void setFloatRegBits(int reg_idx, FloatRegBits val, int width);
189
190 virtual void setFloatRegBits(int reg_idx, FloatRegBits val);
191
192 /** Reads this thread's PC. */
193 virtual uint64_t readPC()
194 { return cpu->readPC(thread->readTid()); }
195
196 /** Sets this thread's PC. */
197 virtual void setPC(uint64_t val);
198
199 /** Reads this thread's next PC. */
200 virtual uint64_t readNextPC()
201 { return cpu->readNextPC(thread->readTid()); }
202
203 /** Sets this thread's next PC. */
204 virtual void setNextPC(uint64_t val);
205
206 /** Reads a miscellaneous register. */
207 virtual MiscReg readMiscRegNoEffect(int misc_reg)
208 { return cpu->readMiscRegNoEffect(misc_reg, thread->readTid()); }
209
210 /** Reads a misc. register, including any side-effects the
211 * read might have as defined by the architecture. */
212 virtual MiscReg readMiscReg(int misc_reg)
213 { return cpu->readMiscReg(misc_reg, thread->readTid()); }
214
215 /** Sets a misc. register. */
216 virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
217
218 /** Sets a misc. register, including any side-effects the
219 * write might have as defined by the architecture. */
220 virtual void setMiscReg(int misc_reg, const MiscReg &val);
221
222 /** Returns the number of consecutive store conditional failures. */
223 // @todo: Figure out where these store cond failures should go.
224 virtual unsigned readStCondFailures()
225 { return thread->storeCondFailures; }
226
227 /** Sets the number of consecutive store conditional failures. */
228 virtual void setStCondFailures(unsigned sc_failures)
229 { thread->storeCondFailures = sc_failures; }
230
231 // Only really makes sense for old CPU model. Lots of code
232 // outside the CPU still checks this function, so it will
233 // always return false to keep everything working.
234 /** Checks if the thread is misspeculating. Because it is
235 * very difficult to determine if the thread is
236 * misspeculating, this is set as false. */
237 virtual bool misspeculating() { return false; }
238
239#if !FULL_SYSTEM
240 /** Gets a syscall argument by index. */
241 virtual IntReg getSyscallArg(int i);
242
243 /** Sets a syscall argument. */
244 virtual void setSyscallArg(int i, IntReg val);
245
246 /** Sets the syscall return value. */
247 virtual void setSyscallReturn(SyscallReturn return_value);
248
249 /** Executes a syscall in SE mode. */
250 virtual void syscall(int64_t callnum)
251 { return cpu->syscall(callnum, thread->readTid()); }
252
253 /** Reads the funcExeInst counter. */
254 virtual Counter readFuncExeInst() { return thread->funcExeInst; }
255#endif
256};
257
258#endif