decoder.isa revision 2135
16145Snate@binkert.org// -*- mode:c++ -*- 26145Snate@binkert.org 36145Snate@binkert.org//////////////////////////////////////////////////////////////////// 46145Snate@binkert.org// 56145Snate@binkert.org// The actual MIPS32 ISA decoder 66145Snate@binkert.org// ----------------------------- 76145Snate@binkert.org// The following instructions are specified in the MIPS32 ISA 86145Snate@binkert.org// Specification. Decoding closely follows the style specified 96145Snate@binkert.org// in the MIPS32 ISAthe specification document starting with Table 106145Snate@binkert.org// A-2 (document available @ www.mips.com) 116145Snate@binkert.org// 126145Snate@binkert.org//@todo: Distinguish "unknown/future" use insts from "reserved" 136145Snate@binkert.org// ones 146145Snate@binkert.orgdecode OPCODE_HI default Unknown::unknown() { 156145Snate@binkert.org 166145Snate@binkert.org // Derived From ... Table A-2 MIPS32 ISA Manual 176145Snate@binkert.org 0x0: decode OPCODE_LO { 186145Snate@binkert.org 196145Snate@binkert.org 0x0: decode FUNCTION_HI { 206145Snate@binkert.org 0x0: decode FUNCTION_LO { 216145Snate@binkert.org 0x1: decode MOVCI { 226145Snate@binkert.org format BasicOp { 236145Snate@binkert.org 0: movf({{ if( xc->miscRegs.fpcr == 0) Rd = Rs}}); 246145Snate@binkert.org 1: movt({{ if( xc->miscRegs.fpcr == 1) Rd = Rs}}); 256145Snate@binkert.org } 266145Snate@binkert.org } 276145Snate@binkert.org 286145Snate@binkert.org format BasicOp { 296145Snate@binkert.org 307039Snate@binkert.org //Table A-3 Note: "1. Specific encodings of the rt, rd, and sa fields 316145Snate@binkert.org //are used to distinguish among the SLL, NOP, SSNOP and EHB functions." 326145Snate@binkert.org 337039Snate@binkert.org 0x0: sll({{ Rd = Rt.uw << SA; }}); 347039Snate@binkert.org 356145Snate@binkert.org 0x2: decode SRL { 367055Snate@binkert.org 0: srl({{ Rd = Rt.uw >> SA; }}); 377055Snate@binkert.org 387039Snate@binkert.org //Hardcoded assuming 32-bit ISA, probably need parameter here 397039Snate@binkert.org 1: rotr({{ Rd = (Rt.uw << (32 - SA)) | (Rt.uw >> SA);}}); 406154Snate@binkert.org } 416882SBrad.Beckmann@amd.com 426145Snate@binkert.org 0x3: sra({{ Rd = Rt.sw >> SA; }}); 436285Snate@binkert.org 446285Snate@binkert.org 0x4: sllv({{ Rd = Rt.uw << Rs<4:0>; }}); 457039Snate@binkert.org 467039Snate@binkert.org 0x6: decode SRLV { 477039Snate@binkert.org 0: srlv({{ Rd = Rt.uw >> Rs<4:0>; }}); 487039Snate@binkert.org 497039Snate@binkert.org //Hardcoded assuming 32-bit ISA, probably need parameter here 506145Snate@binkert.org 1: rotrv({{ Rd = (Rt.uw << (32 - Rs<4:0>)) | (Rt.uw >> Rs<4:0>);}}); 517039Snate@binkert.org } 527039Snate@binkert.org 537039Snate@binkert.org 0x7: srav({{ Rd = Rt.sw >> Rs<4:0>; }}); 547039Snate@binkert.org } 557039Snate@binkert.org } 566145Snate@binkert.org 576145Snate@binkert.org 0x1: decode FUNCTION_LO { 587055Snate@binkert.org 597055Snate@binkert.org //Table A-3 Note: "Specific encodings of the hint field are used 606145Snate@binkert.org //to distinguish JR from JR.HB and JALR from JALR.HB" 617039Snate@binkert.org format Jump { 627055Snate@binkert.org 0x0: decode HINT { 637039Snate@binkert.org 0:jr({{ NNPC = Rs; }},IsReturn); 646145Snate@binkert.org 656145Snate@binkert.org 1:jr_hb({{ NNPC = Rs; clear_exe_inst_hazards(); }},IsReturn); 667039Snate@binkert.org } 676145Snate@binkert.org 68 0x1: decode HINT { 69 0: jalr({{ NNPC = Rs; }},IsCall,IsReturn); 70 71 1: jalr_hb({{ NNPC = Rs; clear_exe_inst_hazards();}},IsCall,IsReturn); 72 } 73 } 74 75 format BasicOp { 76 0x2: movz({{ if (Rt == 0) Rd = Rs; }}); 77 0x3: movn({{ if (Rt != 0) Rd = Rs; }}); 78 } 79 80 format WarnUnimpl { 81 0x4: syscall();//{{ xc->syscall()}},IsNonSpeculative 82 0x5: break(); 83 0x7: sync(); 84 } 85 } 86 87 0x2: decode FUNCTION_LO { 88 format BasicOp { 89 0x0: mfhi({{ Rd = xc->miscRegs.hi; }}); 90 0x1: mthi({{ xc->miscRegs.hi = Rs; }}); 91 0x2: mflo({{ Rd = xc->miscRegs.lo; }}); 92 0x3: mtlo({{ xc->miscRegs.lo = Rs; }}); 93 } 94 } 95 96 0x3: decode FUNCTION_LO { 97 format IntOp { 98 0x0: mult({{ 99 int64_t temp1 = Rs.sw * Rt.sw; 100 xc->miscRegs.hi->temp1<63:32>; 101 xc->miscRegs.lo->temp1<31:0>; 102 }}); 103 104 0x1: multu({{ 105 int64_t temp1 = Rs.uw * Rt.uw; 106 xc->miscRegs.hi->temp1<63:32>; 107 xc->miscRegs.lo->temp1<31:0> 108 Rd.sw = Rs.uw * Rt.uw; 109 }}); 110 111 0x2: div({{ 112 xc->miscRegs.hi = Rs.sw % Rt.sw; 113 xc->miscRegs.lo = Rs.sw / Rt.sw; 114 }}); 115 116 0x3: divu({{ 117 xc->miscRegs.hi = Rs.uw % Rt.uw; 118 xc->miscRegs.lo = Rs.uw / Rt.uw; 119 }}); 120 } 121 } 122 123 0x4: decode FUNCTION_LO { 124 format IntOp { 125 0x0: add({{ Rd.sw = Rs.sw + Rt.sw;}}); 126 0x1: addu({{ Rd.uw = Rs.uw + Rt.uw;}}); 127 0x2: sub({{ Rd.sw = Rs.sw - Rt.sw;}}); 128 0x3: subu({{ Rd.uw = Rs.uw - Rt.uw;}}); 129 0x4: and({{ Rd.sw = Rs.uw & Rt.uw;}}); 130 0x5: or({{ Rd.sw = Rs.uw | Rt.uw;}}); 131 0x6: xor({{ Rd.sw = Rs.uw ^ Rt.uw;}}); 132 0x7: nor({{ Rd.sw = ~(Rs.uw | Rt.uw);}}); 133 } 134 } 135 136 0x5: decode FUNCTION_LO { 137 format IntOp{ 138 0x2: slt({{ Rd.sw = ( Rs.sw < Rt.sw ) ? 1 : 0}}); 139 0x3: sltu({{ Rd.uw = ( Rs.uw < Rt.uw ) ? 1 : 0}}); 140 } 141 } 142 143 0x6: decode FUNCTION_LO { 144 format BasicOp { 145 0x0: tge({{ cond = (Rs.sw >= Rt.sw); }}); 146 0x1: tgeu({{ cond = (Rs.uw >= Rt.uw); }}); 147 0x2: tlt({{ cond = (Rs.sw < Rt.sw); }}); 148 0x3: tltu({{ cond = (Rs.uw >= Rt.uw); }}); 149 0x4: teq({{ cond = (Rs.sw == Rt.sw); }}); 150 0x6: tne({{ cond = (Rs.sw != Rt.sw); }}); 151 } 152 } 153 } 154 155 0x1: decode REGIMM_HI { 156 0x0: decode REGIMM_LO { 157 format Branch { 158 0x0: bltz({{ cond = (Rs.sw < 0); }}); 159 0x1: bgez({{ cond = (Rs.sw >= 0); }}); 160 } 161 162 format BranchLikely { 163 //MIPS obsolete instructions 164 0x2: bltzl({{ cond = (Rs.sw < 0); }}); 165 0x3: bgezl({{ cond = (Rs.sw >= 0); }}); 166 } 167 } 168 169 0x1: decode REGIMM_LO { 170 format BasicOp { 171 0x0: tgei( {{ cond = (Rs.sw >= INTIMM); }}); 172 0x1: tgeiu({{ cond = (Rs.uw >= INTIMM); }}); 173 0x2: tlti( {{ cond = (Rs.sw < INTIMM); }}); 174 0x3: tltiu({{ cond = (Rs.uw < INTIMM); }}); 175 0x4: teqi( {{ cond = (Rs.sw == INTIMM);}}); 176 0x6: tnei( {{ cond = (Rs.sw != INTIMM);}}); 177 } 178 } 179 180 0x2: decode REGIMM_LO { 181 format Branch { 182 0x0: bltzal({{ cond = (Rs.sw < 0); }}, IsCall,IsReturn); 183 0x1: bgezal({{ cond = (Rs.sw >= 0); }}, IsCall,IsReturn); 184 } 185 186 format BranchLikely { 187 //Will be removed in future MIPS releases 188 0x2: bltzall({{ cond = (Rs.sw < 0); }}, IsCall, IsReturn); 189 0x3: bgezall({{ cond = (Rs.sw >= 0); }}, IsCall, IsReturn); 190 } 191 } 192 193 0x3: decode REGIMM_LO { 194 format WarnUnimpl { 195 0x7: synci(); 196 } 197 } 198 } 199 200 format Jump { 201 0x2: j({{ NNPC = (NPC & 0xF0000000) & (0x00000000 & JMPTARG << 2);}}); 202 203 0x3: jal({{ NNPC = (NPC & 0xF0000000) & (0x00000000 & JMPTARG << 2);}},IsCall,IsReturn); 204 } 205 206 format Branch { 207 0x4: beq({{ cond = (Rs.sw == 0); }}); 208 0x5: bne({{ cond = (Rs.sw != 0); }}); 209 0x6: blez({{ cond = (Rs.sw <= 0); }}); 210 0x7: bgtz({{ cond = (Rs.sw > 0); }}); 211 } 212 } 213 214 0x1: decode OPCODE_LO { 215 format IntOp { 216 0x0: addi({{ Rt.sw = Rs.sw + INTIMM; }}); 217 0x1: addiu({{ Rt.uw = Rs.uw + INTIMM;}}); 218 0x2: slti({{ Rt.sw = ( Rs.sw < INTIMM ) ? 1 : 0 }}); 219 0x3: sltiu({{ Rt.uw = ( Rs.uw < INTIMM ) ? 1 : 0 }}); 220 0x4: andi({{ Rt.sw = Rs.sw & INTIMM;}}); 221 0x5: ori({{ Rt.sw = Rs.sw | INTIMM;}}); 222 0x6: xori({{ Rt.sw = Rs.sw ^ INTIMM;}}); 223 0x7: lui({{ Rt = INTIMM << 16}}); 224 } 225 } 226 227 0x2: decode OPCODE_LO { 228 229 //Table A-11 MIPS32 COP0 Encoding of rs Field 230 0x0: decode RS_MSB { 231 0x0: decode RS { 232 format BasicOp { 233 0x0: mfc0({{ 234 //The contents of the coprocessor 0 register specified by the 235 //combination of rd and sel are loaded into general register 236 //rt. Note that not all coprocessor 0 registers support the 237 //sel field. In those instances, the sel field must be zero. 238 239 if (SEL > 0) 240 panic("Can't Handle Cop0 with register select yet\n"); 241 242 uint64_t reg_num = Rd.uw; 243 244 Rt = xc->miscRegs.cop0[reg_num]; 245 }}); 246 247 0x4: mtc0({{ 248 //The contents of the coprocessor 0 register specified by the 249 //combination of rd and sel are loaded into general register 250 //rt. Note that not all coprocessor 0 registers support the 251 //sel field. In those instances, the sel field must be zero. 252 253 if (SEL > 0) 254 panic("Can't Handle Cop0 with register select yet\n"); 255 256 uint64_t reg_num = Rd.uw; 257 258 xc->miscRegs.cop0[reg_num] = Rt; 259 }}); 260 261 0x8: mftr({{ 262 //The contents of the coprocessor 0 register specified by the 263 //combination of rd and sel are loaded into general register 264 //rt. Note that not all coprocessor 0 registers support the 265 //sel field. In those instances, the sel field must be zero. 266 267 //MT Code Needed Here 268 }}); 269 270 0xC: mttr({{ 271 //The contents of the coprocessor 0 register specified by the 272 //combination of rd and sel are loaded into general register 273 //rt. Note that not all coprocessor 0 registers support the 274 //sel field. In those instances, the sel field must be zero. 275 276 //MT Code Needed Here 277 }}); 278 279 280 0xA: rdpgpr({{ 281 //Accessing Previous Shadow Set Register Number 282 uint64_t prev = xc->miscRegs.cop0[SRSCtl][PSS]; 283 uint64_t reg_num = Rt.uw; 284 285 Rd = xc->shadowIntRegFile[prev][reg_num]; 286 }}); 287 288 0xB: decode RD { 289 290 0x0: decode SC { 291 0x0: dvpe({{ 292 Rt.sw = xc->miscRegs.cop0.MVPControl; 293 xc->miscRegs.cop0.MVPControl[EVP] = 0; 294 }}); 295 296 0x1: evpe({{ 297 Rt.sw = xc->miscRegs.cop0.MVPControl; 298 xc->miscRegs.cop0.MVPControl[EVP] = 1; 299 }}); 300 } 301 302 0x1: decode SC { 303 0x0: dmt({{ 304 Rt.sw = xc->miscRegs.cop0.VPEControl; 305 xc->miscRegs.cop0.VPEControl[THREAD_ENABLE] = 0; 306 }}); 307 308 0x1: emt({{ 309 Rt.sw = xc->miscRegs.cop0.VPEControl; 310 xc->miscRegs.cop0.VPEControl[THREAD_ENABLE] = 1; 311 }}); 312 } 313 314 0xC: decode SC { 315 0x0: di({{ 316 Rt.sw = xc->miscRegs.cop0.Status; 317 xc->miscRegs.cop0.Status[INTERRUPT_ENABLE] = 0; 318 }}); 319 320 0x1: ei({{ 321 Rt.sw = xc->miscRegs.cop0.Status; 322 xc->miscRegs.cop0.Status[INTERRUPT_ENABLE] = 1; 323 }}); 324 } 325 } 326 327 0xE: wrpgpr({{ 328 //Accessing Previous Shadow Set Register Number 329 uint64_t prev = xc->miscRegs.cop0[SRSCtl][PSS]; 330 uint64_t reg_num = Rd.uw; 331 332 xc->shadowIntRegFile[prev][reg_num] = Rt; 333 }}); 334 } 335 } 336 337 //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO 338 0x1: decode FUNCTION { 339 format BasicOp { 340 0x01: tlbr({{ }}); 341 0x02: tlbwi({{ }}); 342 0x06: tlbwr({{ }}); 343 0x08: tlbp({{ }}); 344 } 345 346 format WarnUnimpl { 347 0x18: eret(); 348 0x1F: deret(); 349 0x20: wait(); 350 } 351 } 352 } 353 354 //Table A-13 MIPS32 COP1 Encoding of rs Field 355 0x1: decode RS_MSB { 356 357 0x0: decode RS_HI { 358 0x0: decode RS_LO { 359 format FloatOp { 360 0x0: mfc1({{ Rt = Fs<31:0>; }}); 361 0x2: cfc1({{ Rt = xc->miscRegs.fpcr[Fs];}}); 362 0x3: mfhc1({{ Rt = Fs<63:32>;}}); 363 0x4: mtc1({{ Fs<31:0> = Rt}}); 364 0x6: ctc1({{ xc->miscRegs.fpcr[Fs] = Rt;}}); 365 0x7: mftc1({{ Fs<63:32> = Rt}}); 366 } 367 } 368 369 0x1: decode ND { 370 0x0: decode TF { 371 format Branch { 372 0x0: bc1f({{ cond = (xc->miscRegs.fpcr == 0); }}); 373 0x1: bc1t({{ cond = (xc->miscRegs.fpcr == 1); }}); 374 } 375 } 376 377 0x1: decode TF { 378 format BranchLikely { 379 0x0: bc1fl({{ cond = (xc->miscRegs.fpcr == 0); }}); 380 0x1: bc1tl({{ cond = (xc->miscRegs.fpcr == 1); }}); 381 } 382 } 383 } 384 } 385 386 0x1: decode RS_HI { 387 0x2: decode RS_LO { 388 389 //Table A-14 MIPS32 COP1 Encoding of Function Field When rs=S 390 //(( single-word )) 391 0x0: decode RS_HI { 392 0x0: decode RS_LO { 393 format FloatOp { 394 0x0: adds({{ Fd.sf = Fs.sf + Ft.sf;}}); 395 0x1: subs({{ Fd.sf = Fs.sf - Ft.sf;}}); 396 0x2: muls({{ Fd.sf = Fs.sf * Ft.sf;}}); 397 0x3: divs({{ Fd.sf = Fs.sf / Ft.sf;}}); 398 0x4: sqrts({{ Fd.sf = sqrt(Fs.sf);}}); 399 0x5: abss({{ Fd.sf = abs(Fs.sf);}}); 400 0x6: movs({{ Fd.sf = Fs.sf;}}); 401 0x7: negs({{ Fd.sf = -1 * Fs.sf;}}); 402 } 403 } 404 405 0x1: decode RS_LO { 406 //only legal for 64 bit-FP 407 format Float64Op { 408 0x0: round_l_s({{ Fd = convert_and_round(Fs.sf,RND_NEAREST,FP_LONG,FP_SINGLE);}}); 409 0x1: trunc_l_s({{ Fd = convert_and_round(Fs.sf,RND_ZERO,FP_LONG,FP_SINGLE);}}); 410 0x2: ceil_l_s({{ Fd = convert_and_round(Fs.sf,RND_UP,FP_LONG,FP_SINGLE);}}); 411 0x3: floor_l_s({{ Fd = convert_and_round(Fs.sf,RND_DOWN,FP_LONG,FP_SINGLE);}}); 412 } 413 414 format FloatOp { 415 0x4: round_w_s({{ Fd = convert_and_round(Fs.sf,RND_NEAREST,FP_WORD,FP_SINGLE);}}); 416 0x5: trunc_w_s({{ Fd = convert_and_round(Fs.sf,RND_ZERO,FP_WORD,FP_SINGLE);}}); 417 0x6: ceil_w_s({{ Fd = convert_and_round(Fs.sf,RND_UP,FP_WORD,FP_SINGLE);}}); 418 0x7: floor_w_s({{ Fd = convert_and_round(Fs.sf,RND_DOWN,FP_WORD,FP_SINGLE);}}); 419 } 420 } 421 422 0x2: decode RS_LO { 423 0x1: decode MOVCF { 424 format FloatOp { 425 0x0: movfs({{ if ( FPConditionCode(CC) == 0 ) Fd = Fs; }}); 426 0x1: movts({{ if ( FPConditionCode(CC) == 1 ) Fd = Fs;}}); 427 } 428 } 429 430 format BasicOp { 431 0x2: movzs({{ if (Rt == 0) Fd = Fs; }}); 432 0x3: movns({{ if (Rt != 0) Fd = Fs; }}); 433 } 434 435 format Float64Op { 436 0x5: recips({{ Fd = 1 / Fs; }}); 437 0x6: rsqrts({{ Fd = 1 / sqrt(Fs.ud);}}); 438 } 439 } 440 441 0x4: decode RS_LO { 442 443 format FloatOp { 444 0x1: cvt_d_s({{ int rnd_mode = xc->miscRegs.fcsr; 445 Fd = convert_and_round(Fs.sf,rnd_mode,FP_DOUBLE,FP_SINGLE); 446 }}); 447 448 0x4: cvt_w_s({{ int rnd_mode = xc->miscRegs.fcsr; 449 Fd = convert_and_round(Fs.sf,rnd_mode,FP_WORD,FP_SINGLE); 450 }}); 451 } 452 453 //only legal for 64 bit 454 format Float64Op { 455 0x5: cvt_l_s({{ int rnd_mode = xc->miscRegs.fcsr; 456 Fd = convert_and_round(Fs.sf,rnd_mode,FP_LONG,FP_SINGLE); 457 }}); 458 459 0x6: cvt_ps_s({{ Fd.df = Fs.df<31:0> | Ft.df<31:0>; }}); 460 } 461 } 462 } 463 464 //Table A-15 MIPS32 COP1 Encoding of Function Field When rs=D 465 0x1: decode RS_HI { 466 0x0: decode RS_LO { 467 format FloatOp { 468 0x0: addd({{ Fd.df = Fs.df + Ft.df;}}); 469 0x1: subd({{ Fd.df = Fs.df - Ft.df;}}); 470 0x2: muld({{ Fd.df = Fs.df * Ft.df;}}); 471 0x3: divd({{ Fd.df = Fs.df / Ft.df;}}); 472 0x4: sqrtd({{ Fd.df = sqrt(Fs.df);}}); 473 0x5: absd({{ Fd.df = abs(Fs.df);}}); 474 0x6: movd({{ Fd.df = Fs.df;}}); 475 0x7: negd({{ Fd.df = -1 * Fs.df;}}); 476 } 477 } 478 479 0x1: decode RS_LO { 480 //only legal for 64 bit 481 format Float64Op { 482 0x0: round_l_d({{ Fd = convert_and_round(Fs.df,RND_NEAREST,FP_LONG,FP_DOUBLE); }}); 483 0x1: trunc_l_d({{ Fd = convert_and_round(Fs.df,RND_ZERO,FP_LONG,FP_DOUBLE);}}); 484 0x2: ceil_l_d({{ Fd = convert_and_round(Fs.df,RND_UP,FP_LONG,FP_DOUBLE);}}); 485 0x3: floor_l_d({{ Fd = convert_and_round(Fs.df,RND_DOWN,FP_LONG,FP_DOUBLE);}}); 486 } 487 488 format FloatOp { 489 0x4: round_w_d({{ Fd = convert_and_round(Fs.df,RND_NEAREST,FP_LONG,FP_DOUBLE); }}); 490 0x5: trunc_w_d({{ Fd = convert_and_round(Fs.df,RND_ZERO,FP_LONG,FP_DOUBLE); }}); 491 0x6: ceil_w_d({{ Fd = convert_and_round(Fs.df,RND_UP,FP_LONG,FP_DOUBLE); }}); 492 0x7: floor_w_d({{ Fd = convert_and_round(Fs.df,RND_DOWN,FP_LONG,FP_DOUBLE); }}); 493 } 494 } 495 496 0x2: decode RS_LO { 497 0x1: decode MOVCF { 498 format FloatOp { 499 0x0: movfd({{ if (FPConditionCode(CC) == 0) Fd.df = Fs.df; }}); 500 0x1: movtd({{ if (FPConditionCode(CC) == 1) Fd.df = Fs.df; }}); 501 } 502 } 503 504 format BasicOp { 505 0x2: movzd({{ if (Rt == 0) Fd.df = Fs.df; }}); 506 0x3: movnd({{ if (Rt != 0) Fd.df = Fs.df; }}); 507 } 508 509 format Float64Op { 510 0x5: recipd({{ Fd.df = 1 / Fs.df}}); 511 0x6: rsqrtd({{ Fd.df = 1 / sqrt(Fs.df) }}); 512 } 513 } 514 515 0x4: decode RS_LO { 516 format FloatOp { 517 0x0: cvt_s_d({{ 518 int rnd_mode = xc->miscRegs.fcsr; 519 Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_DOUBLE); 520 }}); 521 522 0x4: cvt_w_d({{ 523 int rnd_mode = xc->miscRegs.fcsr; 524 Fd = convert_and_round(Fs.df,rnd_mode,FP_WORD,FP_DOUBLE); 525 }}); 526 } 527 528 //only legal for 64 bit 529 format Float64Op { 530 0x5: cvt_l_d({{ 531 int rnd_mode = xc->miscRegs.fcsr; 532 Fd = convert_and_round(Fs.df,rnd_mode,FP_LONG,FP_DOUBLE); 533 }}); 534 } 535 } 536 } 537 538 //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=W 539 0x4: decode FUNCTION { 540 format FloatOp { 541 0x20: cvt_s({{ 542 int rnd_mode = xc->miscRegs.fcsr; 543 Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_WORD); 544 }}); 545 546 0x21: cvt_d({{ 547 int rnd_mode = xc->miscRegs.fcsr; 548 Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_WORD); 549 }}); 550 } 551 } 552 553 //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=L1 554 //Note: "1. Format type L is legal only if 64-bit floating point operations 555 //are enabled." 556 0x5: decode FUNCTION_HI { 557 format FloatOp { 558 0x10: cvt_s_l({{ 559 int rnd_mode = xc->miscRegs.fcsr; 560 Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_LONG); 561 }}); 562 563 0x11: cvt_d_l({{ 564 int rnd_mode = xc->miscRegs.fcsr; 565 Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_LONG); 566 }}); 567 } 568 } 569 570 //Table A-17 MIPS64 COP1 Encoding of Function Field When rs=PS1 571 //Note: "1. Format type PS is legal only if 64-bit floating point operations 572 //are enabled. " 573 0x6: decode RS_HI { 574 0x0: decode RS_LO { 575 format Float64Op { 576 0x0: addps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 577 //Lower Halves Independently but we take simulator shortcut 578 Fd.df = Fs.df + Ft.df; 579 }}); 580 581 0x1: subps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 582 //Lower Halves Independently but we take simulator shortcut 583 Fd.df = Fs.df - Ft.df; 584 }}); 585 586 0x2: mulps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 587 //Lower Halves Independently but we take simulator shortcut 588 Fd.df = Fs.df * Ft.df; 589 }}); 590 591 0x5: absps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 592 //Lower Halves Independently but we take simulator shortcut 593 Fd.df = abs(Fs.df); 594 }}); 595 596 0x6: movps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 597 //Lower Halves Independently but we take simulator shortcut 598 Fd.df = Fs<31:0> | Ft<31:0>; 599 }}); 600 601 0x7: negps({{ //Must Check for Exception Here... Supposed to Operate on Upper and 602 //Lower Halves Independently but we take simulator shortcut 603 Fd.df = -1 * Fs.df; 604 }}); 605 } 606 } 607 608 0x2: decode RS_LO { 609 0x1: decode MOVCF { 610 format Float64Op { 611 0x0: movfps({{ if ( FPConditionCode(CC) == 0) Fd = Fs;}}); 612 0x1: movtps({{ if ( FPConditionCode(CC) == 0) Fd = Fs;}}); 613 } 614 } 615 616 format BasicOp { 617 0x2: movzps({{ if ( FPConditionCode(CC) == 0) Fd = Fs; }}); 618 0x3: movnps({{ if ( FPConditionCode(CC) == 0) Fd = Fs; }}); 619 } 620 621 } 622 623 0x4: decode RS_LO { 624 0x0: Float64Op::cvt_s_pu({{ 625 int rnd_mode = xc->miscRegs.fcsr; 626 Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_PS_HI); 627 }}); 628 } 629 630 0x5: decode RS_LO { 631 format Float64Op { 632 0x0: cvt_s_pl({{ 633 int rnd_mode = xc->miscRegs.fcsr; 634 Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_PS_LO); 635 }}); 636 0x4: pll({{ Fd.df = Fs<31:0> | Ft<31:0>}}); 637 0x5: plu({{ Fd.df = Fs<31:0> | Ft<63:32>}}); 638 0x6: pul({{ Fd.df = Fs<63:32> | Ft<31:0>}}); 639 0x7: puu({{ Fd.df = Fs<63:32 | Ft<63:32>}}); 640 } 641 } 642 } 643 } 644 } 645 } 646 647 //Table A-19 MIPS32 COP2 Encoding of rs Field 648 0x2: decode RS_MSB { 649 0x0: decode RS_HI { 650 0x0: decode RS_LO { 651 format WarnUnimpl { 652 0x0: mfc2(); 653 0x2: cfc2(); 654 0x3: mfhc2(); 655 0x4: mtc2(); 656 0x6: ctc2(); 657 0x7: mftc2(); 658 } 659 } 660 661 0x1: decode ND { 662 0x0: decode TF { 663 format WarnUnimpl { 664 0x0: bc2f(); 665 0x1: bc2t(); 666 } 667 } 668 669 0x1: decode TF { 670 format WarnUnimpl { 671 0x0: bc2fl(); 672 0x1: bc2tl(); 673 } 674 } 675 } 676 } 677 } 678 679 //Table A-20 MIPS64 COP1X Encoding of Function Field 1 680 //Note: "COP1X instructions are legal only if 64-bit floating point 681 //operations are enabled." 682 0x3: decode FUNCTION_HI { 683 0x0: decode FUNCTION_LO { 684 format LoadMemory2 { 685 0x0: lwxc1({{ EA = Rs + Rt; }},{{ Ft<31:0> = Mem.sf; }}); 686 0x1: ldxc1({{ EA = Rs + Rt; }},{{ Ft<63:0> = Mem.df; }}); 687 0x5: luxc1({{ //Need to make EA<2:0> = 0 688 EA = Rs + Rt; 689 }}, 690 {{ Ft<31:0> = Mem.df; }}); 691 } 692 } 693 694 0x1: decode FUNCTION_LO { 695 format StoreMemory2 { 696 0x0: swxc1({{ EA = Rs + Rt; }},{{ Mem.sf = Ft<31:0>; }}); 697 0x1: sdxc1({{ EA = Rs + Rt; }},{{ Mem.df = Ft<63:0>}}); 698 0x5: suxc1({{ //Need to make EA<2:0> = 0 699 EA = Rs + Rt; 700 }}, 701 {{ Mem.df = Ft<63:0>;}}); 702 } 703 704 0x7: WarnUnimpl::prefx(); 705 } 706 707 format FloatOp { 708 0x3: WarnUnimpl::alnv_ps(); 709 710 format BasicOp { 711 0x4: decode FUNCTION_LO { 712 0x0: madd_s({{ Fd.sf = (Fs.sf * Fs.sf) + Fr.sf; }}); 713 0x1: madd_d({{ Fd.df = (Fs.df * Fs.df) + Fr.df; }}); 714 0x6: madd_ps({{ 715 //Must Check for Exception Here... Supposed to Operate on Upper and 716 //Lower Halves Independently but we take simulator shortcut 717 Fd.df = (Fs.df * Fs.df) + Fr.df; 718 }}); 719 } 720 721 0x5: decode FUNCTION_LO { 722 0x0: msub_s({{ Fd.sf = (Fs.sf * Fs.sf) - Fr.sf; }}); 723 0x1: msub_d({{ Fd.df = (Fs.df * Fs.df) - Fr.df; }}); 724 0x6: msub_ps({{ 725 //Must Check for Exception Here... Supposed to Operate on Upper and 726 //Lower Halves Independently but we take simulator shortcut 727 Fd.df = (Fs.df * Fs.df) - Fr.df; 728 }}); 729 } 730 731 0x6: decode FUNCTION_LO { 732 0x0: nmadd_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }}); 733 0x1: nmadd_d({{ Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; }}); 734 0x6: nmadd_ps({{ 735 //Must Check for Exception Here... Supposed to Operate on Upper and 736 //Lower Halves Independently but we take simulator shortcut 737 Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; 738 }}); 739 } 740 741 0x7: decode FUNCTION_LO { 742 0x0: nmsub_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }}); 743 0x1: nmsub_d({{ Fd.df = (-1 * Fs.df * Fs.df) - Fr.df; }}); 744 0x6: nmsub_ps({{ 745 //Must Check for Exception Here... Supposed to Operate on Upper and 746 //Lower Halves Independently but we take simulator shortcut 747 Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; 748 }}); 749 } 750 } 751 } 752 } 753 754 //MIPS obsolete instructions 755 format BranchLikely { 756 0x4: beql({{ cond = (Rs.sw == 0); }}); 757 0x5: bnel({{ cond = (Rs.sw != 0); }}); 758 0x6: blezl({{ cond = (Rs.sw <= 0); }}); 759 0x7: bgtzl({{ cond = (Rs.sw > 0); }}); 760 } 761 } 762 763 0x3: decode OPCODE_LO default FailUnimpl::reserved() { 764 765 //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field 766 0x4: decode FUNCTION_HI { 767 768 0x0: decode FUNCTION_LO { 769 format IntOp { 770 0x0: madd({{ 771 int64_t temp1 = Hi.sw << 32 | Lo.sw >> 32; 772 temp1 = temp1 + (Rs.sw * Rt.sw); 773 xc->miscRegs.hi->temp1<63:32>; 774 xc->miscRegs.lo->temp1<31:0> 775 }}); 776 777 0x1: maddu({{ 778 int64_t temp1 = Hi.uw << 32 | Lo.uw >> 32; 779 temp1 = temp1 + (Rs.uw * Rt.uw); 780 xc->miscRegs.hi->temp1<63:32>; 781 xc->miscRegs.lo->temp1<31:0> 782 }}); 783 784 0x2: mul({{ Rd.sw = Rs.sw * Rt.sw; }}); 785 786 0x4: msub({{ 787 int64_t temp1 = Hi.sw << 32 | Lo.sw >> 32; 788 temp1 = temp1 - (Rs.sw * Rt.sw); 789 xc->miscRegs.hi->temp1<63:32>; 790 xc->miscRegs.lo->temp1<31:0> 791 }}); 792 793 0x5: msubu({{ 794 int64_t temp1 = Hi.uw << 32 | Lo.uw >> 32; 795 temp1 = temp1 - (Rs.uw * Rt.uw); 796 xc->miscRegs.hi->temp1<63:32>; 797 xc->miscRegs.lo->temp1<31:0> 798 }}); 799 } 800 } 801 802 0x4: decode FUNCTION_LO { 803 format BasicOp { 804 0x0: clz({{ 805 int cnt = 0; 806 int idx = 0; 807 while ( Rs.uw<idx>!= 1) { 808 cnt++; 809 idx--; 810 } 811 812 Rd.uw = cnt; 813 }}); 814 815 0x1: clo({{ 816 int cnt = 0; 817 int idx = 0; 818 while ( Rs.uw<idx>!= 0) { 819 cnt++; 820 idx--; 821 } 822 823 Rd.uw = cnt; 824 }}); 825 } 826 } 827 828 0x7: decode FUNCTION_LO { 829 0x7: WarnUnimpl::sdbbp(); 830 } 831 } 832 833 //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2 of the Architecture 834 0x7: decode FUNCTION_HI { 835 836 0x0: decode FUNCTION_LO { 837 format WarnUnimpl { 838 0x1: ext(); 839 0x4: ins(); 840 } 841 } 842 843 0x1: decode FUNCTION_LO { 844 format WarnUnimpl { 845 0x0: fork(); 846 0x1: yield(); 847 } 848 } 849 850 851 //Table A-10 MIPS32 BSHFL Encoding of sa Field 852 0x4: decode SA { 853 854 0x02: WarnUnimpl::wsbh(); 855 856 format BasicOp { 857 0x10: seb({{ Rd.sw = /* sext32(Rt<7>,24) | */ Rt<7:0>}}); 858 0x18: seh({{ Rd.sw = /* sext32(Rt<15>,16) | */ Rt<15:0>}}); 859 } 860 } 861 862 0x6: decode FUNCTION_LO { 863 0x7: BasicOp::rdhwr({{ Rt = xc->hwRegs[RD];}}); 864 } 865 } 866 } 867 868 0x4: decode OPCODE_LO default FailUnimpl::reserved() { 869 format LoadMemory { 870 0x0: lb({{ Rb.sw = Mem.sb; }}); 871 0x1: lh({{ Rb.sw = Mem.sh; }}); 872 0x2: lwl({{ Rb.sw = Mem.sw; }});//, WordAlign); 873 0x3: lw({{ Rb.uq = Mem.sb; }}); 874 0x4: lbu({{ Rb.uw = Mem.ub; }}); 875 0x5: lhu({{ Rb.uw = Mem.uh; }}); 876 0x6: lwr({{ Rb.uw = Mem.uw; }});//, WordAlign); 877 } 878 879 0x7: FailUnimpl::reserved(); 880 } 881 882 0x5: decode OPCODE_LO default FailUnimpl::reserved() { 883 format StoreMemory { 884 0x0: sb({{ Mem.ub = Rt<7:0>; }}); 885 0x1: sh({{ Mem.uh = Rt<15:0>; }}); 886 0x2: swl({{ Mem.ub = Rt<31:0>; }});//,WordAlign); 887 0x3: sw({{ Mem.ub = Rt<31:0>; }}); 888 0x6: swr({{ Mem.ub = Rt<31:0>; }});//,WordAlign); 889 } 890 891 format WarnUnimpl { 892 0x7: cache(); 893 } 894 895 } 896 897 0x6: decode OPCODE_LO default FailUnimpl::reserved() { 898 0x0: WarnUnimpl::ll(); 899 900 format LoadMemory { 901 0x1: lwc1({{ Ft<31:0> = Mem.sf; }}); 902 0x5: ldc1({{ Ft<63:0> = Mem.df; }}); 903 } 904 } 905 906 0x7: decode OPCODE_LO default FailUnimpl::reserved() { 907 0x0: WarnUnimpl::sc(); 908 909 format StoreMemory { 910 0x1: swc1({{ Mem.sf = Ft<31:0>; }}); 911 0x5: sdc1({{ Mem.df = Ft<63:0>; }}); 912 } 913 914 } 915} 916 917 918