add translations for new sections that are mmapped or when the brk
[gem5.git] / arch / mips / isa_traits.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
29 #ifndef __ARCH_MIPS_ISA_TRAITS_HH__
30 #define __ARCH_MIPS_ISA_TRAITS_HH__
31
32 //#include "arch/mips/misc_regfile.hh"
33 #include "base/misc.hh"
34 #include "config/full_system.hh"
35 #include "sim/host.hh"
36 #include "sim/faults.hh"
37
38 #include <vector>
39
40 class FastCPU;
41 class FullCPU;
42 class Checkpoint;
43
44 namespace LittleEndianGuest {};
45 using namespace LittleEndianGuest;
46
47 #define TARGET_MIPS
48
49 class StaticInst;
50 class StaticInstPtr;
51
52 namespace MIPS34K {
53 int DTB_ASN_ASN(uint64_t reg);
54 int ITB_ASN_ASN(uint64_t reg);
55 };
56
57 #if !FULL_SYSTEM
58 class SyscallReturn {
59 public:
60 template <class T>
61 SyscallReturn(T v, bool s)
62 {
63 retval = (uint64_t)v;
64 success = s;
65 }
66
67 template <class T>
68 SyscallReturn(T v)
69 {
70 success = (v >= 0);
71 retval = (uint64_t)v;
72 }
73
74 ~SyscallReturn() {}
75
76 SyscallReturn& operator=(const SyscallReturn& s) {
77 retval = s.retval;
78 success = s.success;
79 return *this;
80 }
81
82 bool successful() { return success; }
83 uint64_t value() { return retval; }
84
85
86 private:
87 uint64_t retval;
88 bool success;
89 };
90 #endif
91
92 namespace MipsISA
93 {
94 typedef uint32_t MachInst;
95 typedef uint32_t MachInst;
96 typedef uint64_t ExtMachInst;
97 typedef uint8_t RegIndex;
98 // typedef uint64_t Addr;
99
100 // Constants Related to the number of registers
101
102 const int NumIntArchRegs = 32;
103 const int NumPALShadowRegs = 8;
104 const int NumFloatArchRegs = 32;
105 // @todo: Figure out what this number really should be.
106 const int NumMiscArchRegs = 32;
107
108 const int NumIntRegs = NumIntArchRegs + NumPALShadowRegs;
109 const int NumFloatRegs = NumFloatArchRegs;
110 const int NumMiscRegs = NumMiscArchRegs;
111
112 const int TotalNumRegs = NumIntRegs + NumFloatRegs +
113 NumMiscRegs + 0/*NumInternalProcRegs*/;
114
115 const int TotalDataRegs = NumIntRegs + NumFloatRegs;
116
117 // Static instruction parameters
118 const int MaxInstSrcRegs = 3;
119 const int MaxInstDestRegs = 2;
120
121 // semantically meaningful register indices
122 const int ZeroReg = 31; // architecturally meaningful
123 // the rest of these depend on the ABI
124 const int StackPointerReg = 30;
125 const int GlobalPointerReg = 29;
126 const int ProcedureValueReg = 27;
127 const int ReturnAddressReg = 26;
128 const int ReturnValueReg = 0;
129 const int FramePointerReg = 15;
130 const int ArgumentReg0 = 16;
131 const int ArgumentReg1 = 17;
132 const int ArgumentReg2 = 18;
133 const int ArgumentReg3 = 19;
134 const int ArgumentReg4 = 20;
135 const int ArgumentReg5 = 21;
136 const int SyscallNumReg = ReturnValueReg;
137 const int SyscallPseudoReturnReg = ArgumentReg4;
138 const int SyscallSuccessReg = 19;
139
140 const int LogVMPageSize = 13; // 8K bytes
141 const int VMPageSize = (1 << LogVMPageSize);
142
143 const int BranchPredAddrShiftAmt = 2; // instructions are 4-byte aligned
144
145 const int MachineBytes = 4;
146 const int WordBytes = 4;
147 const int HalfwordBytes = 2;
148 const int ByteBytes = 1;
149
150
151 // These enumerate all the registers for dependence tracking.
152 enum DependenceTags {
153 // 0..31 are the integer regs 0..31
154 // 32..63 are the FP regs 0..31, i.e. use (reg + FP_Base_DepTag)
155 FP_Base_DepTag = 32,
156 Ctrl_Base_DepTag = 64,
157 Fpcr_DepTag = 64, // floating point control register
158 Uniq_DepTag = 65,
159 IPR_Base_DepTag = 66,
160 MiscReg_DepTag = 67
161 };
162
163 typedef uint64_t IntReg;
164 typedef IntReg IntRegFile[NumIntRegs];
165
166 // floating point register file entry type
167 typedef union {
168 uint64_t q;
169 double d;
170 } FloatReg;
171
172 typedef union {
173 uint64_t q[NumFloatRegs]; // integer qword view
174 double d[NumFloatRegs]; // double-precision floating point view
175 } FloatRegFile;
176
177 // cop-0/cop-1 system control register file
178 typedef uint64_t MiscReg;
179 //typedef MiscReg MiscRegFile[NumMiscRegs];
180 class MiscRegFile {
181
182 protected:
183 uint64_t fpcr; // floating point condition codes
184 uint64_t uniq; // process-unique register
185 bool lock_flag; // lock flag for LL/SC
186 Addr lock_addr; // lock address for LL/SC
187
188 MiscReg miscRegFile[NumMiscRegs];
189
190 public:
191 //These functions should be removed once the simplescalar cpu model
192 //has been replaced.
193 int getInstAsid();
194 int getDataAsid();
195
196 void copyMiscRegs(ExecContext *xc);
197
198 MiscReg readReg(int misc_reg)
199 { return miscRegFile[misc_reg]; }
200
201 MiscReg readRegWithEffect(int misc_reg, Fault &fault, ExecContext *xc)
202 { return miscRegFile[misc_reg];}
203
204 Fault setReg(int misc_reg, const MiscReg &val)
205 { miscRegFile[misc_reg] = val; return NoFault; }
206
207 Fault setRegWithEffect(int misc_reg, const MiscReg &val,
208 ExecContext *xc)
209 { miscRegFile[misc_reg] = val; return NoFault; }
210
211 #if FULL_SYSTEM
212 void clearIprs() { }
213
214 protected:
215 InternalProcReg ipr[NumInternalProcRegs]; // Internal processor regs
216
217 private:
218 MiscReg readIpr(int idx, Fault &fault, ExecContext *xc) { }
219
220 Fault setIpr(int idx, uint64_t val, ExecContext *xc) { }
221 #endif
222 friend class RegFile;
223 };
224
225 enum MiscRegTags {
226 //Coprocessor 0 Registers
227 //Reference MIPS32 Arch. for Programmers, Vol. III, Ch.8
228 //(Register Number-Register Select) Summary of Register
229 //------------------------------------------------------
230 Index = 0, //0-0 Index into the TLB array
231
232 MVPControl = 1, //0-1 Per-processor register containing global
233 //MIPS® MT configuration data
234
235 MVPConf0 = 2, //0-2 Per-processor register containing global
236 //MIPS® MT configuration data
237
238 MVPConf1 = 3, //0-3 Per-processor register containing global
239 //MIPS® MT configuration data
240
241 Random = 8, //1-0 Randomly generated index into the TLB array
242
243 VPEControl = 9, //1-1 Per-VPE register containing relatively volatile
244 //thread configuration data
245
246 VPEConf0 = 10, //1-2 Per-VPE multi-thread configuration
247 //information
248
249
250 VPEConf1 = 11, //1-2 Per-VPE multi-thread configuration
251 //information
252
253 YQMask = 12, //Per-VPE register defining which YIELD
254 //qualifier bits may be used without generating
255 //an exception
256
257 VPESchedule = 13,
258 VPEScheFBack = 14,
259 VPEOpt = 15,
260 EntryLo0 = 16, // Bank 3: 16 - 23
261 TCStatus = 17,
262 TCBind = 18,
263 TCRestart = 19,
264 TCHalt = 20,
265 TCContext = 21,
266 TCSchedule = 22,
267 TCScheFBack = 23,
268
269 EntryLo1 = 24,// Bank 4: 24 - 31
270
271 Context = 32, // Bank 5: 32 - 39
272 ContextConfig = 33,
273
274 //PageMask = 40, //Bank 6: 40 - 47
275 PageGrain = 41,
276
277 Wired = 48, //Bank 7:48 - 55
278 SRSConf0 = 49,
279 SRSConf1 = 50,
280 SRSConf2 = 51,
281 SRSConf3 = 52,
282 SRSConf4 = 53,
283 BadVAddr = 54,
284
285 HWRena = 56,//Bank 8:56 - 63
286
287 Count = 64, //Bank 9:64 - 71
288
289 EntryHi = 72,//Bank 10:72 - 79
290
291 Compare = 80,//Bank 11:80 - 87
292
293 Status = 88,//Bank 12:88 - 96 //12-0 Processor status and control
294 IntCtl = 89, //12-1 Interrupt system status and control
295 SRSCtl = 90, //12-2 Shadow register set status and control
296 SRSMap = 91, //12-3 Shadow set IPL mapping
297
298 Cause = 97,//97-104 //13-0 Cause of last general exception
299
300 EPC = 105,//105-112 //14-0 Program counter at last exception
301
302 PRId = 113,//113-120, //15-0 Processor identification and revision
303 EBase = 114, //15-1 Exception vector base register
304
305 Config = 121,//Bank 16: 121-128
306 Config1 = 122,
307 Config2 = 123,
308 Config3 = 124,
309 Config6 = 127,
310 Config7 = 128,
311
312
313 LLAddr = 129,//Bank 17: 129-136
314
315 WatchLo0 = 137,//Bank 18: 137-144
316 WatchLo1 = 138,
317 WatchLo2 = 139,
318 WatchLo3 = 140,
319 WatchLo4 = 141,
320 WatchLo5 = 142,
321 WatchLo6 = 143,
322 WatchLo7 = 144,
323
324 WatchHi0 = 145,//Bank 19: 145-152
325 WatchHi1 = 146,
326 WatchHi2 = 147,
327 WatchHi3 = 148,
328 WatchHi4 = 149,
329 WatchHi5 = 150,
330 WatchHi6 = 151,
331 WatchHi7 = 152,
332
333 XCContext64 = 153,//Bank 20: 153-160
334
335 //Bank 21: 161-168
336
337 //Bank 22: 169-176
338
339 Debug = 177, //Bank 23: 177-184
340 TraceControl1 = 178,
341 TraceControl2 = 179,
342 UserTraceData = 180,
343 TraceBPC = 181,
344
345 DEPC = 185,//Bank 24: 185-192
346
347 PerfCnt0 = 193,//Bank 25: 193 - 200
348 PerfCnt1 = 194,
349 PerfCnt2 = 195,
350 PerfCnt3 = 196,
351 PerfCnt4 = 197,
352 PerfCnt5 = 198,
353 PerfCnt6 = 199,
354 PerfCnt7 = 200,
355
356 ErrCtl = 201, //Bank 26: 201 - 208
357
358 CacheErr0 = 209, //Bank 27: 209 - 216
359 CacheErr1 = 210,
360 CacheErr2 = 211,
361 CacheErr3 = 212,
362
363 TagLo0 = 217,//Bank 28: 217 - 224
364 DataLo1 = 218,
365 TagLo2 = 219,
366 DataLo3 = 220,
367 TagLo4 = 221,
368 DataLo5 = 222,
369 TagLo6 = 223,
370 DataLo7 = 234,
371
372 TagHi0 = 233,//Bank 29: 233 - 240
373 DataHi1 = 234,
374 TagHi2 = 235,
375 DataHi3 = 236,
376 TagHi4 = 237,
377 DataHi5 = 238,
378 TagHi6 = 239,
379 DataHi7 = 240,
380
381
382 ErrorEPC = 249,//Bank 30: 241 - 248
383
384 DESAVE = 257,//Bank 31: 249-256
385
386 //More Misc. Regs
387 Hi,
388 Lo,
389 FCSR,
390 FPCR,
391
392 //Alpha Regs, but here now, for
393 //compiling sake
394 UNIQ,
395 LockAddr,
396 LockFlag
397 };
398
399 extern const Addr PageShift;
400 extern const Addr PageBytes;
401 extern const Addr PageMask;
402 extern const Addr PageOffset;
403
404 #if FULL_SYSTEM
405
406 typedef uint64_t InternalProcReg;
407
408 #include "arch/mips/isa_fullsys_traits.hh"
409
410 #else
411 enum {
412 NumInternalProcRegs = 0
413 };
414 #endif
415
416 typedef union {
417 IntReg intreg;
418 FloatReg fpreg;
419 MiscReg ctrlreg;
420 } AnyReg;
421
422 struct RegFile {
423 IntRegFile intRegFile; // (signed) integer register file
424 FloatRegFile floatRegFile; // floating point register file
425 MiscRegFile miscRegs; // control register file
426
427
428 Addr pc; // program counter
429 Addr npc; // next-cycle program counter
430 Addr nnpc; // next-next-cycle program counter
431 // used to implement branch delay slot
432 // not real register
433
434 MiscReg hi; // MIPS HI Register
435 MiscReg lo; // MIPS LO Register
436
437
438 #if FULL_SYSTEM
439 IntReg palregs[NumIntRegs]; // PAL shadow registers
440 InternalProcReg ipr[NumInternalProcRegs]; // internal processor regs
441 int intrflag; // interrupt flag
442 bool pal_shadow; // using pal_shadow registers
443 inline int instAsid() { return MIPS34K::ITB_ASN_ASN(ipr[IPR_ITB_ASN]); }
444 inline int dataAsid() { return MIPS34K::DTB_ASN_ASN(ipr[IPR_DTB_ASN]); }
445 #endif // FULL_SYSTEM
446
447 //void initCP0Regs();
448 void serialize(std::ostream &os);
449 void unserialize(Checkpoint *cp, const std::string &section);
450
451 void createCP0Regs();
452 void coldReset();
453 };
454
455 StaticInstPtr decodeInst(ExtMachInst);
456
457 // return a no-op instruction... used for instruction fetch faults
458 extern const MachInst NoopMachInst;
459
460 enum annotes {
461 ANNOTE_NONE = 0,
462 // An impossible number for instruction annotations
463 ITOUCH_ANNOTE = 0xffffffff,
464 };
465
466 //void getMiscRegIdx(int reg_name,int &idx, int &sel);
467
468 static inline ExtMachInst
469 makeExtMI(MachInst inst, const uint64_t &pc) {
470 #if FULL_SYSTEM
471 ExtMachInst ext_inst = inst;
472 if (pc && 0x1)
473 return ext_inst|=(static_cast<ExtMachInst>(pc & 0x1) << 32);
474 else
475 return ext_inst;
476 #else
477 return ExtMachInst(inst);
478 #endif
479 }
480
481 static inline bool isCallerSaveIntegerRegister(unsigned int reg) {
482 panic("register classification not implemented");
483 return (reg >= 1 && reg <= 8 || reg >= 22 && reg <= 25 || reg == 27);
484 }
485
486 static inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
487 panic("register classification not implemented");
488 return (reg >= 9 && reg <= 15);
489 }
490
491 static inline bool isCallerSaveFloatRegister(unsigned int reg) {
492 panic("register classification not implemented");
493 return false;
494 }
495
496 static inline bool isCalleeSaveFloatRegister(unsigned int reg) {
497 panic("register classification not implemented");
498 return false;
499 }
500
501 static inline Addr alignAddress(const Addr &addr,
502 unsigned int nbytes) {
503 return (addr & ~(nbytes - 1));
504 }
505
506 // Instruction address compression hooks
507 static inline Addr realPCToFetchPC(const Addr &addr) {
508 return addr;
509 }
510
511 static inline Addr fetchPCToRealPC(const Addr &addr) {
512 return addr;
513 }
514
515 // the size of "fetched" instructions (not necessarily the size
516 // of real instructions for PISA)
517 static inline size_t fetchInstSize() {
518 return sizeof(MachInst);
519 }
520
521 static inline MachInst makeRegisterCopy(int dest, int src) {
522 panic("makeRegisterCopy not implemented");
523 return 0;
524 }
525
526 static inline void setSyscallReturn(SyscallReturn return_value, RegFile *regs)
527 {
528 // check for error condition. SPARC syscall convention is to
529 // indicate success/failure in reg the carry bit of the ccr
530 // and put the return value itself in the standard return value reg ().
531 if (return_value.successful()) {
532 // no error
533 //regs->miscRegFile.ccrFields.iccFields.c = 0;
534 regs->intRegFile[ReturnValueReg] = return_value.value();
535 } else {
536 // got an error, return details
537 //regs->miscRegFile.ccrFields.iccFields.c = 1;
538 regs->intRegFile[ReturnValueReg] = -return_value.value();
539 }
540 }
541
542 // Machine operations
543
544 void saveMachineReg(AnyReg &savereg, const RegFile &reg_file,
545 int regnum);
546
547 void restoreMachineReg(RegFile &regs, const AnyReg &reg,
548 int regnum);
549
550 #if 0
551 static void serializeSpecialRegs(const Serializable::Proxy &proxy,
552 const RegFile &regs);
553
554 static void unserializeSpecialRegs(const IniFile *db,
555 const std::string &category,
556 ConfigNode *node,
557 RegFile &regs);
558 #endif
559
560 /**
561 * Function to insure ISA semantics about 0 registers.
562 * @param xc The execution context.
563 */
564 template <class XC>
565 void zeroRegisters(XC *xc);
566
567 const Addr MaxAddr = (Addr)-1;
568 };
569
570 #if FULL_SYSTEM
571 //typedef TheISA::InternalProcReg InternalProcReg;
572 //const int NumInternalProcRegs = TheISA::NumInternalProcRegs;
573 //const int NumInterruptLevels = TheISA::NumInterruptLevels;
574
575 #include "arch/mips/mips34k.hh"
576 #endif
577
578 using namespace MipsISA;
579
580 #endif // __ARCH_MIPS_ISA_TRAITS_HH__