2 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
28 * Authors: Korey Sewell
32 #ifndef __CPU_INORDER_THREAD_CONTEXT_HH__
33 #define __CPU_INORDER_THREAD_CONTEXT_HH__
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"
42 class EndQuiesceEvent;
47 class TranslatingPort;
50 * Derived ThreadContext class for use with the InOrderCPU. It
51 * provides the interface for any external objects to access a
52 * single thread's state and some general CPU state. Any time
53 * external objects try to update state through this interface,
54 * the CPU will create an event to squash all in-flight
55 * instructions in order to ensure state is maintained correctly.
56 * It must be defined specifically for the InOrderCPU because
57 * not all architectural state is located within the O3ThreadState
58 * (such as the commit PC, and registers), and specific actions
59 * must be taken when using this interface (such as squashing all
60 * in-flight instructions when doing a write to this interface).
62 class InOrderThreadContext : public ThreadContext
65 InOrderThreadContext() { }
67 /** Pointer to the CPU. */
70 /** Pointer to the thread state that this TC corrseponds to. */
71 InOrderThreadState *thread;
73 /** Returns a pointer to the ITB. */
74 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
75 TheISA::TLB *getITBPtr() { return cpu->getITBPtr(); }
77 /** Returns a pointer to the DTB. */
78 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
79 TheISA::TLB *getDTBPtr() { return cpu->getDTBPtr(); }
81 Decoder *getDecoderPtr() { return cpu->getDecoderPtr(); }
83 System *getSystemPtr() { return cpu->system; }
85 /** Returns a pointer to this CPU. */
86 BaseCPU *getCpuPtr() { return cpu; }
88 /** Returns a pointer to this CPU. */
89 std::string getCpuName() { return cpu->name(); }
91 /** Reads this CPU's ID. */
92 int cpuId() { return cpu->cpuId(); }
94 int contextId() { return thread->contextId(); }
96 void setContextId(int id) { thread->setContextId(id); }
98 /** Returns this thread's ID number. */
99 int threadId() { return thread->threadId(); }
100 void setThreadId(int id) { return thread->setThreadId(id); }
102 uint64_t readMicroPC()
105 void setMicroPC(uint64_t val) { };
107 uint64_t readNextMicroPC()
110 void setNextMicroPC(uint64_t val) { };
112 /** Returns a pointer to physical memory. */
113 PhysicalMemory *getPhysMemPtr()
114 { assert(0); return 0; /*return cpu->physmem;*/ }
116 /** Returns a pointer to this thread's kernel statistics. */
117 TheISA::Kernel::Statistics *getKernelStats()
118 { return thread->kernelStats; }
120 void connectMemPorts(ThreadContext *tc)
121 { thread->connectMemPorts(tc); }
123 /** Dumps the function profiling information.
126 void dumpFuncProfile();
128 /** Reads the last tick that this thread was activated on. */
129 Tick readLastActivate();
130 /** Reads the last tick that this thread was suspended on. */
131 Tick readLastSuspend();
133 /** Clears the function profiling information. */
136 /** Samples the function profiling information. */
137 void profileSample();
139 /** Returns pointer to the quiesce event. */
140 EndQuiesceEvent *getQuiesceEvent()
142 return this->thread->quiesceEvent;
145 /** Returns a pointer to this thread's process. */
146 Process *getProcessPtr() { return thread->getProcessPtr(); }
148 TranslatingPort *getMemPort() { return thread->getMemPort(); }
150 VirtualPort *getVirtPort();
151 FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
153 /** Returns this thread's status. */
154 Status status() const { return thread->status(); }
156 /** Sets this thread's status. */
157 void setStatus(Status new_status)
158 { thread->setStatus(new_status); }
160 /** Set the status to Active. Optional delay indicates number of
161 * cycles to wait before beginning execution. */
162 void activate(int delay = 1);
164 /** Set the status to Suspended. */
165 void suspend(int delay = 0);
167 /** Set the status to Halted. */
168 void halt(int delay = 0);
170 /** Takes over execution of a thread from another CPU. */
171 void takeOverFrom(ThreadContext *old_context);
173 /** Registers statistics associated with this TC. */
174 void regStats(const std::string &name);
176 /** Serializes state. */
177 void serialize(std::ostream &os);
179 /** Unserializes state. */
180 void unserialize(Checkpoint *cp, const std::string §ion);
182 /** Returns this thread's ID number. */
183 int getThreadNum() { return thread->threadId(); }
185 /** Copies the architectural registers from another TC into this TC. */
186 void copyArchRegs(ThreadContext *src_tc);
188 /** Resets all architectural registers to 0. */
189 void clearArchRegs();
191 /** Reads an integer register. */
192 uint64_t readIntReg(int reg_idx);
194 FloatReg readFloatReg(int reg_idx);
196 FloatRegBits readFloatRegBits(int reg_idx);
198 uint64_t readRegOtherThread(int misc_reg, ThreadID tid);
200 /** Sets an integer register to a value. */
201 void setIntReg(int reg_idx, uint64_t val);
203 void setFloatReg(int reg_idx, FloatReg val);
205 void setFloatRegBits(int reg_idx, FloatRegBits val);
207 void setRegOtherThread(int misc_reg,
211 /** Reads this thread's PC. */
212 TheISA::PCState pcState()
213 { return cpu->pcState(thread->threadId()); }
215 /** Sets this thread's PC. */
216 void pcState(const TheISA::PCState &val)
217 { cpu->pcState(val, thread->threadId()); }
220 { return cpu->instAddr(thread->threadId()); }
223 { return cpu->nextInstAddr(thread->threadId()); }
226 { return cpu->microPC(thread->threadId()); }
228 /** Reads a miscellaneous register. */
229 MiscReg readMiscRegNoEffect(int misc_reg)
230 { return cpu->readMiscRegNoEffect(misc_reg, thread->threadId()); }
232 /** Reads a misc. register, including any side-effects the
233 * read might have as defined by the architecture. */
234 MiscReg readMiscReg(int misc_reg)
235 { return cpu->readMiscReg(misc_reg, thread->threadId()); }
237 /** Sets a misc. register. */
238 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
240 /** Sets a misc. register, including any side-effects the
241 * write might have as defined by the architecture. */
242 void setMiscReg(int misc_reg, const MiscReg &val);
244 int flattenIntIndex(int reg)
245 { return cpu->isa[thread->threadId()].flattenIntIndex(reg); }
247 int flattenFloatIndex(int reg)
248 { return cpu->isa[thread->threadId()].flattenFloatIndex(reg); }
250 void activateContext(int delay)
251 { cpu->activateContext(thread->threadId(), delay); }
253 void deallocateContext()
254 { cpu->deallocateContext(thread->threadId()); }
256 /** Returns the number of consecutive store conditional failures. */
257 // @todo: Figure out where these store cond failures should go.
258 unsigned readStCondFailures()
259 { return thread->storeCondFailures; }
261 /** Sets the number of consecutive store conditional failures. */
262 void setStCondFailures(unsigned sc_failures)
263 { thread->storeCondFailures = sc_failures; }
265 // Only really makes sense for old CPU model. Lots of code
266 // outside the CPU still checks this function, so it will
267 // always return false to keep everything working.
268 /** Checks if the thread is misspeculating. Because it is
269 * very difficult to determine if the thread is
270 * misspeculating, this is set as false. */
271 bool misspeculating() { return false; }
273 /** Executes a syscall in SE mode. */
274 void syscall(int64_t callnum)
275 { return cpu->syscall(callnum, thread->threadId()); }
277 /** Reads the funcExeInst counter. */
278 Counter readFuncExeInst() { return thread->funcExeInst; }
280 void changeRegFileContext(unsigned param,
282 { panic("Not supported!"); }