MEM: Clean-up of Functional/Virtual/TranslatingPort remnants
[gem5.git] / src / cpu / inorder / thread_context.hh
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
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: Korey Sewell
29 *
30 */
31
32 #ifndef __CPU_INORDER_THREAD_CONTEXT_HH__
33 #define __CPU_INORDER_THREAD_CONTEXT_HH__
34
35 #include "config/the_isa.hh"
36 #include "cpu/inorder/cpu.hh"
37 #include "cpu/inorder/thread_state.hh"
38 #include "cpu/exetrace.hh"
39 #include "cpu/thread_context.hh"
40 #include "arch/kernel_stats.hh"
41
42 class EndQuiesceEvent;
43 namespace Kernel {
44 class Statistics;
45 };
46
47 /**
48 * Derived ThreadContext class for use with the InOrderCPU. It
49 * provides the interface for any external objects to access a
50 * single thread's state and some general CPU state. Any time
51 * external objects try to update state through this interface,
52 * the CPU will create an event to squash all in-flight
53 * instructions in order to ensure state is maintained correctly.
54 * It must be defined specifically for the InOrderCPU because
55 * not all architectural state is located within the O3ThreadState
56 * (such as the commit PC, and registers), and specific actions
57 * must be taken when using this interface (such as squashing all
58 * in-flight instructions when doing a write to this interface).
59 */
60 class InOrderThreadContext : public ThreadContext
61 {
62 public:
63 InOrderThreadContext() { }
64
65 /** Pointer to the CPU. */
66 InOrderCPU *cpu;
67
68 /** Pointer to the thread state that this TC corrseponds to. */
69 InOrderThreadState *thread;
70
71 /** Returns a pointer to the ITB. */
72 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
73 TheISA::TLB *getITBPtr() { return cpu->getITBPtr(); }
74
75 /** Returns a pointer to the DTB. */
76 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
77 TheISA::TLB *getDTBPtr() { return cpu->getDTBPtr(); }
78
79 Decoder *getDecoderPtr() { return cpu->getDecoderPtr(); }
80
81 System *getSystemPtr() { return cpu->system; }
82
83 /** Returns a pointer to this CPU. */
84 BaseCPU *getCpuPtr() { return cpu; }
85
86 /** Returns a pointer to this CPU. */
87 std::string getCpuName() { return cpu->name(); }
88
89 /** Reads this CPU's ID. */
90 int cpuId() { return cpu->cpuId(); }
91
92 int contextId() { return thread->contextId(); }
93
94 void setContextId(int id) { thread->setContextId(id); }
95
96 /** Returns this thread's ID number. */
97 int threadId() { return thread->threadId(); }
98 void setThreadId(int id) { return thread->setThreadId(id); }
99
100 uint64_t readMicroPC()
101 { return 0; }
102
103 void setMicroPC(uint64_t val) { };
104
105 uint64_t readNextMicroPC()
106 { return 0; }
107
108 void setNextMicroPC(uint64_t val) { };
109
110 #if FULL_SYSTEM
111 /** Returns a pointer to physical memory. */
112 PhysicalMemory *getPhysMemPtr()
113 { assert(0); return 0; /*return cpu->physmem;*/ }
114
115 /** Returns a pointer to this thread's kernel statistics. */
116 TheISA::Kernel::Statistics *getKernelStats()
117 { return thread->kernelStats; }
118
119 PortProxy* getPhysProxy() { return thread->getPhysProxy(); }
120
121 FSTranslatingPortProxy* getVirtProxy();
122
123 void initMemProxies(ThreadContext *tc)
124 { thread->initMemProxies(tc); }
125
126 /** Dumps the function profiling information.
127 * @todo: Implement.
128 */
129 void dumpFuncProfile();
130
131 /** Reads the last tick that this thread was activated on. */
132 Tick readLastActivate();
133 /** Reads the last tick that this thread was suspended on. */
134 Tick readLastSuspend();
135
136 /** Clears the function profiling information. */
137 void profileClear();
138
139 /** Samples the function profiling information. */
140 void profileSample();
141
142 /** Returns pointer to the quiesce event. */
143 EndQuiesceEvent *getQuiesceEvent()
144 {
145 return this->thread->quiesceEvent;
146 }
147 #else
148 SETranslatingPortProxy* getMemProxy() { return thread->getMemProxy(); }
149
150 /** Returns a pointer to this thread's process. */
151 Process *getProcessPtr() { return thread->getProcessPtr(); }
152 #endif
153
154 /** Returns this thread's status. */
155 Status status() const { return thread->status(); }
156
157 /** Sets this thread's status. */
158 void setStatus(Status new_status)
159 { thread->setStatus(new_status); }
160
161 /** Set the status to Active. Optional delay indicates number of
162 * cycles to wait before beginning execution. */
163 void activate(int delay = 1);
164
165 /** Set the status to Suspended. */
166 void suspend(int delay = 0);
167
168 /** Set the status to Halted. */
169 void halt(int delay = 0);
170
171 /** Takes over execution of a thread from another CPU. */
172 void takeOverFrom(ThreadContext *old_context);
173
174 /** Registers statistics associated with this TC. */
175 void regStats(const std::string &name);
176
177 /** Serializes state. */
178 void serialize(std::ostream &os);
179
180 /** Unserializes state. */
181 void unserialize(Checkpoint *cp, const std::string &section);
182
183 /** Returns this thread's ID number. */
184 int getThreadNum() { return thread->threadId(); }
185
186 /** Copies the architectural registers from another TC into this TC. */
187 void copyArchRegs(ThreadContext *src_tc);
188
189 /** Resets all architectural registers to 0. */
190 void clearArchRegs();
191
192 /** Reads an integer register. */
193 uint64_t readIntReg(int reg_idx);
194
195 FloatReg readFloatReg(int reg_idx);
196
197 FloatRegBits readFloatRegBits(int reg_idx);
198
199 uint64_t readRegOtherThread(int misc_reg, ThreadID tid);
200
201 /** Sets an integer register to a value. */
202 void setIntReg(int reg_idx, uint64_t val);
203
204 void setFloatReg(int reg_idx, FloatReg val);
205
206 void setFloatRegBits(int reg_idx, FloatRegBits val);
207
208 void setRegOtherThread(int misc_reg,
209 const MiscReg &val,
210 ThreadID tid);
211
212 /** Reads this thread's PC. */
213 TheISA::PCState pcState()
214 { return cpu->pcState(thread->threadId()); }
215
216 /** Sets this thread's PC. */
217 void pcState(const TheISA::PCState &val)
218 { cpu->pcState(val, thread->threadId()); }
219
220 Addr instAddr()
221 { return cpu->instAddr(thread->threadId()); }
222
223 Addr nextInstAddr()
224 { return cpu->nextInstAddr(thread->threadId()); }
225
226 MicroPC microPC()
227 { return cpu->microPC(thread->threadId()); }
228
229 /** Reads a miscellaneous register. */
230 MiscReg readMiscRegNoEffect(int misc_reg)
231 { return cpu->readMiscRegNoEffect(misc_reg, thread->threadId()); }
232
233 /** Reads a misc. register, including any side-effects the
234 * read might have as defined by the architecture. */
235 MiscReg readMiscReg(int misc_reg)
236 { return cpu->readMiscReg(misc_reg, thread->threadId()); }
237
238 /** Sets a misc. register. */
239 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
240
241 /** Sets a misc. register, including any side-effects the
242 * write might have as defined by the architecture. */
243 void setMiscReg(int misc_reg, const MiscReg &val);
244
245 int flattenIntIndex(int reg)
246 { return cpu->isa[thread->threadId()].flattenIntIndex(reg); }
247
248 int flattenFloatIndex(int reg)
249 { return cpu->isa[thread->threadId()].flattenFloatIndex(reg); }
250
251 void activateContext(int delay)
252 { cpu->activateContext(thread->threadId(), delay); }
253
254 void deallocateContext()
255 { cpu->deallocateContext(thread->threadId()); }
256
257 /** Returns the number of consecutive store conditional failures. */
258 // @todo: Figure out where these store cond failures should go.
259 unsigned readStCondFailures()
260 { return thread->storeCondFailures; }
261
262 /** Sets the number of consecutive store conditional failures. */
263 void setStCondFailures(unsigned sc_failures)
264 { thread->storeCondFailures = sc_failures; }
265
266 // Only really makes sense for old CPU model. Lots of code
267 // outside the CPU still checks this function, so it will
268 // always return false to keep everything working.
269 /** Checks if the thread is misspeculating. Because it is
270 * very difficult to determine if the thread is
271 * misspeculating, this is set as false. */
272 bool misspeculating() { return false; }
273
274 #if !FULL_SYSTEM
275 /** Executes a syscall in SE mode. */
276 void syscall(int64_t callnum)
277 { return cpu->syscall(callnum, thread->threadId()); }
278 #endif
279
280 /** Reads the funcExeInst counter. */
281 Counter readFuncExeInst() { return thread->funcExeInst; }
282
283 void changeRegFileContext(unsigned param,
284 unsigned val)
285 { panic("Not supported!"); }
286 };
287
288 #endif