Merge zizzer:/bk/newmem
[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 MISCREG_MMU_ITLB_C0_TSB_PS0,
104 MISCREG_MMU_ITLB_C0_TSB_PS1,
105 MISCREG_MMU_ITLB_C0_CONFIG,
106 MISCREG_MMU_ITLB_CX_TSB_PS0,
107 MISCREG_MMU_ITLB_CX_TSB_PS1,
108 MISCREG_MMU_ITLB_CX_CONFIG,
109 MISCREG_MMU_ITLB_SFSR,
110 MISCREG_MMU_ITLB_TAG_ACCESS, /* 50 */
111
112 MISCREG_MMU_DTLB_C0_TSB_PS0,
113 MISCREG_MMU_DTLB_C0_TSB_PS1,
114 MISCREG_MMU_DTLB_C0_CONFIG,
115 MISCREG_MMU_DTLB_CX_TSB_PS0,
116 MISCREG_MMU_DTLB_CX_TSB_PS1,
117 MISCREG_MMU_DTLB_CX_CONFIG,
118 MISCREG_MMU_DTLB_SFSR,
119 MISCREG_MMU_DTLB_SFAR,
120 MISCREG_MMU_DTLB_TAG_ACCESS,
121
122 /** Scratchpad regiscers **/
123 MISCREG_SCRATCHPAD_R0, /* 60 */
124 MISCREG_SCRATCHPAD_R1,
125 MISCREG_SCRATCHPAD_R2,
126 MISCREG_SCRATCHPAD_R3,
127 MISCREG_SCRATCHPAD_R4,
128 MISCREG_SCRATCHPAD_R5,
129 MISCREG_SCRATCHPAD_R6,
130 MISCREG_SCRATCHPAD_R7,
131
132 /* CPU Queue Registers */
133 MISCREG_QUEUE_CPU_MONDO_HEAD,
134 MISCREG_QUEUE_CPU_MONDO_TAIL,
135 MISCREG_QUEUE_DEV_MONDO_HEAD, /* 70 */
136 MISCREG_QUEUE_DEV_MONDO_TAIL,
137 MISCREG_QUEUE_RES_ERROR_HEAD,
138 MISCREG_QUEUE_RES_ERROR_TAIL,
139 MISCREG_QUEUE_NRES_ERROR_HEAD,
140 MISCREG_QUEUE_NRES_ERROR_TAIL,
141
142 /* All the data for the TLB packed up in one register. */
143 MISCREG_TLB_DATA,
144 MISCREG_NUMMISCREGS
145 };
146
147 struct HPSTATE {
148 const static uint64_t id = 0x800; // this impl. dependent (id) field m
149 const static uint64_t ibe = 0x400;
150 const static uint64_t red = 0x20;
151 const static uint64_t hpriv = 0x4;
152 const static uint64_t tlz = 0x1;
153 };
154
155
156 struct PSTATE {
157 const static int cle = 0x200;
158 const static int tle = 0x100;
159 const static int mm = 0xC0;
160 const static int pef = 0x10;
161 const static int am = 0x8;
162 const static int priv = 0x4;
163 const static int ie = 0x2;
164 };
165
166
167 const int NumMiscArchRegs = MISCREG_NUMMISCREGS;
168 const int NumMiscRegs = MISCREG_NUMMISCREGS;
169
170 // The control registers, broken out into fields
171 class MiscRegFile
172 {
173 private:
174
175 /* ASR Registers */
176 //uint64_t y; // Y (used in obsolete multiplication)
177 //uint8_t ccr; // Condition Code Register
178 uint8_t asi; // Address Space Identifier
179 uint64_t tick; // Hardware clock-tick counter
180 uint8_t fprs; // Floating-Point Register State
181 uint64_t gsr; // General Status Register
182 uint64_t softint;
183 uint64_t tick_cmpr; // Hardware tick compare registers
184 uint64_t stick; // Hardware clock-tick counter
185 uint64_t stick_cmpr; // Hardware tick compare registers
186
187
188 /* Privileged Registers */
189 uint64_t tpc[MaxTL]; // Trap Program Counter (value from
190 // previous trap level)
191 uint64_t tnpc[MaxTL]; // Trap Next Program Counter (value from
192 // previous trap level)
193 uint64_t tstate[MaxTL]; // Trap State
194 uint16_t tt[MaxTL]; // Trap Type (Type of trap which occured
195 // on the previous level)
196 uint64_t tba; // Trap Base Address
197
198 uint16_t pstate; // Process State Register
199 uint8_t tl; // Trap Level
200 uint8_t pil; // Process Interrupt Register
201 uint8_t cwp; // Current Window Pointer
202 //uint8_t cansave; // Savable windows
203 //uint8_t canrestore; // Restorable windows
204 //uint8_t cleanwin; // Clean windows
205 //uint8_t otherwin; // Other windows
206 //uint8_t wstate; // Window State
207 uint8_t gl; // Global level register
208
209 /** Hyperprivileged Registers */
210 uint64_t hpstate; // Hyperprivileged State Register
211 uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
212 uint64_t hintp;
213 uint64_t htba; // Hyperprivileged Trap Base Address register
214 uint64_t hstick_cmpr; // Hardware tick compare registers
215
216 uint64_t strandStatusReg;// Per strand status register
217
218 /** Floating point misc registers. */
219 uint64_t fsr; // Floating-Point State Register
220
221 /** MMU Internal Registers */
222 uint16_t priContext;
223 uint16_t secContext;
224 uint16_t partId;
225 uint64_t lsuCtrlReg;
226
227 uint64_t iTlbC0TsbPs0;
228 uint64_t iTlbC0TsbPs1;
229 uint64_t iTlbC0Config;
230 uint64_t iTlbCXTsbPs0;
231 uint64_t iTlbCXTsbPs1;
232 uint64_t iTlbCXConfig;
233 uint64_t iTlbSfsr;
234 uint64_t iTlbTagAccess;
235
236 uint64_t dTlbC0TsbPs0;
237 uint64_t dTlbC0TsbPs1;
238 uint64_t dTlbC0Config;
239 uint64_t dTlbCXTsbPs0;
240 uint64_t dTlbCXTsbPs1;
241 uint64_t dTlbCXConfig;
242 uint64_t dTlbSfsr;
243 uint64_t dTlbSfar;
244 uint64_t dTlbTagAccess;
245
246 uint64_t scratchPad[8];
247
248 uint64_t cpu_mondo_head;
249 uint64_t cpu_mondo_tail;
250 uint64_t dev_mondo_head;
251 uint64_t dev_mondo_tail;
252 uint64_t res_error_head;
253 uint64_t res_error_tail;
254 uint64_t nres_error_head;
255 uint64_t nres_error_tail;
256
257 // These need to check the int_dis field and if 0 then
258 // set appropriate bit in softint and checkinterrutps on the cpu
259 #if FULL_SYSTEM
260 void setFSRegWithEffect(int miscReg, const MiscReg &val,
261 ThreadContext *tc);
262 MiscReg readFSRegWithEffect(int miscReg, ThreadContext * tc);
263
264 // Update interrupt state on softint or pil change
265 void checkSoftInt(ThreadContext *tc);
266
267 /** Process a tick compare event and generate an interrupt on the cpu if
268 * appropriate. */
269 void processTickCompare(ThreadContext *tc);
270 void processSTickCompare(ThreadContext *tc);
271 void processHSTickCompare(ThreadContext *tc);
272
273 typedef CpuEventWrapper<MiscRegFile,
274 &MiscRegFile::processTickCompare> TickCompareEvent;
275 TickCompareEvent *tickCompare;
276
277 typedef CpuEventWrapper<MiscRegFile,
278 &MiscRegFile::processSTickCompare> STickCompareEvent;
279 STickCompareEvent *sTickCompare;
280
281 typedef CpuEventWrapper<MiscRegFile,
282 &MiscRegFile::processHSTickCompare> HSTickCompareEvent;
283 HSTickCompareEvent *hSTickCompare;
284 #endif
285 public:
286
287 void clear();
288
289 MiscRegFile()
290 {
291 clear();
292 }
293
294 MiscReg readReg(int miscReg);
295
296 MiscReg readRegWithEffect(int miscReg, ThreadContext *tc);
297
298 void setReg(int miscReg, const MiscReg &val);
299
300 void setRegWithEffect(int miscReg,
301 const MiscReg &val, ThreadContext * tc);
302
303 int getInstAsid()
304 {
305 return priContext | (uint32_t)partId << 13;
306 }
307
308 int getDataAsid()
309 {
310 return priContext | (uint32_t)partId << 13;
311 }
312
313 void serialize(std::ostream & os);
314
315 void unserialize(Checkpoint * cp, const std::string & section);
316
317 void copyMiscRegs(ThreadContext * tc);
318
319 protected:
320
321 bool isHyperPriv() { return (hpstate & (1 << 2)); }
322 bool isPriv() { return (hpstate & (1 << 2)) || (pstate & (1 << 2)); }
323 bool isNonPriv() { return !isPriv(); }
324 };
325 }
326
327 #endif