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