Merge isabel.reinhardt.house:/z/stever/bk/m5-head
[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, IntAluOp)
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', 'NO_FAULT', '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', 'MemReadOp', 'NO_FAULT']
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, *flags) {{
1378 iop = InstObjParams(name, Name, 'EmulatedCallPal', CodeBlock(code), flags)
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, *flags) {{
1440 iop = InstObjParams(name, Name, 'CallPalBase', CodeBlock(code), flags)
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 // don't call execute() (which panics) if we're on a
1592 // speculative path
1593 flags[IsNonSpeculative] = true;
1594 }
1595
1596 %(BasicExecDeclare)s
1597
1598 std::string generateDisassembly(Addr pc, const SymbolTable *symtab);
1599 };
1600
1601 /**
1602 * Base class for unimplemented instructions that cause a warning
1603 * to be printed (but do not terminate simulation). This
1604 * implementation is a little screwy in that it will print a
1605 * warning for each instance of a particular unimplemented machine
1606 * instruction, not just for each unimplemented opcode. Should
1607 * probably make the 'warned' flag a static member of the derived
1608 * class.
1609 */
1610 class WarnUnimplemented : public AlphaStaticInst
1611 {
1612 private:
1613 /// Have we warned on this instruction yet?
1614 bool warned;
1615
1616 public:
1617 /// Constructor
1618 WarnUnimplemented(const char *_mnemonic, MachInst _machInst)
1619 : AlphaStaticInst(_mnemonic, _machInst, No_OpClass), warned(false)
1620 {
1621 // don't call execute() (which panics) if we're on a
1622 // speculative path
1623 flags[IsNonSpeculative] = true;
1624 }
1625
1626 %(BasicExecDeclare)s
1627
1628 std::string generateDisassembly(Addr pc, const SymbolTable *symtab);
1629 };
1630 }};
1631
1632 output decoder {{
1633 std::string
1634 FailUnimplemented::generateDisassembly(Addr pc, const SymbolTable *symtab)
1635 {
1636 return csprintf("%-10s (unimplemented)", mnemonic);
1637 }
1638
1639 std::string
1640 WarnUnimplemented::generateDisassembly(Addr pc, const SymbolTable *symtab)
1641 {
1642 #ifdef SS_COMPATIBLE_DISASSEMBLY
1643 return csprintf("%-10s", mnemonic);
1644 #else
1645 return csprintf("%-10s (unimplemented)", mnemonic);
1646 #endif
1647 }
1648 }};
1649
1650 output exec {{
1651 Fault
1652 FailUnimplemented::execute(%(CPU_exec_context)s *xc,
1653 Trace::InstRecord *traceData)
1654 {
1655 panic("attempt to execute unimplemented instruction '%s' "
1656 "(inst 0x%08x, opcode 0x%x)", mnemonic, machInst, OPCODE);
1657 return Unimplemented_Opcode_Fault;
1658 }
1659
1660 Fault
1661 WarnUnimplemented::execute(%(CPU_exec_context)s *xc,
1662 Trace::InstRecord *traceData)
1663 {
1664 if (!warned) {
1665 warn("instruction '%s' unimplemented\n", mnemonic);
1666 warned = true;
1667 }
1668
1669 return No_Fault;
1670 }
1671 }};
1672
1673
1674 def format FailUnimpl() {{
1675 iop = InstObjParams(name, 'FailUnimplemented')
1676 decode_block = BasicDecodeWithMnemonic.subst(iop)
1677 }};
1678
1679 def format WarnUnimpl() {{
1680 iop = InstObjParams(name, 'WarnUnimplemented')
1681 decode_block = BasicDecodeWithMnemonic.subst(iop)
1682 }};
1683
1684 output header {{
1685 /**
1686 * Static instruction class for unknown (illegal) instructions.
1687 * These cause simulator termination if they are executed in a
1688 * non-speculative mode. This is a leaf class.
1689 */
1690 class Unknown : public AlphaStaticInst
1691 {
1692 public:
1693 /// Constructor
1694 Unknown(MachInst _machInst)
1695 : AlphaStaticInst("unknown", _machInst, No_OpClass)
1696 {
1697 // don't call execute() (which panics) if we're on a
1698 // speculative path
1699 flags[IsNonSpeculative] = true;
1700 }
1701
1702 %(BasicExecDeclare)s
1703
1704 std::string generateDisassembly(Addr pc, const SymbolTable *symtab);
1705 };
1706 }};
1707
1708 ////////////////////////////////////////////////////////////////////
1709 //
1710 // Unknown instructions
1711 //
1712
1713 output decoder {{
1714 std::string
1715 Unknown::generateDisassembly(Addr pc, const SymbolTable *symtab)
1716 {
1717 return csprintf("%-10s (inst 0x%x, opcode 0x%x)",
1718 "unknown", machInst, OPCODE);
1719 }
1720 }};
1721
1722 output exec {{
1723 Fault
1724 Unknown::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData)
1725 {
1726 panic("attempt to execute unknown instruction "
1727 "(inst 0x%08x, opcode 0x%x)", machInst, OPCODE);
1728 return Unimplemented_Opcode_Fault;
1729 }
1730 }};
1731
1732 def format Unknown() {{
1733 decode_block = 'return new Unknown(machInst);\n'
1734 }};
1735
1736 ////////////////////////////////////////////////////////////////////
1737 //
1738 // Utility functions for execute methods
1739 //
1740
1741 output exec {{
1742
1743 /// Return opa + opb, summing carry into third arg.
1744 inline uint64_t
1745 addc(uint64_t opa, uint64_t opb, int &carry)
1746 {
1747 uint64_t res = opa + opb;
1748 if (res < opa || res < opb)
1749 ++carry;
1750 return res;
1751 }
1752
1753 /// Multiply two 64-bit values (opa * opb), returning the 128-bit
1754 /// product in res_hi and res_lo.
1755 inline void
1756 mul128(uint64_t opa, uint64_t opb, uint64_t &res_hi, uint64_t &res_lo)
1757 {
1758 // do a 64x64 --> 128 multiply using four 32x32 --> 64 multiplies
1759 uint64_t opa_hi = opa<63:32>;
1760 uint64_t opa_lo = opa<31:0>;
1761 uint64_t opb_hi = opb<63:32>;
1762 uint64_t opb_lo = opb<31:0>;
1763
1764 res_lo = opa_lo * opb_lo;
1765
1766 // The middle partial products logically belong in bit
1767 // positions 95 to 32. Thus the lower 32 bits of each product
1768 // sum into the upper 32 bits of the low result, while the
1769 // upper 32 sum into the low 32 bits of the upper result.
1770 uint64_t partial1 = opa_hi * opb_lo;
1771 uint64_t partial2 = opa_lo * opb_hi;
1772
1773 uint64_t partial1_lo = partial1<31:0> << 32;
1774 uint64_t partial1_hi = partial1<63:32>;
1775 uint64_t partial2_lo = partial2<31:0> << 32;
1776 uint64_t partial2_hi = partial2<63:32>;
1777
1778 // Add partial1_lo and partial2_lo to res_lo, keeping track
1779 // of any carries out
1780 int carry_out = 0;
1781 res_lo = addc(partial1_lo, res_lo, carry_out);
1782 res_lo = addc(partial2_lo, res_lo, carry_out);
1783
1784 // Now calculate the high 64 bits...
1785 res_hi = (opa_hi * opb_hi) + partial1_hi + partial2_hi + carry_out;
1786 }
1787
1788 /// Map 8-bit S-floating exponent to 11-bit T-floating exponent.
1789 /// See Table 2-2 of Alpha AHB.
1790 inline int
1791 map_s(int old_exp)
1792 {
1793 int hibit = old_exp<7:>;
1794 int lobits = old_exp<6:0>;
1795
1796 if (hibit == 1) {
1797 return (lobits == 0x7f) ? 0x7ff : (0x400 | lobits);
1798 }
1799 else {
1800 return (lobits == 0) ? 0 : (0x380 | lobits);
1801 }
1802 }
1803
1804 /// Convert a 32-bit S-floating value to the equivalent 64-bit
1805 /// representation to be stored in an FP reg.
1806 inline uint64_t
1807 s_to_t(uint32_t s_val)
1808 {
1809 uint64_t tmp = s_val;
1810 return (tmp<31:> << 63 // sign bit
1811 | (uint64_t)map_s(tmp<30:23>) << 52 // exponent
1812 | tmp<22:0> << 29); // fraction
1813 }
1814
1815 /// Convert a 64-bit T-floating value to the equivalent 32-bit
1816 /// S-floating representation to be stored in memory.
1817 inline int32_t
1818 t_to_s(uint64_t t_val)
1819 {
1820 return (t_val<63:62> << 30 // sign bit & hi exp bit
1821 | t_val<58:29>); // rest of exp & fraction
1822 }
1823 }};
1824
1825 ////////////////////////////////////////////////////////////////////
1826 //
1827 // The actual decoder specification
1828 //
1829
1830 decode OPCODE default Unknown::unknown() {
1831
1832 format LoadAddress {
1833 0x08: lda({{ Ra = Rb + disp; }});
1834 0x09: ldah({{ Ra = Rb + (disp << 16); }});
1835 }
1836
1837 format LoadOrNop {
1838 0x0a: ldbu({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.ub; }});
1839 0x0c: ldwu({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uw; }});
1840 0x0b: ldq_u({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }});
1841 0x23: ldt({{ EA = Rb + disp; }}, {{ Fa = Mem.df; }});
1842 0x2a: ldl_l({{ EA = Rb + disp; }}, {{ Ra.sl = Mem.sl; }}, LOCKED);
1843 0x2b: ldq_l({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uq; }}, LOCKED);
1844 0x20: copy_load({{EA = Ra;}},
1845 {{ fault = xc->copySrcTranslate(EA);}},
1846 IsMemRef, IsLoad, IsCopy);
1847 }
1848
1849 format LoadOrPrefetch {
1850 0x28: ldl({{ EA = Rb + disp; }}, {{ Ra.sl = Mem.sl; }});
1851 0x29: ldq({{ EA = Rb + disp; }}, {{ Ra.uq = Mem.uq; }}, EVICT_NEXT);
1852 // IsFloating flag on lds gets the prefetch to disassemble
1853 // using f31 instead of r31... funcitonally it's unnecessary
1854 0x22: lds({{ EA = Rb + disp; }}, {{ Fa.uq = s_to_t(Mem.ul); }},
1855 PF_EXCLUSIVE, IsFloating);
1856 }
1857
1858 format Store {
1859 0x0e: stb({{ EA = Rb + disp; }}, {{ Mem.ub = Ra<7:0>; }});
1860 0x0d: stw({{ EA = Rb + disp; }}, {{ Mem.uw = Ra<15:0>; }});
1861 0x2c: stl({{ EA = Rb + disp; }}, {{ Mem.ul = Ra<31:0>; }});
1862 0x2d: stq({{ EA = Rb + disp; }}, {{ Mem.uq = Ra.uq; }});
1863 0x0f: stq_u({{ EA = (Rb + disp) & ~7; }}, {{ Mem.uq = Ra.uq; }});
1864 0x26: sts({{ EA = Rb + disp; }}, {{ Mem.ul = t_to_s(Fa.uq); }});
1865 0x27: stt({{ EA = Rb + disp; }}, {{ Mem.df = Fa; }});
1866 0x24: copy_store({{EA = Rb;}},
1867 {{ fault = xc->copy(EA);}},
1868 IsMemRef, IsStore, IsCopy);
1869 }
1870
1871 format StoreCond {
1872 0x2e: stl_c({{ EA = Rb + disp; }}, {{ Mem.ul = Ra<31:0>; }},
1873 {{
1874 uint64_t tmp = Mem_write_result;
1875 // see stq_c
1876 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
1877 }}, LOCKED);
1878 0x2f: stq_c({{ EA = Rb + disp; }}, {{ Mem.uq = Ra; }},
1879 {{
1880 uint64_t tmp = Mem_write_result;
1881 // If the write operation returns 0 or 1, then
1882 // this was a conventional store conditional,
1883 // and the value indicates the success/failure
1884 // of the operation. If another value is
1885 // returned, then this was a Turbolaser
1886 // mailbox access, and we don't update the
1887 // result register at all.
1888 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
1889 }}, LOCKED);
1890 }
1891
1892 format IntegerOperate {
1893
1894 0x10: decode INTFUNC { // integer arithmetic operations
1895
1896 0x00: addl({{ Rc.sl = Ra.sl + Rb_or_imm.sl; }});
1897 0x40: addlv({{
1898 uint32_t tmp = Ra.sl + Rb_or_imm.sl;
1899 // signed overflow occurs when operands have same sign
1900 // and sign of result does not match.
1901 if (Ra.sl<31:> == Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
1902 fault = Integer_Overflow_Fault;
1903 Rc.sl = tmp;
1904 }});
1905 0x02: s4addl({{ Rc.sl = (Ra.sl << 2) + Rb_or_imm.sl; }});
1906 0x12: s8addl({{ Rc.sl = (Ra.sl << 3) + Rb_or_imm.sl; }});
1907
1908 0x20: addq({{ Rc = Ra + Rb_or_imm; }});
1909 0x60: addqv({{
1910 uint64_t tmp = Ra + Rb_or_imm;
1911 // signed overflow occurs when operands have same sign
1912 // and sign of result does not match.
1913 if (Ra<63:> == Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
1914 fault = Integer_Overflow_Fault;
1915 Rc = tmp;
1916 }});
1917 0x22: s4addq({{ Rc = (Ra << 2) + Rb_or_imm; }});
1918 0x32: s8addq({{ Rc = (Ra << 3) + Rb_or_imm; }});
1919
1920 0x09: subl({{ Rc.sl = Ra.sl - Rb_or_imm.sl; }});
1921 0x49: sublv({{
1922 uint32_t tmp = Ra.sl - Rb_or_imm.sl;
1923 // signed overflow detection is same as for add,
1924 // except we need to look at the *complemented*
1925 // sign bit of the subtrahend (Rb), i.e., if the initial
1926 // signs are the *same* then no overflow can occur
1927 if (Ra.sl<31:> != Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
1928 fault = Integer_Overflow_Fault;
1929 Rc.sl = tmp;
1930 }});
1931 0x0b: s4subl({{ Rc.sl = (Ra.sl << 2) - Rb_or_imm.sl; }});
1932 0x1b: s8subl({{ Rc.sl = (Ra.sl << 3) - Rb_or_imm.sl; }});
1933
1934 0x29: subq({{ Rc = Ra - Rb_or_imm; }});
1935 0x69: subqv({{
1936 uint64_t tmp = Ra - Rb_or_imm;
1937 // signed overflow detection is same as for add,
1938 // except we need to look at the *complemented*
1939 // sign bit of the subtrahend (Rb), i.e., if the initial
1940 // signs are the *same* then no overflow can occur
1941 if (Ra<63:> != Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
1942 fault = Integer_Overflow_Fault;
1943 Rc = tmp;
1944 }});
1945 0x2b: s4subq({{ Rc = (Ra << 2) - Rb_or_imm; }});
1946 0x3b: s8subq({{ Rc = (Ra << 3) - Rb_or_imm; }});
1947
1948 0x2d: cmpeq({{ Rc = (Ra == Rb_or_imm); }});
1949 0x6d: cmple({{ Rc = (Ra.sq <= Rb_or_imm.sq); }});
1950 0x4d: cmplt({{ Rc = (Ra.sq < Rb_or_imm.sq); }});
1951 0x3d: cmpule({{ Rc = (Ra.uq <= Rb_or_imm.uq); }});
1952 0x1d: cmpult({{ Rc = (Ra.uq < Rb_or_imm.uq); }});
1953
1954 0x0f: cmpbge({{
1955 int hi = 7;
1956 int lo = 0;
1957 uint64_t tmp = 0;
1958 for (int i = 0; i < 8; ++i) {
1959 tmp |= (Ra.uq<hi:lo> >= Rb_or_imm.uq<hi:lo>) << i;
1960 hi += 8;
1961 lo += 8;
1962 }
1963 Rc = tmp;
1964 }});
1965 }
1966
1967 0x11: decode INTFUNC { // integer logical operations
1968
1969 0x00: and({{ Rc = Ra & Rb_or_imm; }});
1970 0x08: bic({{ Rc = Ra & ~Rb_or_imm; }});
1971 0x20: bis({{ Rc = Ra | Rb_or_imm; }});
1972 0x28: ornot({{ Rc = Ra | ~Rb_or_imm; }});
1973 0x40: xor({{ Rc = Ra ^ Rb_or_imm; }});
1974 0x48: eqv({{ Rc = Ra ^ ~Rb_or_imm; }});
1975
1976 // conditional moves
1977 0x14: cmovlbs({{ Rc = ((Ra & 1) == 1) ? Rb_or_imm : Rc; }});
1978 0x16: cmovlbc({{ Rc = ((Ra & 1) == 0) ? Rb_or_imm : Rc; }});
1979 0x24: cmoveq({{ Rc = (Ra == 0) ? Rb_or_imm : Rc; }});
1980 0x26: cmovne({{ Rc = (Ra != 0) ? Rb_or_imm : Rc; }});
1981 0x44: cmovlt({{ Rc = (Ra.sq < 0) ? Rb_or_imm : Rc; }});
1982 0x46: cmovge({{ Rc = (Ra.sq >= 0) ? Rb_or_imm : Rc; }});
1983 0x64: cmovle({{ Rc = (Ra.sq <= 0) ? Rb_or_imm : Rc; }});
1984 0x66: cmovgt({{ Rc = (Ra.sq > 0) ? Rb_or_imm : Rc; }});
1985
1986 // For AMASK, RA must be R31.
1987 0x61: decode RA {
1988 31: amask({{ Rc = Rb_or_imm & ~ULL(0x17); }});
1989 }
1990
1991 // For IMPLVER, RA must be R31 and the B operand
1992 // must be the immediate value 1.
1993 0x6c: decode RA {
1994 31: decode IMM {
1995 1: decode INTIMM {
1996 // return EV5 for FULL_SYSTEM and EV6 otherwise
1997 1: implver({{
1998 #ifdef FULL_SYSTEM
1999 Rc = 1;
2000 #else
2001 Rc = 2;
2002 #endif
2003 }});
2004 }
2005 }
2006 }
2007
2008 #ifdef FULL_SYSTEM
2009 // The mysterious 11.25...
2010 0x25: WarnUnimpl::eleven25();
2011 #endif
2012 }
2013
2014 0x12: decode INTFUNC {
2015 0x39: sll({{ Rc = Ra << Rb_or_imm<5:0>; }});
2016 0x34: srl({{ Rc = Ra.uq >> Rb_or_imm<5:0>; }});
2017 0x3c: sra({{ Rc = Ra.sq >> Rb_or_imm<5:0>; }});
2018
2019 0x02: mskbl({{ Rc = Ra & ~(mask( 8) << (Rb_or_imm<2:0> * 8)); }});
2020 0x12: mskwl({{ Rc = Ra & ~(mask(16) << (Rb_or_imm<2:0> * 8)); }});
2021 0x22: mskll({{ Rc = Ra & ~(mask(32) << (Rb_or_imm<2:0> * 8)); }});
2022 0x32: mskql({{ Rc = Ra & ~(mask(64) << (Rb_or_imm<2:0> * 8)); }});
2023
2024 0x52: mskwh({{
2025 int bv = Rb_or_imm<2:0>;
2026 Rc = bv ? (Ra & ~(mask(16) >> (64 - 8 * bv))) : Ra;
2027 }});
2028 0x62: msklh({{
2029 int bv = Rb_or_imm<2:0>;
2030 Rc = bv ? (Ra & ~(mask(32) >> (64 - 8 * bv))) : Ra;
2031 }});
2032 0x72: mskqh({{
2033 int bv = Rb_or_imm<2:0>;
2034 Rc = bv ? (Ra & ~(mask(64) >> (64 - 8 * bv))) : Ra;
2035 }});
2036
2037 0x06: extbl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))< 7:0>; }});
2038 0x16: extwl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<15:0>; }});
2039 0x26: extll({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<31:0>; }});
2040 0x36: extql({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8)); }});
2041
2042 0x5a: extwh({{
2043 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<15:0>; }});
2044 0x6a: extlh({{
2045 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<31:0>; }});
2046 0x7a: extqh({{
2047 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>); }});
2048
2049 0x0b: insbl({{ Rc = Ra< 7:0> << (Rb_or_imm<2:0> * 8); }});
2050 0x1b: inswl({{ Rc = Ra<15:0> << (Rb_or_imm<2:0> * 8); }});
2051 0x2b: insll({{ Rc = Ra<31:0> << (Rb_or_imm<2:0> * 8); }});
2052 0x3b: insql({{ Rc = Ra << (Rb_or_imm<2:0> * 8); }});
2053
2054 0x57: inswh({{
2055 int bv = Rb_or_imm<2:0>;
2056 Rc = bv ? (Ra.uq<15:0> >> (64 - 8 * bv)) : 0;
2057 }});
2058 0x67: inslh({{
2059 int bv = Rb_or_imm<2:0>;
2060 Rc = bv ? (Ra.uq<31:0> >> (64 - 8 * bv)) : 0;
2061 }});
2062 0x77: insqh({{
2063 int bv = Rb_or_imm<2:0>;
2064 Rc = bv ? (Ra.uq >> (64 - 8 * bv)) : 0;
2065 }});
2066
2067 0x30: zap({{
2068 uint64_t zapmask = 0;
2069 for (int i = 0; i < 8; ++i) {
2070 if (Rb_or_imm<i:>)
2071 zapmask |= (mask(8) << (i * 8));
2072 }
2073 Rc = Ra & ~zapmask;
2074 }});
2075 0x31: zapnot({{
2076 uint64_t zapmask = 0;
2077 for (int i = 0; i < 8; ++i) {
2078 if (!Rb_or_imm<i:>)
2079 zapmask |= (mask(8) << (i * 8));
2080 }
2081 Rc = Ra & ~zapmask;
2082 }});
2083 }
2084
2085 0x13: decode INTFUNC { // integer multiplies
2086 0x00: mull({{ Rc.sl = Ra.sl * Rb_or_imm.sl; }}, IntMultOp);
2087 0x20: mulq({{ Rc = Ra * Rb_or_imm; }}, IntMultOp);
2088 0x30: umulh({{
2089 uint64_t hi, lo;
2090 mul128(Ra, Rb_or_imm, hi, lo);
2091 Rc = hi;
2092 }}, IntMultOp);
2093 0x40: mullv({{
2094 // 32-bit multiply with trap on overflow
2095 int64_t Rax = Ra.sl; // sign extended version of Ra.sl
2096 int64_t Rbx = Rb_or_imm.sl;
2097 int64_t tmp = Rax * Rbx;
2098 // To avoid overflow, all the upper 32 bits must match
2099 // the sign bit of the lower 32. We code this as
2100 // checking the upper 33 bits for all 0s or all 1s.
2101 uint64_t sign_bits = tmp<63:31>;
2102 if (sign_bits != 0 && sign_bits != mask(33))
2103 fault = Integer_Overflow_Fault;
2104 Rc.sl = tmp<31:0>;
2105 }}, IntMultOp);
2106 0x60: mulqv({{
2107 // 64-bit multiply with trap on overflow
2108 uint64_t hi, lo;
2109 mul128(Ra, Rb_or_imm, hi, lo);
2110 // all the upper 64 bits must match the sign bit of
2111 // the lower 64
2112 if (!((hi == 0 && lo<63:> == 0) ||
2113 (hi == mask(64) && lo<63:> == 1)))
2114 fault = Integer_Overflow_Fault;
2115 Rc = lo;
2116 }}, IntMultOp);
2117 }
2118
2119 0x1c: decode INTFUNC {
2120 0x00: decode RA { 31: sextb({{ Rc.sb = Rb_or_imm< 7:0>; }}); }
2121 0x01: decode RA { 31: sextw({{ Rc.sw = Rb_or_imm<15:0>; }}); }
2122
2123 format FailUnimpl {
2124 0x30: ctpop();
2125 0x31: perr();
2126 0x32: ctlz();
2127 0x33: cttz();
2128 0x34: unpkbw();
2129 0x35: unpkbl();
2130 0x36: pkwb();
2131 0x37: pklb();
2132 0x38: minsb8();
2133 0x39: minsw4();
2134 0x3a: minub8();
2135 0x3b: minuw4();
2136 0x3c: maxub8();
2137 0x3d: maxuw4();
2138 0x3e: maxsb8();
2139 0x3f: maxsw4();
2140 }
2141
2142 format BasicOperateWithNopCheck {
2143 0x70: decode RB {
2144 31: ftoit({{ Rc = Fa.uq; }}, FloatCvtOp);
2145 }
2146 0x78: decode RB {
2147 31: ftois({{ Rc.sl = t_to_s(Fa.uq); }},
2148 FloatCvtOp);
2149 }
2150 }
2151 }
2152 }
2153
2154 // Conditional branches.
2155 format CondBranch {
2156 0x39: beq({{ cond = (Ra == 0); }});
2157 0x3d: bne({{ cond = (Ra != 0); }});
2158 0x3e: bge({{ cond = (Ra.sq >= 0); }});
2159 0x3f: bgt({{ cond = (Ra.sq > 0); }});
2160 0x3b: ble({{ cond = (Ra.sq <= 0); }});
2161 0x3a: blt({{ cond = (Ra.sq < 0); }});
2162 0x38: blbc({{ cond = ((Ra & 1) == 0); }});
2163 0x3c: blbs({{ cond = ((Ra & 1) == 1); }});
2164
2165 0x31: fbeq({{ cond = (Fa == 0); }});
2166 0x35: fbne({{ cond = (Fa != 0); }});
2167 0x36: fbge({{ cond = (Fa >= 0); }});
2168 0x37: fbgt({{ cond = (Fa > 0); }});
2169 0x33: fble({{ cond = (Fa <= 0); }});
2170 0x32: fblt({{ cond = (Fa < 0); }});
2171 }
2172
2173 // unconditional branches
2174 format UncondBranch {
2175 0x30: br();
2176 0x34: bsr(IsCall);
2177 }
2178
2179 // indirect branches
2180 0x1a: decode JMPFUNC {
2181 format Jump {
2182 0: jmp();
2183 1: jsr(IsCall);
2184 2: ret(IsReturn);
2185 3: jsr_coroutine(IsCall, IsReturn);
2186 }
2187 }
2188
2189 // IEEE floating point
2190 0x14: decode FP_SHORTFUNC {
2191 // Integer to FP register moves must have RB == 31
2192 0x4: decode RB {
2193 31: decode FP_FULLFUNC {
2194 format BasicOperateWithNopCheck {
2195 0x004: itofs({{ Fc.uq = s_to_t(Ra.ul); }}, FloatCvtOp);
2196 0x024: itoft({{ Fc.uq = Ra.uq; }}, FloatCvtOp);
2197 0x014: FailUnimpl::itoff(); // VAX-format conversion
2198 }
2199 }
2200 }
2201
2202 // Square root instructions must have FA == 31
2203 0xb: decode FA {
2204 31: decode FP_TYPEFUNC {
2205 format FloatingPointOperate {
2206 #ifdef SS_COMPATIBLE_FP
2207 0x0b: sqrts({{
2208 if (Fb < 0.0)
2209 fault = Arithmetic_Fault;
2210 Fc = sqrt(Fb);
2211 }}, FloatSqrtOp);
2212 #else
2213 0x0b: sqrts({{
2214 if (Fb.sf < 0.0)
2215 fault = Arithmetic_Fault;
2216 Fc.sf = sqrt(Fb.sf);
2217 }}, FloatSqrtOp);
2218 #endif
2219 0x2b: sqrtt({{
2220 if (Fb < 0.0)
2221 fault = Arithmetic_Fault;
2222 Fc = sqrt(Fb);
2223 }}, FloatSqrtOp);
2224 }
2225 }
2226 }
2227
2228 // VAX-format sqrtf and sqrtg are not implemented
2229 0xa: FailUnimpl::sqrtfg();
2230 }
2231
2232 // IEEE floating point
2233 0x16: decode FP_SHORTFUNC_TOP2 {
2234 // The top two bits of the short function code break this space
2235 // into four groups: binary ops, compares, reserved, and conversions.
2236 // See Table 4-12 of AHB.
2237 // Most of these instructions may have various trapping and
2238 // rounding mode flags set; these are decoded in the
2239 // FloatingPointDecode template used by the
2240 // FloatingPointOperate format.
2241
2242 // add/sub/mul/div: just decode on the short function code
2243 // and source type.
2244 0: decode FP_TYPEFUNC {
2245 format FloatingPointOperate {
2246 #ifdef SS_COMPATIBLE_FP
2247 0x00: adds({{ Fc = Fa + Fb; }});
2248 0x01: subs({{ Fc = Fa - Fb; }});
2249 0x02: muls({{ Fc = Fa * Fb; }}, FloatMultOp);
2250 0x03: divs({{ Fc = Fa / Fb; }}, FloatDivOp);
2251 #else
2252 0x00: adds({{ Fc.sf = Fa.sf + Fb.sf; }});
2253 0x01: subs({{ Fc.sf = Fa.sf - Fb.sf; }});
2254 0x02: muls({{ Fc.sf = Fa.sf * Fb.sf; }}, FloatMultOp);
2255 0x03: divs({{ Fc.sf = Fa.sf / Fb.sf; }}, FloatDivOp);
2256 #endif
2257
2258 0x20: addt({{ Fc = Fa + Fb; }});
2259 0x21: subt({{ Fc = Fa - Fb; }});
2260 0x22: mult({{ Fc = Fa * Fb; }}, FloatMultOp);
2261 0x23: divt({{ Fc = Fa / Fb; }}, FloatDivOp);
2262 }
2263 }
2264
2265 // Floating-point compare instructions must have the default
2266 // rounding mode, and may use the default trapping mode or
2267 // /SU. Both trapping modes are treated the same by M5; the
2268 // only difference on the real hardware (as far a I can tell)
2269 // is that without /SU you'd get an imprecise trap if you
2270 // tried to compare a NaN with something else (instead of an
2271 // "unordered" result).
2272 1: decode FP_FULLFUNC {
2273 format BasicOperateWithNopCheck {
2274 0x0a5, 0x5a5: cmpteq({{ Fc = (Fa == Fb) ? 2.0 : 0.0; }},
2275 FloatCmpOp);
2276 0x0a7, 0x5a7: cmptle({{ Fc = (Fa <= Fb) ? 2.0 : 0.0; }},
2277 FloatCmpOp);
2278 0x0a6, 0x5a6: cmptlt({{ Fc = (Fa < Fb) ? 2.0 : 0.0; }},
2279 FloatCmpOp);
2280 0x0a4, 0x5a4: cmptun({{ // unordered
2281 Fc = (!(Fa < Fb) && !(Fa == Fb) && !(Fa > Fb)) ? 2.0 : 0.0;
2282 }}, FloatCmpOp);
2283 }
2284 }
2285
2286 // The FP-to-integer and integer-to-FP conversion insts
2287 // require that FA be 31.
2288 3: decode FA {
2289 31: decode FP_TYPEFUNC {
2290 format FloatingPointOperate {
2291 0x2f: cvttq({{ Fc.sq = (int64_t)rint(Fb); }});
2292
2293 // The cvtts opcode is overloaded to be cvtst if the trap
2294 // mode is 2 or 6 (which are not valid otherwise)
2295 0x2c: decode FP_FULLFUNC {
2296 format BasicOperateWithNopCheck {
2297 // trap on denorm version "cvtst/s" is
2298 // simulated same as cvtst
2299 0x2ac, 0x6ac: cvtst({{ Fc = Fb.sf; }});
2300 }
2301 default: cvtts({{ Fc.sf = Fb; }});
2302 }
2303
2304 // The trapping mode for integer-to-FP conversions
2305 // must be /SUI or nothing; /U and /SU are not
2306 // allowed. The full set of rounding modes are
2307 // supported though.
2308 0x3c: decode FP_TRAPMODE {
2309 0,7: cvtqs({{ Fc.sf = Fb.sq; }});
2310 }
2311 0x3e: decode FP_TRAPMODE {
2312 0,7: cvtqt({{ Fc = Fb.sq; }});
2313 }
2314 }
2315 }
2316 }
2317 }
2318
2319 // misc FP operate
2320 0x17: decode FP_FULLFUNC {
2321 format BasicOperateWithNopCheck {
2322 0x010: cvtlq({{
2323 Fc.sl = (Fb.uq<63:62> << 30) | Fb.uq<58:29>;
2324 }});
2325 0x030: cvtql({{
2326 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
2327 }});
2328
2329 // We treat the precise & imprecise trapping versions of
2330 // cvtql identically.
2331 0x130, 0x530: cvtqlv({{
2332 // To avoid overflow, all the upper 32 bits must match
2333 // the sign bit of the lower 32. We code this as
2334 // checking the upper 33 bits for all 0s or all 1s.
2335 uint64_t sign_bits = Fb.uq<63:31>;
2336 if (sign_bits != 0 && sign_bits != mask(33))
2337 fault = Integer_Overflow_Fault;
2338 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
2339 }});
2340
2341 0x020: cpys({{ // copy sign
2342 Fc.uq = (Fa.uq<63:> << 63) | Fb.uq<62:0>;
2343 }});
2344 0x021: cpysn({{ // copy sign negated
2345 Fc.uq = (~Fa.uq<63:> << 63) | Fb.uq<62:0>;
2346 }});
2347 0x022: cpyse({{ // copy sign and exponent
2348 Fc.uq = (Fa.uq<63:52> << 52) | Fb.uq<51:0>;
2349 }});
2350
2351 0x02a: fcmoveq({{ Fc = (Fa == 0) ? Fb : Fc; }});
2352 0x02b: fcmovne({{ Fc = (Fa != 0) ? Fb : Fc; }});
2353 0x02c: fcmovlt({{ Fc = (Fa < 0) ? Fb : Fc; }});
2354 0x02d: fcmovge({{ Fc = (Fa >= 0) ? Fb : Fc; }});
2355 0x02e: fcmovle({{ Fc = (Fa <= 0) ? Fb : Fc; }});
2356 0x02f: fcmovgt({{ Fc = (Fa > 0) ? Fb : Fc; }});
2357
2358 0x024: mt_fpcr({{ FPCR = Fa.uq; }});
2359 0x025: mf_fpcr({{ Fa.uq = FPCR; }});
2360 }
2361 }
2362
2363 // miscellaneous mem-format ops
2364 0x18: decode MEMFUNC {
2365 format WarnUnimpl {
2366 0x8000: fetch();
2367 0xa000: fetch_m();
2368 0xe800: ecb();
2369 }
2370
2371 format MiscPrefetch {
2372 0xf800: wh64({{ EA = Rb & ~ULL(63); }},
2373 {{ xc->writeHint(EA, 64, memAccessFlags); }},
2374 IsMemRef, IsDataPrefetch, IsStore, MemWriteOp,
2375 NO_FAULT);
2376 }
2377
2378 format BasicOperate {
2379 0xc000: rpcc({{
2380 #ifdef FULL_SYSTEM
2381 Ra = xc->readIpr(AlphaISA::IPR_CC, fault);
2382 #else
2383 Ra = curTick;
2384 #endif
2385 }});
2386
2387 // All of the barrier instructions below do nothing in
2388 // their execute() methods (hence the empty code blocks).
2389 // All of their functionality is hard-coded in the
2390 // pipeline based on the flags IsSerializing,
2391 // IsMemBarrier, and IsWriteBarrier. In the current
2392 // detailed CPU model, the execute() function only gets
2393 // called at fetch, so there's no way to generate pipeline
2394 // behavior at any other stage. Once we go to an
2395 // exec-in-exec CPU model we should be able to get rid of
2396 // these flags and implement this behavior via the
2397 // execute() methods.
2398
2399 // trapb is just a barrier on integer traps, where excb is
2400 // a barrier on integer and FP traps. "EXCB is thus a
2401 // superset of TRAPB." (Alpha ARM, Sec 4.11.4) We treat
2402 // them the same though.
2403 0x0000: trapb({{ }}, IsSerializing, No_OpClass);
2404 0x0400: excb({{ }}, IsSerializing, No_OpClass);
2405 0x4000: mb({{ }}, IsMemBarrier, MemReadOp);
2406 0x4400: wmb({{ }}, IsWriteBarrier, MemWriteOp);
2407 }
2408
2409 #ifdef FULL_SYSTEM
2410 format BasicOperate {
2411 0xe000: rc({{
2412 Ra = xc->readIntrFlag();
2413 xc->setIntrFlag(0);
2414 }}, IsNonSpeculative);
2415 0xf000: rs({{
2416 Ra = xc->readIntrFlag();
2417 xc->setIntrFlag(1);
2418 }}, IsNonSpeculative);
2419 }
2420 #else
2421 format FailUnimpl {
2422 0xe000: rc();
2423 0xf000: rs();
2424 }
2425 #endif
2426 }
2427
2428 #ifdef FULL_SYSTEM
2429 0x00: CallPal::call_pal({{
2430 if (!palValid ||
2431 (palPriv
2432 && xc->readIpr(AlphaISA::IPR_ICM, fault) != AlphaISA::mode_kernel)) {
2433 // invalid pal function code, or attempt to do privileged
2434 // PAL call in non-kernel mode
2435 fault = Unimplemented_Opcode_Fault;
2436 }
2437 else {
2438 // check to see if simulator wants to do something special
2439 // on this PAL call (including maybe suppress it)
2440 bool dopal = xc->simPalCheck(palFunc);
2441
2442 if (dopal) {
2443 AlphaISA::swap_palshadow(&xc->xcBase()->regs, true);
2444 xc->setIpr(AlphaISA::IPR_EXC_ADDR, NPC);
2445 NPC = xc->readIpr(AlphaISA::IPR_PAL_BASE, fault) + palOffset;
2446 }
2447 }
2448 }}, IsNonSpeculative);
2449 #else
2450 0x00: decode PALFUNC {
2451 format EmulatedCallPal {
2452 0x00: halt ({{
2453 SimExit(curTick, "halt instruction encountered");
2454 }}, IsNonSpeculative);
2455 0x83: callsys({{
2456 xc->syscall();
2457 }}, IsNonSpeculative);
2458 // Read uniq reg into ABI return value register (r0)
2459 0x9e: rduniq({{ R0 = Runiq; }});
2460 // Write uniq reg with value from ABI arg register (r16)
2461 0x9f: wruniq({{ Runiq = R16; }});
2462 }
2463 }
2464 #endif
2465
2466 #ifdef FULL_SYSTEM
2467 format HwLoadStore {
2468 0x1b: decode HW_LDST_QUAD {
2469 0: hw_ld({{ EA = (Rb + disp) & ~3; }}, {{ Ra = Mem.ul; }}, L);
2470 1: hw_ld({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }}, Q);
2471 }
2472
2473 0x1f: decode HW_LDST_COND {
2474 0: decode HW_LDST_QUAD {
2475 0: hw_st({{ EA = (Rb + disp) & ~3; }},
2476 {{ Mem.ul = Ra<31:0>; }}, L);
2477 1: hw_st({{ EA = (Rb + disp) & ~7; }},
2478 {{ Mem.uq = Ra.uq; }}, Q);
2479 }
2480
2481 1: FailUnimpl::hw_st_cond();
2482 }
2483 }
2484
2485 format BasicOperate {
2486 0x1e: hw_rei({{ xc->hwrei(); }});
2487
2488 // M5 special opcodes use the reserved 0x01 opcode space
2489 0x01: decode M5FUNC {
2490 0x00: arm({{
2491 AlphaPseudo::arm(xc->xcBase());
2492 }}, IsNonSpeculative);
2493 0x01: quiesce({{
2494 AlphaPseudo::quiesce(xc->xcBase());
2495 }}, IsNonSpeculative);
2496 0x10: ivlb({{
2497 AlphaPseudo::ivlb(xc->xcBase());
2498 }}, No_OpClass, IsNonSpeculative);
2499 0x11: ivle({{
2500 AlphaPseudo::ivle(xc->xcBase());
2501 }}, No_OpClass, IsNonSpeculative);
2502 0x20: m5exit_old({{
2503 AlphaPseudo::m5exit_old(xc->xcBase());
2504 }}, No_OpClass, IsNonSpeculative);
2505 0x21: m5exit({{
2506 AlphaPseudo::m5exit(xc->xcBase());
2507 }}, No_OpClass, IsNonSpeculative);
2508 0x30: initparam({{ Ra = xc->xcBase()->cpu->system->init_param; }});
2509 0x40: resetstats({{
2510 AlphaPseudo::resetstats(xc->xcBase());
2511 }}, IsNonSpeculative);
2512 0x41: dumpstats({{
2513 AlphaPseudo::dumpstats(xc->xcBase());
2514 }}, IsNonSpeculative);
2515 0x42: dumpresetstats({{
2516 AlphaPseudo::dumpresetstats(xc->xcBase());
2517 }}, IsNonSpeculative);
2518 0x43: m5checkpoint({{
2519 AlphaPseudo::m5checkpoint(xc->xcBase());
2520 }}, IsNonSpeculative);
2521 }
2522 }
2523
2524 format HwMoveIPR {
2525 0x19: hw_mfpr({{
2526 // this instruction is only valid in PAL mode
2527 if (!xc->inPalMode()) {
2528 fault = Unimplemented_Opcode_Fault;
2529 }
2530 else {
2531 Ra = xc->readIpr(ipr_index, fault);
2532 }
2533 }});
2534 0x1d: hw_mtpr({{
2535 // this instruction is only valid in PAL mode
2536 if (!xc->inPalMode()) {
2537 fault = Unimplemented_Opcode_Fault;
2538 }
2539 else {
2540 xc->setIpr(ipr_index, Ra);
2541 if (traceData) { traceData->setData(Ra); }
2542 }
2543 }});
2544 }
2545 #endif
2546 }