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 typedef struct DisasContext
{
469 struct TranslationBlock
*tb
;
470 target_ulong pc
, saved_pc
;
473 /* Routine used to access memory */
475 uint32_t hflags
, saved_hflags
;
477 target_ulong btarget
;
481 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
482 * exception condition
484 BS_STOP
= 1, /* We want to stop translation for any reason */
485 BS_BRANCH
= 2, /* We reached a branch condition */
486 BS_EXCP
= 3, /* We reached an exception condition */
489 static const char *regnames
[] =
490 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
491 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
492 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
493 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
495 static const char *fregnames
[] =
496 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
497 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
498 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
499 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
501 #ifdef MIPS_DEBUG_DISAS
502 #define MIPS_DEBUG(fmt, args...) \
504 if (loglevel & CPU_LOG_TB_IN_ASM) { \
505 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
506 ctx->pc, ctx->opcode , ##args); \
510 #define MIPS_DEBUG(fmt, args...) do { } while(0)
513 #define MIPS_INVAL(op) \
515 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
516 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
519 /* General purpose registers moves. */
520 static inline void gen_load_gpr (TCGv t
, int reg
)
523 tcg_gen_movi_tl(t
, 0);
525 tcg_gen_ld_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
528 static inline void gen_store_gpr (TCGv t
, int reg
)
531 tcg_gen_st_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
534 /* Moves to/from shadow registers. */
535 static inline void gen_load_srsgpr (TCGv t
, int reg
)
538 tcg_gen_movi_tl(t
, 0);
540 TCGv r_tmp
= new_tmp();
542 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
543 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
544 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
545 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
546 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
548 tcg_gen_ld_tl(t
, r_tmp
, sizeof(target_ulong
) * reg
);
553 static inline void gen_store_srsgpr (TCGv t
, int reg
)
556 TCGv r_tmp
= new_tmp();
558 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
559 tcg_gen_shri_i32(r_tmp
, r_tmp
, CP0SRSCtl_PSS
);
560 tcg_gen_andi_i32(r_tmp
, r_tmp
, 0xf);
561 tcg_gen_muli_i32(r_tmp
, r_tmp
, sizeof(target_ulong
) * 32);
562 tcg_gen_add_i32(r_tmp
, cpu_env
, r_tmp
);
564 tcg_gen_st_tl(t
, r_tmp
, sizeof(target_ulong
) * reg
);
569 /* Floating point register moves. */
570 #define FGEN32(func, NAME) \
571 static GenOpFunc *NAME ## _table [32] = { \
572 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
573 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
574 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
575 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
576 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
577 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
578 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
579 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
581 static always_inline void func(int n) \
583 NAME ## _table[n](); \
586 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
587 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
589 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
590 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
592 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
593 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
595 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
596 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
598 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
599 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
601 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
602 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
604 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
605 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
607 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
608 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
610 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
611 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
613 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
615 glue(gen_op_load_fpr_, FTn)(Fn); \
618 #define GEN_STORE_FTN_FREG(Fn, FTn) \
620 glue(gen_op_store_fpr_, FTn)(Fn); \
623 #define FOP_CONDS(type, fmt) \
624 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
625 gen_op_cmp ## type ## _ ## fmt ## _f, \
626 gen_op_cmp ## type ## _ ## fmt ## _un, \
627 gen_op_cmp ## type ## _ ## fmt ## _eq, \
628 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
629 gen_op_cmp ## type ## _ ## fmt ## _olt, \
630 gen_op_cmp ## type ## _ ## fmt ## _ult, \
631 gen_op_cmp ## type ## _ ## fmt ## _ole, \
632 gen_op_cmp ## type ## _ ## fmt ## _ule, \
633 gen_op_cmp ## type ## _ ## fmt ## _sf, \
634 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
635 gen_op_cmp ## type ## _ ## fmt ## _seq, \
636 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
637 gen_op_cmp ## type ## _ ## fmt ## _lt, \
638 gen_op_cmp ## type ## _ ## fmt ## _nge, \
639 gen_op_cmp ## type ## _ ## fmt ## _le, \
640 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
642 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
644 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
655 #define OP_COND(name, cond) \
656 void glue(gen_op_, name) (void) \
658 int l1 = gen_new_label(); \
659 int l2 = gen_new_label(); \
661 tcg_gen_brcond_tl(cond, cpu_T[0], cpu_T[1], l1); \
662 tcg_gen_movi_tl(cpu_T[0], 0); \
665 tcg_gen_movi_tl(cpu_T[0], 1); \
668 OP_COND(eq
, TCG_COND_EQ
);
669 OP_COND(ne
, TCG_COND_NE
);
670 OP_COND(ge
, TCG_COND_GE
);
671 OP_COND(geu
, TCG_COND_GEU
);
672 OP_COND(lt
, TCG_COND_LT
);
673 OP_COND(ltu
, TCG_COND_LTU
);
676 #define OP_CONDI(name, cond) \
677 void glue(gen_op_, name) (target_ulong val) \
679 int l1 = gen_new_label(); \
680 int l2 = gen_new_label(); \
682 tcg_gen_brcond_tl(cond, cpu_T[0], tcg_const_tl(val), l1); \
683 tcg_gen_movi_tl(cpu_T[0], 0); \
686 tcg_gen_movi_tl(cpu_T[0], 1); \
689 OP_CONDI(lti
, TCG_COND_LT
);
690 OP_CONDI(ltiu
, TCG_COND_LTU
);
693 #define OP_CONDZ(name, cond) \
694 void glue(gen_op_, name) (void) \
696 int l1 = gen_new_label(); \
697 int l2 = gen_new_label(); \
699 tcg_gen_brcond_tl(cond, cpu_T[0], tcg_const_tl(0), l1); \
700 tcg_gen_movi_tl(cpu_T[0], 0); \
703 tcg_gen_movi_tl(cpu_T[0], 1); \
706 OP_CONDZ(gez
, TCG_COND_GE
);
707 OP_CONDZ(gtz
, TCG_COND_GT
);
708 OP_CONDZ(lez
, TCG_COND_LE
);
709 OP_CONDZ(ltz
, TCG_COND_LT
);
712 static inline void gen_save_pc(target_ulong pc
)
714 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
715 TCGv r_tc_off
= new_tmp();
716 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
717 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
719 tcg_gen_movi_tl(r_tmp
, pc
);
720 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
721 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
722 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
723 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
724 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
728 static inline void gen_breg_pc(void)
730 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
731 TCGv r_tc_off
= new_tmp();
732 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
733 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
735 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
736 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
737 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
738 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
739 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
740 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
744 static inline void gen_save_btarget(target_ulong btarget
)
746 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
748 tcg_gen_movi_tl(r_tmp
, btarget
);
749 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
752 static always_inline
void gen_save_breg_target(int reg
)
754 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
756 gen_load_gpr(r_tmp
, reg
);
757 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
760 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
762 #if defined MIPS_DEBUG_DISAS
763 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
764 fprintf(logfile
, "hflags %08x saved %08x\n",
765 ctx
->hflags
, ctx
->saved_hflags
);
768 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
769 gen_save_pc(ctx
->pc
);
770 ctx
->saved_pc
= ctx
->pc
;
772 if (ctx
->hflags
!= ctx
->saved_hflags
) {
773 gen_op_save_state(ctx
->hflags
);
774 ctx
->saved_hflags
= ctx
->hflags
;
775 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
781 gen_save_btarget(ctx
->btarget
);
787 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
789 ctx
->saved_hflags
= ctx
->hflags
;
790 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
796 ctx
->btarget
= env
->btarget
;
801 static always_inline
void
802 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
804 save_cpu_state(ctx
, 1);
805 tcg_gen_helper_0_2(do_raise_exception_err
, tcg_const_i32(excp
), tcg_const_i32(err
));
806 tcg_gen_helper_0_0(do_interrupt_restart
);
810 static always_inline
void
811 generate_exception (DisasContext
*ctx
, int excp
)
813 save_cpu_state(ctx
, 1);
814 tcg_gen_helper_0_1(do_raise_exception
, tcg_const_i32(excp
));
815 tcg_gen_helper_0_0(do_interrupt_restart
);
819 /* Addresses computation */
820 static inline void gen_op_addr_add (void)
822 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
824 #if defined(TARGET_MIPS64)
825 /* For compatibility with 32-bit code, data reference in user mode
826 with Status_UX = 0 should be casted to 32-bit and sign extended.
827 See the MIPS64 PRA manual, section 4.10. */
829 TCGv r_tmp
= new_tmp();
830 int l1
= gen_new_label();
832 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
833 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
834 tcg_gen_brcond_i32(TCG_COND_NE
, r_tmp
, tcg_const_i32(MIPS_HFLAG_UM
), l1
);
835 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
836 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
837 tcg_gen_brcond_i32(TCG_COND_NE
, r_tmp
, tcg_const_i32(0), l1
);
838 tcg_gen_ext32s_i64(cpu_T
[0], cpu_T
[0]);
845 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
847 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
848 generate_exception_err(ctx
, EXCP_CpU
, 1);
851 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
853 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
854 generate_exception_err(ctx
, EXCP_CpU
, 1);
857 /* Verify that the processor is running with COP1X instructions enabled.
858 This is associated with the nabla symbol in the MIPS32 and MIPS64
861 static always_inline
void check_cop1x(DisasContext
*ctx
)
863 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
864 generate_exception(ctx
, EXCP_RI
);
867 /* Verify that the processor is running with 64-bit floating-point
868 operations enabled. */
870 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
872 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
873 generate_exception(ctx
, EXCP_RI
);
877 * Verify if floating point register is valid; an operation is not defined
878 * if bit 0 of any register specification is set and the FR bit in the
879 * Status register equals zero, since the register numbers specify an
880 * even-odd pair of adjacent coprocessor general registers. When the FR bit
881 * in the Status register equals one, both even and odd register numbers
882 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
884 * Multiple 64 bit wide registers can be checked by calling
885 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
887 void check_cp1_registers(DisasContext
*ctx
, int regs
)
889 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
890 generate_exception(ctx
, EXCP_RI
);
893 /* This code generates a "reserved instruction" exception if the
894 CPU does not support the instruction set corresponding to flags. */
895 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
897 if (unlikely(!(env
->insn_flags
& flags
)))
898 generate_exception(ctx
, EXCP_RI
);
901 /* This code generates a "reserved instruction" exception if 64-bit
902 instructions are not enabled. */
903 static always_inline
void check_mips_64(DisasContext
*ctx
)
905 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
906 generate_exception(ctx
, EXCP_RI
);
909 /* load/store instructions. */
910 #if defined(CONFIG_USER_ONLY)
911 #define op_ldst(name) gen_op_##name##_raw()
912 #define OP_LD_TABLE(width)
913 #define OP_ST_TABLE(width)
915 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
916 #define OP_LD_TABLE(width) \
917 static GenOpFunc *gen_op_l##width[] = { \
918 &gen_op_l##width##_kernel, \
919 &gen_op_l##width##_super, \
920 &gen_op_l##width##_user, \
922 #define OP_ST_TABLE(width) \
923 static GenOpFunc *gen_op_s##width[] = { \
924 &gen_op_s##width##_kernel, \
925 &gen_op_s##width##_super, \
926 &gen_op_s##width##_user, \
930 #if defined(TARGET_MIPS64)
947 #define OP_LD(insn,fname) \
948 void inline op_ldst_##insn(DisasContext *ctx) \
950 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
957 #if defined(TARGET_MIPS64)
963 #define OP_ST(insn,fname) \
964 void inline op_ldst_##insn(DisasContext *ctx) \
966 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
971 #if defined(TARGET_MIPS64)
976 #define OP_LD_ATOMIC(insn,fname) \
977 void inline op_ldst_##insn(DisasContext *ctx) \
979 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]); \
980 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
981 tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUState, CP0_LLAddr)); \
983 OP_LD_ATOMIC(ll
,ld32s
);
984 #if defined(TARGET_MIPS64)
985 OP_LD_ATOMIC(lld
,ld64
);
989 #define OP_ST_ATOMIC(insn,fname,almask) \
990 void inline op_ldst_##insn(DisasContext *ctx) \
992 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL); \
993 int l1 = gen_new_label(); \
994 int l2 = gen_new_label(); \
995 int l3 = gen_new_label(); \
997 tcg_gen_andi_tl(r_tmp, cpu_T[0], almask); \
998 tcg_gen_brcond_tl(TCG_COND_EQ, r_tmp, tcg_const_tl(0), l1); \
999 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1000 generate_exception(ctx, EXCP_AdES); \
1001 gen_set_label(l1); \
1002 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1003 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], r_tmp, l2); \
1004 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1005 tcg_gen_movi_tl(cpu_T[0], 1); \
1007 gen_set_label(l2); \
1008 tcg_gen_movi_tl(cpu_T[0], 0); \
1009 gen_set_label(l3); \
1011 OP_ST_ATOMIC(sc
,st32
,0x3);
1012 #if defined(TARGET_MIPS64)
1013 OP_ST_ATOMIC(scd
,st64
,0x7);
1017 void inline op_ldst_lwc1(DisasContext
*ctx
)
1022 void inline op_ldst_ldc1(DisasContext
*ctx
)
1027 void inline op_ldst_swc1(DisasContext
*ctx
)
1032 void inline op_ldst_sdc1(DisasContext
*ctx
)
1037 /* Load and store */
1038 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1039 int base
, int16_t offset
)
1041 const char *opn
= "ldst";
1044 tcg_gen_movi_tl(cpu_T
[0], offset
);
1045 } else if (offset
== 0) {
1046 gen_load_gpr(cpu_T
[0], base
);
1048 gen_load_gpr(cpu_T
[0], base
);
1049 tcg_gen_movi_tl(cpu_T
[1], offset
);
1052 /* Don't do NOP if destination is zero: we must perform the actual
1055 #if defined(TARGET_MIPS64)
1058 gen_store_gpr(cpu_T
[0], rt
);
1063 gen_store_gpr(cpu_T
[0], rt
);
1068 gen_store_gpr(cpu_T
[0], rt
);
1072 gen_load_gpr(cpu_T
[1], rt
);
1077 save_cpu_state(ctx
, 1);
1078 gen_load_gpr(cpu_T
[1], rt
);
1080 gen_store_gpr(cpu_T
[0], rt
);
1084 gen_load_gpr(cpu_T
[1], rt
);
1086 gen_store_gpr(cpu_T
[1], rt
);
1090 gen_load_gpr(cpu_T
[1], rt
);
1095 gen_load_gpr(cpu_T
[1], rt
);
1097 gen_store_gpr(cpu_T
[1], rt
);
1101 gen_load_gpr(cpu_T
[1], rt
);
1108 gen_store_gpr(cpu_T
[0], rt
);
1112 gen_load_gpr(cpu_T
[1], rt
);
1118 gen_store_gpr(cpu_T
[0], rt
);
1122 gen_load_gpr(cpu_T
[1], rt
);
1128 gen_store_gpr(cpu_T
[0], rt
);
1133 gen_store_gpr(cpu_T
[0], rt
);
1137 gen_load_gpr(cpu_T
[1], rt
);
1143 gen_store_gpr(cpu_T
[0], rt
);
1147 gen_load_gpr(cpu_T
[1], rt
);
1149 gen_store_gpr(cpu_T
[1], rt
);
1153 gen_load_gpr(cpu_T
[1], rt
);
1158 gen_load_gpr(cpu_T
[1], rt
);
1160 gen_store_gpr(cpu_T
[1], rt
);
1164 gen_load_gpr(cpu_T
[1], rt
);
1170 gen_store_gpr(cpu_T
[0], rt
);
1174 save_cpu_state(ctx
, 1);
1175 gen_load_gpr(cpu_T
[1], rt
);
1177 gen_store_gpr(cpu_T
[0], rt
);
1182 generate_exception(ctx
, EXCP_RI
);
1185 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1188 /* Load and store */
1189 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1190 int base
, int16_t offset
)
1192 const char *opn
= "flt_ldst";
1195 tcg_gen_movi_tl(cpu_T
[0], offset
);
1196 } else if (offset
== 0) {
1197 gen_load_gpr(cpu_T
[0], base
);
1199 gen_load_gpr(cpu_T
[0], base
);
1200 tcg_gen_movi_tl(cpu_T
[1], offset
);
1203 /* Don't do NOP if destination is zero: we must perform the actual
1208 GEN_STORE_FTN_FREG(ft
, WT0
);
1212 GEN_LOAD_FREG_FTN(WT0
, ft
);
1218 GEN_STORE_FTN_FREG(ft
, DT0
);
1222 GEN_LOAD_FREG_FTN(DT0
, ft
);
1228 generate_exception(ctx
, EXCP_RI
);
1231 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1234 /* Arithmetic with immediate operand */
1235 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1236 int rt
, int rs
, int16_t imm
)
1239 const char *opn
= "imm arith";
1241 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1242 /* If no destination, treat it as a NOP.
1243 For addi, we must generate the overflow exception when needed. */
1247 uimm
= (uint16_t)imm
;
1251 #if defined(TARGET_MIPS64)
1257 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1258 tcg_gen_movi_tl(cpu_T
[1], uimm
);
1263 gen_load_gpr(cpu_T
[0], rs
);
1266 tcg_gen_movi_tl(cpu_T
[0], imm
<< 16);
1271 #if defined(TARGET_MIPS64)
1280 gen_load_gpr(cpu_T
[0], rs
);
1286 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1287 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1288 int l1
= gen_new_label();
1290 save_cpu_state(ctx
, 1);
1291 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1292 tcg_gen_addi_tl(cpu_T
[0], r_tmp1
, uimm
);
1294 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1295 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1296 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1297 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1298 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1299 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1300 /* operands of same sign, result different sign */
1301 generate_exception(ctx
, EXCP_OVERFLOW
);
1304 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1309 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1310 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1311 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1314 #if defined(TARGET_MIPS64)
1317 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1318 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1319 int l1
= gen_new_label();
1321 save_cpu_state(ctx
, 1);
1322 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1323 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1325 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1326 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1327 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1328 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1329 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1330 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1331 /* operands of same sign, result different sign */
1332 generate_exception(ctx
, EXCP_OVERFLOW
);
1338 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1351 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1355 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1359 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1366 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1367 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1368 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1372 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1373 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1374 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1378 switch ((ctx
->opcode
>> 21) & 0x1f) {
1380 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1381 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1382 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1386 /* rotr is decoded as srl on non-R2 CPUs */
1387 if (env
->insn_flags
& ISA_MIPS32R2
) {
1389 TCGv r_tmp1
= new_tmp();
1390 TCGv r_tmp2
= new_tmp();
1392 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1393 tcg_gen_movi_i32(r_tmp2
, 0x20);
1394 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1395 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1396 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1397 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1398 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1404 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1405 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1406 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1411 MIPS_INVAL("invalid srl flag");
1412 generate_exception(ctx
, EXCP_RI
);
1416 #if defined(TARGET_MIPS64)
1418 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1422 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1426 switch ((ctx
->opcode
>> 21) & 0x1f) {
1428 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1432 /* drotr is decoded as dsrl on non-R2 CPUs */
1433 if (env
->insn_flags
& ISA_MIPS32R2
) {
1435 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1437 tcg_gen_movi_tl(r_tmp1
, 0x40);
1438 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1439 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1440 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1441 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1445 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1450 MIPS_INVAL("invalid dsrl flag");
1451 generate_exception(ctx
, EXCP_RI
);
1456 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1460 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1464 switch ((ctx
->opcode
>> 21) & 0x1f) {
1466 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1470 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1471 if (env
->insn_flags
& ISA_MIPS32R2
) {
1472 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1473 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1475 tcg_gen_movi_tl(r_tmp1
, 0x40);
1476 tcg_gen_movi_tl(r_tmp2
, 32);
1477 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1478 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1479 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1480 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], r_tmp2
);
1481 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1484 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1489 MIPS_INVAL("invalid dsrl32 flag");
1490 generate_exception(ctx
, EXCP_RI
);
1497 generate_exception(ctx
, EXCP_RI
);
1500 gen_store_gpr(cpu_T
[0], rt
);
1501 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1505 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1506 int rd
, int rs
, int rt
)
1508 const char *opn
= "arith";
1510 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1511 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1512 /* If no destination, treat it as a NOP.
1513 For add & sub, we must generate the overflow exception when needed. */
1517 gen_load_gpr(cpu_T
[0], rs
);
1518 /* Specialcase the conventional move operation. */
1519 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1520 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1521 gen_store_gpr(cpu_T
[0], rd
);
1524 gen_load_gpr(cpu_T
[1], rt
);
1528 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1529 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1530 int l1
= gen_new_label();
1532 save_cpu_state(ctx
, 1);
1533 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1534 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1535 tcg_gen_add_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1537 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1538 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1539 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1540 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1541 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1542 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1543 /* operands of same sign, result different sign */
1544 generate_exception(ctx
, EXCP_OVERFLOW
);
1547 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1552 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1553 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1554 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1555 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1560 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1561 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1562 int l1
= gen_new_label();
1564 save_cpu_state(ctx
, 1);
1565 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1566 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1567 tcg_gen_sub_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1569 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1570 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1571 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1572 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1573 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1574 /* operands of different sign, first operand and result different sign */
1575 generate_exception(ctx
, EXCP_OVERFLOW
);
1578 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1583 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1584 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1585 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1586 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1589 #if defined(TARGET_MIPS64)
1592 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1593 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1594 int l1
= gen_new_label();
1596 save_cpu_state(ctx
, 1);
1597 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1598 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1600 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1601 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1602 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1603 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1604 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1605 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1606 /* operands of same sign, result different sign */
1607 generate_exception(ctx
, EXCP_OVERFLOW
);
1613 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1618 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1619 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1620 int l1
= gen_new_label();
1622 save_cpu_state(ctx
, 1);
1623 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1624 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1626 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1627 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1628 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1629 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1630 tcg_gen_brcond_tl(TCG_COND_EQ
, r_tmp1
, tcg_const_tl(0), l1
);
1631 /* operands of different sign, first operand and result different sign */
1632 generate_exception(ctx
, EXCP_OVERFLOW
);
1638 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1651 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1655 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1656 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
1660 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1664 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1668 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1669 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1670 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1671 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1676 int l1
= gen_new_label();
1678 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1679 gen_store_gpr(cpu_T
[0], rd
);
1686 int l1
= gen_new_label();
1688 tcg_gen_brcond_tl(TCG_COND_NE
, cpu_T
[1], tcg_const_tl(0), l1
);
1689 gen_store_gpr(cpu_T
[0], rd
);
1695 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1696 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1697 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1698 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1699 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1703 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1704 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1705 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1706 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1710 switch ((ctx
->opcode
>> 6) & 0x1f) {
1712 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1713 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1714 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1715 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1719 /* rotrv is decoded as srlv on non-R2 CPUs */
1720 if (env
->insn_flags
& ISA_MIPS32R2
) {
1721 int l1
= gen_new_label();
1722 int l2
= gen_new_label();
1724 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1725 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[0], tcg_const_tl(0), l1
);
1727 TCGv r_tmp1
= new_tmp();
1728 TCGv r_tmp2
= new_tmp();
1729 TCGv r_tmp3
= new_tmp();
1731 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1732 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1733 tcg_gen_movi_i32(r_tmp3
, 0x20);
1734 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1735 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1736 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1737 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1738 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1745 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1749 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1750 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1751 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1752 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1757 MIPS_INVAL("invalid srlv flag");
1758 generate_exception(ctx
, EXCP_RI
);
1762 #if defined(TARGET_MIPS64)
1764 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1765 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1769 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1770 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1774 switch ((ctx
->opcode
>> 6) & 0x1f) {
1776 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1777 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1781 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1782 if (env
->insn_flags
& ISA_MIPS32R2
) {
1783 int l1
= gen_new_label();
1784 int l2
= gen_new_label();
1786 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1787 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[0], tcg_const_tl(0), l1
);
1789 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1791 tcg_gen_movi_tl(r_tmp1
, 0x40);
1792 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1793 tcg_gen_shl_tl(r_tmp1
, cpu_T
[1], r_tmp1
);
1794 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1795 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1799 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1803 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1804 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1809 MIPS_INVAL("invalid dsrlv flag");
1810 generate_exception(ctx
, EXCP_RI
);
1817 generate_exception(ctx
, EXCP_RI
);
1820 gen_store_gpr(cpu_T
[0], rd
);
1822 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1825 /* Arithmetic on HI/LO registers */
1826 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1828 const char *opn
= "hilo";
1830 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1837 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, HI
[0]));
1838 gen_store_gpr(cpu_T
[0], reg
);
1842 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, LO
[0]));
1843 gen_store_gpr(cpu_T
[0], reg
);
1847 gen_load_gpr(cpu_T
[0], reg
);
1848 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, HI
[0]));
1852 gen_load_gpr(cpu_T
[0], reg
);
1853 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, LO
[0]));
1858 generate_exception(ctx
, EXCP_RI
);
1861 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1864 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1867 const char *opn
= "mul/div";
1869 gen_load_gpr(cpu_T
[0], rs
);
1870 gen_load_gpr(cpu_T
[1], rt
);
1874 int l1
= gen_new_label();
1876 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1878 TCGv r_tmp1
= new_tmp();
1879 TCGv r_tmp2
= new_tmp();
1880 TCGv r_tmp3
= new_tmp();
1881 TCGv r_tc_off
= new_tmp();
1882 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1883 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1885 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1886 tcg_gen_ext_i32_tl(r_tmp2
, cpu_T
[1]);
1887 tcg_gen_div_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1888 tcg_gen_rem_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1889 tcg_gen_trunc_tl_i32(cpu_T
[0], r_tmp3
);
1890 tcg_gen_trunc_tl_i32(cpu_T
[1], r_tmp1
);
1894 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1895 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1896 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1897 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1898 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1899 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
1908 int l1
= gen_new_label();
1910 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1912 TCGv r_tmp1
= new_tmp();
1913 TCGv r_tmp2
= new_tmp();
1914 TCGv r_tmp3
= new_tmp();
1915 TCGv r_tc_off
= new_tmp();
1916 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1917 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1919 tcg_gen_ext_i32_tl(r_tmp1
, cpu_T
[0]);
1920 tcg_gen_ext_i32_tl(r_tmp2
, cpu_T
[1]);
1921 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1922 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1923 tcg_gen_trunc_tl_i32(cpu_T
[0], r_tmp3
);
1924 tcg_gen_trunc_tl_i32(cpu_T
[1], r_tmp1
);
1928 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1929 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1930 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1931 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1932 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1933 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
1948 #if defined(TARGET_MIPS64)
1951 int l1
= gen_new_label();
1953 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1955 TCGv r_tc_off
= new_tmp();
1956 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1957 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1958 int l2
= gen_new_label();
1959 int l3
= gen_new_label();
1961 tcg_gen_brcond_tl(TCG_COND_NE
, cpu_T
[0], tcg_const_tl(1ULL << 63), l2
);
1962 tcg_gen_brcond_tl(TCG_COND_NE
, cpu_T
[1], tcg_const_tl(-1ULL), l2
);
1963 tcg_gen_div_i64(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1964 tcg_gen_movi_tl(cpu_T
[1], 0);
1967 tcg_gen_div_i64(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1968 tcg_gen_rem_i64(cpu_T
[1], cpu_T
[0], cpu_T
[1]);
1971 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1972 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1973 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
1974 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
1975 tcg_gen_st_tl(cpu_T
[0], r_ptr
, offsetof(CPUState
, LO
));
1976 tcg_gen_st_tl(cpu_T
[1], r_ptr
, offsetof(CPUState
, HI
));
1985 int l1
= gen_new_label();
1987 tcg_gen_brcond_tl(TCG_COND_EQ
, cpu_T
[1], tcg_const_tl(0), l1
);
1989 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1990 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1991 TCGv r_tc_off
= new_tmp();
1992 TCGv r_tc_off_tl
= tcg_temp_new(TCG_TYPE_TL
);
1993 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
1995 tcg_gen_divu_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
1996 tcg_gen_remu_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1997 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
1998 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
1999 tcg_gen_ext_i32_ptr(r_tc_off_tl
, r_tc_off
);
2000 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_tl
);
2001 tcg_gen_st_tl(r_tmp1
, r_ptr
, offsetof(CPUState
, LO
));
2002 tcg_gen_st_tl(r_tmp2
, r_ptr
, offsetof(CPUState
, HI
));
2036 generate_exception(ctx
, EXCP_RI
);
2039 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2042 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2043 int rd
, int rs
, int rt
)
2045 const char *opn
= "mul vr54xx";
2047 gen_load_gpr(cpu_T
[0], rs
);
2048 gen_load_gpr(cpu_T
[1], rt
);
2051 case OPC_VR54XX_MULS
:
2055 case OPC_VR54XX_MULSU
:
2059 case OPC_VR54XX_MACC
:
2063 case OPC_VR54XX_MACCU
:
2067 case OPC_VR54XX_MSAC
:
2071 case OPC_VR54XX_MSACU
:
2075 case OPC_VR54XX_MULHI
:
2079 case OPC_VR54XX_MULHIU
:
2083 case OPC_VR54XX_MULSHI
:
2087 case OPC_VR54XX_MULSHIU
:
2091 case OPC_VR54XX_MACCHI
:
2095 case OPC_VR54XX_MACCHIU
:
2099 case OPC_VR54XX_MSACHI
:
2103 case OPC_VR54XX_MSACHIU
:
2108 MIPS_INVAL("mul vr54xx");
2109 generate_exception(ctx
, EXCP_RI
);
2112 gen_store_gpr(cpu_T
[0], rd
);
2113 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2116 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2119 const char *opn
= "CLx";
2125 gen_load_gpr(cpu_T
[0], rs
);
2128 tcg_gen_helper_0_0(do_clo
);
2132 tcg_gen_helper_0_0(do_clz
);
2135 #if defined(TARGET_MIPS64)
2137 tcg_gen_helper_0_0(do_dclo
);
2141 tcg_gen_helper_0_0(do_dclz
);
2147 generate_exception(ctx
, EXCP_RI
);
2150 gen_store_gpr(cpu_T
[0], rd
);
2151 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2155 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2156 int rs
, int rt
, int16_t imm
)
2161 /* Load needed operands */
2169 /* Compare two registers */
2171 gen_load_gpr(cpu_T
[0], rs
);
2172 gen_load_gpr(cpu_T
[1], rt
);
2182 /* Compare register to immediate */
2183 if (rs
!= 0 || imm
!= 0) {
2184 gen_load_gpr(cpu_T
[0], rs
);
2185 tcg_gen_movi_tl(cpu_T
[1], (int32_t)imm
);
2192 case OPC_TEQ
: /* rs == rs */
2193 case OPC_TEQI
: /* r0 == 0 */
2194 case OPC_TGE
: /* rs >= rs */
2195 case OPC_TGEI
: /* r0 >= 0 */
2196 case OPC_TGEU
: /* rs >= rs unsigned */
2197 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2199 tcg_gen_movi_tl(cpu_T
[0], 1);
2201 case OPC_TLT
: /* rs < rs */
2202 case OPC_TLTI
: /* r0 < 0 */
2203 case OPC_TLTU
: /* rs < rs unsigned */
2204 case OPC_TLTIU
: /* r0 < 0 unsigned */
2205 case OPC_TNE
: /* rs != rs */
2206 case OPC_TNEI
: /* r0 != 0 */
2207 /* Never trap: treat as NOP. */
2211 generate_exception(ctx
, EXCP_RI
);
2242 generate_exception(ctx
, EXCP_RI
);
2246 save_cpu_state(ctx
, 1);
2248 ctx
->bstate
= BS_STOP
;
2251 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2253 TranslationBlock
*tb
;
2255 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2258 tcg_gen_exit_tb((long)tb
+ n
);
2265 /* Branches (before delay slot) */
2266 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2267 int rs
, int rt
, int32_t offset
)
2269 target_ulong btarget
= -1;
2273 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2274 #ifdef MIPS_DEBUG_DISAS
2275 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2277 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2281 generate_exception(ctx
, EXCP_RI
);
2285 /* Load needed operands */
2291 /* Compare two registers */
2293 gen_load_gpr(cpu_T
[0], rs
);
2294 gen_load_gpr(cpu_T
[1], rt
);
2297 btarget
= ctx
->pc
+ 4 + offset
;
2311 /* Compare to zero */
2313 gen_load_gpr(cpu_T
[0], rs
);
2316 btarget
= ctx
->pc
+ 4 + offset
;
2320 /* Jump to immediate */
2321 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2325 /* Jump to register */
2326 if (offset
!= 0 && offset
!= 16) {
2327 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2328 others are reserved. */
2329 MIPS_INVAL("jump hint");
2330 generate_exception(ctx
, EXCP_RI
);
2333 gen_save_breg_target(rs
);
2336 MIPS_INVAL("branch/jump");
2337 generate_exception(ctx
, EXCP_RI
);
2341 /* No condition to be computed */
2343 case OPC_BEQ
: /* rx == rx */
2344 case OPC_BEQL
: /* rx == rx likely */
2345 case OPC_BGEZ
: /* 0 >= 0 */
2346 case OPC_BGEZL
: /* 0 >= 0 likely */
2347 case OPC_BLEZ
: /* 0 <= 0 */
2348 case OPC_BLEZL
: /* 0 <= 0 likely */
2350 ctx
->hflags
|= MIPS_HFLAG_B
;
2351 MIPS_DEBUG("balways");
2353 case OPC_BGEZAL
: /* 0 >= 0 */
2354 case OPC_BGEZALL
: /* 0 >= 0 likely */
2355 /* Always take and link */
2357 ctx
->hflags
|= MIPS_HFLAG_B
;
2358 MIPS_DEBUG("balways and link");
2360 case OPC_BNE
: /* rx != rx */
2361 case OPC_BGTZ
: /* 0 > 0 */
2362 case OPC_BLTZ
: /* 0 < 0 */
2364 MIPS_DEBUG("bnever (NOP)");
2366 case OPC_BLTZAL
: /* 0 < 0 */
2367 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2368 gen_store_gpr(cpu_T
[0], 31);
2369 MIPS_DEBUG("bnever and link");
2371 case OPC_BLTZALL
: /* 0 < 0 likely */
2372 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2373 gen_store_gpr(cpu_T
[0], 31);
2374 /* Skip the instruction in the delay slot */
2375 MIPS_DEBUG("bnever, link and skip");
2378 case OPC_BNEL
: /* rx != rx likely */
2379 case OPC_BGTZL
: /* 0 > 0 likely */
2380 case OPC_BLTZL
: /* 0 < 0 likely */
2381 /* Skip the instruction in the delay slot */
2382 MIPS_DEBUG("bnever and skip");
2386 ctx
->hflags
|= MIPS_HFLAG_B
;
2387 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
2391 ctx
->hflags
|= MIPS_HFLAG_B
;
2392 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
2395 ctx
->hflags
|= MIPS_HFLAG_BR
;
2396 MIPS_DEBUG("jr %s", regnames
[rs
]);
2400 ctx
->hflags
|= MIPS_HFLAG_BR
;
2401 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2404 MIPS_INVAL("branch/jump");
2405 generate_exception(ctx
, EXCP_RI
);
2412 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2413 regnames
[rs
], regnames
[rt
], btarget
);
2417 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2418 regnames
[rs
], regnames
[rt
], btarget
);
2422 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2423 regnames
[rs
], regnames
[rt
], btarget
);
2427 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2428 regnames
[rs
], regnames
[rt
], btarget
);
2432 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2436 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2440 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2446 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2450 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2454 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2458 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2462 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2466 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2470 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2475 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2477 ctx
->hflags
|= MIPS_HFLAG_BC
;
2478 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2483 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2485 ctx
->hflags
|= MIPS_HFLAG_BL
;
2486 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2489 MIPS_INVAL("conditional branch/jump");
2490 generate_exception(ctx
, EXCP_RI
);
2494 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2495 blink
, ctx
->hflags
, btarget
);
2497 ctx
->btarget
= btarget
;
2499 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2500 gen_store_gpr(cpu_T
[0], blink
);
2504 /* special3 bitfield operations */
2505 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2506 int rs
, int lsb
, int msb
)
2508 gen_load_gpr(cpu_T
[1], rs
);
2513 gen_op_ext(lsb
, msb
+ 1);
2515 #if defined(TARGET_MIPS64)
2519 gen_op_dext(lsb
, msb
+ 1 + 32);
2524 gen_op_dext(lsb
+ 32, msb
+ 1);
2529 gen_op_dext(lsb
, msb
+ 1);
2535 gen_load_gpr(cpu_T
[0], rt
);
2536 gen_op_ins(lsb
, msb
- lsb
+ 1);
2538 #if defined(TARGET_MIPS64)
2542 gen_load_gpr(cpu_T
[0], rt
);
2543 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2548 gen_load_gpr(cpu_T
[0], rt
);
2549 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2554 gen_load_gpr(cpu_T
[0], rt
);
2555 gen_op_dins(lsb
, msb
- lsb
+ 1);
2560 MIPS_INVAL("bitops");
2561 generate_exception(ctx
, EXCP_RI
);
2564 gen_store_gpr(cpu_T
[0], rt
);
2567 /* CP0 (MMU and control) */
2568 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2570 const char *rn
= "invalid";
2573 check_insn(env
, ctx
, ISA_MIPS32
);
2579 gen_op_mfc0_index();
2583 check_insn(env
, ctx
, ASE_MT
);
2584 gen_op_mfc0_mvpcontrol();
2588 check_insn(env
, ctx
, ASE_MT
);
2589 gen_op_mfc0_mvpconf0();
2593 check_insn(env
, ctx
, ASE_MT
);
2594 gen_op_mfc0_mvpconf1();
2604 gen_op_mfc0_random();
2608 check_insn(env
, ctx
, ASE_MT
);
2609 gen_op_mfc0_vpecontrol();
2613 check_insn(env
, ctx
, ASE_MT
);
2614 gen_op_mfc0_vpeconf0();
2618 check_insn(env
, ctx
, ASE_MT
);
2619 gen_op_mfc0_vpeconf1();
2623 check_insn(env
, ctx
, ASE_MT
);
2624 gen_op_mfc0_yqmask();
2628 check_insn(env
, ctx
, ASE_MT
);
2629 gen_op_mfc0_vpeschedule();
2633 check_insn(env
, ctx
, ASE_MT
);
2634 gen_op_mfc0_vpeschefback();
2635 rn
= "VPEScheFBack";
2638 check_insn(env
, ctx
, ASE_MT
);
2639 gen_op_mfc0_vpeopt();
2649 gen_op_mfc0_entrylo0();
2653 check_insn(env
, ctx
, ASE_MT
);
2654 gen_op_mfc0_tcstatus();
2658 check_insn(env
, ctx
, ASE_MT
);
2659 gen_op_mfc0_tcbind();
2663 check_insn(env
, ctx
, ASE_MT
);
2664 gen_op_mfc0_tcrestart();
2668 check_insn(env
, ctx
, ASE_MT
);
2669 gen_op_mfc0_tchalt();
2673 check_insn(env
, ctx
, ASE_MT
);
2674 gen_op_mfc0_tccontext();
2678 check_insn(env
, ctx
, ASE_MT
);
2679 gen_op_mfc0_tcschedule();
2683 check_insn(env
, ctx
, ASE_MT
);
2684 gen_op_mfc0_tcschefback();
2694 gen_op_mfc0_entrylo1();
2704 gen_op_mfc0_context();
2708 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2709 rn
= "ContextConfig";
2718 gen_op_mfc0_pagemask();
2722 check_insn(env
, ctx
, ISA_MIPS32R2
);
2723 gen_op_mfc0_pagegrain();
2733 gen_op_mfc0_wired();
2737 check_insn(env
, ctx
, ISA_MIPS32R2
);
2738 gen_op_mfc0_srsconf0();
2742 check_insn(env
, ctx
, ISA_MIPS32R2
);
2743 gen_op_mfc0_srsconf1();
2747 check_insn(env
, ctx
, ISA_MIPS32R2
);
2748 gen_op_mfc0_srsconf2();
2752 check_insn(env
, ctx
, ISA_MIPS32R2
);
2753 gen_op_mfc0_srsconf3();
2757 check_insn(env
, ctx
, ISA_MIPS32R2
);
2758 gen_op_mfc0_srsconf4();
2768 check_insn(env
, ctx
, ISA_MIPS32R2
);
2769 gen_op_mfc0_hwrena();
2779 gen_op_mfc0_badvaddr();
2789 gen_op_mfc0_count();
2792 /* 6,7 are implementation dependent */
2800 gen_op_mfc0_entryhi();
2810 gen_op_mfc0_compare();
2813 /* 6,7 are implementation dependent */
2821 gen_op_mfc0_status();
2825 check_insn(env
, ctx
, ISA_MIPS32R2
);
2826 gen_op_mfc0_intctl();
2830 check_insn(env
, ctx
, ISA_MIPS32R2
);
2831 gen_op_mfc0_srsctl();
2835 check_insn(env
, ctx
, ISA_MIPS32R2
);
2836 gen_op_mfc0_srsmap();
2846 gen_op_mfc0_cause();
2870 check_insn(env
, ctx
, ISA_MIPS32R2
);
2871 gen_op_mfc0_ebase();
2881 gen_op_mfc0_config0();
2885 gen_op_mfc0_config1();
2889 gen_op_mfc0_config2();
2893 gen_op_mfc0_config3();
2896 /* 4,5 are reserved */
2897 /* 6,7 are implementation dependent */
2899 gen_op_mfc0_config6();
2903 gen_op_mfc0_config7();
2913 gen_op_mfc0_lladdr();
2923 gen_op_mfc0_watchlo(sel
);
2933 gen_op_mfc0_watchhi(sel
);
2943 #if defined(TARGET_MIPS64)
2944 check_insn(env
, ctx
, ISA_MIPS3
);
2945 gen_op_mfc0_xcontext();
2954 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2957 gen_op_mfc0_framemask();
2966 rn
= "'Diagnostic"; /* implementation dependent */
2971 gen_op_mfc0_debug(); /* EJTAG support */
2975 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2976 rn
= "TraceControl";
2979 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2980 rn
= "TraceControl2";
2983 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2984 rn
= "UserTraceData";
2987 // gen_op_mfc0_debug(); /* PDtrace support */
2997 gen_op_mfc0_depc(); /* EJTAG support */
3007 gen_op_mfc0_performance0();
3008 rn
= "Performance0";
3011 // gen_op_mfc0_performance1();
3012 rn
= "Performance1";
3015 // gen_op_mfc0_performance2();
3016 rn
= "Performance2";
3019 // gen_op_mfc0_performance3();
3020 rn
= "Performance3";
3023 // gen_op_mfc0_performance4();
3024 rn
= "Performance4";
3027 // gen_op_mfc0_performance5();
3028 rn
= "Performance5";
3031 // gen_op_mfc0_performance6();
3032 rn
= "Performance6";
3035 // gen_op_mfc0_performance7();
3036 rn
= "Performance7";
3061 gen_op_mfc0_taglo();
3068 gen_op_mfc0_datalo();
3081 gen_op_mfc0_taghi();
3088 gen_op_mfc0_datahi();
3098 gen_op_mfc0_errorepc();
3108 gen_op_mfc0_desave(); /* EJTAG support */
3118 #if defined MIPS_DEBUG_DISAS
3119 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3120 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3127 #if defined MIPS_DEBUG_DISAS
3128 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3129 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3133 generate_exception(ctx
, EXCP_RI
);
3136 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3138 const char *rn
= "invalid";
3141 check_insn(env
, ctx
, ISA_MIPS32
);
3147 gen_op_mtc0_index();
3151 check_insn(env
, ctx
, ASE_MT
);
3152 gen_op_mtc0_mvpcontrol();
3156 check_insn(env
, ctx
, ASE_MT
);
3161 check_insn(env
, ctx
, ASE_MT
);
3176 check_insn(env
, ctx
, ASE_MT
);
3177 gen_op_mtc0_vpecontrol();
3181 check_insn(env
, ctx
, ASE_MT
);
3182 gen_op_mtc0_vpeconf0();
3186 check_insn(env
, ctx
, ASE_MT
);
3187 gen_op_mtc0_vpeconf1();
3191 check_insn(env
, ctx
, ASE_MT
);
3192 gen_op_mtc0_yqmask();
3196 check_insn(env
, ctx
, ASE_MT
);
3197 gen_op_mtc0_vpeschedule();
3201 check_insn(env
, ctx
, ASE_MT
);
3202 gen_op_mtc0_vpeschefback();
3203 rn
= "VPEScheFBack";
3206 check_insn(env
, ctx
, ASE_MT
);
3207 gen_op_mtc0_vpeopt();
3217 gen_op_mtc0_entrylo0();
3221 check_insn(env
, ctx
, ASE_MT
);
3222 gen_op_mtc0_tcstatus();
3226 check_insn(env
, ctx
, ASE_MT
);
3227 gen_op_mtc0_tcbind();
3231 check_insn(env
, ctx
, ASE_MT
);
3232 gen_op_mtc0_tcrestart();
3236 check_insn(env
, ctx
, ASE_MT
);
3237 gen_op_mtc0_tchalt();
3241 check_insn(env
, ctx
, ASE_MT
);
3242 gen_op_mtc0_tccontext();
3246 check_insn(env
, ctx
, ASE_MT
);
3247 gen_op_mtc0_tcschedule();
3251 check_insn(env
, ctx
, ASE_MT
);
3252 gen_op_mtc0_tcschefback();
3262 gen_op_mtc0_entrylo1();
3272 gen_op_mtc0_context();
3276 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3277 rn
= "ContextConfig";
3286 gen_op_mtc0_pagemask();
3290 check_insn(env
, ctx
, ISA_MIPS32R2
);
3291 gen_op_mtc0_pagegrain();
3301 gen_op_mtc0_wired();
3305 check_insn(env
, ctx
, ISA_MIPS32R2
);
3306 gen_op_mtc0_srsconf0();
3310 check_insn(env
, ctx
, ISA_MIPS32R2
);
3311 gen_op_mtc0_srsconf1();
3315 check_insn(env
, ctx
, ISA_MIPS32R2
);
3316 gen_op_mtc0_srsconf2();
3320 check_insn(env
, ctx
, ISA_MIPS32R2
);
3321 gen_op_mtc0_srsconf3();
3325 check_insn(env
, ctx
, ISA_MIPS32R2
);
3326 gen_op_mtc0_srsconf4();
3336 check_insn(env
, ctx
, ISA_MIPS32R2
);
3337 gen_op_mtc0_hwrena();
3351 gen_op_mtc0_count();
3354 /* 6,7 are implementation dependent */
3358 /* Stop translation as we may have switched the execution mode */
3359 ctx
->bstate
= BS_STOP
;
3364 gen_op_mtc0_entryhi();
3374 gen_op_mtc0_compare();
3377 /* 6,7 are implementation dependent */
3381 /* Stop translation as we may have switched the execution mode */
3382 ctx
->bstate
= BS_STOP
;
3387 gen_op_mtc0_status();
3388 /* BS_STOP isn't good enough here, hflags may have changed. */
3389 gen_save_pc(ctx
->pc
+ 4);
3390 ctx
->bstate
= BS_EXCP
;
3394 check_insn(env
, ctx
, ISA_MIPS32R2
);
3395 gen_op_mtc0_intctl();
3396 /* Stop translation as we may have switched the execution mode */
3397 ctx
->bstate
= BS_STOP
;
3401 check_insn(env
, ctx
, ISA_MIPS32R2
);
3402 gen_op_mtc0_srsctl();
3403 /* Stop translation as we may have switched the execution mode */
3404 ctx
->bstate
= BS_STOP
;
3408 check_insn(env
, ctx
, ISA_MIPS32R2
);
3409 gen_op_mtc0_srsmap();
3410 /* Stop translation as we may have switched the execution mode */
3411 ctx
->bstate
= BS_STOP
;
3421 gen_op_mtc0_cause();
3427 /* Stop translation as we may have switched the execution mode */
3428 ctx
->bstate
= BS_STOP
;
3447 check_insn(env
, ctx
, ISA_MIPS32R2
);
3448 gen_op_mtc0_ebase();
3458 gen_op_mtc0_config0();
3460 /* Stop translation as we may have switched the execution mode */
3461 ctx
->bstate
= BS_STOP
;
3464 /* ignored, read only */
3468 gen_op_mtc0_config2();
3470 /* Stop translation as we may have switched the execution mode */
3471 ctx
->bstate
= BS_STOP
;
3474 /* ignored, read only */
3477 /* 4,5 are reserved */
3478 /* 6,7 are implementation dependent */
3488 rn
= "Invalid config selector";
3505 gen_op_mtc0_watchlo(sel
);
3515 gen_op_mtc0_watchhi(sel
);
3525 #if defined(TARGET_MIPS64)
3526 check_insn(env
, ctx
, ISA_MIPS3
);
3527 gen_op_mtc0_xcontext();
3536 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3539 gen_op_mtc0_framemask();
3548 rn
= "Diagnostic"; /* implementation dependent */
3553 gen_op_mtc0_debug(); /* EJTAG support */
3554 /* BS_STOP isn't good enough here, hflags may have changed. */
3555 gen_save_pc(ctx
->pc
+ 4);
3556 ctx
->bstate
= BS_EXCP
;
3560 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3561 rn
= "TraceControl";
3562 /* Stop translation as we may have switched the execution mode */
3563 ctx
->bstate
= BS_STOP
;
3566 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3567 rn
= "TraceControl2";
3568 /* Stop translation as we may have switched the execution mode */
3569 ctx
->bstate
= BS_STOP
;
3572 /* Stop translation as we may have switched the execution mode */
3573 ctx
->bstate
= BS_STOP
;
3574 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3575 rn
= "UserTraceData";
3576 /* Stop translation as we may have switched the execution mode */
3577 ctx
->bstate
= BS_STOP
;
3580 // gen_op_mtc0_debug(); /* PDtrace support */
3581 /* Stop translation as we may have switched the execution mode */
3582 ctx
->bstate
= BS_STOP
;
3592 gen_op_mtc0_depc(); /* EJTAG support */
3602 gen_op_mtc0_performance0();
3603 rn
= "Performance0";
3606 // gen_op_mtc0_performance1();
3607 rn
= "Performance1";
3610 // gen_op_mtc0_performance2();
3611 rn
= "Performance2";
3614 // gen_op_mtc0_performance3();
3615 rn
= "Performance3";
3618 // gen_op_mtc0_performance4();
3619 rn
= "Performance4";
3622 // gen_op_mtc0_performance5();
3623 rn
= "Performance5";
3626 // gen_op_mtc0_performance6();
3627 rn
= "Performance6";
3630 // gen_op_mtc0_performance7();
3631 rn
= "Performance7";
3657 gen_op_mtc0_taglo();
3664 gen_op_mtc0_datalo();
3677 gen_op_mtc0_taghi();
3684 gen_op_mtc0_datahi();
3695 gen_op_mtc0_errorepc();
3705 gen_op_mtc0_desave(); /* EJTAG support */
3711 /* Stop translation as we may have switched the execution mode */
3712 ctx
->bstate
= BS_STOP
;
3717 #if defined MIPS_DEBUG_DISAS
3718 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3719 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3726 #if defined MIPS_DEBUG_DISAS
3727 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3728 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3732 generate_exception(ctx
, EXCP_RI
);
3735 #if defined(TARGET_MIPS64)
3736 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3738 const char *rn
= "invalid";
3741 check_insn(env
, ctx
, ISA_MIPS64
);
3747 gen_op_mfc0_index();
3751 check_insn(env
, ctx
, ASE_MT
);
3752 gen_op_mfc0_mvpcontrol();
3756 check_insn(env
, ctx
, ASE_MT
);
3757 gen_op_mfc0_mvpconf0();
3761 check_insn(env
, ctx
, ASE_MT
);
3762 gen_op_mfc0_mvpconf1();
3772 gen_op_mfc0_random();
3776 check_insn(env
, ctx
, ASE_MT
);
3777 gen_op_mfc0_vpecontrol();
3781 check_insn(env
, ctx
, ASE_MT
);
3782 gen_op_mfc0_vpeconf0();
3786 check_insn(env
, ctx
, ASE_MT
);
3787 gen_op_mfc0_vpeconf1();
3791 check_insn(env
, ctx
, ASE_MT
);
3792 gen_op_dmfc0_yqmask();
3796 check_insn(env
, ctx
, ASE_MT
);
3797 gen_op_dmfc0_vpeschedule();
3801 check_insn(env
, ctx
, ASE_MT
);
3802 gen_op_dmfc0_vpeschefback();
3803 rn
= "VPEScheFBack";
3806 check_insn(env
, ctx
, ASE_MT
);
3807 gen_op_mfc0_vpeopt();
3817 gen_op_dmfc0_entrylo0();
3821 check_insn(env
, ctx
, ASE_MT
);
3822 gen_op_mfc0_tcstatus();
3826 check_insn(env
, ctx
, ASE_MT
);
3827 gen_op_mfc0_tcbind();
3831 check_insn(env
, ctx
, ASE_MT
);
3832 gen_op_dmfc0_tcrestart();
3836 check_insn(env
, ctx
, ASE_MT
);
3837 gen_op_dmfc0_tchalt();
3841 check_insn(env
, ctx
, ASE_MT
);
3842 gen_op_dmfc0_tccontext();
3846 check_insn(env
, ctx
, ASE_MT
);
3847 gen_op_dmfc0_tcschedule();
3851 check_insn(env
, ctx
, ASE_MT
);
3852 gen_op_dmfc0_tcschefback();
3862 gen_op_dmfc0_entrylo1();
3872 gen_op_dmfc0_context();
3876 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3877 rn
= "ContextConfig";
3886 gen_op_mfc0_pagemask();
3890 check_insn(env
, ctx
, ISA_MIPS32R2
);
3891 gen_op_mfc0_pagegrain();
3901 gen_op_mfc0_wired();
3905 check_insn(env
, ctx
, ISA_MIPS32R2
);
3906 gen_op_mfc0_srsconf0();
3910 check_insn(env
, ctx
, ISA_MIPS32R2
);
3911 gen_op_mfc0_srsconf1();
3915 check_insn(env
, ctx
, ISA_MIPS32R2
);
3916 gen_op_mfc0_srsconf2();
3920 check_insn(env
, ctx
, ISA_MIPS32R2
);
3921 gen_op_mfc0_srsconf3();
3925 check_insn(env
, ctx
, ISA_MIPS32R2
);
3926 gen_op_mfc0_srsconf4();
3936 check_insn(env
, ctx
, ISA_MIPS32R2
);
3937 gen_op_mfc0_hwrena();
3947 gen_op_dmfc0_badvaddr();
3957 gen_op_mfc0_count();
3960 /* 6,7 are implementation dependent */
3968 gen_op_dmfc0_entryhi();
3978 gen_op_mfc0_compare();
3981 /* 6,7 are implementation dependent */
3989 gen_op_mfc0_status();
3993 check_insn(env
, ctx
, ISA_MIPS32R2
);
3994 gen_op_mfc0_intctl();
3998 check_insn(env
, ctx
, ISA_MIPS32R2
);
3999 gen_op_mfc0_srsctl();
4003 check_insn(env
, ctx
, ISA_MIPS32R2
);
4004 gen_op_mfc0_srsmap();
4014 gen_op_mfc0_cause();
4038 check_insn(env
, ctx
, ISA_MIPS32R2
);
4039 gen_op_mfc0_ebase();
4049 gen_op_mfc0_config0();
4053 gen_op_mfc0_config1();
4057 gen_op_mfc0_config2();
4061 gen_op_mfc0_config3();
4064 /* 6,7 are implementation dependent */
4072 gen_op_dmfc0_lladdr();
4082 gen_op_dmfc0_watchlo(sel
);
4092 gen_op_mfc0_watchhi(sel
);
4102 check_insn(env
, ctx
, ISA_MIPS3
);
4103 gen_op_dmfc0_xcontext();
4111 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4114 gen_op_mfc0_framemask();
4123 rn
= "'Diagnostic"; /* implementation dependent */
4128 gen_op_mfc0_debug(); /* EJTAG support */
4132 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
4133 rn
= "TraceControl";
4136 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
4137 rn
= "TraceControl2";
4140 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
4141 rn
= "UserTraceData";
4144 // gen_op_dmfc0_debug(); /* PDtrace support */
4154 gen_op_dmfc0_depc(); /* EJTAG support */
4164 gen_op_mfc0_performance0();
4165 rn
= "Performance0";
4168 // gen_op_dmfc0_performance1();
4169 rn
= "Performance1";
4172 // gen_op_dmfc0_performance2();
4173 rn
= "Performance2";
4176 // gen_op_dmfc0_performance3();
4177 rn
= "Performance3";
4180 // gen_op_dmfc0_performance4();
4181 rn
= "Performance4";
4184 // gen_op_dmfc0_performance5();
4185 rn
= "Performance5";
4188 // gen_op_dmfc0_performance6();
4189 rn
= "Performance6";
4192 // gen_op_dmfc0_performance7();
4193 rn
= "Performance7";
4218 gen_op_mfc0_taglo();
4225 gen_op_mfc0_datalo();
4238 gen_op_mfc0_taghi();
4245 gen_op_mfc0_datahi();
4255 gen_op_dmfc0_errorepc();
4265 gen_op_mfc0_desave(); /* EJTAG support */
4275 #if defined MIPS_DEBUG_DISAS
4276 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4277 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4284 #if defined MIPS_DEBUG_DISAS
4285 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4286 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4290 generate_exception(ctx
, EXCP_RI
);
4293 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
4295 const char *rn
= "invalid";
4298 check_insn(env
, ctx
, ISA_MIPS64
);
4304 gen_op_mtc0_index();
4308 check_insn(env
, ctx
, ASE_MT
);
4309 gen_op_mtc0_mvpcontrol();
4313 check_insn(env
, ctx
, ASE_MT
);
4318 check_insn(env
, ctx
, ASE_MT
);
4333 check_insn(env
, ctx
, ASE_MT
);
4334 gen_op_mtc0_vpecontrol();
4338 check_insn(env
, ctx
, ASE_MT
);
4339 gen_op_mtc0_vpeconf0();
4343 check_insn(env
, ctx
, ASE_MT
);
4344 gen_op_mtc0_vpeconf1();
4348 check_insn(env
, ctx
, ASE_MT
);
4349 gen_op_mtc0_yqmask();
4353 check_insn(env
, ctx
, ASE_MT
);
4354 gen_op_mtc0_vpeschedule();
4358 check_insn(env
, ctx
, ASE_MT
);
4359 gen_op_mtc0_vpeschefback();
4360 rn
= "VPEScheFBack";
4363 check_insn(env
, ctx
, ASE_MT
);
4364 gen_op_mtc0_vpeopt();
4374 gen_op_mtc0_entrylo0();
4378 check_insn(env
, ctx
, ASE_MT
);
4379 gen_op_mtc0_tcstatus();
4383 check_insn(env
, ctx
, ASE_MT
);
4384 gen_op_mtc0_tcbind();
4388 check_insn(env
, ctx
, ASE_MT
);
4389 gen_op_mtc0_tcrestart();
4393 check_insn(env
, ctx
, ASE_MT
);
4394 gen_op_mtc0_tchalt();
4398 check_insn(env
, ctx
, ASE_MT
);
4399 gen_op_mtc0_tccontext();
4403 check_insn(env
, ctx
, ASE_MT
);
4404 gen_op_mtc0_tcschedule();
4408 check_insn(env
, ctx
, ASE_MT
);
4409 gen_op_mtc0_tcschefback();
4419 gen_op_mtc0_entrylo1();
4429 gen_op_mtc0_context();
4433 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
4434 rn
= "ContextConfig";
4443 gen_op_mtc0_pagemask();
4447 check_insn(env
, ctx
, ISA_MIPS32R2
);
4448 gen_op_mtc0_pagegrain();
4458 gen_op_mtc0_wired();
4462 check_insn(env
, ctx
, ISA_MIPS32R2
);
4463 gen_op_mtc0_srsconf0();
4467 check_insn(env
, ctx
, ISA_MIPS32R2
);
4468 gen_op_mtc0_srsconf1();
4472 check_insn(env
, ctx
, ISA_MIPS32R2
);
4473 gen_op_mtc0_srsconf2();
4477 check_insn(env
, ctx
, ISA_MIPS32R2
);
4478 gen_op_mtc0_srsconf3();
4482 check_insn(env
, ctx
, ISA_MIPS32R2
);
4483 gen_op_mtc0_srsconf4();
4493 check_insn(env
, ctx
, ISA_MIPS32R2
);
4494 gen_op_mtc0_hwrena();
4508 gen_op_mtc0_count();
4511 /* 6,7 are implementation dependent */
4515 /* Stop translation as we may have switched the execution mode */
4516 ctx
->bstate
= BS_STOP
;
4521 gen_op_mtc0_entryhi();
4531 gen_op_mtc0_compare();
4534 /* 6,7 are implementation dependent */
4538 /* Stop translation as we may have switched the execution mode */
4539 ctx
->bstate
= BS_STOP
;
4544 gen_op_mtc0_status();
4545 /* BS_STOP isn't good enough here, hflags may have changed. */
4546 gen_save_pc(ctx
->pc
+ 4);
4547 ctx
->bstate
= BS_EXCP
;
4551 check_insn(env
, ctx
, ISA_MIPS32R2
);
4552 gen_op_mtc0_intctl();
4553 /* Stop translation as we may have switched the execution mode */
4554 ctx
->bstate
= BS_STOP
;
4558 check_insn(env
, ctx
, ISA_MIPS32R2
);
4559 gen_op_mtc0_srsctl();
4560 /* Stop translation as we may have switched the execution mode */
4561 ctx
->bstate
= BS_STOP
;
4565 check_insn(env
, ctx
, ISA_MIPS32R2
);
4566 gen_op_mtc0_srsmap();
4567 /* Stop translation as we may have switched the execution mode */
4568 ctx
->bstate
= BS_STOP
;
4578 gen_op_mtc0_cause();
4584 /* Stop translation as we may have switched the execution mode */
4585 ctx
->bstate
= BS_STOP
;
4604 check_insn(env
, ctx
, ISA_MIPS32R2
);
4605 gen_op_mtc0_ebase();
4615 gen_op_mtc0_config0();
4617 /* Stop translation as we may have switched the execution mode */
4618 ctx
->bstate
= BS_STOP
;
4625 gen_op_mtc0_config2();
4627 /* Stop translation as we may have switched the execution mode */
4628 ctx
->bstate
= BS_STOP
;
4634 /* 6,7 are implementation dependent */
4636 rn
= "Invalid config selector";
4653 gen_op_mtc0_watchlo(sel
);
4663 gen_op_mtc0_watchhi(sel
);
4673 check_insn(env
, ctx
, ISA_MIPS3
);
4674 gen_op_mtc0_xcontext();
4682 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4685 gen_op_mtc0_framemask();
4694 rn
= "Diagnostic"; /* implementation dependent */
4699 gen_op_mtc0_debug(); /* EJTAG support */
4700 /* BS_STOP isn't good enough here, hflags may have changed. */
4701 gen_save_pc(ctx
->pc
+ 4);
4702 ctx
->bstate
= BS_EXCP
;
4706 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4707 /* Stop translation as we may have switched the execution mode */
4708 ctx
->bstate
= BS_STOP
;
4709 rn
= "TraceControl";
4712 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4713 /* Stop translation as we may have switched the execution mode */
4714 ctx
->bstate
= BS_STOP
;
4715 rn
= "TraceControl2";
4718 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4719 /* Stop translation as we may have switched the execution mode */
4720 ctx
->bstate
= BS_STOP
;
4721 rn
= "UserTraceData";
4724 // gen_op_mtc0_debug(); /* PDtrace support */
4725 /* Stop translation as we may have switched the execution mode */
4726 ctx
->bstate
= BS_STOP
;
4736 gen_op_mtc0_depc(); /* EJTAG support */
4746 gen_op_mtc0_performance0();
4747 rn
= "Performance0";
4750 // gen_op_mtc0_performance1();
4751 rn
= "Performance1";
4754 // gen_op_mtc0_performance2();
4755 rn
= "Performance2";
4758 // gen_op_mtc0_performance3();
4759 rn
= "Performance3";
4762 // gen_op_mtc0_performance4();
4763 rn
= "Performance4";
4766 // gen_op_mtc0_performance5();
4767 rn
= "Performance5";
4770 // gen_op_mtc0_performance6();
4771 rn
= "Performance6";
4774 // gen_op_mtc0_performance7();
4775 rn
= "Performance7";
4801 gen_op_mtc0_taglo();
4808 gen_op_mtc0_datalo();
4821 gen_op_mtc0_taghi();
4828 gen_op_mtc0_datahi();
4839 gen_op_mtc0_errorepc();
4849 gen_op_mtc0_desave(); /* EJTAG support */
4855 /* Stop translation as we may have switched the execution mode */
4856 ctx
->bstate
= BS_STOP
;
4861 #if defined MIPS_DEBUG_DISAS
4862 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4863 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4870 #if defined MIPS_DEBUG_DISAS
4871 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4872 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4876 generate_exception(ctx
, EXCP_RI
);
4878 #endif /* TARGET_MIPS64 */
4880 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4881 int u
, int sel
, int h
)
4883 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4885 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4886 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4887 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4888 tcg_gen_movi_tl(cpu_T
[0], -1);
4889 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4890 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4891 tcg_gen_movi_tl(cpu_T
[0], -1);
4897 gen_op_mftc0_tcstatus();
4900 gen_op_mftc0_tcbind();
4903 gen_op_mftc0_tcrestart();
4906 gen_op_mftc0_tchalt();
4909 gen_op_mftc0_tccontext();
4912 gen_op_mftc0_tcschedule();
4915 gen_op_mftc0_tcschefback();
4918 gen_mfc0(env
, ctx
, rt
, sel
);
4925 gen_op_mftc0_entryhi();
4928 gen_mfc0(env
, ctx
, rt
, sel
);
4934 gen_op_mftc0_status();
4937 gen_mfc0(env
, ctx
, rt
, sel
);
4943 gen_op_mftc0_debug();
4946 gen_mfc0(env
, ctx
, rt
, sel
);
4951 gen_mfc0(env
, ctx
, rt
, sel
);
4953 } else switch (sel
) {
4954 /* GPR registers. */
4958 /* Auxiliary CPU registers */
5004 /* Floating point (COP1). */
5006 /* XXX: For now we support only a single FPU context. */
5008 GEN_LOAD_FREG_FTN(WT0
, rt
);
5011 GEN_LOAD_FREG_FTN(WTH0
, rt
);
5016 /* XXX: For now we support only a single FPU context. */
5019 /* COP2: Not implemented. */
5026 #if defined MIPS_DEBUG_DISAS
5027 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5028 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5035 #if defined MIPS_DEBUG_DISAS
5036 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5037 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5041 generate_exception(ctx
, EXCP_RI
);
5044 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
5045 int u
, int sel
, int h
)
5047 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5049 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5050 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5051 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5053 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5054 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5061 gen_op_mttc0_tcstatus();
5064 gen_op_mttc0_tcbind();
5067 gen_op_mttc0_tcrestart();
5070 gen_op_mttc0_tchalt();
5073 gen_op_mttc0_tccontext();
5076 gen_op_mttc0_tcschedule();
5079 gen_op_mttc0_tcschefback();
5082 gen_mtc0(env
, ctx
, rd
, sel
);
5089 gen_op_mttc0_entryhi();
5092 gen_mtc0(env
, ctx
, rd
, sel
);
5098 gen_op_mttc0_status();
5101 gen_mtc0(env
, ctx
, rd
, sel
);
5107 gen_op_mttc0_debug();
5110 gen_mtc0(env
, ctx
, rd
, sel
);
5115 gen_mtc0(env
, ctx
, rd
, sel
);
5117 } else switch (sel
) {
5118 /* GPR registers. */
5122 /* Auxiliary CPU registers */
5168 /* Floating point (COP1). */
5170 /* XXX: For now we support only a single FPU context. */
5173 GEN_STORE_FTN_FREG(rd
, WT0
);
5176 GEN_STORE_FTN_FREG(rd
, WTH0
);
5180 /* XXX: For now we support only a single FPU context. */
5183 /* COP2: Not implemented. */
5190 #if defined MIPS_DEBUG_DISAS
5191 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5192 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5199 #if defined MIPS_DEBUG_DISAS
5200 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5201 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5205 generate_exception(ctx
, EXCP_RI
);
5208 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5210 const char *opn
= "ldst";
5218 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5219 gen_store_gpr(cpu_T
[0], rt
);
5223 gen_load_gpr(cpu_T
[0], rt
);
5224 save_cpu_state(ctx
, 1);
5225 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5228 #if defined(TARGET_MIPS64)
5230 check_insn(env
, ctx
, ISA_MIPS3
);
5235 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5236 gen_store_gpr(cpu_T
[0], rt
);
5240 check_insn(env
, ctx
, ISA_MIPS3
);
5241 gen_load_gpr(cpu_T
[0], rt
);
5242 save_cpu_state(ctx
, 1);
5243 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5248 check_insn(env
, ctx
, ASE_MT
);
5253 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
5254 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5255 gen_store_gpr(cpu_T
[0], rd
);
5259 check_insn(env
, ctx
, ASE_MT
);
5260 gen_load_gpr(cpu_T
[0], rt
);
5261 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
5262 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5267 if (!env
->tlb
->do_tlbwi
)
5273 if (!env
->tlb
->do_tlbwr
)
5279 if (!env
->tlb
->do_tlbp
)
5285 if (!env
->tlb
->do_tlbr
)
5291 check_insn(env
, ctx
, ISA_MIPS2
);
5292 save_cpu_state(ctx
, 1);
5294 ctx
->bstate
= BS_EXCP
;
5298 check_insn(env
, ctx
, ISA_MIPS32
);
5299 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5301 generate_exception(ctx
, EXCP_RI
);
5303 save_cpu_state(ctx
, 1);
5305 ctx
->bstate
= BS_EXCP
;
5310 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5311 /* If we get an exception, we want to restart at next instruction */
5313 save_cpu_state(ctx
, 1);
5316 ctx
->bstate
= BS_EXCP
;
5321 generate_exception(ctx
, EXCP_RI
);
5324 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5327 /* CP1 Branches (before delay slot) */
5328 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5329 int32_t cc
, int32_t offset
)
5331 target_ulong btarget
;
5332 const char *opn
= "cp1 cond branch";
5335 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5337 btarget
= ctx
->pc
+ 4 + offset
;
5356 ctx
->hflags
|= MIPS_HFLAG_BL
;
5357 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5360 gen_op_bc1any2f(cc
);
5364 gen_op_bc1any2t(cc
);
5368 gen_op_bc1any4f(cc
);
5372 gen_op_bc1any4t(cc
);
5375 ctx
->hflags
|= MIPS_HFLAG_BC
;
5376 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5380 generate_exception (ctx
, EXCP_RI
);
5383 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5384 ctx
->hflags
, btarget
);
5385 ctx
->btarget
= btarget
;
5388 /* Coprocessor 1 (FPU) */
5390 #define FOP(func, fmt) (((fmt) << 21) | (func))
5392 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5394 const char *opn
= "cp1 move";
5398 GEN_LOAD_FREG_FTN(WT0
, fs
);
5400 gen_store_gpr(cpu_T
[0], rt
);
5404 gen_load_gpr(cpu_T
[0], rt
);
5406 GEN_STORE_FTN_FREG(fs
, WT0
);
5411 gen_store_gpr(cpu_T
[0], rt
);
5415 gen_load_gpr(cpu_T
[0], rt
);
5420 GEN_LOAD_FREG_FTN(DT0
, fs
);
5422 gen_store_gpr(cpu_T
[0], rt
);
5426 gen_load_gpr(cpu_T
[0], rt
);
5428 GEN_STORE_FTN_FREG(fs
, DT0
);
5432 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5434 gen_store_gpr(cpu_T
[0], rt
);
5438 gen_load_gpr(cpu_T
[0], rt
);
5440 GEN_STORE_FTN_FREG(fs
, WTH0
);
5445 generate_exception (ctx
, EXCP_RI
);
5448 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5451 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5453 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
5454 TCGv r_tmp
= new_tmp();
5455 TCGv t0
= tcg_temp_new(TCG_TYPE_TL
);
5456 TCGv t1
= tcg_temp_new(TCG_TYPE_TL
);
5457 int l1
= gen_new_label();
5462 ccbit
= 1 << (24 + cc
);
5470 gen_load_gpr(t0
, rd
);
5471 gen_load_gpr(t1
, rs
);
5472 tcg_gen_ld_ptr(r_ptr
, cpu_env
, offsetof(CPUState
, fpu
));
5473 tcg_gen_ld_i32(r_tmp
, r_ptr
, offsetof(CPUMIPSFPUContext
, fcr31
));
5474 tcg_gen_andi_i32(r_tmp
, r_tmp
, ccbit
);
5475 tcg_gen_brcond_i32(cond
, r_tmp
, tcg_const_i32(0), l1
);
5476 tcg_gen_mov_tl(t0
, t1
);
5479 gen_store_gpr(t0
, rd
);
5482 #define GEN_MOVCF(fmt) \
5483 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
5488 ccbit = 1 << (24 + cc); \
5492 glue(gen_op_float_movf_, fmt)(ccbit); \
5494 glue(gen_op_float_movt_, fmt)(ccbit); \
5501 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5502 int ft
, int fs
, int fd
, int cc
)
5504 const char *opn
= "farith";
5505 const char *condnames
[] = {
5523 const char *condnames_abs
[] = {
5541 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5542 uint32_t func
= ctx
->opcode
& 0x3f;
5544 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5546 GEN_LOAD_FREG_FTN(WT0
, fs
);
5547 GEN_LOAD_FREG_FTN(WT1
, ft
);
5548 gen_op_float_add_s();
5549 GEN_STORE_FTN_FREG(fd
, WT2
);
5554 GEN_LOAD_FREG_FTN(WT0
, fs
);
5555 GEN_LOAD_FREG_FTN(WT1
, ft
);
5556 gen_op_float_sub_s();
5557 GEN_STORE_FTN_FREG(fd
, WT2
);
5562 GEN_LOAD_FREG_FTN(WT0
, fs
);
5563 GEN_LOAD_FREG_FTN(WT1
, ft
);
5564 gen_op_float_mul_s();
5565 GEN_STORE_FTN_FREG(fd
, WT2
);
5570 GEN_LOAD_FREG_FTN(WT0
, fs
);
5571 GEN_LOAD_FREG_FTN(WT1
, ft
);
5572 gen_op_float_div_s();
5573 GEN_STORE_FTN_FREG(fd
, WT2
);
5578 GEN_LOAD_FREG_FTN(WT0
, fs
);
5579 gen_op_float_sqrt_s();
5580 GEN_STORE_FTN_FREG(fd
, WT2
);
5584 GEN_LOAD_FREG_FTN(WT0
, fs
);
5585 gen_op_float_abs_s();
5586 GEN_STORE_FTN_FREG(fd
, WT2
);
5590 GEN_LOAD_FREG_FTN(WT0
, fs
);
5591 gen_op_float_mov_s();
5592 GEN_STORE_FTN_FREG(fd
, WT2
);
5596 GEN_LOAD_FREG_FTN(WT0
, fs
);
5597 gen_op_float_chs_s();
5598 GEN_STORE_FTN_FREG(fd
, WT2
);
5602 check_cp1_64bitmode(ctx
);
5603 GEN_LOAD_FREG_FTN(WT0
, fs
);
5604 gen_op_float_roundl_s();
5605 GEN_STORE_FTN_FREG(fd
, DT2
);
5609 check_cp1_64bitmode(ctx
);
5610 GEN_LOAD_FREG_FTN(WT0
, fs
);
5611 gen_op_float_truncl_s();
5612 GEN_STORE_FTN_FREG(fd
, DT2
);
5616 check_cp1_64bitmode(ctx
);
5617 GEN_LOAD_FREG_FTN(WT0
, fs
);
5618 gen_op_float_ceill_s();
5619 GEN_STORE_FTN_FREG(fd
, DT2
);
5623 check_cp1_64bitmode(ctx
);
5624 GEN_LOAD_FREG_FTN(WT0
, fs
);
5625 gen_op_float_floorl_s();
5626 GEN_STORE_FTN_FREG(fd
, DT2
);
5630 GEN_LOAD_FREG_FTN(WT0
, fs
);
5631 gen_op_float_roundw_s();
5632 GEN_STORE_FTN_FREG(fd
, WT2
);
5636 GEN_LOAD_FREG_FTN(WT0
, fs
);
5637 gen_op_float_truncw_s();
5638 GEN_STORE_FTN_FREG(fd
, WT2
);
5642 GEN_LOAD_FREG_FTN(WT0
, fs
);
5643 gen_op_float_ceilw_s();
5644 GEN_STORE_FTN_FREG(fd
, WT2
);
5648 GEN_LOAD_FREG_FTN(WT0
, fs
);
5649 gen_op_float_floorw_s();
5650 GEN_STORE_FTN_FREG(fd
, WT2
);
5654 gen_load_gpr(cpu_T
[0], ft
);
5655 GEN_LOAD_FREG_FTN(WT0
, fs
);
5656 GEN_LOAD_FREG_FTN(WT2
, fd
);
5657 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5658 GEN_STORE_FTN_FREG(fd
, WT2
);
5662 gen_load_gpr(cpu_T
[0], ft
);
5663 GEN_LOAD_FREG_FTN(WT0
, fs
);
5664 GEN_LOAD_FREG_FTN(WT2
, fd
);
5665 gen_op_float_movz_s();
5666 GEN_STORE_FTN_FREG(fd
, WT2
);
5670 gen_load_gpr(cpu_T
[0], ft
);
5671 GEN_LOAD_FREG_FTN(WT0
, fs
);
5672 GEN_LOAD_FREG_FTN(WT2
, fd
);
5673 gen_op_float_movn_s();
5674 GEN_STORE_FTN_FREG(fd
, WT2
);
5679 GEN_LOAD_FREG_FTN(WT0
, fs
);
5680 gen_op_float_recip_s();
5681 GEN_STORE_FTN_FREG(fd
, WT2
);
5686 GEN_LOAD_FREG_FTN(WT0
, fs
);
5687 gen_op_float_rsqrt_s();
5688 GEN_STORE_FTN_FREG(fd
, WT2
);
5692 check_cp1_64bitmode(ctx
);
5693 GEN_LOAD_FREG_FTN(WT0
, fs
);
5694 GEN_LOAD_FREG_FTN(WT2
, fd
);
5695 gen_op_float_recip2_s();
5696 GEN_STORE_FTN_FREG(fd
, WT2
);
5700 check_cp1_64bitmode(ctx
);
5701 GEN_LOAD_FREG_FTN(WT0
, fs
);
5702 gen_op_float_recip1_s();
5703 GEN_STORE_FTN_FREG(fd
, WT2
);
5707 check_cp1_64bitmode(ctx
);
5708 GEN_LOAD_FREG_FTN(WT0
, fs
);
5709 gen_op_float_rsqrt1_s();
5710 GEN_STORE_FTN_FREG(fd
, WT2
);
5714 check_cp1_64bitmode(ctx
);
5715 GEN_LOAD_FREG_FTN(WT0
, fs
);
5716 GEN_LOAD_FREG_FTN(WT2
, ft
);
5717 gen_op_float_rsqrt2_s();
5718 GEN_STORE_FTN_FREG(fd
, WT2
);
5722 check_cp1_registers(ctx
, fd
);
5723 GEN_LOAD_FREG_FTN(WT0
, fs
);
5724 gen_op_float_cvtd_s();
5725 GEN_STORE_FTN_FREG(fd
, DT2
);
5729 GEN_LOAD_FREG_FTN(WT0
, fs
);
5730 gen_op_float_cvtw_s();
5731 GEN_STORE_FTN_FREG(fd
, WT2
);
5735 check_cp1_64bitmode(ctx
);
5736 GEN_LOAD_FREG_FTN(WT0
, fs
);
5737 gen_op_float_cvtl_s();
5738 GEN_STORE_FTN_FREG(fd
, DT2
);
5742 check_cp1_64bitmode(ctx
);
5743 GEN_LOAD_FREG_FTN(WT1
, fs
);
5744 GEN_LOAD_FREG_FTN(WT0
, ft
);
5745 gen_op_float_cvtps_s();
5746 GEN_STORE_FTN_FREG(fd
, DT2
);
5765 GEN_LOAD_FREG_FTN(WT0
, fs
);
5766 GEN_LOAD_FREG_FTN(WT1
, ft
);
5767 if (ctx
->opcode
& (1 << 6)) {
5769 gen_cmpabs_s(func
-48, cc
);
5770 opn
= condnames_abs
[func
-48];
5772 gen_cmp_s(func
-48, cc
);
5773 opn
= condnames
[func
-48];
5777 check_cp1_registers(ctx
, fs
| ft
| fd
);
5778 GEN_LOAD_FREG_FTN(DT0
, fs
);
5779 GEN_LOAD_FREG_FTN(DT1
, ft
);
5780 gen_op_float_add_d();
5781 GEN_STORE_FTN_FREG(fd
, DT2
);
5786 check_cp1_registers(ctx
, fs
| ft
| fd
);
5787 GEN_LOAD_FREG_FTN(DT0
, fs
);
5788 GEN_LOAD_FREG_FTN(DT1
, ft
);
5789 gen_op_float_sub_d();
5790 GEN_STORE_FTN_FREG(fd
, DT2
);
5795 check_cp1_registers(ctx
, fs
| ft
| fd
);
5796 GEN_LOAD_FREG_FTN(DT0
, fs
);
5797 GEN_LOAD_FREG_FTN(DT1
, ft
);
5798 gen_op_float_mul_d();
5799 GEN_STORE_FTN_FREG(fd
, DT2
);
5804 check_cp1_registers(ctx
, fs
| ft
| fd
);
5805 GEN_LOAD_FREG_FTN(DT0
, fs
);
5806 GEN_LOAD_FREG_FTN(DT1
, ft
);
5807 gen_op_float_div_d();
5808 GEN_STORE_FTN_FREG(fd
, DT2
);
5813 check_cp1_registers(ctx
, fs
| fd
);
5814 GEN_LOAD_FREG_FTN(DT0
, fs
);
5815 gen_op_float_sqrt_d();
5816 GEN_STORE_FTN_FREG(fd
, DT2
);
5820 check_cp1_registers(ctx
, fs
| fd
);
5821 GEN_LOAD_FREG_FTN(DT0
, fs
);
5822 gen_op_float_abs_d();
5823 GEN_STORE_FTN_FREG(fd
, DT2
);
5827 check_cp1_registers(ctx
, fs
| fd
);
5828 GEN_LOAD_FREG_FTN(DT0
, fs
);
5829 gen_op_float_mov_d();
5830 GEN_STORE_FTN_FREG(fd
, DT2
);
5834 check_cp1_registers(ctx
, fs
| fd
);
5835 GEN_LOAD_FREG_FTN(DT0
, fs
);
5836 gen_op_float_chs_d();
5837 GEN_STORE_FTN_FREG(fd
, DT2
);
5841 check_cp1_64bitmode(ctx
);
5842 GEN_LOAD_FREG_FTN(DT0
, fs
);
5843 gen_op_float_roundl_d();
5844 GEN_STORE_FTN_FREG(fd
, DT2
);
5848 check_cp1_64bitmode(ctx
);
5849 GEN_LOAD_FREG_FTN(DT0
, fs
);
5850 gen_op_float_truncl_d();
5851 GEN_STORE_FTN_FREG(fd
, DT2
);
5855 check_cp1_64bitmode(ctx
);
5856 GEN_LOAD_FREG_FTN(DT0
, fs
);
5857 gen_op_float_ceill_d();
5858 GEN_STORE_FTN_FREG(fd
, DT2
);
5862 check_cp1_64bitmode(ctx
);
5863 GEN_LOAD_FREG_FTN(DT0
, fs
);
5864 gen_op_float_floorl_d();
5865 GEN_STORE_FTN_FREG(fd
, DT2
);
5869 check_cp1_registers(ctx
, fs
);
5870 GEN_LOAD_FREG_FTN(DT0
, fs
);
5871 gen_op_float_roundw_d();
5872 GEN_STORE_FTN_FREG(fd
, WT2
);
5876 check_cp1_registers(ctx
, fs
);
5877 GEN_LOAD_FREG_FTN(DT0
, fs
);
5878 gen_op_float_truncw_d();
5879 GEN_STORE_FTN_FREG(fd
, WT2
);
5883 check_cp1_registers(ctx
, fs
);
5884 GEN_LOAD_FREG_FTN(DT0
, fs
);
5885 gen_op_float_ceilw_d();
5886 GEN_STORE_FTN_FREG(fd
, WT2
);
5890 check_cp1_registers(ctx
, fs
);
5891 GEN_LOAD_FREG_FTN(DT0
, fs
);
5892 gen_op_float_floorw_d();
5893 GEN_STORE_FTN_FREG(fd
, WT2
);
5897 gen_load_gpr(cpu_T
[0], ft
);
5898 GEN_LOAD_FREG_FTN(DT0
, fs
);
5899 GEN_LOAD_FREG_FTN(DT2
, fd
);
5900 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5901 GEN_STORE_FTN_FREG(fd
, DT2
);
5905 gen_load_gpr(cpu_T
[0], ft
);
5906 GEN_LOAD_FREG_FTN(DT0
, fs
);
5907 GEN_LOAD_FREG_FTN(DT2
, fd
);
5908 gen_op_float_movz_d();
5909 GEN_STORE_FTN_FREG(fd
, DT2
);
5913 gen_load_gpr(cpu_T
[0], ft
);
5914 GEN_LOAD_FREG_FTN(DT0
, fs
);
5915 GEN_LOAD_FREG_FTN(DT2
, fd
);
5916 gen_op_float_movn_d();
5917 GEN_STORE_FTN_FREG(fd
, DT2
);
5921 check_cp1_64bitmode(ctx
);
5922 GEN_LOAD_FREG_FTN(DT0
, fs
);
5923 gen_op_float_recip_d();
5924 GEN_STORE_FTN_FREG(fd
, DT2
);
5928 check_cp1_64bitmode(ctx
);
5929 GEN_LOAD_FREG_FTN(DT0
, fs
);
5930 gen_op_float_rsqrt_d();
5931 GEN_STORE_FTN_FREG(fd
, DT2
);
5935 check_cp1_64bitmode(ctx
);
5936 GEN_LOAD_FREG_FTN(DT0
, fs
);
5937 GEN_LOAD_FREG_FTN(DT2
, ft
);
5938 gen_op_float_recip2_d();
5939 GEN_STORE_FTN_FREG(fd
, DT2
);
5943 check_cp1_64bitmode(ctx
);
5944 GEN_LOAD_FREG_FTN(DT0
, fs
);
5945 gen_op_float_recip1_d();
5946 GEN_STORE_FTN_FREG(fd
, DT2
);
5950 check_cp1_64bitmode(ctx
);
5951 GEN_LOAD_FREG_FTN(DT0
, fs
);
5952 gen_op_float_rsqrt1_d();
5953 GEN_STORE_FTN_FREG(fd
, DT2
);
5957 check_cp1_64bitmode(ctx
);
5958 GEN_LOAD_FREG_FTN(DT0
, fs
);
5959 GEN_LOAD_FREG_FTN(DT2
, ft
);
5960 gen_op_float_rsqrt2_d();
5961 GEN_STORE_FTN_FREG(fd
, DT2
);
5980 GEN_LOAD_FREG_FTN(DT0
, fs
);
5981 GEN_LOAD_FREG_FTN(DT1
, ft
);
5982 if (ctx
->opcode
& (1 << 6)) {
5984 check_cp1_registers(ctx
, fs
| ft
);
5985 gen_cmpabs_d(func
-48, cc
);
5986 opn
= condnames_abs
[func
-48];
5988 check_cp1_registers(ctx
, fs
| ft
);
5989 gen_cmp_d(func
-48, cc
);
5990 opn
= condnames
[func
-48];
5994 check_cp1_registers(ctx
, fs
);
5995 GEN_LOAD_FREG_FTN(DT0
, fs
);
5996 gen_op_float_cvts_d();
5997 GEN_STORE_FTN_FREG(fd
, WT2
);
6001 check_cp1_registers(ctx
, fs
);
6002 GEN_LOAD_FREG_FTN(DT0
, fs
);
6003 gen_op_float_cvtw_d();
6004 GEN_STORE_FTN_FREG(fd
, WT2
);
6008 check_cp1_64bitmode(ctx
);
6009 GEN_LOAD_FREG_FTN(DT0
, fs
);
6010 gen_op_float_cvtl_d();
6011 GEN_STORE_FTN_FREG(fd
, DT2
);
6015 GEN_LOAD_FREG_FTN(WT0
, fs
);
6016 gen_op_float_cvts_w();
6017 GEN_STORE_FTN_FREG(fd
, WT2
);
6021 check_cp1_registers(ctx
, fd
);
6022 GEN_LOAD_FREG_FTN(WT0
, fs
);
6023 gen_op_float_cvtd_w();
6024 GEN_STORE_FTN_FREG(fd
, DT2
);
6028 check_cp1_64bitmode(ctx
);
6029 GEN_LOAD_FREG_FTN(DT0
, fs
);
6030 gen_op_float_cvts_l();
6031 GEN_STORE_FTN_FREG(fd
, WT2
);
6035 check_cp1_64bitmode(ctx
);
6036 GEN_LOAD_FREG_FTN(DT0
, fs
);
6037 gen_op_float_cvtd_l();
6038 GEN_STORE_FTN_FREG(fd
, DT2
);
6042 check_cp1_64bitmode(ctx
);
6043 GEN_LOAD_FREG_FTN(WT0
, fs
);
6044 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6045 gen_op_float_cvtps_pw();
6046 GEN_STORE_FTN_FREG(fd
, WT2
);
6047 GEN_STORE_FTN_FREG(fd
, WTH2
);
6051 check_cp1_64bitmode(ctx
);
6052 GEN_LOAD_FREG_FTN(WT0
, fs
);
6053 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6054 GEN_LOAD_FREG_FTN(WT1
, ft
);
6055 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6056 gen_op_float_add_ps();
6057 GEN_STORE_FTN_FREG(fd
, WT2
);
6058 GEN_STORE_FTN_FREG(fd
, WTH2
);
6062 check_cp1_64bitmode(ctx
);
6063 GEN_LOAD_FREG_FTN(WT0
, fs
);
6064 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6065 GEN_LOAD_FREG_FTN(WT1
, ft
);
6066 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6067 gen_op_float_sub_ps();
6068 GEN_STORE_FTN_FREG(fd
, WT2
);
6069 GEN_STORE_FTN_FREG(fd
, WTH2
);
6073 check_cp1_64bitmode(ctx
);
6074 GEN_LOAD_FREG_FTN(WT0
, fs
);
6075 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6076 GEN_LOAD_FREG_FTN(WT1
, ft
);
6077 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6078 gen_op_float_mul_ps();
6079 GEN_STORE_FTN_FREG(fd
, WT2
);
6080 GEN_STORE_FTN_FREG(fd
, WTH2
);
6084 check_cp1_64bitmode(ctx
);
6085 GEN_LOAD_FREG_FTN(WT0
, fs
);
6086 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6087 gen_op_float_abs_ps();
6088 GEN_STORE_FTN_FREG(fd
, WT2
);
6089 GEN_STORE_FTN_FREG(fd
, WTH2
);
6093 check_cp1_64bitmode(ctx
);
6094 GEN_LOAD_FREG_FTN(WT0
, fs
);
6095 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6096 gen_op_float_mov_ps();
6097 GEN_STORE_FTN_FREG(fd
, WT2
);
6098 GEN_STORE_FTN_FREG(fd
, WTH2
);
6102 check_cp1_64bitmode(ctx
);
6103 GEN_LOAD_FREG_FTN(WT0
, fs
);
6104 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6105 gen_op_float_chs_ps();
6106 GEN_STORE_FTN_FREG(fd
, WT2
);
6107 GEN_STORE_FTN_FREG(fd
, WTH2
);
6111 check_cp1_64bitmode(ctx
);
6112 gen_load_gpr(cpu_T
[0], ft
);
6113 GEN_LOAD_FREG_FTN(WT0
, fs
);
6114 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6115 GEN_LOAD_FREG_FTN(WT2
, fd
);
6116 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6117 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
6118 GEN_STORE_FTN_FREG(fd
, WT2
);
6119 GEN_STORE_FTN_FREG(fd
, WTH2
);
6123 check_cp1_64bitmode(ctx
);
6124 gen_load_gpr(cpu_T
[0], ft
);
6125 GEN_LOAD_FREG_FTN(WT0
, fs
);
6126 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6127 GEN_LOAD_FREG_FTN(WT2
, fd
);
6128 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6129 gen_op_float_movz_ps();
6130 GEN_STORE_FTN_FREG(fd
, WT2
);
6131 GEN_STORE_FTN_FREG(fd
, WTH2
);
6135 check_cp1_64bitmode(ctx
);
6136 gen_load_gpr(cpu_T
[0], ft
);
6137 GEN_LOAD_FREG_FTN(WT0
, fs
);
6138 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6139 GEN_LOAD_FREG_FTN(WT2
, fd
);
6140 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6141 gen_op_float_movn_ps();
6142 GEN_STORE_FTN_FREG(fd
, WT2
);
6143 GEN_STORE_FTN_FREG(fd
, WTH2
);
6147 check_cp1_64bitmode(ctx
);
6148 GEN_LOAD_FREG_FTN(WT0
, ft
);
6149 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6150 GEN_LOAD_FREG_FTN(WT1
, fs
);
6151 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6152 gen_op_float_addr_ps();
6153 GEN_STORE_FTN_FREG(fd
, WT2
);
6154 GEN_STORE_FTN_FREG(fd
, WTH2
);
6158 check_cp1_64bitmode(ctx
);
6159 GEN_LOAD_FREG_FTN(WT0
, ft
);
6160 GEN_LOAD_FREG_FTN(WTH0
, ft
);
6161 GEN_LOAD_FREG_FTN(WT1
, fs
);
6162 GEN_LOAD_FREG_FTN(WTH1
, fs
);
6163 gen_op_float_mulr_ps();
6164 GEN_STORE_FTN_FREG(fd
, WT2
);
6165 GEN_STORE_FTN_FREG(fd
, WTH2
);
6169 check_cp1_64bitmode(ctx
);
6170 GEN_LOAD_FREG_FTN(WT0
, fs
);
6171 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6172 GEN_LOAD_FREG_FTN(WT2
, fd
);
6173 GEN_LOAD_FREG_FTN(WTH2
, fd
);
6174 gen_op_float_recip2_ps();
6175 GEN_STORE_FTN_FREG(fd
, WT2
);
6176 GEN_STORE_FTN_FREG(fd
, WTH2
);
6180 check_cp1_64bitmode(ctx
);
6181 GEN_LOAD_FREG_FTN(WT0
, fs
);
6182 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6183 gen_op_float_recip1_ps();
6184 GEN_STORE_FTN_FREG(fd
, WT2
);
6185 GEN_STORE_FTN_FREG(fd
, WTH2
);
6189 check_cp1_64bitmode(ctx
);
6190 GEN_LOAD_FREG_FTN(WT0
, fs
);
6191 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6192 gen_op_float_rsqrt1_ps();
6193 GEN_STORE_FTN_FREG(fd
, WT2
);
6194 GEN_STORE_FTN_FREG(fd
, WTH2
);
6198 check_cp1_64bitmode(ctx
);
6199 GEN_LOAD_FREG_FTN(WT0
, fs
);
6200 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6201 GEN_LOAD_FREG_FTN(WT2
, ft
);
6202 GEN_LOAD_FREG_FTN(WTH2
, ft
);
6203 gen_op_float_rsqrt2_ps();
6204 GEN_STORE_FTN_FREG(fd
, WT2
);
6205 GEN_STORE_FTN_FREG(fd
, WTH2
);
6209 check_cp1_64bitmode(ctx
);
6210 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6211 gen_op_float_cvts_pu();
6212 GEN_STORE_FTN_FREG(fd
, WT2
);
6216 check_cp1_64bitmode(ctx
);
6217 GEN_LOAD_FREG_FTN(WT0
, fs
);
6218 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6219 gen_op_float_cvtpw_ps();
6220 GEN_STORE_FTN_FREG(fd
, WT2
);
6221 GEN_STORE_FTN_FREG(fd
, WTH2
);
6225 check_cp1_64bitmode(ctx
);
6226 GEN_LOAD_FREG_FTN(WT0
, fs
);
6227 gen_op_float_cvts_pl();
6228 GEN_STORE_FTN_FREG(fd
, WT2
);
6232 check_cp1_64bitmode(ctx
);
6233 GEN_LOAD_FREG_FTN(WT0
, fs
);
6234 GEN_LOAD_FREG_FTN(WT1
, ft
);
6235 gen_op_float_pll_ps();
6236 GEN_STORE_FTN_FREG(fd
, DT2
);
6240 check_cp1_64bitmode(ctx
);
6241 GEN_LOAD_FREG_FTN(WT0
, fs
);
6242 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6243 gen_op_float_plu_ps();
6244 GEN_STORE_FTN_FREG(fd
, DT2
);
6248 check_cp1_64bitmode(ctx
);
6249 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6250 GEN_LOAD_FREG_FTN(WT1
, ft
);
6251 gen_op_float_pul_ps();
6252 GEN_STORE_FTN_FREG(fd
, DT2
);
6256 check_cp1_64bitmode(ctx
);
6257 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6258 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6259 gen_op_float_puu_ps();
6260 GEN_STORE_FTN_FREG(fd
, DT2
);
6279 check_cp1_64bitmode(ctx
);
6280 GEN_LOAD_FREG_FTN(WT0
, fs
);
6281 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6282 GEN_LOAD_FREG_FTN(WT1
, ft
);
6283 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6284 if (ctx
->opcode
& (1 << 6)) {
6285 gen_cmpabs_ps(func
-48, cc
);
6286 opn
= condnames_abs
[func
-48];
6288 gen_cmp_ps(func
-48, cc
);
6289 opn
= condnames
[func
-48];
6294 generate_exception (ctx
, EXCP_RI
);
6299 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
6302 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
6305 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
6310 /* Coprocessor 3 (FPU) */
6311 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
6312 int fd
, int fs
, int base
, int index
)
6314 const char *opn
= "extended float load/store";
6318 gen_load_gpr(cpu_T
[0], index
);
6319 } else if (index
== 0) {
6320 gen_load_gpr(cpu_T
[0], base
);
6322 gen_load_gpr(cpu_T
[0], base
);
6323 gen_load_gpr(cpu_T
[1], index
);
6326 /* Don't do NOP if destination is zero: we must perform the actual
6332 GEN_STORE_FTN_FREG(fd
, WT0
);
6337 check_cp1_registers(ctx
, fd
);
6339 GEN_STORE_FTN_FREG(fd
, DT0
);
6343 check_cp1_64bitmode(ctx
);
6345 GEN_STORE_FTN_FREG(fd
, DT0
);
6350 GEN_LOAD_FREG_FTN(WT0
, fs
);
6357 check_cp1_registers(ctx
, fs
);
6358 GEN_LOAD_FREG_FTN(DT0
, fs
);
6364 check_cp1_64bitmode(ctx
);
6365 GEN_LOAD_FREG_FTN(DT0
, fs
);
6372 generate_exception(ctx
, EXCP_RI
);
6375 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
6376 regnames
[index
], regnames
[base
]);
6379 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
6380 int fd
, int fr
, int fs
, int ft
)
6382 const char *opn
= "flt3_arith";
6386 check_cp1_64bitmode(ctx
);
6387 gen_load_gpr(cpu_T
[0], fr
);
6388 GEN_LOAD_FREG_FTN(DT0
, fs
);
6389 GEN_LOAD_FREG_FTN(DT1
, ft
);
6390 gen_op_float_alnv_ps();
6391 GEN_STORE_FTN_FREG(fd
, DT2
);
6396 GEN_LOAD_FREG_FTN(WT0
, fs
);
6397 GEN_LOAD_FREG_FTN(WT1
, ft
);
6398 GEN_LOAD_FREG_FTN(WT2
, fr
);
6399 gen_op_float_muladd_s();
6400 GEN_STORE_FTN_FREG(fd
, WT2
);
6405 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6406 GEN_LOAD_FREG_FTN(DT0
, fs
);
6407 GEN_LOAD_FREG_FTN(DT1
, ft
);
6408 GEN_LOAD_FREG_FTN(DT2
, fr
);
6409 gen_op_float_muladd_d();
6410 GEN_STORE_FTN_FREG(fd
, DT2
);
6414 check_cp1_64bitmode(ctx
);
6415 GEN_LOAD_FREG_FTN(WT0
, fs
);
6416 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6417 GEN_LOAD_FREG_FTN(WT1
, ft
);
6418 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6419 GEN_LOAD_FREG_FTN(WT2
, fr
);
6420 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6421 gen_op_float_muladd_ps();
6422 GEN_STORE_FTN_FREG(fd
, WT2
);
6423 GEN_STORE_FTN_FREG(fd
, WTH2
);
6428 GEN_LOAD_FREG_FTN(WT0
, fs
);
6429 GEN_LOAD_FREG_FTN(WT1
, ft
);
6430 GEN_LOAD_FREG_FTN(WT2
, fr
);
6431 gen_op_float_mulsub_s();
6432 GEN_STORE_FTN_FREG(fd
, WT2
);
6437 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6438 GEN_LOAD_FREG_FTN(DT0
, fs
);
6439 GEN_LOAD_FREG_FTN(DT1
, ft
);
6440 GEN_LOAD_FREG_FTN(DT2
, fr
);
6441 gen_op_float_mulsub_d();
6442 GEN_STORE_FTN_FREG(fd
, DT2
);
6446 check_cp1_64bitmode(ctx
);
6447 GEN_LOAD_FREG_FTN(WT0
, fs
);
6448 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6449 GEN_LOAD_FREG_FTN(WT1
, ft
);
6450 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6451 GEN_LOAD_FREG_FTN(WT2
, fr
);
6452 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6453 gen_op_float_mulsub_ps();
6454 GEN_STORE_FTN_FREG(fd
, WT2
);
6455 GEN_STORE_FTN_FREG(fd
, WTH2
);
6460 GEN_LOAD_FREG_FTN(WT0
, fs
);
6461 GEN_LOAD_FREG_FTN(WT1
, ft
);
6462 GEN_LOAD_FREG_FTN(WT2
, fr
);
6463 gen_op_float_nmuladd_s();
6464 GEN_STORE_FTN_FREG(fd
, WT2
);
6469 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6470 GEN_LOAD_FREG_FTN(DT0
, fs
);
6471 GEN_LOAD_FREG_FTN(DT1
, ft
);
6472 GEN_LOAD_FREG_FTN(DT2
, fr
);
6473 gen_op_float_nmuladd_d();
6474 GEN_STORE_FTN_FREG(fd
, DT2
);
6478 check_cp1_64bitmode(ctx
);
6479 GEN_LOAD_FREG_FTN(WT0
, fs
);
6480 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6481 GEN_LOAD_FREG_FTN(WT1
, ft
);
6482 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6483 GEN_LOAD_FREG_FTN(WT2
, fr
);
6484 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6485 gen_op_float_nmuladd_ps();
6486 GEN_STORE_FTN_FREG(fd
, WT2
);
6487 GEN_STORE_FTN_FREG(fd
, WTH2
);
6492 GEN_LOAD_FREG_FTN(WT0
, fs
);
6493 GEN_LOAD_FREG_FTN(WT1
, ft
);
6494 GEN_LOAD_FREG_FTN(WT2
, fr
);
6495 gen_op_float_nmulsub_s();
6496 GEN_STORE_FTN_FREG(fd
, WT2
);
6501 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6502 GEN_LOAD_FREG_FTN(DT0
, fs
);
6503 GEN_LOAD_FREG_FTN(DT1
, ft
);
6504 GEN_LOAD_FREG_FTN(DT2
, fr
);
6505 gen_op_float_nmulsub_d();
6506 GEN_STORE_FTN_FREG(fd
, DT2
);
6510 check_cp1_64bitmode(ctx
);
6511 GEN_LOAD_FREG_FTN(WT0
, fs
);
6512 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6513 GEN_LOAD_FREG_FTN(WT1
, ft
);
6514 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6515 GEN_LOAD_FREG_FTN(WT2
, fr
);
6516 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6517 gen_op_float_nmulsub_ps();
6518 GEN_STORE_FTN_FREG(fd
, WT2
);
6519 GEN_STORE_FTN_FREG(fd
, WTH2
);
6524 generate_exception (ctx
, EXCP_RI
);
6527 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6528 fregnames
[fs
], fregnames
[ft
]);
6531 /* ISA extensions (ASEs) */
6532 /* MIPS16 extension to MIPS32 */
6533 /* SmartMIPS extension to MIPS32 */
6535 #if defined(TARGET_MIPS64)
6537 /* MDMX extension to MIPS64 */
6541 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6545 uint32_t op
, op1
, op2
;
6548 /* make sure instructions are on a word boundary */
6549 if (ctx
->pc
& 0x3) {
6550 env
->CP0_BadVAddr
= ctx
->pc
;
6551 generate_exception(ctx
, EXCP_AdEL
);
6555 /* Handle blikely not taken case */
6556 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6557 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
6558 int l1
= gen_new_label();
6560 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6561 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
6562 tcg_gen_brcond_tl(TCG_COND_NE
, r_tmp
, tcg_const_tl(0), l1
);
6563 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6564 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6567 op
= MASK_OP_MAJOR(ctx
->opcode
);
6568 rs
= (ctx
->opcode
>> 21) & 0x1f;
6569 rt
= (ctx
->opcode
>> 16) & 0x1f;
6570 rd
= (ctx
->opcode
>> 11) & 0x1f;
6571 sa
= (ctx
->opcode
>> 6) & 0x1f;
6572 imm
= (int16_t)ctx
->opcode
;
6575 op1
= MASK_SPECIAL(ctx
->opcode
);
6577 case OPC_SLL
: /* Arithmetic with immediate */
6578 case OPC_SRL
... OPC_SRA
:
6579 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6581 case OPC_MOVZ
... OPC_MOVN
:
6582 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6583 case OPC_SLLV
: /* Arithmetic */
6584 case OPC_SRLV
... OPC_SRAV
:
6585 case OPC_ADD
... OPC_NOR
:
6586 case OPC_SLT
... OPC_SLTU
:
6587 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6589 case OPC_MULT
... OPC_DIVU
:
6591 check_insn(env
, ctx
, INSN_VR54XX
);
6592 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6593 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6595 gen_muldiv(ctx
, op1
, rs
, rt
);
6597 case OPC_JR
... OPC_JALR
:
6598 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6600 case OPC_TGE
... OPC_TEQ
: /* Traps */
6602 gen_trap(ctx
, op1
, rs
, rt
, -1);
6604 case OPC_MFHI
: /* Move from HI/LO */
6606 gen_HILO(ctx
, op1
, rd
);
6609 case OPC_MTLO
: /* Move to HI/LO */
6610 gen_HILO(ctx
, op1
, rs
);
6612 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6613 #ifdef MIPS_STRICT_STANDARD
6614 MIPS_INVAL("PMON / selsl");
6615 generate_exception(ctx
, EXCP_RI
);
6621 generate_exception(ctx
, EXCP_SYSCALL
);
6624 generate_exception(ctx
, EXCP_BREAK
);
6627 #ifdef MIPS_STRICT_STANDARD
6629 generate_exception(ctx
, EXCP_RI
);
6631 /* Implemented as RI exception for now. */
6632 MIPS_INVAL("spim (unofficial)");
6633 generate_exception(ctx
, EXCP_RI
);
6641 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6642 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6643 save_cpu_state(ctx
, 1);
6644 check_cp1_enabled(ctx
);
6645 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6646 (ctx
->opcode
>> 16) & 1);
6648 generate_exception_err(ctx
, EXCP_CpU
, 1);
6652 #if defined(TARGET_MIPS64)
6653 /* MIPS64 specific opcodes */
6655 case OPC_DSRL
... OPC_DSRA
:
6657 case OPC_DSRL32
... OPC_DSRA32
:
6658 check_insn(env
, ctx
, ISA_MIPS3
);
6660 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6663 case OPC_DSRLV
... OPC_DSRAV
:
6664 case OPC_DADD
... OPC_DSUBU
:
6665 check_insn(env
, ctx
, ISA_MIPS3
);
6667 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6669 case OPC_DMULT
... OPC_DDIVU
:
6670 check_insn(env
, ctx
, ISA_MIPS3
);
6672 gen_muldiv(ctx
, op1
, rs
, rt
);
6675 default: /* Invalid */
6676 MIPS_INVAL("special");
6677 generate_exception(ctx
, EXCP_RI
);
6682 op1
= MASK_SPECIAL2(ctx
->opcode
);
6684 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6685 case OPC_MSUB
... OPC_MSUBU
:
6686 check_insn(env
, ctx
, ISA_MIPS32
);
6687 gen_muldiv(ctx
, op1
, rs
, rt
);
6690 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6692 case OPC_CLZ
... OPC_CLO
:
6693 check_insn(env
, ctx
, ISA_MIPS32
);
6694 gen_cl(ctx
, op1
, rd
, rs
);
6697 /* XXX: not clear which exception should be raised
6698 * when in debug mode...
6700 check_insn(env
, ctx
, ISA_MIPS32
);
6701 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6702 generate_exception(ctx
, EXCP_DBp
);
6704 generate_exception(ctx
, EXCP_DBp
);
6708 #if defined(TARGET_MIPS64)
6709 case OPC_DCLZ
... OPC_DCLO
:
6710 check_insn(env
, ctx
, ISA_MIPS64
);
6712 gen_cl(ctx
, op1
, rd
, rs
);
6715 default: /* Invalid */
6716 MIPS_INVAL("special2");
6717 generate_exception(ctx
, EXCP_RI
);
6722 op1
= MASK_SPECIAL3(ctx
->opcode
);
6726 check_insn(env
, ctx
, ISA_MIPS32R2
);
6727 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6730 check_insn(env
, ctx
, ISA_MIPS32R2
);
6731 op2
= MASK_BSHFL(ctx
->opcode
);
6734 gen_load_gpr(cpu_T
[1], rt
);
6738 gen_load_gpr(cpu_T
[1], rt
);
6739 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[1]);
6742 gen_load_gpr(cpu_T
[1], rt
);
6743 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[1]);
6745 default: /* Invalid */
6746 MIPS_INVAL("bshfl");
6747 generate_exception(ctx
, EXCP_RI
);
6750 gen_store_gpr(cpu_T
[0], rd
);
6753 check_insn(env
, ctx
, ISA_MIPS32R2
);
6756 save_cpu_state(ctx
, 1);
6757 gen_op_rdhwr_cpunum();
6760 save_cpu_state(ctx
, 1);
6761 gen_op_rdhwr_synci_step();
6764 save_cpu_state(ctx
, 1);
6768 save_cpu_state(ctx
, 1);
6769 gen_op_rdhwr_ccres();
6772 #if defined (CONFIG_USER_ONLY)
6776 default: /* Invalid */
6777 MIPS_INVAL("rdhwr");
6778 generate_exception(ctx
, EXCP_RI
);
6781 gen_store_gpr(cpu_T
[0], rt
);
6784 check_insn(env
, ctx
, ASE_MT
);
6785 gen_load_gpr(cpu_T
[0], rt
);
6786 gen_load_gpr(cpu_T
[1], rs
);
6790 check_insn(env
, ctx
, ASE_MT
);
6791 gen_load_gpr(cpu_T
[0], rs
);
6793 gen_store_gpr(cpu_T
[0], rd
);
6795 #if defined(TARGET_MIPS64)
6796 case OPC_DEXTM
... OPC_DEXT
:
6797 case OPC_DINSM
... OPC_DINS
:
6798 check_insn(env
, ctx
, ISA_MIPS64R2
);
6800 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6803 check_insn(env
, ctx
, ISA_MIPS64R2
);
6805 op2
= MASK_DBSHFL(ctx
->opcode
);
6808 gen_load_gpr(cpu_T
[1], rt
);
6812 gen_load_gpr(cpu_T
[1], rt
);
6815 default: /* Invalid */
6816 MIPS_INVAL("dbshfl");
6817 generate_exception(ctx
, EXCP_RI
);
6820 gen_store_gpr(cpu_T
[0], rd
);
6823 default: /* Invalid */
6824 MIPS_INVAL("special3");
6825 generate_exception(ctx
, EXCP_RI
);
6830 op1
= MASK_REGIMM(ctx
->opcode
);
6832 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6833 case OPC_BLTZAL
... OPC_BGEZALL
:
6834 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6836 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6838 gen_trap(ctx
, op1
, rs
, -1, imm
);
6841 check_insn(env
, ctx
, ISA_MIPS32R2
);
6844 default: /* Invalid */
6845 MIPS_INVAL("regimm");
6846 generate_exception(ctx
, EXCP_RI
);
6851 check_cp0_enabled(ctx
);
6852 op1
= MASK_CP0(ctx
->opcode
);
6858 #if defined(TARGET_MIPS64)
6862 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6864 case OPC_C0_FIRST
... OPC_C0_LAST
:
6865 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6868 op2
= MASK_MFMC0(ctx
->opcode
);
6871 check_insn(env
, ctx
, ASE_MT
);
6875 check_insn(env
, ctx
, ASE_MT
);
6879 check_insn(env
, ctx
, ASE_MT
);
6883 check_insn(env
, ctx
, ASE_MT
);
6887 check_insn(env
, ctx
, ISA_MIPS32R2
);
6888 save_cpu_state(ctx
, 1);
6890 /* Stop translation as we may have switched the execution mode */
6891 ctx
->bstate
= BS_STOP
;
6894 check_insn(env
, ctx
, ISA_MIPS32R2
);
6895 save_cpu_state(ctx
, 1);
6897 /* Stop translation as we may have switched the execution mode */
6898 ctx
->bstate
= BS_STOP
;
6900 default: /* Invalid */
6901 MIPS_INVAL("mfmc0");
6902 generate_exception(ctx
, EXCP_RI
);
6905 gen_store_gpr(cpu_T
[0], rt
);
6908 check_insn(env
, ctx
, ISA_MIPS32R2
);
6909 gen_load_srsgpr(cpu_T
[0], rt
);
6910 gen_store_gpr(cpu_T
[0], rd
);
6913 check_insn(env
, ctx
, ISA_MIPS32R2
);
6914 gen_load_gpr(cpu_T
[0], rt
);
6915 gen_store_srsgpr(cpu_T
[0], rd
);
6919 generate_exception(ctx
, EXCP_RI
);
6923 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6924 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6926 case OPC_J
... OPC_JAL
: /* Jump */
6927 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6928 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6930 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6931 case OPC_BEQL
... OPC_BGTZL
:
6932 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6934 case OPC_LB
... OPC_LWR
: /* Load and stores */
6935 case OPC_SB
... OPC_SW
:
6939 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6942 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6946 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6950 /* Floating point (COP1). */
6955 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6956 save_cpu_state(ctx
, 1);
6957 check_cp1_enabled(ctx
);
6958 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6960 generate_exception_err(ctx
, EXCP_CpU
, 1);
6965 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6966 save_cpu_state(ctx
, 1);
6967 check_cp1_enabled(ctx
);
6968 op1
= MASK_CP1(ctx
->opcode
);
6972 check_insn(env
, ctx
, ISA_MIPS32R2
);
6977 gen_cp1(ctx
, op1
, rt
, rd
);
6979 #if defined(TARGET_MIPS64)
6982 check_insn(env
, ctx
, ISA_MIPS3
);
6983 gen_cp1(ctx
, op1
, rt
, rd
);
6989 check_insn(env
, ctx
, ASE_MIPS3D
);
6992 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6993 (rt
>> 2) & 0x7, imm
<< 2);
7000 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
7005 generate_exception (ctx
, EXCP_RI
);
7009 generate_exception_err(ctx
, EXCP_CpU
, 1);
7019 /* COP2: Not implemented. */
7020 generate_exception_err(ctx
, EXCP_CpU
, 2);
7024 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7025 save_cpu_state(ctx
, 1);
7026 check_cp1_enabled(ctx
);
7027 op1
= MASK_CP3(ctx
->opcode
);
7035 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
7053 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
7057 generate_exception (ctx
, EXCP_RI
);
7061 generate_exception_err(ctx
, EXCP_CpU
, 1);
7065 #if defined(TARGET_MIPS64)
7066 /* MIPS64 opcodes */
7068 case OPC_LDL
... OPC_LDR
:
7069 case OPC_SDL
... OPC_SDR
:
7074 check_insn(env
, ctx
, ISA_MIPS3
);
7076 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7078 case OPC_DADDI
... OPC_DADDIU
:
7079 check_insn(env
, ctx
, ISA_MIPS3
);
7081 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7085 check_insn(env
, ctx
, ASE_MIPS16
);
7086 /* MIPS16: Not implemented. */
7088 check_insn(env
, ctx
, ASE_MDMX
);
7089 /* MDMX: Not implemented. */
7090 default: /* Invalid */
7091 MIPS_INVAL("major opcode");
7092 generate_exception(ctx
, EXCP_RI
);
7095 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7096 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7097 /* Branches completion */
7098 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7099 ctx
->bstate
= BS_BRANCH
;
7100 save_cpu_state(ctx
, 0);
7103 /* unconditional branch */
7104 MIPS_DEBUG("unconditional branch");
7105 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7108 /* blikely taken case */
7109 MIPS_DEBUG("blikely branch taken");
7110 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7113 /* Conditional branch */
7114 MIPS_DEBUG("conditional branch");
7116 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
7117 int l1
= gen_new_label();
7119 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7120 tcg_gen_brcond_tl(TCG_COND_NE
, r_tmp
, tcg_const_tl(0), l1
);
7121 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7123 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7127 /* unconditional branch to register */
7128 MIPS_DEBUG("branch to register");
7133 MIPS_DEBUG("unknown branch");
7139 static always_inline
int
7140 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
7144 target_ulong pc_start
;
7145 uint16_t *gen_opc_end
;
7148 if (search_pc
&& loglevel
)
7149 fprintf (logfile
, "search pc %d\n", search_pc
);
7152 memset(temps
, 0, sizeof(temps
));
7155 memset(temps
, 0, sizeof(temps
));
7158 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7162 ctx
.bstate
= BS_NONE
;
7163 /* Restore delay slot state from the tb context. */
7164 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
7165 restore_cpu_state(env
, &ctx
);
7166 #if defined(CONFIG_USER_ONLY)
7167 ctx
.mem_idx
= MIPS_HFLAG_UM
;
7169 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
7172 if (loglevel
& CPU_LOG_TB_CPU
) {
7173 fprintf(logfile
, "------------------------------------------------\n");
7174 /* FIXME: This may print out stale hflags from env... */
7175 cpu_dump_state(env
, logfile
, fprintf
, 0);
7178 #ifdef MIPS_DEBUG_DISAS
7179 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7180 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
7181 tb
, ctx
.mem_idx
, ctx
.hflags
);
7183 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7184 if (env
->nb_breakpoints
> 0) {
7185 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
7186 if (env
->breakpoints
[j
] == ctx
.pc
) {
7187 save_cpu_state(&ctx
, 1);
7188 ctx
.bstate
= BS_BRANCH
;
7190 /* Include the breakpoint location or the tb won't
7191 * be flushed when it must be. */
7193 goto done_generating
;
7199 j
= gen_opc_ptr
- gen_opc_buf
;
7203 gen_opc_instr_start
[lj
++] = 0;
7205 gen_opc_pc
[lj
] = ctx
.pc
;
7206 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
7207 gen_opc_instr_start
[lj
] = 1;
7209 ctx
.opcode
= ldl_code(ctx
.pc
);
7210 decode_opc(env
, &ctx
);
7213 "Internal resource leak before " TARGET_FMT_lx
"\n",
7219 if (env
->singlestep_enabled
)
7222 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
7225 #if defined (MIPS_SINGLE_STEP)
7229 if (env
->singlestep_enabled
) {
7230 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
7233 switch (ctx
.bstate
) {
7235 tcg_gen_helper_0_0(do_interrupt_restart
);
7236 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7239 save_cpu_state(&ctx
, 0);
7240 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7243 tcg_gen_helper_0_0(do_interrupt_restart
);
7252 *gen_opc_ptr
= INDEX_op_end
;
7254 j
= gen_opc_ptr
- gen_opc_buf
;
7257 gen_opc_instr_start
[lj
++] = 0;
7259 tb
->size
= ctx
.pc
- pc_start
;
7262 #if defined MIPS_DEBUG_DISAS
7263 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7264 fprintf(logfile
, "\n");
7266 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7267 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7268 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
7269 fprintf(logfile
, "\n");
7271 if (loglevel
& CPU_LOG_TB_CPU
) {
7272 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
7279 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7281 return gen_intermediate_code_internal(env
, tb
, 0);
7284 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7286 return gen_intermediate_code_internal(env
, tb
, 1);
7289 void fpu_dump_state(CPUState
*env
, FILE *f
,
7290 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7294 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
7296 #define printfpr(fp) \
7299 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7300 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7301 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7304 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7305 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7306 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7307 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7308 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7313 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7314 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
7315 get_float_exception_flags(&env
->fpu
->fp_status
));
7316 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
7317 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
7318 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
7319 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
7320 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
7321 printfpr(&env
->fpu
->fpr
[i
]);
7327 void dump_fpu (CPUState
*env
)
7331 "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
7332 " LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
7334 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0],
7335 env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
,
7337 fpu_dump_state(env
, logfile
, fprintf
, 0);
7341 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7342 /* Debug help: The architecture requires 32bit code to maintain proper
7343 sign-extened values on 64bit machines. */
7345 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7347 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
7348 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7353 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
7354 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
7355 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
7356 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
7357 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
7358 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
7359 if (!SIGN_EXT_P(env
->btarget
))
7360 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
7362 for (i
= 0; i
< 32; i
++) {
7363 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
7364 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7367 if (!SIGN_EXT_P(env
->CP0_EPC
))
7368 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
7369 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
7370 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
7374 void cpu_dump_state (CPUState
*env
, FILE *f
,
7375 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7380 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",
7381 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
7382 for (i
= 0; i
< 32; i
++) {
7384 cpu_fprintf(f
, "GPR%02d:", i
);
7385 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7387 cpu_fprintf(f
, "\n");
7390 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
7391 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
7392 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
7393 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
7394 if (env
->hflags
& MIPS_HFLAG_FPU
)
7395 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
7396 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7397 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
7401 static void mips_tcg_init(void)
7405 /* Initialize various static tables. */
7409 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
7410 current_tc_gprs
= tcg_global_mem_new(TCG_TYPE_PTR
,
7412 offsetof(CPUState
, current_tc_gprs
),
7414 #if TARGET_LONG_BITS > HOST_LONG_BITS
7415 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
7416 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
7417 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
7418 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
7420 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
7421 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
7427 #include "translate_init.c"
7429 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
7432 const mips_def_t
*def
;
7434 def
= cpu_mips_find_by_name(cpu_model
);
7437 env
= qemu_mallocz(sizeof(CPUMIPSState
));
7440 env
->cpu_model
= def
;
7443 env
->cpu_model_str
= cpu_model
;
7449 void cpu_reset (CPUMIPSState
*env
)
7451 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
7456 #if !defined(CONFIG_USER_ONLY)
7457 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
7458 /* If the exception was raised from a delay slot,
7459 * come back to the jump. */
7460 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
7462 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
7464 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
7466 /* SMP not implemented */
7467 env
->CP0_EBase
= 0x80000000;
7468 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
7469 /* vectored interrupts not implemented, timer on int 7,
7470 no performance counters. */
7471 env
->CP0_IntCtl
= 0xe0000000;
7475 for (i
= 0; i
< 7; i
++) {
7476 env
->CP0_WatchLo
[i
] = 0;
7477 env
->CP0_WatchHi
[i
] = 0x80000000;
7479 env
->CP0_WatchLo
[7] = 0;
7480 env
->CP0_WatchHi
[7] = 0;
7482 /* Count register increments in debug mode, EJTAG version 1 */
7483 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
7485 env
->exception_index
= EXCP_NONE
;
7486 #if defined(CONFIG_USER_ONLY)
7487 env
->hflags
= MIPS_HFLAG_UM
;
7488 env
->user_mode_only
= 1;
7490 env
->hflags
= MIPS_HFLAG_CP0
;
7492 cpu_mips_register(env
, env
->cpu_model
);
7495 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7496 unsigned long searched_pc
, int pc_pos
, void *puc
)
7498 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
7499 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
7500 env
->hflags
|= gen_opc_hflags
[pc_pos
];