decoder.isa revision 2025
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 SPECIAL_HI {
18            0x0: decode SPECIAL_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 SPECIAL_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 SPECIAL_LO {
69              format MultDiv {
70                0x0: mfhi({{ }});
71                0x1: mthi({{ }});
72                0x2: mflo({{ }});
73                0x3: mtlo({{ }});
74              }
75            };
76
77            0x3: decode SPECIAL_LO {
78              format MultDiv {
79                0x0: mult({{ }});
80                0x1: multu({{ }});
81                0x2: div({{ }});
82                0x3: divu({{ }});
83              }
84            };
85
86            0x4: decode SPECIAL_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 SPECIAL_LO {
103              format SetInstructions{
104                0x2: slt({{ }});
105                0x3: sltu({{ }});
106              }
107            };
108
109            0x6: decode SPECIAL_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      0x0: decode RS {
189        //Table A-11 MIPS32 COP0 Encoding of rs Field
190      }
191
192      0x1: decode RS {
193        //Table A-13 MIPS32 COP1 Encoding of rs Field
194      }
195
196      0x2: decode RS {
197        //Table A-19 MIPS32 COP2 Encoding of rs Field
198      }
199
200      0x3: decode FUNCTION_HI {
201        //Table A-20 MIPS64 COP1X Encoding of Function Field 1
202      }
203
204      //MIPS obsolete instructions
205      0x4: beql({{ }});
206      0x5: bnel({{ }});
207      0x6: blezl({{ }});
208      0x7: bgtzl({{ }});
209    };
210
211    0x3: decode OPCODE_LO default FailUnimpl::reserved(){
212        format FailUnimpl{
213            0x0: reserved_inst_exception({{ }})
214            0x1: reserved_inst_exception({{ }})
215            0x2: reserved_inst_exception({{ }})
216            0x3: reserved_inst_exception({{ }})
217            0x5: reserved_inst_exception({{ }})
218            0x6: reserved_inst_exception({{ }})
219        };
220
221        4: decode SPECIAL2 {
222            0x0:;
223            0x1:;
224            0x2:;
225            0x3:;
226            0x4:;
227            0x5:;
228            0x6:;
229        }
230
231        7: decode SPECIAL3 {
232            0x0:;
233            0x1:;
234            0x2:;
235            0x3:;
236            0x4:;
237            0x5:;
238            0x6:;
239        }
240    };
241
242    0x4: decode OPCODE_LO default FailUnimpl::reserved(){
243        format LoadMemory{
244            0x0: lb({{ }});
245            0x1: lh({{ }});
246            0x2: lwl({{ }});
247            0x3: lw({{ }});
248            0x4: lbu({{ }});
249            0x5: lhu({{ }});
250            0x6: lhu({{ }});
251        };
252
253        0x7: FailUnimpl::reserved_inst_exception({{ }});
254    };
255
256    0x5: decode OPCODE_LO default FailUnimpl::reserved(){
257        format StoreMemory{
258            0x0: sb({{ }});
259            0x1: sh({{ }});
260            0x2: swl({{ }});
261            0x3: sw({{ }});
262            0x6: swr({{ }});
263        };
264
265        format FailUnimpl{
266            0x4: reserved_inst_exception({{ }});
267            0x5: reserved_inst_exception({{ }});
268            0x2: cache({{ }});
269        };
270
271    };
272
273    0x6: decode OPCODE_LO default FailUnimpl::reserved(){
274        format LoadMemory{
275            0x0: ll({{ }});
276            0x1: lwc1({{ }});
277            0x5: ldc1({{ }});
278        };
279
280        format FailUnimpl{
281            0x2: lwc2({{ }});
282            0x3: pref({{ }});
283            0x4: reserved_inst_exception({{ }});
284            0x6: ldc2({{ }});
285            0x7: reserved_inst_exception({{ }});
286        };
287
288    };
289
290    0x7: decode OPCODE_LO default FailUnimpl::reserved(){
291        format StoreMemory{
292            0x0: sc({{ }});
293            0x1: swc1({{ }});
294            0x5: sdc1({{ }});
295        };
296
297        format FailUnimpl{
298            0x2: swc2({{ }});
299            0x3: reserved_inst_exception({{ }});
300            0x4: reserved_inst_exception({{ }});
301            0x6: sdc2({{ }});
302            0x7: reserved_inst_exception({{ }});
303        };
304
305    };
306
307}
308
309