2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 //#define MIPS_DEBUG_DISAS
34 //#define MIPS_DEBUG_SIGN_EXTENSIONS
35 //#define MIPS_SINGLE_STEP
37 #ifdef USE_DIRECT_JUMP
40 #define TBPARAM(x) (long)(x)
44 #define DEF(s, n, copy_size) INDEX_op_ ## s,
50 static uint16_t *gen_opc_ptr
;
51 static uint32_t *gen_opparam_ptr
;
55 /* MIPS major opcodes */
56 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
59 /* indirect opcode tables */
60 OPC_SPECIAL
= (0x00 << 26),
61 OPC_REGIMM
= (0x01 << 26),
62 OPC_CP0
= (0x10 << 26),
63 OPC_CP1
= (0x11 << 26),
64 OPC_CP2
= (0x12 << 26),
65 OPC_CP3
= (0x13 << 26),
66 OPC_SPECIAL2
= (0x1C << 26),
67 OPC_SPECIAL3
= (0x1F << 26),
68 /* arithmetic with immediate */
69 OPC_ADDI
= (0x08 << 26),
70 OPC_ADDIU
= (0x09 << 26),
71 OPC_SLTI
= (0x0A << 26),
72 OPC_SLTIU
= (0x0B << 26),
73 OPC_ANDI
= (0x0C << 26),
74 OPC_ORI
= (0x0D << 26),
75 OPC_XORI
= (0x0E << 26),
76 OPC_LUI
= (0x0F << 26),
77 OPC_DADDI
= (0x18 << 26),
78 OPC_DADDIU
= (0x19 << 26),
79 /* Jump and branches */
81 OPC_JAL
= (0x03 << 26),
82 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
83 OPC_BEQL
= (0x14 << 26),
84 OPC_BNE
= (0x05 << 26),
85 OPC_BNEL
= (0x15 << 26),
86 OPC_BLEZ
= (0x06 << 26),
87 OPC_BLEZL
= (0x16 << 26),
88 OPC_BGTZ
= (0x07 << 26),
89 OPC_BGTZL
= (0x17 << 26),
90 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
92 OPC_LDL
= (0x1A << 26),
93 OPC_LDR
= (0x1B << 26),
94 OPC_LB
= (0x20 << 26),
95 OPC_LH
= (0x21 << 26),
96 OPC_LWL
= (0x22 << 26),
97 OPC_LW
= (0x23 << 26),
98 OPC_LBU
= (0x24 << 26),
99 OPC_LHU
= (0x25 << 26),
100 OPC_LWR
= (0x26 << 26),
101 OPC_LWU
= (0x27 << 26),
102 OPC_SB
= (0x28 << 26),
103 OPC_SH
= (0x29 << 26),
104 OPC_SWL
= (0x2A << 26),
105 OPC_SW
= (0x2B << 26),
106 OPC_SDL
= (0x2C << 26),
107 OPC_SDR
= (0x2D << 26),
108 OPC_SWR
= (0x2E << 26),
109 OPC_LL
= (0x30 << 26),
110 OPC_LLD
= (0x34 << 26),
111 OPC_LD
= (0x37 << 26),
112 OPC_SC
= (0x38 << 26),
113 OPC_SCD
= (0x3C << 26),
114 OPC_SD
= (0x3F << 26),
115 /* Floating point load/store */
116 OPC_LWC1
= (0x31 << 26),
117 OPC_LWC2
= (0x32 << 26),
118 OPC_LDC1
= (0x35 << 26),
119 OPC_LDC2
= (0x36 << 26),
120 OPC_SWC1
= (0x39 << 26),
121 OPC_SWC2
= (0x3A << 26),
122 OPC_SDC1
= (0x3D << 26),
123 OPC_SDC2
= (0x3E << 26),
124 /* MDMX ASE specific */
125 OPC_MDMX
= (0x1E << 26),
126 /* Cache and prefetch */
127 OPC_CACHE
= (0x2F << 26),
128 OPC_PREF
= (0x33 << 26),
129 /* Reserved major opcode */
130 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
133 /* MIPS special opcodes */
134 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
138 OPC_SLL
= 0x00 | OPC_SPECIAL
,
139 /* NOP is SLL r0, r0, 0 */
140 /* SSNOP is SLL r0, r0, 1 */
141 /* EHB is SLL r0, r0, 3 */
142 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
143 OPC_SRA
= 0x03 | OPC_SPECIAL
,
144 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
145 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
146 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
147 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
148 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
149 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
150 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
151 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
152 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
153 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
154 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
155 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
156 /* Multiplication / division */
157 OPC_MULT
= 0x18 | OPC_SPECIAL
,
158 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
159 OPC_DIV
= 0x1A | OPC_SPECIAL
,
160 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
161 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
162 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
163 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
164 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
165 /* 2 registers arithmetic / logic */
166 OPC_ADD
= 0x20 | OPC_SPECIAL
,
167 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
168 OPC_SUB
= 0x22 | OPC_SPECIAL
,
169 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
170 OPC_AND
= 0x24 | OPC_SPECIAL
,
171 OPC_OR
= 0x25 | OPC_SPECIAL
,
172 OPC_XOR
= 0x26 | OPC_SPECIAL
,
173 OPC_NOR
= 0x27 | OPC_SPECIAL
,
174 OPC_SLT
= 0x2A | OPC_SPECIAL
,
175 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
176 OPC_DADD
= 0x2C | OPC_SPECIAL
,
177 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
178 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
179 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
181 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
182 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
184 OPC_TGE
= 0x30 | OPC_SPECIAL
,
185 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
186 OPC_TLT
= 0x32 | OPC_SPECIAL
,
187 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
188 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
189 OPC_TNE
= 0x36 | OPC_SPECIAL
,
190 /* HI / LO registers load & stores */
191 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
192 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
193 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
194 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
195 /* Conditional moves */
196 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
197 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
199 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
202 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
203 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
204 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
205 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
206 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
208 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
209 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
210 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
211 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
212 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
213 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
214 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
217 /* REGIMM (rt field) opcodes */
218 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
221 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
222 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
223 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
224 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
225 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
226 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
227 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
228 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
229 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
230 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
231 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
232 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
233 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
234 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
235 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
238 /* Special2 opcodes */
239 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
242 /* Multiply & xxx operations */
243 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
244 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
245 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
246 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
247 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
249 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
250 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
251 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
252 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
254 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
257 /* Special3 opcodes */
258 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
261 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
262 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
263 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
264 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
265 OPC_INS
= 0x04 | OPC_SPECIAL3
,
266 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
267 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
268 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
269 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
270 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
271 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
272 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
273 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
277 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
280 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
281 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
282 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
286 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
289 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
290 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
293 /* Coprocessor 0 (rs field) */
294 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
297 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
298 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
299 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
300 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
301 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
302 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
303 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
304 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
305 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
306 OPC_C0
= (0x10 << 21) | OPC_CP0
,
307 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
308 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
312 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
315 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
316 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
317 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
318 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
319 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
320 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
323 /* Coprocessor 0 (with rs == C0) */
324 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
327 OPC_TLBR
= 0x01 | OPC_C0
,
328 OPC_TLBWI
= 0x02 | OPC_C0
,
329 OPC_TLBWR
= 0x06 | OPC_C0
,
330 OPC_TLBP
= 0x08 | OPC_C0
,
331 OPC_RFE
= 0x10 | OPC_C0
,
332 OPC_ERET
= 0x18 | OPC_C0
,
333 OPC_DERET
= 0x1F | OPC_C0
,
334 OPC_WAIT
= 0x20 | OPC_C0
,
337 /* Coprocessor 1 (rs field) */
338 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
341 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
342 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
343 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
344 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
345 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
346 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
347 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
348 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
349 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
350 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
351 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
352 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
353 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
354 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
355 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
356 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
357 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
358 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
361 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
362 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
365 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
366 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
367 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
368 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
372 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
373 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
377 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
378 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
381 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
384 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
385 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
386 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
387 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
388 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
389 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
390 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
391 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
392 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
395 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
398 OPC_LWXC1
= 0x00 | OPC_CP3
,
399 OPC_LDXC1
= 0x01 | OPC_CP3
,
400 OPC_LUXC1
= 0x05 | OPC_CP3
,
401 OPC_SWXC1
= 0x08 | OPC_CP3
,
402 OPC_SDXC1
= 0x09 | OPC_CP3
,
403 OPC_SUXC1
= 0x0D | OPC_CP3
,
404 OPC_PREFX
= 0x0F | OPC_CP3
,
405 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
406 OPC_MADD_S
= 0x20 | OPC_CP3
,
407 OPC_MADD_D
= 0x21 | OPC_CP3
,
408 OPC_MADD_PS
= 0x26 | OPC_CP3
,
409 OPC_MSUB_S
= 0x28 | OPC_CP3
,
410 OPC_MSUB_D
= 0x29 | OPC_CP3
,
411 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
412 OPC_NMADD_S
= 0x30 | OPC_CP3
,
413 OPC_NMADD_D
= 0x31 | OPC_CP3
,
414 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
415 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
416 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
417 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
421 const unsigned char *regnames
[] =
422 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
423 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
424 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
425 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
427 /* Warning: no function for r0 register (hard wired to zero) */
428 #define GEN32(func, NAME) \
429 static GenOpFunc *NAME ## _table [32] = { \
430 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
431 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
432 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
433 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
434 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
435 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
436 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
437 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
439 static inline void func(int n) \
441 NAME ## _table[n](); \
444 /* General purpose registers moves */
445 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
446 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
447 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
449 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
450 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
452 /* Moves to/from shadow registers */
453 GEN32(gen_op_load_srsgpr_T0
, gen_op_load_srsgpr_T0_gpr
);
454 GEN32(gen_op_store_T0_srsgpr
, gen_op_store_T0_srsgpr_gpr
);
456 static const char *fregnames
[] =
457 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
458 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
459 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
460 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
462 #define FGEN32(func, NAME) \
463 static GenOpFunc *NAME ## _table [32] = { \
464 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
465 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
466 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
467 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
468 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
469 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
470 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
471 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
473 static inline void func(int n) \
475 NAME ## _table[n](); \
478 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
479 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
481 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
482 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
484 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
485 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
487 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
488 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
490 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
491 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
493 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
494 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
496 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
497 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
499 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
500 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
502 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
503 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
505 #define FOP_CONDS(type, fmt) \
506 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
507 gen_op_cmp ## type ## _ ## fmt ## _f, \
508 gen_op_cmp ## type ## _ ## fmt ## _un, \
509 gen_op_cmp ## type ## _ ## fmt ## _eq, \
510 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
511 gen_op_cmp ## type ## _ ## fmt ## _olt, \
512 gen_op_cmp ## type ## _ ## fmt ## _ult, \
513 gen_op_cmp ## type ## _ ## fmt ## _ole, \
514 gen_op_cmp ## type ## _ ## fmt ## _ule, \
515 gen_op_cmp ## type ## _ ## fmt ## _sf, \
516 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
517 gen_op_cmp ## type ## _ ## fmt ## _seq, \
518 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
519 gen_op_cmp ## type ## _ ## fmt ## _lt, \
520 gen_op_cmp ## type ## _ ## fmt ## _nge, \
521 gen_op_cmp ## type ## _ ## fmt ## _le, \
522 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
524 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
526 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
536 typedef struct DisasContext
{
537 struct TranslationBlock
*tb
;
538 target_ulong pc
, saved_pc
;
541 /* Routine used to access memory */
543 uint32_t hflags
, saved_hflags
;
545 target_ulong btarget
;
549 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
550 * exception condition
552 BS_STOP
= 1, /* We want to stop translation for any reason */
553 BS_BRANCH
= 2, /* We reached a branch condition */
554 BS_EXCP
= 3, /* We reached an exception condition */
557 #ifdef MIPS_DEBUG_DISAS
558 #define MIPS_DEBUG(fmt, args...) \
560 if (loglevel & CPU_LOG_TB_IN_ASM) { \
561 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
562 ctx->pc, ctx->opcode , ##args); \
566 #define MIPS_DEBUG(fmt, args...) do { } while(0)
569 #define MIPS_INVAL(op) \
571 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
572 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
575 #define GEN_LOAD_REG_TN(Tn, Rn) \
578 glue(gen_op_reset_, Tn)(); \
580 glue(gen_op_load_gpr_, Tn)(Rn); \
584 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
587 glue(gen_op_reset_, Tn)(); \
589 glue(gen_op_load_srsgpr_, Tn)(Rn); \
594 #define GEN_LOAD_IMM_TN(Tn, Imm) \
597 glue(gen_op_reset_, Tn)(); \
598 } else if ((int32_t)Imm == Imm) { \
599 glue(gen_op_set_, Tn)(Imm); \
601 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
605 #define GEN_LOAD_IMM_TN(Tn, Imm) \
608 glue(gen_op_reset_, Tn)(); \
610 glue(gen_op_set_, Tn)(Imm); \
615 #define GEN_STORE_TN_REG(Rn, Tn) \
618 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
622 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
625 glue(glue(gen_op_store_, Tn),_srsgpr)(Rn); \
629 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
631 glue(gen_op_load_fpr_, FTn)(Fn); \
634 #define GEN_STORE_FTN_FREG(Fn, FTn) \
636 glue(gen_op_store_fpr_, FTn)(Fn); \
639 static inline void gen_save_pc(target_ulong pc
)
642 if (pc
== (int32_t)pc
) {
645 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
652 static inline void gen_save_btarget(target_ulong btarget
)
655 if (btarget
== (int32_t)btarget
) {
656 gen_op_save_btarget(btarget
);
658 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
661 gen_op_save_btarget(btarget
);
665 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
667 #if defined MIPS_DEBUG_DISAS
668 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
669 fprintf(logfile
, "hflags %08x saved %08x\n",
670 ctx
->hflags
, ctx
->saved_hflags
);
673 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
674 gen_save_pc(ctx
->pc
);
675 ctx
->saved_pc
= ctx
->pc
;
677 if (ctx
->hflags
!= ctx
->saved_hflags
) {
678 gen_op_save_state(ctx
->hflags
);
679 ctx
->saved_hflags
= ctx
->hflags
;
680 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
682 gen_op_save_breg_target();
688 /* bcond was already saved by the BL insn */
691 gen_save_btarget(ctx
->btarget
);
697 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
699 ctx
->saved_hflags
= ctx
->hflags
;
700 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
702 gen_op_restore_breg_target();
705 ctx
->btarget
= env
->btarget
;
709 ctx
->btarget
= env
->btarget
;
710 gen_op_restore_bcond();
715 static inline void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
717 #if defined MIPS_DEBUG_DISAS
718 if (loglevel
& CPU_LOG_TB_IN_ASM
)
719 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
721 save_cpu_state(ctx
, 1);
723 gen_op_raise_exception(excp
);
725 gen_op_raise_exception_err(excp
, err
);
726 ctx
->bstate
= BS_EXCP
;
729 static inline void generate_exception (DisasContext
*ctx
, int excp
)
731 generate_exception_err (ctx
, excp
, 0);
734 static inline void check_cp1_enabled(DisasContext
*ctx
)
736 if (!(ctx
->hflags
& MIPS_HFLAG_FPU
))
737 generate_exception_err(ctx
, EXCP_CpU
, 1);
740 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
742 if (!(ctx
->hflags
& MIPS_HFLAG_F64
))
743 generate_exception(ctx
, EXCP_RI
);
747 * Verify if floating point register is valid; an operation is not defined
748 * if bit 0 of any register specification is set and the FR bit in the
749 * Status register equals zero, since the register numbers specify an
750 * even-odd pair of adjacent coprocessor general registers. When the FR bit
751 * in the Status register equals one, both even and odd register numbers
752 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
754 * Multiple 64 bit wide registers can be checked by calling
755 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
757 void check_cp1_registers(DisasContext
*ctx
, int regs
)
759 if (!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1))
760 generate_exception(ctx
, EXCP_RI
);
763 /* This code generates a "reserved instruction" exception if the
764 CPU does not support the instruction set corresponding to flags. */
765 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
767 if (unlikely(!(env
->insn_flags
& flags
)))
768 generate_exception(ctx
, EXCP_RI
);
771 /* This code generates a "reserved instruction" exception if the
772 CPU is not MIPS MT capable. */
773 static inline void check_mips_mt(CPUState
*env
, DisasContext
*ctx
)
775 if (!(env
->CP0_Config3
& (1 << CP0C3_MT
)))
776 generate_exception(ctx
, EXCP_RI
);
779 /* This code generates a "reserved instruction" exception if 64-bit
780 instructions are not enabled. */
781 static inline void check_mips_64(DisasContext
*ctx
)
783 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
784 generate_exception(ctx
, EXCP_RI
);
787 #if defined(CONFIG_USER_ONLY)
788 #define op_ldst(name) gen_op_##name##_raw()
789 #define OP_LD_TABLE(width)
790 #define OP_ST_TABLE(width)
792 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
793 #define OP_LD_TABLE(width) \
794 static GenOpFunc *gen_op_l##width[] = { \
795 &gen_op_l##width##_user, \
796 &gen_op_l##width##_kernel, \
798 #define OP_ST_TABLE(width) \
799 static GenOpFunc *gen_op_s##width[] = { \
800 &gen_op_s##width##_user, \
801 &gen_op_s##width##_kernel, \
838 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
839 int base
, int16_t offset
)
841 const char *opn
= "ldst";
844 GEN_LOAD_IMM_TN(T0
, offset
);
845 } else if (offset
== 0) {
846 gen_op_load_gpr_T0(base
);
848 gen_op_load_gpr_T0(base
);
849 gen_op_set_T1(offset
);
852 /* Don't do NOP if destination is zero: we must perform the actual
858 GEN_STORE_TN_REG(rt
, T0
);
863 GEN_STORE_TN_REG(rt
, T0
);
868 GEN_STORE_TN_REG(rt
, T0
);
872 GEN_LOAD_REG_TN(T1
, rt
);
877 save_cpu_state(ctx
, 1);
878 GEN_LOAD_REG_TN(T1
, rt
);
880 GEN_STORE_TN_REG(rt
, T0
);
884 GEN_LOAD_REG_TN(T1
, rt
);
886 GEN_STORE_TN_REG(rt
, T0
);
890 GEN_LOAD_REG_TN(T1
, rt
);
895 GEN_LOAD_REG_TN(T1
, rt
);
897 GEN_STORE_TN_REG(rt
, T0
);
901 GEN_LOAD_REG_TN(T1
, rt
);
908 GEN_STORE_TN_REG(rt
, T0
);
912 GEN_LOAD_REG_TN(T1
, rt
);
918 GEN_STORE_TN_REG(rt
, T0
);
922 GEN_LOAD_REG_TN(T1
, rt
);
928 GEN_STORE_TN_REG(rt
, T0
);
933 GEN_STORE_TN_REG(rt
, T0
);
937 GEN_LOAD_REG_TN(T1
, rt
);
943 GEN_STORE_TN_REG(rt
, T0
);
947 GEN_LOAD_REG_TN(T1
, rt
);
949 GEN_STORE_TN_REG(rt
, T0
);
953 GEN_LOAD_REG_TN(T1
, rt
);
958 GEN_LOAD_REG_TN(T1
, rt
);
960 GEN_STORE_TN_REG(rt
, T0
);
964 GEN_LOAD_REG_TN(T1
, rt
);
970 GEN_STORE_TN_REG(rt
, T0
);
974 save_cpu_state(ctx
, 1);
975 GEN_LOAD_REG_TN(T1
, rt
);
977 GEN_STORE_TN_REG(rt
, T0
);
982 generate_exception(ctx
, EXCP_RI
);
985 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
989 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
990 int base
, int16_t offset
)
992 const char *opn
= "flt_ldst";
995 GEN_LOAD_IMM_TN(T0
, offset
);
996 } else if (offset
== 0) {
997 gen_op_load_gpr_T0(base
);
999 gen_op_load_gpr_T0(base
);
1000 gen_op_set_T1(offset
);
1003 /* Don't do NOP if destination is zero: we must perform the actual
1008 GEN_STORE_FTN_FREG(ft
, WT0
);
1012 GEN_LOAD_FREG_FTN(WT0
, ft
);
1018 GEN_STORE_FTN_FREG(ft
, DT0
);
1022 GEN_LOAD_FREG_FTN(DT0
, ft
);
1028 generate_exception(ctx
, EXCP_RI
);
1031 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1034 /* Arithmetic with immediate operand */
1035 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1036 int rt
, int rs
, int16_t imm
)
1039 const char *opn
= "imm arith";
1041 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1042 /* If no destination, treat it as a NOP.
1043 For addi, we must generate the overflow exception when needed. */
1047 uimm
= (uint16_t)imm
;
1051 #ifdef TARGET_MIPS64
1057 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1062 GEN_LOAD_REG_TN(T0
, rs
);
1063 GEN_LOAD_IMM_TN(T1
, uimm
);
1066 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1071 #ifdef TARGET_MIPS64
1080 GEN_LOAD_REG_TN(T0
, rs
);
1081 GEN_LOAD_IMM_TN(T1
, uimm
);
1086 save_cpu_state(ctx
, 1);
1094 #ifdef TARGET_MIPS64
1096 save_cpu_state(ctx
, 1);
1137 switch ((ctx
->opcode
>> 21) & 0x1f) {
1143 /* rotr is decoded as srl on non-R2 CPUs */
1144 if (env
->insn_flags
& ISA_MIPS32R2
) {
1153 MIPS_INVAL("invalid srl flag");
1154 generate_exception(ctx
, EXCP_RI
);
1158 #ifdef TARGET_MIPS64
1168 switch ((ctx
->opcode
>> 21) & 0x1f) {
1174 /* drotr is decoded as dsrl on non-R2 CPUs */
1175 if (env
->insn_flags
& ISA_MIPS32R2
) {
1184 MIPS_INVAL("invalid dsrl flag");
1185 generate_exception(ctx
, EXCP_RI
);
1198 switch ((ctx
->opcode
>> 21) & 0x1f) {
1204 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1205 if (env
->insn_flags
& ISA_MIPS32R2
) {
1214 MIPS_INVAL("invalid dsrl32 flag");
1215 generate_exception(ctx
, EXCP_RI
);
1222 generate_exception(ctx
, EXCP_RI
);
1225 GEN_STORE_TN_REG(rt
, T0
);
1226 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1230 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1231 int rd
, int rs
, int rt
)
1233 const char *opn
= "arith";
1235 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1236 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1237 /* If no destination, treat it as a NOP.
1238 For add & sub, we must generate the overflow exception when needed. */
1242 GEN_LOAD_REG_TN(T0
, rs
);
1243 GEN_LOAD_REG_TN(T1
, rt
);
1246 save_cpu_state(ctx
, 1);
1255 save_cpu_state(ctx
, 1);
1263 #ifdef TARGET_MIPS64
1265 save_cpu_state(ctx
, 1);
1274 save_cpu_state(ctx
, 1);
1328 switch ((ctx
->opcode
>> 6) & 0x1f) {
1334 /* rotrv is decoded as srlv on non-R2 CPUs */
1335 if (env
->insn_flags
& ISA_MIPS32R2
) {
1344 MIPS_INVAL("invalid srlv flag");
1345 generate_exception(ctx
, EXCP_RI
);
1349 #ifdef TARGET_MIPS64
1359 switch ((ctx
->opcode
>> 6) & 0x1f) {
1365 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1366 if (env
->insn_flags
& ISA_MIPS32R2
) {
1375 MIPS_INVAL("invalid dsrlv flag");
1376 generate_exception(ctx
, EXCP_RI
);
1383 generate_exception(ctx
, EXCP_RI
);
1386 GEN_STORE_TN_REG(rd
, T0
);
1388 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1391 /* Arithmetic on HI/LO registers */
1392 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1394 const char *opn
= "hilo";
1396 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1404 GEN_STORE_TN_REG(reg
, T0
);
1409 GEN_STORE_TN_REG(reg
, T0
);
1413 GEN_LOAD_REG_TN(T0
, reg
);
1418 GEN_LOAD_REG_TN(T0
, reg
);
1424 generate_exception(ctx
, EXCP_RI
);
1427 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1430 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1433 const char *opn
= "mul/div";
1435 GEN_LOAD_REG_TN(T0
, rs
);
1436 GEN_LOAD_REG_TN(T1
, rt
);
1454 #ifdef TARGET_MIPS64
1490 generate_exception(ctx
, EXCP_RI
);
1493 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1496 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1499 const char *opn
= "CLx";
1505 GEN_LOAD_REG_TN(T0
, rs
);
1515 #ifdef TARGET_MIPS64
1527 generate_exception(ctx
, EXCP_RI
);
1530 gen_op_store_T0_gpr(rd
);
1531 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1535 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1536 int rs
, int rt
, int16_t imm
)
1541 /* Load needed operands */
1549 /* Compare two registers */
1551 GEN_LOAD_REG_TN(T0
, rs
);
1552 GEN_LOAD_REG_TN(T1
, rt
);
1562 /* Compare register to immediate */
1563 if (rs
!= 0 || imm
!= 0) {
1564 GEN_LOAD_REG_TN(T0
, rs
);
1565 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1572 case OPC_TEQ
: /* rs == rs */
1573 case OPC_TEQI
: /* r0 == 0 */
1574 case OPC_TGE
: /* rs >= rs */
1575 case OPC_TGEI
: /* r0 >= 0 */
1576 case OPC_TGEU
: /* rs >= rs unsigned */
1577 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1581 case OPC_TLT
: /* rs < rs */
1582 case OPC_TLTI
: /* r0 < 0 */
1583 case OPC_TLTU
: /* rs < rs unsigned */
1584 case OPC_TLTIU
: /* r0 < 0 unsigned */
1585 case OPC_TNE
: /* rs != rs */
1586 case OPC_TNEI
: /* r0 != 0 */
1587 /* Never trap: treat as NOP. */
1591 generate_exception(ctx
, EXCP_RI
);
1622 generate_exception(ctx
, EXCP_RI
);
1626 save_cpu_state(ctx
, 1);
1628 ctx
->bstate
= BS_STOP
;
1631 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1633 TranslationBlock
*tb
;
1635 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1637 gen_op_goto_tb0(TBPARAM(tb
));
1639 gen_op_goto_tb1(TBPARAM(tb
));
1641 gen_op_set_T0((long)tb
+ n
);
1649 /* Branches (before delay slot) */
1650 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1651 int rs
, int rt
, int32_t offset
)
1653 target_ulong btarget
= -1;
1657 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1658 #ifdef MIPS_DEBUG_DISAS
1659 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1661 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1665 generate_exception(ctx
, EXCP_RI
);
1669 /* Load needed operands */
1675 /* Compare two registers */
1677 GEN_LOAD_REG_TN(T0
, rs
);
1678 GEN_LOAD_REG_TN(T1
, rt
);
1681 btarget
= ctx
->pc
+ 4 + offset
;
1695 /* Compare to zero */
1697 gen_op_load_gpr_T0(rs
);
1700 btarget
= ctx
->pc
+ 4 + offset
;
1704 /* Jump to immediate */
1705 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
1709 /* Jump to register */
1710 if (offset
!= 0 && offset
!= 16) {
1711 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1712 others are reserved. */
1713 MIPS_INVAL("jump hint");
1714 generate_exception(ctx
, EXCP_RI
);
1717 GEN_LOAD_REG_TN(T2
, rs
);
1720 MIPS_INVAL("branch/jump");
1721 generate_exception(ctx
, EXCP_RI
);
1725 /* No condition to be computed */
1727 case OPC_BEQ
: /* rx == rx */
1728 case OPC_BEQL
: /* rx == rx likely */
1729 case OPC_BGEZ
: /* 0 >= 0 */
1730 case OPC_BGEZL
: /* 0 >= 0 likely */
1731 case OPC_BLEZ
: /* 0 <= 0 */
1732 case OPC_BLEZL
: /* 0 <= 0 likely */
1734 ctx
->hflags
|= MIPS_HFLAG_B
;
1735 MIPS_DEBUG("balways");
1737 case OPC_BGEZAL
: /* 0 >= 0 */
1738 case OPC_BGEZALL
: /* 0 >= 0 likely */
1739 /* Always take and link */
1741 ctx
->hflags
|= MIPS_HFLAG_B
;
1742 MIPS_DEBUG("balways and link");
1744 case OPC_BNE
: /* rx != rx */
1745 case OPC_BGTZ
: /* 0 > 0 */
1746 case OPC_BLTZ
: /* 0 < 0 */
1748 MIPS_DEBUG("bnever (NOP)");
1750 case OPC_BLTZAL
: /* 0 < 0 */
1751 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1752 gen_op_store_T0_gpr(31);
1753 MIPS_DEBUG("bnever and link");
1755 case OPC_BLTZALL
: /* 0 < 0 likely */
1756 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1757 gen_op_store_T0_gpr(31);
1758 /* Skip the instruction in the delay slot */
1759 MIPS_DEBUG("bnever, link and skip");
1762 case OPC_BNEL
: /* rx != rx likely */
1763 case OPC_BGTZL
: /* 0 > 0 likely */
1764 case OPC_BLTZL
: /* 0 < 0 likely */
1765 /* Skip the instruction in the delay slot */
1766 MIPS_DEBUG("bnever and skip");
1770 ctx
->hflags
|= MIPS_HFLAG_B
;
1771 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1775 ctx
->hflags
|= MIPS_HFLAG_B
;
1776 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1779 ctx
->hflags
|= MIPS_HFLAG_BR
;
1780 MIPS_DEBUG("jr %s", regnames
[rs
]);
1784 ctx
->hflags
|= MIPS_HFLAG_BR
;
1785 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1788 MIPS_INVAL("branch/jump");
1789 generate_exception(ctx
, EXCP_RI
);
1796 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1797 regnames
[rs
], regnames
[rt
], btarget
);
1801 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1802 regnames
[rs
], regnames
[rt
], btarget
);
1806 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1807 regnames
[rs
], regnames
[rt
], btarget
);
1811 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1812 regnames
[rs
], regnames
[rt
], btarget
);
1816 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1820 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1824 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1830 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1834 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1838 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1842 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1846 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1850 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1854 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1859 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1861 ctx
->hflags
|= MIPS_HFLAG_BC
;
1867 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1869 ctx
->hflags
|= MIPS_HFLAG_BL
;
1871 gen_op_save_bcond();
1874 MIPS_INVAL("conditional branch/jump");
1875 generate_exception(ctx
, EXCP_RI
);
1879 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
1880 blink
, ctx
->hflags
, btarget
);
1882 ctx
->btarget
= btarget
;
1884 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1885 gen_op_store_T0_gpr(blink
);
1889 /* special3 bitfield operations */
1890 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
1891 int rs
, int lsb
, int msb
)
1893 GEN_LOAD_REG_TN(T1
, rs
);
1898 gen_op_ext(lsb
, msb
+ 1);
1903 gen_op_ext(lsb
, msb
+ 1 + 32);
1908 gen_op_ext(lsb
+ 32, msb
+ 1);
1911 gen_op_ext(lsb
, msb
+ 1);
1916 GEN_LOAD_REG_TN(T0
, rt
);
1917 gen_op_ins(lsb
, msb
- lsb
+ 1);
1922 GEN_LOAD_REG_TN(T0
, rt
);
1923 gen_op_ins(lsb
, msb
- lsb
+ 1 + 32);
1928 GEN_LOAD_REG_TN(T0
, rt
);
1929 gen_op_ins(lsb
+ 32, msb
- lsb
+ 1);
1934 GEN_LOAD_REG_TN(T0
, rt
);
1935 gen_op_ins(lsb
, msb
- lsb
+ 1);
1939 MIPS_INVAL("bitops");
1940 generate_exception(ctx
, EXCP_RI
);
1943 GEN_STORE_TN_REG(rt
, T0
);
1946 /* CP0 (MMU and control) */
1947 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
1949 const char *rn
= "invalid";
1952 check_insn(env
, ctx
, ISA_MIPS32
);
1958 gen_op_mfc0_index();
1962 check_mips_mt(env
, ctx
);
1963 gen_op_mfc0_mvpcontrol();
1967 check_mips_mt(env
, ctx
);
1968 gen_op_mfc0_mvpconf0();
1972 check_mips_mt(env
, ctx
);
1973 gen_op_mfc0_mvpconf1();
1983 gen_op_mfc0_random();
1987 check_mips_mt(env
, ctx
);
1988 gen_op_mfc0_vpecontrol();
1992 check_mips_mt(env
, ctx
);
1993 gen_op_mfc0_vpeconf0();
1997 check_mips_mt(env
, ctx
);
1998 gen_op_mfc0_vpeconf1();
2002 check_mips_mt(env
, ctx
);
2003 gen_op_mfc0_yqmask();
2007 check_mips_mt(env
, ctx
);
2008 gen_op_mfc0_vpeschedule();
2012 check_mips_mt(env
, ctx
);
2013 gen_op_mfc0_vpeschefback();
2014 rn
= "VPEScheFBack";
2017 check_mips_mt(env
, ctx
);
2018 gen_op_mfc0_vpeopt();
2028 gen_op_mfc0_entrylo0();
2032 check_mips_mt(env
, ctx
);
2033 gen_op_mfc0_tcstatus();
2037 check_mips_mt(env
, ctx
);
2038 gen_op_mfc0_tcbind();
2042 check_mips_mt(env
, ctx
);
2043 gen_op_mfc0_tcrestart();
2047 check_mips_mt(env
, ctx
);
2048 gen_op_mfc0_tchalt();
2052 check_mips_mt(env
, ctx
);
2053 gen_op_mfc0_tccontext();
2057 check_mips_mt(env
, ctx
);
2058 gen_op_mfc0_tcschedule();
2062 check_mips_mt(env
, ctx
);
2063 gen_op_mfc0_tcschefback();
2073 gen_op_mfc0_entrylo1();
2083 gen_op_mfc0_context();
2087 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2088 rn
= "ContextConfig";
2097 gen_op_mfc0_pagemask();
2101 check_insn(env
, ctx
, ISA_MIPS32R2
);
2102 gen_op_mfc0_pagegrain();
2112 gen_op_mfc0_wired();
2116 check_insn(env
, ctx
, ISA_MIPS32R2
);
2117 gen_op_mfc0_srsconf0();
2121 check_insn(env
, ctx
, ISA_MIPS32R2
);
2122 gen_op_mfc0_srsconf1();
2126 check_insn(env
, ctx
, ISA_MIPS32R2
);
2127 gen_op_mfc0_srsconf2();
2131 check_insn(env
, ctx
, ISA_MIPS32R2
);
2132 gen_op_mfc0_srsconf3();
2136 check_insn(env
, ctx
, ISA_MIPS32R2
);
2137 gen_op_mfc0_srsconf4();
2147 check_insn(env
, ctx
, ISA_MIPS32R2
);
2148 gen_op_mfc0_hwrena();
2158 gen_op_mfc0_badvaddr();
2168 gen_op_mfc0_count();
2171 /* 6,7 are implementation dependent */
2179 gen_op_mfc0_entryhi();
2189 gen_op_mfc0_compare();
2192 /* 6,7 are implementation dependent */
2200 gen_op_mfc0_status();
2204 check_insn(env
, ctx
, ISA_MIPS32R2
);
2205 gen_op_mfc0_intctl();
2209 check_insn(env
, ctx
, ISA_MIPS32R2
);
2210 gen_op_mfc0_srsctl();
2214 check_insn(env
, ctx
, ISA_MIPS32R2
);
2215 gen_op_mfc0_srsmap();
2225 gen_op_mfc0_cause();
2249 check_insn(env
, ctx
, ISA_MIPS32R2
);
2250 gen_op_mfc0_ebase();
2260 gen_op_mfc0_config0();
2264 gen_op_mfc0_config1();
2268 gen_op_mfc0_config2();
2272 gen_op_mfc0_config3();
2275 /* 4,5 are reserved */
2276 /* 6,7 are implementation dependent */
2278 gen_op_mfc0_config6();
2282 gen_op_mfc0_config7();
2292 gen_op_mfc0_lladdr();
2302 gen_op_mfc0_watchlo(sel
);
2312 gen_op_mfc0_watchhi(sel
);
2322 #ifdef TARGET_MIPS64
2323 check_insn(env
, ctx
, ISA_MIPS3
);
2324 gen_op_mfc0_xcontext();
2333 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2336 gen_op_mfc0_framemask();
2345 rn
= "'Diagnostic"; /* implementation dependent */
2350 gen_op_mfc0_debug(); /* EJTAG support */
2354 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2355 rn
= "TraceControl";
2358 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2359 rn
= "TraceControl2";
2362 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2363 rn
= "UserTraceData";
2366 // gen_op_mfc0_debug(); /* PDtrace support */
2376 gen_op_mfc0_depc(); /* EJTAG support */
2386 gen_op_mfc0_performance0();
2387 rn
= "Performance0";
2390 // gen_op_mfc0_performance1();
2391 rn
= "Performance1";
2394 // gen_op_mfc0_performance2();
2395 rn
= "Performance2";
2398 // gen_op_mfc0_performance3();
2399 rn
= "Performance3";
2402 // gen_op_mfc0_performance4();
2403 rn
= "Performance4";
2406 // gen_op_mfc0_performance5();
2407 rn
= "Performance5";
2410 // gen_op_mfc0_performance6();
2411 rn
= "Performance6";
2414 // gen_op_mfc0_performance7();
2415 rn
= "Performance7";
2440 gen_op_mfc0_taglo();
2447 gen_op_mfc0_datalo();
2460 gen_op_mfc0_taghi();
2467 gen_op_mfc0_datahi();
2477 gen_op_mfc0_errorepc();
2487 gen_op_mfc0_desave(); /* EJTAG support */
2497 #if defined MIPS_DEBUG_DISAS
2498 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2499 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2506 #if defined MIPS_DEBUG_DISAS
2507 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2508 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2512 generate_exception(ctx
, EXCP_RI
);
2515 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2517 const char *rn
= "invalid";
2520 check_insn(env
, ctx
, ISA_MIPS32
);
2526 gen_op_mtc0_index();
2530 check_mips_mt(env
, ctx
);
2531 gen_op_mtc0_mvpcontrol();
2535 check_mips_mt(env
, ctx
);
2540 check_mips_mt(env
, ctx
);
2555 check_mips_mt(env
, ctx
);
2556 gen_op_mtc0_vpecontrol();
2560 check_mips_mt(env
, ctx
);
2561 gen_op_mtc0_vpeconf0();
2565 check_mips_mt(env
, ctx
);
2566 gen_op_mtc0_vpeconf1();
2570 check_mips_mt(env
, ctx
);
2571 gen_op_mtc0_yqmask();
2575 check_mips_mt(env
, ctx
);
2576 gen_op_mtc0_vpeschedule();
2580 check_mips_mt(env
, ctx
);
2581 gen_op_mtc0_vpeschefback();
2582 rn
= "VPEScheFBack";
2585 check_mips_mt(env
, ctx
);
2586 gen_op_mtc0_vpeopt();
2596 gen_op_mtc0_entrylo0();
2600 check_mips_mt(env
, ctx
);
2601 gen_op_mtc0_tcstatus();
2605 check_mips_mt(env
, ctx
);
2606 gen_op_mtc0_tcbind();
2610 check_mips_mt(env
, ctx
);
2611 gen_op_mtc0_tcrestart();
2615 check_mips_mt(env
, ctx
);
2616 gen_op_mtc0_tchalt();
2620 check_mips_mt(env
, ctx
);
2621 gen_op_mtc0_tccontext();
2625 check_mips_mt(env
, ctx
);
2626 gen_op_mtc0_tcschedule();
2630 check_mips_mt(env
, ctx
);
2631 gen_op_mtc0_tcschefback();
2641 gen_op_mtc0_entrylo1();
2651 gen_op_mtc0_context();
2655 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2656 rn
= "ContextConfig";
2665 gen_op_mtc0_pagemask();
2669 check_insn(env
, ctx
, ISA_MIPS32R2
);
2670 gen_op_mtc0_pagegrain();
2680 gen_op_mtc0_wired();
2684 check_insn(env
, ctx
, ISA_MIPS32R2
);
2685 gen_op_mtc0_srsconf0();
2689 check_insn(env
, ctx
, ISA_MIPS32R2
);
2690 gen_op_mtc0_srsconf1();
2694 check_insn(env
, ctx
, ISA_MIPS32R2
);
2695 gen_op_mtc0_srsconf2();
2699 check_insn(env
, ctx
, ISA_MIPS32R2
);
2700 gen_op_mtc0_srsconf3();
2704 check_insn(env
, ctx
, ISA_MIPS32R2
);
2705 gen_op_mtc0_srsconf4();
2715 check_insn(env
, ctx
, ISA_MIPS32R2
);
2716 gen_op_mtc0_hwrena();
2730 gen_op_mtc0_count();
2733 /* 6,7 are implementation dependent */
2737 /* Stop translation as we may have switched the execution mode */
2738 ctx
->bstate
= BS_STOP
;
2743 gen_op_mtc0_entryhi();
2753 gen_op_mtc0_compare();
2756 /* 6,7 are implementation dependent */
2760 /* Stop translation as we may have switched the execution mode */
2761 ctx
->bstate
= BS_STOP
;
2766 gen_op_mtc0_status();
2767 /* BS_STOP isn't good enough here, hflags may have changed. */
2768 gen_save_pc(ctx
->pc
+ 4);
2769 ctx
->bstate
= BS_EXCP
;
2773 check_insn(env
, ctx
, ISA_MIPS32R2
);
2774 gen_op_mtc0_intctl();
2775 /* Stop translation as we may have switched the execution mode */
2776 ctx
->bstate
= BS_STOP
;
2780 check_insn(env
, ctx
, ISA_MIPS32R2
);
2781 gen_op_mtc0_srsctl();
2782 /* Stop translation as we may have switched the execution mode */
2783 ctx
->bstate
= BS_STOP
;
2787 check_insn(env
, ctx
, ISA_MIPS32R2
);
2788 gen_op_mtc0_srsmap();
2789 /* Stop translation as we may have switched the execution mode */
2790 ctx
->bstate
= BS_STOP
;
2800 gen_op_mtc0_cause();
2806 /* Stop translation as we may have switched the execution mode */
2807 ctx
->bstate
= BS_STOP
;
2826 check_insn(env
, ctx
, ISA_MIPS32R2
);
2827 gen_op_mtc0_ebase();
2837 gen_op_mtc0_config0();
2839 /* Stop translation as we may have switched the execution mode */
2840 ctx
->bstate
= BS_STOP
;
2843 /* ignored, read only */
2847 gen_op_mtc0_config2();
2849 /* Stop translation as we may have switched the execution mode */
2850 ctx
->bstate
= BS_STOP
;
2853 /* ignored, read only */
2856 /* 4,5 are reserved */
2857 /* 6,7 are implementation dependent */
2867 rn
= "Invalid config selector";
2884 gen_op_mtc0_watchlo(sel
);
2894 gen_op_mtc0_watchhi(sel
);
2904 #ifdef TARGET_MIPS64
2905 check_insn(env
, ctx
, ISA_MIPS3
);
2906 gen_op_mtc0_xcontext();
2915 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2918 gen_op_mtc0_framemask();
2927 rn
= "Diagnostic"; /* implementation dependent */
2932 gen_op_mtc0_debug(); /* EJTAG support */
2933 /* BS_STOP isn't good enough here, hflags may have changed. */
2934 gen_save_pc(ctx
->pc
+ 4);
2935 ctx
->bstate
= BS_EXCP
;
2939 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2940 rn
= "TraceControl";
2941 /* Stop translation as we may have switched the execution mode */
2942 ctx
->bstate
= BS_STOP
;
2945 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2946 rn
= "TraceControl2";
2947 /* Stop translation as we may have switched the execution mode */
2948 ctx
->bstate
= BS_STOP
;
2951 /* Stop translation as we may have switched the execution mode */
2952 ctx
->bstate
= BS_STOP
;
2953 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2954 rn
= "UserTraceData";
2955 /* Stop translation as we may have switched the execution mode */
2956 ctx
->bstate
= BS_STOP
;
2959 // gen_op_mtc0_debug(); /* PDtrace support */
2960 /* Stop translation as we may have switched the execution mode */
2961 ctx
->bstate
= BS_STOP
;
2971 gen_op_mtc0_depc(); /* EJTAG support */
2981 gen_op_mtc0_performance0();
2982 rn
= "Performance0";
2985 // gen_op_mtc0_performance1();
2986 rn
= "Performance1";
2989 // gen_op_mtc0_performance2();
2990 rn
= "Performance2";
2993 // gen_op_mtc0_performance3();
2994 rn
= "Performance3";
2997 // gen_op_mtc0_performance4();
2998 rn
= "Performance4";
3001 // gen_op_mtc0_performance5();
3002 rn
= "Performance5";
3005 // gen_op_mtc0_performance6();
3006 rn
= "Performance6";
3009 // gen_op_mtc0_performance7();
3010 rn
= "Performance7";
3036 gen_op_mtc0_taglo();
3043 gen_op_mtc0_datalo();
3056 gen_op_mtc0_taghi();
3063 gen_op_mtc0_datahi();
3074 gen_op_mtc0_errorepc();
3084 gen_op_mtc0_desave(); /* EJTAG support */
3090 /* Stop translation as we may have switched the execution mode */
3091 ctx
->bstate
= BS_STOP
;
3096 #if defined MIPS_DEBUG_DISAS
3097 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3098 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3105 #if defined MIPS_DEBUG_DISAS
3106 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3107 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3111 generate_exception(ctx
, EXCP_RI
);
3114 #ifdef TARGET_MIPS64
3115 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3117 const char *rn
= "invalid";
3120 check_insn(env
, ctx
, ISA_MIPS64
);
3126 gen_op_mfc0_index();
3130 check_mips_mt(env
, ctx
);
3131 gen_op_mfc0_mvpcontrol();
3135 check_mips_mt(env
, ctx
);
3136 gen_op_mfc0_mvpconf0();
3140 check_mips_mt(env
, ctx
);
3141 gen_op_mfc0_mvpconf1();
3151 gen_op_mfc0_random();
3155 check_mips_mt(env
, ctx
);
3156 gen_op_mfc0_vpecontrol();
3160 check_mips_mt(env
, ctx
);
3161 gen_op_mfc0_vpeconf0();
3165 check_mips_mt(env
, ctx
);
3166 gen_op_mfc0_vpeconf1();
3170 check_mips_mt(env
, ctx
);
3171 gen_op_dmfc0_yqmask();
3175 check_mips_mt(env
, ctx
);
3176 gen_op_dmfc0_vpeschedule();
3180 check_mips_mt(env
, ctx
);
3181 gen_op_dmfc0_vpeschefback();
3182 rn
= "VPEScheFBack";
3185 check_mips_mt(env
, ctx
);
3186 gen_op_mfc0_vpeopt();
3196 gen_op_dmfc0_entrylo0();
3200 check_mips_mt(env
, ctx
);
3201 gen_op_mfc0_tcstatus();
3205 check_mips_mt(env
, ctx
);
3206 gen_op_mfc0_tcbind();
3210 check_mips_mt(env
, ctx
);
3211 gen_op_dmfc0_tcrestart();
3215 check_mips_mt(env
, ctx
);
3216 gen_op_dmfc0_tchalt();
3220 check_mips_mt(env
, ctx
);
3221 gen_op_dmfc0_tccontext();
3225 check_mips_mt(env
, ctx
);
3226 gen_op_dmfc0_tcschedule();
3230 check_mips_mt(env
, ctx
);
3231 gen_op_dmfc0_tcschefback();
3241 gen_op_dmfc0_entrylo1();
3251 gen_op_dmfc0_context();
3255 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3256 rn
= "ContextConfig";
3265 gen_op_mfc0_pagemask();
3269 check_insn(env
, ctx
, ISA_MIPS32R2
);
3270 gen_op_mfc0_pagegrain();
3280 gen_op_mfc0_wired();
3284 check_insn(env
, ctx
, ISA_MIPS32R2
);
3285 gen_op_mfc0_srsconf0();
3289 check_insn(env
, ctx
, ISA_MIPS32R2
);
3290 gen_op_mfc0_srsconf1();
3294 check_insn(env
, ctx
, ISA_MIPS32R2
);
3295 gen_op_mfc0_srsconf2();
3299 check_insn(env
, ctx
, ISA_MIPS32R2
);
3300 gen_op_mfc0_srsconf3();
3304 check_insn(env
, ctx
, ISA_MIPS32R2
);
3305 gen_op_mfc0_srsconf4();
3315 check_insn(env
, ctx
, ISA_MIPS32R2
);
3316 gen_op_mfc0_hwrena();
3326 gen_op_dmfc0_badvaddr();
3336 gen_op_mfc0_count();
3339 /* 6,7 are implementation dependent */
3347 gen_op_dmfc0_entryhi();
3357 gen_op_mfc0_compare();
3360 /* 6,7 are implementation dependent */
3368 gen_op_mfc0_status();
3372 check_insn(env
, ctx
, ISA_MIPS32R2
);
3373 gen_op_mfc0_intctl();
3377 check_insn(env
, ctx
, ISA_MIPS32R2
);
3378 gen_op_mfc0_srsctl();
3382 check_insn(env
, ctx
, ISA_MIPS32R2
);
3383 gen_op_mfc0_srsmap();
3393 gen_op_mfc0_cause();
3417 check_insn(env
, ctx
, ISA_MIPS32R2
);
3418 gen_op_mfc0_ebase();
3428 gen_op_mfc0_config0();
3432 gen_op_mfc0_config1();
3436 gen_op_mfc0_config2();
3440 gen_op_mfc0_config3();
3443 /* 6,7 are implementation dependent */
3451 gen_op_dmfc0_lladdr();
3461 gen_op_dmfc0_watchlo(sel
);
3471 gen_op_mfc0_watchhi(sel
);
3481 check_insn(env
, ctx
, ISA_MIPS3
);
3482 gen_op_dmfc0_xcontext();
3490 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3493 gen_op_mfc0_framemask();
3502 rn
= "'Diagnostic"; /* implementation dependent */
3507 gen_op_mfc0_debug(); /* EJTAG support */
3511 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3512 rn
= "TraceControl";
3515 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3516 rn
= "TraceControl2";
3519 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3520 rn
= "UserTraceData";
3523 // gen_op_dmfc0_debug(); /* PDtrace support */
3533 gen_op_dmfc0_depc(); /* EJTAG support */
3543 gen_op_mfc0_performance0();
3544 rn
= "Performance0";
3547 // gen_op_dmfc0_performance1();
3548 rn
= "Performance1";
3551 // gen_op_dmfc0_performance2();
3552 rn
= "Performance2";
3555 // gen_op_dmfc0_performance3();
3556 rn
= "Performance3";
3559 // gen_op_dmfc0_performance4();
3560 rn
= "Performance4";
3563 // gen_op_dmfc0_performance5();
3564 rn
= "Performance5";
3567 // gen_op_dmfc0_performance6();
3568 rn
= "Performance6";
3571 // gen_op_dmfc0_performance7();
3572 rn
= "Performance7";
3597 gen_op_mfc0_taglo();
3604 gen_op_mfc0_datalo();
3617 gen_op_mfc0_taghi();
3624 gen_op_mfc0_datahi();
3634 gen_op_dmfc0_errorepc();
3644 gen_op_mfc0_desave(); /* EJTAG support */
3654 #if defined MIPS_DEBUG_DISAS
3655 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3656 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3663 #if defined MIPS_DEBUG_DISAS
3664 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3665 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3669 generate_exception(ctx
, EXCP_RI
);
3672 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3674 const char *rn
= "invalid";
3677 check_insn(env
, ctx
, ISA_MIPS64
);
3683 gen_op_mtc0_index();
3687 check_mips_mt(env
, ctx
);
3688 gen_op_mtc0_mvpcontrol();
3692 check_mips_mt(env
, ctx
);
3697 check_mips_mt(env
, ctx
);
3712 check_mips_mt(env
, ctx
);
3713 gen_op_mtc0_vpecontrol();
3717 check_mips_mt(env
, ctx
);
3718 gen_op_mtc0_vpeconf0();
3722 check_mips_mt(env
, ctx
);
3723 gen_op_mtc0_vpeconf1();
3727 check_mips_mt(env
, ctx
);
3728 gen_op_mtc0_yqmask();
3732 check_mips_mt(env
, ctx
);
3733 gen_op_mtc0_vpeschedule();
3737 check_mips_mt(env
, ctx
);
3738 gen_op_mtc0_vpeschefback();
3739 rn
= "VPEScheFBack";
3742 check_mips_mt(env
, ctx
);
3743 gen_op_mtc0_vpeopt();
3753 gen_op_mtc0_entrylo0();
3757 check_mips_mt(env
, ctx
);
3758 gen_op_mtc0_tcstatus();
3762 check_mips_mt(env
, ctx
);
3763 gen_op_mtc0_tcbind();
3767 check_mips_mt(env
, ctx
);
3768 gen_op_mtc0_tcrestart();
3772 check_mips_mt(env
, ctx
);
3773 gen_op_mtc0_tchalt();
3777 check_mips_mt(env
, ctx
);
3778 gen_op_mtc0_tccontext();
3782 check_mips_mt(env
, ctx
);
3783 gen_op_mtc0_tcschedule();
3787 check_mips_mt(env
, ctx
);
3788 gen_op_mtc0_tcschefback();
3798 gen_op_mtc0_entrylo1();
3808 gen_op_mtc0_context();
3812 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3813 rn
= "ContextConfig";
3822 gen_op_mtc0_pagemask();
3826 check_insn(env
, ctx
, ISA_MIPS32R2
);
3827 gen_op_mtc0_pagegrain();
3837 gen_op_mtc0_wired();
3841 check_insn(env
, ctx
, ISA_MIPS32R2
);
3842 gen_op_mtc0_srsconf0();
3846 check_insn(env
, ctx
, ISA_MIPS32R2
);
3847 gen_op_mtc0_srsconf1();
3851 check_insn(env
, ctx
, ISA_MIPS32R2
);
3852 gen_op_mtc0_srsconf2();
3856 check_insn(env
, ctx
, ISA_MIPS32R2
);
3857 gen_op_mtc0_srsconf3();
3861 check_insn(env
, ctx
, ISA_MIPS32R2
);
3862 gen_op_mtc0_srsconf4();
3872 check_insn(env
, ctx
, ISA_MIPS32R2
);
3873 gen_op_mtc0_hwrena();
3887 gen_op_mtc0_count();
3890 /* 6,7 are implementation dependent */
3894 /* Stop translation as we may have switched the execution mode */
3895 ctx
->bstate
= BS_STOP
;
3900 gen_op_mtc0_entryhi();
3910 gen_op_mtc0_compare();
3913 /* 6,7 are implementation dependent */
3917 /* Stop translation as we may have switched the execution mode */
3918 ctx
->bstate
= BS_STOP
;
3923 gen_op_mtc0_status();
3924 /* BS_STOP isn't good enough here, hflags may have changed. */
3925 gen_save_pc(ctx
->pc
+ 4);
3926 ctx
->bstate
= BS_EXCP
;
3930 check_insn(env
, ctx
, ISA_MIPS32R2
);
3931 gen_op_mtc0_intctl();
3932 /* Stop translation as we may have switched the execution mode */
3933 ctx
->bstate
= BS_STOP
;
3937 check_insn(env
, ctx
, ISA_MIPS32R2
);
3938 gen_op_mtc0_srsctl();
3939 /* Stop translation as we may have switched the execution mode */
3940 ctx
->bstate
= BS_STOP
;
3944 check_insn(env
, ctx
, ISA_MIPS32R2
);
3945 gen_op_mtc0_srsmap();
3946 /* Stop translation as we may have switched the execution mode */
3947 ctx
->bstate
= BS_STOP
;
3957 gen_op_mtc0_cause();
3963 /* Stop translation as we may have switched the execution mode */
3964 ctx
->bstate
= BS_STOP
;
3983 check_insn(env
, ctx
, ISA_MIPS32R2
);
3984 gen_op_mtc0_ebase();
3994 gen_op_mtc0_config0();
3996 /* Stop translation as we may have switched the execution mode */
3997 ctx
->bstate
= BS_STOP
;
4004 gen_op_mtc0_config2();
4006 /* Stop translation as we may have switched the execution mode */
4007 ctx
->bstate
= BS_STOP
;
4013 /* 6,7 are implementation dependent */
4015 rn
= "Invalid config selector";
4032 gen_op_mtc0_watchlo(sel
);
4042 gen_op_mtc0_watchhi(sel
);
4052 check_insn(env
, ctx
, ISA_MIPS3
);
4053 gen_op_mtc0_xcontext();
4061 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4064 gen_op_mtc0_framemask();
4073 rn
= "Diagnostic"; /* implementation dependent */
4078 gen_op_mtc0_debug(); /* EJTAG support */
4079 /* BS_STOP isn't good enough here, hflags may have changed. */
4080 gen_save_pc(ctx
->pc
+ 4);
4081 ctx
->bstate
= BS_EXCP
;
4085 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4086 /* Stop translation as we may have switched the execution mode */
4087 ctx
->bstate
= BS_STOP
;
4088 rn
= "TraceControl";
4091 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4092 /* Stop translation as we may have switched the execution mode */
4093 ctx
->bstate
= BS_STOP
;
4094 rn
= "TraceControl2";
4097 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4098 /* Stop translation as we may have switched the execution mode */
4099 ctx
->bstate
= BS_STOP
;
4100 rn
= "UserTraceData";
4103 // gen_op_mtc0_debug(); /* PDtrace support */
4104 /* Stop translation as we may have switched the execution mode */
4105 ctx
->bstate
= BS_STOP
;
4115 gen_op_mtc0_depc(); /* EJTAG support */
4125 gen_op_mtc0_performance0();
4126 rn
= "Performance0";
4129 // gen_op_mtc0_performance1();
4130 rn
= "Performance1";
4133 // gen_op_mtc0_performance2();
4134 rn
= "Performance2";
4137 // gen_op_mtc0_performance3();
4138 rn
= "Performance3";
4141 // gen_op_mtc0_performance4();
4142 rn
= "Performance4";
4145 // gen_op_mtc0_performance5();
4146 rn
= "Performance5";
4149 // gen_op_mtc0_performance6();
4150 rn
= "Performance6";
4153 // gen_op_mtc0_performance7();
4154 rn
= "Performance7";
4180 gen_op_mtc0_taglo();
4187 gen_op_mtc0_datalo();
4200 gen_op_mtc0_taghi();
4207 gen_op_mtc0_datahi();
4218 gen_op_mtc0_errorepc();
4228 gen_op_mtc0_desave(); /* EJTAG support */
4234 /* Stop translation as we may have switched the execution mode */
4235 ctx
->bstate
= BS_STOP
;
4240 #if defined MIPS_DEBUG_DISAS
4241 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4242 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4249 #if defined MIPS_DEBUG_DISAS
4250 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4251 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4255 generate_exception(ctx
, EXCP_RI
);
4257 #endif /* TARGET_MIPS64 */
4259 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4260 int u
, int sel
, int h
)
4262 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4264 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4265 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4266 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4268 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4269 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4276 gen_op_mftc0_tcstatus();
4279 gen_op_mftc0_tcbind();
4282 gen_op_mftc0_tcrestart();
4285 gen_op_mftc0_tchalt();
4288 gen_op_mftc0_tccontext();
4291 gen_op_mftc0_tcschedule();
4294 gen_op_mftc0_tcschefback();
4297 gen_mfc0(env
, ctx
, rt
, sel
);
4304 gen_op_mftc0_entryhi();
4307 gen_mfc0(env
, ctx
, rt
, sel
);
4313 gen_op_mftc0_status();
4316 gen_mfc0(env
, ctx
, rt
, sel
);
4322 gen_op_mftc0_debug();
4325 gen_mfc0(env
, ctx
, rt
, sel
);
4330 gen_mfc0(env
, ctx
, rt
, sel
);
4332 } else switch (sel
) {
4333 /* GPR registers. */
4337 /* Auxiliary CPU registers */
4383 /* Floating point (COP1). */
4385 /* XXX: For now we support only a single FPU context. */
4387 GEN_LOAD_FREG_FTN(WT0
, rt
);
4390 GEN_LOAD_FREG_FTN(WTH0
, rt
);
4395 /* XXX: For now we support only a single FPU context. */
4398 /* COP2: Not implemented. */
4405 #if defined MIPS_DEBUG_DISAS
4406 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4407 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4414 #if defined MIPS_DEBUG_DISAS
4415 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4416 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4420 generate_exception(ctx
, EXCP_RI
);
4423 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
4424 int u
, int sel
, int h
)
4426 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4428 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4429 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4430 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4432 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4433 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4440 gen_op_mttc0_tcstatus();
4443 gen_op_mttc0_tcbind();
4446 gen_op_mttc0_tcrestart();
4449 gen_op_mttc0_tchalt();
4452 gen_op_mttc0_tccontext();
4455 gen_op_mttc0_tcschedule();
4458 gen_op_mttc0_tcschefback();
4461 gen_mtc0(env
, ctx
, rd
, sel
);
4468 gen_op_mttc0_entryhi();
4471 gen_mtc0(env
, ctx
, rd
, sel
);
4477 gen_op_mttc0_status();
4480 gen_mtc0(env
, ctx
, rd
, sel
);
4486 gen_op_mttc0_debug();
4489 gen_mtc0(env
, ctx
, rd
, sel
);
4494 gen_mtc0(env
, ctx
, rd
, sel
);
4496 } else switch (sel
) {
4497 /* GPR registers. */
4501 /* Auxiliary CPU registers */
4547 /* Floating point (COP1). */
4549 /* XXX: For now we support only a single FPU context. */
4552 GEN_STORE_FTN_FREG(rd
, WT0
);
4555 GEN_STORE_FTN_FREG(rd
, WTH0
);
4559 /* XXX: For now we support only a single FPU context. */
4562 /* COP2: Not implemented. */
4569 #if defined MIPS_DEBUG_DISAS
4570 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4571 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4578 #if defined MIPS_DEBUG_DISAS
4579 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4580 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4584 generate_exception(ctx
, EXCP_RI
);
4587 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4589 const char *opn
= "ldst";
4597 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4598 gen_op_store_T0_gpr(rt
);
4602 GEN_LOAD_REG_TN(T0
, rt
);
4603 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4606 #ifdef TARGET_MIPS64
4608 check_insn(env
, ctx
, ISA_MIPS3
);
4613 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4614 gen_op_store_T0_gpr(rt
);
4618 check_insn(env
, ctx
, ISA_MIPS3
);
4619 GEN_LOAD_REG_TN(T0
, rt
);
4620 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4625 check_mips_mt(env
, ctx
);
4630 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
4631 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4632 gen_op_store_T0_gpr(rd
);
4636 check_mips_mt(env
, ctx
);
4637 GEN_LOAD_REG_TN(T0
, rt
);
4638 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
4639 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4644 if (!env
->tlb
->do_tlbwi
)
4650 if (!env
->tlb
->do_tlbwr
)
4656 if (!env
->tlb
->do_tlbp
)
4662 if (!env
->tlb
->do_tlbr
)
4668 check_insn(env
, ctx
, ISA_MIPS2
);
4670 ctx
->bstate
= BS_EXCP
;
4674 check_insn(env
, ctx
, ISA_MIPS32
);
4675 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4677 generate_exception(ctx
, EXCP_RI
);
4680 ctx
->bstate
= BS_EXCP
;
4685 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
4686 /* If we get an exception, we want to restart at next instruction */
4688 save_cpu_state(ctx
, 1);
4691 ctx
->bstate
= BS_EXCP
;
4696 generate_exception(ctx
, EXCP_RI
);
4699 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4702 /* CP1 Branches (before delay slot) */
4703 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
4704 int32_t cc
, int32_t offset
)
4706 target_ulong btarget
;
4707 const char *opn
= "cp1 cond branch";
4710 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
4712 btarget
= ctx
->pc
+ 4 + offset
;
4731 ctx
->hflags
|= MIPS_HFLAG_BL
;
4733 gen_op_save_bcond();
4736 gen_op_bc1any2f(cc
);
4740 gen_op_bc1any2t(cc
);
4744 gen_op_bc1any4f(cc
);
4748 gen_op_bc1any4t(cc
);
4751 ctx
->hflags
|= MIPS_HFLAG_BC
;
4756 generate_exception (ctx
, EXCP_RI
);
4759 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4760 ctx
->hflags
, btarget
);
4761 ctx
->btarget
= btarget
;
4764 /* Coprocessor 1 (FPU) */
4766 #define FOP(func, fmt) (((fmt) << 21) | (func))
4768 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4770 const char *opn
= "cp1 move";
4774 GEN_LOAD_FREG_FTN(WT0
, fs
);
4776 GEN_STORE_TN_REG(rt
, T0
);
4780 GEN_LOAD_REG_TN(T0
, rt
);
4782 GEN_STORE_FTN_FREG(fs
, WT0
);
4787 GEN_STORE_TN_REG(rt
, T0
);
4791 GEN_LOAD_REG_TN(T0
, rt
);
4796 GEN_LOAD_FREG_FTN(DT0
, fs
);
4798 GEN_STORE_TN_REG(rt
, T0
);
4802 GEN_LOAD_REG_TN(T0
, rt
);
4804 GEN_STORE_FTN_FREG(fs
, DT0
);
4808 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4810 GEN_STORE_TN_REG(rt
, T0
);
4814 GEN_LOAD_REG_TN(T0
, rt
);
4816 GEN_STORE_FTN_FREG(fs
, WTH0
);
4821 generate_exception (ctx
, EXCP_RI
);
4824 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4827 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4831 GEN_LOAD_REG_TN(T0
, rd
);
4832 GEN_LOAD_REG_TN(T1
, rs
);
4834 ccbit
= 1 << (24 + cc
);
4841 GEN_STORE_TN_REG(rd
, T0
);
4844 #define GEN_MOVCF(fmt) \
4845 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4850 ccbit = 1 << (24 + cc); \
4854 glue(gen_op_float_movf_, fmt)(ccbit); \
4856 glue(gen_op_float_movt_, fmt)(ccbit); \
4863 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4864 int ft
, int fs
, int fd
, int cc
)
4866 const char *opn
= "farith";
4867 const char *condnames
[] = {
4885 const char *condnames_abs
[] = {
4903 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
4904 uint32_t func
= ctx
->opcode
& 0x3f;
4906 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
4908 GEN_LOAD_FREG_FTN(WT0
, fs
);
4909 GEN_LOAD_FREG_FTN(WT1
, ft
);
4910 gen_op_float_add_s();
4911 GEN_STORE_FTN_FREG(fd
, WT2
);
4916 GEN_LOAD_FREG_FTN(WT0
, fs
);
4917 GEN_LOAD_FREG_FTN(WT1
, ft
);
4918 gen_op_float_sub_s();
4919 GEN_STORE_FTN_FREG(fd
, WT2
);
4924 GEN_LOAD_FREG_FTN(WT0
, fs
);
4925 GEN_LOAD_FREG_FTN(WT1
, ft
);
4926 gen_op_float_mul_s();
4927 GEN_STORE_FTN_FREG(fd
, WT2
);
4932 GEN_LOAD_FREG_FTN(WT0
, fs
);
4933 GEN_LOAD_FREG_FTN(WT1
, ft
);
4934 gen_op_float_div_s();
4935 GEN_STORE_FTN_FREG(fd
, WT2
);
4940 GEN_LOAD_FREG_FTN(WT0
, fs
);
4941 gen_op_float_sqrt_s();
4942 GEN_STORE_FTN_FREG(fd
, WT2
);
4946 GEN_LOAD_FREG_FTN(WT0
, fs
);
4947 gen_op_float_abs_s();
4948 GEN_STORE_FTN_FREG(fd
, WT2
);
4952 GEN_LOAD_FREG_FTN(WT0
, fs
);
4953 gen_op_float_mov_s();
4954 GEN_STORE_FTN_FREG(fd
, WT2
);
4958 GEN_LOAD_FREG_FTN(WT0
, fs
);
4959 gen_op_float_chs_s();
4960 GEN_STORE_FTN_FREG(fd
, WT2
);
4964 check_cp1_64bitmode(ctx
);
4965 GEN_LOAD_FREG_FTN(WT0
, fs
);
4966 gen_op_float_roundl_s();
4967 GEN_STORE_FTN_FREG(fd
, DT2
);
4971 check_cp1_64bitmode(ctx
);
4972 GEN_LOAD_FREG_FTN(WT0
, fs
);
4973 gen_op_float_truncl_s();
4974 GEN_STORE_FTN_FREG(fd
, DT2
);
4978 check_cp1_64bitmode(ctx
);
4979 GEN_LOAD_FREG_FTN(WT0
, fs
);
4980 gen_op_float_ceill_s();
4981 GEN_STORE_FTN_FREG(fd
, DT2
);
4985 check_cp1_64bitmode(ctx
);
4986 GEN_LOAD_FREG_FTN(WT0
, fs
);
4987 gen_op_float_floorl_s();
4988 GEN_STORE_FTN_FREG(fd
, DT2
);
4992 GEN_LOAD_FREG_FTN(WT0
, fs
);
4993 gen_op_float_roundw_s();
4994 GEN_STORE_FTN_FREG(fd
, WT2
);
4998 GEN_LOAD_FREG_FTN(WT0
, fs
);
4999 gen_op_float_truncw_s();
5000 GEN_STORE_FTN_FREG(fd
, WT2
);
5004 GEN_LOAD_FREG_FTN(WT0
, fs
);
5005 gen_op_float_ceilw_s();
5006 GEN_STORE_FTN_FREG(fd
, WT2
);
5010 GEN_LOAD_FREG_FTN(WT0
, fs
);
5011 gen_op_float_floorw_s();
5012 GEN_STORE_FTN_FREG(fd
, WT2
);
5016 GEN_LOAD_REG_TN(T0
, ft
);
5017 GEN_LOAD_FREG_FTN(WT0
, fs
);
5018 GEN_LOAD_FREG_FTN(WT2
, fd
);
5019 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5020 GEN_STORE_FTN_FREG(fd
, WT2
);
5024 GEN_LOAD_REG_TN(T0
, ft
);
5025 GEN_LOAD_FREG_FTN(WT0
, fs
);
5026 GEN_LOAD_FREG_FTN(WT2
, fd
);
5027 gen_op_float_movz_s();
5028 GEN_STORE_FTN_FREG(fd
, WT2
);
5032 GEN_LOAD_REG_TN(T0
, ft
);
5033 GEN_LOAD_FREG_FTN(WT0
, fs
);
5034 GEN_LOAD_FREG_FTN(WT2
, fd
);
5035 gen_op_float_movn_s();
5036 GEN_STORE_FTN_FREG(fd
, WT2
);
5040 GEN_LOAD_FREG_FTN(WT0
, fs
);
5041 gen_op_float_recip_s();
5042 GEN_STORE_FTN_FREG(fd
, WT2
);
5046 GEN_LOAD_FREG_FTN(WT0
, fs
);
5047 gen_op_float_rsqrt_s();
5048 GEN_STORE_FTN_FREG(fd
, WT2
);
5052 check_cp1_64bitmode(ctx
);
5053 GEN_LOAD_FREG_FTN(WT0
, fs
);
5054 GEN_LOAD_FREG_FTN(WT2
, fd
);
5055 gen_op_float_recip2_s();
5056 GEN_STORE_FTN_FREG(fd
, WT2
);
5060 check_cp1_64bitmode(ctx
);
5061 GEN_LOAD_FREG_FTN(WT0
, fs
);
5062 gen_op_float_recip1_s();
5063 GEN_STORE_FTN_FREG(fd
, WT2
);
5067 check_cp1_64bitmode(ctx
);
5068 GEN_LOAD_FREG_FTN(WT0
, fs
);
5069 gen_op_float_rsqrt1_s();
5070 GEN_STORE_FTN_FREG(fd
, WT2
);
5074 check_cp1_64bitmode(ctx
);
5075 GEN_LOAD_FREG_FTN(WT0
, fs
);
5076 GEN_LOAD_FREG_FTN(WT2
, ft
);
5077 gen_op_float_rsqrt2_s();
5078 GEN_STORE_FTN_FREG(fd
, WT2
);
5082 check_cp1_registers(ctx
, fd
);
5083 GEN_LOAD_FREG_FTN(WT0
, fs
);
5084 gen_op_float_cvtd_s();
5085 GEN_STORE_FTN_FREG(fd
, DT2
);
5089 GEN_LOAD_FREG_FTN(WT0
, fs
);
5090 gen_op_float_cvtw_s();
5091 GEN_STORE_FTN_FREG(fd
, WT2
);
5095 check_cp1_64bitmode(ctx
);
5096 GEN_LOAD_FREG_FTN(WT0
, fs
);
5097 gen_op_float_cvtl_s();
5098 GEN_STORE_FTN_FREG(fd
, DT2
);
5102 check_cp1_64bitmode(ctx
);
5103 GEN_LOAD_FREG_FTN(WT1
, fs
);
5104 GEN_LOAD_FREG_FTN(WT0
, ft
);
5105 gen_op_float_cvtps_s();
5106 GEN_STORE_FTN_FREG(fd
, DT2
);
5125 GEN_LOAD_FREG_FTN(WT0
, fs
);
5126 GEN_LOAD_FREG_FTN(WT1
, ft
);
5127 if (ctx
->opcode
& (1 << 6)) {
5128 check_cp1_64bitmode(ctx
);
5129 gen_cmpabs_s(func
-48, cc
);
5130 opn
= condnames_abs
[func
-48];
5132 gen_cmp_s(func
-48, cc
);
5133 opn
= condnames
[func
-48];
5137 check_cp1_registers(ctx
, fs
| ft
| fd
);
5138 GEN_LOAD_FREG_FTN(DT0
, fs
);
5139 GEN_LOAD_FREG_FTN(DT1
, ft
);
5140 gen_op_float_add_d();
5141 GEN_STORE_FTN_FREG(fd
, DT2
);
5146 check_cp1_registers(ctx
, fs
| ft
| fd
);
5147 GEN_LOAD_FREG_FTN(DT0
, fs
);
5148 GEN_LOAD_FREG_FTN(DT1
, ft
);
5149 gen_op_float_sub_d();
5150 GEN_STORE_FTN_FREG(fd
, DT2
);
5155 check_cp1_registers(ctx
, fs
| ft
| fd
);
5156 GEN_LOAD_FREG_FTN(DT0
, fs
);
5157 GEN_LOAD_FREG_FTN(DT1
, ft
);
5158 gen_op_float_mul_d();
5159 GEN_STORE_FTN_FREG(fd
, DT2
);
5164 check_cp1_registers(ctx
, fs
| ft
| fd
);
5165 GEN_LOAD_FREG_FTN(DT0
, fs
);
5166 GEN_LOAD_FREG_FTN(DT1
, ft
);
5167 gen_op_float_div_d();
5168 GEN_STORE_FTN_FREG(fd
, DT2
);
5173 check_cp1_registers(ctx
, fs
| fd
);
5174 GEN_LOAD_FREG_FTN(DT0
, fs
);
5175 gen_op_float_sqrt_d();
5176 GEN_STORE_FTN_FREG(fd
, DT2
);
5180 check_cp1_registers(ctx
, fs
| fd
);
5181 GEN_LOAD_FREG_FTN(DT0
, fs
);
5182 gen_op_float_abs_d();
5183 GEN_STORE_FTN_FREG(fd
, DT2
);
5187 check_cp1_registers(ctx
, fs
| fd
);
5188 GEN_LOAD_FREG_FTN(DT0
, fs
);
5189 gen_op_float_mov_d();
5190 GEN_STORE_FTN_FREG(fd
, DT2
);
5194 check_cp1_registers(ctx
, fs
| fd
);
5195 GEN_LOAD_FREG_FTN(DT0
, fs
);
5196 gen_op_float_chs_d();
5197 GEN_STORE_FTN_FREG(fd
, DT2
);
5201 check_cp1_64bitmode(ctx
);
5202 GEN_LOAD_FREG_FTN(DT0
, fs
);
5203 gen_op_float_roundl_d();
5204 GEN_STORE_FTN_FREG(fd
, DT2
);
5208 check_cp1_64bitmode(ctx
);
5209 GEN_LOAD_FREG_FTN(DT0
, fs
);
5210 gen_op_float_truncl_d();
5211 GEN_STORE_FTN_FREG(fd
, DT2
);
5215 check_cp1_64bitmode(ctx
);
5216 GEN_LOAD_FREG_FTN(DT0
, fs
);
5217 gen_op_float_ceill_d();
5218 GEN_STORE_FTN_FREG(fd
, DT2
);
5222 check_cp1_64bitmode(ctx
);
5223 GEN_LOAD_FREG_FTN(DT0
, fs
);
5224 gen_op_float_floorl_d();
5225 GEN_STORE_FTN_FREG(fd
, DT2
);
5229 check_cp1_registers(ctx
, fs
);
5230 GEN_LOAD_FREG_FTN(DT0
, fs
);
5231 gen_op_float_roundw_d();
5232 GEN_STORE_FTN_FREG(fd
, WT2
);
5236 check_cp1_registers(ctx
, fs
);
5237 GEN_LOAD_FREG_FTN(DT0
, fs
);
5238 gen_op_float_truncw_d();
5239 GEN_STORE_FTN_FREG(fd
, WT2
);
5243 check_cp1_registers(ctx
, fs
);
5244 GEN_LOAD_FREG_FTN(DT0
, fs
);
5245 gen_op_float_ceilw_d();
5246 GEN_STORE_FTN_FREG(fd
, WT2
);
5250 check_cp1_registers(ctx
, fs
);
5251 GEN_LOAD_FREG_FTN(DT0
, fs
);
5252 gen_op_float_floorw_d();
5253 GEN_STORE_FTN_FREG(fd
, WT2
);
5257 GEN_LOAD_REG_TN(T0
, ft
);
5258 GEN_LOAD_FREG_FTN(DT0
, fs
);
5259 GEN_LOAD_FREG_FTN(DT2
, fd
);
5260 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5261 GEN_STORE_FTN_FREG(fd
, DT2
);
5265 GEN_LOAD_REG_TN(T0
, ft
);
5266 GEN_LOAD_FREG_FTN(DT0
, fs
);
5267 GEN_LOAD_FREG_FTN(DT2
, fd
);
5268 gen_op_float_movz_d();
5269 GEN_STORE_FTN_FREG(fd
, DT2
);
5273 GEN_LOAD_REG_TN(T0
, ft
);
5274 GEN_LOAD_FREG_FTN(DT0
, fs
);
5275 GEN_LOAD_FREG_FTN(DT2
, fd
);
5276 gen_op_float_movn_d();
5277 GEN_STORE_FTN_FREG(fd
, DT2
);
5281 check_cp1_registers(ctx
, fs
| fd
);
5282 GEN_LOAD_FREG_FTN(DT0
, fs
);
5283 gen_op_float_recip_d();
5284 GEN_STORE_FTN_FREG(fd
, DT2
);
5288 check_cp1_registers(ctx
, fs
| fd
);
5289 GEN_LOAD_FREG_FTN(DT0
, fs
);
5290 gen_op_float_rsqrt_d();
5291 GEN_STORE_FTN_FREG(fd
, DT2
);
5295 check_cp1_64bitmode(ctx
);
5296 GEN_LOAD_FREG_FTN(DT0
, fs
);
5297 GEN_LOAD_FREG_FTN(DT2
, ft
);
5298 gen_op_float_recip2_d();
5299 GEN_STORE_FTN_FREG(fd
, DT2
);
5303 check_cp1_64bitmode(ctx
);
5304 GEN_LOAD_FREG_FTN(DT0
, fs
);
5305 gen_op_float_recip1_d();
5306 GEN_STORE_FTN_FREG(fd
, DT2
);
5310 check_cp1_64bitmode(ctx
);
5311 GEN_LOAD_FREG_FTN(DT0
, fs
);
5312 gen_op_float_rsqrt1_d();
5313 GEN_STORE_FTN_FREG(fd
, DT2
);
5317 check_cp1_64bitmode(ctx
);
5318 GEN_LOAD_FREG_FTN(DT0
, fs
);
5319 GEN_LOAD_FREG_FTN(DT2
, ft
);
5320 gen_op_float_rsqrt2_d();
5321 GEN_STORE_FTN_FREG(fd
, DT2
);
5340 GEN_LOAD_FREG_FTN(DT0
, fs
);
5341 GEN_LOAD_FREG_FTN(DT1
, ft
);
5342 if (ctx
->opcode
& (1 << 6)) {
5343 check_cp1_64bitmode(ctx
);
5344 gen_cmpabs_d(func
-48, cc
);
5345 opn
= condnames_abs
[func
-48];
5347 check_cp1_registers(ctx
, fs
| ft
);
5348 gen_cmp_d(func
-48, cc
);
5349 opn
= condnames
[func
-48];
5353 check_cp1_registers(ctx
, fs
);
5354 GEN_LOAD_FREG_FTN(DT0
, fs
);
5355 gen_op_float_cvts_d();
5356 GEN_STORE_FTN_FREG(fd
, WT2
);
5360 check_cp1_registers(ctx
, fs
);
5361 GEN_LOAD_FREG_FTN(DT0
, fs
);
5362 gen_op_float_cvtw_d();
5363 GEN_STORE_FTN_FREG(fd
, WT2
);
5367 check_cp1_64bitmode(ctx
);
5368 GEN_LOAD_FREG_FTN(DT0
, fs
);
5369 gen_op_float_cvtl_d();
5370 GEN_STORE_FTN_FREG(fd
, DT2
);
5374 GEN_LOAD_FREG_FTN(WT0
, fs
);
5375 gen_op_float_cvts_w();
5376 GEN_STORE_FTN_FREG(fd
, WT2
);
5380 check_cp1_registers(ctx
, fd
);
5381 GEN_LOAD_FREG_FTN(WT0
, fs
);
5382 gen_op_float_cvtd_w();
5383 GEN_STORE_FTN_FREG(fd
, DT2
);
5387 check_cp1_64bitmode(ctx
);
5388 GEN_LOAD_FREG_FTN(DT0
, fs
);
5389 gen_op_float_cvts_l();
5390 GEN_STORE_FTN_FREG(fd
, WT2
);
5394 check_cp1_64bitmode(ctx
);
5395 GEN_LOAD_FREG_FTN(DT0
, fs
);
5396 gen_op_float_cvtd_l();
5397 GEN_STORE_FTN_FREG(fd
, DT2
);
5402 check_cp1_64bitmode(ctx
);
5403 GEN_LOAD_FREG_FTN(WT0
, fs
);
5404 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5405 gen_op_float_cvtps_pw();
5406 GEN_STORE_FTN_FREG(fd
, WT2
);
5407 GEN_STORE_FTN_FREG(fd
, WTH2
);
5411 check_cp1_64bitmode(ctx
);
5412 GEN_LOAD_FREG_FTN(WT0
, fs
);
5413 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5414 GEN_LOAD_FREG_FTN(WT1
, ft
);
5415 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5416 gen_op_float_add_ps();
5417 GEN_STORE_FTN_FREG(fd
, WT2
);
5418 GEN_STORE_FTN_FREG(fd
, WTH2
);
5422 check_cp1_64bitmode(ctx
);
5423 GEN_LOAD_FREG_FTN(WT0
, fs
);
5424 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5425 GEN_LOAD_FREG_FTN(WT1
, ft
);
5426 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5427 gen_op_float_sub_ps();
5428 GEN_STORE_FTN_FREG(fd
, WT2
);
5429 GEN_STORE_FTN_FREG(fd
, WTH2
);
5433 check_cp1_64bitmode(ctx
);
5434 GEN_LOAD_FREG_FTN(WT0
, fs
);
5435 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5436 GEN_LOAD_FREG_FTN(WT1
, ft
);
5437 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5438 gen_op_float_mul_ps();
5439 GEN_STORE_FTN_FREG(fd
, WT2
);
5440 GEN_STORE_FTN_FREG(fd
, WTH2
);
5444 check_cp1_64bitmode(ctx
);
5445 GEN_LOAD_FREG_FTN(WT0
, fs
);
5446 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5447 gen_op_float_abs_ps();
5448 GEN_STORE_FTN_FREG(fd
, WT2
);
5449 GEN_STORE_FTN_FREG(fd
, WTH2
);
5453 check_cp1_64bitmode(ctx
);
5454 GEN_LOAD_FREG_FTN(WT0
, fs
);
5455 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5456 gen_op_float_mov_ps();
5457 GEN_STORE_FTN_FREG(fd
, WT2
);
5458 GEN_STORE_FTN_FREG(fd
, WTH2
);
5462 check_cp1_64bitmode(ctx
);
5463 GEN_LOAD_FREG_FTN(WT0
, fs
);
5464 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5465 gen_op_float_chs_ps();
5466 GEN_STORE_FTN_FREG(fd
, WT2
);
5467 GEN_STORE_FTN_FREG(fd
, WTH2
);
5471 check_cp1_64bitmode(ctx
);
5472 GEN_LOAD_REG_TN(T0
, ft
);
5473 GEN_LOAD_FREG_FTN(WT0
, fs
);
5474 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5475 GEN_LOAD_FREG_FTN(WT2
, fd
);
5476 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5477 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5478 GEN_STORE_FTN_FREG(fd
, WT2
);
5479 GEN_STORE_FTN_FREG(fd
, WTH2
);
5483 check_cp1_64bitmode(ctx
);
5484 GEN_LOAD_REG_TN(T0
, ft
);
5485 GEN_LOAD_FREG_FTN(WT0
, fs
);
5486 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5487 GEN_LOAD_FREG_FTN(WT2
, fd
);
5488 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5489 gen_op_float_movz_ps();
5490 GEN_STORE_FTN_FREG(fd
, WT2
);
5491 GEN_STORE_FTN_FREG(fd
, WTH2
);
5495 check_cp1_64bitmode(ctx
);
5496 GEN_LOAD_REG_TN(T0
, ft
);
5497 GEN_LOAD_FREG_FTN(WT0
, fs
);
5498 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5499 GEN_LOAD_FREG_FTN(WT2
, fd
);
5500 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5501 gen_op_float_movn_ps();
5502 GEN_STORE_FTN_FREG(fd
, WT2
);
5503 GEN_STORE_FTN_FREG(fd
, WTH2
);
5507 check_cp1_64bitmode(ctx
);
5508 GEN_LOAD_FREG_FTN(WT0
, ft
);
5509 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5510 GEN_LOAD_FREG_FTN(WT1
, fs
);
5511 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5512 gen_op_float_addr_ps();
5513 GEN_STORE_FTN_FREG(fd
, WT2
);
5514 GEN_STORE_FTN_FREG(fd
, WTH2
);
5518 check_cp1_64bitmode(ctx
);
5519 GEN_LOAD_FREG_FTN(WT0
, ft
);
5520 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5521 GEN_LOAD_FREG_FTN(WT1
, fs
);
5522 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5523 gen_op_float_mulr_ps();
5524 GEN_STORE_FTN_FREG(fd
, WT2
);
5525 GEN_STORE_FTN_FREG(fd
, WTH2
);
5529 check_cp1_64bitmode(ctx
);
5530 GEN_LOAD_FREG_FTN(WT0
, fs
);
5531 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5532 GEN_LOAD_FREG_FTN(WT2
, fd
);
5533 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5534 gen_op_float_recip2_ps();
5535 GEN_STORE_FTN_FREG(fd
, WT2
);
5536 GEN_STORE_FTN_FREG(fd
, WTH2
);
5540 check_cp1_64bitmode(ctx
);
5541 GEN_LOAD_FREG_FTN(WT0
, fs
);
5542 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5543 gen_op_float_recip1_ps();
5544 GEN_STORE_FTN_FREG(fd
, WT2
);
5545 GEN_STORE_FTN_FREG(fd
, WTH2
);
5549 check_cp1_64bitmode(ctx
);
5550 GEN_LOAD_FREG_FTN(WT0
, fs
);
5551 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5552 gen_op_float_rsqrt1_ps();
5553 GEN_STORE_FTN_FREG(fd
, WT2
);
5554 GEN_STORE_FTN_FREG(fd
, WTH2
);
5558 check_cp1_64bitmode(ctx
);
5559 GEN_LOAD_FREG_FTN(WT0
, fs
);
5560 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5561 GEN_LOAD_FREG_FTN(WT2
, ft
);
5562 GEN_LOAD_FREG_FTN(WTH2
, ft
);
5563 gen_op_float_rsqrt2_ps();
5564 GEN_STORE_FTN_FREG(fd
, WT2
);
5565 GEN_STORE_FTN_FREG(fd
, WTH2
);
5569 check_cp1_64bitmode(ctx
);
5570 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5571 gen_op_float_cvts_pu();
5572 GEN_STORE_FTN_FREG(fd
, WT2
);
5576 check_cp1_64bitmode(ctx
);
5577 GEN_LOAD_FREG_FTN(WT0
, fs
);
5578 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5579 gen_op_float_cvtpw_ps();
5580 GEN_STORE_FTN_FREG(fd
, WT2
);
5581 GEN_STORE_FTN_FREG(fd
, WTH2
);
5585 check_cp1_64bitmode(ctx
);
5586 GEN_LOAD_FREG_FTN(WT0
, fs
);
5587 gen_op_float_cvts_pl();
5588 GEN_STORE_FTN_FREG(fd
, WT2
);
5592 check_cp1_64bitmode(ctx
);
5593 GEN_LOAD_FREG_FTN(WT0
, fs
);
5594 GEN_LOAD_FREG_FTN(WT1
, ft
);
5595 gen_op_float_pll_ps();
5596 GEN_STORE_FTN_FREG(fd
, DT2
);
5600 check_cp1_64bitmode(ctx
);
5601 GEN_LOAD_FREG_FTN(WT0
, fs
);
5602 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5603 gen_op_float_plu_ps();
5604 GEN_STORE_FTN_FREG(fd
, DT2
);
5608 check_cp1_64bitmode(ctx
);
5609 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5610 GEN_LOAD_FREG_FTN(WT1
, ft
);
5611 gen_op_float_pul_ps();
5612 GEN_STORE_FTN_FREG(fd
, DT2
);
5616 check_cp1_64bitmode(ctx
);
5617 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5618 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5619 gen_op_float_puu_ps();
5620 GEN_STORE_FTN_FREG(fd
, DT2
);
5639 check_cp1_64bitmode(ctx
);
5640 GEN_LOAD_FREG_FTN(WT0
, fs
);
5641 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5642 GEN_LOAD_FREG_FTN(WT1
, ft
);
5643 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5644 if (ctx
->opcode
& (1 << 6)) {
5645 gen_cmpabs_ps(func
-48, cc
);
5646 opn
= condnames_abs
[func
-48];
5648 gen_cmp_ps(func
-48, cc
);
5649 opn
= condnames
[func
-48];
5654 generate_exception (ctx
, EXCP_RI
);
5659 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5662 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5665 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5670 /* Coprocessor 3 (FPU) */
5671 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5672 int fd
, int fs
, int base
, int index
)
5674 const char *opn
= "extended float load/store";
5677 /* All of those work only on 64bit FPUs. */
5678 check_cp1_64bitmode(ctx
);
5683 GEN_LOAD_REG_TN(T0
, index
);
5684 } else if (index
== 0) {
5685 GEN_LOAD_REG_TN(T0
, base
);
5687 GEN_LOAD_REG_TN(T0
, base
);
5688 GEN_LOAD_REG_TN(T1
, index
);
5691 /* Don't do NOP if destination is zero: we must perform the actual
5696 GEN_STORE_FTN_FREG(fd
, WT0
);
5701 GEN_STORE_FTN_FREG(fd
, DT0
);
5706 GEN_STORE_FTN_FREG(fd
, DT0
);
5710 GEN_LOAD_FREG_FTN(WT0
, fs
);
5716 GEN_LOAD_FREG_FTN(DT0
, fs
);
5722 GEN_LOAD_FREG_FTN(DT0
, fs
);
5729 generate_exception(ctx
, EXCP_RI
);
5732 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5733 regnames
[index
], regnames
[base
]);
5736 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5737 int fd
, int fr
, int fs
, int ft
)
5739 const char *opn
= "flt3_arith";
5741 /* All of those work only on 64bit FPUs. */
5742 check_cp1_64bitmode(ctx
);
5745 GEN_LOAD_REG_TN(T0
, fr
);
5746 GEN_LOAD_FREG_FTN(DT0
, fs
);
5747 GEN_LOAD_FREG_FTN(DT1
, ft
);
5748 gen_op_float_alnv_ps();
5749 GEN_STORE_FTN_FREG(fd
, DT2
);
5753 GEN_LOAD_FREG_FTN(WT0
, fs
);
5754 GEN_LOAD_FREG_FTN(WT1
, ft
);
5755 GEN_LOAD_FREG_FTN(WT2
, fr
);
5756 gen_op_float_muladd_s();
5757 GEN_STORE_FTN_FREG(fd
, WT2
);
5761 GEN_LOAD_FREG_FTN(DT0
, fs
);
5762 GEN_LOAD_FREG_FTN(DT1
, ft
);
5763 GEN_LOAD_FREG_FTN(DT2
, fr
);
5764 gen_op_float_muladd_d();
5765 GEN_STORE_FTN_FREG(fd
, DT2
);
5769 GEN_LOAD_FREG_FTN(WT0
, fs
);
5770 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5771 GEN_LOAD_FREG_FTN(WT1
, ft
);
5772 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5773 GEN_LOAD_FREG_FTN(WT2
, fr
);
5774 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5775 gen_op_float_muladd_ps();
5776 GEN_STORE_FTN_FREG(fd
, WT2
);
5777 GEN_STORE_FTN_FREG(fd
, WTH2
);
5781 GEN_LOAD_FREG_FTN(WT0
, fs
);
5782 GEN_LOAD_FREG_FTN(WT1
, ft
);
5783 GEN_LOAD_FREG_FTN(WT2
, fr
);
5784 gen_op_float_mulsub_s();
5785 GEN_STORE_FTN_FREG(fd
, WT2
);
5789 GEN_LOAD_FREG_FTN(DT0
, fs
);
5790 GEN_LOAD_FREG_FTN(DT1
, ft
);
5791 GEN_LOAD_FREG_FTN(DT2
, fr
);
5792 gen_op_float_mulsub_d();
5793 GEN_STORE_FTN_FREG(fd
, DT2
);
5797 GEN_LOAD_FREG_FTN(WT0
, fs
);
5798 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5799 GEN_LOAD_FREG_FTN(WT1
, ft
);
5800 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5801 GEN_LOAD_FREG_FTN(WT2
, fr
);
5802 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5803 gen_op_float_mulsub_ps();
5804 GEN_STORE_FTN_FREG(fd
, WT2
);
5805 GEN_STORE_FTN_FREG(fd
, WTH2
);
5809 GEN_LOAD_FREG_FTN(WT0
, fs
);
5810 GEN_LOAD_FREG_FTN(WT1
, ft
);
5811 GEN_LOAD_FREG_FTN(WT2
, fr
);
5812 gen_op_float_nmuladd_s();
5813 GEN_STORE_FTN_FREG(fd
, WT2
);
5817 GEN_LOAD_FREG_FTN(DT0
, fs
);
5818 GEN_LOAD_FREG_FTN(DT1
, ft
);
5819 GEN_LOAD_FREG_FTN(DT2
, fr
);
5820 gen_op_float_nmuladd_d();
5821 GEN_STORE_FTN_FREG(fd
, DT2
);
5825 GEN_LOAD_FREG_FTN(WT0
, fs
);
5826 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5827 GEN_LOAD_FREG_FTN(WT1
, ft
);
5828 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5829 GEN_LOAD_FREG_FTN(WT2
, fr
);
5830 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5831 gen_op_float_nmuladd_ps();
5832 GEN_STORE_FTN_FREG(fd
, WT2
);
5833 GEN_STORE_FTN_FREG(fd
, WTH2
);
5837 GEN_LOAD_FREG_FTN(WT0
, fs
);
5838 GEN_LOAD_FREG_FTN(WT1
, ft
);
5839 GEN_LOAD_FREG_FTN(WT2
, fr
);
5840 gen_op_float_nmulsub_s();
5841 GEN_STORE_FTN_FREG(fd
, WT2
);
5845 GEN_LOAD_FREG_FTN(DT0
, fs
);
5846 GEN_LOAD_FREG_FTN(DT1
, ft
);
5847 GEN_LOAD_FREG_FTN(DT2
, fr
);
5848 gen_op_float_nmulsub_d();
5849 GEN_STORE_FTN_FREG(fd
, DT2
);
5853 GEN_LOAD_FREG_FTN(WT0
, fs
);
5854 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5855 GEN_LOAD_FREG_FTN(WT1
, ft
);
5856 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5857 GEN_LOAD_FREG_FTN(WT2
, fr
);
5858 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5859 gen_op_float_nmulsub_ps();
5860 GEN_STORE_FTN_FREG(fd
, WT2
);
5861 GEN_STORE_FTN_FREG(fd
, WTH2
);
5866 generate_exception (ctx
, EXCP_RI
);
5869 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
5870 fregnames
[fs
], fregnames
[ft
]);
5873 /* ISA extensions (ASEs) */
5874 /* MIPS16 extension to MIPS32 */
5875 /* SmartMIPS extension to MIPS32 */
5877 #ifdef TARGET_MIPS64
5879 /* MDMX extension to MIPS64 */
5880 /* MIPS-3D extension to MIPS64 */
5884 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
5888 uint32_t op
, op1
, op2
;
5891 /* make sure instructions are on a word boundary */
5892 if (ctx
->pc
& 0x3) {
5893 env
->CP0_BadVAddr
= ctx
->pc
;
5894 generate_exception(ctx
, EXCP_AdEL
);
5898 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
5900 /* Handle blikely not taken case */
5901 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
5902 l1
= gen_new_label();
5904 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
5905 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5908 op
= MASK_OP_MAJOR(ctx
->opcode
);
5909 rs
= (ctx
->opcode
>> 21) & 0x1f;
5910 rt
= (ctx
->opcode
>> 16) & 0x1f;
5911 rd
= (ctx
->opcode
>> 11) & 0x1f;
5912 sa
= (ctx
->opcode
>> 6) & 0x1f;
5913 imm
= (int16_t)ctx
->opcode
;
5916 op1
= MASK_SPECIAL(ctx
->opcode
);
5918 case OPC_SLL
: /* Arithmetic with immediate */
5919 case OPC_SRL
... OPC_SRA
:
5920 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
5922 case OPC_MOVZ
... OPC_MOVN
:
5923 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5924 case OPC_SLLV
: /* Arithmetic */
5925 case OPC_SRLV
... OPC_SRAV
:
5926 case OPC_ADD
... OPC_NOR
:
5927 case OPC_SLT
... OPC_SLTU
:
5928 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
5930 case OPC_MULT
... OPC_DIVU
:
5931 gen_muldiv(ctx
, op1
, rs
, rt
);
5933 case OPC_JR
... OPC_JALR
:
5934 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
5936 case OPC_TGE
... OPC_TEQ
: /* Traps */
5938 gen_trap(ctx
, op1
, rs
, rt
, -1);
5940 case OPC_MFHI
: /* Move from HI/LO */
5942 gen_HILO(ctx
, op1
, rd
);
5945 case OPC_MTLO
: /* Move to HI/LO */
5946 gen_HILO(ctx
, op1
, rs
);
5948 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
5949 #ifdef MIPS_STRICT_STANDARD
5950 MIPS_INVAL("PMON / selsl");
5951 generate_exception(ctx
, EXCP_RI
);
5957 generate_exception(ctx
, EXCP_SYSCALL
);
5960 generate_exception(ctx
, EXCP_BREAK
);
5963 #ifdef MIPS_STRICT_STANDARD
5965 generate_exception(ctx
, EXCP_RI
);
5967 /* Implemented as RI exception for now. */
5968 MIPS_INVAL("spim (unofficial)");
5969 generate_exception(ctx
, EXCP_RI
);
5977 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5978 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5979 save_cpu_state(ctx
, 1);
5980 check_cp1_enabled(ctx
);
5981 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
5982 (ctx
->opcode
>> 16) & 1);
5984 generate_exception_err(ctx
, EXCP_CpU
, 1);
5988 #ifdef TARGET_MIPS64
5989 /* MIPS64 specific opcodes */
5991 case OPC_DSRL
... OPC_DSRA
:
5993 case OPC_DSRL32
... OPC_DSRA32
:
5994 check_insn(env
, ctx
, ISA_MIPS3
);
5996 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
5999 case OPC_DSRLV
... OPC_DSRAV
:
6000 case OPC_DADD
... OPC_DSUBU
:
6001 check_insn(env
, ctx
, ISA_MIPS3
);
6003 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6005 case OPC_DMULT
... OPC_DDIVU
:
6006 check_insn(env
, ctx
, ISA_MIPS3
);
6008 gen_muldiv(ctx
, op1
, rs
, rt
);
6011 default: /* Invalid */
6012 MIPS_INVAL("special");
6013 generate_exception(ctx
, EXCP_RI
);
6018 op1
= MASK_SPECIAL2(ctx
->opcode
);
6020 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6021 case OPC_MSUB
... OPC_MSUBU
:
6022 check_insn(env
, ctx
, ISA_MIPS32
);
6023 gen_muldiv(ctx
, op1
, rs
, rt
);
6026 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6028 case OPC_CLZ
... OPC_CLO
:
6029 check_insn(env
, ctx
, ISA_MIPS32
);
6030 gen_cl(ctx
, op1
, rd
, rs
);
6033 /* XXX: not clear which exception should be raised
6034 * when in debug mode...
6036 check_insn(env
, ctx
, ISA_MIPS32
);
6037 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6038 generate_exception(ctx
, EXCP_DBp
);
6040 generate_exception(ctx
, EXCP_DBp
);
6044 #ifdef TARGET_MIPS64
6045 case OPC_DCLZ
... OPC_DCLO
:
6046 check_insn(env
, ctx
, ISA_MIPS64
);
6048 gen_cl(ctx
, op1
, rd
, rs
);
6051 default: /* Invalid */
6052 MIPS_INVAL("special2");
6053 generate_exception(ctx
, EXCP_RI
);
6058 op1
= MASK_SPECIAL3(ctx
->opcode
);
6062 check_insn(env
, ctx
, ISA_MIPS32R2
);
6063 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6066 check_insn(env
, ctx
, ISA_MIPS32R2
);
6067 op2
= MASK_BSHFL(ctx
->opcode
);
6070 GEN_LOAD_REG_TN(T1
, rt
);
6074 GEN_LOAD_REG_TN(T1
, rt
);
6078 GEN_LOAD_REG_TN(T1
, rt
);
6081 default: /* Invalid */
6082 MIPS_INVAL("bshfl");
6083 generate_exception(ctx
, EXCP_RI
);
6086 GEN_STORE_TN_REG(rd
, T0
);
6089 check_insn(env
, ctx
, ISA_MIPS32R2
);
6092 save_cpu_state(ctx
, 1);
6093 gen_op_rdhwr_cpunum();
6096 save_cpu_state(ctx
, 1);
6097 gen_op_rdhwr_synci_step();
6100 save_cpu_state(ctx
, 1);
6104 save_cpu_state(ctx
, 1);
6105 gen_op_rdhwr_ccres();
6108 #if defined (CONFIG_USER_ONLY)
6112 default: /* Invalid */
6113 MIPS_INVAL("rdhwr");
6114 generate_exception(ctx
, EXCP_RI
);
6117 GEN_STORE_TN_REG(rt
, T0
);
6120 check_mips_mt(env
, ctx
);
6121 GEN_LOAD_REG_TN(T0
, rt
);
6122 GEN_LOAD_REG_TN(T1
, rs
);
6126 check_mips_mt(env
, ctx
);
6127 GEN_LOAD_REG_TN(T0
, rs
);
6129 GEN_STORE_TN_REG(rd
, T0
);
6131 #ifdef TARGET_MIPS64
6132 case OPC_DEXTM
... OPC_DEXT
:
6133 case OPC_DINSM
... OPC_DINS
:
6134 check_insn(env
, ctx
, ISA_MIPS64R2
);
6136 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6139 check_insn(env
, ctx
, ISA_MIPS64R2
);
6141 op2
= MASK_DBSHFL(ctx
->opcode
);
6144 GEN_LOAD_REG_TN(T1
, rt
);
6148 GEN_LOAD_REG_TN(T1
, rt
);
6151 default: /* Invalid */
6152 MIPS_INVAL("dbshfl");
6153 generate_exception(ctx
, EXCP_RI
);
6156 GEN_STORE_TN_REG(rd
, T0
);
6158 default: /* Invalid */
6159 MIPS_INVAL("special3");
6160 generate_exception(ctx
, EXCP_RI
);
6165 op1
= MASK_REGIMM(ctx
->opcode
);
6167 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6168 case OPC_BLTZAL
... OPC_BGEZALL
:
6169 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6171 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6173 gen_trap(ctx
, op1
, rs
, -1, imm
);
6176 check_insn(env
, ctx
, ISA_MIPS32R2
);
6179 default: /* Invalid */
6180 MIPS_INVAL("regimm");
6181 generate_exception(ctx
, EXCP_RI
);
6186 save_cpu_state(ctx
, 1);
6187 gen_op_cp0_enabled();
6188 op1
= MASK_CP0(ctx
->opcode
);
6194 #ifdef TARGET_MIPS64
6198 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6200 case OPC_C0_FIRST
... OPC_C0_LAST
:
6201 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6204 op2
= MASK_MFMC0(ctx
->opcode
);
6207 check_mips_mt(env
, ctx
);
6211 check_mips_mt(env
, ctx
);
6215 check_mips_mt(env
, ctx
);
6219 check_mips_mt(env
, ctx
);
6223 check_insn(env
, ctx
, ISA_MIPS32R2
);
6225 /* Stop translation as we may have switched the execution mode */
6226 ctx
->bstate
= BS_STOP
;
6229 check_insn(env
, ctx
, ISA_MIPS32R2
);
6231 /* Stop translation as we may have switched the execution mode */
6232 ctx
->bstate
= BS_STOP
;
6234 default: /* Invalid */
6235 MIPS_INVAL("mfmc0");
6236 generate_exception(ctx
, EXCP_RI
);
6239 GEN_STORE_TN_REG(rt
, T0
);
6242 check_insn(env
, ctx
, ISA_MIPS32R2
);
6243 GEN_LOAD_SRSREG_TN(T0
, rt
);
6244 GEN_STORE_TN_REG(rd
, T0
);
6247 check_insn(env
, ctx
, ISA_MIPS32R2
);
6248 GEN_LOAD_REG_TN(T0
, rt
);
6249 GEN_STORE_TN_SRSREG(rd
, T0
);
6253 generate_exception(ctx
, EXCP_RI
);
6257 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6258 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6260 case OPC_J
... OPC_JAL
: /* Jump */
6261 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6262 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6264 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6265 case OPC_BEQL
... OPC_BGTZL
:
6266 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6268 case OPC_LB
... OPC_LWR
: /* Load and stores */
6269 case OPC_SB
... OPC_SW
:
6273 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6276 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6280 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6284 /* Floating point (COP1). */
6289 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6290 save_cpu_state(ctx
, 1);
6291 check_cp1_enabled(ctx
);
6292 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6294 generate_exception_err(ctx
, EXCP_CpU
, 1);
6299 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6300 save_cpu_state(ctx
, 1);
6301 check_cp1_enabled(ctx
);
6302 op1
= MASK_CP1(ctx
->opcode
);
6306 check_insn(env
, ctx
, ISA_MIPS32R2
);
6311 gen_cp1(ctx
, op1
, rt
, rd
);
6313 #ifdef TARGET_MIPS64
6316 check_insn(env
, ctx
, ISA_MIPS3
);
6317 gen_cp1(ctx
, op1
, rt
, rd
);
6323 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6324 (rt
>> 2) & 0x7, imm
<< 2);
6331 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
6336 generate_exception (ctx
, EXCP_RI
);
6340 generate_exception_err(ctx
, EXCP_CpU
, 1);
6350 /* COP2: Not implemented. */
6351 generate_exception_err(ctx
, EXCP_CpU
, 2);
6355 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6356 save_cpu_state(ctx
, 1);
6357 check_cp1_enabled(ctx
);
6358 op1
= MASK_CP3(ctx
->opcode
);
6366 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
6384 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
6388 generate_exception (ctx
, EXCP_RI
);
6392 generate_exception_err(ctx
, EXCP_CpU
, 1);
6396 #ifdef TARGET_MIPS64
6397 /* MIPS64 opcodes */
6399 case OPC_LDL
... OPC_LDR
:
6400 case OPC_SDL
... OPC_SDR
:
6405 check_insn(env
, ctx
, ISA_MIPS3
);
6407 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6409 case OPC_DADDI
... OPC_DADDIU
:
6410 check_insn(env
, ctx
, ISA_MIPS3
);
6412 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6416 check_insn(env
, ctx
, ASE_MIPS16
);
6417 /* MIPS16: Not implemented. */
6419 check_insn(env
, ctx
, ASE_MDMX
);
6420 /* MDMX: Not implemented. */
6421 default: /* Invalid */
6422 MIPS_INVAL("major opcode");
6423 generate_exception(ctx
, EXCP_RI
);
6426 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
6427 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
6428 /* Branches completion */
6429 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
6430 ctx
->bstate
= BS_BRANCH
;
6431 save_cpu_state(ctx
, 0);
6434 /* unconditional branch */
6435 MIPS_DEBUG("unconditional branch");
6436 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6439 /* blikely taken case */
6440 MIPS_DEBUG("blikely branch taken");
6441 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6444 /* Conditional branch */
6445 MIPS_DEBUG("conditional branch");
6448 l1
= gen_new_label();
6450 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6452 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6456 /* unconditional branch to register */
6457 MIPS_DEBUG("branch to register");
6463 MIPS_DEBUG("unknown branch");
6470 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
6474 target_ulong pc_start
;
6475 uint16_t *gen_opc_end
;
6478 if (search_pc
&& loglevel
)
6479 fprintf (logfile
, "search pc %d\n", search_pc
);
6482 gen_opc_ptr
= gen_opc_buf
;
6483 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6484 gen_opparam_ptr
= gen_opparam_buf
;
6489 ctx
.bstate
= BS_NONE
;
6490 /* Restore delay slot state from the tb context. */
6491 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
6492 restore_cpu_state(env
, &ctx
);
6493 #if defined(CONFIG_USER_ONLY)
6496 ctx
.mem_idx
= !((ctx
.hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_UM
);
6499 if (loglevel
& CPU_LOG_TB_CPU
) {
6500 fprintf(logfile
, "------------------------------------------------\n");
6501 /* FIXME: This may print out stale hflags from env... */
6502 cpu_dump_state(env
, logfile
, fprintf
, 0);
6505 #ifdef MIPS_DEBUG_DISAS
6506 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6507 fprintf(logfile
, "\ntb %p super %d cond %04x\n",
6508 tb
, ctx
.mem_idx
, ctx
.hflags
);
6510 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6511 if (env
->nb_breakpoints
> 0) {
6512 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6513 if (env
->breakpoints
[j
] == ctx
.pc
) {
6514 save_cpu_state(&ctx
, 1);
6515 ctx
.bstate
= BS_BRANCH
;
6517 /* Include the breakpoint location or the tb won't
6518 * be flushed when it must be. */
6520 goto done_generating
;
6526 j
= gen_opc_ptr
- gen_opc_buf
;
6530 gen_opc_instr_start
[lj
++] = 0;
6532 gen_opc_pc
[lj
] = ctx
.pc
;
6533 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6534 gen_opc_instr_start
[lj
] = 1;
6536 ctx
.opcode
= ldl_code(ctx
.pc
);
6537 decode_opc(env
, &ctx
);
6540 if (env
->singlestep_enabled
)
6543 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6546 #if defined (MIPS_SINGLE_STEP)
6550 if (env
->singlestep_enabled
) {
6551 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
6554 switch (ctx
.bstate
) {
6556 gen_op_interrupt_restart();
6557 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6560 save_cpu_state(&ctx
, 0);
6561 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6564 gen_op_interrupt_restart();
6574 *gen_opc_ptr
= INDEX_op_end
;
6576 j
= gen_opc_ptr
- gen_opc_buf
;
6579 gen_opc_instr_start
[lj
++] = 0;
6581 tb
->size
= ctx
.pc
- pc_start
;
6584 #if defined MIPS_DEBUG_DISAS
6585 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6586 fprintf(logfile
, "\n");
6588 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6589 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6590 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6591 fprintf(logfile
, "\n");
6593 if (loglevel
& CPU_LOG_TB_OP
) {
6594 fprintf(logfile
, "OP:\n");
6595 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6596 fprintf(logfile
, "\n");
6598 if (loglevel
& CPU_LOG_TB_CPU
) {
6599 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6606 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6608 return gen_intermediate_code_internal(env
, tb
, 0);
6611 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6613 return gen_intermediate_code_internal(env
, tb
, 1);
6616 void fpu_dump_state(CPUState
*env
, FILE *f
,
6617 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6621 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6623 #define printfpr(fp) \
6626 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6627 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6628 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6631 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6632 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6633 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6634 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6635 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6640 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6641 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
6642 get_float_exception_flags(&env
->fpu
->fp_status
));
6643 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
6644 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
6645 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
6646 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6647 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6648 printfpr(&env
->fpu
->fpr
[i
]);
6654 void dump_fpu (CPUState
*env
)
6657 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6658 env
->PC
[env
->current_tc
], env
->HI
[0][env
->current_tc
], env
->LO
[0][env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6659 fpu_dump_state(env
, logfile
, fprintf
, 0);
6663 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6664 /* Debug help: The architecture requires 32bit code to maintain proper
6665 sign-extened values on 64bit machines. */
6667 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6669 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6670 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6675 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
6676 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
6677 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
]))
6678 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
]);
6679 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
]))
6680 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
]);
6681 if (!SIGN_EXT_P(env
->btarget
))
6682 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6684 for (i
= 0; i
< 32; i
++) {
6685 if (!SIGN_EXT_P(env
->gpr
[i
][env
->current_tc
]))
6686 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[i
][env
->current_tc
]);
6689 if (!SIGN_EXT_P(env
->CP0_EPC
))
6690 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6691 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6692 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6696 void cpu_dump_state (CPUState
*env
, FILE *f
,
6697 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6702 cpu_fprintf(f
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6703 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6704 for (i
= 0; i
< 32; i
++) {
6706 cpu_fprintf(f
, "GPR%02d:", i
);
6707 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[i
][env
->current_tc
]);
6709 cpu_fprintf(f
, "\n");
6712 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6713 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6714 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6715 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6716 if (env
->hflags
& MIPS_HFLAG_FPU
)
6717 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6718 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6719 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6723 CPUMIPSState
*cpu_mips_init (void)
6727 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6735 void cpu_reset (CPUMIPSState
*env
)
6737 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6742 #if !defined(CONFIG_USER_ONLY)
6743 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6744 /* If the exception was raised from a delay slot,
6745 * come back to the jump. */
6746 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
6748 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
6751 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
6753 /* SMP not implemented */
6754 env
->CP0_EBase
= 0x80000000;
6755 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6756 /* vectored interrupts not implemented, timer on int 7,
6757 no performance counters. */
6758 env
->CP0_IntCtl
= 0xe0000000;
6762 for (i
= 0; i
< 7; i
++) {
6763 env
->CP0_WatchLo
[i
] = 0;
6764 env
->CP0_WatchHi
[i
] = 0x80000000;
6766 env
->CP0_WatchLo
[7] = 0;
6767 env
->CP0_WatchHi
[7] = 0;
6769 /* Count register increments in debug mode, EJTAG version 1 */
6770 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6772 env
->exception_index
= EXCP_NONE
;
6773 #if defined(CONFIG_USER_ONLY)
6774 env
->hflags
|= MIPS_HFLAG_UM
;
6775 env
->user_mode_only
= 1;
6779 #include "translate_init.c"