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