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
, cpu_T
[2];
428 /* The code generator doesn't like lots of temporaries, so maintain our own
429 cache for reuse within a function. */
431 static int num_temps
;
432 static TCGv temps
[MAX_TEMPS
];
434 /* Allocate a temporary variable. */
435 static TCGv
new_tmp(void)
438 if (num_temps
== MAX_TEMPS
)
441 if (GET_TCGV(temps
[num_temps
]))
442 return temps
[num_temps
++];
444 tmp
= tcg_temp_new(TCG_TYPE_I32
);
445 temps
[num_temps
++] = tmp
;
449 /* Release a temporary variable. */
450 static void dead_tmp(TCGv tmp
)
455 if (GET_TCGV(temps
[i
]) == GET_TCGV(tmp
))
458 /* Shuffle this temp to the last slot. */
459 while (GET_TCGV(temps
[i
]) != GET_TCGV(tmp
))
461 while (i
< num_temps
) {
462 temps
[i
] = temps
[i
+ 1];
468 /* General purpose registers moves */
469 const unsigned char *regnames
[] =
470 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
471 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
472 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
473 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
475 static inline void gen_op_load_gpr_TN(int t_index
, int reg
)
477 tcg_gen_ld_tl(cpu_T
[t_index
], current_tc_gprs
, sizeof(target_ulong
) * reg
);
480 static inline void gen_op_load_gpr_T0(int reg
)
482 gen_op_load_gpr_TN(0, reg
);
485 static inline void gen_op_load_gpr_T1(int reg
)
487 gen_op_load_gpr_TN(1, reg
);
490 static inline void gen_op_store_gpr_TN(int t_index
, int reg
)
492 tcg_gen_st_tl(cpu_T
[t_index
], current_tc_gprs
, sizeof(target_ulong
) * reg
);
495 static inline void gen_op_store_gpr_T0(int reg
)
497 gen_op_store_gpr_TN(0, reg
);
500 static inline void gen_op_store_gpr_T1(int reg
)
502 gen_op_store_gpr_TN(1, reg
);
505 /* Moves to/from shadow registers */
506 static inline void gen_op_load_srsgpr_T0(int reg
)
508 TCGv r_tmp
= new_tmp();
510 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
511 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
512 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
513 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
514 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
516 tcg_gen_ld_tl(cpu_T
[0], r_tmp
, sizeof(target_ulong
) * reg
);
520 static inline void gen_op_store_srsgpr_T0(int reg
)
522 TCGv r_tmp
= new_tmp();
524 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
525 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
526 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
527 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
528 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
530 tcg_gen_st_tl(cpu_T
[0], r_tmp
, sizeof(target_ulong
) * reg
);
534 /* Load immediates, zero being a special case. */
535 static inline void gen_op_set_T0(target_ulong arg
)
537 tcg_gen_movi_tl(cpu_T
[0], arg
);
540 static inline void gen_op_set_T1(target_ulong arg
)
542 tcg_gen_movi_tl(cpu_T
[1], arg
);
545 static inline void gen_op_reset_T0(void)
547 tcg_gen_movi_tl(cpu_T
[0], 0);
550 static inline void gen_op_reset_T1(void)
552 tcg_gen_movi_tl(cpu_T
[1], 0);
555 /* Moves to/from HI/LO registers. */
556 static inline void gen_op_load_HI(int reg
)
558 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, HI
[reg
]));
561 static inline void gen_op_store_HI(int reg
)
563 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, HI
[reg
]));
566 static inline void gen_op_load_LO(int reg
)
568 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, LO
[reg
]));
571 static inline void gen_op_store_LO(int reg
)
573 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, LO
[reg
]));
577 /* Floating point register moves. */
578 static const char *fregnames
[] =
579 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
580 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
581 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
582 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
584 #define FGEN32(func, NAME) \
585 static GenOpFunc *NAME ## _table [32] = { \
586 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
587 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
588 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
589 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
590 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
591 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
592 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
593 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
595 static always_inline void func(int n) \
597 NAME ## _table[n](); \
600 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
601 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
603 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
604 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
606 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
607 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
609 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
610 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
612 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
613 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
615 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
616 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
618 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
619 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
621 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
622 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
624 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
625 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
627 #define FOP_CONDS(type, fmt) \
628 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
629 gen_op_cmp ## type ## _ ## fmt ## _f, \
630 gen_op_cmp ## type ## _ ## fmt ## _un, \
631 gen_op_cmp ## type ## _ ## fmt ## _eq, \
632 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
633 gen_op_cmp ## type ## _ ## fmt ## _olt, \
634 gen_op_cmp ## type ## _ ## fmt ## _ult, \
635 gen_op_cmp ## type ## _ ## fmt ## _ole, \
636 gen_op_cmp ## type ## _ ## fmt ## _ule, \
637 gen_op_cmp ## type ## _ ## fmt ## _sf, \
638 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
639 gen_op_cmp ## type ## _ ## fmt ## _seq, \
640 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
641 gen_op_cmp ## type ## _ ## fmt ## _lt, \
642 gen_op_cmp ## type ## _ ## fmt ## _nge, \
643 gen_op_cmp ## type ## _ ## fmt ## _le, \
644 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
646 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
648 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
658 typedef struct DisasContext
{
659 struct TranslationBlock
*tb
;
660 target_ulong pc
, saved_pc
;
663 /* Routine used to access memory */
665 uint32_t hflags
, saved_hflags
;
667 target_ulong btarget
;
673 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
674 * exception condition
676 BS_STOP
= 1, /* We want to stop translation for any reason */
677 BS_BRANCH
= 2, /* We reached a branch condition */
678 BS_EXCP
= 3, /* We reached an exception condition */
681 #ifdef MIPS_DEBUG_DISAS
682 #define MIPS_DEBUG(fmt, args...) \
684 if (loglevel & CPU_LOG_TB_IN_ASM) { \
685 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
686 ctx->pc, ctx->opcode , ##args); \
690 #define MIPS_DEBUG(fmt, args...) do { } while(0)
693 #define MIPS_INVAL(op) \
695 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
696 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
699 #define GEN_LOAD_REG_T0(Rn) \
704 if (ctx->glue(last_T0, _store) != gen_opc_ptr \
705 || ctx->glue(last_T0, _gpr) != Rn) { \
706 gen_op_load_gpr_T0(Rn); \
711 #define GEN_LOAD_REG_T1(Rn) \
716 gen_op_load_gpr_T1(Rn); \
720 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
723 glue(gen_op_reset_, Tn)(); \
725 glue(gen_op_load_srsgpr_, Tn)(Rn); \
729 #define GEN_LOAD_IMM_TN(Tn, Imm) \
732 glue(gen_op_reset_, Tn)(); \
734 glue(gen_op_set_, Tn)(Imm); \
738 #define GEN_STORE_T0_REG(Rn) \
741 gen_op_store_gpr_T0(Rn); \
742 ctx->glue(last_T0,_store) = gen_opc_ptr; \
743 ctx->glue(last_T0,_gpr) = Rn; \
747 #define GEN_STORE_T1_REG(Rn) \
750 gen_op_store_gpr_T1(Rn); \
753 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
756 glue(gen_op_store_srsgpr_, Tn)(Rn); \
759 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
761 glue(gen_op_load_fpr_, FTn)(Fn); \
764 #define GEN_STORE_FTN_FREG(Fn, FTn) \
766 glue(gen_op_store_fpr_, FTn)(Fn); \
769 static always_inline
void gen_save_pc(target_ulong pc
)
771 #if defined(TARGET_MIPS64)
772 if (pc
== (int32_t)pc
) {
775 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
782 static always_inline
void gen_save_btarget(target_ulong btarget
)
784 #if defined(TARGET_MIPS64)
785 if (btarget
== (int32_t)btarget
) {
786 gen_op_save_btarget(btarget
);
788 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
791 gen_op_save_btarget(btarget
);
795 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
797 #if defined MIPS_DEBUG_DISAS
798 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
799 fprintf(logfile
, "hflags %08x saved %08x\n",
800 ctx
->hflags
, ctx
->saved_hflags
);
803 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
804 gen_save_pc(ctx
->pc
);
805 ctx
->saved_pc
= ctx
->pc
;
807 if (ctx
->hflags
!= ctx
->saved_hflags
) {
808 gen_op_save_state(ctx
->hflags
);
809 ctx
->saved_hflags
= ctx
->hflags
;
810 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
816 gen_save_btarget(ctx
->btarget
);
822 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
824 ctx
->saved_hflags
= ctx
->hflags
;
825 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
831 ctx
->btarget
= env
->btarget
;
836 static always_inline
void
837 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
839 save_cpu_state(ctx
, 1);
840 tcg_gen_helper_0_2(do_raise_exception_err
, tcg_const_i32(excp
), tcg_const_i32(err
));
841 tcg_gen_helper_0_0(do_interrupt_restart
);
845 static always_inline
void
846 generate_exception (DisasContext
*ctx
, int excp
)
848 save_cpu_state(ctx
, 1);
849 tcg_gen_helper_0_1(do_raise_exception
, tcg_const_i32(excp
));
850 tcg_gen_helper_0_0(do_interrupt_restart
);
854 /* Addresses computation */
855 static inline void gen_op_addr_add (void)
857 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
859 #if defined(TARGET_MIPS64)
860 /* For compatibility with 32-bit code, data reference in user mode
861 with Status_UX = 0 should be casted to 32-bit and sign extended.
862 See the MIPS64 PRA manual, section 4.10. */
864 TCGv r_tmp
= new_tmp();
865 int l1
= gen_new_label();
867 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
868 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
869 tcg_gen_brcond_i32(TCG_COND_NE
, r_tmp
, tcg_const_i32(MIPS_HFLAG_UM
), l1
);
870 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
871 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
872 tcg_gen_brcond_i32(TCG_COND_NE
, r_tmp
, tcg_const_i32(0), l1
);
873 tcg_gen_ext32s_i64(cpu_T
[0], cpu_T
[0]);
880 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
882 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
883 generate_exception_err(ctx
, EXCP_CpU
, 1);
886 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
888 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
889 generate_exception_err(ctx
, EXCP_CpU
, 1);
892 /* Verify that the processor is running with COP1X instructions enabled.
893 This is associated with the nabla symbol in the MIPS32 and MIPS64
896 static always_inline
void check_cop1x(DisasContext
*ctx
)
898 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
899 generate_exception(ctx
, EXCP_RI
);
902 /* Verify that the processor is running with 64-bit floating-point
903 operations enabled. */
905 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
907 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
908 generate_exception(ctx
, EXCP_RI
);
912 * Verify if floating point register is valid; an operation is not defined
913 * if bit 0 of any register specification is set and the FR bit in the
914 * Status register equals zero, since the register numbers specify an
915 * even-odd pair of adjacent coprocessor general registers. When the FR bit
916 * in the Status register equals one, both even and odd register numbers
917 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
919 * Multiple 64 bit wide registers can be checked by calling
920 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
922 void check_cp1_registers(DisasContext
*ctx
, int regs
)
924 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
925 generate_exception(ctx
, EXCP_RI
);
928 /* This code generates a "reserved instruction" exception if the
929 CPU does not support the instruction set corresponding to flags. */
930 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
932 if (unlikely(!(env
->insn_flags
& flags
)))
933 generate_exception(ctx
, EXCP_RI
);
936 /* This code generates a "reserved instruction" exception if 64-bit
937 instructions are not enabled. */
938 static always_inline
void check_mips_64(DisasContext
*ctx
)
940 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
941 generate_exception(ctx
, EXCP_RI
);
944 /* load/store instructions. */
945 #if defined(CONFIG_USER_ONLY)
946 #define op_ldst(name) gen_op_##name##_raw()
947 #define OP_LD_TABLE(width)
948 #define OP_ST_TABLE(width)
950 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
951 #define OP_LD_TABLE(width) \
952 static GenOpFunc *gen_op_l##width[] = { \
953 &gen_op_l##width##_kernel, \
954 &gen_op_l##width##_super, \
955 &gen_op_l##width##_user, \
957 #define OP_ST_TABLE(width) \
958 static GenOpFunc *gen_op_s##width[] = { \
959 &gen_op_s##width##_kernel, \
960 &gen_op_s##width##_super, \
961 &gen_op_s##width##_user, \
965 #if defined(TARGET_MIPS64)
982 #define OP_LD(insn,fname) \
983 void inline op_ldst_##insn(DisasContext *ctx) \
985 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
992 #if defined(TARGET_MIPS64)
998 #define OP_ST(insn,fname) \
999 void inline op_ldst_##insn(DisasContext *ctx) \
1001 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1006 #if defined(TARGET_MIPS64)
1011 #define OP_LD_ATOMIC(insn,fname) \
1012 void inline op_ldst_##insn(DisasContext *ctx) \
1014 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]); \
1015 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
1016 tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1018 OP_LD_ATOMIC(ll
,ld32s
);
1019 #if defined(TARGET_MIPS64)
1020 OP_LD_ATOMIC(lld
,ld64
);
1024 #define OP_ST_ATOMIC(insn,fname,almask) \
1025 void inline op_ldst_##insn(DisasContext *ctx) \
1027 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL); \
1028 int l1 = gen_new_label(); \
1029 int l2 = gen_new_label(); \
1030 int l3 = gen_new_label(); \
1032 tcg_gen_andi_tl(r_tmp, cpu_T[0], almask); \
1033 tcg_gen_brcond_tl(TCG_COND_EQ, r_tmp, tcg_const_tl(0), l1); \
1034 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1035 generate_exception(ctx, EXCP_AdES); \
1036 gen_set_label(l1); \
1037 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1038 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], r_tmp, l2); \
1039 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1040 tcg_gen_movi_tl(cpu_T[0], 1); \
1042 gen_set_label(l2); \
1043 tcg_gen_movi_tl(cpu_T[0], 0); \
1044 gen_set_label(l3); \
1046 OP_ST_ATOMIC(sc
,st32
,0x3);
1047 #if defined(TARGET_MIPS64)
1048 OP_ST_ATOMIC(scd
,st64
,0x7);
1052 void inline op_ldst_lwc1(DisasContext
*ctx
)
1057 void inline op_ldst_ldc1(DisasContext
*ctx
)
1062 void inline op_ldst_swc1(DisasContext
*ctx
)
1067 void inline op_ldst_sdc1(DisasContext
*ctx
)
1072 /* Load and store */
1073 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1074 int base
, int16_t offset
)
1076 const char *opn
= "ldst";
1079 GEN_LOAD_IMM_TN(T0
, offset
);
1080 } else if (offset
== 0) {
1081 gen_op_load_gpr_T0(base
);
1083 gen_op_load_gpr_T0(base
);
1084 gen_op_set_T1(offset
);
1087 /* Don't do NOP if destination is zero: we must perform the actual
1090 #if defined(TARGET_MIPS64)
1093 GEN_STORE_T0_REG(rt
);
1098 GEN_STORE_T0_REG(rt
);
1103 GEN_STORE_T0_REG(rt
);
1107 GEN_LOAD_REG_T1(rt
);
1112 save_cpu_state(ctx
, 1);
1113 GEN_LOAD_REG_T1(rt
);
1115 GEN_STORE_T0_REG(rt
);
1119 GEN_LOAD_REG_T1(rt
);
1121 GEN_STORE_T1_REG(rt
);
1125 GEN_LOAD_REG_T1(rt
);
1130 GEN_LOAD_REG_T1(rt
);
1132 GEN_STORE_T1_REG(rt
);
1136 GEN_LOAD_REG_T1(rt
);
1143 GEN_STORE_T0_REG(rt
);
1147 GEN_LOAD_REG_T1(rt
);
1153 GEN_STORE_T0_REG(rt
);
1157 GEN_LOAD_REG_T1(rt
);
1163 GEN_STORE_T0_REG(rt
);
1168 GEN_STORE_T0_REG(rt
);
1172 GEN_LOAD_REG_T1(rt
);
1178 GEN_STORE_T0_REG(rt
);
1182 GEN_LOAD_REG_T1(rt
);
1184 GEN_STORE_T1_REG(rt
);
1188 GEN_LOAD_REG_T1(rt
);
1193 GEN_LOAD_REG_T1(rt
);
1195 GEN_STORE_T1_REG(rt
);
1199 GEN_LOAD_REG_T1(rt
);
1205 GEN_STORE_T0_REG(rt
);
1209 save_cpu_state(ctx
, 1);
1210 GEN_LOAD_REG_T1(rt
);
1212 GEN_STORE_T0_REG(rt
);
1217 generate_exception(ctx
, EXCP_RI
);
1220 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1223 /* Load and store */
1224 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1225 int base
, int16_t offset
)
1227 const char *opn
= "flt_ldst";
1230 GEN_LOAD_IMM_TN(T0
, offset
);
1231 } else if (offset
== 0) {
1232 gen_op_load_gpr_T0(base
);
1234 gen_op_load_gpr_T0(base
);
1235 gen_op_set_T1(offset
);
1238 /* Don't do NOP if destination is zero: we must perform the actual
1243 GEN_STORE_FTN_FREG(ft
, WT0
);
1247 GEN_LOAD_FREG_FTN(WT0
, ft
);
1253 GEN_STORE_FTN_FREG(ft
, DT0
);
1257 GEN_LOAD_FREG_FTN(DT0
, ft
);
1263 generate_exception(ctx
, EXCP_RI
);
1266 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1269 /* Arithmetic with immediate operand */
1270 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1271 int rt
, int rs
, int16_t imm
)
1274 const char *opn
= "imm arith";
1276 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1277 /* If no destination, treat it as a NOP.
1278 For addi, we must generate the overflow exception when needed. */
1282 uimm
= (uint16_t)imm
;
1286 #if defined(TARGET_MIPS64)
1292 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1293 GEN_LOAD_IMM_TN(T1
, uimm
);
1298 GEN_LOAD_REG_T0(rs
);
1301 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1306 #if defined(TARGET_MIPS64)
1315 GEN_LOAD_REG_T0(rs
);
1321 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1322 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1323 int l1
= gen_new_label();
1325 save_cpu_state(ctx
, 1);
1326 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1327 tcg_gen_addi_tl(cpu_T
[0], r_tmp1
, uimm
);
1329 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1330 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1331 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1332 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1333 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1334 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1335 /* operands of same sign, result different sign */
1336 generate_exception(ctx
, EXCP_OVERFLOW
);
1339 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1344 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1345 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1346 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1349 #if defined(TARGET_MIPS64)
1352 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1353 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1354 int l1
= gen_new_label();
1356 save_cpu_state(ctx
, 1);
1357 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1358 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1360 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1361 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1362 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1363 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1364 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1365 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1366 /* operands of same sign, result different sign */
1367 generate_exception(ctx
, EXCP_OVERFLOW
);
1373 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1386 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1390 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1394 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1401 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1402 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1403 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1407 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1408 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1409 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1413 switch ((ctx
->opcode
>> 21) & 0x1f) {
1415 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1416 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1417 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1421 /* rotr is decoded as srl on non-R2 CPUs */
1422 if (env
->insn_flags
& ISA_MIPS32R2
) {
1424 TCGv r_tmp1
= new_tmp();
1425 TCGv r_tmp2
= new_tmp();
1427 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1428 tcg_gen_movi_i32(r_tmp2
, 0x20);
1429 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1430 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1431 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1432 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1433 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1439 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1440 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1441 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1446 MIPS_INVAL("invalid srl flag");
1447 generate_exception(ctx
, EXCP_RI
);
1451 #if defined(TARGET_MIPS64)
1453 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1457 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1461 switch ((ctx
->opcode
>> 21) & 0x1f) {
1463 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1467 /* drotr is decoded as dsrl on non-R2 CPUs */
1468 if (env
->insn_flags
& ISA_MIPS32R2
) {
1470 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1472 tcg_gen_movi_tl(r_tmp1
, 0x40);
1473 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1474 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1475 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1476 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1480 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1485 MIPS_INVAL("invalid dsrl flag");
1486 generate_exception(ctx
, EXCP_RI
);
1491 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1495 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1499 switch ((ctx
->opcode
>> 21) & 0x1f) {
1501 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1505 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1506 if (env
->insn_flags
& ISA_MIPS32R2
) {
1507 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1508 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1510 tcg_gen_movi_tl(r_tmp1
, 0x40);
1511 tcg_gen_movi_tl(r_tmp2
, 32);
1512 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1513 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1514 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1515 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], r_tmp2
);
1516 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1519 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1524 MIPS_INVAL("invalid dsrl32 flag");
1525 generate_exception(ctx
, EXCP_RI
);
1532 generate_exception(ctx
, EXCP_RI
);
1535 GEN_STORE_T0_REG(rt
);
1536 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1540 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1541 int rd
, int rs
, int rt
)
1543 const char *opn
= "arith";
1545 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1546 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1547 /* If no destination, treat it as a NOP.
1548 For add & sub, we must generate the overflow exception when needed. */
1552 GEN_LOAD_REG_T0(rs
);
1553 /* Specialcase the conventional move operation. */
1554 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1555 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1556 GEN_STORE_T0_REG(rd
);
1559 GEN_LOAD_REG_T1(rt
);
1563 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1564 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1565 int l1
= gen_new_label();
1567 save_cpu_state(ctx
, 1);
1568 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1569 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1570 tcg_gen_add_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1572 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1573 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1574 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1575 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1576 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1577 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1578 /* operands of same sign, result different sign */
1579 generate_exception(ctx
, EXCP_OVERFLOW
);
1582 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1587 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1588 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1589 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1590 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1595 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1596 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1597 int l1
= gen_new_label();
1599 save_cpu_state(ctx
, 1);
1600 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1601 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1602 tcg_gen_sub_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1604 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1605 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1606 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1607 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1608 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1609 /* operands of different sign, first operand and result different sign */
1610 generate_exception(ctx
, EXCP_OVERFLOW
);
1613 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1618 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1619 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1620 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1621 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1624 #if defined(TARGET_MIPS64)
1627 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1628 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1629 int l1
= gen_new_label();
1631 save_cpu_state(ctx
, 1);
1632 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1633 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1635 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1636 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1637 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1638 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1639 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1640 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1641 /* operands of same sign, result different sign */
1642 generate_exception(ctx
, EXCP_OVERFLOW
);
1648 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1653 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1654 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1655 int l1
= gen_new_label();
1657 save_cpu_state(ctx
, 1);
1658 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1659 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1661 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1662 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1663 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1664 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1665 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
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]);
1718 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1719 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1720 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1721 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1722 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1726 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1727 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1728 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1729 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1733 switch ((ctx
->opcode
>> 6) & 0x1f) {
1735 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1736 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1737 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1738 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1742 /* rotrv is decoded as srlv on non-R2 CPUs */
1743 if (env
->insn_flags
& ISA_MIPS32R2
) {
1744 int l1
= gen_new_label();
1745 int l2
= gen_new_label();
1747 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1748 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[0], tcg_const_tl(0), l1
);
1750 TCGv r_tmp1
= new_tmp();
1751 TCGv r_tmp2
= new_tmp();
1752 TCGv r_tmp3
= new_tmp();
1754 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1755 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1756 tcg_gen_movi_i32(r_tmp3
, 0x20);
1757 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1758 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1759 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1760 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1761 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1768 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1772 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1773 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1774 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1775 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1780 MIPS_INVAL("invalid srlv flag");
1781 generate_exception(ctx
, EXCP_RI
);
1785 #if defined(TARGET_MIPS64)
1787 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1788 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1792 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1793 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1797 switch ((ctx
->opcode
>> 6) & 0x1f) {
1799 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1800 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1804 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1805 if (env
->insn_flags
& ISA_MIPS32R2
) {
1806 int l1
= gen_new_label();
1807 int l2
= gen_new_label();
1809 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1810 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[0], tcg_const_tl(0), l1
);
1812 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1814 tcg_gen_movi_tl(r_tmp1
, 0x40);
1815 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1816 tcg_gen_shl_tl(r_tmp1
, cpu_T
[1], r_tmp1
);
1817 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1818 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1822 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1826 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1827 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1832 MIPS_INVAL("invalid dsrlv flag");
1833 generate_exception(ctx
, EXCP_RI
);
1840 generate_exception(ctx
, EXCP_RI
);
1843 GEN_STORE_T0_REG(rd
);
1845 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1848 /* Arithmetic on HI/LO registers */
1849 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1851 const char *opn
= "hilo";
1853 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1861 GEN_STORE_T0_REG(reg
);
1866 GEN_STORE_T0_REG(reg
);
1870 GEN_LOAD_REG_T0(reg
);
1875 GEN_LOAD_REG_T0(reg
);
1881 generate_exception(ctx
, EXCP_RI
);
1884 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1887 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1890 const char *opn
= "mul/div";
1892 GEN_LOAD_REG_T0(rs
);
1893 GEN_LOAD_REG_T1(rt
);
1897 int l1
= gen_new_label();
1899 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1901 TCGv r_tmp1
= new_tmp();
1902 TCGv r_tmp2
= new_tmp();
1903 TCGv r_tmp3
= new_tmp();
1904 TCGv r_tc_off
= new_tmp();
1905 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1906 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1908 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1909 tcg_gen_ext_i32_tl(r_tmp2
, cpu_T
[1]);
1910 tcg_gen_div_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1911 tcg_gen_rem_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1912 tcg_gen_trunc_tl_i32(cpu_T
[0], r_tmp3
);
1913 tcg_gen_trunc_tl_i32(cpu_T
[1], r_tmp1
);
1917 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1918 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1919 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1920 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1921 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1922 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
1931 int l1
= gen_new_label();
1933 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1935 TCGv r_tmp1
= new_tmp();
1936 TCGv r_tmp2
= new_tmp();
1937 TCGv r_tmp3
= new_tmp();
1938 TCGv r_tc_off
= new_tmp();
1939 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1940 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1942 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1943 tcg_gen_ext_i32_tl(r_tmp2
, cpu_T
[1]);
1944 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1945 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1946 tcg_gen_trunc_tl_i32(cpu_T
[0], r_tmp3
);
1947 tcg_gen_trunc_tl_i32(cpu_T
[1], r_tmp1
);
1951 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1952 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1953 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1954 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1955 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1956 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
1971 #if defined(TARGET_MIPS64)
1974 int l1
= gen_new_label();
1976 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1978 TCGv r_tc_off
= new_tmp();
1979 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1980 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1981 int l2
= gen_new_label();
1982 int l3
= gen_new_label();
1984 tcg_gen_brcond_tl(TCG_COND_NE
, cpu_T
[0], tcg_const_tl(1ULL << 63), l2
);
1985 tcg_gen_brcond_tl(TCG_COND_NE
, cpu_T
[1], tcg_const_tl(-1ULL), l2
);
1986 tcg_gen_div_i64(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1987 tcg_gen_movi_tl(cpu_T
[1], 0);
1990 tcg_gen_div_i64(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1991 tcg_gen_rem_i64(cpu_T
[1], cpu_T
[0], cpu_T
[1]);
1994 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1995 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1996 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1997 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1998 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1999 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
2008 int l1
= gen_new_label();
2010 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
2012 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2013 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2014 TCGv r_tc_off
= new_tmp();
2015 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
2016 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
2018 tcg_gen_divu_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
2019 tcg_gen_remu_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
2020 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
2021 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
2022 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
2023 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
2024 tcg_gen_st_tl(r_tmp1
, r_ptr
, offsetof(CPUState
, LO
));
2025 tcg_gen_st_tl(r_tmp2
, r_ptr
, offsetof(CPUState
, HI
));
2059 generate_exception(ctx
, EXCP_RI
);
2062 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2065 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2066 int rd
, int rs
, int rt
)
2068 const char *opn
= "mul vr54xx";
2070 GEN_LOAD_REG_T0(rs
);
2071 GEN_LOAD_REG_T1(rt
);
2074 case OPC_VR54XX_MULS
:
2078 case OPC_VR54XX_MULSU
:
2082 case OPC_VR54XX_MACC
:
2086 case OPC_VR54XX_MACCU
:
2090 case OPC_VR54XX_MSAC
:
2094 case OPC_VR54XX_MSACU
:
2098 case OPC_VR54XX_MULHI
:
2102 case OPC_VR54XX_MULHIU
:
2106 case OPC_VR54XX_MULSHI
:
2110 case OPC_VR54XX_MULSHIU
:
2114 case OPC_VR54XX_MACCHI
:
2118 case OPC_VR54XX_MACCHIU
:
2122 case OPC_VR54XX_MSACHI
:
2126 case OPC_VR54XX_MSACHIU
:
2131 MIPS_INVAL("mul vr54xx");
2132 generate_exception(ctx
, EXCP_RI
);
2135 GEN_STORE_T0_REG(rd
);
2136 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2139 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2142 const char *opn
= "CLx";
2148 GEN_LOAD_REG_T0(rs
);
2158 #if defined(TARGET_MIPS64)
2170 generate_exception(ctx
, EXCP_RI
);
2173 gen_op_store_gpr_T0(rd
);
2174 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2178 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2179 int rs
, int rt
, int16_t imm
)
2184 /* Load needed operands */
2192 /* Compare two registers */
2194 GEN_LOAD_REG_T0(rs
);
2195 GEN_LOAD_REG_T1(rt
);
2205 /* Compare register to immediate */
2206 if (rs
!= 0 || imm
!= 0) {
2207 GEN_LOAD_REG_T0(rs
);
2208 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
2215 case OPC_TEQ
: /* rs == rs */
2216 case OPC_TEQI
: /* r0 == 0 */
2217 case OPC_TGE
: /* rs >= rs */
2218 case OPC_TGEI
: /* r0 >= 0 */
2219 case OPC_TGEU
: /* rs >= rs unsigned */
2220 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2224 case OPC_TLT
: /* rs < rs */
2225 case OPC_TLTI
: /* r0 < 0 */
2226 case OPC_TLTU
: /* rs < rs unsigned */
2227 case OPC_TLTIU
: /* r0 < 0 unsigned */
2228 case OPC_TNE
: /* rs != rs */
2229 case OPC_TNEI
: /* r0 != 0 */
2230 /* Never trap: treat as NOP. */
2234 generate_exception(ctx
, EXCP_RI
);
2265 generate_exception(ctx
, EXCP_RI
);
2269 save_cpu_state(ctx
, 1);
2271 ctx
->bstate
= BS_STOP
;
2274 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2276 TranslationBlock
*tb
;
2278 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2281 tcg_gen_exit_tb((long)tb
+ n
);
2288 static inline void tcg_gen_set_bcond(void)
2290 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2293 static inline void tcg_gen_jnz_bcond(int label
)
2295 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
2297 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
2298 tcg_gen_brcond_tl(TCG_COND_NE
, r_tmp
, tcg_const_tl(0), label
);
2301 /* Branches (before delay slot) */
2302 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2303 int rs
, int rt
, int32_t offset
)
2305 target_ulong btarget
= -1;
2309 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2310 #ifdef MIPS_DEBUG_DISAS
2311 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2313 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2317 generate_exception(ctx
, EXCP_RI
);
2321 /* Load needed operands */
2327 /* Compare two registers */
2329 GEN_LOAD_REG_T0(rs
);
2330 GEN_LOAD_REG_T1(rt
);
2333 btarget
= ctx
->pc
+ 4 + offset
;
2347 /* Compare to zero */
2349 gen_op_load_gpr_T0(rs
);
2352 btarget
= ctx
->pc
+ 4 + offset
;
2356 /* Jump to immediate */
2357 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2361 /* Jump to register */
2362 if (offset
!= 0 && offset
!= 16) {
2363 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2364 others are reserved. */
2365 MIPS_INVAL("jump hint");
2366 generate_exception(ctx
, EXCP_RI
);
2369 GEN_LOAD_REG_T1(rs
);
2370 gen_op_save_breg_target();
2373 MIPS_INVAL("branch/jump");
2374 generate_exception(ctx
, EXCP_RI
);
2378 /* No condition to be computed */
2380 case OPC_BEQ
: /* rx == rx */
2381 case OPC_BEQL
: /* rx == rx likely */
2382 case OPC_BGEZ
: /* 0 >= 0 */
2383 case OPC_BGEZL
: /* 0 >= 0 likely */
2384 case OPC_BLEZ
: /* 0 <= 0 */
2385 case OPC_BLEZL
: /* 0 <= 0 likely */
2387 ctx
->hflags
|= MIPS_HFLAG_B
;
2388 MIPS_DEBUG("balways");
2390 case OPC_BGEZAL
: /* 0 >= 0 */
2391 case OPC_BGEZALL
: /* 0 >= 0 likely */
2392 /* Always take and link */
2394 ctx
->hflags
|= MIPS_HFLAG_B
;
2395 MIPS_DEBUG("balways and link");
2397 case OPC_BNE
: /* rx != rx */
2398 case OPC_BGTZ
: /* 0 > 0 */
2399 case OPC_BLTZ
: /* 0 < 0 */
2401 MIPS_DEBUG("bnever (NOP)");
2403 case OPC_BLTZAL
: /* 0 < 0 */
2404 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2405 gen_op_store_gpr_T0(31);
2406 MIPS_DEBUG("bnever and link");
2408 case OPC_BLTZALL
: /* 0 < 0 likely */
2409 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2410 gen_op_store_gpr_T0(31);
2411 /* Skip the instruction in the delay slot */
2412 MIPS_DEBUG("bnever, link and skip");
2415 case OPC_BNEL
: /* rx != rx likely */
2416 case OPC_BGTZL
: /* 0 > 0 likely */
2417 case OPC_BLTZL
: /* 0 < 0 likely */
2418 /* Skip the instruction in the delay slot */
2419 MIPS_DEBUG("bnever and skip");
2423 ctx
->hflags
|= MIPS_HFLAG_B
;
2424 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
2428 ctx
->hflags
|= MIPS_HFLAG_B
;
2429 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
2432 ctx
->hflags
|= MIPS_HFLAG_BR
;
2433 MIPS_DEBUG("jr %s", regnames
[rs
]);
2437 ctx
->hflags
|= MIPS_HFLAG_BR
;
2438 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2441 MIPS_INVAL("branch/jump");
2442 generate_exception(ctx
, EXCP_RI
);
2449 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2450 regnames
[rs
], regnames
[rt
], btarget
);
2454 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2455 regnames
[rs
], regnames
[rt
], btarget
);
2459 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2460 regnames
[rs
], regnames
[rt
], btarget
);
2464 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2465 regnames
[rs
], regnames
[rt
], btarget
);
2469 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2473 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2477 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2483 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2487 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2491 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2495 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2499 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2503 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2507 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2512 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2514 ctx
->hflags
|= MIPS_HFLAG_BC
;
2515 tcg_gen_set_bcond();
2520 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2522 ctx
->hflags
|= MIPS_HFLAG_BL
;
2523 tcg_gen_set_bcond();
2526 MIPS_INVAL("conditional branch/jump");
2527 generate_exception(ctx
, EXCP_RI
);
2531 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2532 blink
, ctx
->hflags
, btarget
);
2534 ctx
->btarget
= btarget
;
2536 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2537 gen_op_store_gpr_T0(blink
);
2541 /* special3 bitfield operations */
2542 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2543 int rs
, int lsb
, int msb
)
2545 GEN_LOAD_REG_T1(rs
);
2550 gen_op_ext(lsb
, msb
+ 1);
2552 #if defined(TARGET_MIPS64)
2556 gen_op_dext(lsb
, msb
+ 1 + 32);
2561 gen_op_dext(lsb
+ 32, msb
+ 1);
2566 gen_op_dext(lsb
, msb
+ 1);
2572 GEN_LOAD_REG_T0(rt
);
2573 gen_op_ins(lsb
, msb
- lsb
+ 1);
2575 #if defined(TARGET_MIPS64)
2579 GEN_LOAD_REG_T0(rt
);
2580 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2585 GEN_LOAD_REG_T0(rt
);
2586 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2591 GEN_LOAD_REG_T0(rt
);
2592 gen_op_dins(lsb
, msb
- lsb
+ 1);
2597 MIPS_INVAL("bitops");
2598 generate_exception(ctx
, EXCP_RI
);
2601 GEN_STORE_T0_REG(rt
);
2604 /* CP0 (MMU and control) */
2605 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2607 const char *rn
= "invalid";
2610 check_insn(env
, ctx
, ISA_MIPS32
);
2616 gen_op_mfc0_index();
2620 check_insn(env
, ctx
, ASE_MT
);
2621 gen_op_mfc0_mvpcontrol();
2625 check_insn(env
, ctx
, ASE_MT
);
2626 gen_op_mfc0_mvpconf0();
2630 check_insn(env
, ctx
, ASE_MT
);
2631 gen_op_mfc0_mvpconf1();
2641 gen_op_mfc0_random();
2645 check_insn(env
, ctx
, ASE_MT
);
2646 gen_op_mfc0_vpecontrol();
2650 check_insn(env
, ctx
, ASE_MT
);
2651 gen_op_mfc0_vpeconf0();
2655 check_insn(env
, ctx
, ASE_MT
);
2656 gen_op_mfc0_vpeconf1();
2660 check_insn(env
, ctx
, ASE_MT
);
2661 gen_op_mfc0_yqmask();
2665 check_insn(env
, ctx
, ASE_MT
);
2666 gen_op_mfc0_vpeschedule();
2670 check_insn(env
, ctx
, ASE_MT
);
2671 gen_op_mfc0_vpeschefback();
2672 rn
= "VPEScheFBack";
2675 check_insn(env
, ctx
, ASE_MT
);
2676 gen_op_mfc0_vpeopt();
2686 gen_op_mfc0_entrylo0();
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 gen_op_mfc0_entrylo1();
2741 gen_op_mfc0_context();
2745 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2746 rn
= "ContextConfig";
2755 gen_op_mfc0_pagemask();
2759 check_insn(env
, ctx
, ISA_MIPS32R2
);
2760 gen_op_mfc0_pagegrain();
2770 gen_op_mfc0_wired();
2774 check_insn(env
, ctx
, ISA_MIPS32R2
);
2775 gen_op_mfc0_srsconf0();
2779 check_insn(env
, ctx
, ISA_MIPS32R2
);
2780 gen_op_mfc0_srsconf1();
2784 check_insn(env
, ctx
, ISA_MIPS32R2
);
2785 gen_op_mfc0_srsconf2();
2789 check_insn(env
, ctx
, ISA_MIPS32R2
);
2790 gen_op_mfc0_srsconf3();
2794 check_insn(env
, ctx
, ISA_MIPS32R2
);
2795 gen_op_mfc0_srsconf4();
2805 check_insn(env
, ctx
, ISA_MIPS32R2
);
2806 gen_op_mfc0_hwrena();
2816 gen_op_mfc0_badvaddr();
2826 gen_op_mfc0_count();
2829 /* 6,7 are implementation dependent */
2837 gen_op_mfc0_entryhi();
2847 gen_op_mfc0_compare();
2850 /* 6,7 are implementation dependent */
2858 gen_op_mfc0_status();
2862 check_insn(env
, ctx
, ISA_MIPS32R2
);
2863 gen_op_mfc0_intctl();
2867 check_insn(env
, ctx
, ISA_MIPS32R2
);
2868 gen_op_mfc0_srsctl();
2872 check_insn(env
, ctx
, ISA_MIPS32R2
);
2873 gen_op_mfc0_srsmap();
2883 gen_op_mfc0_cause();
2907 check_insn(env
, ctx
, ISA_MIPS32R2
);
2908 gen_op_mfc0_ebase();
2918 gen_op_mfc0_config0();
2922 gen_op_mfc0_config1();
2926 gen_op_mfc0_config2();
2930 gen_op_mfc0_config3();
2933 /* 4,5 are reserved */
2934 /* 6,7 are implementation dependent */
2936 gen_op_mfc0_config6();
2940 gen_op_mfc0_config7();
2950 gen_op_mfc0_lladdr();
2960 gen_op_mfc0_watchlo(sel
);
2970 gen_op_mfc0_watchhi(sel
);
2980 #if defined(TARGET_MIPS64)
2981 check_insn(env
, ctx
, ISA_MIPS3
);
2982 gen_op_mfc0_xcontext();
2991 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2994 gen_op_mfc0_framemask();
3003 rn
= "'Diagnostic"; /* implementation dependent */
3008 gen_op_mfc0_debug(); /* EJTAG support */
3012 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
3013 rn
= "TraceControl";
3016 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
3017 rn
= "TraceControl2";
3020 // gen_op_mfc0_usertracedata(); /* PDtrace support */
3021 rn
= "UserTraceData";
3024 // gen_op_mfc0_debug(); /* PDtrace support */
3034 gen_op_mfc0_depc(); /* EJTAG support */
3044 gen_op_mfc0_performance0();
3045 rn
= "Performance0";
3048 // gen_op_mfc0_performance1();
3049 rn
= "Performance1";
3052 // gen_op_mfc0_performance2();
3053 rn
= "Performance2";
3056 // gen_op_mfc0_performance3();
3057 rn
= "Performance3";
3060 // gen_op_mfc0_performance4();
3061 rn
= "Performance4";
3064 // gen_op_mfc0_performance5();
3065 rn
= "Performance5";
3068 // gen_op_mfc0_performance6();
3069 rn
= "Performance6";
3072 // gen_op_mfc0_performance7();
3073 rn
= "Performance7";
3098 gen_op_mfc0_taglo();
3105 gen_op_mfc0_datalo();
3118 gen_op_mfc0_taghi();
3125 gen_op_mfc0_datahi();
3135 gen_op_mfc0_errorepc();
3145 gen_op_mfc0_desave(); /* EJTAG support */
3155 #if defined MIPS_DEBUG_DISAS
3156 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3157 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3164 #if defined MIPS_DEBUG_DISAS
3165 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3166 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3170 generate_exception(ctx
, EXCP_RI
);
3173 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3175 const char *rn
= "invalid";
3178 check_insn(env
, ctx
, ISA_MIPS32
);
3184 gen_op_mtc0_index();
3188 check_insn(env
, ctx
, ASE_MT
);
3189 gen_op_mtc0_mvpcontrol();
3193 check_insn(env
, ctx
, ASE_MT
);
3198 check_insn(env
, ctx
, ASE_MT
);
3213 check_insn(env
, ctx
, ASE_MT
);
3214 gen_op_mtc0_vpecontrol();
3218 check_insn(env
, ctx
, ASE_MT
);
3219 gen_op_mtc0_vpeconf0();
3223 check_insn(env
, ctx
, ASE_MT
);
3224 gen_op_mtc0_vpeconf1();
3228 check_insn(env
, ctx
, ASE_MT
);
3229 gen_op_mtc0_yqmask();
3233 check_insn(env
, ctx
, ASE_MT
);
3234 gen_op_mtc0_vpeschedule();
3238 check_insn(env
, ctx
, ASE_MT
);
3239 gen_op_mtc0_vpeschefback();
3240 rn
= "VPEScheFBack";
3243 check_insn(env
, ctx
, ASE_MT
);
3244 gen_op_mtc0_vpeopt();
3254 gen_op_mtc0_entrylo0();
3258 check_insn(env
, ctx
, ASE_MT
);
3259 gen_op_mtc0_tcstatus();
3263 check_insn(env
, ctx
, ASE_MT
);
3264 gen_op_mtc0_tcbind();
3268 check_insn(env
, ctx
, ASE_MT
);
3269 gen_op_mtc0_tcrestart();
3273 check_insn(env
, ctx
, ASE_MT
);
3274 gen_op_mtc0_tchalt();
3278 check_insn(env
, ctx
, ASE_MT
);
3279 gen_op_mtc0_tccontext();
3283 check_insn(env
, ctx
, ASE_MT
);
3284 gen_op_mtc0_tcschedule();
3288 check_insn(env
, ctx
, ASE_MT
);
3289 gen_op_mtc0_tcschefback();
3299 gen_op_mtc0_entrylo1();
3309 gen_op_mtc0_context();
3313 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3314 rn
= "ContextConfig";
3323 gen_op_mtc0_pagemask();
3327 check_insn(env
, ctx
, ISA_MIPS32R2
);
3328 gen_op_mtc0_pagegrain();
3338 gen_op_mtc0_wired();
3342 check_insn(env
, ctx
, ISA_MIPS32R2
);
3343 gen_op_mtc0_srsconf0();
3347 check_insn(env
, ctx
, ISA_MIPS32R2
);
3348 gen_op_mtc0_srsconf1();
3352 check_insn(env
, ctx
, ISA_MIPS32R2
);
3353 gen_op_mtc0_srsconf2();
3357 check_insn(env
, ctx
, ISA_MIPS32R2
);
3358 gen_op_mtc0_srsconf3();
3362 check_insn(env
, ctx
, ISA_MIPS32R2
);
3363 gen_op_mtc0_srsconf4();
3373 check_insn(env
, ctx
, ISA_MIPS32R2
);
3374 gen_op_mtc0_hwrena();
3388 gen_op_mtc0_count();
3391 /* 6,7 are implementation dependent */
3395 /* Stop translation as we may have switched the execution mode */
3396 ctx
->bstate
= BS_STOP
;
3401 gen_op_mtc0_entryhi();
3411 gen_op_mtc0_compare();
3414 /* 6,7 are implementation dependent */
3418 /* Stop translation as we may have switched the execution mode */
3419 ctx
->bstate
= BS_STOP
;
3424 gen_op_mtc0_status();
3425 /* BS_STOP isn't good enough here, hflags may have changed. */
3426 gen_save_pc(ctx
->pc
+ 4);
3427 ctx
->bstate
= BS_EXCP
;
3431 check_insn(env
, ctx
, ISA_MIPS32R2
);
3432 gen_op_mtc0_intctl();
3433 /* Stop translation as we may have switched the execution mode */
3434 ctx
->bstate
= BS_STOP
;
3438 check_insn(env
, ctx
, ISA_MIPS32R2
);
3439 gen_op_mtc0_srsctl();
3440 /* Stop translation as we may have switched the execution mode */
3441 ctx
->bstate
= BS_STOP
;
3445 check_insn(env
, ctx
, ISA_MIPS32R2
);
3446 gen_op_mtc0_srsmap();
3447 /* Stop translation as we may have switched the execution mode */
3448 ctx
->bstate
= BS_STOP
;
3458 gen_op_mtc0_cause();
3464 /* Stop translation as we may have switched the execution mode */
3465 ctx
->bstate
= BS_STOP
;
3484 check_insn(env
, ctx
, ISA_MIPS32R2
);
3485 gen_op_mtc0_ebase();
3495 gen_op_mtc0_config0();
3497 /* Stop translation as we may have switched the execution mode */
3498 ctx
->bstate
= BS_STOP
;
3501 /* ignored, read only */
3505 gen_op_mtc0_config2();
3507 /* Stop translation as we may have switched the execution mode */
3508 ctx
->bstate
= BS_STOP
;
3511 /* ignored, read only */
3514 /* 4,5 are reserved */
3515 /* 6,7 are implementation dependent */
3525 rn
= "Invalid config selector";
3542 gen_op_mtc0_watchlo(sel
);
3552 gen_op_mtc0_watchhi(sel
);
3562 #if defined(TARGET_MIPS64)
3563 check_insn(env
, ctx
, ISA_MIPS3
);
3564 gen_op_mtc0_xcontext();
3573 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3576 gen_op_mtc0_framemask();
3585 rn
= "Diagnostic"; /* implementation dependent */
3590 gen_op_mtc0_debug(); /* EJTAG support */
3591 /* BS_STOP isn't good enough here, hflags may have changed. */
3592 gen_save_pc(ctx
->pc
+ 4);
3593 ctx
->bstate
= BS_EXCP
;
3597 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3598 rn
= "TraceControl";
3599 /* Stop translation as we may have switched the execution mode */
3600 ctx
->bstate
= BS_STOP
;
3603 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3604 rn
= "TraceControl2";
3605 /* Stop translation as we may have switched the execution mode */
3606 ctx
->bstate
= BS_STOP
;
3609 /* Stop translation as we may have switched the execution mode */
3610 ctx
->bstate
= BS_STOP
;
3611 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3612 rn
= "UserTraceData";
3613 /* Stop translation as we may have switched the execution mode */
3614 ctx
->bstate
= BS_STOP
;
3617 // gen_op_mtc0_debug(); /* PDtrace support */
3618 /* Stop translation as we may have switched the execution mode */
3619 ctx
->bstate
= BS_STOP
;
3629 gen_op_mtc0_depc(); /* EJTAG support */
3639 gen_op_mtc0_performance0();
3640 rn
= "Performance0";
3643 // gen_op_mtc0_performance1();
3644 rn
= "Performance1";
3647 // gen_op_mtc0_performance2();
3648 rn
= "Performance2";
3651 // gen_op_mtc0_performance3();
3652 rn
= "Performance3";
3655 // gen_op_mtc0_performance4();
3656 rn
= "Performance4";
3659 // gen_op_mtc0_performance5();
3660 rn
= "Performance5";
3663 // gen_op_mtc0_performance6();
3664 rn
= "Performance6";
3667 // gen_op_mtc0_performance7();
3668 rn
= "Performance7";
3694 gen_op_mtc0_taglo();
3701 gen_op_mtc0_datalo();
3714 gen_op_mtc0_taghi();
3721 gen_op_mtc0_datahi();
3732 gen_op_mtc0_errorepc();
3742 gen_op_mtc0_desave(); /* EJTAG support */
3748 /* Stop translation as we may have switched the execution mode */
3749 ctx
->bstate
= BS_STOP
;
3754 #if defined MIPS_DEBUG_DISAS
3755 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3756 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3763 #if defined MIPS_DEBUG_DISAS
3764 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3765 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3769 generate_exception(ctx
, EXCP_RI
);
3772 #if defined(TARGET_MIPS64)
3773 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3775 const char *rn
= "invalid";
3778 check_insn(env
, ctx
, ISA_MIPS64
);
3784 gen_op_mfc0_index();
3788 check_insn(env
, ctx
, ASE_MT
);
3789 gen_op_mfc0_mvpcontrol();
3793 check_insn(env
, ctx
, ASE_MT
);
3794 gen_op_mfc0_mvpconf0();
3798 check_insn(env
, ctx
, ASE_MT
);
3799 gen_op_mfc0_mvpconf1();
3809 gen_op_mfc0_random();
3813 check_insn(env
, ctx
, ASE_MT
);
3814 gen_op_mfc0_vpecontrol();
3818 check_insn(env
, ctx
, ASE_MT
);
3819 gen_op_mfc0_vpeconf0();
3823 check_insn(env
, ctx
, ASE_MT
);
3824 gen_op_mfc0_vpeconf1();
3828 check_insn(env
, ctx
, ASE_MT
);
3829 gen_op_dmfc0_yqmask();
3833 check_insn(env
, ctx
, ASE_MT
);
3834 gen_op_dmfc0_vpeschedule();
3838 check_insn(env
, ctx
, ASE_MT
);
3839 gen_op_dmfc0_vpeschefback();
3840 rn
= "VPEScheFBack";
3843 check_insn(env
, ctx
, ASE_MT
);
3844 gen_op_mfc0_vpeopt();
3854 gen_op_dmfc0_entrylo0();
3858 check_insn(env
, ctx
, ASE_MT
);
3859 gen_op_mfc0_tcstatus();
3863 check_insn(env
, ctx
, ASE_MT
);
3864 gen_op_mfc0_tcbind();
3868 check_insn(env
, ctx
, ASE_MT
);
3869 gen_op_dmfc0_tcrestart();
3873 check_insn(env
, ctx
, ASE_MT
);
3874 gen_op_dmfc0_tchalt();
3878 check_insn(env
, ctx
, ASE_MT
);
3879 gen_op_dmfc0_tccontext();
3883 check_insn(env
, ctx
, ASE_MT
);
3884 gen_op_dmfc0_tcschedule();
3888 check_insn(env
, ctx
, ASE_MT
);
3889 gen_op_dmfc0_tcschefback();
3899 gen_op_dmfc0_entrylo1();
3909 gen_op_dmfc0_context();
3913 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3914 rn
= "ContextConfig";
3923 gen_op_mfc0_pagemask();
3927 check_insn(env
, ctx
, ISA_MIPS32R2
);
3928 gen_op_mfc0_pagegrain();
3938 gen_op_mfc0_wired();
3942 check_insn(env
, ctx
, ISA_MIPS32R2
);
3943 gen_op_mfc0_srsconf0();
3947 check_insn(env
, ctx
, ISA_MIPS32R2
);
3948 gen_op_mfc0_srsconf1();
3952 check_insn(env
, ctx
, ISA_MIPS32R2
);
3953 gen_op_mfc0_srsconf2();
3957 check_insn(env
, ctx
, ISA_MIPS32R2
);
3958 gen_op_mfc0_srsconf3();
3962 check_insn(env
, ctx
, ISA_MIPS32R2
);
3963 gen_op_mfc0_srsconf4();
3973 check_insn(env
, ctx
, ISA_MIPS32R2
);
3974 gen_op_mfc0_hwrena();
3984 gen_op_dmfc0_badvaddr();
3994 gen_op_mfc0_count();
3997 /* 6,7 are implementation dependent */
4005 gen_op_dmfc0_entryhi();
4015 gen_op_mfc0_compare();
4018 /* 6,7 are implementation dependent */
4026 gen_op_mfc0_status();
4030 check_insn(env
, ctx
, ISA_MIPS32R2
);
4031 gen_op_mfc0_intctl();
4035 check_insn(env
, ctx
, ISA_MIPS32R2
);
4036 gen_op_mfc0_srsctl();
4040 check_insn(env
, ctx
, ISA_MIPS32R2
);
4041 gen_op_mfc0_srsmap();
4051 gen_op_mfc0_cause();
4075 check_insn(env
, ctx
, ISA_MIPS32R2
);
4076 gen_op_mfc0_ebase();
4086 gen_op_mfc0_config0();
4090 gen_op_mfc0_config1();
4094 gen_op_mfc0_config2();
4098 gen_op_mfc0_config3();
4101 /* 6,7 are implementation dependent */
4109 gen_op_dmfc0_lladdr();
4119 gen_op_dmfc0_watchlo(sel
);
4129 gen_op_mfc0_watchhi(sel
);
4139 check_insn(env
, ctx
, ISA_MIPS3
);
4140 gen_op_dmfc0_xcontext();
4148 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4151 gen_op_mfc0_framemask();
4160 rn
= "'Diagnostic"; /* implementation dependent */
4165 gen_op_mfc0_debug(); /* EJTAG support */
4169 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
4170 rn
= "TraceControl";
4173 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
4174 rn
= "TraceControl2";
4177 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
4178 rn
= "UserTraceData";
4181 // gen_op_dmfc0_debug(); /* PDtrace support */
4191 gen_op_dmfc0_depc(); /* EJTAG support */
4201 gen_op_mfc0_performance0();
4202 rn
= "Performance0";
4205 // gen_op_dmfc0_performance1();
4206 rn
= "Performance1";
4209 // gen_op_dmfc0_performance2();
4210 rn
= "Performance2";
4213 // gen_op_dmfc0_performance3();
4214 rn
= "Performance3";
4217 // gen_op_dmfc0_performance4();
4218 rn
= "Performance4";
4221 // gen_op_dmfc0_performance5();
4222 rn
= "Performance5";
4225 // gen_op_dmfc0_performance6();
4226 rn
= "Performance6";
4229 // gen_op_dmfc0_performance7();
4230 rn
= "Performance7";
4255 gen_op_mfc0_taglo();
4262 gen_op_mfc0_datalo();
4275 gen_op_mfc0_taghi();
4282 gen_op_mfc0_datahi();
4292 gen_op_dmfc0_errorepc();
4302 gen_op_mfc0_desave(); /* EJTAG support */
4312 #if defined MIPS_DEBUG_DISAS
4313 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4314 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4321 #if defined MIPS_DEBUG_DISAS
4322 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4323 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4327 generate_exception(ctx
, EXCP_RI
);
4330 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
4332 const char *rn
= "invalid";
4335 check_insn(env
, ctx
, ISA_MIPS64
);
4341 gen_op_mtc0_index();
4345 check_insn(env
, ctx
, ASE_MT
);
4346 gen_op_mtc0_mvpcontrol();
4350 check_insn(env
, ctx
, ASE_MT
);
4355 check_insn(env
, ctx
, ASE_MT
);
4370 check_insn(env
, ctx
, ASE_MT
);
4371 gen_op_mtc0_vpecontrol();
4375 check_insn(env
, ctx
, ASE_MT
);
4376 gen_op_mtc0_vpeconf0();
4380 check_insn(env
, ctx
, ASE_MT
);
4381 gen_op_mtc0_vpeconf1();
4385 check_insn(env
, ctx
, ASE_MT
);
4386 gen_op_mtc0_yqmask();
4390 check_insn(env
, ctx
, ASE_MT
);
4391 gen_op_mtc0_vpeschedule();
4395 check_insn(env
, ctx
, ASE_MT
);
4396 gen_op_mtc0_vpeschefback();
4397 rn
= "VPEScheFBack";
4400 check_insn(env
, ctx
, ASE_MT
);
4401 gen_op_mtc0_vpeopt();
4411 gen_op_mtc0_entrylo0();
4415 check_insn(env
, ctx
, ASE_MT
);
4416 gen_op_mtc0_tcstatus();
4420 check_insn(env
, ctx
, ASE_MT
);
4421 gen_op_mtc0_tcbind();
4425 check_insn(env
, ctx
, ASE_MT
);
4426 gen_op_mtc0_tcrestart();
4430 check_insn(env
, ctx
, ASE_MT
);
4431 gen_op_mtc0_tchalt();
4435 check_insn(env
, ctx
, ASE_MT
);
4436 gen_op_mtc0_tccontext();
4440 check_insn(env
, ctx
, ASE_MT
);
4441 gen_op_mtc0_tcschedule();
4445 check_insn(env
, ctx
, ASE_MT
);
4446 gen_op_mtc0_tcschefback();
4456 gen_op_mtc0_entrylo1();
4466 gen_op_mtc0_context();
4470 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
4471 rn
= "ContextConfig";
4480 gen_op_mtc0_pagemask();
4484 check_insn(env
, ctx
, ISA_MIPS32R2
);
4485 gen_op_mtc0_pagegrain();
4495 gen_op_mtc0_wired();
4499 check_insn(env
, ctx
, ISA_MIPS32R2
);
4500 gen_op_mtc0_srsconf0();
4504 check_insn(env
, ctx
, ISA_MIPS32R2
);
4505 gen_op_mtc0_srsconf1();
4509 check_insn(env
, ctx
, ISA_MIPS32R2
);
4510 gen_op_mtc0_srsconf2();
4514 check_insn(env
, ctx
, ISA_MIPS32R2
);
4515 gen_op_mtc0_srsconf3();
4519 check_insn(env
, ctx
, ISA_MIPS32R2
);
4520 gen_op_mtc0_srsconf4();
4530 check_insn(env
, ctx
, ISA_MIPS32R2
);
4531 gen_op_mtc0_hwrena();
4545 gen_op_mtc0_count();
4548 /* 6,7 are implementation dependent */
4552 /* Stop translation as we may have switched the execution mode */
4553 ctx
->bstate
= BS_STOP
;
4558 gen_op_mtc0_entryhi();
4568 gen_op_mtc0_compare();
4571 /* 6,7 are implementation dependent */
4575 /* Stop translation as we may have switched the execution mode */
4576 ctx
->bstate
= BS_STOP
;
4581 gen_op_mtc0_status();
4582 /* BS_STOP isn't good enough here, hflags may have changed. */
4583 gen_save_pc(ctx
->pc
+ 4);
4584 ctx
->bstate
= BS_EXCP
;
4588 check_insn(env
, ctx
, ISA_MIPS32R2
);
4589 gen_op_mtc0_intctl();
4590 /* Stop translation as we may have switched the execution mode */
4591 ctx
->bstate
= BS_STOP
;
4595 check_insn(env
, ctx
, ISA_MIPS32R2
);
4596 gen_op_mtc0_srsctl();
4597 /* Stop translation as we may have switched the execution mode */
4598 ctx
->bstate
= BS_STOP
;
4602 check_insn(env
, ctx
, ISA_MIPS32R2
);
4603 gen_op_mtc0_srsmap();
4604 /* Stop translation as we may have switched the execution mode */
4605 ctx
->bstate
= BS_STOP
;
4615 gen_op_mtc0_cause();
4621 /* Stop translation as we may have switched the execution mode */
4622 ctx
->bstate
= BS_STOP
;
4641 check_insn(env
, ctx
, ISA_MIPS32R2
);
4642 gen_op_mtc0_ebase();
4652 gen_op_mtc0_config0();
4654 /* Stop translation as we may have switched the execution mode */
4655 ctx
->bstate
= BS_STOP
;
4662 gen_op_mtc0_config2();
4664 /* Stop translation as we may have switched the execution mode */
4665 ctx
->bstate
= BS_STOP
;
4671 /* 6,7 are implementation dependent */
4673 rn
= "Invalid config selector";
4690 gen_op_mtc0_watchlo(sel
);
4700 gen_op_mtc0_watchhi(sel
);
4710 check_insn(env
, ctx
, ISA_MIPS3
);
4711 gen_op_mtc0_xcontext();
4719 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4722 gen_op_mtc0_framemask();
4731 rn
= "Diagnostic"; /* implementation dependent */
4736 gen_op_mtc0_debug(); /* EJTAG support */
4737 /* BS_STOP isn't good enough here, hflags may have changed. */
4738 gen_save_pc(ctx
->pc
+ 4);
4739 ctx
->bstate
= BS_EXCP
;
4743 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4744 /* Stop translation as we may have switched the execution mode */
4745 ctx
->bstate
= BS_STOP
;
4746 rn
= "TraceControl";
4749 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4750 /* Stop translation as we may have switched the execution mode */
4751 ctx
->bstate
= BS_STOP
;
4752 rn
= "TraceControl2";
4755 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4756 /* Stop translation as we may have switched the execution mode */
4757 ctx
->bstate
= BS_STOP
;
4758 rn
= "UserTraceData";
4761 // gen_op_mtc0_debug(); /* PDtrace support */
4762 /* Stop translation as we may have switched the execution mode */
4763 ctx
->bstate
= BS_STOP
;
4773 gen_op_mtc0_depc(); /* EJTAG support */
4783 gen_op_mtc0_performance0();
4784 rn
= "Performance0";
4787 // gen_op_mtc0_performance1();
4788 rn
= "Performance1";
4791 // gen_op_mtc0_performance2();
4792 rn
= "Performance2";
4795 // gen_op_mtc0_performance3();
4796 rn
= "Performance3";
4799 // gen_op_mtc0_performance4();
4800 rn
= "Performance4";
4803 // gen_op_mtc0_performance5();
4804 rn
= "Performance5";
4807 // gen_op_mtc0_performance6();
4808 rn
= "Performance6";
4811 // gen_op_mtc0_performance7();
4812 rn
= "Performance7";
4838 gen_op_mtc0_taglo();
4845 gen_op_mtc0_datalo();
4858 gen_op_mtc0_taghi();
4865 gen_op_mtc0_datahi();
4876 gen_op_mtc0_errorepc();
4886 gen_op_mtc0_desave(); /* EJTAG support */
4892 /* Stop translation as we may have switched the execution mode */
4893 ctx
->bstate
= BS_STOP
;
4898 #if defined MIPS_DEBUG_DISAS
4899 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4900 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4907 #if defined MIPS_DEBUG_DISAS
4908 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4909 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4913 generate_exception(ctx
, EXCP_RI
);
4915 #endif /* TARGET_MIPS64 */
4917 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4918 int u
, int sel
, int h
)
4920 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4922 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4923 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4924 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4926 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4927 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4934 gen_op_mftc0_tcstatus();
4937 gen_op_mftc0_tcbind();
4940 gen_op_mftc0_tcrestart();
4943 gen_op_mftc0_tchalt();
4946 gen_op_mftc0_tccontext();
4949 gen_op_mftc0_tcschedule();
4952 gen_op_mftc0_tcschefback();
4955 gen_mfc0(env
, ctx
, rt
, sel
);
4962 gen_op_mftc0_entryhi();
4965 gen_mfc0(env
, ctx
, rt
, sel
);
4971 gen_op_mftc0_status();
4974 gen_mfc0(env
, ctx
, rt
, sel
);
4980 gen_op_mftc0_debug();
4983 gen_mfc0(env
, ctx
, rt
, sel
);
4988 gen_mfc0(env
, ctx
, rt
, sel
);
4990 } else switch (sel
) {
4991 /* GPR registers. */
4995 /* Auxiliary CPU registers */
5041 /* Floating point (COP1). */
5043 /* XXX: For now we support only a single FPU context. */
5045 GEN_LOAD_FREG_FTN(WT0
, rt
);
5048 GEN_LOAD_FREG_FTN(WTH0
, rt
);
5053 /* XXX: For now we support only a single FPU context. */
5056 /* COP2: Not implemented. */
5063 #if defined MIPS_DEBUG_DISAS
5064 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5065 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5072 #if defined MIPS_DEBUG_DISAS
5073 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5074 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5078 generate_exception(ctx
, EXCP_RI
);
5081 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
5082 int u
, int sel
, int h
)
5084 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5086 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5087 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5088 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5090 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5091 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5098 gen_op_mttc0_tcstatus();
5101 gen_op_mttc0_tcbind();
5104 gen_op_mttc0_tcrestart();
5107 gen_op_mttc0_tchalt();
5110 gen_op_mttc0_tccontext();
5113 gen_op_mttc0_tcschedule();
5116 gen_op_mttc0_tcschefback();
5119 gen_mtc0(env
, ctx
, rd
, sel
);
5126 gen_op_mttc0_entryhi();
5129 gen_mtc0(env
, ctx
, rd
, sel
);
5135 gen_op_mttc0_status();
5138 gen_mtc0(env
, ctx
, rd
, sel
);
5144 gen_op_mttc0_debug();
5147 gen_mtc0(env
, ctx
, rd
, sel
);
5152 gen_mtc0(env
, ctx
, rd
, sel
);
5154 } else switch (sel
) {
5155 /* GPR registers. */
5159 /* Auxiliary CPU registers */
5205 /* Floating point (COP1). */
5207 /* XXX: For now we support only a single FPU context. */
5210 GEN_STORE_FTN_FREG(rd
, WT0
);
5213 GEN_STORE_FTN_FREG(rd
, WTH0
);
5217 /* XXX: For now we support only a single FPU context. */
5220 /* COP2: Not implemented. */
5227 #if defined MIPS_DEBUG_DISAS
5228 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5229 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5236 #if defined MIPS_DEBUG_DISAS
5237 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5238 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5242 generate_exception(ctx
, EXCP_RI
);
5245 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5247 const char *opn
= "ldst";
5255 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5256 gen_op_store_gpr_T0(rt
);
5260 GEN_LOAD_REG_T0(rt
);
5261 save_cpu_state(ctx
, 1);
5262 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5265 #if defined(TARGET_MIPS64)
5267 check_insn(env
, ctx
, ISA_MIPS3
);
5272 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5273 gen_op_store_gpr_T0(rt
);
5277 check_insn(env
, ctx
, ISA_MIPS3
);
5278 GEN_LOAD_REG_T0(rt
);
5279 save_cpu_state(ctx
, 1);
5280 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5285 check_insn(env
, ctx
, ASE_MT
);
5290 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
5291 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5292 gen_op_store_gpr_T0(rd
);
5296 check_insn(env
, ctx
, ASE_MT
);
5297 GEN_LOAD_REG_T0(rt
);
5298 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
5299 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5304 if (!env
->tlb
->do_tlbwi
)
5310 if (!env
->tlb
->do_tlbwr
)
5316 if (!env
->tlb
->do_tlbp
)
5322 if (!env
->tlb
->do_tlbr
)
5328 check_insn(env
, ctx
, ISA_MIPS2
);
5329 save_cpu_state(ctx
, 1);
5331 ctx
->bstate
= BS_EXCP
;
5335 check_insn(env
, ctx
, ISA_MIPS32
);
5336 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5338 generate_exception(ctx
, EXCP_RI
);
5340 save_cpu_state(ctx
, 1);
5342 ctx
->bstate
= BS_EXCP
;
5347 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5348 /* If we get an exception, we want to restart at next instruction */
5350 save_cpu_state(ctx
, 1);
5353 ctx
->bstate
= BS_EXCP
;
5358 generate_exception(ctx
, EXCP_RI
);
5361 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5364 /* CP1 Branches (before delay slot) */
5365 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5366 int32_t cc
, int32_t offset
)
5368 target_ulong btarget
;
5369 const char *opn
= "cp1 cond branch";
5372 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5374 btarget
= ctx
->pc
+ 4 + offset
;
5393 ctx
->hflags
|= MIPS_HFLAG_BL
;
5394 tcg_gen_set_bcond();
5397 gen_op_bc1any2f(cc
);
5401 gen_op_bc1any2t(cc
);
5405 gen_op_bc1any4f(cc
);
5409 gen_op_bc1any4t(cc
);
5412 ctx
->hflags
|= MIPS_HFLAG_BC
;
5413 tcg_gen_set_bcond();
5417 generate_exception (ctx
, EXCP_RI
);
5420 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5421 ctx
->hflags
, btarget
);
5422 ctx
->btarget
= btarget
;
5425 /* Coprocessor 1 (FPU) */
5427 #define FOP(func, fmt) (((fmt) << 21) | (func))
5429 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5431 const char *opn
= "cp1 move";
5435 GEN_LOAD_FREG_FTN(WT0
, fs
);
5437 GEN_STORE_T0_REG(rt
);
5441 GEN_LOAD_REG_T0(rt
);
5443 GEN_STORE_FTN_FREG(fs
, WT0
);
5448 GEN_STORE_T0_REG(rt
);
5452 GEN_LOAD_REG_T0(rt
);
5457 GEN_LOAD_FREG_FTN(DT0
, fs
);
5459 GEN_STORE_T0_REG(rt
);
5463 GEN_LOAD_REG_T0(rt
);
5465 GEN_STORE_FTN_FREG(fs
, DT0
);
5469 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5471 GEN_STORE_T0_REG(rt
);
5475 GEN_LOAD_REG_T0(rt
);
5477 GEN_STORE_FTN_FREG(fs
, WTH0
);
5482 generate_exception (ctx
, EXCP_RI
);
5485 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5488 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5492 GEN_LOAD_REG_T0(rd
);
5493 GEN_LOAD_REG_T1(rs
);
5495 ccbit
= 1 << (24 + cc
);
5502 GEN_STORE_T0_REG(rd
);
5505 #define GEN_MOVCF(fmt) \
5506 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
5511 ccbit = 1 << (24 + cc); \
5515 glue(gen_op_float_movf_, fmt)(ccbit); \
5517 glue(gen_op_float_movt_, fmt)(ccbit); \
5524 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5525 int ft
, int fs
, int fd
, int cc
)
5527 const char *opn
= "farith";
5528 const char *condnames
[] = {
5546 const char *condnames_abs
[] = {
5564 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5565 uint32_t func
= ctx
->opcode
& 0x3f;
5567 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5569 GEN_LOAD_FREG_FTN(WT0
, fs
);
5570 GEN_LOAD_FREG_FTN(WT1
, ft
);
5571 gen_op_float_add_s();
5572 GEN_STORE_FTN_FREG(fd
, WT2
);
5577 GEN_LOAD_FREG_FTN(WT0
, fs
);
5578 GEN_LOAD_FREG_FTN(WT1
, ft
);
5579 gen_op_float_sub_s();
5580 GEN_STORE_FTN_FREG(fd
, WT2
);
5585 GEN_LOAD_FREG_FTN(WT0
, fs
);
5586 GEN_LOAD_FREG_FTN(WT1
, ft
);
5587 gen_op_float_mul_s();
5588 GEN_STORE_FTN_FREG(fd
, WT2
);
5593 GEN_LOAD_FREG_FTN(WT0
, fs
);
5594 GEN_LOAD_FREG_FTN(WT1
, ft
);
5595 gen_op_float_div_s();
5596 GEN_STORE_FTN_FREG(fd
, WT2
);
5601 GEN_LOAD_FREG_FTN(WT0
, fs
);
5602 gen_op_float_sqrt_s();
5603 GEN_STORE_FTN_FREG(fd
, WT2
);
5607 GEN_LOAD_FREG_FTN(WT0
, fs
);
5608 gen_op_float_abs_s();
5609 GEN_STORE_FTN_FREG(fd
, WT2
);
5613 GEN_LOAD_FREG_FTN(WT0
, fs
);
5614 gen_op_float_mov_s();
5615 GEN_STORE_FTN_FREG(fd
, WT2
);
5619 GEN_LOAD_FREG_FTN(WT0
, fs
);
5620 gen_op_float_chs_s();
5621 GEN_STORE_FTN_FREG(fd
, WT2
);
5625 check_cp1_64bitmode(ctx
);
5626 GEN_LOAD_FREG_FTN(WT0
, fs
);
5627 gen_op_float_roundl_s();
5628 GEN_STORE_FTN_FREG(fd
, DT2
);
5632 check_cp1_64bitmode(ctx
);
5633 GEN_LOAD_FREG_FTN(WT0
, fs
);
5634 gen_op_float_truncl_s();
5635 GEN_STORE_FTN_FREG(fd
, DT2
);
5639 check_cp1_64bitmode(ctx
);
5640 GEN_LOAD_FREG_FTN(WT0
, fs
);
5641 gen_op_float_ceill_s();
5642 GEN_STORE_FTN_FREG(fd
, DT2
);
5646 check_cp1_64bitmode(ctx
);
5647 GEN_LOAD_FREG_FTN(WT0
, fs
);
5648 gen_op_float_floorl_s();
5649 GEN_STORE_FTN_FREG(fd
, DT2
);
5653 GEN_LOAD_FREG_FTN(WT0
, fs
);
5654 gen_op_float_roundw_s();
5655 GEN_STORE_FTN_FREG(fd
, WT2
);
5659 GEN_LOAD_FREG_FTN(WT0
, fs
);
5660 gen_op_float_truncw_s();
5661 GEN_STORE_FTN_FREG(fd
, WT2
);
5665 GEN_LOAD_FREG_FTN(WT0
, fs
);
5666 gen_op_float_ceilw_s();
5667 GEN_STORE_FTN_FREG(fd
, WT2
);
5671 GEN_LOAD_FREG_FTN(WT0
, fs
);
5672 gen_op_float_floorw_s();
5673 GEN_STORE_FTN_FREG(fd
, WT2
);
5677 GEN_LOAD_REG_T0(ft
);
5678 GEN_LOAD_FREG_FTN(WT0
, fs
);
5679 GEN_LOAD_FREG_FTN(WT2
, fd
);
5680 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5681 GEN_STORE_FTN_FREG(fd
, WT2
);
5685 GEN_LOAD_REG_T0(ft
);
5686 GEN_LOAD_FREG_FTN(WT0
, fs
);
5687 GEN_LOAD_FREG_FTN(WT2
, fd
);
5688 gen_op_float_movz_s();
5689 GEN_STORE_FTN_FREG(fd
, WT2
);
5693 GEN_LOAD_REG_T0(ft
);
5694 GEN_LOAD_FREG_FTN(WT0
, fs
);
5695 GEN_LOAD_FREG_FTN(WT2
, fd
);
5696 gen_op_float_movn_s();
5697 GEN_STORE_FTN_FREG(fd
, WT2
);
5702 GEN_LOAD_FREG_FTN(WT0
, fs
);
5703 gen_op_float_recip_s();
5704 GEN_STORE_FTN_FREG(fd
, WT2
);
5709 GEN_LOAD_FREG_FTN(WT0
, fs
);
5710 gen_op_float_rsqrt_s();
5711 GEN_STORE_FTN_FREG(fd
, WT2
);
5715 check_cp1_64bitmode(ctx
);
5716 GEN_LOAD_FREG_FTN(WT0
, fs
);
5717 GEN_LOAD_FREG_FTN(WT2
, fd
);
5718 gen_op_float_recip2_s();
5719 GEN_STORE_FTN_FREG(fd
, WT2
);
5723 check_cp1_64bitmode(ctx
);
5724 GEN_LOAD_FREG_FTN(WT0
, fs
);
5725 gen_op_float_recip1_s();
5726 GEN_STORE_FTN_FREG(fd
, WT2
);
5730 check_cp1_64bitmode(ctx
);
5731 GEN_LOAD_FREG_FTN(WT0
, fs
);
5732 gen_op_float_rsqrt1_s();
5733 GEN_STORE_FTN_FREG(fd
, WT2
);
5737 check_cp1_64bitmode(ctx
);
5738 GEN_LOAD_FREG_FTN(WT0
, fs
);
5739 GEN_LOAD_FREG_FTN(WT2
, ft
);
5740 gen_op_float_rsqrt2_s();
5741 GEN_STORE_FTN_FREG(fd
, WT2
);
5745 check_cp1_registers(ctx
, fd
);
5746 GEN_LOAD_FREG_FTN(WT0
, fs
);
5747 gen_op_float_cvtd_s();
5748 GEN_STORE_FTN_FREG(fd
, DT2
);
5752 GEN_LOAD_FREG_FTN(WT0
, fs
);
5753 gen_op_float_cvtw_s();
5754 GEN_STORE_FTN_FREG(fd
, WT2
);
5758 check_cp1_64bitmode(ctx
);
5759 GEN_LOAD_FREG_FTN(WT0
, fs
);
5760 gen_op_float_cvtl_s();
5761 GEN_STORE_FTN_FREG(fd
, DT2
);
5765 check_cp1_64bitmode(ctx
);
5766 GEN_LOAD_FREG_FTN(WT1
, fs
);
5767 GEN_LOAD_FREG_FTN(WT0
, ft
);
5768 gen_op_float_cvtps_s();
5769 GEN_STORE_FTN_FREG(fd
, DT2
);
5788 GEN_LOAD_FREG_FTN(WT0
, fs
);
5789 GEN_LOAD_FREG_FTN(WT1
, ft
);
5790 if (ctx
->opcode
& (1 << 6)) {
5792 gen_cmpabs_s(func
-48, cc
);
5793 opn
= condnames_abs
[func
-48];
5795 gen_cmp_s(func
-48, cc
);
5796 opn
= condnames
[func
-48];
5800 check_cp1_registers(ctx
, fs
| ft
| fd
);
5801 GEN_LOAD_FREG_FTN(DT0
, fs
);
5802 GEN_LOAD_FREG_FTN(DT1
, ft
);
5803 gen_op_float_add_d();
5804 GEN_STORE_FTN_FREG(fd
, DT2
);
5809 check_cp1_registers(ctx
, fs
| ft
| fd
);
5810 GEN_LOAD_FREG_FTN(DT0
, fs
);
5811 GEN_LOAD_FREG_FTN(DT1
, ft
);
5812 gen_op_float_sub_d();
5813 GEN_STORE_FTN_FREG(fd
, DT2
);
5818 check_cp1_registers(ctx
, fs
| ft
| fd
);
5819 GEN_LOAD_FREG_FTN(DT0
, fs
);
5820 GEN_LOAD_FREG_FTN(DT1
, ft
);
5821 gen_op_float_mul_d();
5822 GEN_STORE_FTN_FREG(fd
, DT2
);
5827 check_cp1_registers(ctx
, fs
| ft
| fd
);
5828 GEN_LOAD_FREG_FTN(DT0
, fs
);
5829 GEN_LOAD_FREG_FTN(DT1
, ft
);
5830 gen_op_float_div_d();
5831 GEN_STORE_FTN_FREG(fd
, DT2
);
5836 check_cp1_registers(ctx
, fs
| fd
);
5837 GEN_LOAD_FREG_FTN(DT0
, fs
);
5838 gen_op_float_sqrt_d();
5839 GEN_STORE_FTN_FREG(fd
, DT2
);
5843 check_cp1_registers(ctx
, fs
| fd
);
5844 GEN_LOAD_FREG_FTN(DT0
, fs
);
5845 gen_op_float_abs_d();
5846 GEN_STORE_FTN_FREG(fd
, DT2
);
5850 check_cp1_registers(ctx
, fs
| fd
);
5851 GEN_LOAD_FREG_FTN(DT0
, fs
);
5852 gen_op_float_mov_d();
5853 GEN_STORE_FTN_FREG(fd
, DT2
);
5857 check_cp1_registers(ctx
, fs
| fd
);
5858 GEN_LOAD_FREG_FTN(DT0
, fs
);
5859 gen_op_float_chs_d();
5860 GEN_STORE_FTN_FREG(fd
, DT2
);
5864 check_cp1_64bitmode(ctx
);
5865 GEN_LOAD_FREG_FTN(DT0
, fs
);
5866 gen_op_float_roundl_d();
5867 GEN_STORE_FTN_FREG(fd
, DT2
);
5871 check_cp1_64bitmode(ctx
);
5872 GEN_LOAD_FREG_FTN(DT0
, fs
);
5873 gen_op_float_truncl_d();
5874 GEN_STORE_FTN_FREG(fd
, DT2
);
5878 check_cp1_64bitmode(ctx
);
5879 GEN_LOAD_FREG_FTN(DT0
, fs
);
5880 gen_op_float_ceill_d();
5881 GEN_STORE_FTN_FREG(fd
, DT2
);
5885 check_cp1_64bitmode(ctx
);
5886 GEN_LOAD_FREG_FTN(DT0
, fs
);
5887 gen_op_float_floorl_d();
5888 GEN_STORE_FTN_FREG(fd
, DT2
);
5892 check_cp1_registers(ctx
, fs
);
5893 GEN_LOAD_FREG_FTN(DT0
, fs
);
5894 gen_op_float_roundw_d();
5895 GEN_STORE_FTN_FREG(fd
, WT2
);
5899 check_cp1_registers(ctx
, fs
);
5900 GEN_LOAD_FREG_FTN(DT0
, fs
);
5901 gen_op_float_truncw_d();
5902 GEN_STORE_FTN_FREG(fd
, WT2
);
5906 check_cp1_registers(ctx
, fs
);
5907 GEN_LOAD_FREG_FTN(DT0
, fs
);
5908 gen_op_float_ceilw_d();
5909 GEN_STORE_FTN_FREG(fd
, WT2
);
5913 check_cp1_registers(ctx
, fs
);
5914 GEN_LOAD_FREG_FTN(DT0
, fs
);
5915 gen_op_float_floorw_d();
5916 GEN_STORE_FTN_FREG(fd
, WT2
);
5920 GEN_LOAD_REG_T0(ft
);
5921 GEN_LOAD_FREG_FTN(DT0
, fs
);
5922 GEN_LOAD_FREG_FTN(DT2
, fd
);
5923 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5924 GEN_STORE_FTN_FREG(fd
, DT2
);
5928 GEN_LOAD_REG_T0(ft
);
5929 GEN_LOAD_FREG_FTN(DT0
, fs
);
5930 GEN_LOAD_FREG_FTN(DT2
, fd
);
5931 gen_op_float_movz_d();
5932 GEN_STORE_FTN_FREG(fd
, DT2
);
5936 GEN_LOAD_REG_T0(ft
);
5937 GEN_LOAD_FREG_FTN(DT0
, fs
);
5938 GEN_LOAD_FREG_FTN(DT2
, fd
);
5939 gen_op_float_movn_d();
5940 GEN_STORE_FTN_FREG(fd
, DT2
);
5944 check_cp1_64bitmode(ctx
);
5945 GEN_LOAD_FREG_FTN(DT0
, fs
);
5946 gen_op_float_recip_d();
5947 GEN_STORE_FTN_FREG(fd
, DT2
);
5951 check_cp1_64bitmode(ctx
);
5952 GEN_LOAD_FREG_FTN(DT0
, fs
);
5953 gen_op_float_rsqrt_d();
5954 GEN_STORE_FTN_FREG(fd
, DT2
);
5958 check_cp1_64bitmode(ctx
);
5959 GEN_LOAD_FREG_FTN(DT0
, fs
);
5960 GEN_LOAD_FREG_FTN(DT2
, ft
);
5961 gen_op_float_recip2_d();
5962 GEN_STORE_FTN_FREG(fd
, DT2
);
5966 check_cp1_64bitmode(ctx
);
5967 GEN_LOAD_FREG_FTN(DT0
, fs
);
5968 gen_op_float_recip1_d();
5969 GEN_STORE_FTN_FREG(fd
, DT2
);
5973 check_cp1_64bitmode(ctx
);
5974 GEN_LOAD_FREG_FTN(DT0
, fs
);
5975 gen_op_float_rsqrt1_d();
5976 GEN_STORE_FTN_FREG(fd
, DT2
);
5980 check_cp1_64bitmode(ctx
);
5981 GEN_LOAD_FREG_FTN(DT0
, fs
);
5982 GEN_LOAD_FREG_FTN(DT2
, ft
);
5983 gen_op_float_rsqrt2_d();
5984 GEN_STORE_FTN_FREG(fd
, DT2
);
6003 GEN_LOAD_FREG_FTN(DT0
, fs
);
6004 GEN_LOAD_FREG_FTN(DT1
, ft
);
6005 if (ctx
->opcode
& (1 << 6)) {
6007 check_cp1_registers(ctx
, fs
| ft
);
6008 gen_cmpabs_d(func
-48, cc
);
6009 opn
= condnames_abs
[func
-48];
6011 check_cp1_registers(ctx
, fs
| ft
);
6012 gen_cmp_d(func
-48, cc
);
6013 opn
= condnames
[func
-48];
6017 check_cp1_registers(ctx
, fs
);
6018 GEN_LOAD_FREG_FTN(DT0
, fs
);
6019 gen_op_float_cvts_d();
6020 GEN_STORE_FTN_FREG(fd
, WT2
);
6024 check_cp1_registers(ctx
, fs
);
6025 GEN_LOAD_FREG_FTN(DT0
, fs
);
6026 gen_op_float_cvtw_d();
6027 GEN_STORE_FTN_FREG(fd
, WT2
);
6031 check_cp1_64bitmode(ctx
);
6032 GEN_LOAD_FREG_FTN(DT0
, fs
);
6033 gen_op_float_cvtl_d();
6034 GEN_STORE_FTN_FREG(fd
, DT2
);
6038 GEN_LOAD_FREG_FTN(WT0
, fs
);
6039 gen_op_float_cvts_w();
6040 GEN_STORE_FTN_FREG(fd
, WT2
);
6044 check_cp1_registers(ctx
, fd
);
6045 GEN_LOAD_FREG_FTN(WT0
, fs
);
6046 gen_op_float_cvtd_w();
6047 GEN_STORE_FTN_FREG(fd
, DT2
);
6051 check_cp1_64bitmode(ctx
);
6052 GEN_LOAD_FREG_FTN(DT0
, fs
);
6053 gen_op_float_cvts_l();
6054 GEN_STORE_FTN_FREG(fd
, WT2
);
6058 check_cp1_64bitmode(ctx
);
6059 GEN_LOAD_FREG_FTN(DT0
, fs
);
6060 gen_op_float_cvtd_l();
6061 GEN_STORE_FTN_FREG(fd
, DT2
);
6065 check_cp1_64bitmode(ctx
);
6066 GEN_LOAD_FREG_FTN(WT0
, fs
);
6067 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6068 gen_op_float_cvtps_pw();
6069 GEN_STORE_FTN_FREG(fd
, WT2
);
6070 GEN_STORE_FTN_FREG(fd
, WTH2
);
6074 check_cp1_64bitmode(ctx
);
6075 GEN_LOAD_FREG_FTN(WT0
, fs
);
6076 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6077 GEN_LOAD_FREG_FTN(WT1
, ft
);
6078 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6079 gen_op_float_add_ps();
6080 GEN_STORE_FTN_FREG(fd
, WT2
);
6081 GEN_STORE_FTN_FREG(fd
, WTH2
);
6085 check_cp1_64bitmode(ctx
);
6086 GEN_LOAD_FREG_FTN(WT0
, fs
);
6087 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6088 GEN_LOAD_FREG_FTN(WT1
, ft
);
6089 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6090 gen_op_float_sub_ps();
6091 GEN_STORE_FTN_FREG(fd
, WT2
);
6092 GEN_STORE_FTN_FREG(fd
, WTH2
);
6096 check_cp1_64bitmode(ctx
);
6097 GEN_LOAD_FREG_FTN(WT0
, fs
);
6098 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6099 GEN_LOAD_FREG_FTN(WT1
, ft
);
6100 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6101 gen_op_float_mul_ps();
6102 GEN_STORE_FTN_FREG(fd
, WT2
);
6103 GEN_STORE_FTN_FREG(fd
, WTH2
);
6107 check_cp1_64bitmode(ctx
);
6108 GEN_LOAD_FREG_FTN(WT0
, fs
);
6109 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6110 gen_op_float_abs_ps();
6111 GEN_STORE_FTN_FREG(fd
, WT2
);
6112 GEN_STORE_FTN_FREG(fd
, WTH2
);
6116 check_cp1_64bitmode(ctx
);
6117 GEN_LOAD_FREG_FTN(WT0
, fs
);
6118 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6119 gen_op_float_mov_ps();
6120 GEN_STORE_FTN_FREG(fd
, WT2
);
6121 GEN_STORE_FTN_FREG(fd
, WTH2
);
6125 check_cp1_64bitmode(ctx
);
6126 GEN_LOAD_FREG_FTN(WT0
, fs
);
6127 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6128 gen_op_float_chs_ps();
6129 GEN_STORE_FTN_FREG(fd
, WT2
);
6130 GEN_STORE_FTN_FREG(fd
, WTH2
);
6134 check_cp1_64bitmode(ctx
);
6135 GEN_LOAD_REG_T0(ft
);
6136 GEN_LOAD_FREG_FTN(WT0
, fs
);
6137 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6138 GEN_LOAD_FREG_FTN(WT2
, fd
);
6139 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6140 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
6141 GEN_STORE_FTN_FREG(fd
, WT2
);
6142 GEN_STORE_FTN_FREG(fd
, WTH2
);
6146 check_cp1_64bitmode(ctx
);
6147 GEN_LOAD_REG_T0(ft
);
6148 GEN_LOAD_FREG_FTN(WT0
, fs
);
6149 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6150 GEN_LOAD_FREG_FTN(WT2
, fd
);
6151 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6152 gen_op_float_movz_ps();
6153 GEN_STORE_FTN_FREG(fd
, WT2
);
6154 GEN_STORE_FTN_FREG(fd
, WTH2
);
6158 check_cp1_64bitmode(ctx
);
6159 GEN_LOAD_REG_T0(ft
);
6160 GEN_LOAD_FREG_FTN(WT0
, fs
);
6161 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6162 GEN_LOAD_FREG_FTN(WT2
, fd
);
6163 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6164 gen_op_float_movn_ps();
6165 GEN_STORE_FTN_FREG(fd
, WT2
);
6166 GEN_STORE_FTN_FREG(fd
, WTH2
);
6170 check_cp1_64bitmode(ctx
);
6171 GEN_LOAD_FREG_FTN(WT0
, ft
);
6172 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6173 GEN_LOAD_FREG_FTN(WT1
, fs
);
6174 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6175 gen_op_float_addr_ps();
6176 GEN_STORE_FTN_FREG(fd
, WT2
);
6177 GEN_STORE_FTN_FREG(fd
, WTH2
);
6181 check_cp1_64bitmode(ctx
);
6182 GEN_LOAD_FREG_FTN(WT0
, ft
);
6183 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6184 GEN_LOAD_FREG_FTN(WT1
, fs
);
6185 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6186 gen_op_float_mulr_ps();
6187 GEN_STORE_FTN_FREG(fd
, WT2
);
6188 GEN_STORE_FTN_FREG(fd
, WTH2
);
6192 check_cp1_64bitmode(ctx
);
6193 GEN_LOAD_FREG_FTN(WT0
, fs
);
6194 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6195 GEN_LOAD_FREG_FTN(WT2
, fd
);
6196 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6197 gen_op_float_recip2_ps();
6198 GEN_STORE_FTN_FREG(fd
, WT2
);
6199 GEN_STORE_FTN_FREG(fd
, WTH2
);
6203 check_cp1_64bitmode(ctx
);
6204 GEN_LOAD_FREG_FTN(WT0
, fs
);
6205 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6206 gen_op_float_recip1_ps();
6207 GEN_STORE_FTN_FREG(fd
, WT2
);
6208 GEN_STORE_FTN_FREG(fd
, WTH2
);
6212 check_cp1_64bitmode(ctx
);
6213 GEN_LOAD_FREG_FTN(WT0
, fs
);
6214 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6215 gen_op_float_rsqrt1_ps();
6216 GEN_STORE_FTN_FREG(fd
, WT2
);
6217 GEN_STORE_FTN_FREG(fd
, WTH2
);
6221 check_cp1_64bitmode(ctx
);
6222 GEN_LOAD_FREG_FTN(WT0
, fs
);
6223 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6224 GEN_LOAD_FREG_FTN(WT2
, ft
);
6225 GEN_LOAD_FREG_FTN(WTH2
, ft
);
6226 gen_op_float_rsqrt2_ps();
6227 GEN_STORE_FTN_FREG(fd
, WT2
);
6228 GEN_STORE_FTN_FREG(fd
, WTH2
);
6232 check_cp1_64bitmode(ctx
);
6233 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6234 gen_op_float_cvts_pu();
6235 GEN_STORE_FTN_FREG(fd
, WT2
);
6239 check_cp1_64bitmode(ctx
);
6240 GEN_LOAD_FREG_FTN(WT0
, fs
);
6241 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6242 gen_op_float_cvtpw_ps();
6243 GEN_STORE_FTN_FREG(fd
, WT2
);
6244 GEN_STORE_FTN_FREG(fd
, WTH2
);
6248 check_cp1_64bitmode(ctx
);
6249 GEN_LOAD_FREG_FTN(WT0
, fs
);
6250 gen_op_float_cvts_pl();
6251 GEN_STORE_FTN_FREG(fd
, WT2
);
6255 check_cp1_64bitmode(ctx
);
6256 GEN_LOAD_FREG_FTN(WT0
, fs
);
6257 GEN_LOAD_FREG_FTN(WT1
, ft
);
6258 gen_op_float_pll_ps();
6259 GEN_STORE_FTN_FREG(fd
, DT2
);
6263 check_cp1_64bitmode(ctx
);
6264 GEN_LOAD_FREG_FTN(WT0
, fs
);
6265 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6266 gen_op_float_plu_ps();
6267 GEN_STORE_FTN_FREG(fd
, DT2
);
6271 check_cp1_64bitmode(ctx
);
6272 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6273 GEN_LOAD_FREG_FTN(WT1
, ft
);
6274 gen_op_float_pul_ps();
6275 GEN_STORE_FTN_FREG(fd
, DT2
);
6279 check_cp1_64bitmode(ctx
);
6280 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6281 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6282 gen_op_float_puu_ps();
6283 GEN_STORE_FTN_FREG(fd
, DT2
);
6302 check_cp1_64bitmode(ctx
);
6303 GEN_LOAD_FREG_FTN(WT0
, fs
);
6304 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6305 GEN_LOAD_FREG_FTN(WT1
, ft
);
6306 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6307 if (ctx
->opcode
& (1 << 6)) {
6308 gen_cmpabs_ps(func
-48, cc
);
6309 opn
= condnames_abs
[func
-48];
6311 gen_cmp_ps(func
-48, cc
);
6312 opn
= condnames
[func
-48];
6317 generate_exception (ctx
, EXCP_RI
);
6322 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
6325 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
6328 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
6333 /* Coprocessor 3 (FPU) */
6334 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
6335 int fd
, int fs
, int base
, int index
)
6337 const char *opn
= "extended float load/store";
6344 GEN_LOAD_REG_T0(index
);
6345 } else if (index
== 0) {
6346 GEN_LOAD_REG_T0(base
);
6348 GEN_LOAD_REG_T0(base
);
6349 GEN_LOAD_REG_T1(index
);
6352 /* Don't do NOP if destination is zero: we must perform the actual
6358 GEN_STORE_FTN_FREG(fd
, WT0
);
6363 check_cp1_registers(ctx
, fd
);
6365 GEN_STORE_FTN_FREG(fd
, DT0
);
6369 check_cp1_64bitmode(ctx
);
6371 GEN_STORE_FTN_FREG(fd
, DT0
);
6376 GEN_LOAD_FREG_FTN(WT0
, fs
);
6383 check_cp1_registers(ctx
, fs
);
6384 GEN_LOAD_FREG_FTN(DT0
, fs
);
6390 check_cp1_64bitmode(ctx
);
6391 GEN_LOAD_FREG_FTN(DT0
, fs
);
6398 generate_exception(ctx
, EXCP_RI
);
6401 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
6402 regnames
[index
], regnames
[base
]);
6405 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
6406 int fd
, int fr
, int fs
, int ft
)
6408 const char *opn
= "flt3_arith";
6412 check_cp1_64bitmode(ctx
);
6413 GEN_LOAD_REG_T0(fr
);
6414 GEN_LOAD_FREG_FTN(DT0
, fs
);
6415 GEN_LOAD_FREG_FTN(DT1
, ft
);
6416 gen_op_float_alnv_ps();
6417 GEN_STORE_FTN_FREG(fd
, DT2
);
6422 GEN_LOAD_FREG_FTN(WT0
, fs
);
6423 GEN_LOAD_FREG_FTN(WT1
, ft
);
6424 GEN_LOAD_FREG_FTN(WT2
, fr
);
6425 gen_op_float_muladd_s();
6426 GEN_STORE_FTN_FREG(fd
, WT2
);
6431 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6432 GEN_LOAD_FREG_FTN(DT0
, fs
);
6433 GEN_LOAD_FREG_FTN(DT1
, ft
);
6434 GEN_LOAD_FREG_FTN(DT2
, fr
);
6435 gen_op_float_muladd_d();
6436 GEN_STORE_FTN_FREG(fd
, DT2
);
6440 check_cp1_64bitmode(ctx
);
6441 GEN_LOAD_FREG_FTN(WT0
, fs
);
6442 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6443 GEN_LOAD_FREG_FTN(WT1
, ft
);
6444 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6445 GEN_LOAD_FREG_FTN(WT2
, fr
);
6446 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6447 gen_op_float_muladd_ps();
6448 GEN_STORE_FTN_FREG(fd
, WT2
);
6449 GEN_STORE_FTN_FREG(fd
, WTH2
);
6454 GEN_LOAD_FREG_FTN(WT0
, fs
);
6455 GEN_LOAD_FREG_FTN(WT1
, ft
);
6456 GEN_LOAD_FREG_FTN(WT2
, fr
);
6457 gen_op_float_mulsub_s();
6458 GEN_STORE_FTN_FREG(fd
, WT2
);
6463 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6464 GEN_LOAD_FREG_FTN(DT0
, fs
);
6465 GEN_LOAD_FREG_FTN(DT1
, ft
);
6466 GEN_LOAD_FREG_FTN(DT2
, fr
);
6467 gen_op_float_mulsub_d();
6468 GEN_STORE_FTN_FREG(fd
, DT2
);
6472 check_cp1_64bitmode(ctx
);
6473 GEN_LOAD_FREG_FTN(WT0
, fs
);
6474 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6475 GEN_LOAD_FREG_FTN(WT1
, ft
);
6476 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6477 GEN_LOAD_FREG_FTN(WT2
, fr
);
6478 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6479 gen_op_float_mulsub_ps();
6480 GEN_STORE_FTN_FREG(fd
, WT2
);
6481 GEN_STORE_FTN_FREG(fd
, WTH2
);
6486 GEN_LOAD_FREG_FTN(WT0
, fs
);
6487 GEN_LOAD_FREG_FTN(WT1
, ft
);
6488 GEN_LOAD_FREG_FTN(WT2
, fr
);
6489 gen_op_float_nmuladd_s();
6490 GEN_STORE_FTN_FREG(fd
, WT2
);
6495 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6496 GEN_LOAD_FREG_FTN(DT0
, fs
);
6497 GEN_LOAD_FREG_FTN(DT1
, ft
);
6498 GEN_LOAD_FREG_FTN(DT2
, fr
);
6499 gen_op_float_nmuladd_d();
6500 GEN_STORE_FTN_FREG(fd
, DT2
);
6504 check_cp1_64bitmode(ctx
);
6505 GEN_LOAD_FREG_FTN(WT0
, fs
);
6506 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6507 GEN_LOAD_FREG_FTN(WT1
, ft
);
6508 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6509 GEN_LOAD_FREG_FTN(WT2
, fr
);
6510 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6511 gen_op_float_nmuladd_ps();
6512 GEN_STORE_FTN_FREG(fd
, WT2
);
6513 GEN_STORE_FTN_FREG(fd
, WTH2
);
6518 GEN_LOAD_FREG_FTN(WT0
, fs
);
6519 GEN_LOAD_FREG_FTN(WT1
, ft
);
6520 GEN_LOAD_FREG_FTN(WT2
, fr
);
6521 gen_op_float_nmulsub_s();
6522 GEN_STORE_FTN_FREG(fd
, WT2
);
6527 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6528 GEN_LOAD_FREG_FTN(DT0
, fs
);
6529 GEN_LOAD_FREG_FTN(DT1
, ft
);
6530 GEN_LOAD_FREG_FTN(DT2
, fr
);
6531 gen_op_float_nmulsub_d();
6532 GEN_STORE_FTN_FREG(fd
, DT2
);
6536 check_cp1_64bitmode(ctx
);
6537 GEN_LOAD_FREG_FTN(WT0
, fs
);
6538 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6539 GEN_LOAD_FREG_FTN(WT1
, ft
);
6540 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6541 GEN_LOAD_FREG_FTN(WT2
, fr
);
6542 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6543 gen_op_float_nmulsub_ps();
6544 GEN_STORE_FTN_FREG(fd
, WT2
);
6545 GEN_STORE_FTN_FREG(fd
, WTH2
);
6550 generate_exception (ctx
, EXCP_RI
);
6553 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6554 fregnames
[fs
], fregnames
[ft
]);
6557 /* ISA extensions (ASEs) */
6558 /* MIPS16 extension to MIPS32 */
6559 /* SmartMIPS extension to MIPS32 */
6561 #if defined(TARGET_MIPS64)
6563 /* MDMX extension to MIPS64 */
6567 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6571 uint32_t op
, op1
, op2
;
6574 /* make sure instructions are on a word boundary */
6575 if (ctx
->pc
& 0x3) {
6576 env
->CP0_BadVAddr
= ctx
->pc
;
6577 generate_exception(ctx
, EXCP_AdEL
);
6581 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6583 /* Handle blikely not taken case */
6584 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6585 l1
= gen_new_label();
6586 tcg_gen_jnz_bcond(l1
);
6587 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6588 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6591 op
= MASK_OP_MAJOR(ctx
->opcode
);
6592 rs
= (ctx
->opcode
>> 21) & 0x1f;
6593 rt
= (ctx
->opcode
>> 16) & 0x1f;
6594 rd
= (ctx
->opcode
>> 11) & 0x1f;
6595 sa
= (ctx
->opcode
>> 6) & 0x1f;
6596 imm
= (int16_t)ctx
->opcode
;
6599 op1
= MASK_SPECIAL(ctx
->opcode
);
6601 case OPC_SLL
: /* Arithmetic with immediate */
6602 case OPC_SRL
... OPC_SRA
:
6603 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6605 case OPC_MOVZ
... OPC_MOVN
:
6606 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6607 case OPC_SLLV
: /* Arithmetic */
6608 case OPC_SRLV
... OPC_SRAV
:
6609 case OPC_ADD
... OPC_NOR
:
6610 case OPC_SLT
... OPC_SLTU
:
6611 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6613 case OPC_MULT
... OPC_DIVU
:
6615 check_insn(env
, ctx
, INSN_VR54XX
);
6616 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6617 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6619 gen_muldiv(ctx
, op1
, rs
, rt
);
6621 case OPC_JR
... OPC_JALR
:
6622 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6624 case OPC_TGE
... OPC_TEQ
: /* Traps */
6626 gen_trap(ctx
, op1
, rs
, rt
, -1);
6628 case OPC_MFHI
: /* Move from HI/LO */
6630 gen_HILO(ctx
, op1
, rd
);
6633 case OPC_MTLO
: /* Move to HI/LO */
6634 gen_HILO(ctx
, op1
, rs
);
6636 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6637 #ifdef MIPS_STRICT_STANDARD
6638 MIPS_INVAL("PMON / selsl");
6639 generate_exception(ctx
, EXCP_RI
);
6645 generate_exception(ctx
, EXCP_SYSCALL
);
6648 generate_exception(ctx
, EXCP_BREAK
);
6651 #ifdef MIPS_STRICT_STANDARD
6653 generate_exception(ctx
, EXCP_RI
);
6655 /* Implemented as RI exception for now. */
6656 MIPS_INVAL("spim (unofficial)");
6657 generate_exception(ctx
, EXCP_RI
);
6665 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6666 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6667 save_cpu_state(ctx
, 1);
6668 check_cp1_enabled(ctx
);
6669 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6670 (ctx
->opcode
>> 16) & 1);
6672 generate_exception_err(ctx
, EXCP_CpU
, 1);
6676 #if defined(TARGET_MIPS64)
6677 /* MIPS64 specific opcodes */
6679 case OPC_DSRL
... OPC_DSRA
:
6681 case OPC_DSRL32
... OPC_DSRA32
:
6682 check_insn(env
, ctx
, ISA_MIPS3
);
6684 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6687 case OPC_DSRLV
... OPC_DSRAV
:
6688 case OPC_DADD
... OPC_DSUBU
:
6689 check_insn(env
, ctx
, ISA_MIPS3
);
6691 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6693 case OPC_DMULT
... OPC_DDIVU
:
6694 check_insn(env
, ctx
, ISA_MIPS3
);
6696 gen_muldiv(ctx
, op1
, rs
, rt
);
6699 default: /* Invalid */
6700 MIPS_INVAL("special");
6701 generate_exception(ctx
, EXCP_RI
);
6706 op1
= MASK_SPECIAL2(ctx
->opcode
);
6708 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6709 case OPC_MSUB
... OPC_MSUBU
:
6710 check_insn(env
, ctx
, ISA_MIPS32
);
6711 gen_muldiv(ctx
, op1
, rs
, rt
);
6714 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6716 case OPC_CLZ
... OPC_CLO
:
6717 check_insn(env
, ctx
, ISA_MIPS32
);
6718 gen_cl(ctx
, op1
, rd
, rs
);
6721 /* XXX: not clear which exception should be raised
6722 * when in debug mode...
6724 check_insn(env
, ctx
, ISA_MIPS32
);
6725 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6726 generate_exception(ctx
, EXCP_DBp
);
6728 generate_exception(ctx
, EXCP_DBp
);
6732 #if defined(TARGET_MIPS64)
6733 case OPC_DCLZ
... OPC_DCLO
:
6734 check_insn(env
, ctx
, ISA_MIPS64
);
6736 gen_cl(ctx
, op1
, rd
, rs
);
6739 default: /* Invalid */
6740 MIPS_INVAL("special2");
6741 generate_exception(ctx
, EXCP_RI
);
6746 op1
= MASK_SPECIAL3(ctx
->opcode
);
6750 check_insn(env
, ctx
, ISA_MIPS32R2
);
6751 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6754 check_insn(env
, ctx
, ISA_MIPS32R2
);
6755 op2
= MASK_BSHFL(ctx
->opcode
);
6758 GEN_LOAD_REG_T1(rt
);
6762 GEN_LOAD_REG_T1(rt
);
6763 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[1]);
6766 GEN_LOAD_REG_T1(rt
);
6767 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[1]);
6769 default: /* Invalid */
6770 MIPS_INVAL("bshfl");
6771 generate_exception(ctx
, EXCP_RI
);
6774 GEN_STORE_T0_REG(rd
);
6777 check_insn(env
, ctx
, ISA_MIPS32R2
);
6780 save_cpu_state(ctx
, 1);
6781 gen_op_rdhwr_cpunum();
6784 save_cpu_state(ctx
, 1);
6785 gen_op_rdhwr_synci_step();
6788 save_cpu_state(ctx
, 1);
6792 save_cpu_state(ctx
, 1);
6793 gen_op_rdhwr_ccres();
6796 #if defined (CONFIG_USER_ONLY)
6800 default: /* Invalid */
6801 MIPS_INVAL("rdhwr");
6802 generate_exception(ctx
, EXCP_RI
);
6805 GEN_STORE_T0_REG(rt
);
6808 check_insn(env
, ctx
, ASE_MT
);
6809 GEN_LOAD_REG_T0(rt
);
6810 GEN_LOAD_REG_T1(rs
);
6814 check_insn(env
, ctx
, ASE_MT
);
6815 GEN_LOAD_REG_T0(rs
);
6817 GEN_STORE_T0_REG(rd
);
6819 #if defined(TARGET_MIPS64)
6820 case OPC_DEXTM
... OPC_DEXT
:
6821 case OPC_DINSM
... OPC_DINS
:
6822 check_insn(env
, ctx
, ISA_MIPS64R2
);
6824 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6827 check_insn(env
, ctx
, ISA_MIPS64R2
);
6829 op2
= MASK_DBSHFL(ctx
->opcode
);
6832 GEN_LOAD_REG_T1(rt
);
6836 GEN_LOAD_REG_T1(rt
);
6839 default: /* Invalid */
6840 MIPS_INVAL("dbshfl");
6841 generate_exception(ctx
, EXCP_RI
);
6844 GEN_STORE_T0_REG(rd
);
6847 default: /* Invalid */
6848 MIPS_INVAL("special3");
6849 generate_exception(ctx
, EXCP_RI
);
6854 op1
= MASK_REGIMM(ctx
->opcode
);
6856 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6857 case OPC_BLTZAL
... OPC_BGEZALL
:
6858 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6860 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6862 gen_trap(ctx
, op1
, rs
, -1, imm
);
6865 check_insn(env
, ctx
, ISA_MIPS32R2
);
6868 default: /* Invalid */
6869 MIPS_INVAL("regimm");
6870 generate_exception(ctx
, EXCP_RI
);
6875 check_cp0_enabled(ctx
);
6876 op1
= MASK_CP0(ctx
->opcode
);
6882 #if defined(TARGET_MIPS64)
6886 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6888 case OPC_C0_FIRST
... OPC_C0_LAST
:
6889 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6892 op2
= MASK_MFMC0(ctx
->opcode
);
6895 check_insn(env
, ctx
, ASE_MT
);
6899 check_insn(env
, ctx
, ASE_MT
);
6903 check_insn(env
, ctx
, ASE_MT
);
6907 check_insn(env
, ctx
, ASE_MT
);
6911 check_insn(env
, ctx
, ISA_MIPS32R2
);
6912 save_cpu_state(ctx
, 1);
6914 /* Stop translation as we may have switched the execution mode */
6915 ctx
->bstate
= BS_STOP
;
6918 check_insn(env
, ctx
, ISA_MIPS32R2
);
6919 save_cpu_state(ctx
, 1);
6921 /* Stop translation as we may have switched the execution mode */
6922 ctx
->bstate
= BS_STOP
;
6924 default: /* Invalid */
6925 MIPS_INVAL("mfmc0");
6926 generate_exception(ctx
, EXCP_RI
);
6929 GEN_STORE_T0_REG(rt
);
6932 check_insn(env
, ctx
, ISA_MIPS32R2
);
6933 GEN_LOAD_SRSREG_TN(T0
, rt
);
6934 GEN_STORE_T0_REG(rd
);
6937 check_insn(env
, ctx
, ISA_MIPS32R2
);
6938 GEN_LOAD_REG_T0(rt
);
6939 GEN_STORE_TN_SRSREG(rd
, T0
);
6943 generate_exception(ctx
, EXCP_RI
);
6947 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6948 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6950 case OPC_J
... OPC_JAL
: /* Jump */
6951 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6952 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6954 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6955 case OPC_BEQL
... OPC_BGTZL
:
6956 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6958 case OPC_LB
... OPC_LWR
: /* Load and stores */
6959 case OPC_SB
... OPC_SW
:
6963 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6966 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6970 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6974 /* Floating point (COP1). */
6979 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6980 save_cpu_state(ctx
, 1);
6981 check_cp1_enabled(ctx
);
6982 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6984 generate_exception_err(ctx
, EXCP_CpU
, 1);
6989 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6990 save_cpu_state(ctx
, 1);
6991 check_cp1_enabled(ctx
);
6992 op1
= MASK_CP1(ctx
->opcode
);
6996 check_insn(env
, ctx
, ISA_MIPS32R2
);
7001 gen_cp1(ctx
, op1
, rt
, rd
);
7003 #if defined(TARGET_MIPS64)
7006 check_insn(env
, ctx
, ISA_MIPS3
);
7007 gen_cp1(ctx
, op1
, rt
, rd
);
7013 check_insn(env
, ctx
, ASE_MIPS3D
);
7016 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
7017 (rt
>> 2) & 0x7, imm
<< 2);
7024 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
7029 generate_exception (ctx
, EXCP_RI
);
7033 generate_exception_err(ctx
, EXCP_CpU
, 1);
7043 /* COP2: Not implemented. */
7044 generate_exception_err(ctx
, EXCP_CpU
, 2);
7048 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7049 save_cpu_state(ctx
, 1);
7050 check_cp1_enabled(ctx
);
7051 op1
= MASK_CP3(ctx
->opcode
);
7059 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
7077 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
7081 generate_exception (ctx
, EXCP_RI
);
7085 generate_exception_err(ctx
, EXCP_CpU
, 1);
7089 #if defined(TARGET_MIPS64)
7090 /* MIPS64 opcodes */
7092 case OPC_LDL
... OPC_LDR
:
7093 case OPC_SDL
... OPC_SDR
:
7098 check_insn(env
, ctx
, ISA_MIPS3
);
7100 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7102 case OPC_DADDI
... OPC_DADDIU
:
7103 check_insn(env
, ctx
, ISA_MIPS3
);
7105 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7109 check_insn(env
, ctx
, ASE_MIPS16
);
7110 /* MIPS16: Not implemented. */
7112 check_insn(env
, ctx
, ASE_MDMX
);
7113 /* MDMX: Not implemented. */
7114 default: /* Invalid */
7115 MIPS_INVAL("major opcode");
7116 generate_exception(ctx
, EXCP_RI
);
7119 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7120 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7121 /* Branches completion */
7122 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7123 ctx
->bstate
= BS_BRANCH
;
7124 save_cpu_state(ctx
, 0);
7127 /* unconditional branch */
7128 MIPS_DEBUG("unconditional branch");
7129 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7132 /* blikely taken case */
7133 MIPS_DEBUG("blikely branch taken");
7134 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7137 /* Conditional branch */
7138 MIPS_DEBUG("conditional branch");
7141 l1
= gen_new_label();
7142 tcg_gen_jnz_bcond(l1
);
7143 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7145 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7149 /* unconditional branch to register */
7150 MIPS_DEBUG("branch to register");
7155 MIPS_DEBUG("unknown branch");
7161 static always_inline
int
7162 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
7166 target_ulong pc_start
;
7167 uint16_t *gen_opc_end
;
7170 if (search_pc
&& loglevel
)
7171 fprintf (logfile
, "search pc %d\n", search_pc
);
7174 memset(temps
, 0, sizeof(temps
));
7177 memset(temps
, 0, sizeof(temps
));
7180 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7184 ctx
.bstate
= BS_NONE
;
7185 /* Restore delay slot state from the tb context. */
7186 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
7187 restore_cpu_state(env
, &ctx
);
7188 #if defined(CONFIG_USER_ONLY)
7189 ctx
.mem_idx
= MIPS_HFLAG_UM
;
7191 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
7194 if (loglevel
& CPU_LOG_TB_CPU
) {
7195 fprintf(logfile
, "------------------------------------------------\n");
7196 /* FIXME: This may print out stale hflags from env... */
7197 cpu_dump_state(env
, logfile
, fprintf
, 0);
7200 #ifdef MIPS_DEBUG_DISAS
7201 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7202 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
7203 tb
, ctx
.mem_idx
, ctx
.hflags
);
7205 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7206 if (env
->nb_breakpoints
> 0) {
7207 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
7208 if (env
->breakpoints
[j
] == ctx
.pc
) {
7209 save_cpu_state(&ctx
, 1);
7210 ctx
.bstate
= BS_BRANCH
;
7212 /* Include the breakpoint location or the tb won't
7213 * be flushed when it must be. */
7215 goto done_generating
;
7221 j
= gen_opc_ptr
- gen_opc_buf
;
7225 gen_opc_instr_start
[lj
++] = 0;
7227 gen_opc_pc
[lj
] = ctx
.pc
;
7228 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
7229 gen_opc_instr_start
[lj
] = 1;
7231 ctx
.opcode
= ldl_code(ctx
.pc
);
7232 decode_opc(env
, &ctx
);
7235 "Internal resource leak before " TARGET_FMT_lx
"\n",
7241 if (env
->singlestep_enabled
)
7244 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
7247 #if defined (MIPS_SINGLE_STEP)
7251 if (env
->singlestep_enabled
) {
7252 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
7255 switch (ctx
.bstate
) {
7257 tcg_gen_helper_0_0(do_interrupt_restart
);
7258 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7261 save_cpu_state(&ctx
, 0);
7262 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7265 tcg_gen_helper_0_0(do_interrupt_restart
);
7274 ctx
.last_T0_store
= NULL
;
7275 *gen_opc_ptr
= INDEX_op_end
;
7277 j
= gen_opc_ptr
- gen_opc_buf
;
7280 gen_opc_instr_start
[lj
++] = 0;
7282 tb
->size
= ctx
.pc
- pc_start
;
7285 #if defined MIPS_DEBUG_DISAS
7286 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7287 fprintf(logfile
, "\n");
7289 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7290 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7291 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
7292 fprintf(logfile
, "\n");
7294 if (loglevel
& CPU_LOG_TB_CPU
) {
7295 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
7302 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7304 return gen_intermediate_code_internal(env
, tb
, 0);
7307 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7309 return gen_intermediate_code_internal(env
, tb
, 1);
7312 void fpu_dump_state(CPUState
*env
, FILE *f
,
7313 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7317 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
7319 #define printfpr(fp) \
7322 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7323 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7324 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7327 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7328 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7329 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7330 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7331 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7336 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7337 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
7338 get_float_exception_flags(&env
->fpu
->fp_status
));
7339 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
7340 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
7341 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
7342 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
7343 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
7344 printfpr(&env
->fpu
->fpr
[i
]);
7350 void dump_fpu (CPUState
*env
)
7354 "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
7355 " LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
7357 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0],
7358 env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
,
7360 fpu_dump_state(env
, logfile
, fprintf
, 0);
7364 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7365 /* Debug help: The architecture requires 32bit code to maintain proper
7366 sign-extened values on 64bit machines. */
7368 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7370 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
7371 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7376 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
7377 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
7378 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
7379 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
7380 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
7381 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
7382 if (!SIGN_EXT_P(env
->btarget
))
7383 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
7385 for (i
= 0; i
< 32; i
++) {
7386 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
7387 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7390 if (!SIGN_EXT_P(env
->CP0_EPC
))
7391 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
7392 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
7393 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
7397 void cpu_dump_state (CPUState
*env
, FILE *f
,
7398 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7403 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",
7404 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
7405 for (i
= 0; i
< 32; i
++) {
7407 cpu_fprintf(f
, "GPR%02d:", i
);
7408 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7410 cpu_fprintf(f
, "\n");
7413 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
7414 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
7415 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
7416 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
7417 if (env
->hflags
& MIPS_HFLAG_FPU
)
7418 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
7419 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7420 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
7424 static void mips_tcg_init(void)
7428 /* Initialize various static tables. */
7432 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
7433 current_tc_gprs
= tcg_global_mem_new(TCG_TYPE_PTR
,
7435 offsetof(CPUState
, current_tc_gprs
),
7437 #if TARGET_LONG_BITS > HOST_LONG_BITS
7438 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
7439 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
7440 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
7441 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
7443 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
7444 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
7450 #include "translate_init.c"
7452 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
7455 const mips_def_t
*def
;
7457 def
= cpu_mips_find_by_name(cpu_model
);
7460 env
= qemu_mallocz(sizeof(CPUMIPSState
));
7463 env
->cpu_model
= def
;
7466 env
->cpu_model_str
= cpu_model
;
7472 void cpu_reset (CPUMIPSState
*env
)
7474 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
7479 #if !defined(CONFIG_USER_ONLY)
7480 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
7481 /* If the exception was raised from a delay slot,
7482 * come back to the jump. */
7483 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
7485 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
7487 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
7489 /* SMP not implemented */
7490 env
->CP0_EBase
= 0x80000000;
7491 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
7492 /* vectored interrupts not implemented, timer on int 7,
7493 no performance counters. */
7494 env
->CP0_IntCtl
= 0xe0000000;
7498 for (i
= 0; i
< 7; i
++) {
7499 env
->CP0_WatchLo
[i
] = 0;
7500 env
->CP0_WatchHi
[i
] = 0x80000000;
7502 env
->CP0_WatchLo
[7] = 0;
7503 env
->CP0_WatchHi
[7] = 0;
7505 /* Count register increments in debug mode, EJTAG version 1 */
7506 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
7508 env
->exception_index
= EXCP_NONE
;
7509 #if defined(CONFIG_USER_ONLY)
7510 env
->hflags
= MIPS_HFLAG_UM
;
7511 env
->user_mode_only
= 1;
7513 env
->hflags
= MIPS_HFLAG_CP0
;
7515 cpu_mips_register(env
, env
->cpu_model
);
7518 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7519 unsigned long searched_pc
, int pc_pos
, void *puc
)
7521 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
7522 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
7523 env
->hflags
|= gen_opc_hflags
[pc_pos
];