decoder.isa revision 2312
1// -*- mode:c++ -*-
2
3// Copyright (c) 2003-2006 The Regents of The University of Michigan
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met: redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer;
10// redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution;
13// neither the name of the copyright holders nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29decode OPCODE default Unknown::unknown() {
30
31    format LoadAddress {
32        0x08: lda({{ Ra = Rb + disp; }});
33        0x09: ldah({{ Ra = Rb + (disp << 16); }});
34    }
35
36    format LoadOrNop {
37        0x0a: ldbu({{ Ra.uq = Mem.ub; }});
38        0x0c: ldwu({{ Ra.uq = Mem.uw; }});
39        0x0b: ldq_u({{ Ra = Mem.uq; }}, ea_code = {{ EA = (Rb + disp) & ~7; }});
40        0x23: ldt({{ Fa = Mem.df; }});
41        0x2a: ldl_l({{ Ra.sl = Mem.sl; }}, mem_flags = LOCKED);
42        0x2b: ldq_l({{ Ra.uq = Mem.uq; }}, mem_flags = LOCKED);
43        0x20: MiscPrefetch::copy_load({{ EA = Ra; }},
44                                      {{ fault = xc->copySrcTranslate(EA); }},
45                                      inst_flags = [IsMemRef, IsLoad, IsCopy]);
46    }
47
48    format LoadOrPrefetch {
49        0x28: ldl({{ Ra.sl = Mem.sl; }});
50        0x29: ldq({{ Ra.uq = Mem.uq; }}, pf_flags = EVICT_NEXT);
51        // IsFloating flag on lds gets the prefetch to disassemble
52        // using f31 instead of r31... funcitonally it's unnecessary
53        0x22: lds({{ Fa.uq = s_to_t(Mem.ul); }},
54                  pf_flags = PF_EXCLUSIVE, inst_flags = IsFloating);
55    }
56
57    format Store {
58        0x0e: stb({{ Mem.ub = Ra<7:0>; }});
59        0x0d: stw({{ Mem.uw = Ra<15:0>; }});
60        0x2c: stl({{ Mem.ul = Ra<31:0>; }});
61        0x2d: stq({{ Mem.uq = Ra.uq; }});
62        0x0f: stq_u({{ Mem.uq = Ra.uq; }}, {{ EA = (Rb + disp) & ~7; }});
63        0x26: sts({{ Mem.ul = t_to_s(Fa.uq); }});
64        0x27: stt({{ Mem.df = Fa; }});
65        0x24: MiscPrefetch::copy_store({{ EA = Rb; }},
66                                       {{ fault = xc->copy(EA); }},
67                                       inst_flags = [IsMemRef, IsStore, IsCopy]);
68    }
69
70    format StoreCond {
71        0x2e: stl_c({{ Mem.ul = Ra<31:0>; }},
72                    {{
73                        uint64_t tmp = write_result;
74                        // see stq_c
75                        Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
76                    }}, mem_flags = LOCKED, inst_flags = [IsNonSpeculative,
77                                                          IsSerializing,
78                                                          IsSerializeAfter]);
79        0x2f: stq_c({{ Mem.uq = Ra; }},
80                    {{
81                        uint64_t tmp = write_result;
82                        // If the write operation returns 0 or 1, then
83                        // this was a conventional store conditional,
84                        // and the value indicates the success/failure
85                        // of the operation.  If another value is
86                        // returned, then this was a Turbolaser
87                        // mailbox access, and we don't update the
88                        // result register at all.
89                        Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
90                    }}, mem_flags = LOCKED, inst_flags = [IsNonSpeculative,
91                                                          IsSerializing,
92                                                          IsSerializeAfter]);
93    }
94
95    format IntegerOperate {
96
97        0x10: decode INTFUNC {	// integer arithmetic operations
98
99            0x00: addl({{ Rc.sl = Ra.sl + Rb_or_imm.sl; }});
100            0x40: addlv({{
101                uint32_t tmp  = Ra.sl + Rb_or_imm.sl;
102                // signed overflow occurs when operands have same sign
103                // and sign of result does not match.
104                if (Ra.sl<31:> == Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
105                    fault = new IntegerOverflowFault;
106                Rc.sl = tmp;
107            }});
108            0x02: s4addl({{ Rc.sl = (Ra.sl << 2) + Rb_or_imm.sl; }});
109            0x12: s8addl({{ Rc.sl = (Ra.sl << 3) + Rb_or_imm.sl; }});
110
111            0x20: addq({{ Rc = Ra + Rb_or_imm; }});
112            0x60: addqv({{
113                uint64_t tmp = Ra + Rb_or_imm;
114                // signed overflow occurs when operands have same sign
115                // and sign of result does not match.
116                if (Ra<63:> == Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
117                    fault = new IntegerOverflowFault;
118                Rc = tmp;
119            }});
120            0x22: s4addq({{ Rc = (Ra << 2) + Rb_or_imm; }});
121            0x32: s8addq({{ Rc = (Ra << 3) + Rb_or_imm; }});
122
123            0x09: subl({{ Rc.sl = Ra.sl - Rb_or_imm.sl; }});
124            0x49: sublv({{
125                uint32_t tmp  = Ra.sl - Rb_or_imm.sl;
126                // signed overflow detection is same as for add,
127                // except we need to look at the *complemented*
128                // sign bit of the subtrahend (Rb), i.e., if the initial
129                // signs are the *same* then no overflow can occur
130                if (Ra.sl<31:> != Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
131                    fault = new IntegerOverflowFault;
132                Rc.sl = tmp;
133            }});
134            0x0b: s4subl({{ Rc.sl = (Ra.sl << 2) - Rb_or_imm.sl; }});
135            0x1b: s8subl({{ Rc.sl = (Ra.sl << 3) - Rb_or_imm.sl; }});
136
137            0x29: subq({{ Rc = Ra - Rb_or_imm; }});
138            0x69: subqv({{
139                uint64_t tmp  = Ra - Rb_or_imm;
140                // signed overflow detection is same as for add,
141                // except we need to look at the *complemented*
142                // sign bit of the subtrahend (Rb), i.e., if the initial
143                // signs are the *same* then no overflow can occur
144                if (Ra<63:> != Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
145                    fault = new IntegerOverflowFault;
146                Rc = tmp;
147            }});
148            0x2b: s4subq({{ Rc = (Ra << 2) - Rb_or_imm; }});
149            0x3b: s8subq({{ Rc = (Ra << 3) - Rb_or_imm; }});
150
151            0x2d: cmpeq({{ Rc = (Ra == Rb_or_imm); }});
152            0x6d: cmple({{ Rc = (Ra.sq <= Rb_or_imm.sq); }});
153            0x4d: cmplt({{ Rc = (Ra.sq <  Rb_or_imm.sq); }});
154            0x3d: cmpule({{ Rc = (Ra.uq <= Rb_or_imm.uq); }});
155            0x1d: cmpult({{ Rc = (Ra.uq <  Rb_or_imm.uq); }});
156
157            0x0f: cmpbge({{
158                int hi = 7;
159                int lo = 0;
160                uint64_t tmp = 0;
161                for (int i = 0; i < 8; ++i) {
162                    tmp |= (Ra.uq<hi:lo> >= Rb_or_imm.uq<hi:lo>) << i;
163                    hi += 8;
164                    lo += 8;
165                }
166                Rc = tmp;
167            }});
168        }
169
170        0x11: decode INTFUNC {	// integer logical operations
171
172            0x00: and({{ Rc = Ra & Rb_or_imm; }});
173            0x08: bic({{ Rc = Ra & ~Rb_or_imm; }});
174            0x20: bis({{ Rc = Ra | Rb_or_imm; }});
175            0x28: ornot({{ Rc = Ra | ~Rb_or_imm; }});
176            0x40: xor({{ Rc = Ra ^ Rb_or_imm; }});
177            0x48: eqv({{ Rc = Ra ^ ~Rb_or_imm; }});
178
179            // conditional moves
180            0x14: cmovlbs({{ Rc = ((Ra & 1) == 1) ? Rb_or_imm : Rc; }});
181            0x16: cmovlbc({{ Rc = ((Ra & 1) == 0) ? Rb_or_imm : Rc; }});
182            0x24: cmoveq({{ Rc = (Ra == 0) ? Rb_or_imm : Rc; }});
183            0x26: cmovne({{ Rc = (Ra != 0) ? Rb_or_imm : Rc; }});
184            0x44: cmovlt({{ Rc = (Ra.sq <  0) ? Rb_or_imm : Rc; }});
185            0x46: cmovge({{ Rc = (Ra.sq >= 0) ? Rb_or_imm : Rc; }});
186            0x64: cmovle({{ Rc = (Ra.sq <= 0) ? Rb_or_imm : Rc; }});
187            0x66: cmovgt({{ Rc = (Ra.sq >  0) ? Rb_or_imm : Rc; }});
188
189            // For AMASK, RA must be R31.
190            0x61: decode RA {
191                31: amask({{ Rc = Rb_or_imm & ~ULL(0x17); }});
192            }
193
194            // For IMPLVER, RA must be R31 and the B operand
195            // must be the immediate value 1.
196            0x6c: decode RA {
197                31: decode IMM {
198                    1: decode INTIMM {
199                        // return EV5 for FULL_SYSTEM and EV6 otherwise
200                        1: implver({{
201#if FULL_SYSTEM
202                             Rc = 1;
203#else
204                             Rc = 2;
205#endif
206                        }});
207                    }
208                }
209            }
210
211#if FULL_SYSTEM
212            // The mysterious 11.25...
213            0x25: WarnUnimpl::eleven25();
214#endif
215        }
216
217        0x12: decode INTFUNC {
218            0x39: sll({{ Rc = Ra << Rb_or_imm<5:0>; }});
219            0x34: srl({{ Rc = Ra.uq >> Rb_or_imm<5:0>; }});
220            0x3c: sra({{ Rc = Ra.sq >> Rb_or_imm<5:0>; }});
221
222            0x02: mskbl({{ Rc = Ra & ~(mask( 8) << (Rb_or_imm<2:0> * 8)); }});
223            0x12: mskwl({{ Rc = Ra & ~(mask(16) << (Rb_or_imm<2:0> * 8)); }});
224            0x22: mskll({{ Rc = Ra & ~(mask(32) << (Rb_or_imm<2:0> * 8)); }});
225            0x32: mskql({{ Rc = Ra & ~(mask(64) << (Rb_or_imm<2:0> * 8)); }});
226
227            0x52: mskwh({{
228                int bv = Rb_or_imm<2:0>;
229                Rc =  bv ? (Ra & ~(mask(16) >> (64 - 8 * bv))) : Ra;
230            }});
231            0x62: msklh({{
232                int bv = Rb_or_imm<2:0>;
233                Rc =  bv ? (Ra & ~(mask(32) >> (64 - 8 * bv))) : Ra;
234            }});
235            0x72: mskqh({{
236                int bv = Rb_or_imm<2:0>;
237                Rc =  bv ? (Ra & ~(mask(64) >> (64 - 8 * bv))) : Ra;
238            }});
239
240            0x06: extbl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))< 7:0>; }});
241            0x16: extwl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<15:0>; }});
242            0x26: extll({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<31:0>; }});
243            0x36: extql({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8)); }});
244
245            0x5a: extwh({{
246                Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<15:0>; }});
247            0x6a: extlh({{
248                Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<31:0>; }});
249            0x7a: extqh({{
250                Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>); }});
251
252            0x0b: insbl({{ Rc = Ra< 7:0> << (Rb_or_imm<2:0> * 8); }});
253            0x1b: inswl({{ Rc = Ra<15:0> << (Rb_or_imm<2:0> * 8); }});
254            0x2b: insll({{ Rc = Ra<31:0> << (Rb_or_imm<2:0> * 8); }});
255            0x3b: insql({{ Rc = Ra       << (Rb_or_imm<2:0> * 8); }});
256
257            0x57: inswh({{
258                int bv = Rb_or_imm<2:0>;
259                Rc = bv ? (Ra.uq<15:0> >> (64 - 8 * bv)) : 0;
260            }});
261            0x67: inslh({{
262                int bv = Rb_or_imm<2:0>;
263                Rc = bv ? (Ra.uq<31:0> >> (64 - 8 * bv)) : 0;
264            }});
265            0x77: insqh({{
266                int bv = Rb_or_imm<2:0>;
267                Rc = bv ? (Ra.uq       >> (64 - 8 * bv)) : 0;
268            }});
269
270            0x30: zap({{
271                uint64_t zapmask = 0;
272                for (int i = 0; i < 8; ++i) {
273                    if (Rb_or_imm<i:>)
274                        zapmask |= (mask(8) << (i * 8));
275                }
276                Rc = Ra & ~zapmask;
277            }});
278            0x31: zapnot({{
279                uint64_t zapmask = 0;
280                for (int i = 0; i < 8; ++i) {
281                    if (!Rb_or_imm<i:>)
282                        zapmask |= (mask(8) << (i * 8));
283                }
284                Rc = Ra & ~zapmask;
285            }});
286        }
287
288        0x13: decode INTFUNC {	// integer multiplies
289            0x00: mull({{ Rc.sl = Ra.sl * Rb_or_imm.sl; }}, IntMultOp);
290            0x20: mulq({{ Rc    = Ra    * Rb_or_imm;    }}, IntMultOp);
291            0x30: umulh({{
292                uint64_t hi, lo;
293                mul128(Ra, Rb_or_imm, hi, lo);
294                Rc = hi;
295            }}, IntMultOp);
296            0x40: mullv({{
297                // 32-bit multiply with trap on overflow
298                int64_t Rax = Ra.sl;	// sign extended version of Ra.sl
299                int64_t Rbx = Rb_or_imm.sl;
300                int64_t tmp = Rax * Rbx;
301                // To avoid overflow, all the upper 32 bits must match
302                // the sign bit of the lower 32.  We code this as
303                // checking the upper 33 bits for all 0s or all 1s.
304                uint64_t sign_bits = tmp<63:31>;
305                if (sign_bits != 0 && sign_bits != mask(33))
306                    fault = new IntegerOverflowFault;
307                Rc.sl = tmp<31:0>;
308            }}, IntMultOp);
309            0x60: mulqv({{
310                // 64-bit multiply with trap on overflow
311                uint64_t hi, lo;
312                mul128(Ra, Rb_or_imm, hi, lo);
313                // all the upper 64 bits must match the sign bit of
314                // the lower 64
315                if (!((hi == 0 && lo<63:> == 0) ||
316                      (hi == mask(64) && lo<63:> == 1)))
317                    fault = new IntegerOverflowFault;
318                Rc = lo;
319            }}, IntMultOp);
320        }
321
322        0x1c: decode INTFUNC {
323            0x00: decode RA { 31: sextb({{ Rc.sb = Rb_or_imm< 7:0>; }}); }
324            0x01: decode RA { 31: sextw({{ Rc.sw = Rb_or_imm<15:0>; }}); }
325            0x32: ctlz({{
326                             uint64_t count = 0;
327                             uint64_t temp = Rb;
328                             if (temp<63:32>) temp >>= 32; else count += 32;
329                             if (temp<31:16>) temp >>= 16; else count += 16;
330                             if (temp<15:8>) temp >>= 8; else count += 8;
331                             if (temp<7:4>) temp >>= 4; else count += 4;
332                             if (temp<3:2>) temp >>= 2; else count += 2;
333                             if (temp<1:1>) temp >>= 1; else count += 1;
334                             if ((temp<0:0>) != 0x1) count += 1;
335                             Rc = count;
336                           }}, IntAluOp);
337
338            0x33: cttz({{
339                             uint64_t count = 0;
340                             uint64_t temp = Rb;
341                             if (!(temp<31:0>)) { temp >>= 32; count += 32; }
342                             if (!(temp<15:0>)) { temp >>= 16; count += 16; }
343                             if (!(temp<7:0>)) { temp >>= 8; count += 8; }
344                             if (!(temp<3:0>)) { temp >>= 4; count += 4; }
345                             if (!(temp<1:0>)) { temp >>= 2; count += 2; }
346                             if (!(temp<0:0> & ULL(0x1))) count += 1;
347                             Rc = count;
348                           }}, IntAluOp);
349
350            format FailUnimpl {
351                0x30: ctpop();
352                0x31: perr();
353                0x34: unpkbw();
354                0x35: unpkbl();
355                0x36: pkwb();
356                0x37: pklb();
357                0x38: minsb8();
358                0x39: minsw4();
359                0x3a: minub8();
360                0x3b: minuw4();
361                0x3c: maxub8();
362                0x3d: maxuw4();
363                0x3e: maxsb8();
364                0x3f: maxsw4();
365            }
366
367            format BasicOperateWithNopCheck {
368                0x70: decode RB {
369                    31: ftoit({{ Rc = Fa.uq; }}, FloatCvtOp);
370                }
371                0x78: decode RB {
372                    31: ftois({{ Rc.sl = t_to_s(Fa.uq); }},
373                              FloatCvtOp);
374                }
375            }
376        }
377    }
378
379    // Conditional branches.
380    format CondBranch {
381        0x39: beq({{ cond = (Ra == 0); }});
382        0x3d: bne({{ cond = (Ra != 0); }});
383        0x3e: bge({{ cond = (Ra.sq >= 0); }});
384        0x3f: bgt({{ cond = (Ra.sq >  0); }});
385        0x3b: ble({{ cond = (Ra.sq <= 0); }});
386        0x3a: blt({{ cond = (Ra.sq < 0); }});
387        0x38: blbc({{ cond = ((Ra & 1) == 0); }});
388        0x3c: blbs({{ cond = ((Ra & 1) == 1); }});
389
390        0x31: fbeq({{ cond = (Fa == 0); }});
391        0x35: fbne({{ cond = (Fa != 0); }});
392        0x36: fbge({{ cond = (Fa >= 0); }});
393        0x37: fbgt({{ cond = (Fa >  0); }});
394        0x33: fble({{ cond = (Fa <= 0); }});
395        0x32: fblt({{ cond = (Fa < 0); }});
396    }
397
398    // unconditional branches
399    format UncondBranch {
400        0x30: br();
401        0x34: bsr(IsCall);
402    }
403
404    // indirect branches
405    0x1a: decode JMPFUNC {
406        format Jump {
407            0: jmp();
408            1: jsr(IsCall);
409            2: ret(IsReturn);
410            3: jsr_coroutine(IsCall, IsReturn);
411        }
412    }
413
414    // Square root and integer-to-FP moves
415    0x14: decode FP_SHORTFUNC {
416        // Integer to FP register moves must have RB == 31
417        0x4: decode RB {
418            31: decode FP_FULLFUNC {
419                format BasicOperateWithNopCheck {
420                    0x004: itofs({{ Fc.uq = s_to_t(Ra.ul); }}, FloatCvtOp);
421                    0x024: itoft({{ Fc.uq = Ra.uq; }}, FloatCvtOp);
422                    0x014: FailUnimpl::itoff();	// VAX-format conversion
423                }
424            }
425        }
426
427        // Square root instructions must have FA == 31
428        0xb: decode FA {
429            31: decode FP_TYPEFUNC {
430                format FloatingPointOperate {
431#if SS_COMPATIBLE_FP
432                    0x0b: sqrts({{
433                        if (Fb < 0.0)
434                            fault = new ArithmeticFault;
435                        Fc = sqrt(Fb);
436                    }}, FloatSqrtOp);
437#else
438                    0x0b: sqrts({{
439                        if (Fb.sf < 0.0)
440                            fault = new ArithmeticFault;
441                        Fc.sf = sqrt(Fb.sf);
442                    }}, FloatSqrtOp);
443#endif
444                    0x2b: sqrtt({{
445                        if (Fb < 0.0)
446                            fault = new ArithmeticFault;
447                        Fc = sqrt(Fb);
448                    }}, FloatSqrtOp);
449                }
450            }
451        }
452
453        // VAX-format sqrtf and sqrtg are not implemented
454        0xa: FailUnimpl::sqrtfg();
455    }
456
457    // IEEE floating point
458    0x16: decode FP_SHORTFUNC_TOP2 {
459        // The top two bits of the short function code break this
460        // space into four groups: binary ops, compares, reserved, and
461        // conversions.  See Table 4-12 of AHB.  There are different
462        // special cases in these different groups, so we decode on
463        // these top two bits first just to select a decode strategy.
464        // Most of these instructions may have various trapping and
465        // rounding mode flags set; these are decoded in the
466        // FloatingPointDecode template used by the
467        // FloatingPointOperate format.
468
469        // add/sub/mul/div: just decode on the short function code
470        // and source type.  All valid trapping and rounding modes apply.
471        0: decode FP_TRAPMODE {
472            // check for valid trapping modes here
473            0,1,5,7: decode FP_TYPEFUNC {
474                   format FloatingPointOperate {
475#if SS_COMPATIBLE_FP
476                       0x00: adds({{ Fc = Fa + Fb; }});
477                       0x01: subs({{ Fc = Fa - Fb; }});
478                       0x02: muls({{ Fc = Fa * Fb; }}, FloatMultOp);
479                       0x03: divs({{ Fc = Fa / Fb; }}, FloatDivOp);
480#else
481                       0x00: adds({{ Fc.sf = Fa.sf + Fb.sf; }});
482                       0x01: subs({{ Fc.sf = Fa.sf - Fb.sf; }});
483                       0x02: muls({{ Fc.sf = Fa.sf * Fb.sf; }}, FloatMultOp);
484                       0x03: divs({{ Fc.sf = Fa.sf / Fb.sf; }}, FloatDivOp);
485#endif
486
487                       0x20: addt({{ Fc = Fa + Fb; }});
488                       0x21: subt({{ Fc = Fa - Fb; }});
489                       0x22: mult({{ Fc = Fa * Fb; }}, FloatMultOp);
490                       0x23: divt({{ Fc = Fa / Fb; }}, FloatDivOp);
491                   }
492             }
493        }
494
495        // Floating-point compare instructions must have the default
496        // rounding mode, and may use the default trapping mode or
497        // /SU.  Both trapping modes are treated the same by M5; the
498        // only difference on the real hardware (as far a I can tell)
499        // is that without /SU you'd get an imprecise trap if you
500        // tried to compare a NaN with something else (instead of an
501        // "unordered" result).
502        1: decode FP_FULLFUNC {
503            format BasicOperateWithNopCheck {
504                0x0a5, 0x5a5: cmpteq({{ Fc = (Fa == Fb) ? 2.0 : 0.0; }},
505                                     FloatCmpOp);
506                0x0a7, 0x5a7: cmptle({{ Fc = (Fa <= Fb) ? 2.0 : 0.0; }},
507                                     FloatCmpOp);
508                0x0a6, 0x5a6: cmptlt({{ Fc = (Fa <  Fb) ? 2.0 : 0.0; }},
509                                     FloatCmpOp);
510                0x0a4, 0x5a4: cmptun({{ // unordered
511                    Fc = (!(Fa < Fb) && !(Fa == Fb) && !(Fa > Fb)) ? 2.0 : 0.0;
512                }}, FloatCmpOp);
513            }
514        }
515
516        // The FP-to-integer and integer-to-FP conversion insts
517        // require that FA be 31.
518        3: decode FA {
519            31: decode FP_TYPEFUNC {
520                format FloatingPointOperate {
521                    0x2f: decode FP_ROUNDMODE {
522                        format FPFixedRounding {
523                            // "chopped" i.e. round toward zero
524                            0: cvttq({{ Fc.sq = (int64_t)trunc(Fb); }},
525                                     Chopped);
526                            // round to minus infinity
527                            1: cvttq({{ Fc.sq = (int64_t)floor(Fb); }},
528                                     MinusInfinity);
529                        }
530                      default: cvttq({{ Fc.sq = (int64_t)nearbyint(Fb); }});
531                    }
532
533                    // The cvtts opcode is overloaded to be cvtst if the trap
534                    // mode is 2 or 6 (which are not valid otherwise)
535                    0x2c: decode FP_FULLFUNC {
536                        format BasicOperateWithNopCheck {
537                            // trap on denorm version "cvtst/s" is
538                            // simulated same as cvtst
539                            0x2ac, 0x6ac: cvtst({{ Fc = Fb.sf; }});
540                        }
541                      default: cvtts({{ Fc.sf = Fb; }});
542                    }
543
544                    // The trapping mode for integer-to-FP conversions
545                    // must be /SUI or nothing; /U and /SU are not
546                    // allowed.  The full set of rounding modes are
547                    // supported though.
548                    0x3c: decode FP_TRAPMODE {
549                        0,7: cvtqs({{ Fc.sf = Fb.sq; }});
550                    }
551                    0x3e: decode FP_TRAPMODE {
552                        0,7: cvtqt({{ Fc    = Fb.sq; }});
553                    }
554                }
555            }
556        }
557    }
558
559    // misc FP operate
560    0x17: decode FP_FULLFUNC {
561        format BasicOperateWithNopCheck {
562            0x010: cvtlq({{
563                Fc.sl = (Fb.uq<63:62> << 30) | Fb.uq<58:29>;
564            }});
565            0x030: cvtql({{
566                Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
567            }});
568
569            // We treat the precise & imprecise trapping versions of
570            // cvtql identically.
571            0x130, 0x530: cvtqlv({{
572                // To avoid overflow, all the upper 32 bits must match
573                // the sign bit of the lower 32.  We code this as
574                // checking the upper 33 bits for all 0s or all 1s.
575                uint64_t sign_bits = Fb.uq<63:31>;
576                if (sign_bits != 0 && sign_bits != mask(33))
577                    fault = new IntegerOverflowFault;
578                Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
579            }});
580
581            0x020: cpys({{  // copy sign
582                Fc.uq = (Fa.uq<63:> << 63) | Fb.uq<62:0>;
583            }});
584            0x021: cpysn({{ // copy sign negated
585                Fc.uq = (~Fa.uq<63:> << 63) | Fb.uq<62:0>;
586            }});
587            0x022: cpyse({{ // copy sign and exponent
588                Fc.uq = (Fa.uq<63:52> << 52) | Fb.uq<51:0>;
589            }});
590
591            0x02a: fcmoveq({{ Fc = (Fa == 0) ? Fb : Fc; }});
592            0x02b: fcmovne({{ Fc = (Fa != 0) ? Fb : Fc; }});
593            0x02c: fcmovlt({{ Fc = (Fa <  0) ? Fb : Fc; }});
594            0x02d: fcmovge({{ Fc = (Fa >= 0) ? Fb : Fc; }});
595            0x02e: fcmovle({{ Fc = (Fa <= 0) ? Fb : Fc; }});
596            0x02f: fcmovgt({{ Fc = (Fa >  0) ? Fb : Fc; }});
597
598            0x024: mt_fpcr({{ FPCR = Fa.uq; }}, IsSerializing, IsSerializeBefore);
599            0x025: mf_fpcr({{ Fa.uq = FPCR; }}, IsSerializing, IsSerializeBefore);
600        }
601    }
602
603    // miscellaneous mem-format ops
604    0x18: decode MEMFUNC {
605        format WarnUnimpl {
606            0x8000: fetch();
607            0xa000: fetch_m();
608            0xe800: ecb();
609        }
610
611        format MiscPrefetch {
612            0xf800: wh64({{ EA = Rb & ~ULL(63); }},
613                         {{ xc->writeHint(EA, 64, memAccessFlags); }},
614                         mem_flags = NO_FAULT,
615                         inst_flags = [IsMemRef, IsDataPrefetch,
616                                       IsStore, MemWriteOp]);
617        }
618
619        format BasicOperate {
620            0xc000: rpcc({{
621#if FULL_SYSTEM
622        /* Rb is a fake dependency so here is a fun way to get
623         * the parser to understand that.
624         */
625                Ra = xc->readMiscRegWithEffect(AlphaISA::IPR_CC, fault) + (Rb & 0);
626
627#else
628                Ra = curTick;
629#endif
630            }}, IsUnverifiable);
631
632            // All of the barrier instructions below do nothing in
633            // their execute() methods (hence the empty code blocks).
634            // All of their functionality is hard-coded in the
635            // pipeline based on the flags IsSerializing,
636            // IsMemBarrier, and IsWriteBarrier.  In the current
637            // detailed CPU model, the execute() function only gets
638            // called at fetch, so there's no way to generate pipeline
639            // behavior at any other stage.  Once we go to an
640            // exec-in-exec CPU model we should be able to get rid of
641            // these flags and implement this behavior via the
642            // execute() methods.
643
644            // trapb is just a barrier on integer traps, where excb is
645            // a barrier on integer and FP traps.  "EXCB is thus a
646            // superset of TRAPB." (Alpha ARM, Sec 4.11.4) We treat
647            // them the same though.
648            0x0000: trapb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
649            0x0400: excb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
650            0x4000: mb({{ }}, IsMemBarrier, MemReadOp);
651            0x4400: wmb({{ }}, IsWriteBarrier, MemWriteOp);
652        }
653
654#if FULL_SYSTEM
655        format BasicOperate {
656            0xe000: rc({{
657                Ra = xc->readIntrFlag();
658                xc->setIntrFlag(0);
659            }}, IsNonSpeculative);
660            0xf000: rs({{
661                Ra = xc->readIntrFlag();
662                xc->setIntrFlag(1);
663            }}, IsNonSpeculative);
664        }
665#else
666        format FailUnimpl {
667            0xe000: rc();
668            0xf000: rs();
669        }
670#endif
671    }
672
673#if FULL_SYSTEM
674    0x00: CallPal::call_pal({{
675        if (!palValid ||
676            (palPriv
677             && xc->readMiscRegWithEffect(AlphaISA::IPR_ICM, fault) != AlphaISA::mode_kernel)) {
678            // invalid pal function code, or attempt to do privileged
679            // PAL call in non-kernel mode
680            fault = new UnimplementedOpcodeFault;
681        }
682        else {
683            // check to see if simulator wants to do something special
684            // on this PAL call (including maybe suppress it)
685            bool dopal = xc->simPalCheck(palFunc);
686
687            if (dopal) {
688                xc->setMiscRegWithEffect(AlphaISA::IPR_EXC_ADDR, NPC);
689                NPC = xc->readMiscRegWithEffect(AlphaISA::IPR_PAL_BASE, fault) + palOffset;
690            }
691        }
692    }}, IsNonSpeculative);
693#else
694    0x00: decode PALFUNC {
695        format EmulatedCallPal {
696            0x00: halt ({{
697                SimExit(curTick, "halt instruction encountered");
698            }}, IsNonSpeculative);
699            0x83: callsys({{
700                xc->syscall();
701            }}, IsNonSpeculative, IsSerializeAfter);
702            // Read uniq reg into ABI return value register (r0)
703            0x9e: rduniq({{ R0 = Runiq; }}, IsSerializing, IsSerializeBefore);
704            // Write uniq reg with value from ABI arg register (r16)
705            0x9f: wruniq({{ Runiq = R16; }}, IsSerializing, IsSerializeBefore);
706        }
707    }
708#endif
709
710#if FULL_SYSTEM
711    0x1b: decode PALMODE {
712        0: OpcdecFault::hw_st_quad();
713        1: decode HW_LDST_QUAD {
714            format HwLoad {
715                0: hw_ld({{ EA = (Rb + disp) & ~3; }}, {{ Ra = Mem.ul; }}, L);
716                1: hw_ld({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }}, Q);
717            }
718        }
719    }
720
721    0x1f: decode PALMODE {
722        0: OpcdecFault::hw_st_cond();
723        format HwStore {
724            1: decode HW_LDST_COND {
725                0: decode HW_LDST_QUAD {
726                    0: hw_st({{ EA = (Rb + disp) & ~3; }},
727                {{ Mem.ul = Ra<31:0>; }}, L);
728                    1: hw_st({{ EA = (Rb + disp) & ~7; }},
729                {{ Mem.uq = Ra.uq; }}, Q);
730                }
731
732                1: FailUnimpl::hw_st_cond();
733            }
734        }
735    }
736
737    0x19: decode PALMODE {
738        0: OpcdecFault::hw_mfpr();
739        format HwMoveIPR {
740            1: hw_mfpr({{
741                Ra = xc->readMiscRegWithEffect(ipr_index, fault);
742            }}, IsSerializing, IsSerializeBefore);
743        }
744    }
745
746    0x1d: decode PALMODE {
747        0: OpcdecFault::hw_mtpr();
748        format HwMoveIPR {
749            1: hw_mtpr({{
750                xc->setMiscRegWithEffect(ipr_index, Ra);
751                if (traceData) { traceData->setData(Ra); }
752            }}, IsSerializing, IsSerializeBefore);
753        }
754    }
755
756    format BasicOperate {
757        0x1e: decode PALMODE {
758            0: OpcdecFault::hw_rei();
759            1:hw_rei({{ xc->hwrei(); }}, IsSerializing, IsSerializeBefore);
760        }
761
762        // M5 special opcodes use the reserved 0x01 opcode space
763        0x01: decode M5FUNC {
764            0x00: arm({{
765                AlphaPseudo::arm(xc->xcBase());
766            }}, IsNonSpeculative);
767            0x01: quiesce({{
768                AlphaPseudo::quiesce(xc->xcBase());
769            }}, IsNonSpeculative, IsQuiesce);
770            0x02: quiesceNs({{
771                AlphaPseudo::quiesceNs(xc->xcBase(), R16);
772            }}, IsNonSpeculative, IsQuiesce);
773            0x03: quiesceCycles({{
774                AlphaPseudo::quiesceCycles(xc->xcBase(), R16);
775            }}, IsNonSpeculative, IsQuiesce);
776            0x04: quiesceTime({{
777                R0 = AlphaPseudo::quiesceTime(xc->xcBase());
778            }}, IsNonSpeculative);
779            0x10: ivlb({{
780                AlphaPseudo::ivlb(xc->xcBase());
781            }}, No_OpClass, IsNonSpeculative);
782            0x11: ivle({{
783                AlphaPseudo::ivle(xc->xcBase());
784            }}, No_OpClass, IsNonSpeculative);
785            0x20: m5exit_old({{
786                AlphaPseudo::m5exit_old(xc->xcBase());
787            }}, No_OpClass, IsNonSpeculative);
788            0x21: m5exit({{
789                AlphaPseudo::m5exit(xc->xcBase(), R16);
790            }}, No_OpClass, IsNonSpeculative);
791            0x30: initparam({{ Ra = xc->xcBase()->getCpuPtr()->system->init_param; }});
792            0x40: resetstats({{
793                AlphaPseudo::resetstats(xc->xcBase(), R16, R17);
794            }}, IsNonSpeculative);
795            0x41: dumpstats({{
796                AlphaPseudo::dumpstats(xc->xcBase(), R16, R17);
797            }}, IsNonSpeculative);
798            0x42: dumpresetstats({{
799                AlphaPseudo::dumpresetstats(xc->xcBase(), R16, R17);
800            }}, IsNonSpeculative);
801            0x43: m5checkpoint({{
802                AlphaPseudo::m5checkpoint(xc->xcBase(), R16, R17);
803            }}, IsNonSpeculative);
804            0x50: m5readfile({{
805                R0 = AlphaPseudo::readfile(xc->xcBase(), R16, R17, R18);
806            }}, IsNonSpeculative);
807            0x51: m5break({{
808                AlphaPseudo::debugbreak(xc->xcBase());
809            }}, IsNonSpeculative);
810            0x52: m5switchcpu({{
811                AlphaPseudo::switchcpu(xc->xcBase());
812            }}, IsNonSpeculative);
813            0x53: m5addsymbol({{
814                AlphaPseudo::addsymbol(xc->xcBase(), R16, R17);
815            }}, IsNonSpeculative);
816            0x54: m5panic({{
817                panic("M5 panic instruction called.");
818            }}, IsNonSpeculative);
819
820        }
821    }
822#endif
823}
824