decoder.isa revision 2027
1////////////////////////////////////////////////////////////////////
2//
3// The actual MIPS32 ISA decoder
4// -----------------------------
5// The following instructions are specified in the MIPS32 ISA
6// Specification. Decoding closely follows the style specified
7// in the MIPS32 ISAthe specification document starting with Table
8// A-2 (document available @ www.mips.com)
9//
10//@todo: Distinguish "unknown/future" use insts from "reserved"
11// ones
12decode OPCODE_HI default FailUnimpl::unknown() {
13
14    // Derived From ... Table A-2 MIPS32 ISA Manual
15    0x0: decode OPCODE_LO default FailUnimpl::reserved(){
16
17        0x0: decode FUNCTION_HI {
18            0x0: decode FUNCTION_LO {
19              0x1: decode MOVCI {
20                format Move {
21                  0: movc({{ }});
22                  1: movt({{ }});
23                }
24              }
25
26              format ShiftRotate {
27                //Table A-3 Note: "1. Specific encodings of the rt, rd, and sa fields
28                //are used to distinguish among the SLL, NOP, SSNOP and EHB functions."
29                0x0: sll({{ }});
30
31                0x2: decode SRL {
32                   0: srl({{ }});
33                   1: rotr({{ }});
34                 }
35
36                 0x3: sar({{ }});
37
38                 0x4: sllv({{ }});
39
40                 0x6: decode SRLV {
41                   0: srlv({{ }});
42                   1: rotrv({{ }});
43                 }
44
45                 0x7: srav({{ }});
46              }
47            }
48
49            0x1: decode FUNCTION_LO {
50
51              //Table A-3 Note: "Specific encodings of the hint field are used
52              //to distinguish JR from JR.HB and JALR from JALR.HB"
53              format Jump {
54                0x0: jr({{ }});
55                0x1: jalr({{ }});
56              }
57
58              format Move {
59                0x2: movz({{ }});
60                0x3: movn({{ }});
61              }
62
63              0x4: Syscall::syscall({{ }});
64              0x5: Break::break({{ }});
65              0x7: Synchronize::synch({{ }});
66            }
67
68            0x2: decode FUNCTION_LO {
69              format MultDiv {
70                0x0: mfhi({{ }});
71                0x1: mthi({{ }});
72                0x2: mflo({{ }});
73                0x3: mtlo({{ }});
74              }
75            };
76
77            0x3: decode FUNCTION_LO {
78              format MultDiv {
79                0x0: mult({{ }});
80                0x1: multu({{ }});
81                0x2: div({{ }});
82                0x3: divu({{ }});
83              }
84            };
85
86            0x4: decode FUNCTION_LO {
87              format Arithmetic {
88                0x0: add({{ }});
89                0x1: addu({{ }});
90                0x2: sub({{ }});
91                0x3: subu({{ }});
92              }
93
94              format Logical {
95                0x0: and({{ }});
96                0x1: or({{ }});
97                0x2: xor({{ }});
98                0x3: nor({{ }});
99              }
100            }
101
102            0x5: decode FUNCTION_LO {
103              format SetInstructions{
104                0x2: slt({{ }});
105                0x3: sltu({{ }});
106              }
107            };
108
109            0x6: decode FUNCTION_LO {
110              format Trap {
111                 0x0: tge({{ }});
112                 0x1: tgeu({{ }});
113                 0x2: tlt({{ }});
114                 0x3: tltu({{ }});
115                 0x4: teq({{ }});
116                 0x6: tne({{ }});
117              }
118            }
119        }
120
121        0x1: decode REGIMM_HI {
122            0x0: decode REGIMM_LO {
123              format Branch {
124                0x0: bltz({{ }});
125                0x1: bgez({{ }});
126
127                //MIPS obsolete instructions
128                0x2: bltzl({{ }});
129                0x3: bgezl({{ }});
130              }
131            }
132
133            0x1: decode REGIMM_LO {
134              format Trap {
135                 0x0: tgei({{ }});
136                 0x1: tgeiu({{ }});
137                 0x2: tlti({{ }});
138                 0x3: tltiu({{ }});
139                 0x4: teqi({{ }});
140                 0x6: tnei({{ }});
141              }
142            }
143
144            0x2: decode REGIMM_LO {
145              format Branch {
146                0x0: bltzal({{ }});
147                0x1: bgezal({{ }});
148
149                //MIPS obsolete instructions
150                0x2: bltzall({{ }});
151                0x3: bgezall({{ }});
152              }
153            }
154
155            0x3: decode REGIMM_LO {
156              0x7: synci({{ }});
157            }
158        }
159
160        format Jump {
161            0x2: j({{ }});
162            0x3: jal({{ }});
163        }
164
165        format Branch {
166            0x4: beq({{ }});
167            0x5: bne({{ }});
168            0x6: blez({{ }});
169            0x7: bgtz({{ }});
170        }
171    };
172
173    0x1: decode OPCODE_LO default FailUnimpl::reserved(){
174        format IntImmediate {
175            0x0: addi({{ }});
176            0x1: addiu({{ }});
177            0x2: slti({{ }});
178            0x3: sltiu({{ }});
179            0x4: andi({{ }});
180            0x5: ori({{ }});
181            0x6: xori({{ }});
182            0x7: lui({{ }});
183        };
184    };
185
186    0x2: decode OPCODE_LO default FailUnimpl::reserved(){
187
188      //Table A-11 MIPS32 COP0 Encoding of rs Field
189      0x0: decode RS_MSB {
190        0x0: decode RS {
191          0x0: mfc0({{ }});
192          0xC: mtc0({{ }});
193          0xA: rdpgpr({{ }});
194
195          0xB: decode SC {
196            0x0: di({{ }});
197            0x1: ei({{ }});
198          }
199
200          0xE: wrpgpr({{ }});
201        }
202
203        //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO
204        0x1: decode FUNCTION {
205          0x01: tlbr({{ }});
206          0x02: tlbwi({{ }});
207          0x06: tlbwr({{ }});
208          0x08: tlbp({{ }});
209          0x18: eret({{ }});
210          0x1F: deret({{ }});
211          0x20: wait({{ }});
212        }
213      }
214
215      //Table A-13 MIPS32 COP1 Encoding of rs Field
216      0x1: decode RS_MSB {
217
218        0x0: decode RS_HI {
219          0x0: decode RS_LO {
220            0x0: mfc1({{ }});
221            0x2: cfc1({{ }});
222            0x3: mfhc1({{ }});
223            0x4: mtc1({{ }});
224            0x6: ctc1({{ }});
225            0x7: mftc1({{ }});
226          }
227
228          0x1: decode ND {
229            0x0: decode TF {
230              0x0: bc1f({{ }});
231              0x1: bc1t({{ }});
232            }
233
234            0x1: decode TF {
235              0x0: bc1fl({{ }});
236              0x1: bc1tl({{ }});
237            }
238          }
239        }
240
241        0x1: decode RS_HI {
242          0x2: decode RS_LO {
243
244            //Table A-14 MIPS32 COP1 Encoding of Function Field When rs=S
245            //(( single-word ))
246            0x0: decode RS_HI {
247              0x0: decode RS_LO {
248                0x0: add_fmt({{ }});
249                0x1: sub_fmt({{ }});
250                0x2: mul_fmt({{ }});
251                0x3: div_fmt({{ }});
252                0x4: sqrt_fmt({{ }});
253                0x5: abs_fmt({{ }});
254                0x6: mov_fmt({{ }});
255                0x7: neg_fmt({{ }});
256              }
257
258              0x1: decode RS_LO {
259                //only legal for 64 bit
260                format mode64 {
261                  0x0: round_l({{ }});
262                  0x1: trunc_l({{ }});
263                  0x2: ceil_l({{ }});
264                  0x3: floor_l({{ }});
265                }
266
267                0x4: round_w({{ }});
268                0x5: trunc_w({{ }});
269                0x6: ceil_w({{ }});
270                0x7: floor_w({{ }});
271              }
272
273              0x2: decode RS_LO {
274                0x1: decode MOVCF {
275                  0x0: movf_fmt({{ }});
276                  0x1: movt_fmt({{ }});
277                }
278
279                0x2: movz({{ }});
280                0x3: movn({{ }});
281
282                format mode64 {
283                  0x2: recip({{ }});
284                  0x3: rsqrt{{ }});
285                }
286              }
287
288              0x4: decode RS_LO {
289                0x1: cvt_d({{ }});
290                0x4: cvt_w({{ }});
291
292                //only legal for 64 bit
293                format mode64 {
294                  0x5: cvt_l({{ }});
295                  0x6: cvt_ps({{ }});
296                }
297              }
298            }
299
300            //Table A-15 MIPS32 COP1 Encoding of Function Field When rs=D
301            0x1: decode RS_HI {
302              0x0: decode RS_LO {
303                0x0: add_fmt({{ }});
304                0x1: sub_fmt({{ }});
305                0x2: mul_fmt({{ }});
306                0x3: div_fmt({{ }});
307                0x4: sqrt_fmt({{ }});
308                0x5: abs_fmt({{ }});
309                0x6: mov_fmt({{ }});
310                0x7: neg_fmt({{ }});
311              }
312
313              0x1: decode RS_LO {
314                //only legal for 64 bit
315                format mode64 {
316                  0x0: round_l({{ }});
317                  0x1: trunc_l({{ }});
318                  0x2: ceil_l({{ }});
319                  0x3: floor_l({{ }});
320                }
321
322                0x4: round_w({{ }});
323                0x5: trunc_w({{ }});
324                0x6: ceil_w({{ }});
325                0x7: floor_w({{ }});
326              }
327
328              0x2: decode RS_LO {
329                0x1: decode MOVCF {
330                  0x0: movf_fmt({{ }});
331                  0x1: movt_fmt({{ }});
332                }
333
334                0x2: movz({{ }});
335                0x3: movn({{ }});
336
337                format mode64 {
338                  0x5: recip({{ }});
339                  0x6: rsqrt{{ }});
340                }
341              }
342
343              0x4: decode RS_LO {
344                0x0: cvt_s({{ }});
345                0x4: cvt_w({{ }});
346
347                //only legal for 64 bit
348                format mode64 {
349                  0x5: cvt_l({{ }});
350                }
351              }
352            }
353
354            //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=W
355            0x4: decode FUNCTION {
356              0x10: cvt_s({{ }});
357              0x10: cvt_d({{ }});
358            }
359
360            //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=L1
361            //Note: "1. Format type L is legal only if 64-bit floating point operations
362            //are enabled."
363            0x5: decode FUNCTION_HI {
364              0x10: cvt_s({{ }});
365              0x11: cvt_d({{ }});
366            }
367
368            //Table A-17 MIPS64 COP1 Encoding of Function Field When rs=PS1
369            //Note: "1. Format type PS is legal only if 64-bit floating point operations
370            //are enabled. "
371            0x6: decode RS_HI {
372              0x0: decode RS_LO {
373                0x0: add_fmt({{ }});
374                0x1: sub_fmt({{ }});
375                0x2: mul_fmt({{ }});
376                0x5: abs_fmt({{ }});
377                0x6: mov_fmt({{ }});
378                0x7: neg_fmt({{ }});
379              }
380
381              0x2: decode RS_LO {
382                0x1: decode MOVCF {
383                  0x0: movf_fmt({{ }});
384                  0x1: movt_fmt({{ }});
385                }
386
387                0x2: movz({{ }});
388                0x3: movn({{ }});
389              }
390
391              0x4: decode RS_LO {
392                0x0: cvt_s_pu({{ }});
393              }
394
395              0x5: decode RS_LO {
396                0x0: cvt_s_pl({{ }});
397                0x4: pll_s_pl({{ }});
398                0x5: plu_s_pl({{ }});
399                0x6: pul_s_pl({{ }});
400                0x7: puu_s_pl({{ }});
401              }
402            }
403      }
404
405      //Table A-19 MIPS32 COP2 Encoding of rs Field
406      0x2: decode RS_MSB {
407        0x0: decode RS_HI {
408          0x0: decode RS_LO {
409            0x0: mfc2({{ }});
410            0x2: cfc2({{ }});
411            0x3: mfhc2({{ }});
412            0x4: mtc2({{ }});
413            0x6: ctc2({{ }});
414            0x7: mftc2({{ }});
415          }
416
417          0x1: decode ND {
418            0x0: decode TF {
419              0x0: bc2f({{ }});
420              0x1: bc2t({{ }});
421            }
422
423            0x1: decode TF {
424              0x0: bc2fl({{ }});
425              0x1: bc2tl({{ }});
426            }
427          }
428        }
429      }
430
431      //Table A-20 MIPS64 COP1X Encoding of Function Field 1
432      //Note: "COP1X instructions are legal only if 64-bit floating point
433      //operations are enabled."
434      0x3: decode FUNCTION_HI {
435        0x0: decode FUNCTION_LO {
436          0x0: lwxc1({{ }});
437          0x1: ldxc1({{ }});
438          0x5: luxc1({{ }});
439        }
440
441        0x1: decode FUNCTION_LO {
442          0x0: swxc1({{ }});
443          0x1: sdxc1({{ }});
444          0x5: suxc1({{ }});
445          0x7: prefx({{ }});
446        }
447
448        0x3: alnv_ps({{ }});
449
450        0x4: decode FUNCTION_LO {
451          0x0: madd_s({{ }});
452          0x1: madd_d({{ }});
453          0x6: madd_ps({{ }});
454        }
455
456        0x5: decode FUNCTION_LO {
457          0x0: msub_s({{ }});
458          0x1: msub_d({{ }});
459          0x6: msub_ps({{ }});
460        }
461
462        0x6: decode FUNCTION_LO {
463          0x0: nmadd_s({{ }});
464          0x1: nmadd_d({{ }});
465          0x6: nmadd_ps({{ }});
466        }
467
468        0x7: decode FUNCTION_LO {
469          0x0: nmsub_s({{ }});
470          0x1: nmsub_d({{ }});
471          0x6: nmsub_ps({{ }});
472        }
473      }
474
475      //MIPS obsolete instructions
476      0x4: beql({{ }});
477      0x5: bnel({{ }});
478      0x6: blezl({{ }});
479      0x7: bgtzl({{ }});
480    };
481
482    0x3: decode OPCODE_LO default FailUnimpl::reserved(){
483
484        //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field
485        0x4: decode FUNCTION_HI {
486
487            0x0: decode FUNCTION_LO {
488              0x0: madd({{ }});
489              0x1: maddu({{ }});
490              0x2: mult({{ }});
491              0x4: msub({{ }});
492              0x5: msubu({{ }});
493            }
494
495            0x4: decode FUNCTION_LO {
496              0x0: clz({{ }});
497              0x1: clo({{ }});
498            }
499
500            0x7: decode FUNCTION_LO {
501              0x7: sdbbp({{ }});
502            }
503        }
504
505        //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2 of the Architecture
506        0x7: decode FUNCTION_HI {
507
508          0x0: decode FUNCTION_LO {
509            0x1: ext({{ }});
510            0x4: ins({{ }});
511          }
512
513          //Table A-10 MIPS32 BSHFL Encoding of sa Field
514          0x4: decode SA {
515            0x02: wsbh({{ }});
516            0x10: seb({{ }});
517            0x18: seh({{ }});
518          }
519
520          0x6: decode FUNCTION_LO {
521            0x7: rdhwr({{ }});
522          }
523        }
524    };
525
526    0x4: decode OPCODE_LO default FailUnimpl::reserved(){
527        format LoadMemory{
528            0x0: lb({{ }});
529            0x1: lh({{ }});
530            0x2: lwl({{ }});
531            0x3: lw({{ }});
532            0x4: lbu({{ }});
533            0x5: lhu({{ }});
534            0x6: lhu({{ }});
535        };
536
537        0x7: FailUnimpl::reserved({{ }});
538    };
539
540    0x5: decode OPCODE_LO default FailUnimpl::reserved(){
541        format StoreMemory{
542            0x0: sb({{ }});
543            0x1: sh({{ }});
544            0x2: swl({{ }});
545            0x3: sw({{ }});
546            0x6: swr({{ }});
547        };
548
549        format FailUnimpl{
550            0x4: reserved({{ }});
551            0x5: reserved({{ }});
552            0x7: cache({{ }});
553        };
554
555    };
556
557    0x6: decode OPCODE_LO default FailUnimpl::reserved(){
558        format LoadMemory{
559            0x0: ll({{ }});
560            0x1: lwc1({{ }});
561            0x5: ldc1({{ }});
562        };
563    };
564
565    0x7: decode OPCODE_LO default FailUnimpl::reserved(){
566        format StoreMemory{
567            0x0: sc({{ }});
568            0x1: swc1({{ }});
569            0x5: sdc1({{ }});
570        };
571
572    }
573}
574
575
576