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
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL
= (0x00 << 26),
46 OPC_REGIMM
= (0x01 << 26),
47 OPC_CP0
= (0x10 << 26),
48 OPC_CP1
= (0x11 << 26),
49 OPC_CP2
= (0x12 << 26),
50 OPC_CP3
= (0x13 << 26),
51 OPC_SPECIAL2
= (0x1C << 26),
52 OPC_SPECIAL3
= (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI
= (0x08 << 26),
55 OPC_ADDIU
= (0x09 << 26),
56 OPC_SLTI
= (0x0A << 26),
57 OPC_SLTIU
= (0x0B << 26),
58 OPC_ANDI
= (0x0C << 26),
59 OPC_ORI
= (0x0D << 26),
60 OPC_XORI
= (0x0E << 26),
61 OPC_LUI
= (0x0F << 26),
62 OPC_DADDI
= (0x18 << 26),
63 OPC_DADDIU
= (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL
= (0x03 << 26),
67 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL
= (0x14 << 26),
69 OPC_BNE
= (0x05 << 26),
70 OPC_BNEL
= (0x15 << 26),
71 OPC_BLEZ
= (0x06 << 26),
72 OPC_BLEZL
= (0x16 << 26),
73 OPC_BGTZ
= (0x07 << 26),
74 OPC_BGTZL
= (0x17 << 26),
75 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL
= (0x1A << 26),
78 OPC_LDR
= (0x1B << 26),
79 OPC_LB
= (0x20 << 26),
80 OPC_LH
= (0x21 << 26),
81 OPC_LWL
= (0x22 << 26),
82 OPC_LW
= (0x23 << 26),
83 OPC_LBU
= (0x24 << 26),
84 OPC_LHU
= (0x25 << 26),
85 OPC_LWR
= (0x26 << 26),
86 OPC_LWU
= (0x27 << 26),
87 OPC_SB
= (0x28 << 26),
88 OPC_SH
= (0x29 << 26),
89 OPC_SWL
= (0x2A << 26),
90 OPC_SW
= (0x2B << 26),
91 OPC_SDL
= (0x2C << 26),
92 OPC_SDR
= (0x2D << 26),
93 OPC_SWR
= (0x2E << 26),
94 OPC_LL
= (0x30 << 26),
95 OPC_LLD
= (0x34 << 26),
96 OPC_LD
= (0x37 << 26),
97 OPC_SC
= (0x38 << 26),
98 OPC_SCD
= (0x3C << 26),
99 OPC_SD
= (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1
= (0x31 << 26),
102 OPC_LWC2
= (0x32 << 26),
103 OPC_LDC1
= (0x35 << 26),
104 OPC_LDC2
= (0x36 << 26),
105 OPC_SWC1
= (0x39 << 26),
106 OPC_SWC2
= (0x3A << 26),
107 OPC_SDC1
= (0x3D << 26),
108 OPC_SDC2
= (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX
= (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE
= (0x2F << 26),
113 OPC_PREF
= (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL
= 0x00 | OPC_SPECIAL
,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
128 OPC_SRA
= 0x03 | OPC_SPECIAL
,
129 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
130 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
131 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
132 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
133 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
134 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
135 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
136 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
137 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
138 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
139 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
140 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
141 /* Multiplication / division */
142 OPC_MULT
= 0x18 | OPC_SPECIAL
,
143 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
144 OPC_DIV
= 0x1A | OPC_SPECIAL
,
145 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
146 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
147 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
148 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
149 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD
= 0x20 | OPC_SPECIAL
,
152 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
153 OPC_SUB
= 0x22 | OPC_SPECIAL
,
154 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
155 OPC_AND
= 0x24 | OPC_SPECIAL
,
156 OPC_OR
= 0x25 | OPC_SPECIAL
,
157 OPC_XOR
= 0x26 | OPC_SPECIAL
,
158 OPC_NOR
= 0x27 | OPC_SPECIAL
,
159 OPC_SLT
= 0x2A | OPC_SPECIAL
,
160 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
161 OPC_DADD
= 0x2C | OPC_SPECIAL
,
162 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
163 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
164 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
166 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
167 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
169 OPC_TGE
= 0x30 | OPC_SPECIAL
,
170 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
171 OPC_TLT
= 0x32 | OPC_SPECIAL
,
172 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
173 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
174 OPC_TNE
= 0x36 | OPC_SPECIAL
,
175 /* HI / LO registers load & stores */
176 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
177 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
178 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
179 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
180 /* Conditional moves */
181 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
182 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
184 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
187 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
188 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
189 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
190 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
191 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
193 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
194 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
195 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
196 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
197 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
198 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
199 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
207 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
208 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
209 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
210 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
211 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
213 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
214 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
215 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
216 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
217 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
218 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
219 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
227 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
228 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
229 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
230 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
231 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
232 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
233 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
234 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
235 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
236 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
237 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
238 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
239 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
240 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
249 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
250 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
251 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
252 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
254 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
255 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
256 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
257 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
259 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
267 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
268 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
269 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
270 OPC_INS
= 0x04 | OPC_SPECIAL3
,
271 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
272 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
273 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
274 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
275 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
276 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
277 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
278 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
286 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
287 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
295 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
303 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
304 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
305 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
306 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
307 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
308 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
309 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
310 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
311 OPC_C0
= (0x10 << 21) | OPC_CP0
,
312 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
313 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
321 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
322 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
323 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
324 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
325 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR
= 0x01 | OPC_C0
,
333 OPC_TLBWI
= 0x02 | OPC_C0
,
334 OPC_TLBWR
= 0x06 | OPC_C0
,
335 OPC_TLBP
= 0x08 | OPC_C0
,
336 OPC_RFE
= 0x10 | OPC_C0
,
337 OPC_ERET
= 0x18 | OPC_C0
,
338 OPC_DERET
= 0x1F | OPC_C0
,
339 OPC_WAIT
= 0x20 | OPC_C0
,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
347 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
348 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
349 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
350 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
351 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
352 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
353 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
354 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
355 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
356 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
357 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
358 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
359 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
360 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
361 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
362 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
371 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
372 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
373 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
377 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
378 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
382 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
383 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
390 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
391 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
392 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
393 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
394 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
395 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
396 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
397 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1
= 0x00 | OPC_CP3
,
404 OPC_LDXC1
= 0x01 | OPC_CP3
,
405 OPC_LUXC1
= 0x05 | OPC_CP3
,
406 OPC_SWXC1
= 0x08 | OPC_CP3
,
407 OPC_SDXC1
= 0x09 | OPC_CP3
,
408 OPC_SUXC1
= 0x0D | OPC_CP3
,
409 OPC_PREFX
= 0x0F | OPC_CP3
,
410 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
411 OPC_MADD_S
= 0x20 | OPC_CP3
,
412 OPC_MADD_D
= 0x21 | OPC_CP3
,
413 OPC_MADD_PS
= 0x26 | OPC_CP3
,
414 OPC_MSUB_S
= 0x28 | OPC_CP3
,
415 OPC_MSUB_D
= 0x29 | OPC_CP3
,
416 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
417 OPC_NMADD_S
= 0x30 | OPC_CP3
,
418 OPC_NMADD_D
= 0x31 | OPC_CP3
,
419 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
420 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
421 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
422 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
425 /* global register indices */
426 static TCGv cpu_env
, current_tc_gprs
, current_tc_hi
, cpu_T
[2];
428 static inline void tcg_gen_helper_0_1i(void *func
, TCGv arg
)
430 TCGv t
= tcg_const_i32(arg
);
432 tcg_gen_helper_0_1(func
, t
);
436 static inline void tcg_gen_helper_0_2ii(void *func
, TCGv arg1
, TCGv arg2
)
438 TCGv t1
= tcg_const_i32(arg1
);
439 TCGv t2
= tcg_const_i32(arg2
);
441 tcg_gen_helper_0_2(func
, t1
, t2
);
446 typedef struct DisasContext
{
447 struct TranslationBlock
*tb
;
448 target_ulong pc
, saved_pc
;
451 /* Routine used to access memory */
453 uint32_t hflags
, saved_hflags
;
455 target_ulong btarget
;
459 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
460 * exception condition
462 BS_STOP
= 1, /* We want to stop translation for any reason */
463 BS_BRANCH
= 2, /* We reached a branch condition */
464 BS_EXCP
= 3, /* We reached an exception condition */
467 static const char *regnames
[] =
468 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
469 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
470 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
471 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
473 static const char *fregnames
[] =
474 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
475 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
476 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
477 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
479 #ifdef MIPS_DEBUG_DISAS
480 #define MIPS_DEBUG(fmt, args...) \
482 if (loglevel & CPU_LOG_TB_IN_ASM) { \
483 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
484 ctx->pc, ctx->opcode , ##args); \
488 #define MIPS_DEBUG(fmt, args...) do { } while(0)
491 #define MIPS_INVAL(op) \
493 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
494 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
497 /* General purpose registers moves. */
498 static inline void gen_load_gpr (TCGv t
, int reg
)
501 tcg_gen_movi_tl(t
, 0);
503 tcg_gen_ld_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
506 static inline void gen_store_gpr (TCGv t
, int reg
)
509 tcg_gen_st_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
512 /* Moves to/from HI and LO registers. */
513 static inline void gen_load_LO (TCGv t
, int reg
)
515 tcg_gen_ld_tl(t
, current_tc_hi
,
516 offsetof(CPUState
, LO
)
517 - offsetof(CPUState
, HI
)
518 + sizeof(target_ulong
) * reg
);
521 static inline void gen_store_LO (TCGv t
, int reg
)
523 tcg_gen_st_tl(t
, current_tc_hi
,
524 offsetof(CPUState
, LO
)
525 - offsetof(CPUState
, HI
)
526 + sizeof(target_ulong
) * reg
);
529 static inline void gen_load_HI (TCGv t
, int reg
)
531 tcg_gen_ld_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
534 static inline void gen_store_HI (TCGv t
, int reg
)
536 tcg_gen_st_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
539 /* Moves to/from shadow registers. */
540 static inline void gen_load_srsgpr (TCGv t
, int reg
)
543 tcg_gen_movi_tl(t
, 0);
545 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
547 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
548 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
549 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
550 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
551 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
553 tcg_gen_ld_tl(t
, r_tmp
, sizeof(target_ulong
) * reg
);
554 tcg_temp_free(r_tmp
);
558 static inline void gen_store_srsgpr (TCGv t
, int reg
)
561 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
563 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
564 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
565 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
566 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
567 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
569 tcg_gen_st_tl(t
, r_tmp
, sizeof(target_ulong
) * reg
);
570 tcg_temp_free(r_tmp
);
574 /* Floating point register moves. */
575 #define FGEN32(func, NAME) \
576 static GenOpFunc *NAME ## _table [32] = { \
577 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
578 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
579 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
580 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
581 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
582 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
583 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
584 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
586 static always_inline void func(int n) \
588 NAME ## _table[n](); \
591 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
592 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
594 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
595 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
597 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
598 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
600 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
601 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
603 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
604 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
606 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
607 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
609 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
610 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
612 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
613 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
615 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
616 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
618 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
620 glue(gen_op_load_fpr_, FTn)(Fn); \
623 #define GEN_STORE_FTN_FREG(Fn, FTn) \
625 glue(gen_op_store_fpr_, FTn)(Fn); \
628 #define FOP_CONDS(type, fmt) \
629 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
630 gen_op_cmp ## type ## _ ## fmt ## _f, \
631 gen_op_cmp ## type ## _ ## fmt ## _un, \
632 gen_op_cmp ## type ## _ ## fmt ## _eq, \
633 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
634 gen_op_cmp ## type ## _ ## fmt ## _olt, \
635 gen_op_cmp ## type ## _ ## fmt ## _ult, \
636 gen_op_cmp ## type ## _ ## fmt ## _ole, \
637 gen_op_cmp ## type ## _ ## fmt ## _ule, \
638 gen_op_cmp ## type ## _ ## fmt ## _sf, \
639 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
640 gen_op_cmp ## type ## _ ## fmt ## _seq, \
641 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
642 gen_op_cmp ## type ## _ ## fmt ## _lt, \
643 gen_op_cmp ## type ## _ ## fmt ## _nge, \
644 gen_op_cmp ## type ## _ ## fmt ## _le, \
645 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
647 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
649 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
660 #define OP_COND(name, cond) \
661 void glue(gen_op_, name) (void) \
663 int l1 = gen_new_label(); \
664 int l2 = gen_new_label(); \
666 tcg_gen_brcond_tl(cond, cpu_T[0], cpu_T[1], l1); \
667 tcg_gen_movi_tl(cpu_T[0], 0); \
670 tcg_gen_movi_tl(cpu_T[0], 1); \
673 OP_COND(eq
, TCG_COND_EQ
);
674 OP_COND(ne
, TCG_COND_NE
);
675 OP_COND(ge
, TCG_COND_GE
);
676 OP_COND(geu
, TCG_COND_GEU
);
677 OP_COND(lt
, TCG_COND_LT
);
678 OP_COND(ltu
, TCG_COND_LTU
);
681 #define OP_CONDI(name, cond) \
682 void glue(gen_op_, name) (target_ulong val) \
684 int l1 = gen_new_label(); \
685 int l2 = gen_new_label(); \
687 tcg_gen_brcondi_tl(cond, cpu_T[0], val, l1); \
688 tcg_gen_movi_tl(cpu_T[0], 0); \
691 tcg_gen_movi_tl(cpu_T[0], 1); \
694 OP_CONDI(lti
, TCG_COND_LT
);
695 OP_CONDI(ltiu
, TCG_COND_LTU
);
698 #define OP_CONDZ(name, cond) \
699 void glue(gen_op_, name) (void) \
701 int l1 = gen_new_label(); \
702 int l2 = gen_new_label(); \
704 tcg_gen_brcondi_tl(cond, cpu_T[0], 0, l1); \
705 tcg_gen_movi_tl(cpu_T[0], 0); \
708 tcg_gen_movi_tl(cpu_T[0], 1); \
711 OP_CONDZ(gez
, TCG_COND_GE
);
712 OP_CONDZ(gtz
, TCG_COND_GT
);
713 OP_CONDZ(lez
, TCG_COND_LE
);
714 OP_CONDZ(ltz
, TCG_COND_LT
);
717 static inline void gen_save_pc(target_ulong pc
)
719 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
720 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
721 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
722 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
724 tcg_gen_movi_tl(r_tmp
, pc
);
725 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
726 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
727 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
728 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
729 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
730 tcg_temp_free(r_tc_off
);
731 tcg_temp_free(r_tc_off_ptr
);
732 tcg_temp_free(r_ptr
);
733 tcg_temp_free(r_tmp
);
736 static inline void gen_breg_pc(void)
738 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
739 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
740 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
741 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
743 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
744 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
745 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
746 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
747 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
748 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
749 tcg_temp_free(r_tc_off
);
750 tcg_temp_free(r_tc_off_ptr
);
751 tcg_temp_free(r_ptr
);
752 tcg_temp_free(r_tmp
);
755 static inline void gen_save_btarget(target_ulong btarget
)
757 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
759 tcg_gen_movi_tl(r_tmp
, btarget
);
760 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
761 tcg_temp_free(r_tmp
);
764 static always_inline
void gen_save_breg_target(int reg
)
766 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
768 gen_load_gpr(r_tmp
, reg
);
769 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
770 tcg_temp_free(r_tmp
);
773 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
775 #if defined MIPS_DEBUG_DISAS
776 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
777 fprintf(logfile
, "hflags %08x saved %08x\n",
778 ctx
->hflags
, ctx
->saved_hflags
);
781 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
782 gen_save_pc(ctx
->pc
);
783 ctx
->saved_pc
= ctx
->pc
;
785 if (ctx
->hflags
!= ctx
->saved_hflags
) {
786 gen_op_save_state(ctx
->hflags
);
787 ctx
->saved_hflags
= ctx
->hflags
;
788 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
794 gen_save_btarget(ctx
->btarget
);
800 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
802 ctx
->saved_hflags
= ctx
->hflags
;
803 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
809 ctx
->btarget
= env
->btarget
;
814 static always_inline
void
815 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
817 save_cpu_state(ctx
, 1);
818 tcg_gen_helper_0_2ii(do_raise_exception_err
, excp
, err
);
819 tcg_gen_helper_0_0(do_interrupt_restart
);
823 static always_inline
void
824 generate_exception (DisasContext
*ctx
, int excp
)
826 save_cpu_state(ctx
, 1);
827 tcg_gen_helper_0_1i(do_raise_exception
, excp
);
828 tcg_gen_helper_0_0(do_interrupt_restart
);
832 /* Addresses computation */
833 static inline void gen_op_addr_add (void)
835 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
837 #if defined(TARGET_MIPS64)
838 /* For compatibility with 32-bit code, data reference in user mode
839 with Status_UX = 0 should be casted to 32-bit and sign extended.
840 See the MIPS64 PRA manual, section 4.10. */
842 int l1
= gen_new_label();
845 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
847 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
848 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
849 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, MIPS_HFLAG_UM
, l1
);
852 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
854 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
855 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
856 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, 0, l1
);
858 tcg_gen_ext32s_i64(cpu_T
[0], cpu_T
[0]);
864 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
866 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
867 generate_exception_err(ctx
, EXCP_CpU
, 1);
870 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
872 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
873 generate_exception_err(ctx
, EXCP_CpU
, 1);
876 /* Verify that the processor is running with COP1X instructions enabled.
877 This is associated with the nabla symbol in the MIPS32 and MIPS64
880 static always_inline
void check_cop1x(DisasContext
*ctx
)
882 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
883 generate_exception(ctx
, EXCP_RI
);
886 /* Verify that the processor is running with 64-bit floating-point
887 operations enabled. */
889 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
891 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
892 generate_exception(ctx
, EXCP_RI
);
896 * Verify if floating point register is valid; an operation is not defined
897 * if bit 0 of any register specification is set and the FR bit in the
898 * Status register equals zero, since the register numbers specify an
899 * even-odd pair of adjacent coprocessor general registers. When the FR bit
900 * in the Status register equals one, both even and odd register numbers
901 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
903 * Multiple 64 bit wide registers can be checked by calling
904 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
906 void check_cp1_registers(DisasContext
*ctx
, int regs
)
908 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
909 generate_exception(ctx
, EXCP_RI
);
912 /* This code generates a "reserved instruction" exception if the
913 CPU does not support the instruction set corresponding to flags. */
914 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
916 if (unlikely(!(env
->insn_flags
& flags
)))
917 generate_exception(ctx
, EXCP_RI
);
920 /* This code generates a "reserved instruction" exception if 64-bit
921 instructions are not enabled. */
922 static always_inline
void check_mips_64(DisasContext
*ctx
)
924 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
925 generate_exception(ctx
, EXCP_RI
);
928 /* load/store instructions. */
929 #if defined(CONFIG_USER_ONLY)
930 #define op_ldst(name) gen_op_##name##_raw()
931 #define OP_LD_TABLE(width)
932 #define OP_ST_TABLE(width)
934 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
935 #define OP_LD_TABLE(width) \
936 static GenOpFunc *gen_op_l##width[] = { \
937 &gen_op_l##width##_kernel, \
938 &gen_op_l##width##_super, \
939 &gen_op_l##width##_user, \
941 #define OP_ST_TABLE(width) \
942 static GenOpFunc *gen_op_s##width[] = { \
943 &gen_op_s##width##_kernel, \
944 &gen_op_s##width##_super, \
945 &gen_op_s##width##_user, \
949 #if defined(TARGET_MIPS64)
966 #define OP_LD(insn,fname) \
967 void inline op_ldst_##insn(DisasContext *ctx) \
969 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
976 #if defined(TARGET_MIPS64)
982 #define OP_ST(insn,fname) \
983 void inline op_ldst_##insn(DisasContext *ctx) \
985 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
990 #if defined(TARGET_MIPS64)
995 #define OP_LD_ATOMIC(insn,fname) \
996 void inline op_ldst_##insn(DisasContext *ctx) \
998 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]); \
999 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
1000 tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1002 OP_LD_ATOMIC(ll
,ld32s
);
1003 #if defined(TARGET_MIPS64)
1004 OP_LD_ATOMIC(lld
,ld64
);
1008 #define OP_ST_ATOMIC(insn,fname,almask) \
1009 void inline op_ldst_##insn(DisasContext *ctx) \
1011 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1012 int l1 = gen_new_label(); \
1013 int l2 = gen_new_label(); \
1014 int l3 = gen_new_label(); \
1016 tcg_gen_andi_tl(r_tmp, cpu_T[0], almask); \
1017 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1018 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1019 generate_exception(ctx, EXCP_AdES); \
1020 gen_set_label(l1); \
1021 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1022 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], r_tmp, l2); \
1023 tcg_temp_free(r_tmp); \
1024 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1025 tcg_gen_movi_tl(cpu_T[0], 1); \
1027 gen_set_label(l2); \
1028 tcg_gen_movi_tl(cpu_T[0], 0); \
1029 gen_set_label(l3); \
1031 OP_ST_ATOMIC(sc
,st32
,0x3);
1032 #if defined(TARGET_MIPS64)
1033 OP_ST_ATOMIC(scd
,st64
,0x7);
1037 void inline op_ldst_lwc1(DisasContext
*ctx
)
1042 void inline op_ldst_ldc1(DisasContext
*ctx
)
1047 void inline op_ldst_swc1(DisasContext
*ctx
)
1052 void inline op_ldst_sdc1(DisasContext
*ctx
)
1057 /* Load and store */
1058 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1059 int base
, int16_t offset
)
1061 const char *opn
= "ldst";
1064 tcg_gen_movi_tl(cpu_T
[0], offset
);
1065 } else if (offset
== 0) {
1066 gen_load_gpr(cpu_T
[0], base
);
1068 gen_load_gpr(cpu_T
[0], base
);
1069 tcg_gen_movi_tl(cpu_T
[1], offset
);
1072 /* Don't do NOP if destination is zero: we must perform the actual
1075 #if defined(TARGET_MIPS64)
1078 gen_store_gpr(cpu_T
[0], rt
);
1083 gen_store_gpr(cpu_T
[0], rt
);
1088 gen_store_gpr(cpu_T
[0], rt
);
1092 gen_load_gpr(cpu_T
[1], rt
);
1097 save_cpu_state(ctx
, 1);
1098 gen_load_gpr(cpu_T
[1], rt
);
1100 gen_store_gpr(cpu_T
[0], rt
);
1104 gen_load_gpr(cpu_T
[1], rt
);
1106 gen_store_gpr(cpu_T
[1], rt
);
1110 gen_load_gpr(cpu_T
[1], rt
);
1115 gen_load_gpr(cpu_T
[1], rt
);
1117 gen_store_gpr(cpu_T
[1], rt
);
1121 gen_load_gpr(cpu_T
[1], rt
);
1128 gen_store_gpr(cpu_T
[0], rt
);
1132 gen_load_gpr(cpu_T
[1], rt
);
1138 gen_store_gpr(cpu_T
[0], rt
);
1142 gen_load_gpr(cpu_T
[1], rt
);
1148 gen_store_gpr(cpu_T
[0], rt
);
1153 gen_store_gpr(cpu_T
[0], rt
);
1157 gen_load_gpr(cpu_T
[1], rt
);
1163 gen_store_gpr(cpu_T
[0], rt
);
1167 gen_load_gpr(cpu_T
[1], rt
);
1169 gen_store_gpr(cpu_T
[1], rt
);
1173 gen_load_gpr(cpu_T
[1], rt
);
1178 gen_load_gpr(cpu_T
[1], rt
);
1180 gen_store_gpr(cpu_T
[1], rt
);
1184 gen_load_gpr(cpu_T
[1], rt
);
1190 gen_store_gpr(cpu_T
[0], rt
);
1194 save_cpu_state(ctx
, 1);
1195 gen_load_gpr(cpu_T
[1], rt
);
1197 gen_store_gpr(cpu_T
[0], rt
);
1202 generate_exception(ctx
, EXCP_RI
);
1205 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1208 /* Load and store */
1209 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1210 int base
, int16_t offset
)
1212 const char *opn
= "flt_ldst";
1215 tcg_gen_movi_tl(cpu_T
[0], offset
);
1216 } else if (offset
== 0) {
1217 gen_load_gpr(cpu_T
[0], base
);
1219 gen_load_gpr(cpu_T
[0], base
);
1220 tcg_gen_movi_tl(cpu_T
[1], offset
);
1223 /* Don't do NOP if destination is zero: we must perform the actual
1228 GEN_STORE_FTN_FREG(ft
, WT0
);
1232 GEN_LOAD_FREG_FTN(WT0
, ft
);
1238 GEN_STORE_FTN_FREG(ft
, DT0
);
1242 GEN_LOAD_FREG_FTN(DT0
, ft
);
1248 generate_exception(ctx
, EXCP_RI
);
1251 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1254 /* Arithmetic with immediate operand */
1255 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1256 int rt
, int rs
, int16_t imm
)
1259 const char *opn
= "imm arith";
1261 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1262 /* If no destination, treat it as a NOP.
1263 For addi, we must generate the overflow exception when needed. */
1267 uimm
= (uint16_t)imm
;
1271 #if defined(TARGET_MIPS64)
1277 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1278 tcg_gen_movi_tl(cpu_T
[1], uimm
);
1283 gen_load_gpr(cpu_T
[0], rs
);
1286 tcg_gen_movi_tl(cpu_T
[0], imm
<< 16);
1291 #if defined(TARGET_MIPS64)
1300 gen_load_gpr(cpu_T
[0], rs
);
1306 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1307 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1308 int l1
= gen_new_label();
1310 save_cpu_state(ctx
, 1);
1311 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1312 tcg_gen_addi_tl(cpu_T
[0], r_tmp1
, uimm
);
1314 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1315 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1316 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1317 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1318 tcg_temp_free(r_tmp2
);
1319 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1320 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1321 tcg_temp_free(r_tmp1
);
1322 /* operands of same sign, result different sign */
1323 generate_exception(ctx
, EXCP_OVERFLOW
);
1326 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1331 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1332 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1333 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1336 #if defined(TARGET_MIPS64)
1339 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1340 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1341 int l1
= gen_new_label();
1343 save_cpu_state(ctx
, 1);
1344 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1345 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1347 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1348 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1349 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1350 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1351 tcg_temp_free(r_tmp2
);
1352 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1353 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1354 tcg_temp_free(r_tmp1
);
1355 /* operands of same sign, result different sign */
1356 generate_exception(ctx
, EXCP_OVERFLOW
);
1362 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1375 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1379 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1383 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1390 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1391 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1392 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1396 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1397 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1398 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1402 switch ((ctx
->opcode
>> 21) & 0x1f) {
1404 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1405 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1406 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1410 /* rotr is decoded as srl on non-R2 CPUs */
1411 if (env
->insn_flags
& ISA_MIPS32R2
) {
1413 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1414 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1416 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1417 tcg_gen_movi_i32(r_tmp2
, 0x20);
1418 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1419 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1420 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1421 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1422 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
1423 tcg_temp_free(r_tmp1
);
1424 tcg_temp_free(r_tmp2
);
1428 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1429 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1430 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1435 MIPS_INVAL("invalid srl flag");
1436 generate_exception(ctx
, EXCP_RI
);
1440 #if defined(TARGET_MIPS64)
1442 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1446 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1450 switch ((ctx
->opcode
>> 21) & 0x1f) {
1452 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1456 /* drotr is decoded as dsrl on non-R2 CPUs */
1457 if (env
->insn_flags
& ISA_MIPS32R2
) {
1459 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1461 tcg_gen_movi_tl(r_tmp1
, 0x40);
1462 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1463 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1464 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1465 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1466 tcg_temp_free(r_tmp1
);
1470 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1475 MIPS_INVAL("invalid dsrl flag");
1476 generate_exception(ctx
, EXCP_RI
);
1481 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1485 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1489 switch ((ctx
->opcode
>> 21) & 0x1f) {
1491 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1495 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1496 if (env
->insn_flags
& ISA_MIPS32R2
) {
1497 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1498 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1500 tcg_gen_movi_tl(r_tmp1
, 0x40);
1501 tcg_gen_movi_tl(r_tmp2
, 32);
1502 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1503 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1504 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1505 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], r_tmp2
);
1506 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1507 tcg_temp_free(r_tmp1
);
1508 tcg_temp_free(r_tmp2
);
1511 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1516 MIPS_INVAL("invalid dsrl32 flag");
1517 generate_exception(ctx
, EXCP_RI
);
1524 generate_exception(ctx
, EXCP_RI
);
1527 gen_store_gpr(cpu_T
[0], rt
);
1528 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1532 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1533 int rd
, int rs
, int rt
)
1535 const char *opn
= "arith";
1537 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1538 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1539 /* If no destination, treat it as a NOP.
1540 For add & sub, we must generate the overflow exception when needed. */
1544 gen_load_gpr(cpu_T
[0], rs
);
1545 /* Specialcase the conventional move operation. */
1546 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1547 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1548 gen_store_gpr(cpu_T
[0], rd
);
1551 gen_load_gpr(cpu_T
[1], rt
);
1555 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1556 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1557 int l1
= gen_new_label();
1559 save_cpu_state(ctx
, 1);
1560 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1561 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1562 tcg_gen_add_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1564 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1565 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1566 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1567 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1568 tcg_temp_free(r_tmp2
);
1569 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1570 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1571 tcg_temp_free(r_tmp1
);
1572 /* operands of same sign, result different sign */
1573 generate_exception(ctx
, EXCP_OVERFLOW
);
1576 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1581 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1582 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1583 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1584 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1589 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1590 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1591 int l1
= gen_new_label();
1593 save_cpu_state(ctx
, 1);
1594 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1595 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1596 tcg_gen_sub_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1598 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1599 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1600 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1601 tcg_temp_free(r_tmp2
);
1602 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1603 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1604 tcg_temp_free(r_tmp1
);
1605 /* operands of different sign, first operand and result different sign */
1606 generate_exception(ctx
, EXCP_OVERFLOW
);
1609 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1614 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1615 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1616 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1617 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1620 #if defined(TARGET_MIPS64)
1623 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1624 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1625 int l1
= gen_new_label();
1627 save_cpu_state(ctx
, 1);
1628 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1629 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1631 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1632 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1633 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1634 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1635 tcg_temp_free(r_tmp2
);
1636 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1637 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1638 tcg_temp_free(r_tmp1
);
1639 /* operands of same sign, result different sign */
1640 generate_exception(ctx
, EXCP_OVERFLOW
);
1646 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1651 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1652 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1653 int l1
= gen_new_label();
1655 save_cpu_state(ctx
, 1);
1656 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1657 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1659 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1660 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1661 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1662 tcg_temp_free(r_tmp2
);
1663 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1664 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1665 tcg_temp_free(r_tmp1
);
1666 /* operands of different sign, first operand and result different sign */
1667 generate_exception(ctx
, EXCP_OVERFLOW
);
1673 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1686 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1690 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1691 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
1695 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1699 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1703 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1704 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1705 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1706 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1711 int l1
= gen_new_label();
1713 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1714 gen_store_gpr(cpu_T
[0], rd
);
1721 int l1
= gen_new_label();
1723 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[1], 0, l1
);
1724 gen_store_gpr(cpu_T
[0], rd
);
1730 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1731 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1732 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1733 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1734 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1738 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1739 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1740 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1741 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1745 switch ((ctx
->opcode
>> 6) & 0x1f) {
1747 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1748 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1749 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1750 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1754 /* rotrv is decoded as srlv on non-R2 CPUs */
1755 if (env
->insn_flags
& ISA_MIPS32R2
) {
1756 int l1
= gen_new_label();
1757 int l2
= gen_new_label();
1759 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1760 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
1762 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1763 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1764 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1766 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1767 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1768 tcg_gen_movi_i32(r_tmp3
, 0x20);
1769 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1770 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1771 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1772 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1773 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
1774 tcg_temp_free(r_tmp1
);
1775 tcg_temp_free(r_tmp2
);
1776 tcg_temp_free(r_tmp3
);
1780 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1784 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1785 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1786 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1787 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1792 MIPS_INVAL("invalid srlv flag");
1793 generate_exception(ctx
, EXCP_RI
);
1797 #if defined(TARGET_MIPS64)
1799 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1800 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1804 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1805 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1809 switch ((ctx
->opcode
>> 6) & 0x1f) {
1811 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1812 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1816 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1817 if (env
->insn_flags
& ISA_MIPS32R2
) {
1818 int l1
= gen_new_label();
1819 int l2
= gen_new_label();
1821 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1822 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
1824 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1826 tcg_gen_movi_tl(r_tmp1
, 0x40);
1827 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1828 tcg_gen_shl_tl(r_tmp1
, cpu_T
[1], r_tmp1
);
1829 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1830 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1831 tcg_temp_free(r_tmp1
);
1835 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1839 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1840 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1845 MIPS_INVAL("invalid dsrlv flag");
1846 generate_exception(ctx
, EXCP_RI
);
1853 generate_exception(ctx
, EXCP_RI
);
1856 gen_store_gpr(cpu_T
[0], rd
);
1858 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1861 /* Arithmetic on HI/LO registers */
1862 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1864 const char *opn
= "hilo";
1866 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1873 gen_load_HI(cpu_T
[0], 0);
1874 gen_store_gpr(cpu_T
[0], reg
);
1878 gen_load_LO(cpu_T
[0], 0);
1879 gen_store_gpr(cpu_T
[0], reg
);
1883 gen_load_gpr(cpu_T
[0], reg
);
1884 gen_store_HI(cpu_T
[0], 0);
1888 gen_load_gpr(cpu_T
[0], reg
);
1889 gen_store_LO(cpu_T
[0], 0);
1894 generate_exception(ctx
, EXCP_RI
);
1897 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1900 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1903 const char *opn
= "mul/div";
1905 gen_load_gpr(cpu_T
[0], rs
);
1906 gen_load_gpr(cpu_T
[1], rt
);
1910 int l1
= gen_new_label();
1912 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1913 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1914 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1916 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1917 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1918 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
1920 tcg_gen_ext_tl_i64(r_tmp1
, cpu_T
[0]);
1921 tcg_gen_ext_tl_i64(r_tmp2
, cpu_T
[1]);
1922 tcg_gen_div_i64(r_tmp3
, r_tmp1
, r_tmp2
);
1923 tcg_gen_rem_i64(r_tmp2
, r_tmp1
, r_tmp2
);
1924 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp3
);
1925 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp2
);
1926 tcg_temp_free(r_tmp1
);
1927 tcg_temp_free(r_tmp2
);
1928 tcg_temp_free(r_tmp3
);
1929 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1930 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1931 gen_store_LO(cpu_T
[0], 0);
1932 gen_store_HI(cpu_T
[1], 0);
1940 int l1
= gen_new_label();
1942 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1943 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1945 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1946 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1947 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1949 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1950 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1951 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1952 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1953 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp3
);
1954 tcg_gen_ext_i32_tl(cpu_T
[1], r_tmp1
);
1955 tcg_temp_free(r_tmp1
);
1956 tcg_temp_free(r_tmp2
);
1957 tcg_temp_free(r_tmp3
);
1958 gen_store_LO(cpu_T
[0], 0);
1959 gen_store_HI(cpu_T
[1], 0);
1973 #if defined(TARGET_MIPS64)
1976 int l1
= gen_new_label();
1978 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1980 int l2
= gen_new_label();
1982 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], -1LL << 63, l2
);
1983 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[1], -1LL, l2
);
1985 tcg_gen_movi_tl(cpu_T
[1], 0);
1986 gen_store_LO(cpu_T
[0], 0);
1987 gen_store_HI(cpu_T
[1], 0);
1992 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1993 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1995 tcg_gen_div_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
1996 tcg_gen_rem_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1997 gen_store_LO(r_tmp1
, 0);
1998 gen_store_HI(r_tmp2
, 0);
1999 tcg_temp_free(r_tmp1
);
2000 tcg_temp_free(r_tmp2
);
2009 int l1
= gen_new_label();
2011 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
2013 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2014 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2016 tcg_gen_divu_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
2017 tcg_gen_remu_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
2018 tcg_temp_free(r_tmp1
);
2019 tcg_temp_free(r_tmp2
);
2020 gen_store_LO(r_tmp1
, 0);
2021 gen_store_HI(r_tmp2
, 0);
2054 generate_exception(ctx
, EXCP_RI
);
2057 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2060 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2061 int rd
, int rs
, int rt
)
2063 const char *opn
= "mul vr54xx";
2065 gen_load_gpr(cpu_T
[0], rs
);
2066 gen_load_gpr(cpu_T
[1], rt
);
2069 case OPC_VR54XX_MULS
:
2073 case OPC_VR54XX_MULSU
:
2077 case OPC_VR54XX_MACC
:
2081 case OPC_VR54XX_MACCU
:
2085 case OPC_VR54XX_MSAC
:
2089 case OPC_VR54XX_MSACU
:
2093 case OPC_VR54XX_MULHI
:
2097 case OPC_VR54XX_MULHIU
:
2101 case OPC_VR54XX_MULSHI
:
2105 case OPC_VR54XX_MULSHIU
:
2109 case OPC_VR54XX_MACCHI
:
2113 case OPC_VR54XX_MACCHIU
:
2117 case OPC_VR54XX_MSACHI
:
2121 case OPC_VR54XX_MSACHIU
:
2126 MIPS_INVAL("mul vr54xx");
2127 generate_exception(ctx
, EXCP_RI
);
2130 gen_store_gpr(cpu_T
[0], rd
);
2131 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2134 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2137 const char *opn
= "CLx";
2143 gen_load_gpr(cpu_T
[0], rs
);
2146 tcg_gen_helper_0_0(do_clo
);
2150 tcg_gen_helper_0_0(do_clz
);
2153 #if defined(TARGET_MIPS64)
2155 tcg_gen_helper_0_0(do_dclo
);
2159 tcg_gen_helper_0_0(do_dclz
);
2165 generate_exception(ctx
, EXCP_RI
);
2168 gen_store_gpr(cpu_T
[0], rd
);
2169 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2173 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2174 int rs
, int rt
, int16_t imm
)
2179 /* Load needed operands */
2187 /* Compare two registers */
2189 gen_load_gpr(cpu_T
[0], rs
);
2190 gen_load_gpr(cpu_T
[1], rt
);
2200 /* Compare register to immediate */
2201 if (rs
!= 0 || imm
!= 0) {
2202 gen_load_gpr(cpu_T
[0], rs
);
2203 tcg_gen_movi_tl(cpu_T
[1], (int32_t)imm
);
2210 case OPC_TEQ
: /* rs == rs */
2211 case OPC_TEQI
: /* r0 == 0 */
2212 case OPC_TGE
: /* rs >= rs */
2213 case OPC_TGEI
: /* r0 >= 0 */
2214 case OPC_TGEU
: /* rs >= rs unsigned */
2215 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2217 tcg_gen_movi_tl(cpu_T
[0], 1);
2219 case OPC_TLT
: /* rs < rs */
2220 case OPC_TLTI
: /* r0 < 0 */
2221 case OPC_TLTU
: /* rs < rs unsigned */
2222 case OPC_TLTIU
: /* r0 < 0 unsigned */
2223 case OPC_TNE
: /* rs != rs */
2224 case OPC_TNEI
: /* r0 != 0 */
2225 /* Never trap: treat as NOP. */
2229 generate_exception(ctx
, EXCP_RI
);
2260 generate_exception(ctx
, EXCP_RI
);
2264 save_cpu_state(ctx
, 1);
2266 ctx
->bstate
= BS_STOP
;
2269 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2271 TranslationBlock
*tb
;
2273 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2276 tcg_gen_exit_tb((long)tb
+ n
);
2283 /* Branches (before delay slot) */
2284 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2285 int rs
, int rt
, int32_t offset
)
2287 target_ulong btarget
= -1;
2291 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2292 #ifdef MIPS_DEBUG_DISAS
2293 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2295 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2299 generate_exception(ctx
, EXCP_RI
);
2303 /* Load needed operands */
2309 /* Compare two registers */
2311 gen_load_gpr(cpu_T
[0], rs
);
2312 gen_load_gpr(cpu_T
[1], rt
);
2315 btarget
= ctx
->pc
+ 4 + offset
;
2329 /* Compare to zero */
2331 gen_load_gpr(cpu_T
[0], rs
);
2334 btarget
= ctx
->pc
+ 4 + offset
;
2338 /* Jump to immediate */
2339 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2343 /* Jump to register */
2344 if (offset
!= 0 && offset
!= 16) {
2345 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2346 others are reserved. */
2347 MIPS_INVAL("jump hint");
2348 generate_exception(ctx
, EXCP_RI
);
2351 gen_save_breg_target(rs
);
2354 MIPS_INVAL("branch/jump");
2355 generate_exception(ctx
, EXCP_RI
);
2359 /* No condition to be computed */
2361 case OPC_BEQ
: /* rx == rx */
2362 case OPC_BEQL
: /* rx == rx likely */
2363 case OPC_BGEZ
: /* 0 >= 0 */
2364 case OPC_BGEZL
: /* 0 >= 0 likely */
2365 case OPC_BLEZ
: /* 0 <= 0 */
2366 case OPC_BLEZL
: /* 0 <= 0 likely */
2368 ctx
->hflags
|= MIPS_HFLAG_B
;
2369 MIPS_DEBUG("balways");
2371 case OPC_BGEZAL
: /* 0 >= 0 */
2372 case OPC_BGEZALL
: /* 0 >= 0 likely */
2373 /* Always take and link */
2375 ctx
->hflags
|= MIPS_HFLAG_B
;
2376 MIPS_DEBUG("balways and link");
2378 case OPC_BNE
: /* rx != rx */
2379 case OPC_BGTZ
: /* 0 > 0 */
2380 case OPC_BLTZ
: /* 0 < 0 */
2382 MIPS_DEBUG("bnever (NOP)");
2384 case OPC_BLTZAL
: /* 0 < 0 */
2385 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2386 gen_store_gpr(cpu_T
[0], 31);
2387 MIPS_DEBUG("bnever and link");
2389 case OPC_BLTZALL
: /* 0 < 0 likely */
2390 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2391 gen_store_gpr(cpu_T
[0], 31);
2392 /* Skip the instruction in the delay slot */
2393 MIPS_DEBUG("bnever, link and skip");
2396 case OPC_BNEL
: /* rx != rx likely */
2397 case OPC_BGTZL
: /* 0 > 0 likely */
2398 case OPC_BLTZL
: /* 0 < 0 likely */
2399 /* Skip the instruction in the delay slot */
2400 MIPS_DEBUG("bnever and skip");
2404 ctx
->hflags
|= MIPS_HFLAG_B
;
2405 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
2409 ctx
->hflags
|= MIPS_HFLAG_B
;
2410 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
2413 ctx
->hflags
|= MIPS_HFLAG_BR
;
2414 MIPS_DEBUG("jr %s", regnames
[rs
]);
2418 ctx
->hflags
|= MIPS_HFLAG_BR
;
2419 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2422 MIPS_INVAL("branch/jump");
2423 generate_exception(ctx
, EXCP_RI
);
2430 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2431 regnames
[rs
], regnames
[rt
], btarget
);
2435 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2436 regnames
[rs
], regnames
[rt
], btarget
);
2440 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2441 regnames
[rs
], regnames
[rt
], btarget
);
2445 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2446 regnames
[rs
], regnames
[rt
], btarget
);
2450 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2454 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2458 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2464 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2468 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2472 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2476 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2480 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2484 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2488 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2493 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2495 ctx
->hflags
|= MIPS_HFLAG_BC
;
2496 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2501 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2503 ctx
->hflags
|= MIPS_HFLAG_BL
;
2504 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2507 MIPS_INVAL("conditional branch/jump");
2508 generate_exception(ctx
, EXCP_RI
);
2512 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2513 blink
, ctx
->hflags
, btarget
);
2515 ctx
->btarget
= btarget
;
2517 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2518 gen_store_gpr(cpu_T
[0], blink
);
2522 /* special3 bitfield operations */
2523 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2524 int rs
, int lsb
, int msb
)
2526 gen_load_gpr(cpu_T
[1], rs
);
2531 gen_op_ext(lsb
, msb
+ 1);
2533 #if defined(TARGET_MIPS64)
2537 gen_op_dext(lsb
, msb
+ 1 + 32);
2542 gen_op_dext(lsb
+ 32, msb
+ 1);
2547 gen_op_dext(lsb
, msb
+ 1);
2553 gen_load_gpr(cpu_T
[0], rt
);
2554 gen_op_ins(lsb
, msb
- lsb
+ 1);
2556 #if defined(TARGET_MIPS64)
2560 gen_load_gpr(cpu_T
[0], rt
);
2561 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2566 gen_load_gpr(cpu_T
[0], rt
);
2567 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2572 gen_load_gpr(cpu_T
[0], rt
);
2573 gen_op_dins(lsb
, msb
- lsb
+ 1);
2578 MIPS_INVAL("bitops");
2579 generate_exception(ctx
, EXCP_RI
);
2582 gen_store_gpr(cpu_T
[0], rt
);
2585 /* CP0 (MMU and control) */
2586 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2588 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2590 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2591 tcg_gen_ext_i32_tl(t
, r_tmp
);
2592 tcg_temp_free(r_tmp
);
2595 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2597 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I64
);
2599 tcg_gen_ld_i64(r_tmp
, cpu_env
, off
);
2600 tcg_gen_trunc_i64_tl(t
, r_tmp
);
2601 tcg_temp_free(r_tmp
);
2604 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2606 const char *rn
= "invalid";
2609 check_insn(env
, ctx
, ISA_MIPS32
);
2615 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Index
));
2619 check_insn(env
, ctx
, ASE_MT
);
2620 gen_op_mfc0_mvpcontrol();
2624 check_insn(env
, ctx
, ASE_MT
);
2625 gen_op_mfc0_mvpconf0();
2629 check_insn(env
, ctx
, ASE_MT
);
2630 gen_op_mfc0_mvpconf1();
2640 gen_op_mfc0_random();
2644 check_insn(env
, ctx
, ASE_MT
);
2645 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEControl
));
2649 check_insn(env
, ctx
, ASE_MT
);
2650 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf0
));
2654 check_insn(env
, ctx
, ASE_MT
);
2655 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf1
));
2659 check_insn(env
, ctx
, ASE_MT
);
2660 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_YQMask
));
2664 check_insn(env
, ctx
, ASE_MT
);
2665 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_VPESchedule
));
2669 check_insn(env
, ctx
, ASE_MT
);
2670 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_VPEScheFBack
));
2671 rn
= "VPEScheFBack";
2674 check_insn(env
, ctx
, ASE_MT
);
2675 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEOpt
));
2685 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2686 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2690 check_insn(env
, ctx
, ASE_MT
);
2691 gen_op_mfc0_tcstatus();
2695 check_insn(env
, ctx
, ASE_MT
);
2696 gen_op_mfc0_tcbind();
2700 check_insn(env
, ctx
, ASE_MT
);
2701 gen_op_mfc0_tcrestart();
2705 check_insn(env
, ctx
, ASE_MT
);
2706 gen_op_mfc0_tchalt();
2710 check_insn(env
, ctx
, ASE_MT
);
2711 gen_op_mfc0_tccontext();
2715 check_insn(env
, ctx
, ASE_MT
);
2716 gen_op_mfc0_tcschedule();
2720 check_insn(env
, ctx
, ASE_MT
);
2721 gen_op_mfc0_tcschefback();
2731 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2732 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2742 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_Context
));
2743 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2747 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2748 rn
= "ContextConfig";
2757 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageMask
));
2761 check_insn(env
, ctx
, ISA_MIPS32R2
);
2762 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageGrain
));
2772 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Wired
));
2776 check_insn(env
, ctx
, ISA_MIPS32R2
);
2777 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf0
));
2781 check_insn(env
, ctx
, ISA_MIPS32R2
);
2782 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf1
));
2786 check_insn(env
, ctx
, ISA_MIPS32R2
);
2787 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf2
));
2791 check_insn(env
, ctx
, ISA_MIPS32R2
);
2792 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf3
));
2796 check_insn(env
, ctx
, ISA_MIPS32R2
);
2797 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf4
));
2807 check_insn(env
, ctx
, ISA_MIPS32R2
);
2808 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_HWREna
));
2818 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
2819 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2829 gen_op_mfc0_count();
2832 /* 6,7 are implementation dependent */
2840 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
2841 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2851 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Compare
));
2854 /* 6,7 are implementation dependent */
2862 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Status
));
2866 check_insn(env
, ctx
, ISA_MIPS32R2
);
2867 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_IntCtl
));
2871 check_insn(env
, ctx
, ISA_MIPS32R2
);
2872 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSCtl
));
2876 check_insn(env
, ctx
, ISA_MIPS32R2
);
2877 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
2887 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Cause
));
2897 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EPC
));
2898 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2908 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PRid
));
2912 check_insn(env
, ctx
, ISA_MIPS32R2
);
2913 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_EBase
));
2923 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config0
));
2927 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config1
));
2931 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config2
));
2935 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config3
));
2938 /* 4,5 are reserved */
2939 /* 6,7 are implementation dependent */
2941 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config6
));
2945 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config7
));
2955 gen_op_mfc0_lladdr();
2965 gen_op_mfc0_watchlo(sel
);
2975 gen_op_mfc0_watchhi(sel
);
2985 #if defined(TARGET_MIPS64)
2986 check_insn(env
, ctx
, ISA_MIPS3
);
2987 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_XContext
));
2988 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2997 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3000 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Framemask
));
3009 rn
= "'Diagnostic"; /* implementation dependent */
3014 gen_op_mfc0_debug(); /* EJTAG support */
3018 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
3019 rn
= "TraceControl";
3022 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
3023 rn
= "TraceControl2";
3026 // gen_op_mfc0_usertracedata(); /* PDtrace support */
3027 rn
= "UserTraceData";
3030 // gen_op_mfc0_debug(); /* PDtrace support */
3041 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3042 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3052 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Performance0
));
3053 rn
= "Performance0";
3056 // gen_op_mfc0_performance1();
3057 rn
= "Performance1";
3060 // gen_op_mfc0_performance2();
3061 rn
= "Performance2";
3064 // gen_op_mfc0_performance3();
3065 rn
= "Performance3";
3068 // gen_op_mfc0_performance4();
3069 rn
= "Performance4";
3072 // gen_op_mfc0_performance5();
3073 rn
= "Performance5";
3076 // gen_op_mfc0_performance6();
3077 rn
= "Performance6";
3080 // gen_op_mfc0_performance7();
3081 rn
= "Performance7";
3106 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagLo
));
3113 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataLo
));
3126 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagHi
));
3133 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataHi
));
3143 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3144 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3155 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
3165 #if defined MIPS_DEBUG_DISAS
3166 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3167 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3174 #if defined MIPS_DEBUG_DISAS
3175 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3176 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3180 generate_exception(ctx
, EXCP_RI
);
3183 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3185 const char *rn
= "invalid";
3188 check_insn(env
, ctx
, ISA_MIPS32
);
3194 gen_op_mtc0_index();
3198 check_insn(env
, ctx
, ASE_MT
);
3199 gen_op_mtc0_mvpcontrol();
3203 check_insn(env
, ctx
, ASE_MT
);
3208 check_insn(env
, ctx
, ASE_MT
);
3223 check_insn(env
, ctx
, ASE_MT
);
3224 gen_op_mtc0_vpecontrol();
3228 check_insn(env
, ctx
, ASE_MT
);
3229 gen_op_mtc0_vpeconf0();
3233 check_insn(env
, ctx
, ASE_MT
);
3234 gen_op_mtc0_vpeconf1();
3238 check_insn(env
, ctx
, ASE_MT
);
3239 gen_op_mtc0_yqmask();
3243 check_insn(env
, ctx
, ASE_MT
);
3244 gen_op_mtc0_vpeschedule();
3248 check_insn(env
, ctx
, ASE_MT
);
3249 gen_op_mtc0_vpeschefback();
3250 rn
= "VPEScheFBack";
3253 check_insn(env
, ctx
, ASE_MT
);
3254 gen_op_mtc0_vpeopt();
3264 gen_op_mtc0_entrylo0();
3268 check_insn(env
, ctx
, ASE_MT
);
3269 gen_op_mtc0_tcstatus();
3273 check_insn(env
, ctx
, ASE_MT
);
3274 gen_op_mtc0_tcbind();
3278 check_insn(env
, ctx
, ASE_MT
);
3279 gen_op_mtc0_tcrestart();
3283 check_insn(env
, ctx
, ASE_MT
);
3284 gen_op_mtc0_tchalt();
3288 check_insn(env
, ctx
, ASE_MT
);
3289 gen_op_mtc0_tccontext();
3293 check_insn(env
, ctx
, ASE_MT
);
3294 gen_op_mtc0_tcschedule();
3298 check_insn(env
, ctx
, ASE_MT
);
3299 gen_op_mtc0_tcschefback();
3309 gen_op_mtc0_entrylo1();
3319 gen_op_mtc0_context();
3323 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3324 rn
= "ContextConfig";
3333 gen_op_mtc0_pagemask();
3337 check_insn(env
, ctx
, ISA_MIPS32R2
);
3338 gen_op_mtc0_pagegrain();
3348 gen_op_mtc0_wired();
3352 check_insn(env
, ctx
, ISA_MIPS32R2
);
3353 gen_op_mtc0_srsconf0();
3357 check_insn(env
, ctx
, ISA_MIPS32R2
);
3358 gen_op_mtc0_srsconf1();
3362 check_insn(env
, ctx
, ISA_MIPS32R2
);
3363 gen_op_mtc0_srsconf2();
3367 check_insn(env
, ctx
, ISA_MIPS32R2
);
3368 gen_op_mtc0_srsconf3();
3372 check_insn(env
, ctx
, ISA_MIPS32R2
);
3373 gen_op_mtc0_srsconf4();
3383 check_insn(env
, ctx
, ISA_MIPS32R2
);
3384 gen_op_mtc0_hwrena();
3398 gen_op_mtc0_count();
3401 /* 6,7 are implementation dependent */
3405 /* Stop translation as we may have switched the execution mode */
3406 ctx
->bstate
= BS_STOP
;
3411 gen_op_mtc0_entryhi();
3421 gen_op_mtc0_compare();
3424 /* 6,7 are implementation dependent */
3428 /* Stop translation as we may have switched the execution mode */
3429 ctx
->bstate
= BS_STOP
;
3434 gen_op_mtc0_status();
3435 /* BS_STOP isn't good enough here, hflags may have changed. */
3436 gen_save_pc(ctx
->pc
+ 4);
3437 ctx
->bstate
= BS_EXCP
;
3441 check_insn(env
, ctx
, ISA_MIPS32R2
);
3442 gen_op_mtc0_intctl();
3443 /* Stop translation as we may have switched the execution mode */
3444 ctx
->bstate
= BS_STOP
;
3448 check_insn(env
, ctx
, ISA_MIPS32R2
);
3449 gen_op_mtc0_srsctl();
3450 /* Stop translation as we may have switched the execution mode */
3451 ctx
->bstate
= BS_STOP
;
3455 check_insn(env
, ctx
, ISA_MIPS32R2
);
3456 gen_op_mtc0_srsmap();
3457 /* Stop translation as we may have switched the execution mode */
3458 ctx
->bstate
= BS_STOP
;
3468 gen_op_mtc0_cause();
3474 /* Stop translation as we may have switched the execution mode */
3475 ctx
->bstate
= BS_STOP
;
3494 check_insn(env
, ctx
, ISA_MIPS32R2
);
3495 gen_op_mtc0_ebase();
3505 gen_op_mtc0_config0();
3507 /* Stop translation as we may have switched the execution mode */
3508 ctx
->bstate
= BS_STOP
;
3511 /* ignored, read only */
3515 gen_op_mtc0_config2();
3517 /* Stop translation as we may have switched the execution mode */
3518 ctx
->bstate
= BS_STOP
;
3521 /* ignored, read only */
3524 /* 4,5 are reserved */
3525 /* 6,7 are implementation dependent */
3535 rn
= "Invalid config selector";
3552 gen_op_mtc0_watchlo(sel
);
3562 gen_op_mtc0_watchhi(sel
);
3572 #if defined(TARGET_MIPS64)
3573 check_insn(env
, ctx
, ISA_MIPS3
);
3574 gen_op_mtc0_xcontext();
3583 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3586 gen_op_mtc0_framemask();
3595 rn
= "Diagnostic"; /* implementation dependent */
3600 gen_op_mtc0_debug(); /* EJTAG support */
3601 /* BS_STOP isn't good enough here, hflags may have changed. */
3602 gen_save_pc(ctx
->pc
+ 4);
3603 ctx
->bstate
= BS_EXCP
;
3607 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3608 rn
= "TraceControl";
3609 /* Stop translation as we may have switched the execution mode */
3610 ctx
->bstate
= BS_STOP
;
3613 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3614 rn
= "TraceControl2";
3615 /* Stop translation as we may have switched the execution mode */
3616 ctx
->bstate
= BS_STOP
;
3619 /* Stop translation as we may have switched the execution mode */
3620 ctx
->bstate
= BS_STOP
;
3621 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3622 rn
= "UserTraceData";
3623 /* Stop translation as we may have switched the execution mode */
3624 ctx
->bstate
= BS_STOP
;
3627 // gen_op_mtc0_debug(); /* PDtrace support */
3628 /* Stop translation as we may have switched the execution mode */
3629 ctx
->bstate
= BS_STOP
;
3639 gen_op_mtc0_depc(); /* EJTAG support */
3649 gen_op_mtc0_performance0();
3650 rn
= "Performance0";
3653 // gen_op_mtc0_performance1();
3654 rn
= "Performance1";
3657 // gen_op_mtc0_performance2();
3658 rn
= "Performance2";
3661 // gen_op_mtc0_performance3();
3662 rn
= "Performance3";
3665 // gen_op_mtc0_performance4();
3666 rn
= "Performance4";
3669 // gen_op_mtc0_performance5();
3670 rn
= "Performance5";
3673 // gen_op_mtc0_performance6();
3674 rn
= "Performance6";
3677 // gen_op_mtc0_performance7();
3678 rn
= "Performance7";
3704 gen_op_mtc0_taglo();
3711 gen_op_mtc0_datalo();
3724 gen_op_mtc0_taghi();
3731 gen_op_mtc0_datahi();
3742 gen_op_mtc0_errorepc();
3752 gen_op_mtc0_desave(); /* EJTAG support */
3758 /* Stop translation as we may have switched the execution mode */
3759 ctx
->bstate
= BS_STOP
;
3764 #if defined MIPS_DEBUG_DISAS
3765 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3766 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3773 #if defined MIPS_DEBUG_DISAS
3774 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3775 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3779 generate_exception(ctx
, EXCP_RI
);
3782 #if defined(TARGET_MIPS64)
3783 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3785 const char *rn
= "invalid";
3788 check_insn(env
, ctx
, ISA_MIPS64
);
3794 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Index
));
3798 check_insn(env
, ctx
, ASE_MT
);
3799 gen_op_mfc0_mvpcontrol();
3803 check_insn(env
, ctx
, ASE_MT
);
3804 gen_op_mfc0_mvpconf0();
3808 check_insn(env
, ctx
, ASE_MT
);
3809 gen_op_mfc0_mvpconf1();
3819 gen_op_mfc0_random();
3823 check_insn(env
, ctx
, ASE_MT
);
3824 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEControl
));
3828 check_insn(env
, ctx
, ASE_MT
);
3829 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf0
));
3833 check_insn(env
, ctx
, ASE_MT
);
3834 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf1
));
3838 check_insn(env
, ctx
, ASE_MT
);
3839 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_YQMask
));
3843 check_insn(env
, ctx
, ASE_MT
);
3844 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
3848 check_insn(env
, ctx
, ASE_MT
);
3849 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
3850 rn
= "VPEScheFBack";
3853 check_insn(env
, ctx
, ASE_MT
);
3854 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEOpt
));
3864 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
3868 check_insn(env
, ctx
, ASE_MT
);
3869 gen_op_mfc0_tcstatus();
3873 check_insn(env
, ctx
, ASE_MT
);
3874 gen_op_mfc0_tcbind();
3878 check_insn(env
, ctx
, ASE_MT
);
3879 gen_op_dmfc0_tcrestart();
3883 check_insn(env
, ctx
, ASE_MT
);
3884 gen_op_dmfc0_tchalt();
3888 check_insn(env
, ctx
, ASE_MT
);
3889 gen_op_dmfc0_tccontext();
3893 check_insn(env
, ctx
, ASE_MT
);
3894 gen_op_dmfc0_tcschedule();
3898 check_insn(env
, ctx
, ASE_MT
);
3899 gen_op_dmfc0_tcschefback();
3909 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3919 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_Context
));
3923 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3924 rn
= "ContextConfig";
3933 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageMask
));
3937 check_insn(env
, ctx
, ISA_MIPS32R2
);
3938 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageGrain
));
3948 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Wired
));
3952 check_insn(env
, ctx
, ISA_MIPS32R2
);
3953 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf0
));
3957 check_insn(env
, ctx
, ISA_MIPS32R2
);
3958 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf1
));
3962 check_insn(env
, ctx
, ISA_MIPS32R2
);
3963 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf2
));
3967 check_insn(env
, ctx
, ISA_MIPS32R2
);
3968 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf3
));
3972 check_insn(env
, ctx
, ISA_MIPS32R2
);
3973 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf4
));
3983 check_insn(env
, ctx
, ISA_MIPS32R2
);
3984 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_HWREna
));
3994 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4004 gen_op_mfc0_count();
4007 /* 6,7 are implementation dependent */
4015 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4025 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Compare
));
4028 /* 6,7 are implementation dependent */
4036 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Status
));
4040 check_insn(env
, ctx
, ISA_MIPS32R2
);
4041 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_IntCtl
));
4045 check_insn(env
, ctx
, ISA_MIPS32R2
);
4046 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSCtl
));
4050 check_insn(env
, ctx
, ISA_MIPS32R2
);
4051 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
4061 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Cause
));
4071 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EPC
));
4081 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PRid
));
4085 check_insn(env
, ctx
, ISA_MIPS32R2
);
4086 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_EBase
));
4096 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config0
));
4100 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config1
));
4104 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config2
));
4108 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config3
));
4111 /* 6,7 are implementation dependent */
4113 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config6
));
4117 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config7
));
4127 gen_op_dmfc0_lladdr();
4137 gen_op_dmfc0_watchlo(sel
);
4147 gen_op_mfc0_watchhi(sel
);
4157 check_insn(env
, ctx
, ISA_MIPS3
);
4158 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_XContext
));
4166 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4169 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Framemask
));
4178 rn
= "'Diagnostic"; /* implementation dependent */
4183 gen_op_mfc0_debug(); /* EJTAG support */
4187 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
4188 rn
= "TraceControl";
4191 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
4192 rn
= "TraceControl2";
4195 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
4196 rn
= "UserTraceData";
4199 // gen_op_dmfc0_debug(); /* PDtrace support */
4210 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4220 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Performance0
));
4221 rn
= "Performance0";
4224 // gen_op_dmfc0_performance1();
4225 rn
= "Performance1";
4228 // gen_op_dmfc0_performance2();
4229 rn
= "Performance2";
4232 // gen_op_dmfc0_performance3();
4233 rn
= "Performance3";
4236 // gen_op_dmfc0_performance4();
4237 rn
= "Performance4";
4240 // gen_op_dmfc0_performance5();
4241 rn
= "Performance5";
4244 // gen_op_dmfc0_performance6();
4245 rn
= "Performance6";
4248 // gen_op_dmfc0_performance7();
4249 rn
= "Performance7";
4274 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagLo
));
4281 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataLo
));
4294 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagHi
));
4301 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataHi
));
4311 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4322 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
4332 #if defined MIPS_DEBUG_DISAS
4333 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4334 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4341 #if defined MIPS_DEBUG_DISAS
4342 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4343 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4347 generate_exception(ctx
, EXCP_RI
);
4350 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
4352 const char *rn
= "invalid";
4355 check_insn(env
, ctx
, ISA_MIPS64
);
4361 gen_op_mtc0_index();
4365 check_insn(env
, ctx
, ASE_MT
);
4366 gen_op_mtc0_mvpcontrol();
4370 check_insn(env
, ctx
, ASE_MT
);
4375 check_insn(env
, ctx
, ASE_MT
);
4390 check_insn(env
, ctx
, ASE_MT
);
4391 gen_op_mtc0_vpecontrol();
4395 check_insn(env
, ctx
, ASE_MT
);
4396 gen_op_mtc0_vpeconf0();
4400 check_insn(env
, ctx
, ASE_MT
);
4401 gen_op_mtc0_vpeconf1();
4405 check_insn(env
, ctx
, ASE_MT
);
4406 gen_op_mtc0_yqmask();
4410 check_insn(env
, ctx
, ASE_MT
);
4411 gen_op_mtc0_vpeschedule();
4415 check_insn(env
, ctx
, ASE_MT
);
4416 gen_op_mtc0_vpeschefback();
4417 rn
= "VPEScheFBack";
4420 check_insn(env
, ctx
, ASE_MT
);
4421 gen_op_mtc0_vpeopt();
4431 gen_op_mtc0_entrylo0();
4435 check_insn(env
, ctx
, ASE_MT
);
4436 gen_op_mtc0_tcstatus();
4440 check_insn(env
, ctx
, ASE_MT
);
4441 gen_op_mtc0_tcbind();
4445 check_insn(env
, ctx
, ASE_MT
);
4446 gen_op_mtc0_tcrestart();
4450 check_insn(env
, ctx
, ASE_MT
);
4451 gen_op_mtc0_tchalt();
4455 check_insn(env
, ctx
, ASE_MT
);
4456 gen_op_mtc0_tccontext();
4460 check_insn(env
, ctx
, ASE_MT
);
4461 gen_op_mtc0_tcschedule();
4465 check_insn(env
, ctx
, ASE_MT
);
4466 gen_op_mtc0_tcschefback();
4476 gen_op_mtc0_entrylo1();
4486 gen_op_mtc0_context();
4490 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
4491 rn
= "ContextConfig";
4500 gen_op_mtc0_pagemask();
4504 check_insn(env
, ctx
, ISA_MIPS32R2
);
4505 gen_op_mtc0_pagegrain();
4515 gen_op_mtc0_wired();
4519 check_insn(env
, ctx
, ISA_MIPS32R2
);
4520 gen_op_mtc0_srsconf0();
4524 check_insn(env
, ctx
, ISA_MIPS32R2
);
4525 gen_op_mtc0_srsconf1();
4529 check_insn(env
, ctx
, ISA_MIPS32R2
);
4530 gen_op_mtc0_srsconf2();
4534 check_insn(env
, ctx
, ISA_MIPS32R2
);
4535 gen_op_mtc0_srsconf3();
4539 check_insn(env
, ctx
, ISA_MIPS32R2
);
4540 gen_op_mtc0_srsconf4();
4550 check_insn(env
, ctx
, ISA_MIPS32R2
);
4551 gen_op_mtc0_hwrena();
4565 gen_op_mtc0_count();
4568 /* 6,7 are implementation dependent */
4572 /* Stop translation as we may have switched the execution mode */
4573 ctx
->bstate
= BS_STOP
;
4578 gen_op_mtc0_entryhi();
4588 gen_op_mtc0_compare();
4591 /* 6,7 are implementation dependent */
4595 /* Stop translation as we may have switched the execution mode */
4596 ctx
->bstate
= BS_STOP
;
4601 gen_op_mtc0_status();
4602 /* BS_STOP isn't good enough here, hflags may have changed. */
4603 gen_save_pc(ctx
->pc
+ 4);
4604 ctx
->bstate
= BS_EXCP
;
4608 check_insn(env
, ctx
, ISA_MIPS32R2
);
4609 gen_op_mtc0_intctl();
4610 /* Stop translation as we may have switched the execution mode */
4611 ctx
->bstate
= BS_STOP
;
4615 check_insn(env
, ctx
, ISA_MIPS32R2
);
4616 gen_op_mtc0_srsctl();
4617 /* Stop translation as we may have switched the execution mode */
4618 ctx
->bstate
= BS_STOP
;
4622 check_insn(env
, ctx
, ISA_MIPS32R2
);
4623 gen_op_mtc0_srsmap();
4624 /* Stop translation as we may have switched the execution mode */
4625 ctx
->bstate
= BS_STOP
;
4635 gen_op_mtc0_cause();
4641 /* Stop translation as we may have switched the execution mode */
4642 ctx
->bstate
= BS_STOP
;
4661 check_insn(env
, ctx
, ISA_MIPS32R2
);
4662 gen_op_mtc0_ebase();
4672 gen_op_mtc0_config0();
4674 /* Stop translation as we may have switched the execution mode */
4675 ctx
->bstate
= BS_STOP
;
4682 gen_op_mtc0_config2();
4684 /* Stop translation as we may have switched the execution mode */
4685 ctx
->bstate
= BS_STOP
;
4691 /* 6,7 are implementation dependent */
4693 rn
= "Invalid config selector";
4710 gen_op_mtc0_watchlo(sel
);
4720 gen_op_mtc0_watchhi(sel
);
4730 check_insn(env
, ctx
, ISA_MIPS3
);
4731 gen_op_mtc0_xcontext();
4739 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4742 gen_op_mtc0_framemask();
4751 rn
= "Diagnostic"; /* implementation dependent */
4756 gen_op_mtc0_debug(); /* EJTAG support */
4757 /* BS_STOP isn't good enough here, hflags may have changed. */
4758 gen_save_pc(ctx
->pc
+ 4);
4759 ctx
->bstate
= BS_EXCP
;
4763 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4764 /* Stop translation as we may have switched the execution mode */
4765 ctx
->bstate
= BS_STOP
;
4766 rn
= "TraceControl";
4769 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4770 /* Stop translation as we may have switched the execution mode */
4771 ctx
->bstate
= BS_STOP
;
4772 rn
= "TraceControl2";
4775 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4776 /* Stop translation as we may have switched the execution mode */
4777 ctx
->bstate
= BS_STOP
;
4778 rn
= "UserTraceData";
4781 // gen_op_mtc0_debug(); /* PDtrace support */
4782 /* Stop translation as we may have switched the execution mode */
4783 ctx
->bstate
= BS_STOP
;
4793 gen_op_mtc0_depc(); /* EJTAG support */
4803 gen_op_mtc0_performance0();
4804 rn
= "Performance0";
4807 // gen_op_mtc0_performance1();
4808 rn
= "Performance1";
4811 // gen_op_mtc0_performance2();
4812 rn
= "Performance2";
4815 // gen_op_mtc0_performance3();
4816 rn
= "Performance3";
4819 // gen_op_mtc0_performance4();
4820 rn
= "Performance4";
4823 // gen_op_mtc0_performance5();
4824 rn
= "Performance5";
4827 // gen_op_mtc0_performance6();
4828 rn
= "Performance6";
4831 // gen_op_mtc0_performance7();
4832 rn
= "Performance7";
4858 gen_op_mtc0_taglo();
4865 gen_op_mtc0_datalo();
4878 gen_op_mtc0_taghi();
4885 gen_op_mtc0_datahi();
4896 gen_op_mtc0_errorepc();
4906 gen_op_mtc0_desave(); /* EJTAG support */
4912 /* Stop translation as we may have switched the execution mode */
4913 ctx
->bstate
= BS_STOP
;
4918 #if defined MIPS_DEBUG_DISAS
4919 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4920 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4927 #if defined MIPS_DEBUG_DISAS
4928 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4929 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4933 generate_exception(ctx
, EXCP_RI
);
4935 #endif /* TARGET_MIPS64 */
4937 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4938 int u
, int sel
, int h
)
4940 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4942 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4943 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4944 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4945 tcg_gen_movi_tl(cpu_T
[0], -1);
4946 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4947 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4948 tcg_gen_movi_tl(cpu_T
[0], -1);
4954 gen_op_mftc0_tcstatus();
4957 gen_op_mftc0_tcbind();
4960 gen_op_mftc0_tcrestart();
4963 gen_op_mftc0_tchalt();
4966 gen_op_mftc0_tccontext();
4969 gen_op_mftc0_tcschedule();
4972 gen_op_mftc0_tcschefback();
4975 gen_mfc0(env
, ctx
, rt
, sel
);
4982 gen_op_mftc0_entryhi();
4985 gen_mfc0(env
, ctx
, rt
, sel
);
4991 gen_op_mftc0_status();
4994 gen_mfc0(env
, ctx
, rt
, sel
);
5000 gen_op_mftc0_debug();
5003 gen_mfc0(env
, ctx
, rt
, sel
);
5008 gen_mfc0(env
, ctx
, rt
, sel
);
5010 } else switch (sel
) {
5011 /* GPR registers. */
5015 /* Auxiliary CPU registers */
5061 /* Floating point (COP1). */
5063 /* XXX: For now we support only a single FPU context. */
5065 GEN_LOAD_FREG_FTN(WT0
, rt
);
5068 GEN_LOAD_FREG_FTN(WTH0
, rt
);
5073 /* XXX: For now we support only a single FPU context. */
5076 /* COP2: Not implemented. */
5083 #if defined MIPS_DEBUG_DISAS
5084 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5085 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5092 #if defined MIPS_DEBUG_DISAS
5093 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5094 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5098 generate_exception(ctx
, EXCP_RI
);
5101 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
5102 int u
, int sel
, int h
)
5104 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5106 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5107 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5108 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5110 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5111 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5118 gen_op_mttc0_tcstatus();
5121 gen_op_mttc0_tcbind();
5124 gen_op_mttc0_tcrestart();
5127 gen_op_mttc0_tchalt();
5130 gen_op_mttc0_tccontext();
5133 gen_op_mttc0_tcschedule();
5136 gen_op_mttc0_tcschefback();
5139 gen_mtc0(env
, ctx
, rd
, sel
);
5146 gen_op_mttc0_entryhi();
5149 gen_mtc0(env
, ctx
, rd
, sel
);
5155 gen_op_mttc0_status();
5158 gen_mtc0(env
, ctx
, rd
, sel
);
5164 gen_op_mttc0_debug();
5167 gen_mtc0(env
, ctx
, rd
, sel
);
5172 gen_mtc0(env
, ctx
, rd
, sel
);
5174 } else switch (sel
) {
5175 /* GPR registers. */
5179 /* Auxiliary CPU registers */
5225 /* Floating point (COP1). */
5227 /* XXX: For now we support only a single FPU context. */
5230 GEN_STORE_FTN_FREG(rd
, WT0
);
5233 GEN_STORE_FTN_FREG(rd
, WTH0
);
5237 /* XXX: For now we support only a single FPU context. */
5240 /* COP2: Not implemented. */
5247 #if defined MIPS_DEBUG_DISAS
5248 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5249 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5256 #if defined MIPS_DEBUG_DISAS
5257 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5258 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5262 generate_exception(ctx
, EXCP_RI
);
5265 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5267 const char *opn
= "ldst";
5275 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5276 gen_store_gpr(cpu_T
[0], rt
);
5280 gen_load_gpr(cpu_T
[0], rt
);
5281 save_cpu_state(ctx
, 1);
5282 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5285 #if defined(TARGET_MIPS64)
5287 check_insn(env
, ctx
, ISA_MIPS3
);
5292 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5293 gen_store_gpr(cpu_T
[0], rt
);
5297 check_insn(env
, ctx
, ISA_MIPS3
);
5298 gen_load_gpr(cpu_T
[0], rt
);
5299 save_cpu_state(ctx
, 1);
5300 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5305 check_insn(env
, ctx
, ASE_MT
);
5310 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
5311 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5312 gen_store_gpr(cpu_T
[0], rd
);
5316 check_insn(env
, ctx
, ASE_MT
);
5317 gen_load_gpr(cpu_T
[0], rt
);
5318 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
5319 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5324 if (!env
->tlb
->do_tlbwi
)
5330 if (!env
->tlb
->do_tlbwr
)
5336 if (!env
->tlb
->do_tlbp
)
5342 if (!env
->tlb
->do_tlbr
)
5348 check_insn(env
, ctx
, ISA_MIPS2
);
5349 save_cpu_state(ctx
, 1);
5351 ctx
->bstate
= BS_EXCP
;
5355 check_insn(env
, ctx
, ISA_MIPS32
);
5356 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5358 generate_exception(ctx
, EXCP_RI
);
5360 save_cpu_state(ctx
, 1);
5362 ctx
->bstate
= BS_EXCP
;
5367 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5368 /* If we get an exception, we want to restart at next instruction */
5370 save_cpu_state(ctx
, 1);
5373 ctx
->bstate
= BS_EXCP
;
5378 generate_exception(ctx
, EXCP_RI
);
5381 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5384 /* CP1 Branches (before delay slot) */
5385 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5386 int32_t cc
, int32_t offset
)
5388 target_ulong btarget
;
5389 const char *opn
= "cp1 cond branch";
5392 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5394 btarget
= ctx
->pc
+ 4 + offset
;
5413 ctx
->hflags
|= MIPS_HFLAG_BL
;
5414 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5417 gen_op_bc1any2f(cc
);
5421 gen_op_bc1any2t(cc
);
5425 gen_op_bc1any4f(cc
);
5429 gen_op_bc1any4t(cc
);
5432 ctx
->hflags
|= MIPS_HFLAG_BC
;
5433 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5437 generate_exception (ctx
, EXCP_RI
);
5440 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5441 ctx
->hflags
, btarget
);
5442 ctx
->btarget
= btarget
;
5445 /* Coprocessor 1 (FPU) */
5447 #define FOP(func, fmt) (((fmt) << 21) | (func))
5449 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5451 const char *opn
= "cp1 move";
5455 GEN_LOAD_FREG_FTN(WT0
, fs
);
5457 gen_store_gpr(cpu_T
[0], rt
);
5461 gen_load_gpr(cpu_T
[0], rt
);
5463 GEN_STORE_FTN_FREG(fs
, WT0
);
5468 gen_store_gpr(cpu_T
[0], rt
);
5472 gen_load_gpr(cpu_T
[0], rt
);
5477 GEN_LOAD_FREG_FTN(DT0
, fs
);
5479 gen_store_gpr(cpu_T
[0], rt
);
5483 gen_load_gpr(cpu_T
[0], rt
);
5485 GEN_STORE_FTN_FREG(fs
, DT0
);
5489 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5491 gen_store_gpr(cpu_T
[0], rt
);
5495 gen_load_gpr(cpu_T
[0], rt
);
5497 GEN_STORE_FTN_FREG(fs
, WTH0
);
5502 generate_exception (ctx
, EXCP_RI
);
5505 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5508 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5510 int l1
= gen_new_label();
5515 ccbit
= 1 << (24 + cc
);
5523 gen_load_gpr(cpu_T
[0], rd
);
5524 gen_load_gpr(cpu_T
[1], rs
);
5526 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
5527 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
5529 tcg_gen_ld_ptr(r_ptr
, cpu_env
, offsetof(CPUState
, fpu
));
5530 tcg_gen_ld_i32(r_tmp
, r_ptr
, offsetof(CPUMIPSFPUContext
, fcr31
));
5531 tcg_temp_free(r_ptr
);
5532 tcg_gen_andi_i32(r_tmp
, r_tmp
, ccbit
);
5533 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
5535 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
5538 gen_store_gpr(cpu_T
[0], rd
);
5541 #define GEN_MOVCF(fmt) \
5542 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
5547 ccbit = 1 << (24 + cc); \
5551 glue(gen_op_float_movf_, fmt)(ccbit); \
5553 glue(gen_op_float_movt_, fmt)(ccbit); \
5559 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5560 int ft
, int fs
, int fd
, int cc
)
5562 const char *opn
= "farith";
5563 const char *condnames
[] = {
5581 const char *condnames_abs
[] = {
5599 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5600 uint32_t func
= ctx
->opcode
& 0x3f;
5602 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5604 GEN_LOAD_FREG_FTN(WT0
, fs
);
5605 GEN_LOAD_FREG_FTN(WT1
, ft
);
5606 gen_op_float_add_s();
5607 GEN_STORE_FTN_FREG(fd
, WT2
);
5612 GEN_LOAD_FREG_FTN(WT0
, fs
);
5613 GEN_LOAD_FREG_FTN(WT1
, ft
);
5614 gen_op_float_sub_s();
5615 GEN_STORE_FTN_FREG(fd
, WT2
);
5620 GEN_LOAD_FREG_FTN(WT0
, fs
);
5621 GEN_LOAD_FREG_FTN(WT1
, ft
);
5622 gen_op_float_mul_s();
5623 GEN_STORE_FTN_FREG(fd
, WT2
);
5628 GEN_LOAD_FREG_FTN(WT0
, fs
);
5629 GEN_LOAD_FREG_FTN(WT1
, ft
);
5630 gen_op_float_div_s();
5631 GEN_STORE_FTN_FREG(fd
, WT2
);
5636 GEN_LOAD_FREG_FTN(WT0
, fs
);
5637 gen_op_float_sqrt_s();
5638 GEN_STORE_FTN_FREG(fd
, WT2
);
5642 GEN_LOAD_FREG_FTN(WT0
, fs
);
5643 gen_op_float_abs_s();
5644 GEN_STORE_FTN_FREG(fd
, WT2
);
5648 GEN_LOAD_FREG_FTN(WT0
, fs
);
5649 gen_op_float_mov_s();
5650 GEN_STORE_FTN_FREG(fd
, WT2
);
5654 GEN_LOAD_FREG_FTN(WT0
, fs
);
5655 gen_op_float_chs_s();
5656 GEN_STORE_FTN_FREG(fd
, WT2
);
5660 check_cp1_64bitmode(ctx
);
5661 GEN_LOAD_FREG_FTN(WT0
, fs
);
5662 gen_op_float_roundl_s();
5663 GEN_STORE_FTN_FREG(fd
, DT2
);
5667 check_cp1_64bitmode(ctx
);
5668 GEN_LOAD_FREG_FTN(WT0
, fs
);
5669 gen_op_float_truncl_s();
5670 GEN_STORE_FTN_FREG(fd
, DT2
);
5674 check_cp1_64bitmode(ctx
);
5675 GEN_LOAD_FREG_FTN(WT0
, fs
);
5676 gen_op_float_ceill_s();
5677 GEN_STORE_FTN_FREG(fd
, DT2
);
5681 check_cp1_64bitmode(ctx
);
5682 GEN_LOAD_FREG_FTN(WT0
, fs
);
5683 gen_op_float_floorl_s();
5684 GEN_STORE_FTN_FREG(fd
, DT2
);
5688 GEN_LOAD_FREG_FTN(WT0
, fs
);
5689 gen_op_float_roundw_s();
5690 GEN_STORE_FTN_FREG(fd
, WT2
);
5694 GEN_LOAD_FREG_FTN(WT0
, fs
);
5695 gen_op_float_truncw_s();
5696 GEN_STORE_FTN_FREG(fd
, WT2
);
5700 GEN_LOAD_FREG_FTN(WT0
, fs
);
5701 gen_op_float_ceilw_s();
5702 GEN_STORE_FTN_FREG(fd
, WT2
);
5706 GEN_LOAD_FREG_FTN(WT0
, fs
);
5707 gen_op_float_floorw_s();
5708 GEN_STORE_FTN_FREG(fd
, WT2
);
5712 gen_load_gpr(cpu_T
[0], ft
);
5713 GEN_LOAD_FREG_FTN(WT0
, fs
);
5714 GEN_LOAD_FREG_FTN(WT2
, fd
);
5715 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5716 GEN_STORE_FTN_FREG(fd
, WT2
);
5720 gen_load_gpr(cpu_T
[0], ft
);
5721 GEN_LOAD_FREG_FTN(WT0
, fs
);
5722 GEN_LOAD_FREG_FTN(WT2
, fd
);
5723 gen_op_float_movz_s();
5724 GEN_STORE_FTN_FREG(fd
, WT2
);
5728 gen_load_gpr(cpu_T
[0], ft
);
5729 GEN_LOAD_FREG_FTN(WT0
, fs
);
5730 GEN_LOAD_FREG_FTN(WT2
, fd
);
5731 gen_op_float_movn_s();
5732 GEN_STORE_FTN_FREG(fd
, WT2
);
5737 GEN_LOAD_FREG_FTN(WT0
, fs
);
5738 gen_op_float_recip_s();
5739 GEN_STORE_FTN_FREG(fd
, WT2
);
5744 GEN_LOAD_FREG_FTN(WT0
, fs
);
5745 gen_op_float_rsqrt_s();
5746 GEN_STORE_FTN_FREG(fd
, WT2
);
5750 check_cp1_64bitmode(ctx
);
5751 GEN_LOAD_FREG_FTN(WT0
, fs
);
5752 GEN_LOAD_FREG_FTN(WT2
, fd
);
5753 gen_op_float_recip2_s();
5754 GEN_STORE_FTN_FREG(fd
, WT2
);
5758 check_cp1_64bitmode(ctx
);
5759 GEN_LOAD_FREG_FTN(WT0
, fs
);
5760 gen_op_float_recip1_s();
5761 GEN_STORE_FTN_FREG(fd
, WT2
);
5765 check_cp1_64bitmode(ctx
);
5766 GEN_LOAD_FREG_FTN(WT0
, fs
);
5767 gen_op_float_rsqrt1_s();
5768 GEN_STORE_FTN_FREG(fd
, WT2
);
5772 check_cp1_64bitmode(ctx
);
5773 GEN_LOAD_FREG_FTN(WT0
, fs
);
5774 GEN_LOAD_FREG_FTN(WT2
, ft
);
5775 gen_op_float_rsqrt2_s();
5776 GEN_STORE_FTN_FREG(fd
, WT2
);
5780 check_cp1_registers(ctx
, fd
);
5781 GEN_LOAD_FREG_FTN(WT0
, fs
);
5782 gen_op_float_cvtd_s();
5783 GEN_STORE_FTN_FREG(fd
, DT2
);
5787 GEN_LOAD_FREG_FTN(WT0
, fs
);
5788 gen_op_float_cvtw_s();
5789 GEN_STORE_FTN_FREG(fd
, WT2
);
5793 check_cp1_64bitmode(ctx
);
5794 GEN_LOAD_FREG_FTN(WT0
, fs
);
5795 gen_op_float_cvtl_s();
5796 GEN_STORE_FTN_FREG(fd
, DT2
);
5800 check_cp1_64bitmode(ctx
);
5801 GEN_LOAD_FREG_FTN(WT1
, fs
);
5802 GEN_LOAD_FREG_FTN(WT0
, ft
);
5803 gen_op_float_cvtps_s();
5804 GEN_STORE_FTN_FREG(fd
, DT2
);
5823 GEN_LOAD_FREG_FTN(WT0
, fs
);
5824 GEN_LOAD_FREG_FTN(WT1
, ft
);
5825 if (ctx
->opcode
& (1 << 6)) {
5827 gen_cmpabs_s(func
-48, cc
);
5828 opn
= condnames_abs
[func
-48];
5830 gen_cmp_s(func
-48, cc
);
5831 opn
= condnames
[func
-48];
5835 check_cp1_registers(ctx
, fs
| ft
| fd
);
5836 GEN_LOAD_FREG_FTN(DT0
, fs
);
5837 GEN_LOAD_FREG_FTN(DT1
, ft
);
5838 gen_op_float_add_d();
5839 GEN_STORE_FTN_FREG(fd
, DT2
);
5844 check_cp1_registers(ctx
, fs
| ft
| fd
);
5845 GEN_LOAD_FREG_FTN(DT0
, fs
);
5846 GEN_LOAD_FREG_FTN(DT1
, ft
);
5847 gen_op_float_sub_d();
5848 GEN_STORE_FTN_FREG(fd
, DT2
);
5853 check_cp1_registers(ctx
, fs
| ft
| fd
);
5854 GEN_LOAD_FREG_FTN(DT0
, fs
);
5855 GEN_LOAD_FREG_FTN(DT1
, ft
);
5856 gen_op_float_mul_d();
5857 GEN_STORE_FTN_FREG(fd
, DT2
);
5862 check_cp1_registers(ctx
, fs
| ft
| fd
);
5863 GEN_LOAD_FREG_FTN(DT0
, fs
);
5864 GEN_LOAD_FREG_FTN(DT1
, ft
);
5865 gen_op_float_div_d();
5866 GEN_STORE_FTN_FREG(fd
, DT2
);
5871 check_cp1_registers(ctx
, fs
| fd
);
5872 GEN_LOAD_FREG_FTN(DT0
, fs
);
5873 gen_op_float_sqrt_d();
5874 GEN_STORE_FTN_FREG(fd
, DT2
);
5878 check_cp1_registers(ctx
, fs
| fd
);
5879 GEN_LOAD_FREG_FTN(DT0
, fs
);
5880 gen_op_float_abs_d();
5881 GEN_STORE_FTN_FREG(fd
, DT2
);
5885 check_cp1_registers(ctx
, fs
| fd
);
5886 GEN_LOAD_FREG_FTN(DT0
, fs
);
5887 gen_op_float_mov_d();
5888 GEN_STORE_FTN_FREG(fd
, DT2
);
5892 check_cp1_registers(ctx
, fs
| fd
);
5893 GEN_LOAD_FREG_FTN(DT0
, fs
);
5894 gen_op_float_chs_d();
5895 GEN_STORE_FTN_FREG(fd
, DT2
);
5899 check_cp1_64bitmode(ctx
);
5900 GEN_LOAD_FREG_FTN(DT0
, fs
);
5901 gen_op_float_roundl_d();
5902 GEN_STORE_FTN_FREG(fd
, DT2
);
5906 check_cp1_64bitmode(ctx
);
5907 GEN_LOAD_FREG_FTN(DT0
, fs
);
5908 gen_op_float_truncl_d();
5909 GEN_STORE_FTN_FREG(fd
, DT2
);
5913 check_cp1_64bitmode(ctx
);
5914 GEN_LOAD_FREG_FTN(DT0
, fs
);
5915 gen_op_float_ceill_d();
5916 GEN_STORE_FTN_FREG(fd
, DT2
);
5920 check_cp1_64bitmode(ctx
);
5921 GEN_LOAD_FREG_FTN(DT0
, fs
);
5922 gen_op_float_floorl_d();
5923 GEN_STORE_FTN_FREG(fd
, DT2
);
5927 check_cp1_registers(ctx
, fs
);
5928 GEN_LOAD_FREG_FTN(DT0
, fs
);
5929 gen_op_float_roundw_d();
5930 GEN_STORE_FTN_FREG(fd
, WT2
);
5934 check_cp1_registers(ctx
, fs
);
5935 GEN_LOAD_FREG_FTN(DT0
, fs
);
5936 gen_op_float_truncw_d();
5937 GEN_STORE_FTN_FREG(fd
, WT2
);
5941 check_cp1_registers(ctx
, fs
);
5942 GEN_LOAD_FREG_FTN(DT0
, fs
);
5943 gen_op_float_ceilw_d();
5944 GEN_STORE_FTN_FREG(fd
, WT2
);
5948 check_cp1_registers(ctx
, fs
);
5949 GEN_LOAD_FREG_FTN(DT0
, fs
);
5950 gen_op_float_floorw_d();
5951 GEN_STORE_FTN_FREG(fd
, WT2
);
5955 gen_load_gpr(cpu_T
[0], ft
);
5956 GEN_LOAD_FREG_FTN(DT0
, fs
);
5957 GEN_LOAD_FREG_FTN(DT2
, fd
);
5958 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5959 GEN_STORE_FTN_FREG(fd
, DT2
);
5963 gen_load_gpr(cpu_T
[0], ft
);
5964 GEN_LOAD_FREG_FTN(DT0
, fs
);
5965 GEN_LOAD_FREG_FTN(DT2
, fd
);
5966 gen_op_float_movz_d();
5967 GEN_STORE_FTN_FREG(fd
, DT2
);
5971 gen_load_gpr(cpu_T
[0], ft
);
5972 GEN_LOAD_FREG_FTN(DT0
, fs
);
5973 GEN_LOAD_FREG_FTN(DT2
, fd
);
5974 gen_op_float_movn_d();
5975 GEN_STORE_FTN_FREG(fd
, DT2
);
5979 check_cp1_64bitmode(ctx
);
5980 GEN_LOAD_FREG_FTN(DT0
, fs
);
5981 gen_op_float_recip_d();
5982 GEN_STORE_FTN_FREG(fd
, DT2
);
5986 check_cp1_64bitmode(ctx
);
5987 GEN_LOAD_FREG_FTN(DT0
, fs
);
5988 gen_op_float_rsqrt_d();
5989 GEN_STORE_FTN_FREG(fd
, DT2
);
5993 check_cp1_64bitmode(ctx
);
5994 GEN_LOAD_FREG_FTN(DT0
, fs
);
5995 GEN_LOAD_FREG_FTN(DT2
, ft
);
5996 gen_op_float_recip2_d();
5997 GEN_STORE_FTN_FREG(fd
, DT2
);
6001 check_cp1_64bitmode(ctx
);
6002 GEN_LOAD_FREG_FTN(DT0
, fs
);
6003 gen_op_float_recip1_d();
6004 GEN_STORE_FTN_FREG(fd
, DT2
);
6008 check_cp1_64bitmode(ctx
);
6009 GEN_LOAD_FREG_FTN(DT0
, fs
);
6010 gen_op_float_rsqrt1_d();
6011 GEN_STORE_FTN_FREG(fd
, DT2
);
6015 check_cp1_64bitmode(ctx
);
6016 GEN_LOAD_FREG_FTN(DT0
, fs
);
6017 GEN_LOAD_FREG_FTN(DT2
, ft
);
6018 gen_op_float_rsqrt2_d();
6019 GEN_STORE_FTN_FREG(fd
, DT2
);
6038 GEN_LOAD_FREG_FTN(DT0
, fs
);
6039 GEN_LOAD_FREG_FTN(DT1
, ft
);
6040 if (ctx
->opcode
& (1 << 6)) {
6042 check_cp1_registers(ctx
, fs
| ft
);
6043 gen_cmpabs_d(func
-48, cc
);
6044 opn
= condnames_abs
[func
-48];
6046 check_cp1_registers(ctx
, fs
| ft
);
6047 gen_cmp_d(func
-48, cc
);
6048 opn
= condnames
[func
-48];
6052 check_cp1_registers(ctx
, fs
);
6053 GEN_LOAD_FREG_FTN(DT0
, fs
);
6054 gen_op_float_cvts_d();
6055 GEN_STORE_FTN_FREG(fd
, WT2
);
6059 check_cp1_registers(ctx
, fs
);
6060 GEN_LOAD_FREG_FTN(DT0
, fs
);
6061 gen_op_float_cvtw_d();
6062 GEN_STORE_FTN_FREG(fd
, WT2
);
6066 check_cp1_64bitmode(ctx
);
6067 GEN_LOAD_FREG_FTN(DT0
, fs
);
6068 gen_op_float_cvtl_d();
6069 GEN_STORE_FTN_FREG(fd
, DT2
);
6073 GEN_LOAD_FREG_FTN(WT0
, fs
);
6074 gen_op_float_cvts_w();
6075 GEN_STORE_FTN_FREG(fd
, WT2
);
6079 check_cp1_registers(ctx
, fd
);
6080 GEN_LOAD_FREG_FTN(WT0
, fs
);
6081 gen_op_float_cvtd_w();
6082 GEN_STORE_FTN_FREG(fd
, DT2
);
6086 check_cp1_64bitmode(ctx
);
6087 GEN_LOAD_FREG_FTN(DT0
, fs
);
6088 gen_op_float_cvts_l();
6089 GEN_STORE_FTN_FREG(fd
, WT2
);
6093 check_cp1_64bitmode(ctx
);
6094 GEN_LOAD_FREG_FTN(DT0
, fs
);
6095 gen_op_float_cvtd_l();
6096 GEN_STORE_FTN_FREG(fd
, DT2
);
6100 check_cp1_64bitmode(ctx
);
6101 GEN_LOAD_FREG_FTN(WT0
, fs
);
6102 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6103 gen_op_float_cvtps_pw();
6104 GEN_STORE_FTN_FREG(fd
, WT2
);
6105 GEN_STORE_FTN_FREG(fd
, WTH2
);
6109 check_cp1_64bitmode(ctx
);
6110 GEN_LOAD_FREG_FTN(WT0
, fs
);
6111 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6112 GEN_LOAD_FREG_FTN(WT1
, ft
);
6113 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6114 gen_op_float_add_ps();
6115 GEN_STORE_FTN_FREG(fd
, WT2
);
6116 GEN_STORE_FTN_FREG(fd
, WTH2
);
6120 check_cp1_64bitmode(ctx
);
6121 GEN_LOAD_FREG_FTN(WT0
, fs
);
6122 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6123 GEN_LOAD_FREG_FTN(WT1
, ft
);
6124 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6125 gen_op_float_sub_ps();
6126 GEN_STORE_FTN_FREG(fd
, WT2
);
6127 GEN_STORE_FTN_FREG(fd
, WTH2
);
6131 check_cp1_64bitmode(ctx
);
6132 GEN_LOAD_FREG_FTN(WT0
, fs
);
6133 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6134 GEN_LOAD_FREG_FTN(WT1
, ft
);
6135 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6136 gen_op_float_mul_ps();
6137 GEN_STORE_FTN_FREG(fd
, WT2
);
6138 GEN_STORE_FTN_FREG(fd
, WTH2
);
6142 check_cp1_64bitmode(ctx
);
6143 GEN_LOAD_FREG_FTN(WT0
, fs
);
6144 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6145 gen_op_float_abs_ps();
6146 GEN_STORE_FTN_FREG(fd
, WT2
);
6147 GEN_STORE_FTN_FREG(fd
, WTH2
);
6151 check_cp1_64bitmode(ctx
);
6152 GEN_LOAD_FREG_FTN(WT0
, fs
);
6153 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6154 gen_op_float_mov_ps();
6155 GEN_STORE_FTN_FREG(fd
, WT2
);
6156 GEN_STORE_FTN_FREG(fd
, WTH2
);
6160 check_cp1_64bitmode(ctx
);
6161 GEN_LOAD_FREG_FTN(WT0
, fs
);
6162 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6163 gen_op_float_chs_ps();
6164 GEN_STORE_FTN_FREG(fd
, WT2
);
6165 GEN_STORE_FTN_FREG(fd
, WTH2
);
6169 check_cp1_64bitmode(ctx
);
6170 gen_load_gpr(cpu_T
[0], ft
);
6171 GEN_LOAD_FREG_FTN(WT0
, fs
);
6172 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6173 GEN_LOAD_FREG_FTN(WT2
, fd
);
6174 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6176 gen_op_float_movt_ps ((ft
>> 2) & 0x7);
6178 gen_op_float_movf_ps ((ft
>> 2) & 0x7);
6179 GEN_STORE_FTN_FREG(fd
, WT2
);
6180 GEN_STORE_FTN_FREG(fd
, WTH2
);
6184 check_cp1_64bitmode(ctx
);
6185 gen_load_gpr(cpu_T
[0], ft
);
6186 GEN_LOAD_FREG_FTN(WT0
, fs
);
6187 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6188 GEN_LOAD_FREG_FTN(WT2
, fd
);
6189 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6190 gen_op_float_movz_ps();
6191 GEN_STORE_FTN_FREG(fd
, WT2
);
6192 GEN_STORE_FTN_FREG(fd
, WTH2
);
6196 check_cp1_64bitmode(ctx
);
6197 gen_load_gpr(cpu_T
[0], ft
);
6198 GEN_LOAD_FREG_FTN(WT0
, fs
);
6199 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6200 GEN_LOAD_FREG_FTN(WT2
, fd
);
6201 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6202 gen_op_float_movn_ps();
6203 GEN_STORE_FTN_FREG(fd
, WT2
);
6204 GEN_STORE_FTN_FREG(fd
, WTH2
);
6208 check_cp1_64bitmode(ctx
);
6209 GEN_LOAD_FREG_FTN(WT0
, ft
);
6210 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6211 GEN_LOAD_FREG_FTN(WT1
, fs
);
6212 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6213 gen_op_float_addr_ps();
6214 GEN_STORE_FTN_FREG(fd
, WT2
);
6215 GEN_STORE_FTN_FREG(fd
, WTH2
);
6219 check_cp1_64bitmode(ctx
);
6220 GEN_LOAD_FREG_FTN(WT0
, ft
);
6221 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6222 GEN_LOAD_FREG_FTN(WT1
, fs
);
6223 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6224 gen_op_float_mulr_ps();
6225 GEN_STORE_FTN_FREG(fd
, WT2
);
6226 GEN_STORE_FTN_FREG(fd
, WTH2
);
6230 check_cp1_64bitmode(ctx
);
6231 GEN_LOAD_FREG_FTN(WT0
, fs
);
6232 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6233 GEN_LOAD_FREG_FTN(WT2
, fd
);
6234 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6235 gen_op_float_recip2_ps();
6236 GEN_STORE_FTN_FREG(fd
, WT2
);
6237 GEN_STORE_FTN_FREG(fd
, WTH2
);
6241 check_cp1_64bitmode(ctx
);
6242 GEN_LOAD_FREG_FTN(WT0
, fs
);
6243 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6244 gen_op_float_recip1_ps();
6245 GEN_STORE_FTN_FREG(fd
, WT2
);
6246 GEN_STORE_FTN_FREG(fd
, WTH2
);
6250 check_cp1_64bitmode(ctx
);
6251 GEN_LOAD_FREG_FTN(WT0
, fs
);
6252 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6253 gen_op_float_rsqrt1_ps();
6254 GEN_STORE_FTN_FREG(fd
, WT2
);
6255 GEN_STORE_FTN_FREG(fd
, WTH2
);
6259 check_cp1_64bitmode(ctx
);
6260 GEN_LOAD_FREG_FTN(WT0
, fs
);
6261 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6262 GEN_LOAD_FREG_FTN(WT2
, ft
);
6263 GEN_LOAD_FREG_FTN(WTH2
, ft
);
6264 gen_op_float_rsqrt2_ps();
6265 GEN_STORE_FTN_FREG(fd
, WT2
);
6266 GEN_STORE_FTN_FREG(fd
, WTH2
);
6270 check_cp1_64bitmode(ctx
);
6271 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6272 gen_op_float_cvts_pu();
6273 GEN_STORE_FTN_FREG(fd
, WT2
);
6277 check_cp1_64bitmode(ctx
);
6278 GEN_LOAD_FREG_FTN(WT0
, fs
);
6279 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6280 gen_op_float_cvtpw_ps();
6281 GEN_STORE_FTN_FREG(fd
, WT2
);
6282 GEN_STORE_FTN_FREG(fd
, WTH2
);
6286 check_cp1_64bitmode(ctx
);
6287 GEN_LOAD_FREG_FTN(WT0
, fs
);
6288 gen_op_float_cvts_pl();
6289 GEN_STORE_FTN_FREG(fd
, WT2
);
6293 check_cp1_64bitmode(ctx
);
6294 GEN_LOAD_FREG_FTN(WT0
, fs
);
6295 GEN_LOAD_FREG_FTN(WT1
, ft
);
6296 gen_op_float_pll_ps();
6297 GEN_STORE_FTN_FREG(fd
, DT2
);
6301 check_cp1_64bitmode(ctx
);
6302 GEN_LOAD_FREG_FTN(WT0
, fs
);
6303 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6304 gen_op_float_plu_ps();
6305 GEN_STORE_FTN_FREG(fd
, DT2
);
6309 check_cp1_64bitmode(ctx
);
6310 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6311 GEN_LOAD_FREG_FTN(WT1
, ft
);
6312 gen_op_float_pul_ps();
6313 GEN_STORE_FTN_FREG(fd
, DT2
);
6317 check_cp1_64bitmode(ctx
);
6318 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6319 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6320 gen_op_float_puu_ps();
6321 GEN_STORE_FTN_FREG(fd
, DT2
);
6340 check_cp1_64bitmode(ctx
);
6341 GEN_LOAD_FREG_FTN(WT0
, fs
);
6342 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6343 GEN_LOAD_FREG_FTN(WT1
, ft
);
6344 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6345 if (ctx
->opcode
& (1 << 6)) {
6346 gen_cmpabs_ps(func
-48, cc
);
6347 opn
= condnames_abs
[func
-48];
6349 gen_cmp_ps(func
-48, cc
);
6350 opn
= condnames
[func
-48];
6355 generate_exception (ctx
, EXCP_RI
);
6360 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
6363 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
6366 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
6371 /* Coprocessor 3 (FPU) */
6372 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
6373 int fd
, int fs
, int base
, int index
)
6375 const char *opn
= "extended float load/store";
6379 gen_load_gpr(cpu_T
[0], index
);
6380 } else if (index
== 0) {
6381 gen_load_gpr(cpu_T
[0], base
);
6383 gen_load_gpr(cpu_T
[0], base
);
6384 gen_load_gpr(cpu_T
[1], index
);
6387 /* Don't do NOP if destination is zero: we must perform the actual
6393 GEN_STORE_FTN_FREG(fd
, WT0
);
6398 check_cp1_registers(ctx
, fd
);
6400 GEN_STORE_FTN_FREG(fd
, DT0
);
6404 check_cp1_64bitmode(ctx
);
6406 GEN_STORE_FTN_FREG(fd
, DT0
);
6411 GEN_LOAD_FREG_FTN(WT0
, fs
);
6418 check_cp1_registers(ctx
, fs
);
6419 GEN_LOAD_FREG_FTN(DT0
, fs
);
6425 check_cp1_64bitmode(ctx
);
6426 GEN_LOAD_FREG_FTN(DT0
, fs
);
6433 generate_exception(ctx
, EXCP_RI
);
6436 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
6437 regnames
[index
], regnames
[base
]);
6440 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
6441 int fd
, int fr
, int fs
, int ft
)
6443 const char *opn
= "flt3_arith";
6447 check_cp1_64bitmode(ctx
);
6448 gen_load_gpr(cpu_T
[0], fr
);
6449 GEN_LOAD_FREG_FTN(DT0
, fs
);
6450 GEN_LOAD_FREG_FTN(DT1
, ft
);
6451 gen_op_float_alnv_ps();
6452 GEN_STORE_FTN_FREG(fd
, DT2
);
6457 GEN_LOAD_FREG_FTN(WT0
, fs
);
6458 GEN_LOAD_FREG_FTN(WT1
, ft
);
6459 GEN_LOAD_FREG_FTN(WT2
, fr
);
6460 gen_op_float_muladd_s();
6461 GEN_STORE_FTN_FREG(fd
, WT2
);
6466 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6467 GEN_LOAD_FREG_FTN(DT0
, fs
);
6468 GEN_LOAD_FREG_FTN(DT1
, ft
);
6469 GEN_LOAD_FREG_FTN(DT2
, fr
);
6470 gen_op_float_muladd_d();
6471 GEN_STORE_FTN_FREG(fd
, DT2
);
6475 check_cp1_64bitmode(ctx
);
6476 GEN_LOAD_FREG_FTN(WT0
, fs
);
6477 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6478 GEN_LOAD_FREG_FTN(WT1
, ft
);
6479 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6480 GEN_LOAD_FREG_FTN(WT2
, fr
);
6481 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6482 gen_op_float_muladd_ps();
6483 GEN_STORE_FTN_FREG(fd
, WT2
);
6484 GEN_STORE_FTN_FREG(fd
, WTH2
);
6489 GEN_LOAD_FREG_FTN(WT0
, fs
);
6490 GEN_LOAD_FREG_FTN(WT1
, ft
);
6491 GEN_LOAD_FREG_FTN(WT2
, fr
);
6492 gen_op_float_mulsub_s();
6493 GEN_STORE_FTN_FREG(fd
, WT2
);
6498 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6499 GEN_LOAD_FREG_FTN(DT0
, fs
);
6500 GEN_LOAD_FREG_FTN(DT1
, ft
);
6501 GEN_LOAD_FREG_FTN(DT2
, fr
);
6502 gen_op_float_mulsub_d();
6503 GEN_STORE_FTN_FREG(fd
, DT2
);
6507 check_cp1_64bitmode(ctx
);
6508 GEN_LOAD_FREG_FTN(WT0
, fs
);
6509 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6510 GEN_LOAD_FREG_FTN(WT1
, ft
);
6511 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6512 GEN_LOAD_FREG_FTN(WT2
, fr
);
6513 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6514 gen_op_float_mulsub_ps();
6515 GEN_STORE_FTN_FREG(fd
, WT2
);
6516 GEN_STORE_FTN_FREG(fd
, WTH2
);
6521 GEN_LOAD_FREG_FTN(WT0
, fs
);
6522 GEN_LOAD_FREG_FTN(WT1
, ft
);
6523 GEN_LOAD_FREG_FTN(WT2
, fr
);
6524 gen_op_float_nmuladd_s();
6525 GEN_STORE_FTN_FREG(fd
, WT2
);
6530 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6531 GEN_LOAD_FREG_FTN(DT0
, fs
);
6532 GEN_LOAD_FREG_FTN(DT1
, ft
);
6533 GEN_LOAD_FREG_FTN(DT2
, fr
);
6534 gen_op_float_nmuladd_d();
6535 GEN_STORE_FTN_FREG(fd
, DT2
);
6539 check_cp1_64bitmode(ctx
);
6540 GEN_LOAD_FREG_FTN(WT0
, fs
);
6541 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6542 GEN_LOAD_FREG_FTN(WT1
, ft
);
6543 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6544 GEN_LOAD_FREG_FTN(WT2
, fr
);
6545 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6546 gen_op_float_nmuladd_ps();
6547 GEN_STORE_FTN_FREG(fd
, WT2
);
6548 GEN_STORE_FTN_FREG(fd
, WTH2
);
6553 GEN_LOAD_FREG_FTN(WT0
, fs
);
6554 GEN_LOAD_FREG_FTN(WT1
, ft
);
6555 GEN_LOAD_FREG_FTN(WT2
, fr
);
6556 gen_op_float_nmulsub_s();
6557 GEN_STORE_FTN_FREG(fd
, WT2
);
6562 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6563 GEN_LOAD_FREG_FTN(DT0
, fs
);
6564 GEN_LOAD_FREG_FTN(DT1
, ft
);
6565 GEN_LOAD_FREG_FTN(DT2
, fr
);
6566 gen_op_float_nmulsub_d();
6567 GEN_STORE_FTN_FREG(fd
, DT2
);
6571 check_cp1_64bitmode(ctx
);
6572 GEN_LOAD_FREG_FTN(WT0
, fs
);
6573 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6574 GEN_LOAD_FREG_FTN(WT1
, ft
);
6575 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6576 GEN_LOAD_FREG_FTN(WT2
, fr
);
6577 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6578 gen_op_float_nmulsub_ps();
6579 GEN_STORE_FTN_FREG(fd
, WT2
);
6580 GEN_STORE_FTN_FREG(fd
, WTH2
);
6585 generate_exception (ctx
, EXCP_RI
);
6588 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6589 fregnames
[fs
], fregnames
[ft
]);
6592 /* ISA extensions (ASEs) */
6593 /* MIPS16 extension to MIPS32 */
6594 /* SmartMIPS extension to MIPS32 */
6596 #if defined(TARGET_MIPS64)
6598 /* MDMX extension to MIPS64 */
6602 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6606 uint32_t op
, op1
, op2
;
6609 /* make sure instructions are on a word boundary */
6610 if (ctx
->pc
& 0x3) {
6611 env
->CP0_BadVAddr
= ctx
->pc
;
6612 generate_exception(ctx
, EXCP_AdEL
);
6616 /* Handle blikely not taken case */
6617 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6618 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
6619 int l1
= gen_new_label();
6621 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6622 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
6623 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
6624 tcg_temp_free(r_tmp
);
6625 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6626 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6629 op
= MASK_OP_MAJOR(ctx
->opcode
);
6630 rs
= (ctx
->opcode
>> 21) & 0x1f;
6631 rt
= (ctx
->opcode
>> 16) & 0x1f;
6632 rd
= (ctx
->opcode
>> 11) & 0x1f;
6633 sa
= (ctx
->opcode
>> 6) & 0x1f;
6634 imm
= (int16_t)ctx
->opcode
;
6637 op1
= MASK_SPECIAL(ctx
->opcode
);
6639 case OPC_SLL
: /* Arithmetic with immediate */
6640 case OPC_SRL
... OPC_SRA
:
6641 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6643 case OPC_MOVZ
... OPC_MOVN
:
6644 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6645 case OPC_SLLV
: /* Arithmetic */
6646 case OPC_SRLV
... OPC_SRAV
:
6647 case OPC_ADD
... OPC_NOR
:
6648 case OPC_SLT
... OPC_SLTU
:
6649 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6651 case OPC_MULT
... OPC_DIVU
:
6653 check_insn(env
, ctx
, INSN_VR54XX
);
6654 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6655 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6657 gen_muldiv(ctx
, op1
, rs
, rt
);
6659 case OPC_JR
... OPC_JALR
:
6660 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6662 case OPC_TGE
... OPC_TEQ
: /* Traps */
6664 gen_trap(ctx
, op1
, rs
, rt
, -1);
6666 case OPC_MFHI
: /* Move from HI/LO */
6668 gen_HILO(ctx
, op1
, rd
);
6671 case OPC_MTLO
: /* Move to HI/LO */
6672 gen_HILO(ctx
, op1
, rs
);
6674 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6675 #ifdef MIPS_STRICT_STANDARD
6676 MIPS_INVAL("PMON / selsl");
6677 generate_exception(ctx
, EXCP_RI
);
6683 generate_exception(ctx
, EXCP_SYSCALL
);
6686 generate_exception(ctx
, EXCP_BREAK
);
6689 #ifdef MIPS_STRICT_STANDARD
6691 generate_exception(ctx
, EXCP_RI
);
6693 /* Implemented as RI exception for now. */
6694 MIPS_INVAL("spim (unofficial)");
6695 generate_exception(ctx
, EXCP_RI
);
6703 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6704 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6705 save_cpu_state(ctx
, 1);
6706 check_cp1_enabled(ctx
);
6707 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6708 (ctx
->opcode
>> 16) & 1);
6710 generate_exception_err(ctx
, EXCP_CpU
, 1);
6714 #if defined(TARGET_MIPS64)
6715 /* MIPS64 specific opcodes */
6717 case OPC_DSRL
... OPC_DSRA
:
6719 case OPC_DSRL32
... OPC_DSRA32
:
6720 check_insn(env
, ctx
, ISA_MIPS3
);
6722 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6725 case OPC_DSRLV
... OPC_DSRAV
:
6726 case OPC_DADD
... OPC_DSUBU
:
6727 check_insn(env
, ctx
, ISA_MIPS3
);
6729 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6731 case OPC_DMULT
... OPC_DDIVU
:
6732 check_insn(env
, ctx
, ISA_MIPS3
);
6734 gen_muldiv(ctx
, op1
, rs
, rt
);
6737 default: /* Invalid */
6738 MIPS_INVAL("special");
6739 generate_exception(ctx
, EXCP_RI
);
6744 op1
= MASK_SPECIAL2(ctx
->opcode
);
6746 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6747 case OPC_MSUB
... OPC_MSUBU
:
6748 check_insn(env
, ctx
, ISA_MIPS32
);
6749 gen_muldiv(ctx
, op1
, rs
, rt
);
6752 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6754 case OPC_CLZ
... OPC_CLO
:
6755 check_insn(env
, ctx
, ISA_MIPS32
);
6756 gen_cl(ctx
, op1
, rd
, rs
);
6759 /* XXX: not clear which exception should be raised
6760 * when in debug mode...
6762 check_insn(env
, ctx
, ISA_MIPS32
);
6763 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6764 generate_exception(ctx
, EXCP_DBp
);
6766 generate_exception(ctx
, EXCP_DBp
);
6770 #if defined(TARGET_MIPS64)
6771 case OPC_DCLZ
... OPC_DCLO
:
6772 check_insn(env
, ctx
, ISA_MIPS64
);
6774 gen_cl(ctx
, op1
, rd
, rs
);
6777 default: /* Invalid */
6778 MIPS_INVAL("special2");
6779 generate_exception(ctx
, EXCP_RI
);
6784 op1
= MASK_SPECIAL3(ctx
->opcode
);
6788 check_insn(env
, ctx
, ISA_MIPS32R2
);
6789 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6792 check_insn(env
, ctx
, ISA_MIPS32R2
);
6793 op2
= MASK_BSHFL(ctx
->opcode
);
6796 gen_load_gpr(cpu_T
[1], rt
);
6800 gen_load_gpr(cpu_T
[1], rt
);
6801 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[1]);
6804 gen_load_gpr(cpu_T
[1], rt
);
6805 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[1]);
6807 default: /* Invalid */
6808 MIPS_INVAL("bshfl");
6809 generate_exception(ctx
, EXCP_RI
);
6812 gen_store_gpr(cpu_T
[0], rd
);
6815 check_insn(env
, ctx
, ISA_MIPS32R2
);
6818 save_cpu_state(ctx
, 1);
6819 gen_op_rdhwr_cpunum();
6822 save_cpu_state(ctx
, 1);
6823 gen_op_rdhwr_synci_step();
6826 save_cpu_state(ctx
, 1);
6830 save_cpu_state(ctx
, 1);
6831 gen_op_rdhwr_ccres();
6834 #if defined (CONFIG_USER_ONLY)
6838 default: /* Invalid */
6839 MIPS_INVAL("rdhwr");
6840 generate_exception(ctx
, EXCP_RI
);
6843 gen_store_gpr(cpu_T
[0], rt
);
6846 check_insn(env
, ctx
, ASE_MT
);
6847 gen_load_gpr(cpu_T
[0], rt
);
6848 gen_load_gpr(cpu_T
[1], rs
);
6852 check_insn(env
, ctx
, ASE_MT
);
6853 gen_load_gpr(cpu_T
[0], rs
);
6855 gen_store_gpr(cpu_T
[0], rd
);
6857 #if defined(TARGET_MIPS64)
6858 case OPC_DEXTM
... OPC_DEXT
:
6859 case OPC_DINSM
... OPC_DINS
:
6860 check_insn(env
, ctx
, ISA_MIPS64R2
);
6862 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6865 check_insn(env
, ctx
, ISA_MIPS64R2
);
6867 op2
= MASK_DBSHFL(ctx
->opcode
);
6870 gen_load_gpr(cpu_T
[1], rt
);
6874 gen_load_gpr(cpu_T
[1], rt
);
6877 default: /* Invalid */
6878 MIPS_INVAL("dbshfl");
6879 generate_exception(ctx
, EXCP_RI
);
6882 gen_store_gpr(cpu_T
[0], rd
);
6885 default: /* Invalid */
6886 MIPS_INVAL("special3");
6887 generate_exception(ctx
, EXCP_RI
);
6892 op1
= MASK_REGIMM(ctx
->opcode
);
6894 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6895 case OPC_BLTZAL
... OPC_BGEZALL
:
6896 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6898 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6900 gen_trap(ctx
, op1
, rs
, -1, imm
);
6903 check_insn(env
, ctx
, ISA_MIPS32R2
);
6906 default: /* Invalid */
6907 MIPS_INVAL("regimm");
6908 generate_exception(ctx
, EXCP_RI
);
6913 check_cp0_enabled(ctx
);
6914 op1
= MASK_CP0(ctx
->opcode
);
6920 #if defined(TARGET_MIPS64)
6924 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6926 case OPC_C0_FIRST
... OPC_C0_LAST
:
6927 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6930 op2
= MASK_MFMC0(ctx
->opcode
);
6933 check_insn(env
, ctx
, ASE_MT
);
6937 check_insn(env
, ctx
, ASE_MT
);
6941 check_insn(env
, ctx
, ASE_MT
);
6945 check_insn(env
, ctx
, ASE_MT
);
6949 check_insn(env
, ctx
, ISA_MIPS32R2
);
6950 save_cpu_state(ctx
, 1);
6952 /* Stop translation as we may have switched the execution mode */
6953 ctx
->bstate
= BS_STOP
;
6956 check_insn(env
, ctx
, ISA_MIPS32R2
);
6957 save_cpu_state(ctx
, 1);
6959 /* Stop translation as we may have switched the execution mode */
6960 ctx
->bstate
= BS_STOP
;
6962 default: /* Invalid */
6963 MIPS_INVAL("mfmc0");
6964 generate_exception(ctx
, EXCP_RI
);
6967 gen_store_gpr(cpu_T
[0], rt
);
6970 check_insn(env
, ctx
, ISA_MIPS32R2
);
6971 gen_load_srsgpr(cpu_T
[0], rt
);
6972 gen_store_gpr(cpu_T
[0], rd
);
6975 check_insn(env
, ctx
, ISA_MIPS32R2
);
6976 gen_load_gpr(cpu_T
[0], rt
);
6977 gen_store_srsgpr(cpu_T
[0], rd
);
6981 generate_exception(ctx
, EXCP_RI
);
6985 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6986 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6988 case OPC_J
... OPC_JAL
: /* Jump */
6989 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6990 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6992 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6993 case OPC_BEQL
... OPC_BGTZL
:
6994 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6996 case OPC_LB
... OPC_LWR
: /* Load and stores */
6997 case OPC_SB
... OPC_SW
:
7001 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7004 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
7008 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7012 /* Floating point (COP1). */
7017 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7018 save_cpu_state(ctx
, 1);
7019 check_cp1_enabled(ctx
);
7020 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
7022 generate_exception_err(ctx
, EXCP_CpU
, 1);
7027 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7028 save_cpu_state(ctx
, 1);
7029 check_cp1_enabled(ctx
);
7030 op1
= MASK_CP1(ctx
->opcode
);
7034 check_insn(env
, ctx
, ISA_MIPS32R2
);
7039 gen_cp1(ctx
, op1
, rt
, rd
);
7041 #if defined(TARGET_MIPS64)
7044 check_insn(env
, ctx
, ISA_MIPS3
);
7045 gen_cp1(ctx
, op1
, rt
, rd
);
7051 check_insn(env
, ctx
, ASE_MIPS3D
);
7054 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
7055 (rt
>> 2) & 0x7, imm
<< 2);
7062 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
7067 generate_exception (ctx
, EXCP_RI
);
7071 generate_exception_err(ctx
, EXCP_CpU
, 1);
7081 /* COP2: Not implemented. */
7082 generate_exception_err(ctx
, EXCP_CpU
, 2);
7086 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7087 save_cpu_state(ctx
, 1);
7088 check_cp1_enabled(ctx
);
7089 op1
= MASK_CP3(ctx
->opcode
);
7097 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
7115 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
7119 generate_exception (ctx
, EXCP_RI
);
7123 generate_exception_err(ctx
, EXCP_CpU
, 1);
7127 #if defined(TARGET_MIPS64)
7128 /* MIPS64 opcodes */
7130 case OPC_LDL
... OPC_LDR
:
7131 case OPC_SDL
... OPC_SDR
:
7136 check_insn(env
, ctx
, ISA_MIPS3
);
7138 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7140 case OPC_DADDI
... OPC_DADDIU
:
7141 check_insn(env
, ctx
, ISA_MIPS3
);
7143 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7147 check_insn(env
, ctx
, ASE_MIPS16
);
7148 /* MIPS16: Not implemented. */
7150 check_insn(env
, ctx
, ASE_MDMX
);
7151 /* MDMX: Not implemented. */
7152 default: /* Invalid */
7153 MIPS_INVAL("major opcode");
7154 generate_exception(ctx
, EXCP_RI
);
7157 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7158 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7159 /* Branches completion */
7160 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7161 ctx
->bstate
= BS_BRANCH
;
7162 save_cpu_state(ctx
, 0);
7165 /* unconditional branch */
7166 MIPS_DEBUG("unconditional branch");
7167 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7170 /* blikely taken case */
7171 MIPS_DEBUG("blikely branch taken");
7172 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7175 /* Conditional branch */
7176 MIPS_DEBUG("conditional branch");
7178 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
7179 int l1
= gen_new_label();
7181 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7182 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
7183 tcg_temp_free(r_tmp
);
7184 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7186 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7190 /* unconditional branch to register */
7191 MIPS_DEBUG("branch to register");
7196 MIPS_DEBUG("unknown branch");
7202 static always_inline
int
7203 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
7207 target_ulong pc_start
;
7208 uint16_t *gen_opc_end
;
7211 if (search_pc
&& loglevel
)
7212 fprintf (logfile
, "search pc %d\n", search_pc
);
7215 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7219 ctx
.bstate
= BS_NONE
;
7220 /* Restore delay slot state from the tb context. */
7221 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
7222 restore_cpu_state(env
, &ctx
);
7223 #if defined(CONFIG_USER_ONLY)
7224 ctx
.mem_idx
= MIPS_HFLAG_UM
;
7226 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
7229 if (loglevel
& CPU_LOG_TB_CPU
) {
7230 fprintf(logfile
, "------------------------------------------------\n");
7231 /* FIXME: This may print out stale hflags from env... */
7232 cpu_dump_state(env
, logfile
, fprintf
, 0);
7235 #ifdef MIPS_DEBUG_DISAS
7236 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7237 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
7238 tb
, ctx
.mem_idx
, ctx
.hflags
);
7240 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7241 if (env
->nb_breakpoints
> 0) {
7242 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
7243 if (env
->breakpoints
[j
] == ctx
.pc
) {
7244 save_cpu_state(&ctx
, 1);
7245 ctx
.bstate
= BS_BRANCH
;
7247 /* Include the breakpoint location or the tb won't
7248 * be flushed when it must be. */
7250 goto done_generating
;
7256 j
= gen_opc_ptr
- gen_opc_buf
;
7260 gen_opc_instr_start
[lj
++] = 0;
7262 gen_opc_pc
[lj
] = ctx
.pc
;
7263 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
7264 gen_opc_instr_start
[lj
] = 1;
7266 ctx
.opcode
= ldl_code(ctx
.pc
);
7267 decode_opc(env
, &ctx
);
7270 if (env
->singlestep_enabled
)
7273 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
7276 #if defined (MIPS_SINGLE_STEP)
7280 if (env
->singlestep_enabled
) {
7281 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
7284 switch (ctx
.bstate
) {
7286 tcg_gen_helper_0_0(do_interrupt_restart
);
7287 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7290 save_cpu_state(&ctx
, 0);
7291 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7294 tcg_gen_helper_0_0(do_interrupt_restart
);
7303 *gen_opc_ptr
= INDEX_op_end
;
7305 j
= gen_opc_ptr
- gen_opc_buf
;
7308 gen_opc_instr_start
[lj
++] = 0;
7310 tb
->size
= ctx
.pc
- pc_start
;
7313 #if defined MIPS_DEBUG_DISAS
7314 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7315 fprintf(logfile
, "\n");
7317 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7318 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7319 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
7320 fprintf(logfile
, "\n");
7322 if (loglevel
& CPU_LOG_TB_CPU
) {
7323 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
7330 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7332 return gen_intermediate_code_internal(env
, tb
, 0);
7335 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7337 return gen_intermediate_code_internal(env
, tb
, 1);
7340 void fpu_dump_state(CPUState
*env
, FILE *f
,
7341 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7345 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
7347 #define printfpr(fp) \
7350 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7351 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7352 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7355 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7356 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7357 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7358 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7359 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7364 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7365 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
7366 get_float_exception_flags(&env
->fpu
->fp_status
));
7367 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
7368 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
7369 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
7370 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
7371 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
7372 printfpr(&env
->fpu
->fpr
[i
]);
7378 void dump_fpu (CPUState
*env
)
7382 "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
7383 " LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
7385 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0],
7386 env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
,
7388 fpu_dump_state(env
, logfile
, fprintf
, 0);
7392 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7393 /* Debug help: The architecture requires 32bit code to maintain proper
7394 sign-extened values on 64bit machines. */
7396 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7398 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
7399 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7404 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
7405 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
7406 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
7407 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
7408 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
7409 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
7410 if (!SIGN_EXT_P(env
->btarget
))
7411 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
7413 for (i
= 0; i
< 32; i
++) {
7414 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
7415 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7418 if (!SIGN_EXT_P(env
->CP0_EPC
))
7419 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
7420 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
7421 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
7425 void cpu_dump_state (CPUState
*env
, FILE *f
,
7426 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7431 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",
7432 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
7433 for (i
= 0; i
< 32; i
++) {
7435 cpu_fprintf(f
, "GPR%02d:", i
);
7436 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7438 cpu_fprintf(f
, "\n");
7441 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
7442 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
7443 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
7444 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
7445 if (env
->hflags
& MIPS_HFLAG_FPU
)
7446 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
7447 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7448 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
7452 static void mips_tcg_init(void)
7456 /* Initialize various static tables. */
7460 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
7461 current_tc_gprs
= tcg_global_mem_new(TCG_TYPE_PTR
,
7463 offsetof(CPUState
, current_tc_gprs
),
7465 current_tc_hi
= tcg_global_mem_new(TCG_TYPE_PTR
,
7467 offsetof(CPUState
, current_tc_hi
),
7469 #if TARGET_LONG_BITS > HOST_LONG_BITS
7470 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
7471 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
7472 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
7473 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
7475 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
7476 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
7482 #include "translate_init.c"
7484 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
7487 const mips_def_t
*def
;
7489 def
= cpu_mips_find_by_name(cpu_model
);
7492 env
= qemu_mallocz(sizeof(CPUMIPSState
));
7495 env
->cpu_model
= def
;
7498 env
->cpu_model_str
= cpu_model
;
7504 void cpu_reset (CPUMIPSState
*env
)
7506 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
7511 #if !defined(CONFIG_USER_ONLY)
7512 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
7513 /* If the exception was raised from a delay slot,
7514 * come back to the jump. */
7515 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
7517 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
7519 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
7521 /* SMP not implemented */
7522 env
->CP0_EBase
= 0x80000000;
7523 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
7524 /* vectored interrupts not implemented, timer on int 7,
7525 no performance counters. */
7526 env
->CP0_IntCtl
= 0xe0000000;
7530 for (i
= 0; i
< 7; i
++) {
7531 env
->CP0_WatchLo
[i
] = 0;
7532 env
->CP0_WatchHi
[i
] = 0x80000000;
7534 env
->CP0_WatchLo
[7] = 0;
7535 env
->CP0_WatchHi
[7] = 0;
7537 /* Count register increments in debug mode, EJTAG version 1 */
7538 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
7540 env
->exception_index
= EXCP_NONE
;
7541 #if defined(CONFIG_USER_ONLY)
7542 env
->hflags
= MIPS_HFLAG_UM
;
7543 env
->user_mode_only
= 1;
7545 env
->hflags
= MIPS_HFLAG_CP0
;
7547 cpu_mips_register(env
, env
->cpu_model
);
7550 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7551 unsigned long searched_pc
, int pc_pos
, void *puc
)
7553 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
7554 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
7555 env
->hflags
|= gen_opc_hflags
[pc_pos
];