FastCPU model added. It's very similar to the SimpleCPU, just without a lot of the...
[gem5.git] / arch / alpha / isa_desc
1 // -*- mode:c++ -*-
2 //
3 // Alpha ISA description file.
4 //
5
6 let {{
7 global rcs_id
8 rcs_id = "$Id$"
9 }};
10
11
12 #include <sstream>
13 #include <iostream>
14 #include <iomanip>
15
16 #include <math.h>
17 #if defined(linux)
18 #include <fenv.h>
19 #endif
20
21 #include "base/cprintf.hh"
22 #include "base/misc.hh"
23 #include "cpu/exec_context.hh"
24 #include "cpu/exetrace.hh"
25 #include "cpu/fast_cpu/fast_cpu.hh"
26 #include "cpu/full_cpu/dyn_inst.hh"
27 #include "cpu/simple_cpu/simple_cpu.hh"
28 #include "cpu/static_inst.hh"
29 #include "sim/annotation.hh"
30 #include "sim/sim_exit.hh"
31
32 #ifdef FULL_SYSTEM
33 #include "arch/alpha/ev5.hh"
34 #include "arch/alpha/pseudo_inst.hh"
35 #endif
36
37 namespace AlphaISA;
38
39 // Universal (format-independent) fields
40 def bitfield OPCODE <31:26>;
41 def bitfield RA <25:21>;
42 def bitfield RB <20:16>;
43
44 // Memory format
45 def signed bitfield MEMDISP <15: 0>; // displacement
46 def bitfield MEMFUNC <15: 0>; // function code (same field, unsigned)
47
48 // Memory-format jumps
49 def bitfield JMPFUNC <15:14>; // function code (disp<15:14>)
50 def bitfield JMPHINT <13: 0>; // tgt Icache idx hint (disp<13:0>)
51
52 // Branch format
53 def signed bitfield BRDISP <20: 0>; // displacement
54
55 // Integer operate format(s>;
56 def bitfield INTIMM <20:13>; // integer immediate (literal)
57 def bitfield IMM <12:12>; // immediate flag
58 def bitfield INTFUNC <11: 5>; // function code
59 def bitfield RC < 4: 0>; // dest reg
60
61 // Floating-point operate format
62 def bitfield FA <25:21>;
63 def bitfield FB <20:16>;
64 def bitfield FP_FULLFUNC <15: 5>; // complete function code
65 def bitfield FP_TRAPMODE <15:13>; // trapping mode
66 def bitfield FP_ROUNDMODE <12:11>; // rounding mode
67 def bitfield FP_TYPEFUNC <10: 5>; // type+func: handiest for decoding
68 def bitfield FP_SRCTYPE <10: 9>; // source reg type
69 def bitfield FP_SHORTFUNC < 8: 5>; // short function code
70 def bitfield FP_SHORTFUNC_TOP2 <8:7>; // top 2 bits of short func code
71 def bitfield FC < 4: 0>; // dest reg
72
73 // PALcode format
74 def bitfield PALFUNC <25: 0>; // function code
75
76 // EV5 PAL instructions:
77 // HW_LD/HW_ST
78 def bitfield HW_LDST_PHYS <15>; // address is physical
79 def bitfield HW_LDST_ALT <14>; // use ALT_MODE IPR
80 def bitfield HW_LDST_WRTCK <13>; // HW_LD only: fault if no write acc
81 def bitfield HW_LDST_QUAD <12>; // size: 0=32b, 1=64b
82 def bitfield HW_LDST_VPTE <11>; // HW_LD only: is PTE fetch
83 def bitfield HW_LDST_LOCK <10>; // HW_LD only: is load locked
84 def bitfield HW_LDST_COND <10>; // HW_ST only: is store conditional
85 def signed bitfield HW_LDST_DISP <9:0>; // signed displacement
86
87 // HW_REI
88 def bitfield HW_REI_TYP <15:14>; // type: stalling vs. non-stallingk
89 def bitfield HW_REI_MBZ <13: 0>; // must be zero
90
91 // HW_MTPR/MW_MFPR
92 def bitfield HW_IPR_IDX <15:0>; // IPR index
93
94 // M5 instructions
95 def bitfield M5FUNC <7:0>;
96
97 let {{
98 global operandTypeMap
99 operandTypeMap = {
100 'sb' : ('signed int', 8),
101 'ub' : ('unsigned int', 8),
102 'sw' : ('signed int', 16),
103 'uw' : ('unsigned int', 16),
104 'sl' : ('signed int', 32),
105 'ul' : ('unsigned int', 32),
106 'sq' : ('signed int', 64),
107 'uq' : ('unsigned int', 64),
108 'sf' : ('float', 32),
109 'df' : ('float', 64)
110 }
111
112 global operandTraitsMap
113 operandTraitsMap = {
114 # Int regs default to unsigned, but code should not count on this.
115 # For clarity, descriptions that depend on unsigned behavior should
116 # explicitly specify '.uq'.
117 'Ra': IntRegOperandTraits('uq', 'RA', 'IsInteger', 1),
118 'Rb': IntRegOperandTraits('uq', 'RB', 'IsInteger', 2),
119 'Rc': IntRegOperandTraits('uq', 'RC', 'IsInteger', 3),
120 'Fa': FloatRegOperandTraits('df', 'FA', 'IsFloating', 1),
121 'Fb': FloatRegOperandTraits('df', 'FB', 'IsFloating', 2),
122 'Fc': FloatRegOperandTraits('df', 'FC', 'IsFloating', 3),
123 'Mem': MemOperandTraits('uq', None,
124 ('IsMemRef', 'IsLoad', 'IsStore'), 4),
125 'NPC': NPCOperandTraits('uq', None, ( None, None, 'IsControl' ), 4),
126 'Runiq': ControlRegOperandTraits('uq', 'Uniq', None, 1),
127 'FPCR': ControlRegOperandTraits('uq', 'Fpcr', None, 1),
128 # The next two are hacks for non-full-system call-pal emulation
129 'R0': IntRegOperandTraits('uq', '0', None, 1),
130 'R16': IntRegOperandTraits('uq', '16', None, 1),
131 }
132
133 defineDerivedOperandVars()
134 }};
135
136 declare {{
137 // just temporary, while comparing with old code for debugging
138 // #define SS_COMPATIBLE_DISASSEMBLY
139
140 /// Check "FP enabled" machine status bit. Called when executing any FP
141 /// instruction in full-system mode.
142 /// @retval Full-system mode: No_Fault if FP is enabled, Fen_Fault
143 /// if not. Non-full-system mode: always returns No_Fault.
144 #ifdef FULL_SYSTEM
145 template <class XC>
146 inline Fault checkFpEnableFault(XC *xc)
147 {
148 Fault fault = No_Fault; // dummy... this ipr access should not fault
149 if (!ICSR_FPE(xc->readIpr(AlphaISA::IPR_ICSR, fault))) {
150 fault = Fen_Fault;
151 }
152 return fault;
153 }
154 #else
155 template <class XC>
156 inline Fault checkFpEnableFault(XC *xc)
157 {
158 return No_Fault;
159 }
160 #endif
161
162 /**
163 * Base class for all Alpha static instructions.
164 */
165 class AlphaStaticInst : public StaticInst<AlphaISA>
166 {
167 protected:
168
169 /// Make AlphaISA register dependence tags directly visible in
170 /// this class and derived classes. Maybe these should really
171 /// live here and not in the AlphaISA namespace.
172 enum DependenceTags {
173 FP_Base_DepTag = AlphaISA::FP_Base_DepTag,
174 Fpcr_DepTag = AlphaISA::Fpcr_DepTag,
175 Uniq_DepTag = AlphaISA::Uniq_DepTag,
176 IPR_Base_DepTag = AlphaISA::IPR_Base_DepTag
177 };
178
179 /// Constructor.
180 AlphaStaticInst(const char *mnem, MachInst _machInst,
181 OpClass __opClass)
182 : StaticInst<AlphaISA>(mnem, _machInst, __opClass)
183 {
184 }
185
186 /// Print a register name for disassembly given the unique
187 /// dependence tag number (FP or int).
188 void printReg(std::ostream &os, int reg)
189 {
190 if (reg < FP_Base_DepTag) {
191 ccprintf(os, "r%d", reg);
192 }
193 else {
194 ccprintf(os, "f%d", reg - FP_Base_DepTag);
195 }
196 }
197
198 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
199 {
200 std::stringstream ss;
201
202 ccprintf(ss, "%-10s ", mnemonic);
203
204 // just print the first two source regs... if there's
205 // a third one, it's a read-modify-write dest (Rc),
206 // e.g. for CMOVxx
207 if (_numSrcRegs > 0) {
208 printReg(ss, _srcRegIdx[0]);
209 }
210 if (_numSrcRegs > 1) {
211 ss << ",";
212 printReg(ss, _srcRegIdx[1]);
213 }
214
215 // just print the first dest... if there's a second one,
216 // it's generally implicit
217 if (_numDestRegs > 0) {
218 if (_numSrcRegs > 0)
219 ss << ",";
220 printReg(ss, _destRegIdx[0]);
221 }
222
223 return ss.str();
224 }
225 };
226 }};
227
228
229 def template BasicDeclare {{
230 /**
231 * Static instruction class for "%(mnemonic)s".
232 */
233 class %(class_name)s : public %(base_class)s
234 {
235 public:
236 /// Constructor.
237 %(class_name)s(MachInst machInst)
238 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
239 {
240 %(constructor)s;
241 }
242
243 %(exec_func_declarations)s
244 };
245 }};
246
247 def template BasicExecute {{
248 Fault %(class_name)s::execute(%(cpu_model)s *xc,
249 Trace::InstRecord *traceData)
250 {
251 Fault fault = No_Fault;
252
253 %(fp_enable_check)s;
254 %(op_decl)s;
255 %(op_rd)s;
256 %(code)s;
257
258 if (fault == No_Fault) {
259 %(op_wb)s;
260 }
261
262 return fault;
263 }
264 }};
265
266 def template BasicDecode {{
267 return new %(class_name)s(machInst);
268 }};
269
270 def template BasicDecodeWithMnemonic {{
271 return new %(class_name)s("%(mnemonic)s", machInst);
272 }};
273
274 // The most basic instruction format... used only for a few misc. insts
275 def format BasicOperate(code, *flags) {{
276 iop = InstObjParams(name, Name, 'AlphaStaticInst', CodeBlock(code), flags)
277 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
278 }};
279
280
281
282 ////////////////////////////////////////////////////////////////////
283
284 declare {{
285 /**
286 * Static instruction class for no-ops. This is a leaf class.
287 */
288 class Nop : public AlphaStaticInst
289 {
290 /// Disassembly of original instruction.
291 const std::string originalDisassembly;
292
293 public:
294 /// Constructor
295 Nop(const std::string _originalDisassembly, MachInst _machInst)
296 : AlphaStaticInst("nop", _machInst, No_OpClass),
297 originalDisassembly(_originalDisassembly)
298 {
299 flags[IsNop] = true;
300 }
301
302 ~Nop() { }
303
304 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
305 {
306 #ifdef SS_COMPATIBLE_DISASSEMBLY
307 return originalDisassembly;
308 #else
309 return csprintf("%-10s (%s)", "nop", originalDisassembly);
310 #endif
311 }
312
313 Fault execute(SimpleCPUExecContext *, Trace::InstRecord *)
314 { return No_Fault; }
315
316 Fault execute(FastCPUExecContext *, Trace::InstRecord *)
317 { return No_Fault; }
318
319 Fault execute(FullCPUExecContext *, Trace::InstRecord *)
320 { return No_Fault; }
321 };
322
323 /// Helper function for decoding nops. Substitute Nop object
324 /// for original inst passed in as arg (and delete latter).
325 inline
326 AlphaStaticInst *
327 makeNop(AlphaStaticInst *inst)
328 {
329 AlphaStaticInst *nop = new Nop(inst->disassemble(0), inst->machInst);
330 delete inst;
331 return nop;
332 }
333 }};
334
335 def format Nop() {{
336 return ('', 'return new Nop("%s", machInst);\n' % name, 'return No_Fault;')
337 }};
338
339
340 // integer & FP operate instructions use Rc as dest, so check for
341 // Rc == 31 to detect nops
342 def template OperateNopCheckDecode {{
343 {
344 AlphaStaticInst *i = new %(class_name)s(machInst);
345 if (RC == 31) {
346 i = makeNop(i);
347 }
348 return i;
349 }
350 }};
351
352 // Like BasicOperate format, but generates NOP if RC/FC == 31
353 def format BasicOperateWithNopCheck(code, *opt_args) {{
354 iop = InstObjParams(name, Name, 'AlphaStaticInst', CodeBlock(code),
355 opt_args)
356 return iop.subst('BasicDeclare', 'OperateNopCheckDecode', 'BasicExecute')
357 }};
358
359
360 ////////////////////////////////////////////////////////////////////
361 //
362 // Integer operate instructions
363 //
364
365 declare {{
366 /**
367 * Base class for integer immediate instructions.
368 */
369 class IntegerImm : public AlphaStaticInst
370 {
371 protected:
372 /// Immediate operand value (unsigned 8-bit int).
373 uint8_t imm;
374
375 /// Constructor
376 IntegerImm(const char *mnem, MachInst _machInst, OpClass __opClass)
377 : AlphaStaticInst(mnem, _machInst, __opClass), imm(INTIMM)
378 {
379 }
380
381 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
382 {
383 std::stringstream ss;
384
385 ccprintf(ss, "%-10s ", mnemonic);
386
387 // just print the first source reg... if there's
388 // a second one, it's a read-modify-write dest (Rc),
389 // e.g. for CMOVxx
390 if (_numSrcRegs > 0) {
391 printReg(ss, _srcRegIdx[0]);
392 ss << ",";
393 }
394
395 ss << (int)imm;
396
397 if (_numDestRegs > 0) {
398 ss << ",";
399 printReg(ss, _destRegIdx[0]);
400 }
401
402 return ss.str();
403 }
404 };
405 }};
406
407 def template RegOrImmDecode {{
408 {
409 AlphaStaticInst *i =
410 (IMM) ? (AlphaStaticInst *)new %(class_name)sImm(machInst)
411 : (AlphaStaticInst *)new %(class_name)s(machInst);
412 if (RC == 31) {
413 i = makeNop(i);
414 }
415 return i;
416 }
417 }};
418
419 // Primary format for integer operate instructions:
420 // - Generates both reg-reg and reg-imm versions if Rb_or_imm is used.
421 // - Generates NOP if RC == 31.
422 def format IntegerOperate(code, *opt_flags) {{
423 # If the code block contains 'Rb_or_imm', we define two instructions,
424 # one using 'Rb' and one using 'imm', and have the decoder select
425 # the right one.
426 uses_imm = (code.find('Rb_or_imm') != -1)
427 if uses_imm:
428 orig_code = code
429 # base code is reg version:
430 # rewrite by substituting 'Rb' for 'Rb_or_imm'
431 code = re.sub(r'Rb_or_imm', 'Rb', orig_code)
432 # generate immediate version by substituting 'imm'
433 # note that imm takes no extenstion, so we extend
434 # the regexp to replace any extension as well
435 imm_code = re.sub(r'Rb_or_imm(\.\w+)?', 'imm', orig_code)
436
437 # generate declaration for register version
438 cblk = CodeBlock(code)
439 iop = InstObjParams(name, Name, 'AlphaStaticInst', cblk, opt_flags)
440 (decls, exec_code) = iop.subst('BasicDeclare', 'BasicExecute')
441
442 if uses_imm:
443 # append declaration for imm version
444 imm_cblk = CodeBlock(imm_code)
445 imm_iop = InstObjParams(name, Name + 'Imm', 'IntegerImm', imm_cblk,
446 opt_flags)
447 (imm_decls, imm_exec_code) = \
448 imm_iop.subst('BasicDeclare', 'BasicExecute')
449 decls += imm_decls
450 exec_code += imm_exec_code
451 # decode checks IMM bit to pick correct version
452 decode = iop.subst('RegOrImmDecode')
453 else:
454 # no imm version: just check for nop
455 decode = iop.subst('OperateNopCheckDecode')
456
457 return (decls, decode, exec_code)
458 }};
459
460
461 ////////////////////////////////////////////////////////////////////
462 //
463 // Floating-point instructions
464 //
465 // Note that many FP-type instructions which do not support all the
466 // various rounding & trapping modes use the simpler format
467 // BasicOperateWithNopCheck.
468 //
469
470 declare {{
471 /**
472 * Base class for general floating-point instructions. Includes
473 * support for various Alpha rounding and trapping modes. Only FP
474 * instructions that require this support are derived from this
475 * class; the rest derive directly from AlphaStaticInst.
476 */
477 class AlphaFP : public AlphaStaticInst
478 {
479 public:
480 /// Alpha FP rounding modes.
481 enum RoundingMode {
482 Chopped = 0, ///< round toward zero
483 Minus_Infinity = 1, ///< round toward minus infinity
484 Normal = 2, ///< round to nearest (default)
485 Dynamic = 3, ///< use FPCR setting (in instruction)
486 Plus_Infinity = 3 ///< round to plus inifinity (in FPCR)
487 };
488
489 /// Alpha FP trapping modes.
490 /// For instructions that produce integer results, the
491 /// "Underflow Enable" modes really mean "Overflow Enable", and
492 /// the assembly modifier is V rather than U.
493 enum TrappingMode {
494 /// default: nothing enabled
495 Imprecise = 0, ///< no modifier
496 /// underflow/overflow traps enabled, inexact disabled
497 Underflow_Imprecise = 1, ///< /U or /V
498 Underflow_Precise = 5, ///< /SU or /SV
499 /// underflow/overflow and inexact traps enabled
500 Underflow_Inexact_Precise = 7 ///< /SUI or /SVI
501 };
502
503 protected:
504 #if defined(linux)
505 static const int alphaToC99RoundingMode[];
506 #endif
507
508 /// Map enum RoundingMode values to disassembly suffixes.
509 static const char *roundingModeSuffix[];
510 /// Map enum TrappingMode values to FP disassembly suffixes.
511 static const char *fpTrappingModeSuffix[];
512 /// Map enum TrappingMode values to integer disassembly suffixes.
513 static const char *intTrappingModeSuffix[];
514
515 /// This instruction's rounding mode.
516 RoundingMode roundingMode;
517 /// This instruction's trapping mode.
518 TrappingMode trappingMode;
519
520 /// Constructor
521 AlphaFP(const char *mnem, MachInst _machInst, OpClass __opClass)
522 : AlphaStaticInst(mnem, _machInst, __opClass),
523 roundingMode((enum RoundingMode)FP_ROUNDMODE),
524 trappingMode((enum TrappingMode)FP_TRAPMODE)
525 {
526 if (trappingMode != Imprecise) {
527 warn("precise FP traps unimplemented\n");
528 }
529 }
530
531 #if defined(linux)
532 int
533 getC99RoundingMode(uint64_t fpcr_val)
534 {
535 if (roundingMode == Dynamic) {
536 return alphaToC99RoundingMode[bits(fpcr_val, 59, 58)];
537 }
538 else {
539 return alphaToC99RoundingMode[roundingMode];
540 }
541 }
542 #endif
543
544 // This differs from the AlphaStaticInst version only in
545 // printing suffixes for non-default rounding & trapping modes.
546 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
547 {
548 std::string mnem_str(mnemonic);
549
550 #ifndef SS_COMPATIBLE_DISASSEMBLY
551 std::string suffix("");
552 suffix += ((_destRegIdx[0] >= FP_Base_DepTag)
553 ? fpTrappingModeSuffix[trappingMode]
554 : intTrappingModeSuffix[trappingMode]);
555 suffix += roundingModeSuffix[roundingMode];
556
557 if (suffix != "") {
558 mnem_str = csprintf("%s/%s", mnemonic, suffix);
559 }
560 #endif
561
562 std::stringstream ss;
563 ccprintf(ss, "%-10s ", mnem_str.c_str());
564
565 // just print the first two source regs... if there's
566 // a third one, it's a read-modify-write dest (Rc),
567 // e.g. for CMOVxx
568 if (_numSrcRegs > 0) {
569 printReg(ss, _srcRegIdx[0]);
570 }
571 if (_numSrcRegs > 1) {
572 ss << ",";
573 printReg(ss, _srcRegIdx[1]);
574 }
575
576 // just print the first dest... if there's a second one,
577 // it's generally implicit
578 if (_numDestRegs > 0) {
579 if (_numSrcRegs > 0)
580 ss << ",";
581 printReg(ss, _destRegIdx[0]);
582 }
583
584 return ss.str();
585 }
586 };
587
588 #if defined(linux)
589 const int AlphaFP::alphaToC99RoundingMode[] = {
590 FE_TOWARDZERO, // Chopped
591 FE_DOWNWARD, // Minus_Infinity
592 FE_TONEAREST, // Normal
593 FE_UPWARD // Dynamic in inst, Plus_Infinity in FPCR
594 };
595 #endif
596
597 const char *AlphaFP::roundingModeSuffix[] = { "c", "m", "", "d" };
598 // mark invalid trapping modes, but don't fail on them, because
599 // you could decode anything on a misspeculated path
600 const char *AlphaFP::fpTrappingModeSuffix[] =
601 { "", "u", "INVTM2", "INVTM3", "INVTM4", "su", "INVTM6", "sui" };
602 const char *AlphaFP::intTrappingModeSuffix[] =
603 { "", "v", "INVTM2", "INVTM3", "INVTM4", "sv", "INVTM6", "svi" };
604 }};
605
606
607 def template FloatingPointDecode {{
608 {
609 bool fast = (FP_TRAPMODE == AlphaFP::Imprecise
610 && FP_ROUNDMODE == AlphaFP::Normal);
611 AlphaStaticInst *i =
612 fast ? (AlphaStaticInst *)new %(class_name)sFast(machInst) :
613 (AlphaStaticInst *)new %(class_name)sGeneral(machInst);
614
615 if (FC == 31) {
616 i = makeNop(i);
617 }
618
619 return i;
620 }
621 }};
622
623 // General format for floating-point operate instructions:
624 // - Checks trapping and rounding mode flags. Trapping modes
625 // currently unimplemented (will fail).
626 // - Generates NOP if FC == 31.
627 def format FloatingPointOperate(code, *opt_args) {{
628 iop = InstObjParams(name, Name, 'AlphaFP', CodeBlock(code), opt_args)
629 decode = iop.subst('FloatingPointDecode')
630
631 fast_iop = InstObjParams(name, Name + 'Fast', 'AlphaFP',
632 CodeBlock(code), opt_args)
633 (fast_declare, fast_exec) = fast_iop.subst('BasicDeclare', 'BasicExecute')
634
635 gen_code_prefix = r'''
636 #if defined(linux)
637 fesetround(getC99RoundingMode(xc->readFpcr()));
638 #endif
639 '''
640 gen_code_suffix = r'''
641 #if defined(linux)
642 fesetround(FE_TONEAREST);
643 #endif
644 '''
645
646 gen_iop = InstObjParams(name, Name + 'General', 'AlphaFP',
647 CodeBlock(gen_code_prefix + code + gen_code_suffix), opt_args)
648 (gen_declare, gen_exec) = gen_iop.subst('BasicDeclare', 'BasicExecute')
649
650 return (fast_declare + gen_declare, decode, fast_exec + gen_exec)
651 }};
652
653
654 ////////////////////////////////////////////////////////////////////
655 //
656 // Memory-format instructions: LoadAddress, Load, Store
657 //
658
659 declare {{
660 /**
661 * Base class for general Alpha memory-format instructions.
662 */
663 class Memory : public AlphaStaticInst
664 {
665 protected:
666
667 /// Displacement for EA calculation (signed).
668 int32_t disp;
669 /// Memory request flags. See mem_req_base.hh.
670 unsigned memAccessFlags;
671
672 /// Constructor
673 Memory(const char *mnem, MachInst _machInst, OpClass __opClass)
674 : AlphaStaticInst(mnem, _machInst, __opClass),
675 disp(MEMDISP), memAccessFlags(0)
676 {
677 }
678
679 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
680 {
681 return csprintf("%-10s %c%d,%d(r%d)", mnemonic,
682 flags[IsFloating] ? 'f' : 'r', RA, MEMDISP, RB);
683 }
684 };
685
686 /**
687 * Base class for a few miscellaneous memory-format insts
688 * that don't interpret the disp field: wh64, fetch, fetch_m, ecb.
689 * None of these instructions has a destination register either.
690 */
691 class MemoryNoDisp : public AlphaStaticInst
692 {
693 protected:
694 /// Memory request flags. See mem_req_base.hh.
695 unsigned memAccessFlags;
696
697 /// Constructor
698 MemoryNoDisp(const char *mnem, MachInst _machInst, OpClass __opClass)
699 : AlphaStaticInst(mnem, _machInst, __opClass),
700 memAccessFlags(0)
701 {
702 }
703
704 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
705 {
706 return csprintf("%-10s (r%d)", mnemonic, RB);
707 }
708 };
709
710 /**
711 * Base class for "fake" effective-address computation
712 * instructions returnded by eaCompInst().
713 */
714 class EACompBase : public AlphaStaticInst
715 {
716 public:
717 /// Constructor
718 EACompBase(MachInst machInst)
719 : AlphaStaticInst("(eacomp)", machInst, IntALU)
720 {
721 }
722
723 Fault execute(SimpleCPUExecContext *, Trace::InstRecord *)
724 { panic("attempt to execute eacomp"); }
725
726 Fault execute(FastCPUExecContext *, Trace::InstRecord *)
727 { panic("attempt to execute eacomp"); }
728
729 Fault execute(FullCPUExecContext *, Trace::InstRecord *)
730 { panic("attempt to execute eacomp"); }
731 };
732
733 /**
734 * Base class for "fake" memory-access instructions returnded by
735 * memAccInst().
736 */
737 class MemAccBase : public AlphaStaticInst
738 {
739 public:
740 /// Constructor
741 MemAccBase(MachInst machInst, OpClass __opClass)
742 : AlphaStaticInst("(memacc)", machInst, __opClass)
743 {
744 }
745
746 Fault execute(SimpleCPUExecContext *, Trace::InstRecord *)
747 { panic("attempt to execute memacc"); }
748
749 Fault execute(FastCPUExecContext *, Trace::InstRecord *)
750 { panic("attempt to execute memacc"); }
751
752 Fault execute(FullCPUExecContext *, Trace::InstRecord *)
753 { panic("attempt to execute memacc"); }
754 };
755
756 }};
757
758
759 def format LoadAddress(code) {{
760 iop = InstObjParams(name, Name, 'Memory', CodeBlock(code))
761 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
762 }};
763
764
765 def template LoadStoreDeclare {{
766 /**
767 * Static instruction class for "%(mnemonic)s".
768 */
769 class %(class_name)s : public %(base_class)s
770 {
771 protected:
772
773 /**
774 * "Fake" effective address computation class for "%(mnemonic)s".
775 */
776 class EAComp : public EACompBase
777 {
778 public:
779 /// Constructor
780 EAComp(MachInst machInst)
781 : EACompBase(machInst)
782 {
783 %(ea_constructor)s;
784 }
785 };
786
787 /**
788 * "Fake" memory access instruction class for "%(mnemonic)s".
789 */
790 class MemAcc : public MemAccBase
791 {
792 public:
793 /// Constructor
794 MemAcc(MachInst machInst)
795 : MemAccBase(machInst, %(op_class)s)
796 {
797 %(memacc_constructor)s;
798 }
799 };
800
801 /// Pointer to EAComp object.
802 StaticInstPtr<AlphaISA> eaCompPtr;
803 /// Pointer to MemAcc object.
804 StaticInstPtr<AlphaISA> memAccPtr;
805
806 public:
807
808 StaticInstPtr<AlphaISA> eaCompInst() { return eaCompPtr; }
809 StaticInstPtr<AlphaISA> memAccInst() { return memAccPtr; }
810
811 /// Constructor.
812 %(class_name)s(MachInst machInst)
813 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s),
814 eaCompPtr(new EAComp(machInst)), memAccPtr(new MemAcc(machInst))
815 {
816 %(constructor)s;
817 }
818
819 %(exec_func_declarations)s
820 };
821 }};
822
823 def template LoadStoreExecute {{
824 Fault %(class_name)s::execute(%(cpu_model)s *xc,
825 Trace::InstRecord *traceData)
826 {
827 Addr EA;
828 Fault fault = No_Fault;
829
830 %(fp_enable_check)s;
831 %(op_decl)s;
832 %(op_nonmem_rd)s;
833 %(ea_code)s;
834
835 if (fault == No_Fault) {
836 %(op_mem_rd)s;
837 %(memacc_code)s;
838 }
839
840 if (fault == No_Fault) {
841 %(op_mem_wb)s;
842 }
843
844 if (fault == No_Fault) {
845 %(postacc_code)s;
846 }
847
848 if (fault == No_Fault) {
849 %(op_nonmem_wb)s;
850 }
851
852 return fault;
853 }
854 }};
855
856 def template PrefetchDeclare {{
857 /**
858 * Static instruction class for "%(mnemonic)s".
859 */
860 class %(class_name)s : public %(base_class)s
861 {
862 protected:
863
864 /**
865 * "Fake" effective address computation class for "%(mnemonic)s".
866 */
867 class EAComp : public EACompBase
868 {
869 public:
870 /// Constructor
871 EAComp(MachInst machInst)
872 : EACompBase(machInst)
873 {
874 %(ea_constructor)s;
875 }
876 };
877
878 /**
879 * "Fake" memory access instruction class for "%(mnemonic)s".
880 */
881 class MemAcc : public MemAccBase
882 {
883 public:
884 /// Constructor
885 MemAcc(MachInst machInst)
886 : MemAccBase(machInst, %(op_class)s)
887 {
888 %(memacc_constructor)s;
889 }
890 };
891
892 /// Pointer to EAComp object.
893 StaticInstPtr<AlphaISA> eaCompPtr;
894 /// Pointer to MemAcc object.
895 StaticInstPtr<AlphaISA> memAccPtr;
896
897 public:
898
899 StaticInstPtr<AlphaISA> eaCompInst() { return eaCompPtr; }
900 StaticInstPtr<AlphaISA> memAccInst() { return memAccPtr; }
901
902 /// Constructor
903 %(class_name)s(MachInst machInst)
904 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s),
905 eaCompPtr(new EAComp(machInst)), memAccPtr(new MemAcc(machInst))
906 {
907 %(constructor)s;
908 }
909
910 %(exec_func_declarations)s
911 };
912 }};
913
914 def template PrefetchExecute {{
915 Fault %(class_name)s::execute(%(cpu_model)s *xc,
916 Trace::InstRecord *traceData)
917 {
918 Addr EA;
919 Fault fault = No_Fault;
920
921 %(fp_enable_check)s;
922 %(op_decl)s;
923 %(op_nonmem_rd)s;
924 %(ea_code)s;
925
926 if (fault == No_Fault) {
927 xc->prefetch(EA, memAccessFlags);
928 }
929
930 return No_Fault;
931 }
932 }};
933
934 // load instructions use Ra as dest, so check for
935 // Ra == 31 to detect nops
936 def template LoadNopCheckDecode {{
937 {
938 AlphaStaticInst *i = new %(class_name)s(machInst);
939 if (RA == 31) {
940 i = makeNop(i);
941 }
942 return i;
943 }
944 }};
945
946
947 // for some load instructions, Ra == 31 indicates a prefetch (not a nop)
948 def template LoadPrefetchCheckDecode {{
949 {
950 if (RA != 31) {
951 return new %(class_name)s(machInst);
952 }
953 else {
954 return new %(class_name)sPrefetch(machInst);
955 }
956 }
957 }};
958
959
960 let {{
961 global LoadStoreBase
962 def LoadStoreBase(name, Name, ea_code, memacc_code, postacc_code = '',
963 base_class = 'Memory', flags = [],
964 declare_template = 'LoadStoreDeclare',
965 decode_template = 'BasicDecode',
966 exec_template = 'LoadStoreExecute'):
967 # Segregate flags into instruction flags (handled by InstObjParams)
968 # and memory access flags (handled here).
969
970 # Would be nice to autogenerate this list, but oh well.
971 valid_mem_flags = ['LOCKED', 'EVICT_NEXT', 'PF_EXCLUSIVE']
972 inst_flags = []
973 mem_flags = []
974 for f in flags:
975 if f in valid_mem_flags:
976 mem_flags.append(f)
977 else:
978 inst_flags.append(f)
979
980 ea_cblk = CodeBlock(ea_code)
981 memacc_cblk = CodeBlock(memacc_code)
982 postacc_cblk = CodeBlock(postacc_code)
983
984 cblk = CodeBlock(ea_code + memacc_code + postacc_code)
985 iop = InstObjParams(name, Name, base_class, cblk, inst_flags)
986
987 iop.ea_constructor = ea_cblk.constructor
988 iop.ea_code = ea_cblk.code
989 iop.memacc_constructor = memacc_cblk.constructor
990 iop.memacc_code = memacc_cblk.code
991 iop.postacc_code = postacc_cblk.code
992
993 mem_flags = string.join(mem_flags, '|')
994 if mem_flags != '':
995 iop.constructor += '\n\tmemAccessFlags = ' + mem_flags + ';'
996
997 return iop.subst(declare_template, decode_template, exec_template)
998 }};
999
1000
1001 def format LoadOrNop(ea_code, memacc_code, *flags) {{
1002 return LoadStoreBase(name, Name, ea_code, memacc_code,
1003 flags = flags,
1004 decode_template = 'LoadNopCheckDecode')
1005 }};
1006
1007
1008 // Note that the flags passed in apply only to the prefetch version
1009 def format LoadOrPrefetch(ea_code, memacc_code, *pf_flags) {{
1010 # declare the load instruction object and generate the decode block
1011 (decls, decode, exec_code) = \
1012 LoadStoreBase(name, Name, ea_code, memacc_code,
1013 decode_template = 'LoadPrefetchCheckDecode')
1014
1015 # Declare the prefetch instruction object.
1016
1017 # convert flags from tuple to list to make them mutable
1018 pf_flags = list(pf_flags) + ['IsMemRef', 'IsLoad', 'IsDataPrefetch', 'RdPort']
1019
1020 (pfdecls, pfdecode, pfexec) = \
1021 LoadStoreBase(name, Name + 'Prefetch', ea_code, '',
1022 flags = pf_flags,
1023 declare_template = 'PrefetchDeclare',
1024 exec_template = 'PrefetchExecute')
1025
1026 return (decls + pfdecls, decode, exec_code + pfexec)
1027 }};
1028
1029
1030 def format Store(ea_code, memacc_code, *flags) {{
1031 return LoadStoreBase(name, Name, ea_code, memacc_code,
1032 flags = flags)
1033 }};
1034
1035
1036 def format StoreCond(ea_code, memacc_code, postacc_code, *flags) {{
1037 return LoadStoreBase(name, Name, ea_code, memacc_code, postacc_code,
1038 flags = flags)
1039 }};
1040
1041
1042 // Use 'MemoryNoDisp' as base: for wh64, fetch, ecb
1043 def format MiscPrefetch(ea_code, memacc_code, *flags) {{
1044 return LoadStoreBase(name, Name, ea_code, memacc_code,
1045 flags = flags, base_class = 'MemoryNoDisp')
1046 }};
1047
1048
1049 ////////////////////////////////////////////////////////////////////
1050
1051
1052 declare {{
1053
1054 /**
1055 * Base class for instructions whose disassembly is not purely a
1056 * function of the machine instruction (i.e., it depends on the
1057 * PC). This class overrides the disassemble() method to check
1058 * the PC and symbol table values before re-using a cached
1059 * disassembly string. This is necessary for branches and jumps,
1060 * where the disassembly string includes the target address (which
1061 * may depend on the PC and/or symbol table).
1062 */
1063 class PCDependentDisassembly : public AlphaStaticInst
1064 {
1065 protected:
1066 /// Cached program counter from last disassembly
1067 Addr cachedPC;
1068 /// Cached symbol table pointer from last disassembly
1069 const SymbolTable *cachedSymtab;
1070
1071 /// Constructor
1072 PCDependentDisassembly(const char *mnem, MachInst _machInst,
1073 OpClass __opClass)
1074 : AlphaStaticInst(mnem, _machInst, __opClass),
1075 cachedPC(0), cachedSymtab(0)
1076 {
1077 }
1078
1079 const std::string &disassemble(Addr pc, const SymbolTable *symtab)
1080 {
1081 if (!cachedDisassembly ||
1082 pc != cachedPC || symtab != cachedSymtab)
1083 {
1084 if (cachedDisassembly)
1085 delete cachedDisassembly;
1086
1087 cachedDisassembly =
1088 new std::string(generateDisassembly(pc, symtab));
1089 cachedPC = pc;
1090 cachedSymtab = symtab;
1091 }
1092
1093 return *cachedDisassembly;
1094 }
1095 };
1096
1097 /**
1098 * Base class for branches (PC-relative control transfers),
1099 * conditional or unconditional.
1100 */
1101 class Branch : public PCDependentDisassembly
1102 {
1103 protected:
1104 /// Displacement to target address (signed).
1105 int32_t disp;
1106
1107 /// Constructor.
1108 Branch(const char *mnem, MachInst _machInst, OpClass __opClass)
1109 : PCDependentDisassembly(mnem, _machInst, __opClass),
1110 disp(BRDISP << 2)
1111 {
1112 }
1113
1114 Addr branchTarget(Addr branchPC) const
1115 {
1116 return branchPC + 4 + disp;
1117 }
1118
1119 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1120 {
1121 std::stringstream ss;
1122
1123 ccprintf(ss, "%-10s ", mnemonic);
1124
1125 // There's only one register arg (RA), but it could be
1126 // either a source (the condition for conditional
1127 // branches) or a destination (the link reg for
1128 // unconditional branches)
1129 if (_numSrcRegs > 0) {
1130 printReg(ss, _srcRegIdx[0]);
1131 ss << ",";
1132 }
1133 else if (_numDestRegs > 0) {
1134 printReg(ss, _destRegIdx[0]);
1135 ss << ",";
1136 }
1137
1138 #ifdef SS_COMPATIBLE_DISASSEMBLY
1139 if (_numSrcRegs == 0 && _numDestRegs == 0) {
1140 printReg(ss, 31);
1141 ss << ",";
1142 }
1143 #endif
1144
1145 Addr target = pc + 4 + disp;
1146
1147 std::string str;
1148 if (symtab && symtab->findSymbol(target, str))
1149 ss << str;
1150 else
1151 ccprintf(ss, "0x%x", target);
1152
1153 return ss.str();
1154 }
1155 };
1156
1157 /**
1158 * Base class for jumps (register-indirect control transfers). In
1159 * the Alpha ISA, these are always unconditional.
1160 */
1161 class Jump : public PCDependentDisassembly
1162 {
1163 protected:
1164
1165 /// Displacement to target address (signed).
1166 int32_t disp;
1167
1168 public:
1169 /// Constructor
1170 Jump(const char *mnem, MachInst _machInst, OpClass __opClass)
1171 : PCDependentDisassembly(mnem, _machInst, __opClass),
1172 disp(BRDISP)
1173 {
1174 }
1175
1176 Addr branchTarget(ExecContext *xc) const
1177 {
1178 Addr NPC = xc->readPC() + 4;
1179 uint64_t Rb = xc->readIntReg(_srcRegIdx[0]);
1180 return (Rb & ~3) | (NPC & 1);
1181 }
1182
1183 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1184 {
1185 std::stringstream ss;
1186
1187 ccprintf(ss, "%-10s ", mnemonic);
1188
1189 #ifdef SS_COMPATIBLE_DISASSEMBLY
1190 if (_numDestRegs == 0) {
1191 printReg(ss, 31);
1192 ss << ",";
1193 }
1194 #endif
1195
1196 if (_numDestRegs > 0) {
1197 printReg(ss, _destRegIdx[0]);
1198 ss << ",";
1199 }
1200
1201 ccprintf(ss, "(r%d)", RB);
1202
1203 return ss.str();
1204 }
1205 };
1206 }};
1207
1208 def template JumpOrBranchDecode {{
1209 return (RA == 31)
1210 ? (StaticInst<AlphaISA> *)new %(class_name)s(machInst)
1211 : (StaticInst<AlphaISA> *)new %(class_name)sAndLink(machInst);
1212 }};
1213
1214 def format CondBranch(code) {{
1215 code = 'bool cond;\n' + code + '\nif (cond) NPC = NPC + disp;\n';
1216 iop = InstObjParams(name, Name, 'Branch', CodeBlock(code),
1217 ('IsDirectControl', 'IsCondControl'))
1218 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
1219 }};
1220
1221 let {{
1222 global UncondCtrlBase
1223 def UncondCtrlBase(name, Name, base_class, npc_expr, flags):
1224 # Declare basic control transfer w/o link (i.e. link reg is R31)
1225 nolink_code = 'NPC = %s;\n' % npc_expr
1226 nolink_iop = InstObjParams(name, Name, base_class,
1227 CodeBlock(nolink_code), flags)
1228 (decls, exec_code) = nolink_iop.subst('BasicDeclare', 'BasicExecute')
1229
1230 # Generate declaration of '*AndLink' version, append to decls
1231 link_code = 'Ra = NPC & ~3;\n' + nolink_code
1232 link_iop = InstObjParams(name, Name + 'AndLink', base_class,
1233 CodeBlock(link_code), flags)
1234 (link_decls, link_exec_code) = \
1235 link_iop.subst('BasicDeclare', 'BasicExecute')
1236 decls += link_decls
1237 exec_code += link_exec_code
1238
1239 # need to use link_iop for the decode template since it is expecting
1240 # the shorter version of class_name (w/o "AndLink")
1241 return (decls, nolink_iop.subst('JumpOrBranchDecode'), exec_code)
1242 }};
1243
1244 def format UncondBranch(*flags) {{
1245 flags += ('IsUncondControl', 'IsDirectControl')
1246 return UncondCtrlBase(name, Name, 'Branch', 'NPC + disp', flags)
1247 }};
1248
1249 def format Jump(*flags) {{
1250 flags += ('IsUncondControl', 'IsIndirectControl')
1251 return UncondCtrlBase(name, Name, 'Jump', '(Rb & ~3) | (NPC & 1)', flags)
1252 }};
1253
1254
1255 declare {{
1256 /**
1257 * Base class for emulated call_pal calls (used only in
1258 * non-full-system mode).
1259 */
1260 class EmulatedCallPal : public AlphaStaticInst
1261 {
1262 protected:
1263
1264 /// Constructor.
1265 EmulatedCallPal(const char *mnem, MachInst _machInst,
1266 OpClass __opClass)
1267 : AlphaStaticInst(mnem, _machInst, __opClass)
1268 {
1269 }
1270
1271 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1272 {
1273 #ifdef SS_COMPATIBLE_DISASSEMBLY
1274 return csprintf("%s %s", "call_pal", mnemonic);
1275 #else
1276 return csprintf("%-10s %s", "call_pal", mnemonic);
1277 #endif
1278 }
1279 };
1280 }};
1281
1282 def format EmulatedCallPal(code) {{
1283 iop = InstObjParams(name, Name, 'EmulatedCallPal', CodeBlock(code))
1284 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
1285 }};
1286
1287 declare {{
1288 /**
1289 * Base class for full-system-mode call_pal instructions.
1290 * Probably could turn this into a leaf class and get rid of the
1291 * parser template.
1292 */
1293 class CallPalBase : public AlphaStaticInst
1294 {
1295 protected:
1296 int palFunc; ///< Function code part of instruction
1297 int palOffset; ///< Target PC, offset from IPR_PAL_BASE
1298 bool palValid; ///< is the function code valid?
1299 bool palPriv; ///< is this call privileged?
1300
1301 /// Constructor.
1302 CallPalBase(const char *mnem, MachInst _machInst,
1303 OpClass __opClass)
1304 : AlphaStaticInst(mnem, _machInst, __opClass),
1305 palFunc(PALFUNC)
1306 {
1307 // From the 21164 HRM (paraphrased):
1308 // Bit 7 of the function code (mask 0x80) indicates
1309 // whether the call is privileged (bit 7 == 0) or
1310 // unprivileged (bit 7 == 1). The privileged call table
1311 // starts at 0x2000, the unprivielged call table starts at
1312 // 0x3000. Bits 5-0 (mask 0x3f) are used to calculate the
1313 // offset.
1314 const int palPrivMask = 0x80;
1315 const int palOffsetMask = 0x3f;
1316
1317 // Pal call is invalid unless all other bits are 0
1318 palValid = ((machInst & ~(palPrivMask | palOffsetMask)) == 0);
1319 palPriv = ((machInst & palPrivMask) == 0);
1320 int shortPalFunc = (machInst & palOffsetMask);
1321 // Add 1 to base to set pal-mode bit
1322 palOffset = (palPriv ? 0x2001 : 0x3001) + (shortPalFunc << 6);
1323 }
1324
1325 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1326 {
1327 return csprintf("%-10s %#x", "call_pal", palFunc);
1328 }
1329 };
1330 }};
1331
1332
1333 def format CallPal(code) {{
1334 iop = InstObjParams(name, Name, 'CallPalBase', CodeBlock(code))
1335 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
1336 }};
1337
1338 //
1339 // hw_ld, hw_st
1340 //
1341 declare {{
1342 /**
1343 * Base class for hw_ld and hw_st.
1344 */
1345 class HwLoadStore : public AlphaStaticInst
1346 {
1347 protected:
1348
1349 /// Displacement for EA calculation (signed).
1350 int16_t disp;
1351 /// Memory request flags. See mem_req_base.hh.
1352 unsigned memAccessFlags;
1353
1354 /// Constructor
1355 HwLoadStore(const char *mnem, MachInst _machInst, OpClass __opClass)
1356 : AlphaStaticInst(mnem, _machInst, __opClass), disp(HW_LDST_DISP)
1357 {
1358 memAccessFlags = 0;
1359 if (HW_LDST_PHYS) memAccessFlags |= PHYSICAL;
1360 if (HW_LDST_ALT) memAccessFlags |= ALTMODE;
1361 if (HW_LDST_VPTE) memAccessFlags |= VPTE;
1362 if (HW_LDST_LOCK) memAccessFlags |= LOCKED;
1363 }
1364
1365 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1366 {
1367 #ifdef SS_COMPATIBLE_DISASSEMBLY
1368 return csprintf("%-10s r%d,%d(r%d)", mnemonic, RA, disp, RB);
1369 #else
1370 // HW_LDST_LOCK and HW_LDST_COND are the same bit.
1371 const char *lock_str =
1372 (HW_LDST_LOCK) ? (flags[IsLoad] ? ",LOCK" : ",COND") : "";
1373
1374 return csprintf("%-10s r%d,%d(r%d)%s%s%s%s%s",
1375 mnemonic, RA, disp, RB,
1376 HW_LDST_PHYS ? ",PHYS" : "",
1377 HW_LDST_ALT ? ",ALT" : "",
1378 HW_LDST_QUAD ? ",QUAD" : "",
1379 HW_LDST_VPTE ? ",VPTE" : "",
1380 lock_str);
1381 #endif
1382 }
1383 };
1384 }};
1385
1386
1387 def format HwLoadStore(ea_code, memacc_code, class_ext, *flags) {{
1388 return LoadStoreBase(name, Name + class_ext, ea_code, memacc_code,
1389 flags = flags,
1390 base_class = 'HwLoadStore')
1391 }};
1392
1393
1394 def format HwStoreCond(ea_code, memacc_code, postacc_code, class_ext, *flags) {{
1395 return LoadStoreBase(name, Name + class_ext,
1396 ea_code, memacc_code, postacc_code,
1397 flags = flags,
1398 base_class = 'HwLoadStore')
1399 }};
1400
1401
1402 declare {{
1403 /**
1404 * Base class for hw_mfpr and hw_mtpr.
1405 */
1406 class HwMoveIPR : public AlphaStaticInst
1407 {
1408 protected:
1409 /// Index of internal processor register.
1410 int ipr_index;
1411
1412 /// Constructor
1413 HwMoveIPR(const char *mnem, MachInst _machInst, OpClass __opClass)
1414 : AlphaStaticInst(mnem, _machInst, __opClass),
1415 ipr_index(HW_IPR_IDX)
1416 {
1417 }
1418
1419 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1420 {
1421 if (_numSrcRegs > 0) {
1422 // must be mtpr
1423 return csprintf("%-10s r%d,IPR(%#x)",
1424 mnemonic, RA, ipr_index);
1425 }
1426 else {
1427 // must be mfpr
1428 return csprintf("%-10s IPR(%#x),r%d",
1429 mnemonic, ipr_index, RA);
1430 }
1431 }
1432 };
1433 }};
1434
1435 def format HwMoveIPR(code) {{
1436 iop = InstObjParams(name, Name, 'HwMoveIPR', CodeBlock(code))
1437 return iop.subst('BasicDeclare', 'BasicDecode', 'BasicExecute')
1438 }};
1439
1440 declare {{
1441 /**
1442 * Static instruction class for unimplemented instructions that
1443 * cause simulator termination. Note that these are recognized
1444 * (legal) instructions that the simulator does not support; the
1445 * 'Unknown' class is used for unrecognized/illegal instructions.
1446 * This is a leaf class.
1447 */
1448 class FailUnimplemented : public AlphaStaticInst
1449 {
1450 public:
1451 /// Constructor
1452 FailUnimplemented(const char *_mnemonic, MachInst _machInst)
1453 : AlphaStaticInst(_mnemonic, _machInst, No_OpClass)
1454 {
1455 }
1456
1457 Fault execute(SimpleCPUExecContext *xc,
1458 Trace::InstRecord *traceData)
1459 {
1460 panic("attempt to execute unimplemented instruction '%s' "
1461 "(inst 0x%08x, opcode 0x%x)", mnemonic, machInst, OPCODE);
1462 return Unimplemented_Opcode_Fault;
1463 }
1464
1465 Fault execute(FastCPUExecContext *xc,
1466 Trace::InstRecord *traceData)
1467 {
1468 panic("attempt to execute unimplemented instruction '%s' "
1469 "(inst 0x%08x, opcode 0x%x)", mnemonic, machInst, OPCODE);
1470 return Unimplemented_Opcode_Fault;
1471 }
1472
1473 Fault execute(FullCPUExecContext *xc,
1474 Trace::InstRecord *traceData)
1475 {
1476 // don't panic if this is a misspeculated instruction
1477 if (!xc->misspeculating())
1478 panic("attempt to execute unimplemented instruction '%s' "
1479 "(inst 0x%08x, opcode 0x%x)",
1480 mnemonic, machInst, OPCODE);
1481 return Unimplemented_Opcode_Fault;
1482 }
1483
1484 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1485 {
1486 return csprintf("%-10s (unimplemented)", mnemonic);
1487 }
1488 };
1489
1490 /**
1491 * Base class for unimplemented instructions that cause a warning
1492 * to be printed (but do not terminate simulation). This
1493 * implementation is a little screwy in that it will print a
1494 * warning for each instance of a particular unimplemented machine
1495 * instruction, not just for each unimplemented opcode. Should
1496 * probably make the 'warned' flag a static member of the derived
1497 * class.
1498 */
1499 class WarnUnimplemented : public AlphaStaticInst
1500 {
1501 private:
1502 /// Have we warned on this instruction yet?
1503 bool warned;
1504
1505 public:
1506 /// Constructor
1507 WarnUnimplemented(const char *_mnemonic, MachInst _machInst)
1508 : AlphaStaticInst(_mnemonic, _machInst, No_OpClass), warned(false)
1509 {
1510 }
1511
1512 Fault execute(SimpleCPUExecContext *xc,
1513 Trace::InstRecord *traceData)
1514 {
1515 if (!warned) {
1516 warn("instruction '%s' unimplemented\n", mnemonic);
1517 warned = true;
1518 }
1519
1520 return No_Fault;
1521 }
1522
1523 Fault execute(FastCPUExecContext *xc,
1524 Trace::InstRecord *traceData)
1525 {
1526 if (!warned) {
1527 warn("instruction '%s' unimplemented\n", mnemonic);
1528 warned = true;
1529 }
1530
1531 return No_Fault;
1532 }
1533
1534 Fault execute(FullCPUExecContext *xc,
1535 Trace::InstRecord *traceData)
1536 {
1537 if (!xc->misspeculating() && !warned) {
1538 warn("instruction '%s' unimplemented\n", mnemonic);
1539 warned = true;
1540 }
1541
1542 return No_Fault;
1543 }
1544
1545 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1546 {
1547 #ifdef SS_COMPATIBLE_DISASSEMBLY
1548 return csprintf("%-10s", mnemonic);
1549 #else
1550 return csprintf("%-10s (unimplemented)", mnemonic);
1551 #endif
1552 }
1553 };
1554 }};
1555
1556 def template WarnUnimplDeclare {{
1557 /**
1558 * Static instruction class for "%(mnemonic)s".
1559 */
1560 class %(class_name)s : public %(base_class)s
1561 {
1562 public:
1563 /// Constructor
1564 %(class_name)s(MachInst machInst)
1565 : %(base_class)s("%(mnemonic)s", machInst)
1566 {
1567 }
1568 };
1569 }};
1570
1571
1572 def format FailUnimpl() {{
1573 iop = InstObjParams(name, 'FailUnimplemented')
1574 return ('', iop.subst('BasicDecodeWithMnemonic'), '')
1575 }};
1576
1577 def format WarnUnimpl() {{
1578 iop = InstObjParams(name, Name, 'WarnUnimplemented')
1579 return iop.subst('WarnUnimplDeclare', 'BasicDecode') + ['']
1580 }};
1581
1582 declare {{
1583 /**
1584 * Static instruction class for unknown (illegal) instructions.
1585 * These cause simulator termination if they are executed in a
1586 * non-speculative mode. This is a leaf class.
1587 */
1588 class Unknown : public AlphaStaticInst
1589 {
1590 public:
1591 /// Constructor
1592 Unknown(MachInst _machInst)
1593 : AlphaStaticInst("unknown", _machInst, No_OpClass)
1594 {
1595 }
1596
1597 Fault execute(SimpleCPUExecContext *xc,
1598 Trace::InstRecord *traceData)
1599 {
1600 panic("attempt to execute unknown instruction "
1601 "(inst 0x%08x, opcode 0x%x)", machInst, OPCODE);
1602 return Unimplemented_Opcode_Fault;
1603 }
1604
1605 Fault execute(FastCPUExecContext *xc,
1606 Trace::InstRecord *traceData)
1607 {
1608 panic("attempt to execute unknown instruction "
1609 "(inst 0x%08x, opcode 0x%x)", machInst, OPCODE);
1610 return Unimplemented_Opcode_Fault;
1611 }
1612
1613 Fault execute(FullCPUExecContext *xc,
1614 Trace::InstRecord *traceData)
1615 {
1616 // don't panic if this is a misspeculated instruction
1617 if (!xc->misspeculating())
1618 panic("attempt to execute unknown instruction "
1619 "(inst 0x%08x, opcode 0x%x)", machInst, OPCODE);
1620 return Unimplemented_Opcode_Fault;
1621 }
1622
1623 std::string generateDisassembly(Addr pc, const SymbolTable *symtab)
1624 {
1625 return csprintf("%-10s (inst 0x%x, opcode 0x%x)",
1626 "unknown", machInst, OPCODE);
1627 }
1628 };
1629 }};
1630
1631 def format Unknown() {{
1632 return ('', 'return new Unknown(machInst);\n', '')
1633 }};
1634
1635 declare {{
1636
1637 /// Return opa + opb, summing carry into third arg.
1638 inline uint64_t
1639 addc(uint64_t opa, uint64_t opb, int &carry)
1640 {
1641 uint64_t res = opa + opb;
1642 if (res < opa || res < opb)
1643 ++carry;
1644 return res;
1645 }
1646
1647 /// Multiply two 64-bit values (opa * opb), returning the 128-bit
1648 /// product in res_hi and res_lo.
1649 void
1650 mul128(uint64_t opa, uint64_t opb, uint64_t &res_hi, uint64_t &res_lo)
1651 {
1652 // do a 64x64 --> 128 multiply using four 32x32 --> 64 multiplies
1653 uint64_t opa_hi = opa<63:32>;
1654 uint64_t opa_lo = opa<31:0>;
1655 uint64_t opb_hi = opb<63:32>;
1656 uint64_t opb_lo = opb<31:0>;
1657
1658 res_lo = opa_lo * opb_lo;
1659
1660 // The middle partial products logically belong in bit
1661 // positions 95 to 32. Thus the lower 32 bits of each product
1662 // sum into the upper 32 bits of the low result, while the
1663 // upper 32 sum into the low 32 bits of the upper result.
1664 uint64_t partial1 = opa_hi * opb_lo;
1665 uint64_t partial2 = opa_lo * opb_hi;
1666
1667 uint64_t partial1_lo = partial1<31:0> << 32;
1668 uint64_t partial1_hi = partial1<63:32>;
1669 uint64_t partial2_lo = partial2<31:0> << 32;
1670 uint64_t partial2_hi = partial2<63:32>;
1671
1672 // Add partial1_lo and partial2_lo to res_lo, keeping track
1673 // of any carries out
1674 int carry_out = 0;
1675 res_lo = addc(partial1_lo, res_lo, carry_out);
1676 res_lo = addc(partial2_lo, res_lo, carry_out);
1677
1678 // Now calculate the high 64 bits...
1679 res_hi = (opa_hi * opb_hi) + partial1_hi + partial2_hi + carry_out;
1680 }
1681
1682 /// Map 8-bit S-floating exponent to 11-bit T-floating exponent.
1683 /// See Table 2-2 of Alpha AHB.
1684 inline int
1685 map_s(int old_exp)
1686 {
1687 int hibit = old_exp<7:>;
1688 int lobits = old_exp<6:0>;
1689
1690 if (hibit == 1) {
1691 return (lobits == 0x7f) ? 0x7ff : (0x400 | lobits);
1692 }
1693 else {
1694 return (lobits == 0) ? 0 : (0x380 | lobits);
1695 }
1696 }
1697
1698 /// Convert a 32-bit S-floating value to the equivalent 64-bit
1699 /// representation to be stored in an FP reg.
1700 inline uint64_t
1701 s_to_t(uint32_t s_val)
1702 {
1703 uint64_t tmp = s_val;
1704 return (tmp<31:> << 63 // sign bit
1705 | (uint64_t)map_s(tmp<30:23>) << 52 // exponent
1706 | tmp<22:0> << 29); // fraction
1707 }
1708
1709 /// Convert a 64-bit T-floating value to the equivalent 32-bit
1710 /// S-floating representation to be stored in memory.
1711 inline int32_t
1712 t_to_s(uint64_t t_val)
1713 {
1714 return (t_val<63:62> << 30 // sign bit & hi exp bit
1715 | t_val<58:29>); // rest of exp & fraction
1716 }
1717 }};
1718
1719 decode OPCODE default Unknown::unknown() {
1720
1721 format LoadAddress {
1722 0x08: lda({{ Ra = Rb + disp; }});
1723 0x09: ldah({{ Ra = Rb + (disp << 16); }});
1724 }
1725
1726 format LoadOrNop {
1727 0x0a: ldbu({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.ub; }});
1728 0x0c: ldwu({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uw; }});
1729 0x0b: ldq_u({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }});
1730 0x23: ldt({{ EA = Rb + disp; }}, {{ Fa = Mem.df; }});
1731 0x2a: ldl_l({{ EA = Rb + disp; }}, {{ Ra.sl = Mem.sl; }}, LOCKED);
1732 0x2b: ldq_l({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uq; }}, LOCKED);
1733 0x20: copy_load({{EA = Ra;}},
1734 {{ fault = xc->copySrcTranslate(EA);}},
1735 IsMemRef, IsLoad, IsCopy);
1736 }
1737
1738 format LoadOrPrefetch {
1739 0x28: ldl({{ EA = Rb + disp; }}, {{ Ra.sl = Mem.sl; }});
1740 0x29: ldq({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uq; }}, EVICT_NEXT);
1741 // IsFloating flag on lds gets the prefetch to disassemble
1742 // using f31 instead of r31... funcitonally it's unnecessary
1743 0x22: lds({{ EA = Rb + disp; }}, {{ Fa.uq = s_to_t(Mem.ul); }},
1744 PF_EXCLUSIVE, IsFloating);
1745 }
1746
1747 format Store {
1748 0x0e: stb({{ EA = Rb + disp; }}, {{ Mem.ub = Ra<7:0>; }});
1749 0x0d: stw({{ EA = Rb + disp; }}, {{ Mem.uw = Ra<15:0>; }});
1750 0x2c: stl({{ EA = Rb + disp; }}, {{ Mem.ul = Ra<31:0>; }});
1751 0x2d: stq({{ EA = Rb + disp; }}, {{ Mem.uq = Ra.uq; }});
1752 0x0f: stq_u({{ EA = (Rb + disp) & ~7; }}, {{ Mem.uq = Ra.uq; }});
1753 0x26: sts({{ EA = Rb + disp; }}, {{ Mem.ul = t_to_s(Fa.uq); }});
1754 0x27: stt({{ EA = Rb + disp; }}, {{ Mem.df = Fa; }});
1755 0x24: copy_store({{EA = Rb;}},
1756 {{ fault = xc->copy(EA);}},
1757 IsMemRef, IsStore, IsCopy);
1758 }
1759
1760 format StoreCond {
1761 0x2e: stl_c({{ EA = Rb + disp; }}, {{ Mem.ul = Ra<31:0>; }},
1762 {{
1763 uint64_t tmp = Mem_write_result;
1764 // see stq_c
1765 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
1766 }}, LOCKED);
1767 0x2f: stq_c({{ EA = Rb + disp; }}, {{ Mem.uq = Ra; }},
1768 {{
1769 uint64_t tmp = Mem_write_result;
1770 // If the write operation returns 0 or 1, then
1771 // this was a conventional store conditional,
1772 // and the value indicates the success/failure
1773 // of the operation. If another value is
1774 // returned, then this was a Turbolaser
1775 // mailbox access, and we don't update the
1776 // result register at all.
1777 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
1778 }}, LOCKED);
1779 }
1780
1781 format IntegerOperate {
1782
1783 0x10: decode INTFUNC { // integer arithmetic operations
1784
1785 0x00: addl({{ Rc.sl = Ra.sl + Rb_or_imm.sl; }});
1786 0x40: addlv({{
1787 uint32_t tmp = Ra.sl + Rb_or_imm.sl;
1788 // signed overflow occurs when operands have same sign
1789 // and sign of result does not match.
1790 if (Ra.sl<31:> == Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
1791 fault = Integer_Overflow_Fault;
1792 Rc.sl = tmp;
1793 }});
1794 0x02: s4addl({{ Rc.sl = (Ra.sl << 2) + Rb_or_imm.sl; }});
1795 0x12: s8addl({{ Rc.sl = (Ra.sl << 3) + Rb_or_imm.sl; }});
1796
1797 0x20: addq({{ Rc = Ra + Rb_or_imm; }});
1798 0x60: addqv({{
1799 uint64_t tmp = Ra + Rb_or_imm;
1800 // signed overflow occurs when operands have same sign
1801 // and sign of result does not match.
1802 if (Ra<63:> == Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
1803 fault = Integer_Overflow_Fault;
1804 Rc = tmp;
1805 }});
1806 0x22: s4addq({{ Rc = (Ra << 2) + Rb_or_imm; }});
1807 0x32: s8addq({{ Rc = (Ra << 3) + Rb_or_imm; }});
1808
1809 0x09: subl({{ Rc.sl = Ra.sl - Rb_or_imm.sl; }});
1810 0x49: sublv({{
1811 uint32_t tmp = Ra.sl - Rb_or_imm.sl;
1812 // signed overflow detection is same as for add,
1813 // except we need to look at the *complemented*
1814 // sign bit of the subtrahend (Rb), i.e., if the initial
1815 // signs are the *same* then no overflow can occur
1816 if (Ra.sl<31:> != Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
1817 fault = Integer_Overflow_Fault;
1818 Rc.sl = tmp;
1819 }});
1820 0x0b: s4subl({{ Rc.sl = (Ra.sl << 2) - Rb_or_imm.sl; }});
1821 0x1b: s8subl({{ Rc.sl = (Ra.sl << 3) - Rb_or_imm.sl; }});
1822
1823 0x29: subq({{ Rc = Ra - Rb_or_imm; }});
1824 0x69: subqv({{
1825 uint64_t tmp = Ra - Rb_or_imm;
1826 // signed overflow detection is same as for add,
1827 // except we need to look at the *complemented*
1828 // sign bit of the subtrahend (Rb), i.e., if the initial
1829 // signs are the *same* then no overflow can occur
1830 if (Ra<63:> != Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
1831 fault = Integer_Overflow_Fault;
1832 Rc = tmp;
1833 }});
1834 0x2b: s4subq({{ Rc = (Ra << 2) - Rb_or_imm; }});
1835 0x3b: s8subq({{ Rc = (Ra << 3) - Rb_or_imm; }});
1836
1837 0x2d: cmpeq({{ Rc = (Ra == Rb_or_imm); }});
1838 0x6d: cmple({{ Rc = (Ra.sq <= Rb_or_imm.sq); }});
1839 0x4d: cmplt({{ Rc = (Ra.sq < Rb_or_imm.sq); }});
1840 0x3d: cmpule({{ Rc = (Ra.uq <= Rb_or_imm.uq); }});
1841 0x1d: cmpult({{ Rc = (Ra.uq < Rb_or_imm.uq); }});
1842
1843 0x0f: cmpbge({{
1844 int hi = 7;
1845 int lo = 0;
1846 uint64_t tmp = 0;
1847 for (int i = 0; i < 8; ++i) {
1848 tmp |= (Ra.uq<hi:lo> >= Rb_or_imm.uq<hi:lo>) << i;
1849 hi += 8;
1850 lo += 8;
1851 }
1852 Rc = tmp;
1853 }});
1854 }
1855
1856 0x11: decode INTFUNC { // integer logical operations
1857
1858 0x00: and({{ Rc = Ra & Rb_or_imm; }});
1859 0x08: bic({{ Rc = Ra & ~Rb_or_imm; }});
1860 0x20: bis({{ Rc = Ra | Rb_or_imm; }});
1861 0x28: ornot({{ Rc = Ra | ~Rb_or_imm; }});
1862 0x40: xor({{ Rc = Ra ^ Rb_or_imm; }});
1863 0x48: eqv({{ Rc = Ra ^ ~Rb_or_imm; }});
1864
1865 // conditional moves
1866 0x14: cmovlbs({{ Rc = ((Ra & 1) == 1) ? Rb_or_imm : Rc; }});
1867 0x16: cmovlbc({{ Rc = ((Ra & 1) == 0) ? Rb_or_imm : Rc; }});
1868 0x24: cmoveq({{ Rc = (Ra == 0) ? Rb_or_imm : Rc; }});
1869 0x26: cmovne({{ Rc = (Ra != 0) ? Rb_or_imm : Rc; }});
1870 0x44: cmovlt({{ Rc = (Ra.sq < 0) ? Rb_or_imm : Rc; }});
1871 0x46: cmovge({{ Rc = (Ra.sq >= 0) ? Rb_or_imm : Rc; }});
1872 0x64: cmovle({{ Rc = (Ra.sq <= 0) ? Rb_or_imm : Rc; }});
1873 0x66: cmovgt({{ Rc = (Ra.sq > 0) ? Rb_or_imm : Rc; }});
1874
1875 // For AMASK, RA must be R31.
1876 0x61: decode RA {
1877 31: amask({{ Rc = Rb_or_imm & ~ULL(0x17); }});
1878 }
1879
1880 // For IMPLVER, RA must be R31 and the B operand
1881 // must be the immediate value 1.
1882 0x6c: decode RA {
1883 31: decode IMM {
1884 1: decode INTIMM {
1885 // return EV5 for FULL_SYSTEM and EV6 otherwise
1886 1: implver({{
1887 #ifdef FULL_SYSTEM
1888 Rc = 1;
1889 #else
1890 Rc = 2;
1891 #endif
1892 }});
1893 }
1894 }
1895 }
1896
1897 #ifdef FULL_SYSTEM
1898 // The mysterious 11.25...
1899 0x25: WarnUnimpl::eleven25();
1900 #endif
1901 }
1902
1903 0x12: decode INTFUNC {
1904 0x39: sll({{ Rc = Ra << Rb_or_imm<5:0>; }});
1905 0x34: srl({{ Rc = Ra.uq >> Rb_or_imm<5:0>; }});
1906 0x3c: sra({{ Rc = Ra.sq >> Rb_or_imm<5:0>; }});
1907
1908 0x02: mskbl({{ Rc = Ra & ~(mask( 8) << (Rb_or_imm<2:0> * 8)); }});
1909 0x12: mskwl({{ Rc = Ra & ~(mask(16) << (Rb_or_imm<2:0> * 8)); }});
1910 0x22: mskll({{ Rc = Ra & ~(mask(32) << (Rb_or_imm<2:0> * 8)); }});
1911 0x32: mskql({{ Rc = Ra & ~(mask(64) << (Rb_or_imm<2:0> * 8)); }});
1912
1913 0x52: mskwh({{
1914 int bv = Rb_or_imm<2:0>;
1915 Rc = bv ? (Ra & ~(mask(16) >> (64 - 8 * bv))) : Ra;
1916 }});
1917 0x62: msklh({{
1918 int bv = Rb_or_imm<2:0>;
1919 Rc = bv ? (Ra & ~(mask(32) >> (64 - 8 * bv))) : Ra;
1920 }});
1921 0x72: mskqh({{
1922 int bv = Rb_or_imm<2:0>;
1923 Rc = bv ? (Ra & ~(mask(64) >> (64 - 8 * bv))) : Ra;
1924 }});
1925
1926 0x06: extbl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))< 7:0>; }});
1927 0x16: extwl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<15:0>; }});
1928 0x26: extll({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<31:0>; }});
1929 0x36: extql({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8)); }});
1930
1931 0x5a: extwh({{
1932 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<15:0>; }});
1933 0x6a: extlh({{
1934 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<31:0>; }});
1935 0x7a: extqh({{
1936 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>); }});
1937
1938 0x0b: insbl({{ Rc = Ra< 7:0> << (Rb_or_imm<2:0> * 8); }});
1939 0x1b: inswl({{ Rc = Ra<15:0> << (Rb_or_imm<2:0> * 8); }});
1940 0x2b: insll({{ Rc = Ra<31:0> << (Rb_or_imm<2:0> * 8); }});
1941 0x3b: insql({{ Rc = Ra << (Rb_or_imm<2:0> * 8); }});
1942
1943 0x57: inswh({{
1944 int bv = Rb_or_imm<2:0>;
1945 Rc = bv ? (Ra.uq<15:0> >> (64 - 8 * bv)) : 0;
1946 }});
1947 0x67: inslh({{
1948 int bv = Rb_or_imm<2:0>;
1949 Rc = bv ? (Ra.uq<31:0> >> (64 - 8 * bv)) : 0;
1950 }});
1951 0x77: insqh({{
1952 int bv = Rb_or_imm<2:0>;
1953 Rc = bv ? (Ra.uq >> (64 - 8 * bv)) : 0;
1954 }});
1955
1956 0x30: zap({{
1957 uint64_t zapmask = 0;
1958 for (int i = 0; i < 8; ++i) {
1959 if (Rb_or_imm<i:>)
1960 zapmask |= (mask(8) << (i * 8));
1961 }
1962 Rc = Ra & ~zapmask;
1963 }});
1964 0x31: zapnot({{
1965 uint64_t zapmask = 0;
1966 for (int i = 0; i < 8; ++i) {
1967 if (!Rb_or_imm<i:>)
1968 zapmask |= (mask(8) << (i * 8));
1969 }
1970 Rc = Ra & ~zapmask;
1971 }});
1972 }
1973
1974 0x13: decode INTFUNC { // integer multiplies
1975 0x00: mull({{ Rc.sl = Ra.sl * Rb_or_imm.sl; }}, IntMULT);
1976 0x20: mulq({{ Rc = Ra * Rb_or_imm; }}, IntMULT);
1977 0x30: umulh({{
1978 uint64_t hi, lo;
1979 mul128(Ra, Rb_or_imm, hi, lo);
1980 Rc = hi;
1981 }}, IntMULT);
1982 0x40: mullv({{
1983 // 32-bit multiply with trap on overflow
1984 int64_t Rax = Ra.sl; // sign extended version of Ra.sl
1985 int64_t Rbx = Rb_or_imm.sl;
1986 int64_t tmp = Rax * Rbx;
1987 // To avoid overflow, all the upper 32 bits must match
1988 // the sign bit of the lower 32. We code this as
1989 // checking the upper 33 bits for all 0s or all 1s.
1990 uint64_t sign_bits = tmp<63:31>;
1991 if (sign_bits != 0 && sign_bits != mask(33))
1992 fault = Integer_Overflow_Fault;
1993 Rc.sl = tmp<31:0>;
1994 }}, IntMULT);
1995 0x60: mulqv({{
1996 // 64-bit multiply with trap on overflow
1997 uint64_t hi, lo;
1998 mul128(Ra, Rb_or_imm, hi, lo);
1999 // all the upper 64 bits must match the sign bit of
2000 // the lower 64
2001 if (!((hi == 0 && lo<63:> == 0) ||
2002 (hi == mask(64) && lo<63:> == 1)))
2003 fault = Integer_Overflow_Fault;
2004 Rc = lo;
2005 }}, IntMULT);
2006 }
2007
2008 0x1c: decode INTFUNC {
2009 0x00: decode RA { 31: sextb({{ Rc.sb = Rb_or_imm< 7:0>; }}); }
2010 0x01: decode RA { 31: sextw({{ Rc.sw = Rb_or_imm<15:0>; }}); }
2011
2012 format FailUnimpl {
2013 0x30: ctpop();
2014 0x31: perr();
2015 0x32: ctlz();
2016 0x33: cttz();
2017 0x34: unpkbw();
2018 0x35: unpkbl();
2019 0x36: pkwb();
2020 0x37: pklb();
2021 0x38: minsb8();
2022 0x39: minsw4();
2023 0x3a: minub8();
2024 0x3b: minuw4();
2025 0x3c: maxub8();
2026 0x3d: maxuw4();
2027 0x3e: maxsb8();
2028 0x3f: maxsw4();
2029 }
2030
2031 format BasicOperateWithNopCheck {
2032 0x70: decode RB {
2033 31: ftoit({{ Rc = Fa.uq; }}, FloatCVT);
2034 }
2035 0x78: decode RB {
2036 31: ftois({{ Rc.sl = t_to_s(Fa.uq); }},
2037 FloatCVT);
2038 }
2039 }
2040 }
2041 }
2042
2043 // Conditional branches.
2044 format CondBranch {
2045 0x39: beq({{ cond = (Ra == 0); }});
2046 0x3d: bne({{ cond = (Ra != 0); }});
2047 0x3e: bge({{ cond = (Ra.sq >= 0); }});
2048 0x3f: bgt({{ cond = (Ra.sq > 0); }});
2049 0x3b: ble({{ cond = (Ra.sq <= 0); }});
2050 0x3a: blt({{ cond = (Ra.sq < 0); }});
2051 0x38: blbc({{ cond = ((Ra & 1) == 0); }});
2052 0x3c: blbs({{ cond = ((Ra & 1) == 1); }});
2053
2054 0x31: fbeq({{ cond = (Fa == 0); }});
2055 0x35: fbne({{ cond = (Fa != 0); }});
2056 0x36: fbge({{ cond = (Fa >= 0); }});
2057 0x37: fbgt({{ cond = (Fa > 0); }});
2058 0x33: fble({{ cond = (Fa <= 0); }});
2059 0x32: fblt({{ cond = (Fa < 0); }});
2060 }
2061
2062 // unconditional branches
2063 format UncondBranch {
2064 0x30: br();
2065 0x34: bsr(IsCall);
2066 }
2067
2068 // indirect branches
2069 0x1a: decode JMPFUNC {
2070 format Jump {
2071 0: jmp();
2072 1: jsr(IsCall);
2073 2: ret(IsReturn);
2074 3: jsr_coroutine(IsCall, IsReturn);
2075 }
2076 }
2077
2078 // IEEE floating point
2079 0x14: decode FP_SHORTFUNC {
2080 // Integer to FP register moves must have RB == 31
2081 0x4: decode RB {
2082 31: decode FP_FULLFUNC {
2083 format BasicOperateWithNopCheck {
2084 0x004: itofs({{ Fc.uq = s_to_t(Ra.ul); }}, FloatCVT);
2085 0x024: itoft({{ Fc.uq = Ra.uq; }}, FloatCVT);
2086 0x014: FailUnimpl::itoff(); // VAX-format conversion
2087 }
2088 }
2089 }
2090
2091 // Square root instructions must have FA == 31
2092 0xb: decode FA {
2093 31: decode FP_TYPEFUNC {
2094 format FloatingPointOperate {
2095 #ifdef SS_COMPATIBLE_FP
2096 0x0b: sqrts({{
2097 if (Fb < 0.0)
2098 fault = Arithmetic_Fault;
2099 Fc = sqrt(Fb);
2100 }}, FloatSQRT);
2101 #else
2102 0x0b: sqrts({{
2103 if (Fb.sf < 0.0)
2104 fault = Arithmetic_Fault;
2105 Fc.sf = sqrt(Fb.sf);
2106 }}, FloatSQRT);
2107 #endif
2108 0x2b: sqrtt({{
2109 if (Fb < 0.0)
2110 fault = Arithmetic_Fault;
2111 Fc = sqrt(Fb);
2112 }}, FloatSQRT);
2113 }
2114 }
2115 }
2116
2117 // VAX-format sqrtf and sqrtg are not implemented
2118 0xa: FailUnimpl::sqrtfg();
2119 }
2120
2121 // IEEE floating point
2122 0x16: decode FP_SHORTFUNC_TOP2 {
2123 // The top two bits of the short function code break this space
2124 // into four groups: binary ops, compares, reserved, and conversions.
2125 // See Table 4-12 of AHB.
2126 // Most of these instructions may have various trapping and
2127 // rounding mode flags set; these are decoded in the
2128 // FloatingPointDecode template used by the
2129 // FloatingPointOperate format.
2130
2131 // add/sub/mul/div: just decode on the short function code
2132 // and source type.
2133 0: decode FP_TYPEFUNC {
2134 format FloatingPointOperate {
2135 #ifdef SS_COMPATIBLE_FP
2136 0x00: adds({{ Fc = Fa + Fb; }});
2137 0x01: subs({{ Fc = Fa - Fb; }});
2138 0x02: muls({{ Fc = Fa * Fb; }}, FloatMULT);
2139 0x03: divs({{ Fc = Fa / Fb; }}, FloatDIV);
2140 #else
2141 0x00: adds({{ Fc.sf = Fa.sf + Fb.sf; }});
2142 0x01: subs({{ Fc.sf = Fa.sf - Fb.sf; }});
2143 0x02: muls({{ Fc.sf = Fa.sf * Fb.sf; }}, FloatMULT);
2144 0x03: divs({{ Fc.sf = Fa.sf / Fb.sf; }}, FloatDIV);
2145 #endif
2146
2147 0x20: addt({{ Fc = Fa + Fb; }});
2148 0x21: subt({{ Fc = Fa - Fb; }});
2149 0x22: mult({{ Fc = Fa * Fb; }}, FloatMULT);
2150 0x23: divt({{ Fc = Fa / Fb; }}, FloatDIV);
2151 }
2152 }
2153
2154 // Floating-point compare instructions must have the default
2155 // rounding mode, and may use the default trapping mode or
2156 // /SU. Both trapping modes are treated the same by M5; the
2157 // only difference on the real hardware (as far a I can tell)
2158 // is that without /SU you'd get an imprecise trap if you
2159 // tried to compare a NaN with something else (instead of an
2160 // "unordered" result).
2161 1: decode FP_FULLFUNC {
2162 format BasicOperateWithNopCheck {
2163 0x0a5, 0x5a5: cmpteq({{ Fc = (Fa == Fb) ? 2.0 : 0.0; }},
2164 FloatCMP);
2165 0x0a7, 0x5a7: cmptle({{ Fc = (Fa <= Fb) ? 2.0 : 0.0; }},
2166 FloatCMP);
2167 0x0a6, 0x5a6: cmptlt({{ Fc = (Fa < Fb) ? 2.0 : 0.0; }},
2168 FloatCMP);
2169 0x0a4, 0x5a4: cmptun({{ // unordered
2170 Fc = (!(Fa < Fb) && !(Fa == Fb) && !(Fa > Fb)) ? 2.0 : 0.0;
2171 }}, FloatCMP);
2172 }
2173 }
2174
2175 // The FP-to-integer and integer-to-FP conversion insts
2176 // require that FA be 31.
2177 3: decode FA {
2178 31: decode FP_TYPEFUNC {
2179 format FloatingPointOperate {
2180 0x2f: cvttq({{ Fc.sq = (int64_t)rint(Fb); }});
2181
2182 // The cvtts opcode is overloaded to be cvtst if the trap
2183 // mode is 2 or 6 (which are not valid otherwise)
2184 0x2c: decode FP_FULLFUNC {
2185 format BasicOperateWithNopCheck {
2186 // trap on denorm version "cvtst/s" is
2187 // simulated same as cvtst
2188 0x2ac, 0x6ac: cvtst({{ Fc = Fb.sf; }});
2189 }
2190 default: cvtts({{ Fc.sf = Fb; }});
2191 }
2192
2193 // The trapping mode for integer-to-FP conversions
2194 // must be /SUI or nothing; /U and /SU are not
2195 // allowed. The full set of rounding modes are
2196 // supported though.
2197 0x3c: decode FP_TRAPMODE {
2198 0,7: cvtqs({{ Fc.sf = Fb.sq; }});
2199 }
2200 0x3e: decode FP_TRAPMODE {
2201 0,7: cvtqt({{ Fc = Fb.sq; }});
2202 }
2203 }
2204 }
2205 }
2206 }
2207
2208 // misc FP operate
2209 0x17: decode FP_FULLFUNC {
2210 format BasicOperateWithNopCheck {
2211 0x010: cvtlq({{
2212 Fc.sl = (Fb.uq<63:62> << 30) | Fb.uq<58:29>;
2213 }});
2214 0x030: cvtql({{
2215 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
2216 }});
2217
2218 // We treat the precise & imprecise trapping versions of
2219 // cvtql identically.
2220 0x130, 0x530: cvtqlv({{
2221 // To avoid overflow, all the upper 32 bits must match
2222 // the sign bit of the lower 32. We code this as
2223 // checking the upper 33 bits for all 0s or all 1s.
2224 uint64_t sign_bits = Fb.uq<63:31>;
2225 if (sign_bits != 0 && sign_bits != mask(33))
2226 fault = Integer_Overflow_Fault;
2227 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
2228 }});
2229
2230 0x020: cpys({{ // copy sign
2231 Fc.uq = (Fa.uq<63:> << 63) | Fb.uq<62:0>;
2232 }});
2233 0x021: cpysn({{ // copy sign negated
2234 Fc.uq = (~Fa.uq<63:> << 63) | Fb.uq<62:0>;
2235 }});
2236 0x022: cpyse({{ // copy sign and exponent
2237 Fc.uq = (Fa.uq<63:52> << 52) | Fb.uq<51:0>;
2238 }});
2239
2240 0x02a: fcmoveq({{ Fc = (Fa == 0) ? Fb : Fc; }});
2241 0x02b: fcmovne({{ Fc = (Fa != 0) ? Fb : Fc; }});
2242 0x02c: fcmovlt({{ Fc = (Fa < 0) ? Fb : Fc; }});
2243 0x02d: fcmovge({{ Fc = (Fa >= 0) ? Fb : Fc; }});
2244 0x02e: fcmovle({{ Fc = (Fa <= 0) ? Fb : Fc; }});
2245 0x02f: fcmovgt({{ Fc = (Fa > 0) ? Fb : Fc; }});
2246
2247 0x024: mt_fpcr({{ FPCR = Fa.uq; }});
2248 0x025: mf_fpcr({{ Fa.uq = FPCR; }});
2249 }
2250 }
2251
2252 // miscellaneous mem-format ops
2253 0x18: decode MEMFUNC {
2254 format WarnUnimpl {
2255 0x8000: fetch();
2256 0xa000: fetch_m();
2257 0xe800: ecb();
2258 }
2259
2260 format MiscPrefetch {
2261 0xf800: wh64({{ EA = Rb; }},
2262 {{ xc->writeHint(EA, 64); }},
2263 IsMemRef, IsStore, WrPort);
2264 }
2265
2266 format BasicOperate {
2267 0xc000: rpcc({{
2268 #ifdef FULL_SYSTEM
2269 Ra = xc->readIpr(AlphaISA::IPR_CC, fault);
2270 #else
2271 Ra = curTick;
2272 #endif
2273 }});
2274
2275 // All of the barrier instructions below do nothing in
2276 // their execute() methods (hence the empty code blocks).
2277 // All of their functionality is hard-coded in the
2278 // pipeline based on the flags IsSerializing,
2279 // IsMemBarrier, and IsWriteBarrier. In the current
2280 // detailed CPU model, the execute() function only gets
2281 // called at fetch, so there's no way to generate pipeline
2282 // behavior at any other stage. Once we go to an
2283 // exec-in-exec CPU model we should be able to get rid of
2284 // these flags and implement this behavior via the
2285 // execute() methods.
2286
2287 // trapb is just a barrier on integer traps, where excb is
2288 // a barrier on integer and FP traps. "EXCB is thus a
2289 // superset of TRAPB." (Alpha ARM, Sec 4.11.4) We treat
2290 // them the same though.
2291 0x0000: trapb({{ }}, IsSerializing, No_OpClass);
2292 0x0400: excb({{ }}, IsSerializing, No_OpClass);
2293 0x4000: mb({{ }}, IsMemBarrier, RdPort);
2294 0x4400: wmb({{ }}, IsWriteBarrier, WrPort);
2295 }
2296
2297 #ifdef FULL_SYSTEM
2298 format BasicOperate {
2299 0xe000: rc({{
2300 Ra = xc->readIntrFlag();
2301 if (!xc->misspeculating()) {
2302 xc->setIntrFlag(0);
2303 }
2304 }});
2305 0xf000: rs({{
2306 Ra = xc->readIntrFlag();
2307 if (!xc->misspeculating()) {
2308 xc->setIntrFlag(1);
2309 }
2310 }});
2311 }
2312 #else
2313 format FailUnimpl {
2314 0xe000: rc();
2315 0xf000: rs();
2316 }
2317 #endif
2318 }
2319
2320 #ifdef FULL_SYSTEM
2321 0x00: CallPal::call_pal({{
2322 if (!palValid ||
2323 (palPriv
2324 && xc->readIpr(AlphaISA::IPR_ICM, fault) != AlphaISA::mode_kernel)) {
2325 // invalid pal function code, or attempt to do privileged
2326 // PAL call in non-kernel mode
2327 fault = Unimplemented_Opcode_Fault;
2328 }
2329 else {
2330 bool dopal = true;
2331
2332 if (!xc->misspeculating()) {
2333 // check to see if simulator wants to do something special
2334 // on this PAL call (including maybe suppress it)
2335 dopal = xc->simPalCheck(palFunc);
2336
2337 Annotate::Callpal(xc->xcBase(), palFunc);
2338
2339 if (dopal) {
2340 AlphaISA::swap_palshadow(&xc->xcBase()->regs, true);
2341 xc->setIpr(AlphaISA::IPR_EXC_ADDR, NPC);
2342 }
2343 }
2344
2345 // if we're misspeculating, it's still safe (if
2346 // unrealistic) to set NPC, as the control-flow change
2347 // won't get committed.
2348 if (dopal) {
2349 NPC = xc->readIpr(AlphaISA::IPR_PAL_BASE, fault) + palOffset;
2350 }
2351 }
2352 }});
2353 #else
2354 0x00: decode PALFUNC {
2355 format EmulatedCallPal {
2356 0x00: halt ({{
2357 if (!xc->misspeculating())
2358 SimExit(curTick, "halt instruction encountered");
2359 }});
2360 0x83: callsys({{
2361 if (!xc->misspeculating())
2362 xc->syscall();
2363 }});
2364 // Read uniq reg into ABI return value register (r0)
2365 0x9e: rduniq({{ R0 = Runiq; }});
2366 // Write uniq reg with value from ABI arg register (r16)
2367 0x9f: wruniq({{ Runiq = R16; }});
2368 }
2369 }
2370 #endif
2371
2372 #ifdef FULL_SYSTEM
2373 format HwLoadStore {
2374 0x1b: decode HW_LDST_QUAD {
2375 0: hw_ld({{ EA = (Rb + disp) & ~3; }}, {{ Ra = Mem.ul; }}, L);
2376 1: hw_ld({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }}, Q);
2377 }
2378
2379 0x1f: decode HW_LDST_COND {
2380 0: decode HW_LDST_QUAD {
2381 0: hw_st({{ EA = (Rb + disp) & ~3; }},
2382 {{ Mem.ul = Ra<31:0>; }}, L);
2383 1: hw_st({{ EA = (Rb + disp) & ~7; }},
2384 {{ Mem.uq = Ra.uq; }}, Q);
2385 }
2386
2387 1: FailUnimpl::hw_st_cond();
2388 }
2389 }
2390
2391 format BasicOperate {
2392 0x1e: hw_rei({{ xc->hwrei(); }});
2393
2394 // M5 special opcodes use the reserved 0x01 opcode space
2395 0x01: decode M5FUNC {
2396 0x00: arm({{
2397 if (!xc->misspeculating()) {
2398 Annotate::ARM(xc->xcBase());
2399 xc->xcBase()->kernelStats.arm();
2400 }
2401 }});
2402 0x01: quiesce({{
2403 if (!xc->misspeculating())
2404 AlphaPseudo::quiesce(xc->xcBase());
2405 }});
2406 0x10: ivlb({{
2407 if (!xc->misspeculating()) {
2408 Annotate::BeginInterval(xc->xcBase());
2409 xc->xcBase()->kernelStats.ivlb();
2410 }
2411 }}, No_OpClass);
2412 0x11: ivle({{
2413 if (!xc->misspeculating())
2414 Annotate::EndInterval(xc->xcBase());
2415 }}, No_OpClass);
2416 0x20: m5exit_old({{
2417 if (!xc->misspeculating())
2418 AlphaPseudo::m5exit_old(xc->xcBase());
2419 }}, No_OpClass);
2420 0x21: m5exit({{
2421 if (!xc->misspeculating())
2422 AlphaPseudo::m5exit(xc->xcBase());
2423 }}, No_OpClass);
2424 0x30: initparam({{ Ra = xc->xcBase()->cpu->system->init_param; }});
2425 0x40: resetstats({{
2426 if (!xc->misspeculating())
2427 AlphaPseudo::resetstats(xc->xcBase());
2428 }});
2429 0x41: dumpstats({{
2430 if (!xc->misspeculating())
2431 AlphaPseudo::dumpstats(xc->xcBase());
2432 }});
2433 0x42: dumpresetstats({{
2434 if (!xc->misspeculating())
2435 AlphaPseudo::dumpresetstats(xc->xcBase());
2436 }});
2437 0x43: m5checkpoint({{
2438 if (!xc->misspeculating())
2439 AlphaPseudo::m5checkpoint(xc->xcBase());
2440 }});
2441 }
2442 }
2443
2444 format HwMoveIPR {
2445 0x19: hw_mfpr({{
2446 // this instruction is only valid in PAL mode
2447 if (!xc->inPalMode()) {
2448 fault = Unimplemented_Opcode_Fault;
2449 }
2450 else {
2451 Ra = xc->readIpr(ipr_index, fault);
2452 }
2453 }});
2454 0x1d: hw_mtpr({{
2455 // this instruction is only valid in PAL mode
2456 if (!xc->inPalMode()) {
2457 fault = Unimplemented_Opcode_Fault;
2458 }
2459 else {
2460 xc->setIpr(ipr_index, Ra);
2461 if (traceData) { traceData->setData(Ra); }
2462 }
2463 }});
2464 }
2465 #endif
2466 }