3 // Copyright (c) 2003-2006 The Regents of The University of Michigan
4 // All rights reserved.
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.
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.
29 // Authors: Steve Reinhardt
31 ////////////////////////////////////////////////////////////////////
33 // The actual decoder specification
36 decode OPCODE default Unknown::unknown() {
39 0x08: lda({{ Ra = Rb + disp; }});
40 0x09: ldah({{ Ra = Rb + (disp << 16); }});
44 0x0a: ldbu({{ Ra.uq = Mem.ub; }});
45 0x0c: ldwu({{ Ra.uq = Mem.uw; }});
46 0x0b: ldq_u({{ Ra = Mem.uq; }}, ea_code = {{ EA = (Rb + disp) & ~7; }});
47 0x23: ldt({{ Fa = Mem.df; }});
48 0x2a: ldl_l({{ Ra.sl = Mem.sl; }}, mem_flags = LLSC);
49 0x2b: ldq_l({{ Ra.uq = Mem.uq; }}, mem_flags = LLSC);
52 format LoadOrPrefetch {
53 0x28: ldl({{ Ra.sl = Mem.sl; }});
54 0x29: ldq({{ Ra.uq = Mem.uq; }}, pf_flags = EVICT_NEXT);
55 // IsFloating flag on lds gets the prefetch to disassemble
56 // using f31 instead of r31... funcitonally it's unnecessary
57 0x22: lds({{ Fa.uq = s_to_t(Mem.ul); }},
58 pf_flags = PF_EXCLUSIVE, inst_flags = IsFloating);
62 0x0e: stb({{ Mem.ub = Ra<7:0>; }});
63 0x0d: stw({{ Mem.uw = Ra<15:0>; }});
64 0x2c: stl({{ Mem.ul = Ra<31:0>; }});
65 0x2d: stq({{ Mem.uq = Ra.uq; }});
66 0x0f: stq_u({{ Mem.uq = Ra.uq; }}, {{ EA = (Rb + disp) & ~7; }});
67 0x26: sts({{ Mem.ul = t_to_s(Fa.uq); }});
68 0x27: stt({{ Mem.df = Fa; }});
72 0x2e: stl_c({{ Mem.ul = Ra<31:0>; }},
74 uint64_t tmp = write_result;
76 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
78 xc->setStCondFailures(0);
80 }}, mem_flags = LLSC, inst_flags = IsStoreConditional);
81 0x2f: stq_c({{ Mem.uq = Ra; }},
83 uint64_t tmp = write_result;
84 // If the write operation returns 0 or 1, then
85 // this was a conventional store conditional,
86 // and the value indicates the success/failure
87 // of the operation. If another value is
88 // returned, then this was a Turbolaser
89 // mailbox access, and we don't update the
90 // result register at all.
91 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
93 // clear failure counter... this is
94 // non-architectural and for debugging
96 xc->setStCondFailures(0);
98 }}, mem_flags = LLSC, inst_flags = IsStoreConditional);
101 format IntegerOperate {
103 0x10: decode INTFUNC { // integer arithmetic operations
105 0x00: addl({{ Rc.sl = Ra.sl + Rb_or_imm.sl; }});
107 int32_t tmp = Ra.sl + Rb_or_imm.sl;
108 // signed overflow occurs when operands have same sign
109 // and sign of result does not match.
110 if (Ra.sl<31:> == Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
111 fault = new IntegerOverflowFault;
114 0x02: s4addl({{ Rc.sl = (Ra.sl << 2) + Rb_or_imm.sl; }});
115 0x12: s8addl({{ Rc.sl = (Ra.sl << 3) + Rb_or_imm.sl; }});
117 0x20: addq({{ Rc = Ra + Rb_or_imm; }});
119 uint64_t tmp = Ra + Rb_or_imm;
120 // signed overflow occurs when operands have same sign
121 // and sign of result does not match.
122 if (Ra<63:> == Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
123 fault = new IntegerOverflowFault;
126 0x22: s4addq({{ Rc = (Ra << 2) + Rb_or_imm; }});
127 0x32: s8addq({{ Rc = (Ra << 3) + Rb_or_imm; }});
129 0x09: subl({{ Rc.sl = Ra.sl - Rb_or_imm.sl; }});
131 int32_t tmp = Ra.sl - Rb_or_imm.sl;
132 // signed overflow detection is same as for add,
133 // except we need to look at the *complemented*
134 // sign bit of the subtrahend (Rb), i.e., if the initial
135 // signs are the *same* then no overflow can occur
136 if (Ra.sl<31:> != Rb_or_imm.sl<31:> && tmp<31:> != Ra.sl<31:>)
137 fault = new IntegerOverflowFault;
140 0x0b: s4subl({{ Rc.sl = (Ra.sl << 2) - Rb_or_imm.sl; }});
141 0x1b: s8subl({{ Rc.sl = (Ra.sl << 3) - Rb_or_imm.sl; }});
143 0x29: subq({{ Rc = Ra - Rb_or_imm; }});
145 uint64_t tmp = Ra - Rb_or_imm;
146 // signed overflow detection is same as for add,
147 // except we need to look at the *complemented*
148 // sign bit of the subtrahend (Rb), i.e., if the initial
149 // signs are the *same* then no overflow can occur
150 if (Ra<63:> != Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
151 fault = new IntegerOverflowFault;
154 0x2b: s4subq({{ Rc = (Ra << 2) - Rb_or_imm; }});
155 0x3b: s8subq({{ Rc = (Ra << 3) - Rb_or_imm; }});
157 0x2d: cmpeq({{ Rc = (Ra == Rb_or_imm); }});
158 0x6d: cmple({{ Rc = (Ra.sq <= Rb_or_imm.sq); }});
159 0x4d: cmplt({{ Rc = (Ra.sq < Rb_or_imm.sq); }});
160 0x3d: cmpule({{ Rc = (Ra.uq <= Rb_or_imm.uq); }});
161 0x1d: cmpult({{ Rc = (Ra.uq < Rb_or_imm.uq); }});
167 for (int i = 0; i < 8; ++i) {
168 tmp |= (Ra.uq<hi:lo> >= Rb_or_imm.uq<hi:lo>) << i;
176 0x11: decode INTFUNC { // integer logical operations
178 0x00: and({{ Rc = Ra & Rb_or_imm; }});
179 0x08: bic({{ Rc = Ra & ~Rb_or_imm; }});
180 0x20: bis({{ Rc = Ra | Rb_or_imm; }});
181 0x28: ornot({{ Rc = Ra | ~Rb_or_imm; }});
182 0x40: xor({{ Rc = Ra ^ Rb_or_imm; }});
183 0x48: eqv({{ Rc = Ra ^ ~Rb_or_imm; }});
186 0x14: cmovlbs({{ Rc = ((Ra & 1) == 1) ? Rb_or_imm : Rc; }});
187 0x16: cmovlbc({{ Rc = ((Ra & 1) == 0) ? Rb_or_imm : Rc; }});
188 0x24: cmoveq({{ Rc = (Ra == 0) ? Rb_or_imm : Rc; }});
189 0x26: cmovne({{ Rc = (Ra != 0) ? Rb_or_imm : Rc; }});
190 0x44: cmovlt({{ Rc = (Ra.sq < 0) ? Rb_or_imm : Rc; }});
191 0x46: cmovge({{ Rc = (Ra.sq >= 0) ? Rb_or_imm : Rc; }});
192 0x64: cmovle({{ Rc = (Ra.sq <= 0) ? Rb_or_imm : Rc; }});
193 0x66: cmovgt({{ Rc = (Ra.sq > 0) ? Rb_or_imm : Rc; }});
195 // For AMASK, RA must be R31.
197 31: amask({{ Rc = Rb_or_imm & ~ULL(0x17); }});
200 // For IMPLVER, RA must be R31 and the B operand
201 // must be the immediate value 1.
205 // return EV5 for FULL_SYSTEM and EV6 otherwise
218 // The mysterious 11.25...
219 0x25: WarnUnimpl::eleven25();
223 0x12: decode INTFUNC {
224 0x39: sll({{ Rc = Ra << Rb_or_imm<5:0>; }});
225 0x34: srl({{ Rc = Ra.uq >> Rb_or_imm<5:0>; }});
226 0x3c: sra({{ Rc = Ra.sq >> Rb_or_imm<5:0>; }});
228 0x02: mskbl({{ Rc = Ra & ~(mask( 8) << (Rb_or_imm<2:0> * 8)); }});
229 0x12: mskwl({{ Rc = Ra & ~(mask(16) << (Rb_or_imm<2:0> * 8)); }});
230 0x22: mskll({{ Rc = Ra & ~(mask(32) << (Rb_or_imm<2:0> * 8)); }});
231 0x32: mskql({{ Rc = Ra & ~(mask(64) << (Rb_or_imm<2:0> * 8)); }});
234 int bv = Rb_or_imm<2:0>;
235 Rc = bv ? (Ra & ~(mask(16) >> (64 - 8 * bv))) : Ra;
238 int bv = Rb_or_imm<2:0>;
239 Rc = bv ? (Ra & ~(mask(32) >> (64 - 8 * bv))) : Ra;
242 int bv = Rb_or_imm<2:0>;
243 Rc = bv ? (Ra & ~(mask(64) >> (64 - 8 * bv))) : Ra;
246 0x06: extbl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))< 7:0>; }});
247 0x16: extwl({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<15:0>; }});
248 0x26: extll({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8))<31:0>; }});
249 0x36: extql({{ Rc = (Ra.uq >> (Rb_or_imm<2:0> * 8)); }});
252 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<15:0>; }});
254 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<31:0>; }});
256 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>); }});
258 0x0b: insbl({{ Rc = Ra< 7:0> << (Rb_or_imm<2:0> * 8); }});
259 0x1b: inswl({{ Rc = Ra<15:0> << (Rb_or_imm<2:0> * 8); }});
260 0x2b: insll({{ Rc = Ra<31:0> << (Rb_or_imm<2:0> * 8); }});
261 0x3b: insql({{ Rc = Ra << (Rb_or_imm<2:0> * 8); }});
264 int bv = Rb_or_imm<2:0>;
265 Rc = bv ? (Ra.uq<15:0> >> (64 - 8 * bv)) : 0;
268 int bv = Rb_or_imm<2:0>;
269 Rc = bv ? (Ra.uq<31:0> >> (64 - 8 * bv)) : 0;
272 int bv = Rb_or_imm<2:0>;
273 Rc = bv ? (Ra.uq >> (64 - 8 * bv)) : 0;
277 uint64_t zapmask = 0;
278 for (int i = 0; i < 8; ++i) {
280 zapmask |= (mask(8) << (i * 8));
285 uint64_t zapmask = 0;
286 for (int i = 0; i < 8; ++i) {
288 zapmask |= (mask(8) << (i * 8));
294 0x13: decode INTFUNC { // integer multiplies
295 0x00: mull({{ Rc.sl = Ra.sl * Rb_or_imm.sl; }}, IntMultOp);
296 0x20: mulq({{ Rc = Ra * Rb_or_imm; }}, IntMultOp);
299 mul128(Ra, Rb_or_imm, hi, lo);
303 // 32-bit multiply with trap on overflow
304 int64_t Rax = Ra.sl; // sign extended version of Ra.sl
305 int64_t Rbx = Rb_or_imm.sl;
306 int64_t tmp = Rax * Rbx;
307 // To avoid overflow, all the upper 32 bits must match
308 // the sign bit of the lower 32. We code this as
309 // checking the upper 33 bits for all 0s or all 1s.
310 uint64_t sign_bits = tmp<63:31>;
311 if (sign_bits != 0 && sign_bits != mask(33))
312 fault = new IntegerOverflowFault;
316 // 64-bit multiply with trap on overflow
318 mul128(Ra, Rb_or_imm, hi, lo);
319 // all the upper 64 bits must match the sign bit of
321 if (!((hi == 0 && lo<63:> == 0) ||
322 (hi == mask(64) && lo<63:> == 1)))
323 fault = new IntegerOverflowFault;
328 0x1c: decode INTFUNC {
329 0x00: decode RA { 31: sextb({{ Rc.sb = Rb_or_imm< 7:0>; }}); }
330 0x01: decode RA { 31: sextw({{ Rc.sw = Rb_or_imm<15:0>; }}); }
334 for (int i = 0; Rb<63:i>; ++i) {
345 for (int i = 0; i < 8; ++i) {
346 uint8_t ra_ub = Ra.uq<hi:lo>;
347 uint8_t rb_ub = Rb.uq<hi:lo>;
348 temp += (ra_ub >= rb_ub) ?
349 (ra_ub - rb_ub) : (rb_ub - ra_ub);
359 if (temp<63:32>) temp >>= 32; else count += 32;
360 if (temp<31:16>) temp >>= 16; else count += 16;
361 if (temp<15:8>) temp >>= 8; else count += 8;
362 if (temp<7:4>) temp >>= 4; else count += 4;
363 if (temp<3:2>) temp >>= 2; else count += 2;
364 if (temp<1:1>) temp >>= 1; else count += 1;
365 if ((temp<0:0>) != 0x1) count += 1;
372 if (!(temp<31:0>)) { temp >>= 32; count += 32; }
373 if (!(temp<15:0>)) { temp >>= 16; count += 16; }
374 if (!(temp<7:0>)) { temp >>= 8; count += 8; }
375 if (!(temp<3:0>)) { temp >>= 4; count += 4; }
376 if (!(temp<1:0>)) { temp >>= 2; count += 2; }
377 if (!(temp<0:0> & ULL(0x1))) {
378 temp >>= 1; count += 1;
380 if (!(temp<0:0> & ULL(0x1))) count += 1;
387 | (Rb.uq<15:8> << 16)
388 | (Rb.uq<23:16> << 32)
389 | (Rb.uq<31:24> << 48));
393 Rc = (Rb.uq<7:0> | (Rb.uq<15:8> << 32));
398 | (Rb.uq<23:16> << 8)
399 | (Rb.uq<39:32> << 16)
400 | (Rb.uq<55:48> << 24));
404 Rc = (Rb.uq<7:0> | (Rb.uq<39:32> << 8));
411 for (int i = 7; i >= 0; --i) {
412 int8_t ra_sb = Ra.uq<hi:lo>;
413 int8_t rb_sb = Rb.uq<hi:lo>;
415 | ((ra_sb < rb_sb) ? Ra.uq<hi:lo>
427 for (int i = 3; i >= 0; --i) {
428 int16_t ra_sw = Ra.uq<hi:lo>;
429 int16_t rb_sw = Rb.uq<hi:lo>;
431 | ((ra_sw < rb_sw) ? Ra.uq<hi:lo>
443 for (int i = 7; i >= 0; --i) {
444 uint8_t ra_ub = Ra.uq<hi:lo>;
445 uint8_t rb_ub = Rb.uq<hi:lo>;
447 | ((ra_ub < rb_ub) ? Ra.uq<hi:lo>
459 for (int i = 3; i >= 0; --i) {
460 uint16_t ra_sw = Ra.uq<hi:lo>;
461 uint16_t rb_sw = Rb.uq<hi:lo>;
463 | ((ra_sw < rb_sw) ? Ra.uq<hi:lo>
475 for (int i = 7; i >= 0; --i) {
476 uint8_t ra_ub = Ra.uq<hi:lo>;
477 uint8_t rb_ub = Rb.uq<hi:lo>;
479 | ((ra_ub > rb_ub) ? Ra.uq<hi:lo>
491 for (int i = 3; i >= 0; --i) {
492 uint16_t ra_uw = Ra.uq<hi:lo>;
493 uint16_t rb_uw = Rb.uq<hi:lo>;
495 | ((ra_uw > rb_uw) ? Ra.uq<hi:lo>
507 for (int i = 7; i >= 0; --i) {
508 int8_t ra_sb = Ra.uq<hi:lo>;
509 int8_t rb_sb = Rb.uq<hi:lo>;
511 | ((ra_sb > rb_sb) ? Ra.uq<hi:lo>
523 for (int i = 3; i >= 0; --i) {
524 int16_t ra_sw = Ra.uq<hi:lo>;
525 int16_t rb_sw = Rb.uq<hi:lo>;
527 | ((ra_sw > rb_sw) ? Ra.uq<hi:lo>
535 format BasicOperateWithNopCheck {
537 31: ftoit({{ Rc = Fa.uq; }}, FloatCvtOp);
540 31: ftois({{ Rc.sl = t_to_s(Fa.uq); }},
547 // Conditional branches.
549 0x39: beq({{ cond = (Ra == 0); }});
550 0x3d: bne({{ cond = (Ra != 0); }});
551 0x3e: bge({{ cond = (Ra.sq >= 0); }});
552 0x3f: bgt({{ cond = (Ra.sq > 0); }});
553 0x3b: ble({{ cond = (Ra.sq <= 0); }});
554 0x3a: blt({{ cond = (Ra.sq < 0); }});
555 0x38: blbc({{ cond = ((Ra & 1) == 0); }});
556 0x3c: blbs({{ cond = ((Ra & 1) == 1); }});
558 0x31: fbeq({{ cond = (Fa == 0); }});
559 0x35: fbne({{ cond = (Fa != 0); }});
560 0x36: fbge({{ cond = (Fa >= 0); }});
561 0x37: fbgt({{ cond = (Fa > 0); }});
562 0x33: fble({{ cond = (Fa <= 0); }});
563 0x32: fblt({{ cond = (Fa < 0); }});
566 // unconditional branches
567 format UncondBranch {
573 0x1a: decode JMPFUNC {
578 3: jsr_coroutine(IsCall, IsReturn);
582 // Square root and integer-to-FP moves
583 0x14: decode FP_SHORTFUNC {
584 // Integer to FP register moves must have RB == 31
586 31: decode FP_FULLFUNC {
587 format BasicOperateWithNopCheck {
588 0x004: itofs({{ Fc.uq = s_to_t(Ra.ul); }}, FloatCvtOp);
589 0x024: itoft({{ Fc.uq = Ra.uq; }}, FloatCvtOp);
590 0x014: FailUnimpl::itoff(); // VAX-format conversion
595 // Square root instructions must have FA == 31
597 31: decode FP_TYPEFUNC {
598 format FloatingPointOperate {
602 fault = new ArithmeticFault;
608 fault = new ArithmeticFault;
614 fault = new ArithmeticFault;
621 // VAX-format sqrtf and sqrtg are not implemented
622 0xa: FailUnimpl::sqrtfg();
625 // IEEE floating point
626 0x16: decode FP_SHORTFUNC_TOP2 {
627 // The top two bits of the short function code break this
628 // space into four groups: binary ops, compares, reserved, and
629 // conversions. See Table 4-12 of AHB. There are different
630 // special cases in these different groups, so we decode on
631 // these top two bits first just to select a decode strategy.
632 // Most of these instructions may have various trapping and
633 // rounding mode flags set; these are decoded in the
634 // FloatingPointDecode template used by the
635 // FloatingPointOperate format.
637 // add/sub/mul/div: just decode on the short function code
638 // and source type. All valid trapping and rounding modes apply.
639 0: decode FP_TRAPMODE {
640 // check for valid trapping modes here
641 0,1,5,7: decode FP_TYPEFUNC {
642 format FloatingPointOperate {
644 0x00: adds({{ Fc = Fa + Fb; }});
645 0x01: subs({{ Fc = Fa - Fb; }});
646 0x02: muls({{ Fc = Fa * Fb; }}, FloatMultOp);
647 0x03: divs({{ Fc = Fa / Fb; }}, FloatDivOp);
649 0x00: adds({{ Fc.sf = Fa.sf + Fb.sf; }});
650 0x01: subs({{ Fc.sf = Fa.sf - Fb.sf; }});
651 0x02: muls({{ Fc.sf = Fa.sf * Fb.sf; }}, FloatMultOp);
652 0x03: divs({{ Fc.sf = Fa.sf / Fb.sf; }}, FloatDivOp);
655 0x20: addt({{ Fc = Fa + Fb; }});
656 0x21: subt({{ Fc = Fa - Fb; }});
657 0x22: mult({{ Fc = Fa * Fb; }}, FloatMultOp);
658 0x23: divt({{ Fc = Fa / Fb; }}, FloatDivOp);
663 // Floating-point compare instructions must have the default
664 // rounding mode, and may use the default trapping mode or
665 // /SU. Both trapping modes are treated the same by M5; the
666 // only difference on the real hardware (as far a I can tell)
667 // is that without /SU you'd get an imprecise trap if you
668 // tried to compare a NaN with something else (instead of an
669 // "unordered" result).
670 1: decode FP_FULLFUNC {
671 format BasicOperateWithNopCheck {
672 0x0a5, 0x5a5: cmpteq({{ Fc = (Fa == Fb) ? 2.0 : 0.0; }},
674 0x0a7, 0x5a7: cmptle({{ Fc = (Fa <= Fb) ? 2.0 : 0.0; }},
676 0x0a6, 0x5a6: cmptlt({{ Fc = (Fa < Fb) ? 2.0 : 0.0; }},
678 0x0a4, 0x5a4: cmptun({{ // unordered
679 Fc = (!(Fa < Fb) && !(Fa == Fb) && !(Fa > Fb)) ? 2.0 : 0.0;
684 // The FP-to-integer and integer-to-FP conversion insts
685 // require that FA be 31.
687 31: decode FP_TYPEFUNC {
688 format FloatingPointOperate {
689 0x2f: decode FP_ROUNDMODE {
690 format FPFixedRounding {
691 // "chopped" i.e. round toward zero
692 0: cvttq({{ Fc.sq = (int64_t)trunc(Fb); }},
694 // round to minus infinity
695 1: cvttq({{ Fc.sq = (int64_t)floor(Fb); }},
698 default: cvttq({{ Fc.sq = (int64_t)nearbyint(Fb); }});
701 // The cvtts opcode is overloaded to be cvtst if the trap
702 // mode is 2 or 6 (which are not valid otherwise)
703 0x2c: decode FP_FULLFUNC {
704 format BasicOperateWithNopCheck {
705 // trap on denorm version "cvtst/s" is
706 // simulated same as cvtst
707 0x2ac, 0x6ac: cvtst({{ Fc = Fb.sf; }});
709 default: cvtts({{ Fc.sf = Fb; }});
712 // The trapping mode for integer-to-FP conversions
713 // must be /SUI or nothing; /U and /SU are not
714 // allowed. The full set of rounding modes are
716 0x3c: decode FP_TRAPMODE {
717 0,7: cvtqs({{ Fc.sf = Fb.sq; }});
719 0x3e: decode FP_TRAPMODE {
720 0,7: cvtqt({{ Fc = Fb.sq; }});
728 0x17: decode FP_FULLFUNC {
729 format BasicOperateWithNopCheck {
731 Fc.sl = (Fb.uq<63:62> << 30) | Fb.uq<58:29>;
734 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
737 // We treat the precise & imprecise trapping versions of
738 // cvtql identically.
739 0x130, 0x530: cvtqlv({{
740 // To avoid overflow, all the upper 32 bits must match
741 // the sign bit of the lower 32. We code this as
742 // checking the upper 33 bits for all 0s or all 1s.
743 uint64_t sign_bits = Fb.uq<63:31>;
744 if (sign_bits != 0 && sign_bits != mask(33))
745 fault = new IntegerOverflowFault;
746 Fc.uq = (Fb.uq<31:30> << 62) | (Fb.uq<29:0> << 29);
749 0x020: cpys({{ // copy sign
750 Fc.uq = (Fa.uq<63:> << 63) | Fb.uq<62:0>;
752 0x021: cpysn({{ // copy sign negated
753 Fc.uq = (~Fa.uq<63:> << 63) | Fb.uq<62:0>;
755 0x022: cpyse({{ // copy sign and exponent
756 Fc.uq = (Fa.uq<63:52> << 52) | Fb.uq<51:0>;
759 0x02a: fcmoveq({{ Fc = (Fa == 0) ? Fb : Fc; }});
760 0x02b: fcmovne({{ Fc = (Fa != 0) ? Fb : Fc; }});
761 0x02c: fcmovlt({{ Fc = (Fa < 0) ? Fb : Fc; }});
762 0x02d: fcmovge({{ Fc = (Fa >= 0) ? Fb : Fc; }});
763 0x02e: fcmovle({{ Fc = (Fa <= 0) ? Fb : Fc; }});
764 0x02f: fcmovgt({{ Fc = (Fa > 0) ? Fb : Fc; }});
766 0x024: mt_fpcr({{ FPCR = Fa.uq; }}, IsIprAccess);
767 0x025: mf_fpcr({{ Fa.uq = FPCR; }}, IsIprAccess);
771 // miscellaneous mem-format ops
772 0x18: decode MEMFUNC {
779 format MiscPrefetch {
780 0xf800: wh64({{ EA = Rb & ~ULL(63); }},
782 mem_flags = PREFETCH);
785 format BasicOperate {
788 /* Rb is a fake dependency so here is a fun way to get
789 * the parser to understand that.
791 Ra = xc->readMiscReg(IPR_CC) + (Rb & 0);
798 // All of the barrier instructions below do nothing in
799 // their execute() methods (hence the empty code blocks).
800 // All of their functionality is hard-coded in the
801 // pipeline based on the flags IsSerializing,
802 // IsMemBarrier, and IsWriteBarrier. In the current
803 // detailed CPU model, the execute() function only gets
804 // called at fetch, so there's no way to generate pipeline
805 // behavior at any other stage. Once we go to an
806 // exec-in-exec CPU model we should be able to get rid of
807 // these flags and implement this behavior via the
808 // execute() methods.
810 // trapb is just a barrier on integer traps, where excb is
811 // a barrier on integer and FP traps. "EXCB is thus a
812 // superset of TRAPB." (Alpha ARM, Sec 4.11.4) We treat
813 // them the same though.
814 0x0000: trapb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
815 0x0400: excb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
816 0x4000: mb({{ }}, IsMemBarrier, MemReadOp);
817 0x4400: wmb({{ }}, IsWriteBarrier, MemWriteOp);
821 format BasicOperate {
825 }}, IsNonSpeculative, IsUnverifiable);
829 }}, IsNonSpeculative, IsUnverifiable);
840 0x00: CallPal::call_pal({{
843 && xc->readMiscReg(IPR_ICM) != mode_kernel)) {
844 // invalid pal function code, or attempt to do privileged
845 // PAL call in non-kernel mode
846 fault = new UnimplementedOpcodeFault;
848 // check to see if simulator wants to do something special
849 // on this PAL call (including maybe suppress it)
850 bool dopal = xc->simPalCheck(palFunc);
853 xc->setMiscReg(IPR_EXC_ADDR, NPC);
854 NPC = xc->readMiscReg(IPR_PAL_BASE) + palOffset;
857 }}, IsNonSpeculative);
859 0x00: decode PALFUNC {
860 format EmulatedCallPal {
862 exitSimLoop("halt instruction encountered");
863 }}, IsNonSpeculative);
866 }}, IsSerializeAfter, IsNonSpeculative, IsSyscall);
867 // Read uniq reg into ABI return value register (r0)
868 0x9e: rduniq({{ R0 = Runiq; }}, IsIprAccess);
869 // Write uniq reg with value from ABI arg register (r16)
870 0x9f: wruniq({{ Runiq = R16; }}, IsIprAccess);
876 0x1b: decode PALMODE {
877 0: OpcdecFault::hw_st_quad();
878 1: decode HW_LDST_QUAD {
880 0: hw_ld({{ EA = (Rb + disp) & ~3; }}, {{ Ra = Mem.ul; }},
881 L, IsSerializing, IsSerializeBefore);
882 1: hw_ld({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem.uq; }},
883 Q, IsSerializing, IsSerializeBefore);
888 0x1f: decode PALMODE {
889 0: OpcdecFault::hw_st_cond();
891 1: decode HW_LDST_COND {
892 0: decode HW_LDST_QUAD {
893 0: hw_st({{ EA = (Rb + disp) & ~3; }},
894 {{ Mem.ul = Ra<31:0>; }}, L, IsSerializing, IsSerializeBefore);
895 1: hw_st({{ EA = (Rb + disp) & ~7; }},
896 {{ Mem.uq = Ra.uq; }}, Q, IsSerializing, IsSerializeBefore);
899 1: FailUnimpl::hw_st_cond();
904 0x19: decode PALMODE {
905 0: OpcdecFault::hw_mfpr();
908 int miscRegIndex = (ipr_index < MaxInternalProcRegs) ?
909 IprToMiscRegIndex[ipr_index] : -1;
910 if(miscRegIndex < 0 || !IprIsReadable(miscRegIndex) ||
911 miscRegIndex >= NumInternalProcRegs)
912 fault = new UnimplementedOpcodeFault;
914 Ra = xc->readMiscReg(miscRegIndex);
919 0x1d: decode PALMODE {
920 0: OpcdecFault::hw_mtpr();
923 int miscRegIndex = (ipr_index < MaxInternalProcRegs) ?
924 IprToMiscRegIndex[ipr_index] : -1;
925 if(miscRegIndex < 0 || !IprIsWritable(miscRegIndex) ||
926 miscRegIndex >= NumInternalProcRegs)
927 fault = new UnimplementedOpcodeFault;
929 xc->setMiscReg(miscRegIndex, Ra);
930 if (traceData) { traceData->setData(Ra); }
935 0x1e: decode PALMODE {
936 0: OpcdecFault::hw_rei();
937 format BasicOperate {
938 1: hw_rei({{ xc->hwrei(); }}, IsSerializing, IsSerializeBefore);
944 format BasicOperate {
945 // M5 special opcodes use the reserved 0x01 opcode space
946 0x01: decode M5FUNC {
949 PseudoInst::arm(xc->tcBase());
950 }}, IsNonSpeculative);
952 PseudoInst::quiesce(xc->tcBase());
953 }}, IsNonSpeculative, IsQuiesce);
955 PseudoInst::quiesceNs(xc->tcBase(), R16);
956 }}, IsNonSpeculative, IsQuiesce);
957 0x03: quiesceCycles({{
958 PseudoInst::quiesceCycles(xc->tcBase(), R16);
959 }}, IsNonSpeculative, IsQuiesce, IsUnverifiable);
961 R0 = PseudoInst::quiesceTime(xc->tcBase());
962 }}, IsNonSpeculative, IsUnverifiable);
965 R0 = PseudoInst::rpns(xc->tcBase());
966 }}, IsNonSpeculative, IsUnverifiable);
968 PseudoInst::wakeCPU(xc->tcBase(), R16);
969 }}, IsNonSpeculative, IsUnverifiable);
970 0x10: deprecated_ivlb({{
971 warn_once("Obsolete M5 ivlb instruction encountered.\n");
973 0x11: deprecated_ivle({{
974 warn_once("Obsolete M5 ivlb instruction encountered.\n");
976 0x20: deprecated_exit ({{
977 warn_once("deprecated M5 exit instruction encountered.\n");
978 PseudoInst::m5exit(xc->tcBase(), 0);
979 }}, No_OpClass, IsNonSpeculative);
981 PseudoInst::m5exit(xc->tcBase(), R16);
982 }}, No_OpClass, IsNonSpeculative);
985 PseudoInst::loadsymbol(xc->tcBase());
986 }}, No_OpClass, IsNonSpeculative);
988 Ra = xc->tcBase()->getCpuPtr()->system->init_param;
992 PseudoInst::resetstats(xc->tcBase(), R16, R17);
993 }}, IsNonSpeculative);
995 PseudoInst::dumpstats(xc->tcBase(), R16, R17);
996 }}, IsNonSpeculative);
997 0x42: dumpresetstats({{
998 PseudoInst::dumpresetstats(xc->tcBase(), R16, R17);
999 }}, IsNonSpeculative);
1000 0x43: m5checkpoint({{
1001 PseudoInst::m5checkpoint(xc->tcBase(), R16, R17);
1002 }}, IsNonSpeculative);
1005 R0 = PseudoInst::readfile(xc->tcBase(), R16, R17, R18);
1006 }}, IsNonSpeculative);
1009 PseudoInst::debugbreak(xc->tcBase());
1010 }}, IsNonSpeculative);
1011 0x52: m5switchcpu({{
1012 PseudoInst::switchcpu(xc->tcBase());
1013 }}, IsNonSpeculative);
1015 0x53: m5addsymbol({{
1016 PseudoInst::addsymbol(xc->tcBase(), R16, R17);
1017 }}, IsNonSpeculative);
1020 panic("M5 panic instruction called at pc = %#x.", PC);
1021 }}, IsNonSpeculative);
1022 #define CPANN(lbl) CPA::cpa()->lbl(xc->tcBase())
1025 panic("Deprecated M5 annotate instruction executed "
1026 "at pc = %#x\n", PC);
1027 }}, IsNonSpeculative);
1030 }}, IsNonSpeculative);
1033 }}, IsNonSpeculative);
1035 CPANN(swExplictBegin);
1036 }}, IsNonSpeculative);
1039 }}, IsNonSpeculative);
1042 }}, IsNonSpeculative);
1045 }}, IsNonSpeculative);
1048 }}, IsNonSpeculative);
1051 }}, IsNonSpeculative);
1054 }}, IsNonSpeculative);
1057 }}, IsNonSpeculative);
1060 }}, IsNonSpeculative);
1063 }}, IsNonSpeculative);
1064 0x10: m5a_identify({{
1066 }}, IsNonSpeculative);
1068 R0 = CPANN(swGetId);
1069 }}, IsNonSpeculative);
1071 CPANN(swSyscallLink);
1072 }}, IsNonSpeculative);
1075 }}, IsNonSpeculative);
1076 } // M5 Annotate Operations
1078 0x56: m5reserved2({{
1079 warn("M5 reserved opcode ignored");
1080 }}, IsNonSpeculative);
1081 0x57: m5reserved3({{
1082 warn("M5 reserved opcode ignored");
1083 }}, IsNonSpeculative);
1084 0x58: m5reserved4({{
1085 warn("M5 reserved opcode ignored");
1086 }}, IsNonSpeculative);
1087 0x59: m5reserved5({{
1088 warn("M5 reserved opcode ignored");
1089 }}, IsNonSpeculative);