2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
32 #ifndef __ARCH_SPARC_MISCREGFILE_HH__
33 #define __ARCH_SPARC_MISCREGFILE_HH__
35 #include "arch/sparc/asi.hh"
36 #include "arch/sparc/faults.hh"
37 #include "arch/sparc/isa_traits.hh"
38 #include "arch/sparc/types.hh"
39 #include "cpu/cpuevent.hh"
46 //These functions map register indices to names
47 std::string getMiscRegName(RegIndex);
49 const int AsrStart = 0;
50 const int PrStart = 32;
51 const int HprStart = 64;
52 const int MiscStart = 96;
56 /** Ancillary State Registers */
57 MISCREG_Y = AsrStart + 0,
58 MISCREG_CCR = AsrStart + 2,
59 MISCREG_ASI = AsrStart + 3,
60 MISCREG_TICK = AsrStart + 4,
61 MISCREG_FPRS = AsrStart + 6,
62 MISCREG_PCR = AsrStart + 16,
63 MISCREG_PIC = AsrStart + 17,
64 MISCREG_GSR = AsrStart + 19,
65 MISCREG_SOFTINT_SET = AsrStart + 20,
66 MISCREG_SOFTINT_CLR = AsrStart + 21,
67 MISCREG_SOFTINT = AsrStart + 22,
68 MISCREG_TICK_CMPR = AsrStart + 23,
69 MISCREG_STICK = AsrStart + 24,
70 MISCREG_STICK_CMPR = AsrStart + 25,
72 /** Privilged Registers */
73 MISCREG_TPC = PrStart + 0,
74 MISCREG_TNPC = PrStart + 1,
75 MISCREG_TSTATE = PrStart + 2,
76 MISCREG_TT = PrStart + 3,
77 MISCREG_PRIVTICK = PrStart + 4,
78 MISCREG_TBA = PrStart + 5,
79 MISCREG_PSTATE = PrStart + 6,
80 MISCREG_TL = PrStart + 7,
81 MISCREG_PIL = PrStart + 8,
82 MISCREG_CWP = PrStart + 9,
83 MISCREG_CANSAVE = PrStart + 10,
84 MISCREG_CANRESTORE = PrStart + 11,
85 MISCREG_CLEANWIN = PrStart + 12,
86 MISCREG_OTHERWIN = PrStart + 13,
87 MISCREG_WSTATE = PrStart + 14,
88 MISCREG_GL = PrStart + 16,
90 /** Hyper privileged registers */
91 MISCREG_HPSTATE = HprStart + 0,
92 MISCREG_HTSTATE = HprStart + 1,
93 MISCREG_HINTP = HprStart + 3,
94 MISCREG_HTBA = HprStart + 5,
95 MISCREG_HVER = HprStart + 6,
96 MISCREG_STRAND_STS_REG = HprStart + 16,
97 MISCREG_HSTICK_CMPR = HprStart + 31,
99 /** Floating Point Status Register */
100 MISCREG_FSR = MiscStart + 0
104 // The control registers, broken out into fields
111 uint64_t y; // Y (used in obsolete multiplication)
113 uint64_t value:32; // The actual value stored in y
114 uint64_t :32; // reserved bits
118 uint8_t ccr; // Condition Code Register
121 uint8_t icc:4; // 32-bit condition codes
123 uint8_t c:1; // Carry
124 uint8_t v:1; // Overflow
126 uint8_t n:1; // Negative
130 uint8_t xcc:4; // 64-bit condition codes
132 uint8_t c:1; // Carry
133 uint8_t v:1; // Overflow
135 uint8_t n:1; // Negative
140 uint8_t asi; // Address Space Identifier
142 uint64_t tick; // Hardware clock-tick counter
144 int64_t counter:63; // Clock-tick count
145 uint64_t npt:1; // Non-priveleged trap
149 uint8_t fprs; // Floating-Point Register State
151 uint8_t dl:1; // Dirty lower
152 uint8_t du:1; // Dirty upper
153 uint8_t fef:1; // FPRS enable floating-Point
157 uint64_t gsr; //General Status Register
172 uint64_t int_level:14;
177 uint64_t tick_cmpr; // Hardware tick compare registers
179 uint64_t tick_cmpr:63; // Clock-tick count
180 uint64_t int_dis:1; // Non-priveleged trap
184 uint64_t stick; // Hardware clock-tick counter
186 int64_t :63; // Not used, storage in SparcSystem
187 uint64_t npt:1; // Non-priveleged trap
191 uint64_t stick_cmpr; // Hardware tick compare registers
193 uint64_t tick_cmpr:63; // Clock-tick count
194 uint64_t int_dis:1; // Non-priveleged trap
199 /* Privileged Registers */
200 uint64_t tpc[MaxTL]; // Trap Program Counter (value from
201 // previous trap level)
202 uint64_t tnpc[MaxTL]; // Trap Next Program Counter (value from
203 // previous trap level)
205 uint64_t tstate[MaxTL]; // Trap State
207 //Values are from previous trap level
208 uint64_t cwp:5; // Current Window Pointer
209 uint64_t :3; // Reserved bits
210 uint64_t pstate:13; // Process State
211 uint64_t :3; // Reserved bits
212 uint64_t asi:8; // Address Space Identifier
213 uint64_t ccr:8; // Condition Code Register
214 uint64_t gl:8; // Global level
215 } tstateFields[MaxTL];
217 uint16_t tt[MaxTL]; // Trap Type (Type of trap which occured
218 // on the previous level)
219 uint64_t tba; // Trap Base Address
222 uint16_t pstate; // Process State Register
224 uint16_t :1; // reserved
225 uint16_t ie:1; // Interrupt enable
226 uint16_t priv:1; // Privelege mode
227 uint16_t am:1; // Address mask
228 uint16_t pef:1; // PSTATE enable floating-point
229 uint16_t :1; // reserved2
230 uint16_t mm:2; // Memory Model
231 uint16_t tle:1; // Trap little-endian
232 uint16_t cle:1; // Current little-endian
235 uint8_t tl; // Trap Level
236 uint8_t pil; // Process Interrupt Register
237 uint8_t cwp; // Current Window Pointer
238 uint8_t cansave; // Savable windows
239 uint8_t canrestore; // Restorable windows
240 uint8_t cleanwin; // Clean windows
241 uint8_t otherwin; // Other windows
243 uint8_t wstate; // Window State
245 uint8_t normal:3; // Bits TT<4:2> are set to on a normal
246 // register window trap
247 uint8_t other:3; // Bits TT<4:2> are set to on an "otherwin"
248 // register window trap
251 uint8_t gl; // Global level register
254 /** Hyperprivileged Registers */
256 uint64_t hpstate; // Hyperprivileged State Register
269 uint64_t htstate[MaxTL]; // Hyperprivileged Trap State Register
271 uint64_t htba; // Hyperprivileged Trap Base Address register
273 uint64_t hstick_cmpr; // Hardware tick compare registers
275 uint64_t tick_cmpr:63; // Clock-tick count
276 uint64_t int_dis:1; // Non-priveleged trap
280 uint64_t strandStatusReg; // Per strand status register
283 /** Floating point misc registers. */
285 uint64_t fsr; // Floating-Point State Register
288 uint64_t cexc:5; // Current excpetion
290 uint64_t nxc:1; // Inexact
291 uint64_t dzc:1; // Divide by zero
292 uint64_t ufc:1; // Underflow
293 uint64_t ofc:1; // Overflow
294 uint64_t nvc:1; // Invalid operand
298 uint64_t aexc:5; // Accrued exception
300 uint64_t nxc:1; // Inexact
301 uint64_t dzc:1; // Divide by zero
302 uint64_t ufc:1; // Underflow
303 uint64_t ofc:1; // Overflow
304 uint64_t nvc:1; // Invalid operand
307 uint64_t fcc0:2; // Floating-Point condtion codes
308 uint64_t :1; // Reserved bits
309 uint64_t qne:1; // Deferred trap queue not empty
310 // with no queue, it should read 0
311 uint64_t ftt:3; // Floating-Point trap type
312 uint64_t ver:3; // Version (of the FPU)
313 uint64_t :2; // Reserved bits
314 uint64_t ns:1; // Nonstandard floating point
316 uint64_t tem:5; // Trap Enable Mask
318 uint64_t nxm:1; // Inexact
319 uint64_t dzm:1; // Divide by zero
320 uint64_t ufm:1; // Underflow
321 uint64_t ofm:1; // Overflow
322 uint64_t nvm:1; // Invalid operand
325 uint64_t :2; // Reserved bits
326 uint64_t rd:2; // Rounding direction
327 uint64_t fcc1:2; // Floating-Point condition codes
328 uint64_t fcc2:2; // Floating-Point condition codes
329 uint64_t fcc3:2; // Floating-Point condition codes
330 uint64_t :26; // Reserved bits
337 // These need to check the int_dis field and if 0 then
338 // set appropriate bit in softint and checkinterrutps on the cpu
340 /** Process a tick compare event and generate an interrupt on the cpu if
342 void processTickCompare(ThreadContext *tc);
343 void processSTickCompare(ThreadContext *tc);
344 void processHSTickCompare(ThreadContext *tc);
346 typedef CpuEventWrapper<MiscRegFile,
347 &MiscRegFile::processTickCompare> TickCompareEvent;
348 TickCompareEvent *tickCompare;
350 typedef CpuEventWrapper<MiscRegFile,
351 &MiscRegFile::processSTickCompare> STickCompareEvent;
352 STickCompareEvent *sTickCompare;
354 typedef CpuEventWrapper<MiscRegFile,
355 &MiscRegFile::processHSTickCompare> HSTickCompareEvent;
356 HSTickCompareEvent *hSTickCompare;
367 MiscReg readReg(int miscReg);
369 MiscReg readRegWithEffect(int miscReg, ThreadContext *tc);
371 void setReg(int miscReg, const MiscReg &val);
373 void setRegWithEffect(int miscReg,
374 const MiscReg &val, ThreadContext * tc);
378 return implicitInstAsi;
383 return implicitDataAsi;
386 void serialize(std::ostream & os);
388 void unserialize(Checkpoint * cp, const std::string & section);
390 void copyMiscRegs(ThreadContext * tc);
394 bool isHyperPriv() { return hpstateFields.hpriv; }
395 bool isPriv() { return hpstateFields.hpriv || pstateFields.priv; }
396 bool isNonPriv() { return !isPriv(); }
397 inline void setImplicitAsis();