style: Remove non-leading tabs everywhere they shouldn't be. Developers should config...
[gem5.git] / src / arch / sparc / miscregfile.hh
1 /*
2 * Copyright (c) 2003-2005 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: Gabe Black
29 * Ali Saidi
30 */
31
32 #ifndef __ARCH_SPARC_MISCREGFILE_HH__
33 #define __ARCH_SPARC_MISCREGFILE_HH__
34
35 #include "arch/sparc/faults.hh"
36 #include "arch/sparc/isa_traits.hh"
37 #include "arch/sparc/types.hh"
38 #include "cpu/cpuevent.hh"
39
40 #include <string>
41
42 class Checkpoint;
43
44 namespace SparcISA
45 {
46 //These functions map register indices to names
47 std::string getMiscRegName(RegIndex);
48
49 enum MiscRegIndex
50 {
51 /** Ancillary State Registers */
52 // MISCREG_Y,
53 // MISCREG_CCR,
54 MISCREG_ASI,
55 MISCREG_TICK,
56 MISCREG_FPRS,
57 MISCREG_PCR,
58 MISCREG_PIC,
59 MISCREG_GSR,
60 MISCREG_SOFTINT_SET,
61 MISCREG_SOFTINT_CLR,
62 MISCREG_SOFTINT, /* 10 */
63 MISCREG_TICK_CMPR,
64 MISCREG_STICK,
65 MISCREG_STICK_CMPR,
66
67 /** Privilged Registers */
68 MISCREG_TPC,
69 MISCREG_TNPC,
70 MISCREG_TSTATE,
71 MISCREG_TT,
72 MISCREG_PRIVTICK,
73 MISCREG_TBA,
74 MISCREG_PSTATE, /* 20 */
75 MISCREG_TL,
76 MISCREG_PIL,
77 MISCREG_CWP,
78 // MISCREG_CANSAVE,
79 // MISCREG_CANRESTORE,
80 // MISCREG_CLEANWIN,
81 // MISCREG_OTHERWIN,
82 // MISCREG_WSTATE,
83 MISCREG_GL,
84
85 /** Hyper privileged registers */
86 MISCREG_HPSTATE, /* 30 */
87 MISCREG_HTSTATE,
88 MISCREG_HINTP,
89 MISCREG_HTBA,
90 MISCREG_HVER,
91 MISCREG_STRAND_STS_REG,
92 MISCREG_HSTICK_CMPR,
93
94 /** Floating Point Status Register */
95 MISCREG_FSR,
96
97 /** MMU Internal Registers */
98 MISCREG_MMU_P_CONTEXT,
99 MISCREG_MMU_S_CONTEXT, /* 40 */
100 MISCREG_MMU_PART_ID,
101 MISCREG_MMU_LSU_CTRL,
102
103 /** Scratchpad regiscers **/
104 MISCREG_SCRATCHPAD_R0, /* 60 */
105 MISCREG_SCRATCHPAD_R1,
106 MISCREG_SCRATCHPAD_R2,
107 MISCREG_SCRATCHPAD_R3,
108 MISCREG_SCRATCHPAD_R4,
109 MISCREG_SCRATCHPAD_R5,
110 MISCREG_SCRATCHPAD_R6,
111 MISCREG_SCRATCHPAD_R7,
112
113 /* CPU Queue Registers */
114 MISCREG_QUEUE_CPU_MONDO_HEAD,
115 MISCREG_QUEUE_CPU_MONDO_TAIL,
116 MISCREG_QUEUE_DEV_MONDO_HEAD, /* 70 */
117 MISCREG_QUEUE_DEV_MONDO_TAIL,
118 MISCREG_QUEUE_RES_ERROR_HEAD,
119 MISCREG_QUEUE_RES_ERROR_TAIL,
120 MISCREG_QUEUE_NRES_ERROR_HEAD,
121 MISCREG_QUEUE_NRES_ERROR_TAIL,
122
123 /* All the data for the TLB packed up in one register. */
124 MISCREG_TLB_DATA,
125 MISCREG_NUMMISCREGS
126 };
127
128 struct HPSTATE {
129 const static uint64_t id = 0x800; // this impl. dependent (id) field m
130 const static uint64_t ibe = 0x400;
131 const static uint64_t red = 0x20;
132 const static uint64_t hpriv = 0x4;
133 const static uint64_t tlz = 0x1;
134 };
135
136
137 struct PSTATE {
138 const static int cle = 0x200;
139 const static int tle = 0x100;
140 const static int mm = 0xC0;
141 const static int pef = 0x10;
142 const static int am = 0x8;
143 const static int priv = 0x4;
144 const static int ie = 0x2;
145 };
146
147 struct STS {
148 const static int st_idle = 0x00;
149 const static int st_wait = 0x01;
150 const static int st_halt = 0x02;
151 const static int st_run = 0x05;
152 const static int st_spec_run = 0x07;
153 const static int st_spec_rdy = 0x13;
154 const static int st_ready = 0x19;
155 const static int active = 0x01;
156 const static int speculative = 0x04;
157 const static int shft_id = 8;
158 const static int shft_fsm0 = 31;
159 const static int shft_fsm1 = 26;
160 const static int shft_fsm2 = 21;
161 const static int shft_fsm3 = 16;
162 };
163
164
165 const int NumMiscArchRegs = MISCREG_NUMMISCREGS;
166 const int NumMiscRegs = MISCREG_NUMMISCREGS;
167
168 // The control registers, broken out into fields
169 class MiscRegFile
170 {
171 private:
172
173 /* ASR Registers */
174 //uint64_t y; // Y (used in obsolete multiplication)
175 //uint8_t ccr; // Condition Code Register
176 uint8_t asi; // Address Space Identifier
177 uint64_t tick; // Hardware clock-tick counter
178 uint8_t fprs; // Floating-Point Register State
179 uint64_t gsr; // General Status Register
180 uint64_t softint;
181 uint64_t tick_cmpr; // Hardware tick compare registers
182 uint64_t stick; // Hardware clock-tick counter
183 uint64_t stick_cmpr; // Hardware tick compare registers
184
185
186 /* Privileged Registers */
187 uint64_t tpc[MaxTL]; // Trap Program Counter (value from
188 // previous trap level)
189 uint64_t tnpc[MaxTL]; // Trap Next Program Counter (value from
190 // previous trap level)
191 uint64_t tstate[MaxTL]; // Trap State
192 uint16_t tt[MaxTL]; // Trap Type (Type of trap which occured
193 // on the previous level)
194 uint64_t tba; // Trap Base Address
195
196 uint16_t pstate; // Process State Register
197 uint8_t tl; // Trap Level
198 uint8_t pil; // Process Interrupt Register
199 uint8_t cwp; // Current Window Pointer
200 //uint8_t cansave; // Savable windows
201 //uint8_t canrestore; // Restorable windows
202 //uint8_t cleanwin; // Clean windows
203 //uint8_t otherwin; // Other windows
204 //uint8_t wstate; // Window State
205 uint8_t gl; // Global level register
206
207 /** Hyperprivileged Registers */
208 uint64_t hpstate; // Hyperprivileged State Register
209 uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
210 uint64_t hintp;
211 uint64_t htba; // Hyperprivileged Trap Base Address register
212 uint64_t hstick_cmpr; // Hardware tick compare registers
213
214 uint64_t strandStatusReg;// Per strand status register
215
216 /** Floating point misc registers. */
217 uint64_t fsr; // Floating-Point State Register
218
219 /** MMU Internal Registers */
220 uint16_t priContext;
221 uint16_t secContext;
222 uint16_t partId;
223 uint64_t lsuCtrlReg;
224
225 uint64_t scratchPad[8];
226
227 uint64_t cpu_mondo_head;
228 uint64_t cpu_mondo_tail;
229 uint64_t dev_mondo_head;
230 uint64_t dev_mondo_tail;
231 uint64_t res_error_head;
232 uint64_t res_error_tail;
233 uint64_t nres_error_head;
234 uint64_t nres_error_tail;
235
236 // These need to check the int_dis field and if 0 then
237 // set appropriate bit in softint and checkinterrutps on the cpu
238 #if FULL_SYSTEM
239 void setFSReg(int miscReg, const MiscReg &val, ThreadContext *tc);
240 MiscReg readFSReg(int miscReg, ThreadContext * tc);
241
242 // Update interrupt state on softint or pil change
243 void checkSoftInt(ThreadContext *tc);
244
245 /** Process a tick compare event and generate an interrupt on the cpu if
246 * appropriate. */
247 void processTickCompare(ThreadContext *tc);
248 void processSTickCompare(ThreadContext *tc);
249 void processHSTickCompare(ThreadContext *tc);
250
251 typedef CpuEventWrapper<MiscRegFile,
252 &MiscRegFile::processTickCompare> TickCompareEvent;
253 TickCompareEvent *tickCompare;
254
255 typedef CpuEventWrapper<MiscRegFile,
256 &MiscRegFile::processSTickCompare> STickCompareEvent;
257 STickCompareEvent *sTickCompare;
258
259 typedef CpuEventWrapper<MiscRegFile,
260 &MiscRegFile::processHSTickCompare> HSTickCompareEvent;
261 HSTickCompareEvent *hSTickCompare;
262 #endif
263 public:
264
265 void clear();
266
267 MiscRegFile()
268 {
269 clear();
270 }
271
272 MiscReg readRegNoEffect(int miscReg);
273
274 MiscReg readReg(int miscReg, ThreadContext *tc);
275
276 void setRegNoEffect(int miscReg, const MiscReg &val);
277
278 void setReg(int miscReg,
279 const MiscReg &val, ThreadContext * tc);
280
281 int getInstAsid()
282 {
283 return priContext | (uint32_t)partId << 13;
284 }
285
286 int getDataAsid()
287 {
288 return priContext | (uint32_t)partId << 13;
289 }
290
291 void serialize(std::ostream & os);
292
293 void unserialize(Checkpoint * cp, const std::string & section);
294
295 void copyMiscRegs(ThreadContext * tc);
296
297 protected:
298
299 bool isHyperPriv() { return (hpstate & (1 << 2)); }
300 bool isPriv() { return (hpstate & (1 << 2)) || (pstate & (1 << 2)); }
301 bool isNonPriv() { return !isPriv(); }
302 };
303 }
304
305 #endif