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