Registers: Get rid of the float register width parameter.
[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 "cpu/exetrace.hh"
36 #include "cpu/thread_context.hh"
37 #include "cpu/inorder/thread_state.hh"
38 #include "cpu/inorder/cpu.hh"
39
40 class TranslatingPort;
41
42 /**
43 * Derived ThreadContext class for use with the InOrderCPU. It
44 * provides the interface for any external objects to access a
45 * single thread's state and some general CPU state. Any time
46 * external objects try to update state through this interface,
47 * the CPU will create an event to squash all in-flight
48 * instructions in order to ensure state is maintained correctly.
49 * It must be defined specifically for the InOrderCPU because
50 * not all architectural state is located within the O3ThreadState
51 * (such as the commit PC, and registers), and specific actions
52 * must be taken when using this interface (such as squashing all
53 * in-flight instructions when doing a write to this interface).
54 */
55 class InOrderThreadContext : public ThreadContext
56 {
57 public:
58 InOrderThreadContext() { }
59
60 /** Pointer to the CPU. */
61 InOrderCPU *cpu;
62
63 /** Pointer to the thread state that this TC corrseponds to. */
64 InOrderThreadState *thread;
65
66
67 /** Returns a pointer to the ITB. */
68 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
69 TheISA::TLB *getITBPtr() { return cpu->getITBPtr(); }
70
71 /** Returns a pointer to the DTB. */
72 /** @TODO: PERF: Should we bind this to a pointer in constructor? */
73 TheISA::TLB *getDTBPtr() { return cpu->getDTBPtr(); }
74
75 System *getSystemPtr() { return cpu->system; }
76
77 /** Returns a pointer to this CPU. */
78 virtual BaseCPU *getCpuPtr() { return cpu; }
79
80 /** Returns a pointer to this CPU. */
81 virtual std::string getCpuName() { return cpu->name(); }
82
83 /** Reads this CPU's ID. */
84 virtual int cpuId() { return cpu->cpuId(); }
85
86 virtual int contextId() { return thread->contextId(); }
87
88 virtual void setContextId(int id) { thread->setContextId(id); }
89
90 /** Returns this thread's ID number. */
91 virtual int threadId() { return thread->threadId(); }
92 virtual void setThreadId(int id) { return thread->setThreadId(id); }
93
94 virtual uint64_t readMicroPC()
95 { return 0; }
96
97 virtual void setMicroPC(uint64_t val) { };
98
99 virtual uint64_t readNextMicroPC()
100 { return 0; }
101
102 virtual void setNextMicroPC(uint64_t val) { };
103
104 virtual TranslatingPort *getMemPort() { return thread->getMemPort(); }
105
106 /** Returns a pointer to this thread's process. */
107 virtual Process *getProcessPtr() { return thread->getProcessPtr(); }
108
109 /** Returns this thread's status. */
110 virtual Status status() const { return thread->status(); }
111
112 /** Sets this thread's status. */
113 virtual void setStatus(Status new_status)
114 { thread->setStatus(new_status); }
115
116 /** Set the status to Active. Optional delay indicates number of
117 * cycles to wait before beginning execution. */
118 virtual void activate(int delay = 1);
119
120 /** Set the status to Suspended. */
121 virtual void suspend(int delay = 0);
122
123 /** Set the status to Halted. */
124 virtual void halt(int delay = 0);
125
126 /** Takes over execution of a thread from another CPU. */
127 virtual void takeOverFrom(ThreadContext *old_context);
128
129 /** Registers statistics associated with this TC. */
130 virtual void regStats(const std::string &name);
131
132 /** Serializes state. */
133 virtual void serialize(std::ostream &os);
134
135 /** Unserializes state. */
136 virtual void unserialize(Checkpoint *cp, const std::string &section);
137
138 /** Returns this thread's ID number. */
139 virtual int getThreadNum() { return thread->readTid(); }
140
141 /** Returns the instruction this thread is currently committing.
142 * Only used when an instruction faults.
143 */
144 virtual TheISA::MachInst getInst();
145
146 /** Copies the architectural registers from another TC into this TC. */
147 virtual void copyArchRegs(ThreadContext *src_tc);
148
149 /** Resets all architectural registers to 0. */
150 virtual void clearArchRegs();
151
152 /** Reads an integer register. */
153 virtual uint64_t readIntReg(int reg_idx);
154
155 virtual FloatReg readFloatReg(int reg_idx);
156
157 virtual FloatRegBits readFloatRegBits(int reg_idx);
158
159 virtual uint64_t readRegOtherThread(int misc_reg, ThreadID tid);
160
161 /** Sets an integer register to a value. */
162 virtual void setIntReg(int reg_idx, uint64_t val);
163
164 virtual void setFloatReg(int reg_idx, FloatReg val);
165
166 virtual void setFloatRegBits(int reg_idx, FloatRegBits val);
167
168 virtual void setRegOtherThread(int misc_reg, const MiscReg &val,
169 ThreadID tid);
170
171 /** Reads this thread's PC. */
172 virtual uint64_t readPC()
173 { return cpu->readPC(thread->readTid()); }
174
175 /** Sets this thread's PC. */
176 virtual void setPC(uint64_t val);
177
178 /** Reads this thread's next PC. */
179 virtual uint64_t readNextPC()
180 { return cpu->readNextPC(thread->readTid()); }
181
182 /** Sets this thread's next PC. */
183 virtual void setNextPC(uint64_t val);
184
185 virtual uint64_t readNextNPC()
186 { return cpu->readNextNPC(thread->readTid()); }
187
188 virtual void setNextNPC(uint64_t val);
189
190 /** Reads a miscellaneous register. */
191 virtual MiscReg readMiscRegNoEffect(int misc_reg)
192 { return cpu->readMiscRegNoEffect(misc_reg, thread->readTid()); }
193
194 /** Reads a misc. register, including any side-effects the
195 * read might have as defined by the architecture. */
196 virtual MiscReg readMiscReg(int misc_reg)
197 { return cpu->readMiscReg(misc_reg, thread->readTid()); }
198
199 /** Sets a misc. register. */
200 virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
201
202 /** Sets a misc. register, including any side-effects the
203 * write might have as defined by the architecture. */
204 virtual void setMiscReg(int misc_reg, const MiscReg &val);
205
206 virtual int flattenIntIndex(int reg)
207 { return cpu->isa[thread->readTid()].flattenIntIndex(reg); }
208
209 virtual int flattenFloatIndex(int reg)
210 { return cpu->isa[thread->readTid()].flattenFloatIndex(reg); }
211
212 virtual void activateContext(int delay)
213 { cpu->activateContext(thread->readTid(), delay); }
214
215 virtual void deallocateContext()
216 { cpu->deallocateContext(thread->readTid()); }
217
218 /** Returns the number of consecutive store conditional failures. */
219 // @todo: Figure out where these store cond failures should go.
220 virtual unsigned readStCondFailures()
221 { return thread->storeCondFailures; }
222
223 /** Sets the number of consecutive store conditional failures. */
224 virtual void setStCondFailures(unsigned sc_failures)
225 { thread->storeCondFailures = sc_failures; }
226
227 // Only really makes sense for old CPU model. Lots of code
228 // outside the CPU still checks this function, so it will
229 // always return false to keep everything working.
230 /** Checks if the thread is misspeculating. Because it is
231 * very difficult to determine if the thread is
232 * misspeculating, this is set as false. */
233 virtual bool misspeculating() { return false; }
234
235 /** Executes a syscall in SE mode. */
236 virtual void syscall(int64_t callnum)
237 { return cpu->syscall(callnum, thread->readTid()); }
238
239 /** Reads the funcExeInst counter. */
240 virtual Counter readFuncExeInst() { return thread->funcExeInst; }
241
242 virtual void changeRegFileContext(unsigned param,
243 unsigned val)
244 { panic("Not supported!"); }
245 };
246
247 #endif