decoder.isa revision 2495
16313Sgblack@eecs.umich.edu// -*- mode:c++ -*-
210844Sandreas.sandberg@arm.com
37093Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////
47093Sgblack@eecs.umich.edu//
57093Sgblack@eecs.umich.edu// The actual MIPS32 ISA decoder
67093Sgblack@eecs.umich.edu// -----------------------------
77093Sgblack@eecs.umich.edu// The following instructions are specified in the MIPS32 ISA
87093Sgblack@eecs.umich.edu// Specification. Decoding closely follows the style specified
97093Sgblack@eecs.umich.edu// in the MIPS32 ISAthe specification document starting with Table
107093Sgblack@eecs.umich.edu// A-2 (document available @ www.mips.com)
117093Sgblack@eecs.umich.edu//
127093Sgblack@eecs.umich.edu//@todo: Distinguish "unknown/future" use insts from "reserved"
137093Sgblack@eecs.umich.edu// ones
146313Sgblack@eecs.umich.edudecode OPCODE_HI default Unknown::unknown() {
156313Sgblack@eecs.umich.edu
166313Sgblack@eecs.umich.edu    // Derived From ... Table A-2 MIPS32 ISA Manual
176313Sgblack@eecs.umich.edu    0x0: decode OPCODE_LO {
186313Sgblack@eecs.umich.edu
196313Sgblack@eecs.umich.edu        0x0: decode FUNCTION_HI {
206313Sgblack@eecs.umich.edu            0x0: decode FUNCTION_LO {
216313Sgblack@eecs.umich.edu                0x1: decode MOVCI {
226313Sgblack@eecs.umich.edu                    format BasicOp {
236313Sgblack@eecs.umich.edu                        0: movf({{ if (xc->readMiscReg(FPCR) != CC) Rd = Rs}});
246313Sgblack@eecs.umich.edu                        1: movt({{ if (xc->readMiscReg(FPCR) == CC) Rd = Rs}});
256313Sgblack@eecs.umich.edu                    }
266313Sgblack@eecs.umich.edu                }
276313Sgblack@eecs.umich.edu
286313Sgblack@eecs.umich.edu                format BasicOp {
296313Sgblack@eecs.umich.edu
306313Sgblack@eecs.umich.edu                    //Table A-3 Note: "1. Specific encodings of the rt, rd, and sa fields
316313Sgblack@eecs.umich.edu                    //are used to distinguish among the SLL, NOP, SSNOP and EHB functions.
326313Sgblack@eecs.umich.edu                    0x0: decode RS  {
336313Sgblack@eecs.umich.edu                        0x0: decode RT {     //fix Nop traditional vs. Nop converted disassembly later
346313Sgblack@eecs.umich.edu                             0x0: decode RD  default Nop::nop(){
356313Sgblack@eecs.umich.edu                                  0x0: decode SA {
366313Sgblack@eecs.umich.edu                                      0x1: ssnop({{ ; }}); //really sll r0,r0,1
376313Sgblack@eecs.umich.edu                                      0x3: ehb({{ ; }});   //really sll r0,r0,3
386313Sgblack@eecs.umich.edu                                  }
396313Sgblack@eecs.umich.edu                             }
406313Sgblack@eecs.umich.edu
416313Sgblack@eecs.umich.edu                             default: sll({{ Rd = Rt.uw << SA; }});
426313Sgblack@eecs.umich.edu                        }
436313Sgblack@eecs.umich.edu
447404SAli.Saidi@ARM.com                    }
456313Sgblack@eecs.umich.edu
4610461SAndreas.Sandberg@ARM.com                    0x2: decode RS_SRL {
476333Sgblack@eecs.umich.edu                        0x0:decode SRL {
4810037SARM gem5 Developers                            0: srl({{ Rd = Rt.uw >> SA; }});
497404SAli.Saidi@ARM.com
506313Sgblack@eecs.umich.edu                            //Hardcoded assuming 32-bit ISA, probably need parameter here
518232Snate@binkert.org                            1: rotr({{ Rd = (Rt.uw << (32 - SA)) | (Rt.uw >> SA);}});
529384SAndreas.Sandberg@arm.com                        }
536313Sgblack@eecs.umich.edu                    }
549384SAndreas.Sandberg@arm.com
5510461SAndreas.Sandberg@ARM.com                    0x3: decode RS {
566333Sgblack@eecs.umich.edu                        0x0: sra({{
576313Sgblack@eecs.umich.edu                            uint32_t temp = Rt >> SA;
586313Sgblack@eecs.umich.edu
596313Sgblack@eecs.umich.edu                            if ( (Rt & 0x80000000) > 0 ) {
606313Sgblack@eecs.umich.edu                                uint32_t mask = 0x80000000;
616313Sgblack@eecs.umich.edu                                for(int i=0; i < SA; i++) {
6210037SARM gem5 Developers                                    temp |= mask;
6310037SARM gem5 Developers                                    mask = mask >> 1;
6410037SARM gem5 Developers                                }
6510037SARM gem5 Developers                            }
6610037SARM gem5 Developers
6710037SARM gem5 Developers                            Rd = temp;
6810037SARM gem5 Developers                        }});
6910037SARM gem5 Developers                    }
7010037SARM gem5 Developers
7110037SARM gem5 Developers                    0x4: sllv({{ Rd = Rt.uw << Rs<4:0>; }});
7210037SARM gem5 Developers
7310037SARM gem5 Developers                    0x6: decode SRLV {
7410037SARM gem5 Developers                        0: srlv({{ Rd = Rt.uw >> Rs<4:0>; }});
7510037SARM gem5 Developers
7610037SARM gem5 Developers                        //Hardcoded assuming 32-bit ISA, probably need parameter here
7710037SARM gem5 Developers                        1: rotrv({{ Rd = (Rt.uw << (32 - Rs<4:0>)) | (Rt.uw >> Rs<4:0>);}});
7810037SARM gem5 Developers                    }
7910037SARM gem5 Developers
8010037SARM gem5 Developers                    0x7: srav({{
8110037SARM gem5 Developers                        int shift_amt = Rs<4:0>;
8210037SARM gem5 Developers
8310037SARM gem5 Developers                        uint32_t temp = Rt >> shift_amt;
8410037SARM gem5 Developers
8510037SARM gem5 Developers                        if ( (Rt & 0x80000000) > 0 ) {
8610037SARM gem5 Developers                                uint32_t mask = 0x80000000;
8710037SARM gem5 Developers                                for(int i=0; i < shift_amt; i++) {
8810037SARM gem5 Developers                                    temp |= mask;
8910037SARM gem5 Developers                                    mask = mask >> 1;
9010037SARM gem5 Developers                                }
9110037SARM gem5 Developers                            }
9210037SARM gem5 Developers
9310037SARM gem5 Developers                        Rd = temp;
9410037SARM gem5 Developers                    }});
9510037SARM gem5 Developers                }
9610037SARM gem5 Developers            }
9710037SARM gem5 Developers
9810037SARM gem5 Developers            0x1: decode FUNCTION_LO {
9910037SARM gem5 Developers
10010037SARM gem5 Developers                //Table A-3 Note: "Specific encodings of the hint field are used
10110037SARM gem5 Developers                //to distinguish JR from JR.HB and JALR from JALR.HB"
10210037SARM gem5 Developers                format Jump {
10310037SARM gem5 Developers                    0x0: decode HINT {
10410037SARM gem5 Developers                        0:jr({{ NNPC = Rs & ~1; }},IsReturn);
10510037SARM gem5 Developers
10610037SARM gem5 Developers                        1:jr_hb({{ NNPC = Rs & ~1; clear_exe_inst_hazards(); }},IsReturn);
10710037SARM gem5 Developers                    }
10810037SARM gem5 Developers
10910037SARM gem5 Developers                    0x1: decode HINT {
11010037SARM gem5 Developers                        0: jalr({{ Rd = NNPC; NNPC = Rs; }},IsCall,IsReturn);
11110037SARM gem5 Developers
11210037SARM gem5 Developers                        1: jalr_hb({{ Rd = NNPC; NNPC = Rs; clear_exe_inst_hazards();}},IsCall,IsReturn);
11310037SARM gem5 Developers                    }
11410037SARM gem5 Developers                }
11510037SARM gem5 Developers
11610037SARM gem5 Developers                format BasicOp {
11710037SARM gem5 Developers                    0x2: movz({{ if (Rt == 0) Rd = Rs; }});
11810037SARM gem5 Developers                    0x3: movn({{ if (Rt != 0) Rd = Rs; }});
11910037SARM gem5 Developers                }
12010037SARM gem5 Developers
12110037SARM gem5 Developers                format BasicOp {
12210037SARM gem5 Developers                    0x4: syscall({{ xc->syscall(); }},IsNonSpeculative);
12310037SARM gem5 Developers                    0x5: break({{ panic("Not implemented break yet"); }},IsNonSpeculative);
12410037SARM gem5 Developers                    0x7: sync({{  panic("Not implemented sync yet"); }},IsNonSpeculative);
12510037SARM gem5 Developers                }
12610037SARM gem5 Developers            }
12710037SARM gem5 Developers
12810037SARM gem5 Developers            0x2: decode FUNCTION_LO {
1299384SAndreas.Sandberg@arm.com                format BasicOp {
1306313Sgblack@eecs.umich.edu                    0x0: mfhi({{ Rd = xc->readMiscReg(Hi); }});
1316313Sgblack@eecs.umich.edu                    0x1: mthi({{ xc->setMiscReg(Hi,Rs); }});
13210037SARM gem5 Developers                    0x2: mflo({{ Rd = xc->readMiscReg(Lo); }});
13310037SARM gem5 Developers                    0x3: mtlo({{ xc->setMiscReg(Lo,Rs); }});
13410037SARM gem5 Developers                }
13510461SAndreas.Sandberg@ARM.com            }
13610461SAndreas.Sandberg@ARM.com
13710461SAndreas.Sandberg@ARM.com            0x3: decode FUNCTION_LO {
13810461SAndreas.Sandberg@ARM.com                format IntOp {
13910461SAndreas.Sandberg@ARM.com                    0x0: mult({{
14010461SAndreas.Sandberg@ARM.com                        int64_t temp1 = Rs.sw * Rt.sw;
14110844Sandreas.sandberg@arm.com                        xc->setMiscReg(Hi,temp1<63:32>);
14210844Sandreas.sandberg@arm.com                        xc->setMiscReg(Lo,temp1<31:0>);
14310844Sandreas.sandberg@arm.com                    }});
14410037SARM gem5 Developers
14510037SARM gem5 Developers                    0x1: multu({{
14610037SARM gem5 Developers                        int64_t temp1 = Rs.uw * Rt.uw;
14710037SARM gem5 Developers                        xc->setMiscReg(Hi,temp1<63:32>);
14810037SARM gem5 Developers                        xc->setMiscReg(Lo,temp1<31:0>);
14910037SARM gem5 Developers                    }});
15010037SARM gem5 Developers
15110037SARM gem5 Developers                    0x2: div({{
15210037SARM gem5 Developers                        xc->setMiscReg(Hi,Rs.sw % Rt.sw);
15310037SARM gem5 Developers                        xc->setMiscReg(Lo,Rs.sw / Rt.sw);
15410037SARM gem5 Developers                    }});
15510037SARM gem5 Developers
15610037SARM gem5 Developers                    0x3: divu({{
15710037SARM gem5 Developers                        xc->setMiscReg(Hi,Rs.uw % Rt.uw);
15810037SARM gem5 Developers                        xc->setMiscReg(Lo,Rs.uw / Rt.uw);
15910037SARM gem5 Developers                    }});
16010037SARM gem5 Developers                }
16110037SARM gem5 Developers            }
16210037SARM gem5 Developers
16310037SARM gem5 Developers            0x4: decode HINT {
16410037SARM gem5 Developers                0x0: decode FUNCTION_LO {
16510037SARM gem5 Developers                    format IntOp {
16610037SARM gem5 Developers                        0x0: add({{  Rd.sw = Rs.sw + Rt.sw;/*Trap on Overflow*/}});
16710037SARM gem5 Developers                        0x1: addu({{ Rd.sw = Rs.sw + Rt.sw;}});
16810037SARM gem5 Developers                        0x2: sub({{ Rd.sw = Rs.sw - Rt.sw; /*Trap on Overflow*/}});
1696333Sgblack@eecs.umich.edu                        0x3: subu({{ Rd.sw = Rs.sw - Rt.sw;}});
1706718Sgblack@eecs.umich.edu                        0x4: and({{ Rd = Rs & Rt;}});
1716718Sgblack@eecs.umich.edu                        0x5: or({{ Rd = Rs | Rt;}});
1726718Sgblack@eecs.umich.edu                        0x6: xor({{ Rd = Rs ^ Rt;}});
1736718Sgblack@eecs.umich.edu                        0x7: nor({{ Rd = ~(Rs | Rt);}});
1746718Sgblack@eecs.umich.edu                    }
17510037SARM gem5 Developers                }
17610037SARM gem5 Developers            }
17710037SARM gem5 Developers
17810037SARM gem5 Developers            0x5: decode HINT {
17910037SARM gem5 Developers                0x0: decode FUNCTION_LO {
18010037SARM gem5 Developers                    format IntOp{
18110037SARM gem5 Developers                        0x2: slt({{  Rd.sw = ( Rs.sw < Rt.sw ) ? 1 : 0}});
18210037SARM gem5 Developers                        0x3: sltu({{ Rd.uw = ( Rs.uw < Rt.uw ) ? 1 : 0}});
18310037SARM gem5 Developers                    }
18410037SARM gem5 Developers                }
18510037SARM gem5 Developers            }
18610037SARM gem5 Developers
18710037SARM gem5 Developers            0x6: decode FUNCTION_LO {
18810037SARM gem5 Developers                format Trap {
18910037SARM gem5 Developers                    0x0: tge({{  cond = (Rs.sw >= Rt.sw); }});
19010037SARM gem5 Developers                    0x1: tgeu({{ cond = (Rs.uw >= Rt.uw); }});
19110037SARM gem5 Developers                    0x2: tlt({{ cond = (Rs.sw < Rt.sw); }});
19210037SARM gem5 Developers                    0x3: tltu({{ cond = (Rs.uw >= Rt.uw); }});
19310037SARM gem5 Developers                    0x4: teq({{ cond = (Rs.sw == Rt.sw); }});
19410037SARM gem5 Developers                    0x6: tne({{ cond = (Rs.sw != Rt.sw); }});
19510037SARM gem5 Developers                }
19610037SARM gem5 Developers            }
19710037SARM gem5 Developers        }
19810037SARM gem5 Developers
19910037SARM gem5 Developers        0x1: decode REGIMM_HI {
20010037SARM gem5 Developers            0x0: decode REGIMM_LO {
20110037SARM gem5 Developers                format Branch {
20210037SARM gem5 Developers                    0x0: bltz({{ cond = (Rs.sw < 0); }});
20310037SARM gem5 Developers                    0x1: bgez({{ cond = (Rs.sw >= 0); }});
20410037SARM gem5 Developers                }
20510037SARM gem5 Developers
20610037SARM gem5 Developers                format BranchLikely {
2076718Sgblack@eecs.umich.edu                    //MIPS obsolete instructions
2086718Sgblack@eecs.umich.edu                    0x2: bltzl({{ cond = (Rs.sw < 0); }});
2096313Sgblack@eecs.umich.edu                    0x3: bgezl({{ cond = (Rs.sw >= 0); }});
21010844Sandreas.sandberg@arm.com                }
21110037SARM gem5 Developers            }
21210037SARM gem5 Developers
21310037SARM gem5 Developers            0x1: decode REGIMM_LO {
21410037SARM gem5 Developers                format Trap {
21510037SARM gem5 Developers                    0x0: tgei( {{ cond = (Rs.sw >= INTIMM); }});
21610037SARM gem5 Developers                    0x1: tgeiu({{ cond = (Rs.uw >= INTIMM); }});
21710037SARM gem5 Developers                    0x2: tlti( {{ cond = (Rs.sw < INTIMM); }});
21810037SARM gem5 Developers                    0x3: tltiu({{ cond = (Rs.uw < INTIMM); }});
21910037SARM gem5 Developers                    0x4: teqi( {{ cond = (Rs.sw == INTIMM);}});
22010037SARM gem5 Developers                    0x6: tnei( {{ cond = (Rs.sw != INTIMM);}});
22110037SARM gem5 Developers                }
22210037SARM gem5 Developers            }
22310037SARM gem5 Developers
22410709SAndreas.Sandberg@ARM.com            0x2: decode REGIMM_LO {
22510037SARM gem5 Developers                format Branch {
22610037SARM gem5 Developers                    0x0: bltzal({{ cond = (Rs.sw < 0); }}, IsCall,IsReturn);
22710037SARM gem5 Developers                    0x1: bgezal({{ cond = (Rs.sw >= 0); }}, IsCall,IsReturn);
22810037SARM gem5 Developers                }
22910037SARM gem5 Developers
23010037SARM gem5 Developers                format BranchLikely {
23110037SARM gem5 Developers                    //Will be removed in future MIPS releases
23210037SARM gem5 Developers                    0x2: bltzall({{ cond = (Rs.sw < 0); }}, IsCall, IsReturn);
23310037SARM gem5 Developers                    0x3: bgezall({{ cond = (Rs.sw >= 0); }}, IsCall, IsReturn);
2346313Sgblack@eecs.umich.edu                }
2357427Sgblack@eecs.umich.edu            }
23610037SARM gem5 Developers
2376313Sgblack@eecs.umich.edu            0x3: decode REGIMM_LO {
23810035Sandreas.hansson@arm.com                format WarnUnimpl {
2397405SAli.Saidi@ARM.com                    0x7: synci();
2407405SAli.Saidi@ARM.com                }
2417405SAli.Saidi@ARM.com            }
2426313Sgblack@eecs.umich.edu        }
2436313Sgblack@eecs.umich.edu
24410035Sandreas.hansson@arm.com        format Jump {
2456313Sgblack@eecs.umich.edu            0x2: j({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2);}});
2466718Sgblack@eecs.umich.edu
2476718Sgblack@eecs.umich.edu            0x3: jal({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2); }},IsCall,IsReturn);
2486718Sgblack@eecs.umich.edu        }
2496726Sgblack@eecs.umich.edu
2506726Sgblack@eecs.umich.edu        format Branch {
25110037SARM gem5 Developers            0x4: beq({{ cond = (Rs.sw == Rt.sw); }});
25210037SARM gem5 Developers            0x5: bne({{ cond = (Rs.sw != Rt.sw); }});
25310037SARM gem5 Developers            0x6: decode RT {
25410037SARM gem5 Developers                0x0: blez({{ cond = (Rs.sw <= 0); }});
25510037SARM gem5 Developers            }
25610037SARM gem5 Developers
25710037SARM gem5 Developers            0x7: decode RT {
25810037SARM gem5 Developers                0x0: bgtz({{ cond = (Rs.sw > 0); }});
25910037SARM gem5 Developers            }
26010037SARM gem5 Developers        }
26110037SARM gem5 Developers    }
26210037SARM gem5 Developers
26310037SARM gem5 Developers    0x1: decode OPCODE_LO {
26410037SARM gem5 Developers        format IntOp {
26510037SARM gem5 Developers            0x0: addi({{ Rt.sw = Rs.sw + imm; /*Trap If Overflow*/}});
26610037SARM gem5 Developers            0x1: addiu({{ Rt.sw = Rs.sw + imm;}});
26710037SARM gem5 Developers            0x2: slti({{ Rt.sw = ( Rs.sw < imm) ? 1 : 0 }});
26810037SARM gem5 Developers            0x3: sltiu({{ Rt.uw = ( Rs.uw < (uint32_t)sextImm ) ? 1 : 0 }});
26910037SARM gem5 Developers            0x4: andi({{ Rt.sw = Rs.sw & zextImm;}});
27010037SARM gem5 Developers            0x5: ori({{ Rt.sw = Rs.sw | zextImm;}});
2716718Sgblack@eecs.umich.edu            0x6: xori({{ Rt.sw = Rs.sw ^ zextImm;}});
27210037SARM gem5 Developers
2736718Sgblack@eecs.umich.edu            0x7: decode RS {
2746313Sgblack@eecs.umich.edu                0x0: lui({{ Rt = imm << 16}});
2756313Sgblack@eecs.umich.edu            }
2766313Sgblack@eecs.umich.edu        }
27710035Sandreas.hansson@arm.com    }
2786313Sgblack@eecs.umich.edu
27910338SCurtis.Dunham@arm.com    0x2: decode OPCODE_LO {
2806313Sgblack@eecs.umich.edu
2816313Sgblack@eecs.umich.edu        //Table A-11 MIPS32 COP0 Encoding of rs Field
2826313Sgblack@eecs.umich.edu        0x0: decode RS_MSB {
2839920Syasuko.eckert@amd.com            0x0: decode RS {
28410035Sandreas.hansson@arm.com                format System {
2859920Syasuko.eckert@amd.com                    0x0: mfc0({{
28610338SCurtis.Dunham@arm.com                        //uint64_t reg_num = Rd.uw;
2879920Syasuko.eckert@amd.com
2889920Syasuko.eckert@amd.com                        Rt = xc->readMiscReg(RD << 5 | SEL);
2899920Syasuko.eckert@amd.com                    }});
2907614Sminkyu.jeong@arm.com
29110035Sandreas.hansson@arm.com                    0x4: mtc0({{
2927614Sminkyu.jeong@arm.com                        //uint64_t reg_num = Rd.uw;
29310338SCurtis.Dunham@arm.com
29410037SARM gem5 Developers                        xc->setMiscReg(RD << 5 | SEL,Rt);
29510037SARM gem5 Developers                    }});
2967614Sminkyu.jeong@arm.com
2977614Sminkyu.jeong@arm.com                    0x8: mftr({{
2987614Sminkyu.jeong@arm.com                        //The contents of the coprocessor 0 register specified by the
29910037SARM gem5 Developers                        //combination of rd and sel are loaded into general register
30010037SARM gem5 Developers                        //rt. Note that not all coprocessor 0 registers support the
30110037SARM gem5 Developers                        //sel field. In those instances, the sel field must be zero.
30210037SARM gem5 Developers
30310037SARM gem5 Developers                        //MT Code Needed Here
30410037SARM gem5 Developers                    }});
30510037SARM gem5 Developers
30610037SARM gem5 Developers                    0xC: mttr({{
30710037SARM gem5 Developers                        //The contents of the coprocessor 0 register specified by the
30810037SARM gem5 Developers                        //combination of rd and sel are loaded into general register
30910037SARM gem5 Developers                        //rt. Note that not all coprocessor 0 registers support the
31010037SARM gem5 Developers                        //sel field. In those instances, the sel field must be zero.
31110037SARM gem5 Developers
31210037SARM gem5 Developers                        //MT Code Needed Here
31310037SARM gem5 Developers                    }});
31410037SARM gem5 Developers
3157614Sminkyu.jeong@arm.com
3167614Sminkyu.jeong@arm.com                    0xA: rdpgpr({{
31710037SARM gem5 Developers                        //Accessing Previous Shadow Set Register Number
3187614Sminkyu.jeong@arm.com                        //uint64_t prev = xc->readMiscReg(SRSCtl)/*[PSS]*/;
3197614Sminkyu.jeong@arm.com                        //uint64_t reg_num = Rt.uw;
32010037SARM gem5 Developers
3217614Sminkyu.jeong@arm.com                        //Rd = xc->regs.IntRegFile[prev];
3227614Sminkyu.jeong@arm.com                       //Rd = xc->shadowIntRegFile[prev][reg_num];
32310037SARM gem5 Developers                    }});
3247614Sminkyu.jeong@arm.com
3257614Sminkyu.jeong@arm.com                    0xB: decode RD {
32610037SARM gem5 Developers
3277614Sminkyu.jeong@arm.com                        0x0: decode SC {
3287614Sminkyu.jeong@arm.com                            0x0: dvpe({{
32910037SARM gem5 Developers                                Rt.sw = xc->readMiscReg(MVPControl);
3307614Sminkyu.jeong@arm.com                                xc->setMiscReg(MVPControl,0);
3317614Sminkyu.jeong@arm.com                            }});
33210037SARM gem5 Developers
33310037SARM gem5 Developers                            0x1: evpe({{
33410037SARM gem5 Developers                                Rt.sw = xc->readMiscReg(MVPControl);
33510037SARM gem5 Developers                                xc->setMiscReg(MVPControl,1);
3367614Sminkyu.jeong@arm.com                            }});
3377614Sminkyu.jeong@arm.com                        }
33810037SARM gem5 Developers
3397614Sminkyu.jeong@arm.com                        0x1: decode SC {
3407614Sminkyu.jeong@arm.com                            0x0: dmt({{
3417614Sminkyu.jeong@arm.com                                Rt.sw = xc->readMiscReg(VPEControl);
3427614Sminkyu.jeong@arm.com                                xc->setMiscReg(VPEControl,0);
34310037SARM gem5 Developers                            }});
3447614Sminkyu.jeong@arm.com
3457614Sminkyu.jeong@arm.com                            0x1: emt({{
34610037SARM gem5 Developers                                Rt.sw = xc->readMiscReg(VPEControl);
34710037SARM gem5 Developers                                xc->setMiscReg(VPEControl,1);
34810037SARM gem5 Developers                            }});
34910037SARM gem5 Developers                        }
35010037SARM gem5 Developers
35110037SARM gem5 Developers                        0xC: decode SC {
35210037SARM gem5 Developers                            0x0: di({{
35310037SARM gem5 Developers                                Rt.sw = xc->readMiscReg(Status);
35410037SARM gem5 Developers                                xc->setMiscReg(Status,0);
35510037SARM gem5 Developers                            }});
35610037SARM gem5 Developers
35710037SARM gem5 Developers                            0x1: ei({{
35810037SARM gem5 Developers                                Rt.sw = xc->readMiscReg(Status);
35910037SARM gem5 Developers                                xc->setMiscReg(Status,1);
36010037SARM gem5 Developers                            }});
36110037SARM gem5 Developers                        }
36210037SARM gem5 Developers                    }
36310037SARM gem5 Developers
36410037SARM gem5 Developers                    0xE: wrpgpr({{
36510037SARM gem5 Developers                        //Accessing Previous Shadow Set Register Number
36610037SARM gem5 Developers                        //uint64_t prev = xc->readMiscReg(SRSCtl/*[PSS]*/);
36710037SARM gem5 Developers                        //uint64_t reg_num = Rd.uw;
36810037SARM gem5 Developers
36910037SARM gem5 Developers                        //xc->regs.IntRegFile[prev];
37010037SARM gem5 Developers                        //xc->shadowIntRegFile[prev][reg_num] = Rt;
37110037SARM gem5 Developers                    }});
37210037SARM gem5 Developers                }
37310037SARM gem5 Developers            }
37410037SARM gem5 Developers
37510037SARM gem5 Developers            //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO
37610037SARM gem5 Developers            0x1: decode FUNCTION {
37710037SARM gem5 Developers                format System {
37810037SARM gem5 Developers                    0x01: tlbr({{ }});
37910037SARM gem5 Developers                    0x02: tlbwi({{ }});
38010037SARM gem5 Developers                    0x06: tlbwr({{ }});
38110037SARM gem5 Developers                    0x08: tlbp({{ }});
38210037SARM gem5 Developers                }
38310037SARM gem5 Developers
38410037SARM gem5 Developers                format WarnUnimpl {
38510037SARM gem5 Developers                    0x18: eret();
38610037SARM gem5 Developers                    0x1F: deret();
38710037SARM gem5 Developers                    0x20: wait();
38810037SARM gem5 Developers                }
38910037SARM gem5 Developers            }
39010037SARM gem5 Developers        }
39110037SARM gem5 Developers
39210037SARM gem5 Developers        //Table A-13 MIPS32 COP1 Encoding of rs Field
39310037SARM gem5 Developers        0x1: decode RS_MSB {
39410037SARM gem5 Developers
39510037SARM gem5 Developers            0x0: decode RS_HI {
39610037SARM gem5 Developers                0x0: decode RS_LO {
39710037SARM gem5 Developers                    format WarnUnimpl {
39810037SARM gem5 Developers                        0x0: mfc1();//{{ /*Rt.uw = Fs.ud<31:0>;*/ }}
39910037SARM gem5 Developers                        0x3: mfhc1();// /*Rt.uw = Fs.ud<63:32>*/;
40010037SARM gem5 Developers                        0x4: mtc1();// /*Fs = Rt.uw*/
4017614Sminkyu.jeong@arm.com                        0x7: mthc1();//{{/*Fs<63:32> = Rt.uw*/}}
40210037SARM gem5 Developers                    }
4037614Sminkyu.jeong@arm.com
4047614Sminkyu.jeong@arm.com                    format System {
4059425SAndreas.Sandberg@ARM.com                        0x2: cfc1({{
4067733SAli.Saidi@ARM.com                            uint32_t fcsr_reg = xc->readMiscReg(FCSR);
4077733SAli.Saidi@ARM.com
4087733SAli.Saidi@ARM.com                            if (Fs == 0){
40910037SARM gem5 Developers                                Rt = xc->readMiscReg(FIR);
41010037SARM gem5 Developers                            } else if (Fs == 25) {
41110037SARM gem5 Developers                                Rt = 0 | (fcsr_reg & 0xFE000000) >> 24 | (fcsr_reg & 0x00800000) >> 23;
41210037SARM gem5 Developers                            } else if (Fs == 26) {
41310037SARM gem5 Developers                                Rt = 0 | (fcsr_reg & 0x0003F07C);
41410037SARM gem5 Developers                            } else if (Fs == 28) {
4157733SAli.Saidi@ARM.com                                Rt = 0 | (fcsr_reg);
4169425SAndreas.Sandberg@ARM.com                            } else if (Fs == 31) {
4177733SAli.Saidi@ARM.com                                Rt = fcsr_reg;
4187733SAli.Saidi@ARM.com                            } else {
4197733SAli.Saidi@ARM.com                                panic("FP Control Value (%d) Not Available. Ignoring Access to"
4207733SAli.Saidi@ARM.com                                      "Floating Control Status Register",fcsr_reg);
4217733SAli.Saidi@ARM.com                            }
42210037SARM gem5 Developers
42310037SARM gem5 Developers                        }});
42410037SARM gem5 Developers
42510037SARM gem5 Developers                        0x6: ctc1({{
42610037SARM gem5 Developers                            /*xc->setMiscReg(FPCR[Fs],Rt);*/
42710037SARM gem5 Developers                        }});
4287733SAli.Saidi@ARM.com                    }
4296313Sgblack@eecs.umich.edu                }
4309461Snilay@cs.wisc.edu
4319461Snilay@cs.wisc.edu                0x1: decode ND {
4329553Sandreas.hansson@arm.com                    0x0: decode TF {
4339553Sandreas.hansson@arm.com                        format Branch {
4349553Sandreas.hansson@arm.com                            0x0: bc1f({{ cond = (xc->readMiscReg(FPCR) == 0); }});
4359384SAndreas.Sandberg@arm.com                            0x1: bc1t({{ cond = (xc->readMiscReg(FPCR) == 1); }});
4367400SAli.Saidi@ARM.com                        }
4379384SAndreas.Sandberg@arm.com                    }
4389384SAndreas.Sandberg@arm.com
4399384SAndreas.Sandberg@arm.com                    0x1: decode TF {
4406313Sgblack@eecs.umich.edu                        format BranchLikely {
4416313Sgblack@eecs.umich.edu                            0x0: bc1fl({{ cond = (xc->readMiscReg(FPCR) == 0); }});
4426313Sgblack@eecs.umich.edu                            0x1: bc1tl({{ cond = (xc->readMiscReg(FPCR) == 1); }});
4436313Sgblack@eecs.umich.edu                        }
444                    }
445                }
446            }
447
448            0x1: decode RS_HI {
449                0x2: decode RS_LO {
450
451                    //Table A-14 MIPS32 COP1 Encoding of Function Field When rs=S
452                    //(( single-word ))
453                    0x0: decode RS_HI {
454                        0x0: decode RS_LO {
455                            format FloatOp {
456                                0x0: adds({{ Fd.sf = Fs.sf + Ft.sf;}});
457                                0x1: subs({{ Fd.sf = Fs.sf - Ft.sf;}});
458                                0x2: muls({{ Fd.sf = Fs.sf * Ft.sf;}});
459                                0x3: divs({{ Fd.sf = Fs.sf / Ft.sf;}});
460                                0x4: sqrts({{ Fd.sf = sqrt(Fs.sf);}});
461                                0x5: abss({{ Fd.sf = fabs(Fs.sf);}});
462                                0x6: movs({{ Fd.sf = Fs.sf;}});
463                                0x7: negs({{ Fd.sf = -1 * Fs.sf;}});
464                            }
465                        }
466
467                        0x1: decode RS_LO {
468                            //only legal for 64 bit-FP
469                            format Float64Op {
470                                0x0: round_l_s({{ Fd = convert_and_round(Fs.sf,RND_NEAREST,FP_LONG,FP_SINGLE);}});
471                                0x1: trunc_l_s({{ Fd = convert_and_round(Fs.sf,RND_ZERO,FP_LONG,FP_SINGLE);}});
472                                0x2: ceil_l_s({{ Fd = convert_and_round(Fs.sf,RND_UP,FP_LONG,FP_SINGLE);}});
473                                0x3: floor_l_s({{ Fd = convert_and_round(Fs.sf,RND_DOWN,FP_LONG,FP_SINGLE);}});
474                            }
475
476                            format FloatOp {
477                                0x4: round_w_s({{ Fd = convert_and_round(Fs.sf,RND_NEAREST,FP_WORD,FP_SINGLE);}});
478                                0x5: trunc_w_s({{ Fd = convert_and_round(Fs.sf,RND_ZERO,FP_WORD,FP_SINGLE);}});
479                                0x6: ceil_w_s({{  Fd = convert_and_round(Fs.sf,RND_UP,FP_WORD,FP_SINGLE);}});
480                                0x7: floor_w_s({{ Fd = convert_and_round(Fs.sf,RND_DOWN,FP_WORD,FP_SINGLE);}});
481                            }
482                        }
483
484                        0x2: decode RS_LO {
485                            0x1: decode MOVCF {
486                                format FloatOp {
487                                    0x0: movfs({{if (xc->readMiscReg(FPCR) != CC) Fd = Fs; }});
488                                    0x1: movts({{if (xc->readMiscReg(FPCR) == CC) Fd = Fs;}});
489                                }
490                            }
491
492                            format BasicOp {
493                                0x2: movzs({{ if (Rt == 0) Fd = Fs; }});
494                                0x3: movns({{ if (Rt != 0) Fd = Fs; }});
495                            }
496
497                            format Float64Op {
498                                0x5: recips({{ Fd = 1 / Fs; }});
499                                0x6: rsqrts({{ Fd = 1 / sqrt((double)Fs.ud);}});
500                            }
501                        }
502
503                        0x4: decode RS_LO {
504
505                            format FloatOp {
506                                0x1: cvt_d_s({{ int rnd_mode = xc->readMiscReg(FCSR);
507                                Fd = convert_and_round(Fs.sf,rnd_mode,FP_DOUBLE,FP_SINGLE);
508                                }});
509
510                                0x4: cvt_w_s({{ int rnd_mode = xc->readMiscReg(FCSR);
511                                Fd = convert_and_round(Fs.sf,rnd_mode,FP_WORD,FP_SINGLE);
512                                }});
513                            }
514
515                            //only legal for 64 bit
516                            format Float64Op {
517                                0x5: cvt_l_s({{ int rnd_mode = xc->readMiscReg(FCSR);
518                                Fd = convert_and_round(Fs.sf,rnd_mode,FP_LONG,FP_SINGLE);
519                                }});
520
521                                0x6: cvt_ps_s({{ /*Fd.df = Fs.df<31:0> | Ft.df<31:0>;*/ }});
522                            }
523                        }
524                    }
525
526                    //Table A-15 MIPS32 COP1 Encoding of Function Field When rs=D
527                    0x1: decode RS_HI {
528                        0x0: decode RS_LO {
529                            format FloatOp {
530                                0x0: addd({{ Fd.df = Fs.df + Ft.df;}});
531                                0x1: subd({{ Fd.df = Fs.df - Ft.df;}});
532                                0x2: muld({{ Fd.df = Fs.df * Ft.df;}});
533                                0x3: divd({{ Fd.df = Fs.df / Ft.df;}});
534                                0x4: sqrtd({{ Fd.df = sqrt(Fs.df);}});
535                                0x5: absd({{ Fd.df = fabs(Fs.df);}});
536                                0x6: movd({{ Fd.df = Fs.df;}});
537                                0x7: negd({{ Fd.df = -1 * Fs.df;}});
538                            }
539                        }
540
541                        0x1: decode RS_LO {
542                            //only legal for 64 bit
543                            format Float64Op {
544                                0x0: round_l_d({{ Fd = convert_and_round(Fs.df,RND_NEAREST,FP_LONG,FP_DOUBLE); }});
545                                0x1: trunc_l_d({{ Fd = convert_and_round(Fs.df,RND_ZERO,FP_LONG,FP_DOUBLE);}});
546                                0x2: ceil_l_d({{ Fd = convert_and_round(Fs.df,RND_UP,FP_LONG,FP_DOUBLE);}});
547                                0x3: floor_l_d({{ Fd = convert_and_round(Fs.df,RND_DOWN,FP_LONG,FP_DOUBLE);}});
548                            }
549
550                            format FloatOp {
551                                0x4: round_w_d({{ Fd = convert_and_round(Fs.df,RND_NEAREST,FP_LONG,FP_DOUBLE); }});
552                                0x5: trunc_w_d({{ Fd = convert_and_round(Fs.df,RND_ZERO,FP_LONG,FP_DOUBLE); }});
553                                0x6: ceil_w_d({{  Fd = convert_and_round(Fs.df,RND_UP,FP_LONG,FP_DOUBLE); }});
554                                0x7: floor_w_d({{ Fd = convert_and_round(Fs.df,RND_DOWN,FP_LONG,FP_DOUBLE); }});
555                            }
556                        }
557
558                        0x2: decode RS_LO {
559                            0x1: decode MOVCF {
560                                format FloatOp {
561                                    0x0: movfd({{if (xc->readMiscReg(FPCR) != CC) Fd.df = Fs.df; }});
562                                    0x1: movtd({{if (xc->readMiscReg(FPCR) == CC) Fd.df = Fs.df; }});
563                                }
564                            }
565
566                            format BasicOp {
567                                0x2: movzd({{ if (Rt == 0) Fd.df = Fs.df; }});
568                                0x3: movnd({{ if (Rt != 0) Fd.df = Fs.df; }});
569                            }
570
571                            format Float64Op {
572                                0x5: recipd({{ Fd.df = 1 / Fs.df}});
573                                0x6: rsqrtd({{ Fd.df = 1 / sqrt(Fs.df) }});
574                            }
575                        }
576
577                        0x4: decode RS_LO {
578                            format FloatOp {
579                                0x0: cvt_s_d({{
580                                    int rnd_mode = xc->readMiscReg(FCSR);
581                                    Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_DOUBLE);
582                                }});
583
584                                0x4: cvt_w_d({{
585                                    int rnd_mode = xc->readMiscReg(FCSR);
586                                    Fd = convert_and_round(Fs.df,rnd_mode,FP_WORD,FP_DOUBLE);
587                                }});
588                            }
589
590                            //only legal for 64 bit
591                            format Float64Op {
592                                0x5: cvt_l_d({{
593                                    int rnd_mode = xc->readMiscReg(FCSR);
594                                    Fd = convert_and_round(Fs.df,rnd_mode,FP_LONG,FP_DOUBLE);
595                                }});
596                            }
597                        }
598                    }
599
600                    //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=W
601                    0x4: decode FUNCTION {
602                        format FloatOp {
603                            0x20: cvt_s({{
604                                int rnd_mode = xc->readMiscReg(FCSR);
605                                Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_WORD);
606                            }});
607
608                            0x21: cvt_d({{
609                                int rnd_mode = xc->readMiscReg(FCSR);
610                                Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_WORD);
611                            }});
612                        }
613                    }
614
615                    //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=L1
616                    //Note: "1. Format type L is legal only if 64-bit floating point operations
617                    //are enabled."
618                    0x5: decode FUNCTION_HI {
619                        format FloatOp {
620                            0x10: cvt_s_l({{
621                                int rnd_mode = xc->readMiscReg(FCSR);
622                                Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_LONG);
623                            }});
624
625                            0x11: cvt_d_l({{
626                                int rnd_mode = xc->readMiscReg(FCSR);
627                                Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_LONG);
628                            }});
629                        }
630                    }
631
632                    //Table A-17 MIPS64 COP1 Encoding of Function Field When rs=PS1
633                    //Note: "1. Format type PS is legal only if 64-bit floating point operations
634                    //are enabled. "
635                    0x6: decode RS_HI {
636                        0x0: decode RS_LO {
637                            format Float64Op {
638                                0x0: addps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
639                                    //Lower Halves Independently but we take simulator shortcut
640                                    Fd.df = Fs.df + Ft.df;
641                                }});
642
643                                0x1: subps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
644                                    //Lower Halves Independently but we take simulator shortcut
645                                    Fd.df = Fs.df - Ft.df;
646                                }});
647
648                                0x2: mulps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
649                                    //Lower Halves Independently but we take simulator shortcut
650                                    Fd.df = Fs.df * Ft.df;
651                                }});
652
653                                0x5: absps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
654                                    //Lower Halves Independently but we take simulator shortcut
655                                    Fd.df = fabs(Fs.df);
656                                }});
657
658                                0x6: movps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
659                                    //Lower Halves Independently but we take simulator shortcut
660                                    //Fd.df = Fs<31:0> |  Ft<31:0>;
661                                }});
662
663                                0x7: negps({{ //Must Check for Exception Here... Supposed to Operate on Upper and
664                                    //Lower Halves Independently but we take simulator shortcut
665                                    Fd.df = -1 * Fs.df;
666                                }});
667                            }
668                        }
669
670                        0x2: decode RS_LO {
671                            0x1: decode MOVCF {
672                                format Float64Op {
673                                    0x0: movfps({{if (xc->readMiscReg(FPCR) != CC) Fd = Fs;}});
674                                    0x1: movtps({{if (xc->readMiscReg(FPCR) == CC) Fd = Fs;}});
675                                }
676                            }
677
678                            format BasicOp {
679                                0x2: movzps({{if (xc->readMiscReg(FPCR) != CC) Fd = Fs; }});
680                                0x3: movnps({{if (xc->readMiscReg(FPCR) == CC) Fd = Fs; }});
681                            }
682
683                        }
684
685                        0x4: decode RS_LO {
686                            0x0: Float64Op::cvt_s_pu({{
687                                int rnd_mode = xc->readMiscReg(FCSR);
688                                Fd = convert_and_round(Fs.df,rnd_mode,FP_DOUBLE,FP_PS_HI);
689                            }});
690                        }
691
692                        0x5: decode RS_LO {
693                            format Float64Op {
694                                0x0: cvt_s_pl({{
695                                    int rnd_mode = xc->readMiscReg(FCSR);
696                                    Fd = convert_and_round(Fs.df,rnd_mode,FP_SINGLE,FP_PS_LO);
697                                }});
698                                0x4: pll({{ /*Fd.df = Fs<31:0> | Ft<31:0>*/}});
699                                0x5: plu({{ /*Fd.df = Fs<31:0> | Ft<63:32>*/}});
700                                0x6: pul({{ /*Fd.df = Fs<63:32> | Ft<31:0>*/}});
701                                0x7: puu({{ /*Fd.df = Fs<63:32 | Ft<63:32>*/}});
702                            }
703                        }
704                    }
705                }
706            }
707        }
708
709        //Table A-19 MIPS32 COP2 Encoding of rs Field
710        0x2: decode RS_MSB {
711            0x0: decode RS_HI {
712                0x0: decode RS_LO {
713                    format WarnUnimpl {
714                        0x0: mfc2();
715                        0x2: cfc2();
716                        0x3: mfhc2();
717                        0x4: mtc2();
718                        0x6: ctc2();
719                        0x7: mftc2();
720                    }
721                }
722
723                0x1: decode ND {
724                    0x0: decode TF {
725                        format WarnUnimpl {
726                            0x0: bc2f();
727                            0x1: bc2t();
728                        }
729                    }
730
731                    0x1: decode TF {
732                        format WarnUnimpl {
733                            0x0: bc2fl();
734                            0x1: bc2tl();
735                        }
736                    }
737                }
738            }
739        }
740
741        //Table A-20 MIPS64 COP1X Encoding of Function Field 1
742        //Note: "COP1X instructions are legal only if 64-bit floating point
743        //operations are enabled."
744        0x3: decode FUNCTION_HI {
745            0x0: decode FUNCTION_LO {
746                format LoadMemory2 {
747                    0x0: lwxc1({{ EA = Rs + Rt; }},{{ /*F_t<31:0> = Mem.sf; */}});
748                    0x1: ldxc1({{ EA = Rs + Rt; }},{{ /*F_t<63:0> = Mem.df;*/ }});
749                    0x5: luxc1({{ //Need to make EA<2:0> = 0
750                        EA = Rs + Rt;
751                    }},
752                {{ /*F_t<31:0> = Mem.df; */}});
753                }
754            }
755
756            0x1: decode FUNCTION_LO {
757                format StoreMemory2 {
758                    0x0: swxc1({{ EA = Rs + Rt; }},{{ /*Mem.sf = Ft<31:0>; */}});
759                    0x1: sdxc1({{ EA = Rs + Rt; }},{{ /*Mem.df = Ft<63:0> */}});
760                    0x5: suxc1({{ //Need to make EA<2:0> = 0
761                        EA = Rs + Rt;
762                    }},
763                {{ /*Mem.df = F_t<63:0>;*/}});
764                }
765
766                0x7: WarnUnimpl::prefx();
767            }
768
769            format FloatOp {
770                0x3: WarnUnimpl::alnv_ps();
771
772                format BasicOp {
773                    0x4: decode FUNCTION_LO {
774                        0x0: madd_s({{ Fd.sf = (Fs.sf * Fs.sf) + Fr.sf; }});
775                        0x1: madd_d({{ Fd.df = (Fs.df * Fs.df) + Fr.df; }});
776                        0x6: madd_ps({{
777                            //Must Check for Exception Here... Supposed to Operate on Upper and
778                            //Lower Halves Independently but we take simulator shortcut
779                            Fd.df = (Fs.df * Fs.df) + Fr.df;
780                        }});
781                    }
782
783                    0x5: decode FUNCTION_LO {
784                        0x0: msub_s({{ Fd.sf = (Fs.sf * Fs.sf) - Fr.sf; }});
785                        0x1: msub_d({{ Fd.df = (Fs.df * Fs.df) - Fr.df; }});
786                        0x6: msub_ps({{
787                            //Must Check for Exception Here... Supposed to Operate on Upper and
788                            //Lower Halves Independently but we take simulator shortcut
789                            Fd.df = (Fs.df * Fs.df) - Fr.df;
790                        }});
791                    }
792
793                    0x6: decode FUNCTION_LO {
794                        0x0: nmadd_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }});
795                        0x1: nmadd_d({{ Fd.df = (-1 * Fs.df * Fs.df) + Fr.df; }});
796                        0x6: nmadd_ps({{
797                            //Must Check for Exception Here... Supposed to Operate on Upper and
798                            //Lower Halves Independently but we take simulator shortcut
799                            Fd.df = (-1 * Fs.df * Fs.df) + Fr.df;
800                        }});
801                    }
802
803                    0x7: decode FUNCTION_LO {
804                        0x0: nmsub_s({{ Fd.sf = (-1 * Fs.sf * Fs.sf) - Fr.sf; }});
805                        0x1: nmsub_d({{ Fd.df = (-1 * Fs.df * Fs.df) - Fr.df; }});
806                        0x6: nmsub_ps({{
807                            //Must Check for Exception Here... Supposed to Operate on Upper and
808                            //Lower Halves Independently but we take simulator shortcut
809                            Fd.df = (-1 * Fs.df * Fs.df) + Fr.df;
810                        }});
811                    }
812                }
813            }
814        }
815
816        //MIPS obsolete instructions
817        format BranchLikely {
818            0x4: beql({{ cond = (Rs.sw == 0); }});
819            0x5: bnel({{ cond = (Rs.sw != 0); }});
820            0x6: blezl({{ cond = (Rs.sw <= 0); }});
821            0x7: bgtzl({{ cond = (Rs.sw > 0); }});
822        }
823    }
824
825    0x3: decode OPCODE_LO default FailUnimpl::reserved() {
826
827        //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field
828        0x4: decode FUNCTION_HI {
829
830            0x0: decode FUNCTION_LO {
831                format IntOp {
832                    0x0: madd({{
833                        int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32;
834                        temp1 = temp1 + (Rs.sw * Rt.sw);
835                        xc->setMiscReg(Hi,temp1<63:32>);
836                        xc->setMiscReg(Lo,temp1<31:0>);
837                            }});
838
839                    0x1: maddu({{
840                        int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32;
841                        temp1 = temp1 + (Rs.uw * Rt.uw);
842                        xc->setMiscReg(Hi,temp1<63:32>);
843                        xc->setMiscReg(Lo,temp1<31:0>);
844                            }});
845
846                    0x2: mul({{ Rd.sw = Rs.sw * Rt.sw; 	}});
847
848                    0x4: msub({{
849                        int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32;
850                        temp1 = temp1 - (Rs.sw * Rt.sw);
851                        xc->setMiscReg(Hi,temp1<63:32>);
852                        xc->setMiscReg(Lo,temp1<31:0>);
853                            }});
854
855                    0x5: msubu({{
856                        int64_t temp1 = xc->readMiscReg(Hi) << 32 | xc->readMiscReg(Lo) >> 32;
857                        temp1 = temp1 - (Rs.uw * Rt.uw);
858                        xc->setMiscReg(Hi,temp1<63:32>);
859                        xc->setMiscReg(Lo,temp1<31:0>);
860                            }});
861                }
862            }
863
864            0x4: decode FUNCTION_LO {
865                format BasicOp {
866                    0x0: clz({{
867                        /*int cnt = 0;
868                        int idx = 0;
869                        while ( Rs.uw<idx> != 1) {
870                            cnt++;
871                            idx--;
872                        }
873
874                        Rd.uw = cnt;*/
875                    }});
876
877                    0x1: clo({{
878                        /*int cnt = 0;
879                        int idx = 0;
880                        while ( Rs.uw<idx> != 0) {
881                            cnt++;
882                            idx--;
883                        }
884
885                        Rd.uw = cnt;*/
886                    }});
887                }
888            }
889
890            0x7: decode FUNCTION_LO {
891                0x7: WarnUnimpl::sdbbp();
892            }
893        }
894
895        //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2 of the Architecture
896        0x7: decode FUNCTION_HI {
897
898            0x0: decode FUNCTION_LO {
899                format FailUnimpl {
900                    0x1: ext();
901                    0x4: ins();
902                }
903            }
904
905            0x1: decode FUNCTION_LO {
906                format FailUnimpl {
907                    0x0: fork();
908                    0x1: yield();
909                }
910            }
911
912
913            //Table A-10 MIPS32 BSHFL Encoding of sa Field
914            0x4: decode SA {
915
916                0x02: FailUnimpl::wsbh();
917
918                format BasicOp {
919                    0x10: seb({{ Rd.sw = Rt<7:0>}});
920                    0x18: seh({{ Rd.sw = Rt<15:0>}});
921                }
922            }
923
924            0x6: decode FUNCTION_LO {
925                0x7: FailUnimpl::rdhwr();//{{ /*Rt = xc->hwRegs[RD];*/ }}
926            }
927        }
928    }
929
930    0x4: decode OPCODE_LO default FailUnimpl::reserved() {
931        format LoadMemory {
932            0x0: lb({{ Rt.sw = Mem.sb; }});
933            0x1: lh({{ Rt.sw = Mem.sh; }});
934
935            0x2: lwl({{
936                uint32_t mem_word = Mem.uw;
937                uint32_t unalign_addr = Rs + disp;
938                uint32_t offset = unalign_addr & 0x00000003;
939#if BYTE_ORDER == BIG_ENDIAN
940                std::cout << "Big Endian Byte Order\n";
941
942                switch(offset)
943                {
944                  case 0:
945                    Rt = mem_word;
946                    break;
947
948                  case 1:
949                    Rt &= 0x000F;
950                    Rt |= (mem_word << 4);
951                    break;
952
953                  case 2:
954                    Rt &= 0x00FF;
955                    Rt |= (mem_word << 8);
956                    break;
957
958                  case 3:
959                    Rt &= 0x0FFF;
960                    Rt |= (mem_word << 12);
961                    break;
962
963                  default:
964                    panic("lwl: bad offset");
965                }
966#elif BYTE_ORDER == LITTLE_ENDIAN
967                std::cout << "Little Endian Byte Order\n";
968
969                switch(offset)
970                {
971                  case 0:
972                    Rt &= 0x0FFF;
973                    Rt |= (mem_word << 12);
974                    break;
975
976                  case 1:
977                    Rt &= 0x00FF;
978                    Rt |= (mem_word << 8);
979                    break;
980
981                  case 2:
982                    Rt &= 0x000F;
983                    Rt |= (mem_word << 4);
984                    break;
985
986                  case 3:
987                    Rt = mem_word;
988                    break;
989
990                  default:
991                    panic("lwl: bad offset");
992                }
993#endif
994            }}, {{ EA = (Rs + disp) & ~3; }});
995
996            0x3: lw({{ Rt.sw = Mem.sw; }});
997            0x4: lbu({{ Rt.uw = Mem.ub; }});
998            0x5: lhu({{ Rt.uw = Mem.uh; }});
999            0x6: lwr({{
1000                uint32_t mem_word = Mem.uw;
1001                uint32_t unalign_addr = Rs + disp;
1002                uint32_t offset = unalign_addr & 0x00000003;
1003
1004#if BYTE_ORDER == BIG_ENDIAN
1005                switch(offset)
1006                {
1007                  case 0: Rt &= 0xFFF0;  Rt |= (mem_word >> 12); break;
1008                  case 1: Rt &= 0xFF00;  Rt |= (mem_word >> 8);  break;
1009                  case 2: Rt &= 0xF000;  Rt |= (mem_word >> 4);  break;
1010                  case 3: Rt = mem_word; break;
1011                  default: panic("lwr: bad offset");
1012                }
1013#elif BYTE_ORDER == LITTLE_ENDIAN
1014                switch(offset)
1015                {
1016                  case 0: Rt = mem_word; break;
1017                  case 1: Rt &= 0xF000;  Rt |= (mem_word >> 4);  break;
1018                  case 2: Rt &= 0xFF00;  Rt |= (mem_word >> 8);  break;
1019                  case 3: Rt &= 0xFFF0;  Rt |= (mem_word >> 12); break;
1020                  default: panic("lwr: bad offset");
1021                }
1022#endif
1023            }},
1024            {{ EA = (Rs + disp) & ~3; }});
1025        }
1026
1027        0x7: FailUnimpl::reserved();
1028    }
1029
1030    0x5: decode OPCODE_LO default FailUnimpl::reserved() {
1031        format StoreMemory {
1032            0x0: sb({{ Mem.ub = Rt<7:0>; }});
1033            0x1: sh({{ Mem.uh = Rt<15:0>; }});
1034            0x2: swl({{
1035                uint32_t mem_word = 0;
1036                uint32_t aligned_addr = (Rs + disp) & ~3;
1037                uint32_t unalign_addr = Rs + disp;
1038                uint32_t offset = unalign_addr & 0x00000003;
1039
1040                DPRINTF(IEW,"Execute: aligned=0x%x unaligned=0x%x\n offset=0x%x",
1041                        aligned_addr,unalign_addr,offset);
1042
1043                fault = xc->read(aligned_addr, (uint32_t&)mem_word, memAccessFlags);
1044
1045#if BYTE_ORDER == BIG_ENDIAN
1046                switch(offset)
1047                {
1048                  case 0:
1049                    Mem = Rt;
1050                    break;
1051
1052                  case 1:
1053                    mem_word &= 0xF000;
1054                    mem_word |= (Rt >> 4);
1055                    Mem = mem_word;
1056                    break;
1057
1058                  case 2:
1059                    mem_word &= 0xFF00;
1060                    mem_word |= (Rt >> 8);
1061                    Mem = mem_word;
1062                    break;
1063
1064                  case 3:
1065                    mem_word &= 0xFFF0;
1066                    mem_word |= (Rt >> 12);
1067                    Mem = mem_word;
1068                   break;
1069
1070                  default:
1071                    panic("swl: bad offset");
1072                }
1073#elif BYTE_ORDER == LITTLE_ENDIAN
1074                switch(offset)
1075                {
1076                  case 0:
1077                    mem_word &= 0xFFF0;
1078                    mem_word |= (Rt >> 12);
1079                    Mem = mem_word;
1080                    break;
1081
1082                  case 1:
1083                    mem_word &= 0xFF00;
1084                    mem_word |= (Rt >> 8);
1085                    Mem = mem_word;
1086                    break;
1087
1088                  case 2:
1089                    mem_word &= 0xF000;
1090                    mem_word |= (Rt >> 4);
1091                    Mem = mem_word;
1092                    break;
1093
1094                  case 3:
1095                    Mem = Rt;
1096                   break;
1097
1098                  default:
1099                    panic("swl: bad offset");
1100                }
1101#endif
1102            }},{{ EA = (Rs + disp) & ~3; }},mem_flags = NO_ALIGN_FAULT);
1103
1104            0x3: sw({{ Mem.uw = Rt<31:0>; }});
1105
1106            0x6: swr({{
1107                uint32_t mem_word = 0;
1108                uint32_t aligned_addr = (Rs + disp) & ~3;
1109                uint32_t unalign_addr = Rs + disp;
1110                uint32_t offset = unalign_addr & 0x00000003;
1111
1112                fault = xc->read(aligned_addr, (uint32_t&)mem_word, memAccessFlags);
1113
1114#if BYTE_ORDER == BIG_ENDIAN
1115                switch(offset)
1116                {
1117                  case 0:
1118                    mem_word &= 0x0FFF;
1119                    mem_word |= (Rt << 12);
1120                    Mem = mem_word;
1121                    break;
1122
1123                  case 1:
1124                    mem_word &= 0x00FF;
1125                    mem_word |= (Rt << 8);
1126                    Mem = mem_word;
1127                    break;
1128
1129                  case 2:
1130                    mem_word &= 0x000F;
1131                    mem_word |= (Rt << 4);
1132                    Mem = mem_word;
1133                    break;
1134
1135                  case 3:
1136                    Mem = Rt;
1137                    break;
1138
1139                  default:
1140                    panic("swr: bad offset");
1141                }
1142#elif BYTE_ORDER == LITTLE_ENDIAN
1143                switch(offset)
1144                {
1145                  case 0:
1146                    Mem = Rt;
1147                    break;
1148
1149                  case 1:
1150                    mem_word &= 0x000F;
1151                    mem_word |= (Rt << 4);
1152                    Mem = mem_word;
1153                    break;
1154
1155                  case 2:
1156                    mem_word &= 0x00FF;
1157                    mem_word |= (Rt << 8);
1158                    Mem = mem_word;
1159                    break;
1160
1161                  case 3:
1162                    mem_word &= 0x0FFF;
1163                    mem_word |= (Rt << 12);
1164                    Mem = mem_word;
1165                    break;
1166
1167                  default:
1168                    panic("swr: bad offset");
1169                }
1170#endif
1171            }},{{ EA = (Rs + disp) & ~3;}},mem_flags = NO_ALIGN_FAULT);
1172        }
1173
1174        format WarnUnimpl {
1175            0x7: cache();
1176        }
1177
1178    }
1179
1180    0x6: decode OPCODE_LO default FailUnimpl::reserved() {
1181        0x0: FailUnimpl::ll();
1182
1183        format LoadMemory {
1184            0x1: lwc1({{ /*F_t<31:0> = Mem.sf; */}});
1185            0x5: ldc1({{ /*F_t<63:0> = Mem.df; */}});
1186        }
1187    }
1188
1189
1190    0x7: decode OPCODE_LO default FailUnimpl::reserved() {
1191        0x0: FailUnimpl::sc();
1192
1193        format StoreMemory {
1194            0x1: swc1({{ //Mem.sf = Ft<31:0>; }});
1195            0x5: sdc1({{ //Mem.df = Ft<63:0>; }});
1196        }
1197    }
1198}
1199
1200
1201