decoder.isa revision 2605
1 // -*- mode:c++ -*- 2 3//////////////////////////////////////////////////////////////////// 4// 5// The actual MIPS32 ISA decoder 6// ----------------------------- 7// The following instructions are specified in the MIPS32 ISA 8// Specification. Decoding closely follows the style specified 9// in the MIPS32 ISAthe specification document starting with Table 10// A-2 (document available @ www.mips.com) 11// 12//@todo: Distinguish "unknown/future" use insts from "reserved" 13// ones 14decode OPCODE_HI default Unknown::unknown() { 15 16 // Derived From ... Table A-2 MIPS32 ISA Manual 17 0x0: decode OPCODE_LO { 18 19 0x0: decode FUNCTION_HI { 20 0x0: decode FUNCTION_LO { 21 0x1: decode MOVCI { 22 format BasicOp { 23 0: movf({{ if (getFPConditionCode(CC) == 0) Rd = Rs}}); 24 1: movt({{ if (getFPConditionCode(CC) == 1) Rd = Rs}}); 25 } 26 } 27 28 format BasicOp { 29 30 //Table A-3 Note: "1. Specific encodings of the rt, rd, and sa fields 31 //are used to distinguish among the SLL, NOP, SSNOP and EHB functions. 32 0x0: decode RS { 33 0x0: decode RT { //fix Nop traditional vs. Nop converted disassembly later 34 0x0: decode RD default Nop::nop(){ 35 0x0: decode SA { 36 0x1: ssnop({{ ; }}); //really sll r0,r0,1 37 0x3: ehb({{ ; }}); //really sll r0,r0,3 38 } 39 } 40 41 default: sll({{ Rd = Rt.uw << SA; }}); 42 } 43 44 } 45 46 0x2: decode RS_SRL { 47 0x0:decode SRL { 48 0: srl({{ Rd = Rt.uw >> SA; }}); 49 50 //Hardcoded assuming 32-bit ISA, probably need parameter here 51 1: rotr({{ Rd = (Rt.uw << (32 - SA)) | (Rt.uw >> SA);}}); 52 } 53 } 54 55 0x3: decode RS { 56 0x0: sra({{ 57 uint32_t temp = Rt >> SA; 58 59 if ( (Rt & 0x80000000) > 0 ) { 60 uint32_t mask = 0x80000000; 61 for(int i=0; i < SA; i++) { 62 temp |= mask; 63 mask = mask >> 1; 64 } 65 } 66 67 Rd = temp; 68 }}); 69 } 70 71 0x4: sllv({{ Rd = Rt.uw << Rs<4:0>; }}); 72 73 0x6: decode SRLV { 74 0: srlv({{ Rd = Rt.uw >> Rs<4:0>; }}); 75 76 //Hardcoded assuming 32-bit ISA, probably need parameter here 77 1: rotrv({{ Rd = (Rt.uw << (32 - Rs<4:0>)) | (Rt.uw >> Rs<4:0>);}}); 78 } 79 80 0x7: srav({{ 81 int shift_amt = Rs<4:0>; 82 83 uint32_t temp = Rt >> shift_amt; 84 85 if ( (Rt & 0x80000000) > 0 ) { 86 uint32_t mask = 0x80000000; 87 for(int i=0; i < shift_amt; i++) { 88 temp |= mask; 89 mask = mask >> 1; 90 } 91 } 92 93 Rd = temp; 94 }}); 95 } 96 } 97 98 0x1: decode FUNCTION_LO { 99 100 //Table A-3 Note: "Specific encodings of the hint field are used 101 //to distinguish JR from JR.HB and JALR from JALR.HB" 102 format Jump { 103 0x0: decode HINT { 104 0:jr({{ NNPC = Rs & ~1; }},IsReturn); 105 106 1:jr_hb({{ NNPC = Rs & ~1; clear_exe_inst_hazards(); }},IsReturn); 107 } 108 109 0x1: decode HINT { 110 0: jalr({{ Rd = NNPC; NNPC = Rs; }},IsCall,IsReturn); 111 112 1: jalr_hb({{ Rd = NNPC; NNPC = Rs; clear_exe_inst_hazards();}},IsCall,IsReturn); 113 } 114 } 115 116 format BasicOp { 117 0x2: movz({{ if (Rt == 0) Rd = Rs; }}); 118 0x3: movn({{ if (Rt != 0) Rd = Rs; }}); 119 } 120 121 format BasicOp { 122 0x4: syscall({{ xc->syscall(R2); }},IsNonSpeculative); 123 0x5: break({{ panic("Not implemented break yet"); }},IsNonSpeculative); 124 0x7: sync({{ panic("Not implemented sync yet"); }},IsNonSpeculative); 125 } 126 } 127 128 0x2: decode FUNCTION_LO { 129 format BasicOp { 130 0x0: mfhi({{ Rd = xc->readMiscReg(Hi); }}); 131 0x1: mthi({{ xc->setMiscReg(Hi,Rs); }}); 132 0x2: mflo({{ Rd = xc->readMiscReg(Lo); }}); 133 0x3: mtlo({{ xc->setMiscReg(Lo,Rs); }}); 134 } 135 } 136 137 0x3: decode FUNCTION_LO { 138 format IntOp { 139 0x0: mult({{ 140 int64_t temp1 = Rs.sd * Rt.sd; 141 xc->setMiscReg(Hi,temp1<63:32>); 142 xc->setMiscReg(Lo,temp1<31:0>); 143 }}); 144 145 0x1: multu({{ 146 uint64_t temp1 = Rs.ud * Rt.ud; 147 xc->setMiscReg(Hi,temp1<63:32>); 148 xc->setMiscReg(Lo,temp1<31:0>); 149 }}); 150 151 0x2: div({{ 152 xc->setMiscReg(Hi,Rs.sd % Rt.sd); 153 xc->setMiscReg(Lo,Rs.sd / Rt.sd); 154 }}); 155 156 0x3: divu({{ 157 xc->setMiscReg(Hi,Rs.ud % Rt.ud); 158 xc->setMiscReg(Lo,Rs.ud / Rt.ud); 159 }}); 160 } 161 } 162 163 0x4: decode HINT { 164 0x0: decode FUNCTION_LO { 165 format IntOp { 166 0x0: add({{ Rd.sw = Rs.sw + Rt.sw;/*Trap on Overflow*/}}); 167 0x1: addu({{ Rd.sw = Rs.sw + Rt.sw;}}); 168 0x2: sub({{ Rd.sw = Rs.sw - Rt.sw; /*Trap on Overflow*/}}); 169 0x3: subu({{ Rd.sw = Rs.sw - Rt.sw;}}); 170 0x4: and({{ Rd = Rs & Rt;}}); 171 0x5: or({{ Rd = Rs | Rt;}}); 172 0x6: xor({{ Rd = Rs ^ Rt;}}); 173 0x7: nor({{ Rd = ~(Rs | Rt);}}); 174 } 175 } 176 } 177 178 0x5: decode HINT { 179 0x0: decode FUNCTION_LO { 180 format IntOp{ 181 0x2: slt({{ Rd.sw = ( Rs.sw < Rt.sw ) ? 1 : 0}}); 182 0x3: sltu({{ Rd.uw = ( Rs.uw < Rt.uw ) ? 1 : 0}}); 183 } 184 } 185 } 186 187 0x6: decode FUNCTION_LO { 188 format Trap { 189 0x0: tge({{ cond = (Rs.sw >= Rt.sw); }}); 190 0x1: tgeu({{ cond = (Rs.uw >= Rt.uw); }}); 191 0x2: tlt({{ cond = (Rs.sw < Rt.sw); }}); 192 0x3: tltu({{ cond = (Rs.uw >= Rt.uw); }}); 193 0x4: teq({{ cond = (Rs.sw == Rt.sw); }}); 194 0x6: tne({{ cond = (Rs.sw != Rt.sw); }}); 195 } 196 } 197 } 198 199 0x1: decode REGIMM_HI { 200 0x0: decode REGIMM_LO { 201 format Branch { 202 0x0: bltz({{ cond = (Rs.sw < 0); }}); 203 0x1: bgez({{ cond = (Rs.sw >= 0); }}); 204 } 205 206 format BranchLikely { 207 0x2: bltzl({{ cond = (Rs.sw < 0); }}); 208 0x3: bgezl({{ cond = (Rs.sw >= 0); }}); 209 } 210 } 211 212 0x1: decode REGIMM_LO { 213 format Trap { 214 0x0: tgei( {{ cond = (Rs.sw >= INTIMM); }}); 215 0x1: tgeiu({{ cond = (Rs.uw >= INTIMM); }}); 216 0x2: tlti( {{ cond = (Rs.sw < INTIMM); }}); 217 0x3: tltiu({{ cond = (Rs.uw < INTIMM); }}); 218 0x4: teqi( {{ cond = (Rs.sw == INTIMM);}}); 219 0x6: tnei( {{ cond = (Rs.sw != INTIMM);}}); 220 } 221 } 222 223 0x2: decode REGIMM_LO { 224 format Branch { 225 0x0: bltzal({{ cond = (Rs.sw < 0); }}, IsCall,IsReturn); 226 0x1: bgezal({{ cond = (Rs.sw >= 0); }}, IsCall,IsReturn); 227 } 228 229 format BranchLikely { 230 0x2: bltzall({{ cond = (Rs.sw < 0); }}, IsCall, IsReturn); 231 0x3: bgezall({{ cond = (Rs.sw >= 0); }}, IsCall, IsReturn); 232 } 233 } 234 235 0x3: decode REGIMM_LO { 236 format WarnUnimpl { 237 0x7: synci(); 238 } 239 } 240 } 241 242 format Jump { 243 0x2: j({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2);}}); 244 245 0x3: jal({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2); }},IsCall,IsReturn); 246 } 247 248 format Branch { 249 0x4: beq({{ cond = (Rs.sw == Rt.sw); }}); 250 0x5: bne({{ cond = (Rs.sw != Rt.sw); }}); 251 0x6: decode RT { 252 0x0: blez({{ cond = (Rs.sw <= 0); }}); 253 } 254 255 0x7: decode RT { 256 0x0: bgtz({{ cond = (Rs.sw > 0); }}); 257 } 258 } 259 } 260 261 0x1: decode OPCODE_LO { 262 format IntOp { 263 0x0: addi({{ Rt.sw = Rs.sw + imm; /*Trap If Overflow*/}}); 264 0x1: addiu({{ Rt.sw = Rs.sw + imm;}}); 265 0x2: slti({{ Rt.sw = ( Rs.sw < imm) ? 1 : 0 }}); 266 0x3: sltiu({{ Rt.uw = ( Rs.uw < (uint32_t)sextImm ) ? 1 : 0 }}); 267 0x4: andi({{ Rt.sw = Rs.sw & zextImm;}}); 268 0x5: ori({{ Rt.sw = Rs.sw | zextImm;}}); 269 0x6: xori({{ Rt.sw = Rs.sw ^ zextImm;}}); 270 271 0x7: decode RS { 272 0x0: lui({{ Rt = imm << 16}}); 273 } 274 } 275 } 276 277 0x2: decode OPCODE_LO { 278 279 //Table A-11 MIPS32 COP0 Encoding of rs Field 280 0x0: decode RS_MSB { 281 0x0: decode RS { 282 format System { 283 0x0: mfc0({{ 284 //uint64_t reg_num = Rd.uw; 285 286 Rt = xc->readMiscReg(RD << 5 | SEL); 287 }}); 288 289 0x4: mtc0({{ 290 //uint64_t reg_num = Rd.uw; 291 292 xc->setMiscReg(RD << 5 | SEL,Rt); 293 }}); 294 295 0x8: mftr({{ 296 //The contents of the coprocessor 0 register specified by the 297 //combination of rd and sel are loaded into general register 298 //rt. Note that not all coprocessor 0 registers support the 299 //sel field. In those instances, the sel field must be zero. 300 301 //MT Code Needed Here 302 }}); 303 304 0xC: mttr({{ 305 //The contents of the coprocessor 0 register specified by the 306 //combination of rd and sel are loaded into general register 307 //rt. Note that not all coprocessor 0 registers support the 308 //sel field. In those instances, the sel field must be zero. 309 310 //MT Code Needed Here 311 }}); 312 313 314 0xA: rdpgpr({{ 315 //Accessing Previous Shadow Set Register Number 316 //uint64_t prev = xc->readMiscReg(SRSCtl)/*[PSS]*/; 317 //uint64_t reg_num = Rt.uw; 318 319 //Rd = xc->regs.IntRegFile[prev]; 320 //Rd = xc->shadowIntRegFile[prev][reg_num]; 321 }}); 322 323 0xB: decode RD { 324 325 0x0: decode SC { 326 0x0: dvpe({{ 327 Rt.sw = xc->readMiscReg(MVPControl); 328 xc->setMiscReg(MVPControl,0); 329 }}); 330 331 0x1: evpe({{ 332 Rt.sw = xc->readMiscReg(MVPControl); 333 xc->setMiscReg(MVPControl,1); 334 }}); 335 } 336 337 0x1: decode SC { 338 0x0: dmt({{ 339 Rt.sw = xc->readMiscReg(VPEControl); 340 xc->setMiscReg(VPEControl,0); 341 }}); 342 343 0x1: emt({{ 344 Rt.sw = xc->readMiscReg(VPEControl); 345 xc->setMiscReg(VPEControl,1); 346 }}); 347 } 348 349 0xC: decode SC { 350 0x0: di({{ 351 Rt.sw = xc->readMiscReg(Status); 352 xc->setMiscReg(Status,0); 353 }}); 354 355 0x1: ei({{ 356 Rt.sw = xc->readMiscReg(Status); 357 xc->setMiscReg(Status,1); 358 }}); 359 } 360 } 361 362 0xE: wrpgpr({{ 363 //Accessing Previous Shadow Set Register Number 364 //uint64_t prev = xc->readMiscReg(SRSCtl/*[PSS]*/); 365 //uint64_t reg_num = Rd.uw; 366 367 //xc->regs.IntRegFile[prev]; 368 //xc->shadowIntRegFile[prev][reg_num] = Rt; 369 }}); 370 } 371 } 372 373 //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO 374 0x1: decode FUNCTION { 375 format System { 376 0x01: tlbr({{ }}); 377 0x02: tlbwi({{ }}); 378 0x06: tlbwr({{ }}); 379 0x08: tlbp({{ }}); 380 } 381 382 format WarnUnimpl { 383 0x18: eret(); 384 0x1F: deret(); 385 0x20: wait(); 386 } 387 } 388 } 389 390 //Table A-13 MIPS32 COP1 Encoding of rs Field 391 0x1: decode RS_MSB { 392 393 0x0: decode RS_HI { 394 0x0: decode RS_LO { 395 format FloatOp { 396 0x0: mfc1 ({{ Rt.uw = Fs.uw<31:0>; }}); 397 0x3: mfhc1({{ Rt.uw = Fs.ud<63:32>;}}); 398 0x4: mtc1 ({{ Fs.uw = Rt.uw; }}); 399 0x7: mthc1({{ 400 uint64_t fs_hi = Rt.ud << 32; 401 uint64_t fs_lo = Fs.ud & 0x0000FFFF; 402 Fs.ud = fs_hi & fs_lo; 403 }}); 404 } 405 406 format System { 407 0x2: cfc1({{ 408 uint32_t fcsr_reg = xc->readMiscReg(FCSR); 409 410 switch (FS) 411 { 412 case 0: 413 Rt = xc->readMiscReg(FIR); 414 break; 415 case 25: 416 Rt = 0 | (fcsr_reg & 0xFE000000) >> 24 | (fcsr_reg & 0x00800000) >> 23; 417 break; 418 case 26: 419 Rt = 0 | (fcsr_reg & 0x0003F07C); 420 break; 421 case 28: 422 Rt = 0 | (fcsr_reg); 423 break; 424 case 31: 425 Rt = fcsr_reg; 426 break; 427 default: 428 panic("FP Control Value (%d) Not Available. Ignoring Access to" 429 "Floating Control Status Register",fcsr_reg); 430 } 431 }}); 432 433 0x6: ctc1({{ 434 uint32_t fcsr_reg = xc->readMiscReg(FCSR); 435 uint32_t temp; 436 437 switch (FS) 438 { 439 case 25: 440 temp = 0 | (Rt.uw<7:1> << 25) // move 31...25 441 | (fcsr_reg & 0x01000000) // bit 24 442 | (fcsr_reg & 0x004FFFFF);// bit 22...0 443 break; 444 445 case 26: 446 temp = 0 | (fcsr_reg & 0xFFFC0000) // move 31...18 447 | Rt.uw<17:12> << 12 // bit 17...12 448 | (fcsr_reg & 0x00000F80) << 7// bit 11...7 449 | Rt.uw<6:2> << 2 // bit 6...2 450 | (fcsr_reg & 0x00000002); // bit 1...0 451 break; 452 453 case 28: 454 temp = 0 | (fcsr_reg & 0xFE000000) // move 31...25 455 | Rt.uw<2:2> << 24 // bit 24 456 | (fcsr_reg & 0x00FFF000) << 23// bit 23...12 457 | Rt.uw<11:7> << 7 // bit 24 458 | (fcsr_reg & 0x000007E) 459 | Rt.uw<1:0>;// bit 22...0 460 break; 461 462 case 31: 463 temp = Rt.uw; 464 break; 465 466 default: 467 panic("FP Control Value (%d) Not Available. Ignoring Access to" 468 "Floating Control Status Register",fcsr_reg); 469 } 470 471 xc->setMiscReg(FCSR,temp); 472 }}); 473 } 474 } 475 476 0x1: decode ND { 477 0x0: decode TF { 478 format Branch { 479 0x0: bc1f({{ cond = (getFPConditionCode(CC) == 0); }}); 480 0x1: bc1t({{ cond = (getFPConditionCode(CC) == 1); }}); 481 } 482 } 483 484 0x1: decode TF { 485 format BranchLikely { 486 0x0: bc1fl({{ cond = (getFPConditionCode(CC) == 0); }}); 487 0x1: bc1tl({{ cond = (getFPConditionCode(CC) == 1); }}); 488 } 489 } 490 } 491 } 492 493 0x1: decode RS_HI { 494 0x2: decode RS_LO { 495 496 //Table A-14 MIPS32 COP1 Encoding of Function Field When rs=S 497 //(( single-word )) 498 0x0: decode FUNCTION_HI { 499 0x0: decode FUNCTION_LO { 500 format FloatOp { 501 0x0: add_s({{ Fd.sf = Fs.sf + Ft.sf;}}); 502 0x1: sub_s({{ Fd.sf = Fs.sf - Ft.sf;}}); 503 0x2: mul_s({{ Fd.sf = Fs.sf * Ft.sf;}}); 504 0x3: div_s({{ Fd.sf = Fs.sf / Ft.sf;}}); 505 0x4: sqrt_s({{ Fd.sf = sqrt(Fs.sf);}}); 506 0x5: abs_s({{ Fd.sf = fabs(Fs.sf);}}); 507 0x6: mov_s({{ Fd.sf = Fs.sf;}}); 508 0x7: neg_s({{ Fd.sf = -1 * Fs.sf;}}); 509 } 510 } 511 512 0x1: decode FUNCTION_LO { 513 format Float64Op { 514 0x0: round_l_s({{ 515 Fd.ud = fpConvert(roundFP(Fs.sf), SINGLE_TO_LONG); 516 }}); 517 518 0x1: trunc_l_s({{ 519 Fd.ud = fpConvert(truncFP(Fs.sf), SINGLE_TO_LONG); 520 }}); 521 522 0x2: ceil_l_s({{ 523 Fd.ud = fpConvert(ceil(Fs.sf), SINGLE_TO_LONG); 524 }}); 525 526 0x3: floor_l_s({{ 527 Fd.ud = fpConvert(floor(Fs.sf), SINGLE_TO_LONG); 528 }}); 529 } 530 531 format FloatOp { 532 0x4: round_w_s({{ 533 Fd.uw = fpConvert(roundFP(Fs.sf), SINGLE_TO_WORD); 534 }}); 535 536 0x5: trunc_w_s({{ 537 Fd.uw = fpConvert(truncFP(Fs.sf), SINGLE_TO_WORD); 538 }}); 539 540 0x6: ceil_w_s({{ 541 Fd.uw = fpConvert(ceil(Fs.sf), SINGLE_TO_WORD); 542 }}); 543 544 0x7: floor_w_s({{ 545 Fd.uw = fpConvert(floor(Fs.sf), SINGLE_TO_WORD); 546 }}); 547 } 548 } 549 550 0x2: decode FUNCTION_LO { 551 0x1: decode MOVCF { 552 format FloatOp { 553 0x0: movf_s({{if (getFPConditionCode(CC) == 0) Fd = Fs;}}); 554 0x1: movt_s({{if (getFPConditionCode(CC) == 1) Fd = Fs;}}); 555 } 556 } 557 558 format FloatOp { 559 0x2: movz_s({{ if (Rt == 0) Fd = Fs; }}); 560 0x3: movn_s({{ if (Rt != 0) Fd = Fs; }}); 561 0x5: recip_s({{ Fd = 1 / Fs; }}); 562 0x6: rsqrt_s({{ Fd = 1 / sqrt(Fs);}}); 563 } 564 } 565 566 0x4: decode FUNCTION_LO { 567 568 format FloatConvertOp { 569 0x1: cvt_d_s({{ 570 Fd.ud = fpConvert(Fs.sf, SINGLE_TO_DOUBLE); 571 }}); 572 573 0x4: cvt_w_s({{ 574 Fd.uw = fpConvert(Fs.sf, SINGLE_TO_WORD); 575 }}); 576 } 577 578 format FloatConvertOp { 579 0x5: cvt_l_s({{ 580 Fd.ud = fpConvert(Fs.sf, SINGLE_TO_LONG); 581 }}); 582 583 0x6: cvt_ps_st({{ 584 Fd.ud = (uint64_t)Fs.uw << 32 | (uint64_t)Ft.uw; 585 }}); 586 } 587 } 588 589 0x6: decode FUNCTION_LO { 590 format FloatCompareOp { 591 0x0: c_f_s({{ cond = 0; }}); 592 593 0x1: c_un_s({{ 594 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 595 cond = 1; 596 else 597 cond = 0; 598 }}); 599 600 0x2: c_eq_s({{ 601 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 602 cond = 0; 603 else 604 cond = (Fs.sf == Ft.sf); 605 }}); 606 607 0x3: c_ueq_s({{ 608 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 609 cond = 1; 610 else 611 cond = (Fs.sf == Ft.sf); 612 }}); 613 614 0x4: c_olt_s({{ 615 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 616 cond = 0; 617 else 618 cond = (Fs.sf < Ft.sf); 619 }}); 620 621 0x5: c_ult_s({{ 622 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 623 cond = 1; 624 else 625 cond = (Fs.sf < Ft.sf); 626 }}); 627 628 0x6: c_ole_s({{ 629 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 630 cond = 0; 631 else 632 cond = (Fs.sf <= Ft.sf); 633 }}); 634 635 0x7: c_ule_s({{ 636 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 637 cond = 1; 638 else 639 cond = (Fs.sf <= Ft.sf); 640 }}); 641 } 642 } 643 644 0x7: decode FUNCTION_LO { 645 format FloatCompareWithXcptOp { 646 0x0: c_sf_s({{ cond = 0; }}); 647 648 0x1: c_ngle_s({{ 649 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 650 cond = 1; 651 else 652 cond = 0; 653 }}); 654 655 0x2: c_seq_s({{ 656 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 657 cond = 0; 658 else 659 cond = (Fs.sf == Ft.sf); 660 }}); 661 662 0x3: c_ngl_s({{ 663 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 664 cond = 1; 665 else 666 cond = (Fs.sf == Ft.sf); 667 }}); 668 669 0x4: c_lt_s({{ 670 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 671 cond = 0; 672 else 673 cond = (Fs.sf < Ft.sf); 674 }}); 675 676 0x5: c_nge_s({{ 677 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 678 cond = 1; 679 else 680 cond = (Fs.sf < Ft.sf); 681 }}); 682 683 0x6: c_le_s({{ 684 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 685 cond = 0; 686 else 687 cond = (Fs.sf <= Ft.sf); 688 }}); 689 690 0x7: c_ngt_s({{ 691 if (unorderedFP(Fs.uw) || unorderedFP(Ft.uw)) 692 cond = 1; 693 else 694 cond = (Fs.sf <= Ft.sf); 695 }}); 696 } 697 } 698 } 699 700 //Table A-15 MIPS32 COP1 Encoding of Function Field When rs=D 701 0x1: decode FUNCTION_HI { 702 0x0: decode FUNCTION_LO { 703 format FloatOp { 704 0x0: add_d({{ Fd.df = Fs.df + Ft.df;}}); 705 0x1: sub_d({{ Fd.df = Fs.df - Ft.df;}}); 706 0x2: mul_d({{ Fd.df = Fs.df * Ft.df;}}); 707 0x3: div_d({{ Fd.df = Fs.df / Ft.df;}}); 708 0x4: sqrt_d({{ Fd.df = sqrt(Fs.df);}}); 709 0x5: abs_d({{ Fd.df = fabs(Fs.df);}}); 710 0x6: mov_d({{ Fd.ud = Fs.ud;}}); 711 0x7: neg_d({{ Fd.df = -1 * Fs.df;}}); 712 } 713 } 714 715 0x1: decode FUNCTION_LO { 716 format FloatOp { 717 0x0: round_l_d({{ 718 Fd.ud = fpConvert(roundFP(Fs.ud), DOUBLE_TO_LONG); 719 }}); 720 721 0x1: trunc_l_d({{ 722 Fd.ud = fpConvert(truncFP(Fs.ud), DOUBLE_TO_LONG); 723 }}); 724 725 0x2: ceil_l_d({{ 726 Fd.ud = fpConvert(ceil(Fs.ud), DOUBLE_TO_LONG); 727 }}); 728 729 0x3: floor_l_d({{ 730 Fd.ud = fpConvert(floor(Fs.ud), DOUBLE_TO_LONG); 731 }}); 732 } 733 734 format FloatOp { 735 0x4: round_w_d({{ 736 Fd.uw = fpConvert(roundFP(Fs.ud), DOUBLE_TO_WORD); 737 }}); 738 739 0x5: trunc_w_d({{ 740 Fd.uw = fpConvert(truncFP(Fs.ud), DOUBLE_TO_WORD); 741 }}); 742 743 0x6: ceil_w_d({{ 744 Fd.uw = fpConvert(ceil(Fs.ud), DOUBLE_TO_WORD); 745 }}); 746 747 0x7: floor_w_d({{ 748 Fd.uw = fpConvert(floor(Fs.ud), DOUBLE_TO_WORD); 749 }}); 750 } 751 } 752 753 0x2: decode FUNCTION_LO { 754 0x1: decode MOVCF { 755 format FloatOp { 756 0x0: movf_d({{if (getFPConditionCode(CC) == 0) Fd.df = Fs.df; }}); 757 0x1: movt_d({{if (getFPConditionCode(CC) == 1) Fd.df = Fs.df; }}); 758 } 759 } 760 761 format BasicOp { 762 0x2: movz_d({{ if (Rt == 0) Fd.df = Fs.df; }}); 763 0x3: movn_d({{ if (Rt != 0) Fd.df = Fs.df; }}); 764 } 765 766 format FloatOp { 767 0x5: recip_d({{ Fd.df = 1 / Fs.df}}); 768 0x6: rsqrt_d({{ Fd.df = 1 / sqrt(Fs.df) }}); 769 } 770 } 771 772 0x4: decode FUNCTION_LO { 773 format FloatOp { 774 0x0: cvt_s_d({{ 775 Fd.uw = fpConvert(Fs.ud, DOUBLE_TO_SINGLE); 776 }}); 777 778 0x4: cvt_w_d({{ 779 Fd.uw = fpConvert(Fs.ud, DOUBLE_TO_WORD); 780 }}); 781 782 0x5: cvt_l_d({{ 783 Fd.ud = fpConvert(Fs.ud, DOUBLE_TO_LONG); 784 }}); 785 } 786 } 787 788 0x6: decode FUNCTION_LO { 789 format FloatCompareOp { 790 0x0: c_f_d({{ cond = 0; }}); 791 792 0x1: c_un_d({{ 793 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 794 cond = 1; 795 else 796 cond = 0; 797 }}); 798 799 0x2: c_eq_d({{ 800 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 801 cond = 0; 802 else 803 cond = (Fs.df == Ft.df); 804 }}); 805 806 0x3: c_ueq_d({{ 807 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 808 cond = 1; 809 else 810 cond = (Fs.df == Ft.df); 811 }}); 812 813 0x4: c_olt_d({{ 814 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 815 cond = 0; 816 else 817 cond = (Fs.df < Ft.df); 818 }}); 819 820 0x5: c_ult_d({{ 821 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 822 cond = 1; 823 else 824 cond = (Fs.df < Ft.df); 825 }}); 826 827 0x6: c_ole_d({{ 828 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 829 cond = 0; 830 else 831 cond = (Fs.df <= Ft.df); 832 }}); 833 834 0x7: c_ule_d({{ 835 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 836 cond = 1; 837 else 838 cond = (Fs.df <= Ft.df); 839 }}); 840 } 841 } 842 843 0x7: decode FUNCTION_LO { 844 format FloatCompareWithXcptOp { 845 0x0: c_sf_d({{ cond = 0; }}); 846 847 0x1: c_ngle_d({{ 848 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 849 cond = 1; 850 else 851 cond = 0; 852 }}); 853 854 0x2: c_seq_d({{ 855 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 856 cond = 0; 857 else 858 cond = (Fs.df == Ft.df); 859 }}); 860 861 0x3: c_ngl_d({{ 862 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 863 cond = 1; 864 else 865 cond = (Fs.df == Ft.df); 866 }}); 867 868 0x4: c_lt_d({{ 869 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 870 cond = 0; 871 else 872 cond = (Fs.df < Ft.df); 873 }}); 874 875 0x5: c_nge_d({{ 876 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 877 cond = 1; 878 else 879 cond = (Fs.df < Ft.df); 880 }}); 881 882 0x6: c_le_d({{ 883 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 884 cond = 0; 885 else 886 cond = (Fs.df <= Ft.df); 887 }}); 888 889 0x7: c_ngt_d({{ 890 if (unorderedFP(Fs.ud) || unorderedFP(Ft.ud)) 891 cond = 1; 892 else 893 cond = (Fs.df <= Ft.df); 894 }}); 895 } 896 } 897 } 898 899 //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=W 900 0x4: decode FUNCTION { 901 format FloatConvertOp { 902 0x20: cvt_s_w({{ 903 Fd.uw = fpConvert(Fs.sf, WORD_TO_SINGLE); 904 }}); 905 906 0x21: cvt_d_w({{ 907 Fd.ud = fpConvert(Fs.sf, WORD_TO_DOUBLE); 908 }}); 909 } 910 911 format Float64ConvertOp { 912 0x26: cvt_ps_pw({{ 913 Fd.ud = fpConvert(Fs.ud, WORD_TO_PS); 914 }}); 915 } 916 } 917 918 //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=L1 919 //Note: "1. Format type L is legal only if 64-bit floating point operations 920 //are enabled." 921 0x5: decode FUNCTION_HI { 922 format Float64ConvertOp { 923 0x20: cvt_s_l({{ 924 Fd.uw = fpConvert(Fs.ud, LONG_TO_SINGLE); 925 }}); 926 927 0x21: cvt_d_l({{ 928 Fd.ud = fpConvert(Fs.ud, LONG_TO_DOUBLE); 929 }}); 930 931 0x26: cvt_ps_l({{ 932 Fd.ud = fpConvert(Fs.ud, LONG_TO_PS); 933 }}); 934 } 935 } 936 937 //Table A-17 MIPS64 COP1 Encoding of Function Field When rs=PS1 938 //Note: "1. Format type PS is legal only if 64-bit floating point operations 939 //are enabled. " 940 0x6: decode FUNCTION_HI { 941 0x0: decode FUNCTION_LO { 942 format Float64Op { 943 0x0: add_ps({{ 944 Fd.df = Fs.df + Ft.df; 945 }}); 946 947 0x1: sub_ps({{ 948 Fd.df = Fs.df - Ft.df; 949 }}); 950 951 0x2: mul_ps({{ 952 Fd.df = Fs.df * Ft.df; 953 }}); 954 955 0x5: abs_ps({{ 956 Fd.df = fabs(Fs.df); 957 }}); 958 959 0x6: mov_ps({{ 960 Fd.df = Fs | Ft; 961 }}); 962 963 0x7: neg_ps({{ 964 Fd.df = -1 * Fs.df; 965 }}); 966 } 967 } 968 969 0x2: decode FUNCTION_LO { 970 0x1: decode MOVCF { 971 format Float64Op { 972 0x0: movf_ps({{if (getFPConditionCode(CC) == 0) Fd = Fs;}}); 973 0x1: movt_ps({{if (getFPConditionCode(CC) == 1) Fd = Fs;}}); 974 } 975 } 976 977 format Float64Op { 978 0x2: movz_ps({{if (getFPConditionCode(CC) == 0) Fd = Fs; }}); 979 0x3: movn_ps({{if (getFPConditionCode(CC) == 1) Fd = Fs; }}); 980 } 981 982 } 983 984 0x4: decode FUNCTION_LO { 985 0x0: Float64Op::cvt_s_pu({{ 986 Fd.uw = fpConvert(Fs.ud, PU_TO_SINGLE); 987 }}); 988 } 989 990 0x5: decode FUNCTION_LO { 991 format Float64Op { 992 0x0: cvt_s_pl({{ 993 Fd.uw = fpConvert(Fs.ud, PL_TO_SINGLE); 994 }}); 995 996 0x4: pll({{ Fd.ud = Fs.ud<31:0> << 32 | Ft.ud<31:0>; }}); 997 0x5: plu({{ Fd.ud = Fs.ud<31:0> << 32 | Ft.ud<63:32>;}}); 998 0x6: pul({{ Fd.ud = Fs.ud<63:32> << 32 | Ft.ud<31:0>; }}); 999 0x7: puu({{ Fd.ud = Fs.ud<63:32> << 32 | Ft.ud<63:32>;}}); 1000 } 1001 } 1002 1003 0x6: decode FUNCTION_LO { 1004 format FloatOp { 1005 0x0: c_f_ps({{ ; }}); 1006 0x1: c_un_ps({{ ; }}); 1007 0x2: c_eq_ps({{ ; }}); 1008 0x3: c_ueq_ps({{ ; }}); 1009 0x4: c_olt_ps({{ ; }}); 1010 0x5: c_ult_ps({{ ; }}); 1011 0x6: c_ole_ps({{ ; }}); 1012 0x7: c_ule_ps({{ ; }}); 1013 } 1014 } 1015 1016 0x7: decode FUNCTION_LO { 1017 format FloatOp { 1018 0x0: c_sf_ps({{ ; }}); 1019 0x1: c_ngle_ps({{ ; }}); 1020 0x2: c_seq_ps({{ ; }}); 1021 0x3: c_ngl_ps({{ ; }}); 1022 0x4: c_lt_ps({{ ; }}); 1023 0x5: c_nge_ps({{ ; }}); 1024 0x6: c_le_ps({{ ; }}); 1025 0x7: c_ngt_ps({{ ; }}); 1026 } 1027 } 1028 1029 } 1030 } 1031 } 1032 } 1033 1034 //Table A-19 MIPS32 COP2 Encoding of rs Field 1035 0x2: decode RS_MSB { 1036 0x0: decode RS_HI { 1037 0x0: decode RS_LO { 1038 format WarnUnimpl { 1039 0x0: mfc2(); 1040 0x2: cfc2(); 1041 0x3: mfhc2(); 1042 0x4: mtc2(); 1043 0x6: ctc2(); 1044 0x7: mftc2(); 1045 } 1046 } 1047 1048 0x1: decode ND { 1049 0x0: decode TF { 1050 format WarnUnimpl { 1051 0x0: bc2f(); 1052 0x1: bc2t(); 1053 } 1054 } 1055 1056 0x1: decode TF { 1057 format WarnUnimpl { 1058 0x0: bc2fl(); 1059 0x1: bc2tl(); 1060 } 1061 } 1062 } 1063 } 1064 } 1065 1066 //Table A-20 MIPS64 COP1X Encoding of Function Field 1 1067 //Note: "COP1X instructions are legal only if 64-bit floating point 1068 //operations are enabled." 1069 0x3: decode FUNCTION_HI { 1070 0x0: decode FUNCTION_LO { 1071 format LoadFloatMemory { 1072 0x0: lwxc1({{ Ft.uw = Mem.uw;}}, {{ EA = Rs + Rt; }}); 1073 0x1: ldxc1({{ Ft.ud = Mem.ud;}}, {{ EA = Rs + Rt; }}); 1074 0x5: luxc1({{ Ft.uw = Mem.ud;}}, {{ EA = Rs + Rt; }}); 1075 } 1076 } 1077 1078 0x1: decode FUNCTION_LO { 1079 format StoreFloatMemory { 1080 0x0: swxc1({{ Mem.uw = Ft.uw;}}, {{ EA = Rs + Rt; }}); 1081 0x1: sdxc1({{ Mem.ud = Ft.ud;}}, {{ EA = Rs + Rt; }}); 1082 0x5: suxc1({{ Mem.ud = Ft.ud;}}, {{ EA = Rs + Rt; }}); 1083 } 1084 1085 0x7: WarnUnimpl::prefx(); 1086 } 1087 1088 format FloatOp { 1089 0x3: WarnUnimpl::alnv_ps(); 1090 1091 format BasicOp { 1092 0x4: decode FUNCTION_LO { 1093 0x0: madd_s({{ Fd.sf = (Fs.sf * Fs.sf) + Fr.sf; }}); 1094 0x1: madd_d({{ Fd.df = (Fs.df * Fs.df) + Fr.df; }}); 1095 0x6: madd_ps({{ 1096 Fd.df = (Fs.df * Fs.df) + Fr.df; 1097 }}); 1098 } 1099 1100 0x5: decode FUNCTION_LO { 1101 0x0: msub_s({{ Fd.sf = (Fs.sf * Fs.sf) - Fr.sf; }}); 1102 0x1: msub_d({{ Fd.df = (Fs.df * Fs.df) - Fr.df; }}); 1103 0x6: msub_ps({{ 1104 Fd.df = (Fs.df * Fs.df) - Fr.df; 1105 }}); 1106 } 1107 1108 0x6: decode FUNCTION_LO { 1109 0x0: nmadd_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }}); 1110 0x1: nmadd_d({{ Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; }}); 1111 0x6: nmadd_ps({{ 1112 Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; 1113 }}); 1114 } 1115 1116 0x7: decode FUNCTION_LO { 1117 0x0: nmsub_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }}); 1118 0x1: nmsub_d({{ Fd.df = (-1 * Fs.df * Fs.df) - Fr.df; }}); 1119 0x6: nmsub_ps({{ 1120 Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; 1121 }}); 1122 } 1123 } 1124 } 1125 } 1126 1127 format BranchLikely { 1128 0x4: beql({{ cond = (Rs.sw == 0); }}); 1129 0x5: bnel({{ cond = (Rs.sw != 0); }}); 1130 0x6: blezl({{ cond = (Rs.sw <= 0); }}); 1131 0x7: bgtzl({{ cond = (Rs.sw > 0); }}); 1132 } 1133 } 1134 1135 0x3: decode OPCODE_LO default FailUnimpl::reserved() { 1136 1137 //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field 1138 0x4: decode FUNCTION_HI { 1139 1140 0x0: decode FUNCTION_LO { 1141 format IntOp { 1142 0x0: madd({{ 1143 int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32; 1144 temp1 = temp1 + (Rs.sw * Rt.sw); 1145 xc->setMiscReg(Hi,temp1<63:32>); 1146 xc->setMiscReg(Lo,temp1<31:0>); 1147 }}); 1148 1149 0x1: maddu({{ 1150 int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32; 1151 temp1 = temp1 + (Rs.uw * Rt.uw); 1152 xc->setMiscReg(Hi,temp1<63:32>); 1153 xc->setMiscReg(Lo,temp1<31:0>); 1154 }}); 1155 1156 0x2: mul({{ Rd.sw = Rs.sw * Rt.sw; }}); 1157 1158 0x4: msub({{ 1159 int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32; 1160 temp1 = temp1 - (Rs.sw * Rt.sw); 1161 xc->setMiscReg(Hi,temp1<63:32>); 1162 xc->setMiscReg(Lo,temp1<31:0>); 1163 }}); 1164 1165 0x5: msubu({{ 1166 int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32; 1167 temp1 = temp1 - (Rs.uw * Rt.uw); 1168 xc->setMiscReg(Hi,temp1<63:32>); 1169 xc->setMiscReg(Lo,temp1<31:0>); 1170 }}); 1171 } 1172 } 1173 1174 0x4: decode FUNCTION_LO { 1175 format BasicOp { 1176 0x0: clz({{ 1177 int cnt = 0; 1178 uint32_t mask = 0x80000000; 1179 for (int i=0; i < 32; i++) 1180 if( (Rs & mask) == 0) { 1181 cnt++; 1182 } else { 1183 break; 1184 } 1185 } 1186 Rd.uw = cnt; 1187 }}); 1188 1189 0x1: clo({{ 1190 int cnt = 0; 1191 uint32_t mask = 0x80000000; 1192 for (int i=0; i < 32; i++) 1193 if( (Rs & mask) != 0) { 1194 cnt++; 1195 } else { 1196 break; 1197 } 1198 } 1199 Rd.uw = cnt; 1200 }}); 1201 } 1202 } 1203 1204 0x7: decode FUNCTION_LO { 1205 0x7: WarnUnimpl::sdbbp(); 1206 } 1207 } 1208 1209 //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2 of the Architecture 1210 0x7: decode FUNCTION_HI { 1211 1212 0x0: decode FUNCTION_LO { 1213 format FailUnimpl { 1214 0x1: ext(); 1215 0x4: ins(); 1216 } 1217 } 1218 1219 0x1: decode FUNCTION_LO { 1220 format FailUnimpl { 1221 0x0: fork(); 1222 0x1: yield(); 1223 } 1224 } 1225 1226 1227 //Table A-10 MIPS32 BSHFL Encoding of sa Field 1228 0x4: decode SA { 1229 1230 0x02: FailUnimpl::wsbh(); 1231 1232 format BasicOp { 1233 0x10: seb({{ Rd.sw = Rt<7:0>}}); 1234 0x18: seh({{ Rd.sw = Rt<15:0>}}); 1235 } 1236 } 1237 1238 0x6: decode FUNCTION_LO { 1239 0x7: FailUnimpl::rdhwr();//{{ /*Rt = xc->hwRegs[RD];*/ }} 1240 } 1241 } 1242 } 1243 1244 0x4: decode OPCODE_LO default FailUnimpl::reserved() { 1245 format LoadMemory { 1246 0x0: lb({{ Rt.sw = Mem.sb; }}); 1247 0x1: lh({{ Rt.sw = Mem.sh; }}); 1248 1249 0x2: lwl({{ 1250 uint32_t mem_word = Mem.uw; 1251 uint32_t unalign_addr = Rs + disp; 1252 uint32_t offset = unalign_addr & 0x00000003; 1253#if BYTE_ORDER == BIG_ENDIAN 1254 switch(offset) 1255 { 1256 case 0: 1257 Rt = mem_word; 1258 break; 1259 1260 case 1: 1261 Rt &= 0x000F; 1262 Rt |= (mem_word << 4); 1263 break; 1264 1265 case 2: 1266 Rt &= 0x00FF; 1267 Rt |= (mem_word << 8); 1268 break; 1269 1270 case 3: 1271 Rt &= 0x0FFF; 1272 Rt |= (mem_word << 12); 1273 break; 1274 1275 default: 1276 panic("lwl: bad offset"); 1277 } 1278#elif BYTE_ORDER == LITTLE_ENDIAN 1279 switch(offset) 1280 { 1281 case 0: 1282 Rt &= 0x0FFF; 1283 Rt |= (mem_word << 12); 1284 break; 1285 1286 case 1: 1287 Rt &= 0x00FF; 1288 Rt |= (mem_word << 8); 1289 break; 1290 1291 case 2: 1292 Rt &= 0x000F; 1293 Rt |= (mem_word << 4); 1294 break; 1295 1296 case 3: 1297 Rt = mem_word; 1298 break; 1299 1300 default: 1301 panic("lwl: bad offset"); 1302 } 1303#endif 1304 }}, {{ EA = (Rs + disp) & ~3; }}); 1305 1306 0x3: lw({{ Rt.sw = Mem.sw; }}); 1307 0x4: lbu({{ Rt.uw = Mem.ub; }}); 1308 0x5: lhu({{ Rt.uw = Mem.uh; }}); 1309 0x6: lwr({{ 1310 uint32_t mem_word = Mem.uw; 1311 uint32_t unalign_addr = Rs + disp; 1312 uint32_t offset = unalign_addr & 0x00000003; 1313 1314#if BYTE_ORDER == BIG_ENDIAN 1315 switch(offset) 1316 { 1317 case 0: Rt &= 0xFFF0; Rt |= (mem_word >> 12); break; 1318 case 1: Rt &= 0xFF00; Rt |= (mem_word >> 8); break; 1319 case 2: Rt &= 0xF000; Rt |= (mem_word >> 4); break; 1320 case 3: Rt = mem_word; break; 1321 default: panic("lwr: bad offset"); 1322 } 1323#elif BYTE_ORDER == LITTLE_ENDIAN 1324 switch(offset) 1325 { 1326 case 0: Rt = mem_word; break; 1327 case 1: Rt &= 0xF000; Rt |= (mem_word >> 4); break; 1328 case 2: Rt &= 0xFF00; Rt |= (mem_word >> 8); break; 1329 case 3: Rt &= 0xFFF0; Rt |= (mem_word >> 12); break; 1330 default: panic("lwr: bad offset"); 1331 } 1332#endif 1333 }}, 1334 {{ EA = (Rs + disp) & ~3; }}); 1335 } 1336 1337 0x7: FailUnimpl::reserved(); 1338 } 1339 1340 0x5: decode OPCODE_LO default FailUnimpl::reserved() { 1341 format StoreMemory { 1342 0x0: sb({{ Mem.ub = Rt<7:0>; }}); 1343 0x1: sh({{ Mem.uh = Rt<15:0>; }}); 1344 0x2: swl({{ 1345 uint32_t mem_word = 0; 1346 uint32_t aligned_addr = (Rs + disp) & ~3; 1347 uint32_t unalign_addr = Rs + disp; 1348 uint32_t offset = unalign_addr & 0x00000003; 1349 1350 DPRINTF(IEW,"Execute: aligned=0x%x unaligned=0x%x\n offset=0x%x", 1351 aligned_addr,unalign_addr,offset); 1352 1353 fault = xc->read(aligned_addr, (uint32_t&)mem_word, memAccessFlags); 1354 1355#if BYTE_ORDER == BIG_ENDIAN 1356 switch(offset) 1357 { 1358 case 0: 1359 Mem = Rt; 1360 break; 1361 1362 case 1: 1363 mem_word &= 0xF000; 1364 mem_word |= (Rt >> 4); 1365 Mem = mem_word; 1366 break; 1367 1368 case 2: 1369 mem_word &= 0xFF00; 1370 mem_word |= (Rt >> 8); 1371 Mem = mem_word; 1372 break; 1373 1374 case 3: 1375 mem_word &= 0xFFF0; 1376 mem_word |= (Rt >> 12); 1377 Mem = mem_word; 1378 break; 1379 1380 default: 1381 panic("swl: bad offset"); 1382 } 1383#elif BYTE_ORDER == LITTLE_ENDIAN 1384 switch(offset) 1385 { 1386 case 0: 1387 mem_word &= 0xFFF0; 1388 mem_word |= (Rt >> 12); 1389 Mem = mem_word; 1390 break; 1391 1392 case 1: 1393 mem_word &= 0xFF00; 1394 mem_word |= (Rt >> 8); 1395 Mem = mem_word; 1396 break; 1397 1398 case 2: 1399 mem_word &= 0xF000; 1400 mem_word |= (Rt >> 4); 1401 Mem = mem_word; 1402 break; 1403 1404 case 3: 1405 Mem = Rt; 1406 break; 1407 1408 default: 1409 panic("swl: bad offset"); 1410 } 1411#endif 1412 }},{{ EA = (Rs + disp) & ~3; }},mem_flags = NO_ALIGN_FAULT); 1413 1414 0x3: sw({{ Mem.uw = Rt<31:0>; }}); 1415 1416 0x6: swr({{ 1417 uint32_t mem_word = 0; 1418 uint32_t aligned_addr = (Rs + disp) & ~3; 1419 uint32_t unalign_addr = Rs + disp; 1420 uint32_t offset = unalign_addr & 0x00000003; 1421 1422 fault = xc->read(aligned_addr, (uint32_t&)mem_word, memAccessFlags); 1423 1424#if BYTE_ORDER == BIG_ENDIAN 1425 switch(offset) 1426 { 1427 case 0: 1428 mem_word &= 0x0FFF; 1429 mem_word |= (Rt << 12); 1430 Mem = mem_word; 1431 break; 1432 1433 case 1: 1434 mem_word &= 0x00FF; 1435 mem_word |= (Rt << 8); 1436 Mem = mem_word; 1437 break; 1438 1439 case 2: 1440 mem_word &= 0x000F; 1441 mem_word |= (Rt << 4); 1442 Mem = mem_word; 1443 break; 1444 1445 case 3: 1446 Mem = Rt; 1447 break; 1448 1449 default: 1450 panic("swr: bad offset"); 1451 } 1452#elif BYTE_ORDER == LITTLE_ENDIAN 1453 switch(offset) 1454 { 1455 case 0: 1456 Mem = Rt; 1457 break; 1458 1459 case 1: 1460 mem_word &= 0x000F; 1461 mem_word |= (Rt << 4); 1462 Mem = mem_word; 1463 break; 1464 1465 case 2: 1466 mem_word &= 0x00FF; 1467 mem_word |= (Rt << 8); 1468 Mem = mem_word; 1469 break; 1470 1471 case 3: 1472 mem_word &= 0x0FFF; 1473 mem_word |= (Rt << 12); 1474 Mem = mem_word; 1475 break; 1476 1477 default: 1478 panic("swr: bad offset"); 1479 } 1480#endif 1481 }},{{ EA = (Rs + disp) & ~3;}},mem_flags = NO_ALIGN_FAULT); 1482 } 1483 1484 format WarnUnimpl { 1485 0x7: cache(); 1486 } 1487 1488 } 1489 1490 0x6: decode OPCODE_LO default FailUnimpl::reserved() { 1491 0x0: LoadMemory::ll({{Rt.uw = Mem.uw}},mem_flags=LOCKED); 1492 1493 format LoadFloatMemory { 1494 0x1: lwc1({{ Ft.uw = Mem.uw; }}); 1495 0x5: ldc1({{ Ft.ud = Mem.ud; }}); 1496 } 1497 } 1498 1499 1500 0x7: decode OPCODE_LO default FailUnimpl::reserved() { 1501 0x0: StoreMemory::sc({{ Mem.uw = Rt.uw; Rt.uw = 1; }}); 1502 1503 format StoreFloatMemory { 1504 0x1: swc1({{ Mem.uw = Ft.uw; }}); 1505 0x5: sdc1({{ Mem.ud = Ft.ud; }}); 1506 } 1507 } 1508} 1509 1510 1511