3 // Copyright (c) 2013 ARM Limited
6 // The license below extends only to copyright in the software and shall
7 // not be construed as granting a license to any other intellectual
8 // property including but not limited to intellectual property relating
9 // to a hardware implementation of the functionality of the software
10 // licensed hereunder. You may use the software subject to the license
11 // terms below provided that you ensure that this notice is replicated
12 // unmodified and in its entirety in all distributions of the software,
13 // modified or unmodified, in source code or in binary form.
15 // Copyright (c) 2003-2006 The Regents of The University of Michigan
16 // All rights reserved.
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met: redistributions of source code must retain the above copyright
21 // notice, this list of conditions and the following disclaimer;
22 // redistributions in binary form must reproduce the above copyright
23 // notice, this list of conditions and the following disclaimer in the
24 // documentation and/or other materials provided with the distribution;
25 // neither the name of the copyright holders nor the names of its
26 // contributors may be used to endorse or promote products derived from
27 // this software without specific prior written permission.
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 // Authors: Steve Reinhardt
43 ////////////////////////////////////////////////////////////////////
45 // The actual decoder specification
48 decode OPCODE default Unknown::unknown() {
51 0x08: lda({{ Ra = Rb + disp; }});
52 0x09: ldah({{ Ra = Rb + (disp << 16); }});
56 0x0a: ldbu({{ Ra_uq = Mem_ub; }});
57 0x0c: ldwu({{ Ra_uq = Mem_uw; }});
58 0x0b: ldq_u({{ Ra = Mem_uq; }}, ea_code = {{ EA = (Rb + disp) & ~7; }});
59 0x23: ldt({{ Fa = Mem_df; }});
60 0x2a: ldl_l({{ Ra_sl = Mem_sl; }}, mem_flags = LLSC);
61 0x2b: ldq_l({{ Ra_uq = Mem_uq; }}, mem_flags = LLSC);
64 format LoadOrPrefetch {
65 0x28: ldl({{ Ra_sl = Mem_sl; }});
66 0x29: ldq({{ Ra_uq = Mem_uq; }}, pf_flags = EVICT_NEXT);
67 // IsFloating flag on lds gets the prefetch to disassemble
68 // using f31 instead of r31... funcitonally it's unnecessary
69 0x22: lds({{ Fa_uq = s_to_t(Mem_ul); }},
70 pf_flags = PF_EXCLUSIVE, inst_flags = IsFloating);
74 0x0e: stb({{ Mem_ub = Ra<7:0>; }});
75 0x0d: stw({{ Mem_uw = Ra<15:0>; }});
76 0x2c: stl({{ Mem_ul = Ra<31:0>; }});
77 0x2d: stq({{ Mem_uq = Ra_uq; }});
78 0x0f: stq_u({{ Mem_uq = Ra_uq; }}, {{ EA = (Rb + disp) & ~7; }});
79 0x26: sts({{ Mem_ul = t_to_s(Fa_uq); }});
80 0x27: stt({{ Mem_df = Fa; }});
84 0x2e: stl_c({{ Mem_ul = Ra<31:0>; }},
86 uint64_t tmp = write_result;
88 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
90 xc->setStCondFailures(0);
92 }}, mem_flags = LLSC, inst_flags = IsStoreConditional);
93 0x2f: stq_c({{ Mem_uq = Ra; }},
95 uint64_t tmp = write_result;
96 // If the write operation returns 0 or 1, then
97 // this was a conventional store conditional,
98 // and the value indicates the success/failure
99 // of the operation. If another value is
100 // returned, then this was a Turbolaser
101 // mailbox access, and we don't update the
102 // result register at all.
103 Ra = (tmp == 0 || tmp == 1) ? tmp : Ra;
105 // clear failure counter... this is
106 // non-architectural and for debugging
108 xc->setStCondFailures(0);
110 }}, mem_flags = LLSC, inst_flags = IsStoreConditional);
113 format IntegerOperate {
115 0x10: decode INTFUNC { // integer arithmetic operations
117 0x00: addl({{ Rc_sl = Ra_sl + Rb_or_imm_sl; }});
119 int32_t tmp = Ra_sl + Rb_or_imm_sl;
120 // signed overflow occurs when operands have same sign
121 // and sign of result does not match.
122 if (Ra_sl<31:> == Rb_or_imm_sl<31:> && tmp<31:> != Ra_sl<31:>)
123 fault = std::make_shared<IntegerOverflowFault>();
126 0x02: s4addl({{ Rc_sl = (Ra_sl << 2) + Rb_or_imm_sl; }});
127 0x12: s8addl({{ Rc_sl = (Ra_sl << 3) + Rb_or_imm_sl; }});
129 0x20: addq({{ Rc = Ra + Rb_or_imm; }});
131 uint64_t tmp = Ra + Rb_or_imm;
132 // signed overflow occurs when operands have same sign
133 // and sign of result does not match.
134 if (Ra<63:> == Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
135 fault = std::make_shared<IntegerOverflowFault>();
138 0x22: s4addq({{ Rc = (Ra << 2) + Rb_or_imm; }});
139 0x32: s8addq({{ Rc = (Ra << 3) + Rb_or_imm; }});
141 0x09: subl({{ Rc_sl = Ra_sl - Rb_or_imm_sl; }});
143 int32_t tmp = Ra_sl - Rb_or_imm_sl;
144 // signed overflow detection is same as for add,
145 // except we need to look at the *complemented*
146 // sign bit of the subtrahend (Rb), i.e., if the initial
147 // signs are the *same* then no overflow can occur
148 if (Ra_sl<31:> != Rb_or_imm_sl<31:> && tmp<31:> != Ra_sl<31:>)
149 fault = std::make_shared<IntegerOverflowFault>();
152 0x0b: s4subl({{ Rc_sl = (Ra_sl << 2) - Rb_or_imm_sl; }});
153 0x1b: s8subl({{ Rc_sl = (Ra_sl << 3) - Rb_or_imm_sl; }});
155 0x29: subq({{ Rc = Ra - Rb_or_imm; }});
157 uint64_t tmp = Ra - Rb_or_imm;
158 // signed overflow detection is same as for add,
159 // except we need to look at the *complemented*
160 // sign bit of the subtrahend (Rb), i.e., if the initial
161 // signs are the *same* then no overflow can occur
162 if (Ra<63:> != Rb_or_imm<63:> && tmp<63:> != Ra<63:>)
163 fault = std::make_shared<IntegerOverflowFault>();
166 0x2b: s4subq({{ Rc = (Ra << 2) - Rb_or_imm; }});
167 0x3b: s8subq({{ Rc = (Ra << 3) - Rb_or_imm; }});
169 0x2d: cmpeq({{ Rc = (Ra == Rb_or_imm); }});
170 0x6d: cmple({{ Rc = (Ra_sq <= Rb_or_imm_sq); }});
171 0x4d: cmplt({{ Rc = (Ra_sq < Rb_or_imm_sq); }});
172 0x3d: cmpule({{ Rc = (Ra_uq <= Rb_or_imm_uq); }});
173 0x1d: cmpult({{ Rc = (Ra_uq < Rb_or_imm_uq); }});
179 for (int i = 0; i < 8; ++i) {
180 tmp |= (Ra_uq<hi:lo> >= Rb_or_imm_uq<hi:lo>) << i;
188 0x11: decode INTFUNC { // integer logical operations
190 0x00: and({{ Rc = Ra & Rb_or_imm; }});
191 0x08: bic({{ Rc = Ra & ~Rb_or_imm; }});
192 0x20: bis({{ Rc = Ra | Rb_or_imm; }});
193 0x28: ornot({{ Rc = Ra | ~Rb_or_imm; }});
194 0x40: xor({{ Rc = Ra ^ Rb_or_imm; }});
195 0x48: eqv({{ Rc = Ra ^ ~Rb_or_imm; }});
198 0x14: cmovlbs({{ Rc = ((Ra & 1) == 1) ? Rb_or_imm : Rc; }});
199 0x16: cmovlbc({{ Rc = ((Ra & 1) == 0) ? Rb_or_imm : Rc; }});
200 0x24: cmoveq({{ Rc = (Ra == 0) ? Rb_or_imm : Rc; }});
201 0x26: cmovne({{ Rc = (Ra != 0) ? Rb_or_imm : Rc; }});
202 0x44: cmovlt({{ Rc = (Ra_sq < 0) ? Rb_or_imm : Rc; }});
203 0x46: cmovge({{ Rc = (Ra_sq >= 0) ? Rb_or_imm : Rc; }});
204 0x64: cmovle({{ Rc = (Ra_sq <= 0) ? Rb_or_imm : Rc; }});
205 0x66: cmovgt({{ Rc = (Ra_sq > 0) ? Rb_or_imm : Rc; }});
207 // For AMASK, RA must be R31.
209 31: amask({{ Rc = Rb_or_imm & ~ULL(0x17); }});
212 // For IMPLVER, RA must be R31 and the B operand
213 // must be the immediate value 1.
217 // return EV5 for FullSystem and EV6 otherwise
218 1: implver({{ Rc = FullSystem ? 1 : 2 }});
223 // The mysterious 11.25...
224 0x25: WarnUnimpl::eleven25();
227 0x12: decode INTFUNC {
228 0x39: sll({{ Rc = Ra << Rb_or_imm<5:0>; }});
229 0x34: srl({{ Rc = Ra_uq >> Rb_or_imm<5:0>; }});
230 0x3c: sra({{ Rc = Ra_sq >> Rb_or_imm<5:0>; }});
232 0x02: mskbl({{ Rc = Ra & ~(mask( 8) << (Rb_or_imm<2:0> * 8)); }});
233 0x12: mskwl({{ Rc = Ra & ~(mask(16) << (Rb_or_imm<2:0> * 8)); }});
234 0x22: mskll({{ Rc = Ra & ~(mask(32) << (Rb_or_imm<2:0> * 8)); }});
235 0x32: mskql({{ Rc = Ra & ~(mask(64) << (Rb_or_imm<2:0> * 8)); }});
238 int bv = Rb_or_imm<2:0>;
239 Rc = bv ? (Ra & ~(mask(16) >> (64 - 8 * bv))) : Ra;
242 int bv = Rb_or_imm<2:0>;
243 Rc = bv ? (Ra & ~(mask(32) >> (64 - 8 * bv))) : Ra;
246 int bv = Rb_or_imm<2:0>;
247 Rc = bv ? (Ra & ~(mask(64) >> (64 - 8 * bv))) : Ra;
250 0x06: extbl({{ Rc = (Ra_uq >> (Rb_or_imm<2:0> * 8))< 7:0>; }});
251 0x16: extwl({{ Rc = (Ra_uq >> (Rb_or_imm<2:0> * 8))<15:0>; }});
252 0x26: extll({{ Rc = (Ra_uq >> (Rb_or_imm<2:0> * 8))<31:0>; }});
253 0x36: extql({{ Rc = (Ra_uq >> (Rb_or_imm<2:0> * 8)); }});
256 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<15:0>; }});
258 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>)<31:0>; }});
260 Rc = (Ra << (64 - (Rb_or_imm<2:0> * 8))<5:0>); }});
262 0x0b: insbl({{ Rc = Ra< 7:0> << (Rb_or_imm<2:0> * 8); }});
263 0x1b: inswl({{ Rc = Ra<15:0> << (Rb_or_imm<2:0> * 8); }});
264 0x2b: insll({{ Rc = Ra<31:0> << (Rb_or_imm<2:0> * 8); }});
265 0x3b: insql({{ Rc = Ra << (Rb_or_imm<2:0> * 8); }});
268 int bv = Rb_or_imm<2:0>;
269 Rc = bv ? (Ra_uq<15:0> >> (64 - 8 * bv)) : 0;
272 int bv = Rb_or_imm<2:0>;
273 Rc = bv ? (Ra_uq<31:0> >> (64 - 8 * bv)) : 0;
276 int bv = Rb_or_imm<2:0>;
277 Rc = bv ? (Ra_uq >> (64 - 8 * bv)) : 0;
281 uint64_t zapmask = 0;
282 for (int i = 0; i < 8; ++i) {
284 zapmask |= (mask(8) << (i * 8));
289 uint64_t zapmask = 0;
290 for (int i = 0; i < 8; ++i) {
292 zapmask |= (mask(8) << (i * 8));
298 0x13: decode INTFUNC { // integer multiplies
299 0x00: mull({{ Rc_sl = Ra_sl * Rb_or_imm_sl; }}, IntMultOp);
300 0x20: mulq({{ Rc = Ra * Rb_or_imm; }}, IntMultOp);
303 mul128(Ra, Rb_or_imm, hi, lo);
307 // 32-bit multiply with trap on overflow
308 int64_t Rax = Ra_sl; // sign extended version of Ra_sl
309 int64_t Rbx = Rb_or_imm_sl;
310 int64_t tmp = Rax * Rbx;
311 // To avoid overflow, all the upper 32 bits must match
312 // the sign bit of the lower 32. We code this as
313 // checking the upper 33 bits for all 0s or all 1s.
314 uint64_t sign_bits = tmp<63:31>;
315 if (sign_bits != 0 && sign_bits != mask(33))
316 fault = std::make_shared<IntegerOverflowFault>();
320 // 64-bit multiply with trap on overflow
322 mul128(Ra, Rb_or_imm, hi, lo);
323 // all the upper 64 bits must match the sign bit of
325 if (!((hi == 0 && lo<63:> == 0) ||
326 (hi == mask(64) && lo<63:> == 1)))
327 fault = std::make_shared<IntegerOverflowFault>();
332 0x1c: decode INTFUNC {
333 0x00: decode RA { 31: sextb({{ Rc_sb = Rb_or_imm< 7:0>; }}); }
334 0x01: decode RA { 31: sextw({{ Rc_sw = Rb_or_imm<15:0>; }}); }
338 for (int i = 0; Rb<63:i>; ++i) {
349 for (int i = 0; i < 8; ++i) {
350 uint8_t ra_ub = Ra_uq<hi:lo>;
351 uint8_t rb_ub = Rb_uq<hi:lo>;
352 temp += (ra_ub >= rb_ub) ?
353 (ra_ub - rb_ub) : (rb_ub - ra_ub);
363 if (temp<63:32>) temp >>= 32; else count += 32;
364 if (temp<31:16>) temp >>= 16; else count += 16;
365 if (temp<15:8>) temp >>= 8; else count += 8;
366 if (temp<7:4>) temp >>= 4; else count += 4;
367 if (temp<3:2>) temp >>= 2; else count += 2;
368 if (temp<1:1>) temp >>= 1; else count += 1;
369 if ((temp<0:0>) != 0x1) count += 1;
376 if (!(temp<31:0>)) { temp >>= 32; count += 32; }
377 if (!(temp<15:0>)) { temp >>= 16; count += 16; }
378 if (!(temp<7:0>)) { temp >>= 8; count += 8; }
379 if (!(temp<3:0>)) { temp >>= 4; count += 4; }
380 if (!(temp<1:0>)) { temp >>= 2; count += 2; }
381 if (!(temp<0:0> & ULL(0x1))) {
382 temp >>= 1; count += 1;
384 if (!(temp<0:0> & ULL(0x1))) count += 1;
391 | (Rb_uq<15:8> << 16)
392 | (Rb_uq<23:16> << 32)
393 | (Rb_uq<31:24> << 48));
397 Rc = (Rb_uq<7:0> | (Rb_uq<15:8> << 32));
402 | (Rb_uq<23:16> << 8)
403 | (Rb_uq<39:32> << 16)
404 | (Rb_uq<55:48> << 24));
408 Rc = (Rb_uq<7:0> | (Rb_uq<39:32> << 8));
415 for (int i = 7; i >= 0; --i) {
416 int8_t ra_sb = Ra_uq<hi:lo>;
417 int8_t rb_sb = Rb_uq<hi:lo>;
419 | ((ra_sb < rb_sb) ? Ra_uq<hi:lo>
431 for (int i = 3; i >= 0; --i) {
432 int16_t ra_sw = Ra_uq<hi:lo>;
433 int16_t rb_sw = Rb_uq<hi:lo>;
435 | ((ra_sw < rb_sw) ? Ra_uq<hi:lo>
447 for (int i = 7; i >= 0; --i) {
448 uint8_t ra_ub = Ra_uq<hi:lo>;
449 uint8_t rb_ub = Rb_uq<hi:lo>;
451 | ((ra_ub < rb_ub) ? Ra_uq<hi:lo>
463 for (int i = 3; i >= 0; --i) {
464 uint16_t ra_sw = Ra_uq<hi:lo>;
465 uint16_t rb_sw = Rb_uq<hi:lo>;
467 | ((ra_sw < rb_sw) ? Ra_uq<hi:lo>
479 for (int i = 7; i >= 0; --i) {
480 uint8_t ra_ub = Ra_uq<hi:lo>;
481 uint8_t rb_ub = Rb_uq<hi:lo>;
483 | ((ra_ub > rb_ub) ? Ra_uq<hi:lo>
495 for (int i = 3; i >= 0; --i) {
496 uint16_t ra_uw = Ra_uq<hi:lo>;
497 uint16_t rb_uw = Rb_uq<hi:lo>;
499 | ((ra_uw > rb_uw) ? Ra_uq<hi:lo>
511 for (int i = 7; i >= 0; --i) {
512 int8_t ra_sb = Ra_uq<hi:lo>;
513 int8_t rb_sb = Rb_uq<hi:lo>;
515 | ((ra_sb > rb_sb) ? Ra_uq<hi:lo>
527 for (int i = 3; i >= 0; --i) {
528 int16_t ra_sw = Ra_uq<hi:lo>;
529 int16_t rb_sw = Rb_uq<hi:lo>;
531 | ((ra_sw > rb_sw) ? Ra_uq<hi:lo>
539 format BasicOperateWithNopCheck {
541 31: ftoit({{ Rc = Fa_uq; }}, FloatCvtOp);
544 31: ftois({{ Rc_sl = t_to_s(Fa_uq); }},
551 // Conditional branches.
553 0x39: beq({{ cond = (Ra == 0); }});
554 0x3d: bne({{ cond = (Ra != 0); }});
555 0x3e: bge({{ cond = (Ra_sq >= 0); }});
556 0x3f: bgt({{ cond = (Ra_sq > 0); }});
557 0x3b: ble({{ cond = (Ra_sq <= 0); }});
558 0x3a: blt({{ cond = (Ra_sq < 0); }});
559 0x38: blbc({{ cond = ((Ra & 1) == 0); }});
560 0x3c: blbs({{ cond = ((Ra & 1) == 1); }});
562 0x31: fbeq({{ cond = (Fa == 0); }});
563 0x35: fbne({{ cond = (Fa != 0); }});
564 0x36: fbge({{ cond = (Fa >= 0); }});
565 0x37: fbgt({{ cond = (Fa > 0); }});
566 0x33: fble({{ cond = (Fa <= 0); }});
567 0x32: fblt({{ cond = (Fa < 0); }});
570 // unconditional branches
571 format UncondBranch {
577 0x1a: decode JMPFUNC {
582 3: jsr_coroutine(IsCall, IsReturn);
586 // Square root and integer-to-FP moves
587 0x14: decode FP_SHORTFUNC {
588 // Integer to FP register moves must have RB == 31
590 31: decode FP_FULLFUNC {
591 format BasicOperateWithNopCheck {
592 0x004: itofs({{ Fc_uq = s_to_t(Ra_ul); }}, FloatCvtOp);
593 0x024: itoft({{ Fc_uq = Ra_uq; }}, FloatCvtOp);
594 0x014: FailUnimpl::itoff(); // VAX-format conversion
599 // Square root instructions must have FA == 31
601 31: decode FP_TYPEFUNC {
602 format FloatingPointOperate {
605 fault = std::make_shared<ArithmeticFault>();
610 fault = std::make_shared<ArithmeticFault>();
617 // VAX-format sqrtf and sqrtg are not implemented
618 0xa: FailUnimpl::sqrtfg();
621 // IEEE floating point
622 0x16: decode FP_SHORTFUNC_TOP2 {
623 // The top two bits of the short function code break this
624 // space into four groups: binary ops, compares, reserved, and
625 // conversions. See Table 4-12 of AHB. There are different
626 // special cases in these different groups, so we decode on
627 // these top two bits first just to select a decode strategy.
628 // Most of these instructions may have various trapping and
629 // rounding mode flags set; these are decoded in the
630 // FloatingPointDecode template used by the
631 // FloatingPointOperate format.
633 // add/sub/mul/div: just decode on the short function code
634 // and source type. All valid trapping and rounding modes apply.
635 0: decode FP_TRAPMODE {
636 // check for valid trapping modes here
637 0,1,5,7: decode FP_TYPEFUNC {
638 format FloatingPointOperate {
639 0x00: adds({{ Fc_sf = Fa_sf + Fb_sf; }});
640 0x01: subs({{ Fc_sf = Fa_sf - Fb_sf; }});
641 0x02: muls({{ Fc_sf = Fa_sf * Fb_sf; }}, FloatMultOp);
642 0x03: divs({{ Fc_sf = Fa_sf / Fb_sf; }}, FloatDivOp);
644 0x20: addt({{ Fc = Fa + Fb; }});
645 0x21: subt({{ Fc = Fa - Fb; }});
646 0x22: mult({{ Fc = Fa * Fb; }}, FloatMultOp);
647 0x23: divt({{ Fc = Fa / Fb; }}, FloatDivOp);
652 // Floating-point compare instructions must have the default
653 // rounding mode, and may use the default trapping mode or
654 // /SU. Both trapping modes are treated the same by M5; the
655 // only difference on the real hardware (as far a I can tell)
656 // is that without /SU you'd get an imprecise trap if you
657 // tried to compare a NaN with something else (instead of an
658 // "unordered" result).
659 1: decode FP_FULLFUNC {
660 format BasicOperateWithNopCheck {
661 0x0a5, 0x5a5: cmpteq({{ Fc = (Fa == Fb) ? 2.0 : 0.0; }},
663 0x0a7, 0x5a7: cmptle({{ Fc = (Fa <= Fb) ? 2.0 : 0.0; }},
665 0x0a6, 0x5a6: cmptlt({{ Fc = (Fa < Fb) ? 2.0 : 0.0; }},
667 0x0a4, 0x5a4: cmptun({{ // unordered
668 Fc = (!(Fa < Fb) && !(Fa == Fb) && !(Fa > Fb)) ? 2.0 : 0.0;
673 // The FP-to-integer and integer-to-FP conversion insts
674 // require that FA be 31.
676 31: decode FP_TYPEFUNC {
677 format FloatingPointOperate {
678 0x2f: decode FP_ROUNDMODE {
679 format FPFixedRounding {
680 // "chopped" i.e. round toward zero
681 0: cvttq({{ Fc_sq = (int64_t)trunc(Fb); }},
683 // round to minus infinity
684 1: cvttq({{ Fc_sq = (int64_t)floor(Fb); }},
687 default: cvttq({{ Fc_sq = (int64_t)nearbyint(Fb); }});
690 // The cvtts opcode is overloaded to be cvtst if the trap
691 // mode is 2 or 6 (which are not valid otherwise)
692 0x2c: decode FP_FULLFUNC {
693 format BasicOperateWithNopCheck {
694 // trap on denorm version "cvtst/s" is
695 // simulated same as cvtst
696 0x2ac, 0x6ac: cvtst({{ Fc = Fb_sf; }});
698 default: cvtts({{ Fc_sf = Fb; }});
701 // The trapping mode for integer-to-FP conversions
702 // must be /SUI or nothing; /U and /SU are not
703 // allowed. The full set of rounding modes are
705 0x3c: decode FP_TRAPMODE {
706 0,7: cvtqs({{ Fc_sf = Fb_sq; }});
708 0x3e: decode FP_TRAPMODE {
709 0,7: cvtqt({{ Fc = Fb_sq; }});
717 0x17: decode FP_FULLFUNC {
718 format BasicOperateWithNopCheck {
720 Fc_sl = (Fb_uq<63:62> << 30) | Fb_uq<58:29>;
723 Fc_uq = (Fb_uq<31:30> << 62) | (Fb_uq<29:0> << 29);
726 // We treat the precise & imprecise trapping versions of
727 // cvtql identically.
728 0x130, 0x530: cvtqlv({{
729 // To avoid overflow, all the upper 32 bits must match
730 // the sign bit of the lower 32. We code this as
731 // checking the upper 33 bits for all 0s or all 1s.
732 uint64_t sign_bits = Fb_uq<63:31>;
733 if (sign_bits != 0 && sign_bits != mask(33))
734 fault = std::make_shared<IntegerOverflowFault>();
735 Fc_uq = (Fb_uq<31:30> << 62) | (Fb_uq<29:0> << 29);
738 0x020: cpys({{ // copy sign
739 Fc_uq = (Fa_uq<63:> << 63) | Fb_uq<62:0>;
741 0x021: cpysn({{ // copy sign negated
742 Fc_uq = (~Fa_uq<63:> << 63) | Fb_uq<62:0>;
744 0x022: cpyse({{ // copy sign and exponent
745 Fc_uq = (Fa_uq<63:52> << 52) | Fb_uq<51:0>;
748 0x02a: fcmoveq({{ Fc = (Fa == 0) ? Fb : Fc; }});
749 0x02b: fcmovne({{ Fc = (Fa != 0) ? Fb : Fc; }});
750 0x02c: fcmovlt({{ Fc = (Fa < 0) ? Fb : Fc; }});
751 0x02d: fcmovge({{ Fc = (Fa >= 0) ? Fb : Fc; }});
752 0x02e: fcmovle({{ Fc = (Fa <= 0) ? Fb : Fc; }});
753 0x02f: fcmovgt({{ Fc = (Fa > 0) ? Fb : Fc; }});
755 0x024: mt_fpcr({{ FPCR = Fa_uq; }}, IsIprAccess);
756 0x025: mf_fpcr({{ Fa_uq = FPCR; }}, IsIprAccess);
760 // miscellaneous mem-format ops
761 0x18: decode MEMFUNC {
768 format MiscPrefetch {
769 0xf800: wh64({{ EA = Rb & ~ULL(63); }},
771 mem_flags = PREFETCH);
774 format BasicOperate {
776 /* Rb is a fake dependency so here is a fun way to get
777 * the parser to understand that.
779 uint64_t unused_var M5_VAR_USED = Rb;
780 Ra = FullSystem ? xc->readMiscReg(IPR_CC) : curTick();
783 // All of the barrier instructions below do nothing in
784 // their execute() methods (hence the empty code blocks).
785 // All of their functionality is hard-coded in the
786 // pipeline based on the flags IsSerializing,
787 // IsMemBarrier, and IsWriteBarrier. In the current
788 // detailed CPU model, the execute() function only gets
789 // called at fetch, so there's no way to generate pipeline
790 // behavior at any other stage. Once we go to an
791 // exec-in-exec CPU model we should be able to get rid of
792 // these flags and implement this behavior via the
793 // execute() methods.
795 // trapb is just a barrier on integer traps, where excb is
796 // a barrier on integer and FP traps. "EXCB is thus a
797 // superset of TRAPB." (Alpha ARM, Sec 4.11.4) We treat
798 // them the same though.
799 0x0000: trapb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
800 0x0400: excb({{ }}, IsSerializing, IsSerializeBefore, No_OpClass);
801 0x4000: mb({{ }}, IsMemBarrier, MemReadOp);
802 0x4400: wmb({{ }}, IsWriteBarrier, MemWriteOp);
805 0xe000: decode FullSystemInt {
806 0: FailUnimpl::rc_se();
807 default: BasicOperate::rc({{
810 }}, IsNonSpeculative, IsUnverifiable);
812 0xf000: decode FullSystemInt {
813 0: FailUnimpl::rs_se();
814 default: BasicOperate::rs({{
817 }}, IsNonSpeculative, IsUnverifiable);
821 0x00: decode FullSystemInt {
823 format EmulatedCallPal {
825 exitSimLoop("halt instruction encountered");
826 }}, IsNonSpeculative);
829 }}, IsSerializeAfter, IsNonSpeculative, IsSyscall);
830 // Read uniq reg into ABI return value register (r0)
831 0x9e: rduniq({{ R0 = Runiq; }}, IsIprAccess);
832 // Write uniq reg with value from ABI arg register (r16)
833 0x9f: wruniq({{ Runiq = R16; }}, IsIprAccess);
836 default: CallPal::call_pal({{
839 && xc->readMiscReg(IPR_ICM) != mode_kernel)) {
840 // invalid pal function code, or attempt to do privileged
841 // PAL call in non-kernel mode
842 fault = std::make_shared<UnimplementedOpcodeFault>();
844 // check to see if simulator wants to do something special
845 // on this PAL call (including maybe suppress it)
847 ThreadContext *tc = xc->tcBase();
848 auto *base_stats = tc->getKernelStats();
849 auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
851 assert(stats || !base_stats);
853 stats->callpal(palFunc, tc);
855 System *sys = tc->getSystemPtr();
859 xc->tcBase()->halt();
860 if (--System::numSystemsRunning == 0)
861 exitSimLoop("all cpus halted");
866 if (sys->breakpoint())
872 xc->setMiscReg(IPR_EXC_ADDR, NPC);
873 NPC = xc->readMiscReg(IPR_PAL_BASE) + palOffset;
876 }}, IsNonSpeculative);
879 0x1b: decode PALMODE {
880 0: OpcdecFault::hw_st_quad();
881 1: decode HW_LDST_QUAD {
883 0: hw_ld({{ EA = (Rb + disp) & ~3; }}, {{ Ra = Mem_ul; }},
884 L, IsSerializing, IsSerializeBefore);
885 1: hw_ld({{ EA = (Rb + disp) & ~7; }}, {{ Ra = Mem_uq; }},
886 Q, IsSerializing, IsSerializeBefore);
891 0x1f: decode PALMODE {
892 0: OpcdecFault::hw_st_cond();
894 1: decode HW_LDST_COND {
895 0: decode HW_LDST_QUAD {
896 0: hw_st({{ EA = (Rb + disp) & ~3; }},
897 {{ Mem_ul = Ra<31:0>; }}, L, IsSerializing, IsSerializeBefore);
898 1: hw_st({{ EA = (Rb + disp) & ~7; }},
899 {{ Mem_uq = Ra_uq; }}, Q, IsSerializing, IsSerializeBefore);
902 1: FailUnimpl::hw_st_cond();
907 0x19: decode PALMODE {
908 0: OpcdecFault::hw_mfpr();
911 int miscRegIndex = (ipr_index < MaxInternalProcRegs) ?
912 IprToMiscRegIndex[ipr_index] : -1;
913 if(miscRegIndex < 0 || !IprIsReadable(miscRegIndex) ||
914 miscRegIndex >= NumInternalProcRegs)
915 fault = std::make_shared<UnimplementedOpcodeFault>();
917 Ra = xc->readMiscReg(miscRegIndex);
922 0x1d: decode PALMODE {
923 0: OpcdecFault::hw_mtpr();
926 int miscRegIndex = (ipr_index < MaxInternalProcRegs) ?
927 IprToMiscRegIndex[ipr_index] : -1;
928 if(miscRegIndex < 0 || !IprIsWritable(miscRegIndex) ||
929 miscRegIndex >= NumInternalProcRegs)
930 fault = std::make_shared<UnimplementedOpcodeFault>();
932 xc->setMiscReg(miscRegIndex, Ra);
933 if (traceData) { traceData->setData(Ra); }
938 0x1e: decode PALMODE {
939 0: OpcdecFault::hw_rei();
940 format BasicOperate {
944 return std::make_shared<UnimplementedOpcodeFault>();
949 ThreadContext *tc = xc->tcBase();
950 auto *base_stats = tc->getKernelStats();
951 auto *stats = dynamic_cast<AlphaISA::Kernel::Statistics *>(
953 assert(stats || !base_stats);
957 CPA::cpa()->swAutoBegin(tc, IprExcAddr);
958 }}, IsSerializing, IsSerializeBefore);
962 format BasicOperate {
963 // M5 special opcodes use the reserved 0x01 opcode space
964 0x01: decode M5FUNC {
966 PseudoInst::arm(xc->tcBase());
967 }}, IsNonSpeculative);
969 // Don't sleep if (unmasked) interrupts are pending
970 BaseInterrupts* interrupts =
971 xc->tcBase()->getCpuPtr()->getInterruptController(0);
972 if (interrupts->checkInterrupts(xc->tcBase())) {
973 PseudoInst::quiesceSkip(xc->tcBase());
975 PseudoInst::quiesce(xc->tcBase());
977 }}, IsNonSpeculative, IsQuiesce);
979 PseudoInst::quiesceNs(xc->tcBase(), R16);
980 }}, IsNonSpeculative, IsQuiesce);
981 0x03: quiesceCycles({{
982 PseudoInst::quiesceCycles(xc->tcBase(), R16);
983 }}, IsNonSpeculative, IsQuiesce, IsUnverifiable);
985 R0 = PseudoInst::quiesceTime(xc->tcBase());
986 }}, IsNonSpeculative, IsUnverifiable);
988 R0 = PseudoInst::rpns(xc->tcBase());
989 }}, IsNonSpeculative, IsUnverifiable);
991 PseudoInst::wakeCPU(xc->tcBase(), R16);
992 }}, IsNonSpeculative, IsUnverifiable);
993 0x10: deprecated_ivlb({{
994 warn_once("Obsolete M5 ivlb instruction encountered.\n");
996 0x11: deprecated_ivle({{
997 warn_once("Obsolete M5 ivlb instruction encountered.\n");
999 0x20: deprecated_exit ({{
1000 warn_once("deprecated M5 exit instruction encountered.\n");
1001 PseudoInst::m5exit(xc->tcBase(), 0);
1002 }}, No_OpClass, IsNonSpeculative);
1004 PseudoInst::m5exit(xc->tcBase(), R16);
1005 }}, No_OpClass, IsNonSpeculative);
1007 PseudoInst::loadsymbol(xc->tcBase());
1008 }}, No_OpClass, IsNonSpeculative);
1010 Ra = PseudoInst::initParam(xc->tcBase(), R16, R17);
1013 PseudoInst::resetstats(xc->tcBase(), R16, R17);
1014 }}, IsNonSpeculative);
1016 PseudoInst::dumpstats(xc->tcBase(), R16, R17);
1017 }}, IsNonSpeculative);
1018 0x42: dumpresetstats({{
1019 PseudoInst::dumpresetstats(xc->tcBase(), R16, R17);
1020 }}, IsNonSpeculative);
1021 0x43: m5checkpoint({{
1022 PseudoInst::m5checkpoint(xc->tcBase(), R16, R17);
1023 }}, IsNonSpeculative);
1025 R0 = PseudoInst::readfile(xc->tcBase(), R16, R17, R18);
1026 }}, IsNonSpeculative);
1028 PseudoInst::debugbreak(xc->tcBase());
1029 }}, IsNonSpeculative);
1030 0x52: m5switchcpu({{
1031 PseudoInst::switchcpu(xc->tcBase());
1032 }}, IsNonSpeculative);
1033 0x53: m5addsymbol({{
1034 PseudoInst::addsymbol(xc->tcBase(), R16, R17);
1035 }}, IsNonSpeculative);
1037 panic("M5 panic instruction called at pc = %#x.", PC);
1038 }}, IsNonSpeculative);
1039 #define CPANN(lbl) CPA::cpa()->lbl(xc->tcBase())
1042 panic("Deprecated M5 annotate instruction executed "
1043 "at pc = %#x\n", PC);
1044 }}, IsNonSpeculative);
1047 }}, IsNonSpeculative);
1050 }}, IsNonSpeculative);
1052 CPANN(swExplictBegin);
1053 }}, IsNonSpeculative);
1056 }}, IsNonSpeculative);
1059 }}, IsNonSpeculative);
1062 }}, IsNonSpeculative);
1065 }}, IsNonSpeculative);
1068 }}, IsNonSpeculative);
1071 }}, IsNonSpeculative);
1074 }}, IsNonSpeculative);
1077 }}, IsNonSpeculative);
1080 }}, IsNonSpeculative);
1081 0x10: m5a_identify({{
1083 }}, IsNonSpeculative);
1085 R0 = CPANN(swGetId);
1086 }}, IsNonSpeculative);
1088 CPANN(swSyscallLink);
1089 }}, IsNonSpeculative);
1092 }}, IsNonSpeculative);
1093 } // M5 Annotate Operations
1095 0x56: m5reserved2({{
1096 warn("M5 reserved opcode ignored");
1097 }}, IsNonSpeculative);
1098 0x57: m5reserved3({{
1099 warn("M5 reserved opcode ignored");
1100 }}, IsNonSpeculative);
1101 0x58: m5reserved4({{
1102 warn("M5 reserved opcode ignored");
1103 }}, IsNonSpeculative);
1104 0x59: m5reserved5({{
1105 warn("M5 reserved opcode ignored");
1106 }}, IsNonSpeculative);