2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "qemu-common.h"
35 //#define MIPS_DEBUG_DISAS
36 //#define MIPS_DEBUG_SIGN_EXTENSIONS
37 //#define MIPS_SINGLE_STEP
39 /* MIPS major opcodes */
40 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
43 /* indirect opcode tables */
44 OPC_SPECIAL
= (0x00 << 26),
45 OPC_REGIMM
= (0x01 << 26),
46 OPC_CP0
= (0x10 << 26),
47 OPC_CP1
= (0x11 << 26),
48 OPC_CP2
= (0x12 << 26),
49 OPC_CP3
= (0x13 << 26),
50 OPC_SPECIAL2
= (0x1C << 26),
51 OPC_SPECIAL3
= (0x1F << 26),
52 /* arithmetic with immediate */
53 OPC_ADDI
= (0x08 << 26),
54 OPC_ADDIU
= (0x09 << 26),
55 OPC_SLTI
= (0x0A << 26),
56 OPC_SLTIU
= (0x0B << 26),
57 OPC_ANDI
= (0x0C << 26),
58 OPC_ORI
= (0x0D << 26),
59 OPC_XORI
= (0x0E << 26),
60 OPC_LUI
= (0x0F << 26),
61 OPC_DADDI
= (0x18 << 26),
62 OPC_DADDIU
= (0x19 << 26),
63 /* Jump and branches */
65 OPC_JAL
= (0x03 << 26),
66 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
67 OPC_BEQL
= (0x14 << 26),
68 OPC_BNE
= (0x05 << 26),
69 OPC_BNEL
= (0x15 << 26),
70 OPC_BLEZ
= (0x06 << 26),
71 OPC_BLEZL
= (0x16 << 26),
72 OPC_BGTZ
= (0x07 << 26),
73 OPC_BGTZL
= (0x17 << 26),
74 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
76 OPC_LDL
= (0x1A << 26),
77 OPC_LDR
= (0x1B << 26),
78 OPC_LB
= (0x20 << 26),
79 OPC_LH
= (0x21 << 26),
80 OPC_LWL
= (0x22 << 26),
81 OPC_LW
= (0x23 << 26),
82 OPC_LBU
= (0x24 << 26),
83 OPC_LHU
= (0x25 << 26),
84 OPC_LWR
= (0x26 << 26),
85 OPC_LWU
= (0x27 << 26),
86 OPC_SB
= (0x28 << 26),
87 OPC_SH
= (0x29 << 26),
88 OPC_SWL
= (0x2A << 26),
89 OPC_SW
= (0x2B << 26),
90 OPC_SDL
= (0x2C << 26),
91 OPC_SDR
= (0x2D << 26),
92 OPC_SWR
= (0x2E << 26),
93 OPC_LL
= (0x30 << 26),
94 OPC_LLD
= (0x34 << 26),
95 OPC_LD
= (0x37 << 26),
96 OPC_SC
= (0x38 << 26),
97 OPC_SCD
= (0x3C << 26),
98 OPC_SD
= (0x3F << 26),
99 /* Floating point load/store */
100 OPC_LWC1
= (0x31 << 26),
101 OPC_LWC2
= (0x32 << 26),
102 OPC_LDC1
= (0x35 << 26),
103 OPC_LDC2
= (0x36 << 26),
104 OPC_SWC1
= (0x39 << 26),
105 OPC_SWC2
= (0x3A << 26),
106 OPC_SDC1
= (0x3D << 26),
107 OPC_SDC2
= (0x3E << 26),
108 /* MDMX ASE specific */
109 OPC_MDMX
= (0x1E << 26),
110 /* Cache and prefetch */
111 OPC_CACHE
= (0x2F << 26),
112 OPC_PREF
= (0x33 << 26),
113 /* Reserved major opcode */
114 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
117 /* MIPS special opcodes */
118 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
122 OPC_SLL
= 0x00 | OPC_SPECIAL
,
123 /* NOP is SLL r0, r0, 0 */
124 /* SSNOP is SLL r0, r0, 1 */
125 /* EHB is SLL r0, r0, 3 */
126 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
127 OPC_SRA
= 0x03 | OPC_SPECIAL
,
128 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
129 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
130 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
131 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
132 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
133 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
134 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
135 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
136 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
137 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
138 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
139 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
140 /* Multiplication / division */
141 OPC_MULT
= 0x18 | OPC_SPECIAL
,
142 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
143 OPC_DIV
= 0x1A | OPC_SPECIAL
,
144 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
145 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
146 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
147 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
148 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
149 /* 2 registers arithmetic / logic */
150 OPC_ADD
= 0x20 | OPC_SPECIAL
,
151 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
152 OPC_SUB
= 0x22 | OPC_SPECIAL
,
153 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
154 OPC_AND
= 0x24 | OPC_SPECIAL
,
155 OPC_OR
= 0x25 | OPC_SPECIAL
,
156 OPC_XOR
= 0x26 | OPC_SPECIAL
,
157 OPC_NOR
= 0x27 | OPC_SPECIAL
,
158 OPC_SLT
= 0x2A | OPC_SPECIAL
,
159 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
160 OPC_DADD
= 0x2C | OPC_SPECIAL
,
161 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
162 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
163 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
165 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
166 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
168 OPC_TGE
= 0x30 | OPC_SPECIAL
,
169 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
170 OPC_TLT
= 0x32 | OPC_SPECIAL
,
171 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
172 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
173 OPC_TNE
= 0x36 | OPC_SPECIAL
,
174 /* HI / LO registers load & stores */
175 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
176 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
177 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
178 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
179 /* Conditional moves */
180 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
181 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
183 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
186 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
187 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
188 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
189 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
190 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
192 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
193 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
194 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
195 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
196 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
197 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
198 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
201 /* Multiplication variants of the vr54xx. */
202 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
205 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
206 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
207 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
208 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
209 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
210 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
211 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
212 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
213 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
214 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
215 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
216 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
217 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
218 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
221 /* REGIMM (rt field) opcodes */
222 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
225 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
226 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
227 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
228 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
229 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
230 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
231 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
232 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
233 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
234 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
235 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
236 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
237 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
238 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
239 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
242 /* Special2 opcodes */
243 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
246 /* Multiply & xxx operations */
247 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
248 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
249 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
250 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
251 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
253 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
254 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
255 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
256 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
258 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
261 /* Special3 opcodes */
262 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
265 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
266 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
267 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
268 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
269 OPC_INS
= 0x04 | OPC_SPECIAL3
,
270 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
271 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
272 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
273 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
274 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
275 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
276 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
277 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
281 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
284 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
285 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
286 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
290 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
293 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
294 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
297 /* Coprocessor 0 (rs field) */
298 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
301 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
302 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
303 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
304 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
305 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
306 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
307 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
308 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
309 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
310 OPC_C0
= (0x10 << 21) | OPC_CP0
,
311 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
312 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
316 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
319 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
320 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
321 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
322 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
323 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
324 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
327 /* Coprocessor 0 (with rs == C0) */
328 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
331 OPC_TLBR
= 0x01 | OPC_C0
,
332 OPC_TLBWI
= 0x02 | OPC_C0
,
333 OPC_TLBWR
= 0x06 | OPC_C0
,
334 OPC_TLBP
= 0x08 | OPC_C0
,
335 OPC_RFE
= 0x10 | OPC_C0
,
336 OPC_ERET
= 0x18 | OPC_C0
,
337 OPC_DERET
= 0x1F | OPC_C0
,
338 OPC_WAIT
= 0x20 | OPC_C0
,
341 /* Coprocessor 1 (rs field) */
342 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
345 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
346 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
347 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
348 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
349 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
350 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
351 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
352 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
353 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
354 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
355 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
356 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
357 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
358 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
359 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
360 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
361 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
362 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
365 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
366 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
369 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
370 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
371 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
372 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
376 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
377 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
381 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
382 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
385 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
388 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
389 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
390 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
391 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
392 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
393 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
394 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
395 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
396 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
399 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
402 OPC_LWXC1
= 0x00 | OPC_CP3
,
403 OPC_LDXC1
= 0x01 | OPC_CP3
,
404 OPC_LUXC1
= 0x05 | OPC_CP3
,
405 OPC_SWXC1
= 0x08 | OPC_CP3
,
406 OPC_SDXC1
= 0x09 | OPC_CP3
,
407 OPC_SUXC1
= 0x0D | OPC_CP3
,
408 OPC_PREFX
= 0x0F | OPC_CP3
,
409 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
410 OPC_MADD_S
= 0x20 | OPC_CP3
,
411 OPC_MADD_D
= 0x21 | OPC_CP3
,
412 OPC_MADD_PS
= 0x26 | OPC_CP3
,
413 OPC_MSUB_S
= 0x28 | OPC_CP3
,
414 OPC_MSUB_D
= 0x29 | OPC_CP3
,
415 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
416 OPC_NMADD_S
= 0x30 | OPC_CP3
,
417 OPC_NMADD_D
= 0x31 | OPC_CP3
,
418 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
419 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
420 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
421 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
425 const unsigned char *regnames
[] =
426 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
427 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
428 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
429 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
431 /* Warning: no function for r0 register (hard wired to zero) */
432 #define GEN32(func, NAME) \
433 static GenOpFunc *NAME ## _table [32] = { \
434 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
435 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
436 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
437 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
438 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
439 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
440 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
441 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
443 static always_inline void func(int n) \
445 NAME ## _table[n](); \
448 /* General purpose registers moves */
449 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
450 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
451 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
453 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
454 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
456 /* Moves to/from shadow registers */
457 GEN32(gen_op_load_srsgpr_T0
, gen_op_load_srsgpr_T0_gpr
);
458 GEN32(gen_op_store_T0_srsgpr
, gen_op_store_T0_srsgpr_gpr
);
460 static const char *fregnames
[] =
461 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
462 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
463 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
464 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
466 #define FGEN32(func, NAME) \
467 static GenOpFunc *NAME ## _table [32] = { \
468 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
469 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
470 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
471 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
472 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
473 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
474 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
475 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
477 static always_inline void func(int n) \
479 NAME ## _table[n](); \
482 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
483 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
485 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
486 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
488 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
489 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
491 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
492 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
494 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
495 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
497 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
498 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
500 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
501 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
503 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
504 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
506 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
507 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
509 #define FOP_CONDS(type, fmt) \
510 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
511 gen_op_cmp ## type ## _ ## fmt ## _f, \
512 gen_op_cmp ## type ## _ ## fmt ## _un, \
513 gen_op_cmp ## type ## _ ## fmt ## _eq, \
514 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
515 gen_op_cmp ## type ## _ ## fmt ## _olt, \
516 gen_op_cmp ## type ## _ ## fmt ## _ult, \
517 gen_op_cmp ## type ## _ ## fmt ## _ole, \
518 gen_op_cmp ## type ## _ ## fmt ## _ule, \
519 gen_op_cmp ## type ## _ ## fmt ## _sf, \
520 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
521 gen_op_cmp ## type ## _ ## fmt ## _seq, \
522 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
523 gen_op_cmp ## type ## _ ## fmt ## _lt, \
524 gen_op_cmp ## type ## _ ## fmt ## _nge, \
525 gen_op_cmp ## type ## _ ## fmt ## _le, \
526 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
528 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
530 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
540 typedef struct DisasContext
{
541 struct TranslationBlock
*tb
;
542 target_ulong pc
, saved_pc
;
545 /* Routine used to access memory */
547 uint32_t hflags
, saved_hflags
;
549 target_ulong btarget
;
555 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
556 * exception condition
558 BS_STOP
= 1, /* We want to stop translation for any reason */
559 BS_BRANCH
= 2, /* We reached a branch condition */
560 BS_EXCP
= 3, /* We reached an exception condition */
563 #ifdef MIPS_DEBUG_DISAS
564 #define MIPS_DEBUG(fmt, args...) \
566 if (loglevel & CPU_LOG_TB_IN_ASM) { \
567 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
568 ctx->pc, ctx->opcode , ##args); \
572 #define MIPS_DEBUG(fmt, args...) do { } while(0)
575 #define MIPS_INVAL(op) \
577 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
578 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
581 #define GEN_LOAD_REG_T0(Rn) \
586 if (ctx->glue(last_T0, _store) != gen_opc_ptr \
587 || ctx->glue(last_T0, _gpr) != Rn) { \
588 gen_op_load_gpr_T0(Rn); \
593 #define GEN_LOAD_REG_T1(Rn) \
598 gen_op_load_gpr_T1(Rn); \
602 #define GEN_LOAD_REG_T2(Rn) \
607 gen_op_load_gpr_T2(Rn); \
611 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
614 glue(gen_op_reset_, Tn)(); \
616 glue(gen_op_load_srsgpr_, Tn)(Rn); \
620 #if defined(TARGET_MIPS64)
621 #define GEN_LOAD_IMM_TN(Tn, Imm) \
624 glue(gen_op_reset_, Tn)(); \
625 } else if ((int32_t)Imm == Imm) { \
626 glue(gen_op_set_, Tn)(Imm); \
628 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
632 #define GEN_LOAD_IMM_TN(Tn, Imm) \
635 glue(gen_op_reset_, Tn)(); \
637 glue(gen_op_set_, Tn)(Imm); \
642 #define GEN_STORE_T0_REG(Rn) \
645 glue(gen_op_store_T0,_gpr)(Rn); \
646 ctx->glue(last_T0,_store) = gen_opc_ptr; \
647 ctx->glue(last_T0,_gpr) = Rn; \
651 #define GEN_STORE_T1_REG(Rn) \
654 glue(gen_op_store_T1,_gpr)(Rn); \
657 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
660 glue(glue(gen_op_store_, Tn),_srsgpr)(Rn); \
664 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
666 glue(gen_op_load_fpr_, FTn)(Fn); \
669 #define GEN_STORE_FTN_FREG(Fn, FTn) \
671 glue(gen_op_store_fpr_, FTn)(Fn); \
674 static always_inline
void gen_save_pc(target_ulong pc
)
676 #if defined(TARGET_MIPS64)
677 if (pc
== (int32_t)pc
) {
680 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
687 static always_inline
void gen_save_btarget(target_ulong btarget
)
689 #if defined(TARGET_MIPS64)
690 if (btarget
== (int32_t)btarget
) {
691 gen_op_save_btarget(btarget
);
693 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
696 gen_op_save_btarget(btarget
);
700 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
702 #if defined MIPS_DEBUG_DISAS
703 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
704 fprintf(logfile
, "hflags %08x saved %08x\n",
705 ctx
->hflags
, ctx
->saved_hflags
);
708 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
709 gen_save_pc(ctx
->pc
);
710 ctx
->saved_pc
= ctx
->pc
;
712 if (ctx
->hflags
!= ctx
->saved_hflags
) {
713 gen_op_save_state(ctx
->hflags
);
714 ctx
->saved_hflags
= ctx
->hflags
;
715 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
717 gen_op_save_breg_target();
723 /* bcond was already saved by the BL insn */
726 gen_save_btarget(ctx
->btarget
);
732 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
734 ctx
->saved_hflags
= ctx
->hflags
;
735 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
737 gen_op_restore_breg_target();
740 ctx
->btarget
= env
->btarget
;
744 ctx
->btarget
= env
->btarget
;
745 gen_op_restore_bcond();
750 static always_inline
void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
752 #if defined MIPS_DEBUG_DISAS
753 if (loglevel
& CPU_LOG_TB_IN_ASM
)
754 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
756 save_cpu_state(ctx
, 1);
758 gen_op_raise_exception(excp
);
760 gen_op_raise_exception_err(excp
, err
);
761 ctx
->bstate
= BS_EXCP
;
764 static always_inline
void generate_exception (DisasContext
*ctx
, int excp
)
766 generate_exception_err (ctx
, excp
, 0);
769 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
771 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
772 generate_exception_err(ctx
, EXCP_CpU
, 1);
775 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
777 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
778 generate_exception_err(ctx
, EXCP_CpU
, 1);
781 /* Verify that the processor is running with COP1X instructions enabled.
782 This is associated with the nabla symbol in the MIPS32 and MIPS64
785 static always_inline
void check_cop1x(DisasContext
*ctx
)
787 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
788 generate_exception(ctx
, EXCP_RI
);
791 /* Verify that the processor is running with 64-bit floating-point
792 operations enabled. */
794 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
796 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
797 generate_exception(ctx
, EXCP_RI
);
801 * Verify if floating point register is valid; an operation is not defined
802 * if bit 0 of any register specification is set and the FR bit in the
803 * Status register equals zero, since the register numbers specify an
804 * even-odd pair of adjacent coprocessor general registers. When the FR bit
805 * in the Status register equals one, both even and odd register numbers
806 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
808 * Multiple 64 bit wide registers can be checked by calling
809 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
811 void check_cp1_registers(DisasContext
*ctx
, int regs
)
813 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
814 generate_exception(ctx
, EXCP_RI
);
817 /* This code generates a "reserved instruction" exception if the
818 CPU does not support the instruction set corresponding to flags. */
819 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
821 if (unlikely(!(env
->insn_flags
& flags
)))
822 generate_exception(ctx
, EXCP_RI
);
825 /* This code generates a "reserved instruction" exception if 64-bit
826 instructions are not enabled. */
827 static always_inline
void check_mips_64(DisasContext
*ctx
)
829 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
830 generate_exception(ctx
, EXCP_RI
);
833 #if defined(CONFIG_USER_ONLY)
834 #define op_ldst(name) gen_op_##name##_raw()
835 #define OP_LD_TABLE(width)
836 #define OP_ST_TABLE(width)
838 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
839 #define OP_LD_TABLE(width) \
840 static GenOpFunc *gen_op_l##width[] = { \
841 &gen_op_l##width##_kernel, \
842 &gen_op_l##width##_super, \
843 &gen_op_l##width##_user, \
845 #define OP_ST_TABLE(width) \
846 static GenOpFunc *gen_op_s##width[] = { \
847 &gen_op_s##width##_kernel, \
848 &gen_op_s##width##_super, \
849 &gen_op_s##width##_user, \
853 #if defined(TARGET_MIPS64)
886 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
887 int base
, int16_t offset
)
889 const char *opn
= "ldst";
892 GEN_LOAD_IMM_TN(T0
, offset
);
893 } else if (offset
== 0) {
894 gen_op_load_gpr_T0(base
);
896 gen_op_load_gpr_T0(base
);
897 gen_op_set_T1(offset
);
900 /* Don't do NOP if destination is zero: we must perform the actual
903 #if defined(TARGET_MIPS64)
906 GEN_STORE_T0_REG(rt
);
911 GEN_STORE_T0_REG(rt
);
916 GEN_STORE_T0_REG(rt
);
925 save_cpu_state(ctx
, 1);
928 GEN_STORE_T0_REG(rt
);
934 GEN_STORE_T1_REG(rt
);
945 GEN_STORE_T1_REG(rt
);
956 GEN_STORE_T0_REG(rt
);
966 GEN_STORE_T0_REG(rt
);
976 GEN_STORE_T0_REG(rt
);
981 GEN_STORE_T0_REG(rt
);
991 GEN_STORE_T0_REG(rt
);
997 GEN_STORE_T1_REG(rt
);
1001 GEN_LOAD_REG_T1(rt
);
1006 GEN_LOAD_REG_T1(rt
);
1008 GEN_STORE_T1_REG(rt
);
1012 GEN_LOAD_REG_T1(rt
);
1018 GEN_STORE_T0_REG(rt
);
1022 save_cpu_state(ctx
, 1);
1023 GEN_LOAD_REG_T1(rt
);
1025 GEN_STORE_T0_REG(rt
);
1030 generate_exception(ctx
, EXCP_RI
);
1033 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1036 /* Load and store */
1037 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1038 int base
, int16_t offset
)
1040 const char *opn
= "flt_ldst";
1043 GEN_LOAD_IMM_TN(T0
, offset
);
1044 } else if (offset
== 0) {
1045 gen_op_load_gpr_T0(base
);
1047 gen_op_load_gpr_T0(base
);
1048 gen_op_set_T1(offset
);
1051 /* Don't do NOP if destination is zero: we must perform the actual
1056 GEN_STORE_FTN_FREG(ft
, WT0
);
1060 GEN_LOAD_FREG_FTN(WT0
, ft
);
1066 GEN_STORE_FTN_FREG(ft
, DT0
);
1070 GEN_LOAD_FREG_FTN(DT0
, ft
);
1076 generate_exception(ctx
, EXCP_RI
);
1079 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1082 /* Arithmetic with immediate operand */
1083 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1084 int rt
, int rs
, int16_t imm
)
1087 const char *opn
= "imm arith";
1089 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1090 /* If no destination, treat it as a NOP.
1091 For addi, we must generate the overflow exception when needed. */
1095 uimm
= (uint16_t)imm
;
1099 #if defined(TARGET_MIPS64)
1105 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1110 GEN_LOAD_REG_T0(rs
);
1111 GEN_LOAD_IMM_TN(T1
, uimm
);
1114 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1119 #if defined(TARGET_MIPS64)
1128 GEN_LOAD_REG_T0(rs
);
1129 GEN_LOAD_IMM_TN(T1
, uimm
);
1134 save_cpu_state(ctx
, 1);
1142 #if defined(TARGET_MIPS64)
1144 save_cpu_state(ctx
, 1);
1185 switch ((ctx
->opcode
>> 21) & 0x1f) {
1191 /* rotr is decoded as srl on non-R2 CPUs */
1192 if (env
->insn_flags
& ISA_MIPS32R2
) {
1201 MIPS_INVAL("invalid srl flag");
1202 generate_exception(ctx
, EXCP_RI
);
1206 #if defined(TARGET_MIPS64)
1216 switch ((ctx
->opcode
>> 21) & 0x1f) {
1222 /* drotr is decoded as dsrl on non-R2 CPUs */
1223 if (env
->insn_flags
& ISA_MIPS32R2
) {
1232 MIPS_INVAL("invalid dsrl flag");
1233 generate_exception(ctx
, EXCP_RI
);
1246 switch ((ctx
->opcode
>> 21) & 0x1f) {
1252 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1253 if (env
->insn_flags
& ISA_MIPS32R2
) {
1262 MIPS_INVAL("invalid dsrl32 flag");
1263 generate_exception(ctx
, EXCP_RI
);
1270 generate_exception(ctx
, EXCP_RI
);
1273 GEN_STORE_T0_REG(rt
);
1274 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1278 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1279 int rd
, int rs
, int rt
)
1281 const char *opn
= "arith";
1283 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1284 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1285 /* If no destination, treat it as a NOP.
1286 For add & sub, we must generate the overflow exception when needed. */
1290 GEN_LOAD_REG_T0(rs
);
1291 /* Specialcase the conventional move operation. */
1292 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1293 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1294 GEN_STORE_T0_REG(rd
);
1297 GEN_LOAD_REG_T1(rt
);
1300 save_cpu_state(ctx
, 1);
1309 save_cpu_state(ctx
, 1);
1317 #if defined(TARGET_MIPS64)
1319 save_cpu_state(ctx
, 1);
1328 save_cpu_state(ctx
, 1);
1382 switch ((ctx
->opcode
>> 6) & 0x1f) {
1388 /* rotrv is decoded as srlv on non-R2 CPUs */
1389 if (env
->insn_flags
& ISA_MIPS32R2
) {
1398 MIPS_INVAL("invalid srlv flag");
1399 generate_exception(ctx
, EXCP_RI
);
1403 #if defined(TARGET_MIPS64)
1413 switch ((ctx
->opcode
>> 6) & 0x1f) {
1419 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1420 if (env
->insn_flags
& ISA_MIPS32R2
) {
1429 MIPS_INVAL("invalid dsrlv flag");
1430 generate_exception(ctx
, EXCP_RI
);
1437 generate_exception(ctx
, EXCP_RI
);
1440 GEN_STORE_T0_REG(rd
);
1442 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1445 /* Arithmetic on HI/LO registers */
1446 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1448 const char *opn
= "hilo";
1450 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1458 GEN_STORE_T0_REG(reg
);
1463 GEN_STORE_T0_REG(reg
);
1467 GEN_LOAD_REG_T0(reg
);
1472 GEN_LOAD_REG_T0(reg
);
1478 generate_exception(ctx
, EXCP_RI
);
1481 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1484 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1487 const char *opn
= "mul/div";
1489 GEN_LOAD_REG_T0(rs
);
1490 GEN_LOAD_REG_T1(rt
);
1508 #if defined(TARGET_MIPS64)
1544 generate_exception(ctx
, EXCP_RI
);
1547 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1550 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
1551 int rd
, int rs
, int rt
)
1553 const char *opn
= "mul vr54xx";
1555 GEN_LOAD_REG_T0(rs
);
1556 GEN_LOAD_REG_T1(rt
);
1559 case OPC_VR54XX_MULS
:
1563 case OPC_VR54XX_MULSU
:
1567 case OPC_VR54XX_MACC
:
1571 case OPC_VR54XX_MACCU
:
1575 case OPC_VR54XX_MSAC
:
1579 case OPC_VR54XX_MSACU
:
1583 case OPC_VR54XX_MULHI
:
1587 case OPC_VR54XX_MULHIU
:
1591 case OPC_VR54XX_MULSHI
:
1595 case OPC_VR54XX_MULSHIU
:
1599 case OPC_VR54XX_MACCHI
:
1603 case OPC_VR54XX_MACCHIU
:
1607 case OPC_VR54XX_MSACHI
:
1611 case OPC_VR54XX_MSACHIU
:
1616 MIPS_INVAL("mul vr54xx");
1617 generate_exception(ctx
, EXCP_RI
);
1620 GEN_STORE_T0_REG(rd
);
1621 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1624 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1627 const char *opn
= "CLx";
1633 GEN_LOAD_REG_T0(rs
);
1643 #if defined(TARGET_MIPS64)
1655 generate_exception(ctx
, EXCP_RI
);
1658 gen_op_store_T0_gpr(rd
);
1659 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1663 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1664 int rs
, int rt
, int16_t imm
)
1669 /* Load needed operands */
1677 /* Compare two registers */
1679 GEN_LOAD_REG_T0(rs
);
1680 GEN_LOAD_REG_T1(rt
);
1690 /* Compare register to immediate */
1691 if (rs
!= 0 || imm
!= 0) {
1692 GEN_LOAD_REG_T0(rs
);
1693 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1700 case OPC_TEQ
: /* rs == rs */
1701 case OPC_TEQI
: /* r0 == 0 */
1702 case OPC_TGE
: /* rs >= rs */
1703 case OPC_TGEI
: /* r0 >= 0 */
1704 case OPC_TGEU
: /* rs >= rs unsigned */
1705 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1709 case OPC_TLT
: /* rs < rs */
1710 case OPC_TLTI
: /* r0 < 0 */
1711 case OPC_TLTU
: /* rs < rs unsigned */
1712 case OPC_TLTIU
: /* r0 < 0 unsigned */
1713 case OPC_TNE
: /* rs != rs */
1714 case OPC_TNEI
: /* r0 != 0 */
1715 /* Never trap: treat as NOP. */
1719 generate_exception(ctx
, EXCP_RI
);
1750 generate_exception(ctx
, EXCP_RI
);
1754 save_cpu_state(ctx
, 1);
1756 ctx
->bstate
= BS_STOP
;
1759 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1761 TranslationBlock
*tb
;
1763 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1766 tcg_gen_exit_tb((long)tb
+ n
);
1773 /* Branches (before delay slot) */
1774 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1775 int rs
, int rt
, int32_t offset
)
1777 target_ulong btarget
= -1;
1781 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1782 #ifdef MIPS_DEBUG_DISAS
1783 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1785 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1789 generate_exception(ctx
, EXCP_RI
);
1793 /* Load needed operands */
1799 /* Compare two registers */
1801 GEN_LOAD_REG_T0(rs
);
1802 GEN_LOAD_REG_T1(rt
);
1805 btarget
= ctx
->pc
+ 4 + offset
;
1819 /* Compare to zero */
1821 gen_op_load_gpr_T0(rs
);
1824 btarget
= ctx
->pc
+ 4 + offset
;
1828 /* Jump to immediate */
1829 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
1833 /* Jump to register */
1834 if (offset
!= 0 && offset
!= 16) {
1835 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1836 others are reserved. */
1837 MIPS_INVAL("jump hint");
1838 generate_exception(ctx
, EXCP_RI
);
1841 GEN_LOAD_REG_T2(rs
);
1844 MIPS_INVAL("branch/jump");
1845 generate_exception(ctx
, EXCP_RI
);
1849 /* No condition to be computed */
1851 case OPC_BEQ
: /* rx == rx */
1852 case OPC_BEQL
: /* rx == rx likely */
1853 case OPC_BGEZ
: /* 0 >= 0 */
1854 case OPC_BGEZL
: /* 0 >= 0 likely */
1855 case OPC_BLEZ
: /* 0 <= 0 */
1856 case OPC_BLEZL
: /* 0 <= 0 likely */
1858 ctx
->hflags
|= MIPS_HFLAG_B
;
1859 MIPS_DEBUG("balways");
1861 case OPC_BGEZAL
: /* 0 >= 0 */
1862 case OPC_BGEZALL
: /* 0 >= 0 likely */
1863 /* Always take and link */
1865 ctx
->hflags
|= MIPS_HFLAG_B
;
1866 MIPS_DEBUG("balways and link");
1868 case OPC_BNE
: /* rx != rx */
1869 case OPC_BGTZ
: /* 0 > 0 */
1870 case OPC_BLTZ
: /* 0 < 0 */
1872 MIPS_DEBUG("bnever (NOP)");
1874 case OPC_BLTZAL
: /* 0 < 0 */
1875 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1876 gen_op_store_T0_gpr(31);
1877 MIPS_DEBUG("bnever and link");
1879 case OPC_BLTZALL
: /* 0 < 0 likely */
1880 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1881 gen_op_store_T0_gpr(31);
1882 /* Skip the instruction in the delay slot */
1883 MIPS_DEBUG("bnever, link and skip");
1886 case OPC_BNEL
: /* rx != rx likely */
1887 case OPC_BGTZL
: /* 0 > 0 likely */
1888 case OPC_BLTZL
: /* 0 < 0 likely */
1889 /* Skip the instruction in the delay slot */
1890 MIPS_DEBUG("bnever and skip");
1894 ctx
->hflags
|= MIPS_HFLAG_B
;
1895 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1899 ctx
->hflags
|= MIPS_HFLAG_B
;
1900 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1903 ctx
->hflags
|= MIPS_HFLAG_BR
;
1904 MIPS_DEBUG("jr %s", regnames
[rs
]);
1908 ctx
->hflags
|= MIPS_HFLAG_BR
;
1909 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1912 MIPS_INVAL("branch/jump");
1913 generate_exception(ctx
, EXCP_RI
);
1920 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1921 regnames
[rs
], regnames
[rt
], btarget
);
1925 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1926 regnames
[rs
], regnames
[rt
], btarget
);
1930 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1931 regnames
[rs
], regnames
[rt
], btarget
);
1935 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1936 regnames
[rs
], regnames
[rt
], btarget
);
1940 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1944 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1948 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1954 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1958 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1962 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1966 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1970 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1974 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1978 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1983 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1985 ctx
->hflags
|= MIPS_HFLAG_BC
;
1991 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1993 ctx
->hflags
|= MIPS_HFLAG_BL
;
1995 gen_op_save_bcond();
1998 MIPS_INVAL("conditional branch/jump");
1999 generate_exception(ctx
, EXCP_RI
);
2003 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2004 blink
, ctx
->hflags
, btarget
);
2006 ctx
->btarget
= btarget
;
2008 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2009 gen_op_store_T0_gpr(blink
);
2013 /* special3 bitfield operations */
2014 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2015 int rs
, int lsb
, int msb
)
2017 GEN_LOAD_REG_T1(rs
);
2022 gen_op_ext(lsb
, msb
+ 1);
2024 #if defined(TARGET_MIPS64)
2028 gen_op_dext(lsb
, msb
+ 1 + 32);
2033 gen_op_dext(lsb
+ 32, msb
+ 1);
2038 gen_op_dext(lsb
, msb
+ 1);
2044 GEN_LOAD_REG_T0(rt
);
2045 gen_op_ins(lsb
, msb
- lsb
+ 1);
2047 #if defined(TARGET_MIPS64)
2051 GEN_LOAD_REG_T0(rt
);
2052 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2057 GEN_LOAD_REG_T0(rt
);
2058 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2063 GEN_LOAD_REG_T0(rt
);
2064 gen_op_dins(lsb
, msb
- lsb
+ 1);
2069 MIPS_INVAL("bitops");
2070 generate_exception(ctx
, EXCP_RI
);
2073 GEN_STORE_T0_REG(rt
);
2076 /* CP0 (MMU and control) */
2077 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2079 const char *rn
= "invalid";
2082 check_insn(env
, ctx
, ISA_MIPS32
);
2088 gen_op_mfc0_index();
2092 check_insn(env
, ctx
, ASE_MT
);
2093 gen_op_mfc0_mvpcontrol();
2097 check_insn(env
, ctx
, ASE_MT
);
2098 gen_op_mfc0_mvpconf0();
2102 check_insn(env
, ctx
, ASE_MT
);
2103 gen_op_mfc0_mvpconf1();
2113 gen_op_mfc0_random();
2117 check_insn(env
, ctx
, ASE_MT
);
2118 gen_op_mfc0_vpecontrol();
2122 check_insn(env
, ctx
, ASE_MT
);
2123 gen_op_mfc0_vpeconf0();
2127 check_insn(env
, ctx
, ASE_MT
);
2128 gen_op_mfc0_vpeconf1();
2132 check_insn(env
, ctx
, ASE_MT
);
2133 gen_op_mfc0_yqmask();
2137 check_insn(env
, ctx
, ASE_MT
);
2138 gen_op_mfc0_vpeschedule();
2142 check_insn(env
, ctx
, ASE_MT
);
2143 gen_op_mfc0_vpeschefback();
2144 rn
= "VPEScheFBack";
2147 check_insn(env
, ctx
, ASE_MT
);
2148 gen_op_mfc0_vpeopt();
2158 gen_op_mfc0_entrylo0();
2162 check_insn(env
, ctx
, ASE_MT
);
2163 gen_op_mfc0_tcstatus();
2167 check_insn(env
, ctx
, ASE_MT
);
2168 gen_op_mfc0_tcbind();
2172 check_insn(env
, ctx
, ASE_MT
);
2173 gen_op_mfc0_tcrestart();
2177 check_insn(env
, ctx
, ASE_MT
);
2178 gen_op_mfc0_tchalt();
2182 check_insn(env
, ctx
, ASE_MT
);
2183 gen_op_mfc0_tccontext();
2187 check_insn(env
, ctx
, ASE_MT
);
2188 gen_op_mfc0_tcschedule();
2192 check_insn(env
, ctx
, ASE_MT
);
2193 gen_op_mfc0_tcschefback();
2203 gen_op_mfc0_entrylo1();
2213 gen_op_mfc0_context();
2217 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2218 rn
= "ContextConfig";
2227 gen_op_mfc0_pagemask();
2231 check_insn(env
, ctx
, ISA_MIPS32R2
);
2232 gen_op_mfc0_pagegrain();
2242 gen_op_mfc0_wired();
2246 check_insn(env
, ctx
, ISA_MIPS32R2
);
2247 gen_op_mfc0_srsconf0();
2251 check_insn(env
, ctx
, ISA_MIPS32R2
);
2252 gen_op_mfc0_srsconf1();
2256 check_insn(env
, ctx
, ISA_MIPS32R2
);
2257 gen_op_mfc0_srsconf2();
2261 check_insn(env
, ctx
, ISA_MIPS32R2
);
2262 gen_op_mfc0_srsconf3();
2266 check_insn(env
, ctx
, ISA_MIPS32R2
);
2267 gen_op_mfc0_srsconf4();
2277 check_insn(env
, ctx
, ISA_MIPS32R2
);
2278 gen_op_mfc0_hwrena();
2288 gen_op_mfc0_badvaddr();
2298 gen_op_mfc0_count();
2301 /* 6,7 are implementation dependent */
2309 gen_op_mfc0_entryhi();
2319 gen_op_mfc0_compare();
2322 /* 6,7 are implementation dependent */
2330 gen_op_mfc0_status();
2334 check_insn(env
, ctx
, ISA_MIPS32R2
);
2335 gen_op_mfc0_intctl();
2339 check_insn(env
, ctx
, ISA_MIPS32R2
);
2340 gen_op_mfc0_srsctl();
2344 check_insn(env
, ctx
, ISA_MIPS32R2
);
2345 gen_op_mfc0_srsmap();
2355 gen_op_mfc0_cause();
2379 check_insn(env
, ctx
, ISA_MIPS32R2
);
2380 gen_op_mfc0_ebase();
2390 gen_op_mfc0_config0();
2394 gen_op_mfc0_config1();
2398 gen_op_mfc0_config2();
2402 gen_op_mfc0_config3();
2405 /* 4,5 are reserved */
2406 /* 6,7 are implementation dependent */
2408 gen_op_mfc0_config6();
2412 gen_op_mfc0_config7();
2422 gen_op_mfc0_lladdr();
2432 gen_op_mfc0_watchlo(sel
);
2442 gen_op_mfc0_watchhi(sel
);
2452 #if defined(TARGET_MIPS64)
2453 check_insn(env
, ctx
, ISA_MIPS3
);
2454 gen_op_mfc0_xcontext();
2463 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2466 gen_op_mfc0_framemask();
2475 rn
= "'Diagnostic"; /* implementation dependent */
2480 gen_op_mfc0_debug(); /* EJTAG support */
2484 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2485 rn
= "TraceControl";
2488 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2489 rn
= "TraceControl2";
2492 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2493 rn
= "UserTraceData";
2496 // gen_op_mfc0_debug(); /* PDtrace support */
2506 gen_op_mfc0_depc(); /* EJTAG support */
2516 gen_op_mfc0_performance0();
2517 rn
= "Performance0";
2520 // gen_op_mfc0_performance1();
2521 rn
= "Performance1";
2524 // gen_op_mfc0_performance2();
2525 rn
= "Performance2";
2528 // gen_op_mfc0_performance3();
2529 rn
= "Performance3";
2532 // gen_op_mfc0_performance4();
2533 rn
= "Performance4";
2536 // gen_op_mfc0_performance5();
2537 rn
= "Performance5";
2540 // gen_op_mfc0_performance6();
2541 rn
= "Performance6";
2544 // gen_op_mfc0_performance7();
2545 rn
= "Performance7";
2570 gen_op_mfc0_taglo();
2577 gen_op_mfc0_datalo();
2590 gen_op_mfc0_taghi();
2597 gen_op_mfc0_datahi();
2607 gen_op_mfc0_errorepc();
2617 gen_op_mfc0_desave(); /* EJTAG support */
2627 #if defined MIPS_DEBUG_DISAS
2628 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2629 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2636 #if defined MIPS_DEBUG_DISAS
2637 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2638 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2642 generate_exception(ctx
, EXCP_RI
);
2645 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2647 const char *rn
= "invalid";
2650 check_insn(env
, ctx
, ISA_MIPS32
);
2656 gen_op_mtc0_index();
2660 check_insn(env
, ctx
, ASE_MT
);
2661 gen_op_mtc0_mvpcontrol();
2665 check_insn(env
, ctx
, ASE_MT
);
2670 check_insn(env
, ctx
, ASE_MT
);
2685 check_insn(env
, ctx
, ASE_MT
);
2686 gen_op_mtc0_vpecontrol();
2690 check_insn(env
, ctx
, ASE_MT
);
2691 gen_op_mtc0_vpeconf0();
2695 check_insn(env
, ctx
, ASE_MT
);
2696 gen_op_mtc0_vpeconf1();
2700 check_insn(env
, ctx
, ASE_MT
);
2701 gen_op_mtc0_yqmask();
2705 check_insn(env
, ctx
, ASE_MT
);
2706 gen_op_mtc0_vpeschedule();
2710 check_insn(env
, ctx
, ASE_MT
);
2711 gen_op_mtc0_vpeschefback();
2712 rn
= "VPEScheFBack";
2715 check_insn(env
, ctx
, ASE_MT
);
2716 gen_op_mtc0_vpeopt();
2726 gen_op_mtc0_entrylo0();
2730 check_insn(env
, ctx
, ASE_MT
);
2731 gen_op_mtc0_tcstatus();
2735 check_insn(env
, ctx
, ASE_MT
);
2736 gen_op_mtc0_tcbind();
2740 check_insn(env
, ctx
, ASE_MT
);
2741 gen_op_mtc0_tcrestart();
2745 check_insn(env
, ctx
, ASE_MT
);
2746 gen_op_mtc0_tchalt();
2750 check_insn(env
, ctx
, ASE_MT
);
2751 gen_op_mtc0_tccontext();
2755 check_insn(env
, ctx
, ASE_MT
);
2756 gen_op_mtc0_tcschedule();
2760 check_insn(env
, ctx
, ASE_MT
);
2761 gen_op_mtc0_tcschefback();
2771 gen_op_mtc0_entrylo1();
2781 gen_op_mtc0_context();
2785 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2786 rn
= "ContextConfig";
2795 gen_op_mtc0_pagemask();
2799 check_insn(env
, ctx
, ISA_MIPS32R2
);
2800 gen_op_mtc0_pagegrain();
2810 gen_op_mtc0_wired();
2814 check_insn(env
, ctx
, ISA_MIPS32R2
);
2815 gen_op_mtc0_srsconf0();
2819 check_insn(env
, ctx
, ISA_MIPS32R2
);
2820 gen_op_mtc0_srsconf1();
2824 check_insn(env
, ctx
, ISA_MIPS32R2
);
2825 gen_op_mtc0_srsconf2();
2829 check_insn(env
, ctx
, ISA_MIPS32R2
);
2830 gen_op_mtc0_srsconf3();
2834 check_insn(env
, ctx
, ISA_MIPS32R2
);
2835 gen_op_mtc0_srsconf4();
2845 check_insn(env
, ctx
, ISA_MIPS32R2
);
2846 gen_op_mtc0_hwrena();
2860 gen_op_mtc0_count();
2863 /* 6,7 are implementation dependent */
2867 /* Stop translation as we may have switched the execution mode */
2868 ctx
->bstate
= BS_STOP
;
2873 gen_op_mtc0_entryhi();
2883 gen_op_mtc0_compare();
2886 /* 6,7 are implementation dependent */
2890 /* Stop translation as we may have switched the execution mode */
2891 ctx
->bstate
= BS_STOP
;
2896 gen_op_mtc0_status();
2897 /* BS_STOP isn't good enough here, hflags may have changed. */
2898 gen_save_pc(ctx
->pc
+ 4);
2899 ctx
->bstate
= BS_EXCP
;
2903 check_insn(env
, ctx
, ISA_MIPS32R2
);
2904 gen_op_mtc0_intctl();
2905 /* Stop translation as we may have switched the execution mode */
2906 ctx
->bstate
= BS_STOP
;
2910 check_insn(env
, ctx
, ISA_MIPS32R2
);
2911 gen_op_mtc0_srsctl();
2912 /* Stop translation as we may have switched the execution mode */
2913 ctx
->bstate
= BS_STOP
;
2917 check_insn(env
, ctx
, ISA_MIPS32R2
);
2918 gen_op_mtc0_srsmap();
2919 /* Stop translation as we may have switched the execution mode */
2920 ctx
->bstate
= BS_STOP
;
2930 gen_op_mtc0_cause();
2936 /* Stop translation as we may have switched the execution mode */
2937 ctx
->bstate
= BS_STOP
;
2956 check_insn(env
, ctx
, ISA_MIPS32R2
);
2957 gen_op_mtc0_ebase();
2967 gen_op_mtc0_config0();
2969 /* Stop translation as we may have switched the execution mode */
2970 ctx
->bstate
= BS_STOP
;
2973 /* ignored, read only */
2977 gen_op_mtc0_config2();
2979 /* Stop translation as we may have switched the execution mode */
2980 ctx
->bstate
= BS_STOP
;
2983 /* ignored, read only */
2986 /* 4,5 are reserved */
2987 /* 6,7 are implementation dependent */
2997 rn
= "Invalid config selector";
3014 gen_op_mtc0_watchlo(sel
);
3024 gen_op_mtc0_watchhi(sel
);
3034 #if defined(TARGET_MIPS64)
3035 check_insn(env
, ctx
, ISA_MIPS3
);
3036 gen_op_mtc0_xcontext();
3045 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3048 gen_op_mtc0_framemask();
3057 rn
= "Diagnostic"; /* implementation dependent */
3062 gen_op_mtc0_debug(); /* EJTAG support */
3063 /* BS_STOP isn't good enough here, hflags may have changed. */
3064 gen_save_pc(ctx
->pc
+ 4);
3065 ctx
->bstate
= BS_EXCP
;
3069 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3070 rn
= "TraceControl";
3071 /* Stop translation as we may have switched the execution mode */
3072 ctx
->bstate
= BS_STOP
;
3075 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3076 rn
= "TraceControl2";
3077 /* Stop translation as we may have switched the execution mode */
3078 ctx
->bstate
= BS_STOP
;
3081 /* Stop translation as we may have switched the execution mode */
3082 ctx
->bstate
= BS_STOP
;
3083 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3084 rn
= "UserTraceData";
3085 /* Stop translation as we may have switched the execution mode */
3086 ctx
->bstate
= BS_STOP
;
3089 // gen_op_mtc0_debug(); /* PDtrace support */
3090 /* Stop translation as we may have switched the execution mode */
3091 ctx
->bstate
= BS_STOP
;
3101 gen_op_mtc0_depc(); /* EJTAG support */
3111 gen_op_mtc0_performance0();
3112 rn
= "Performance0";
3115 // gen_op_mtc0_performance1();
3116 rn
= "Performance1";
3119 // gen_op_mtc0_performance2();
3120 rn
= "Performance2";
3123 // gen_op_mtc0_performance3();
3124 rn
= "Performance3";
3127 // gen_op_mtc0_performance4();
3128 rn
= "Performance4";
3131 // gen_op_mtc0_performance5();
3132 rn
= "Performance5";
3135 // gen_op_mtc0_performance6();
3136 rn
= "Performance6";
3139 // gen_op_mtc0_performance7();
3140 rn
= "Performance7";
3166 gen_op_mtc0_taglo();
3173 gen_op_mtc0_datalo();
3186 gen_op_mtc0_taghi();
3193 gen_op_mtc0_datahi();
3204 gen_op_mtc0_errorepc();
3214 gen_op_mtc0_desave(); /* EJTAG support */
3220 /* Stop translation as we may have switched the execution mode */
3221 ctx
->bstate
= BS_STOP
;
3226 #if defined MIPS_DEBUG_DISAS
3227 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3228 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3235 #if defined MIPS_DEBUG_DISAS
3236 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3237 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3241 generate_exception(ctx
, EXCP_RI
);
3244 #if defined(TARGET_MIPS64)
3245 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3247 const char *rn
= "invalid";
3250 check_insn(env
, ctx
, ISA_MIPS64
);
3256 gen_op_mfc0_index();
3260 check_insn(env
, ctx
, ASE_MT
);
3261 gen_op_mfc0_mvpcontrol();
3265 check_insn(env
, ctx
, ASE_MT
);
3266 gen_op_mfc0_mvpconf0();
3270 check_insn(env
, ctx
, ASE_MT
);
3271 gen_op_mfc0_mvpconf1();
3281 gen_op_mfc0_random();
3285 check_insn(env
, ctx
, ASE_MT
);
3286 gen_op_mfc0_vpecontrol();
3290 check_insn(env
, ctx
, ASE_MT
);
3291 gen_op_mfc0_vpeconf0();
3295 check_insn(env
, ctx
, ASE_MT
);
3296 gen_op_mfc0_vpeconf1();
3300 check_insn(env
, ctx
, ASE_MT
);
3301 gen_op_dmfc0_yqmask();
3305 check_insn(env
, ctx
, ASE_MT
);
3306 gen_op_dmfc0_vpeschedule();
3310 check_insn(env
, ctx
, ASE_MT
);
3311 gen_op_dmfc0_vpeschefback();
3312 rn
= "VPEScheFBack";
3315 check_insn(env
, ctx
, ASE_MT
);
3316 gen_op_mfc0_vpeopt();
3326 gen_op_dmfc0_entrylo0();
3330 check_insn(env
, ctx
, ASE_MT
);
3331 gen_op_mfc0_tcstatus();
3335 check_insn(env
, ctx
, ASE_MT
);
3336 gen_op_mfc0_tcbind();
3340 check_insn(env
, ctx
, ASE_MT
);
3341 gen_op_dmfc0_tcrestart();
3345 check_insn(env
, ctx
, ASE_MT
);
3346 gen_op_dmfc0_tchalt();
3350 check_insn(env
, ctx
, ASE_MT
);
3351 gen_op_dmfc0_tccontext();
3355 check_insn(env
, ctx
, ASE_MT
);
3356 gen_op_dmfc0_tcschedule();
3360 check_insn(env
, ctx
, ASE_MT
);
3361 gen_op_dmfc0_tcschefback();
3371 gen_op_dmfc0_entrylo1();
3381 gen_op_dmfc0_context();
3385 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3386 rn
= "ContextConfig";
3395 gen_op_mfc0_pagemask();
3399 check_insn(env
, ctx
, ISA_MIPS32R2
);
3400 gen_op_mfc0_pagegrain();
3410 gen_op_mfc0_wired();
3414 check_insn(env
, ctx
, ISA_MIPS32R2
);
3415 gen_op_mfc0_srsconf0();
3419 check_insn(env
, ctx
, ISA_MIPS32R2
);
3420 gen_op_mfc0_srsconf1();
3424 check_insn(env
, ctx
, ISA_MIPS32R2
);
3425 gen_op_mfc0_srsconf2();
3429 check_insn(env
, ctx
, ISA_MIPS32R2
);
3430 gen_op_mfc0_srsconf3();
3434 check_insn(env
, ctx
, ISA_MIPS32R2
);
3435 gen_op_mfc0_srsconf4();
3445 check_insn(env
, ctx
, ISA_MIPS32R2
);
3446 gen_op_mfc0_hwrena();
3456 gen_op_dmfc0_badvaddr();
3466 gen_op_mfc0_count();
3469 /* 6,7 are implementation dependent */
3477 gen_op_dmfc0_entryhi();
3487 gen_op_mfc0_compare();
3490 /* 6,7 are implementation dependent */
3498 gen_op_mfc0_status();
3502 check_insn(env
, ctx
, ISA_MIPS32R2
);
3503 gen_op_mfc0_intctl();
3507 check_insn(env
, ctx
, ISA_MIPS32R2
);
3508 gen_op_mfc0_srsctl();
3512 check_insn(env
, ctx
, ISA_MIPS32R2
);
3513 gen_op_mfc0_srsmap();
3523 gen_op_mfc0_cause();
3547 check_insn(env
, ctx
, ISA_MIPS32R2
);
3548 gen_op_mfc0_ebase();
3558 gen_op_mfc0_config0();
3562 gen_op_mfc0_config1();
3566 gen_op_mfc0_config2();
3570 gen_op_mfc0_config3();
3573 /* 6,7 are implementation dependent */
3581 gen_op_dmfc0_lladdr();
3591 gen_op_dmfc0_watchlo(sel
);
3601 gen_op_mfc0_watchhi(sel
);
3611 check_insn(env
, ctx
, ISA_MIPS3
);
3612 gen_op_dmfc0_xcontext();
3620 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3623 gen_op_mfc0_framemask();
3632 rn
= "'Diagnostic"; /* implementation dependent */
3637 gen_op_mfc0_debug(); /* EJTAG support */
3641 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3642 rn
= "TraceControl";
3645 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3646 rn
= "TraceControl2";
3649 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3650 rn
= "UserTraceData";
3653 // gen_op_dmfc0_debug(); /* PDtrace support */
3663 gen_op_dmfc0_depc(); /* EJTAG support */
3673 gen_op_mfc0_performance0();
3674 rn
= "Performance0";
3677 // gen_op_dmfc0_performance1();
3678 rn
= "Performance1";
3681 // gen_op_dmfc0_performance2();
3682 rn
= "Performance2";
3685 // gen_op_dmfc0_performance3();
3686 rn
= "Performance3";
3689 // gen_op_dmfc0_performance4();
3690 rn
= "Performance4";
3693 // gen_op_dmfc0_performance5();
3694 rn
= "Performance5";
3697 // gen_op_dmfc0_performance6();
3698 rn
= "Performance6";
3701 // gen_op_dmfc0_performance7();
3702 rn
= "Performance7";
3727 gen_op_mfc0_taglo();
3734 gen_op_mfc0_datalo();
3747 gen_op_mfc0_taghi();
3754 gen_op_mfc0_datahi();
3764 gen_op_dmfc0_errorepc();
3774 gen_op_mfc0_desave(); /* EJTAG support */
3784 #if defined MIPS_DEBUG_DISAS
3785 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3786 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3793 #if defined MIPS_DEBUG_DISAS
3794 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3795 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3799 generate_exception(ctx
, EXCP_RI
);
3802 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3804 const char *rn
= "invalid";
3807 check_insn(env
, ctx
, ISA_MIPS64
);
3813 gen_op_mtc0_index();
3817 check_insn(env
, ctx
, ASE_MT
);
3818 gen_op_mtc0_mvpcontrol();
3822 check_insn(env
, ctx
, ASE_MT
);
3827 check_insn(env
, ctx
, ASE_MT
);
3842 check_insn(env
, ctx
, ASE_MT
);
3843 gen_op_mtc0_vpecontrol();
3847 check_insn(env
, ctx
, ASE_MT
);
3848 gen_op_mtc0_vpeconf0();
3852 check_insn(env
, ctx
, ASE_MT
);
3853 gen_op_mtc0_vpeconf1();
3857 check_insn(env
, ctx
, ASE_MT
);
3858 gen_op_mtc0_yqmask();
3862 check_insn(env
, ctx
, ASE_MT
);
3863 gen_op_mtc0_vpeschedule();
3867 check_insn(env
, ctx
, ASE_MT
);
3868 gen_op_mtc0_vpeschefback();
3869 rn
= "VPEScheFBack";
3872 check_insn(env
, ctx
, ASE_MT
);
3873 gen_op_mtc0_vpeopt();
3883 gen_op_mtc0_entrylo0();
3887 check_insn(env
, ctx
, ASE_MT
);
3888 gen_op_mtc0_tcstatus();
3892 check_insn(env
, ctx
, ASE_MT
);
3893 gen_op_mtc0_tcbind();
3897 check_insn(env
, ctx
, ASE_MT
);
3898 gen_op_mtc0_tcrestart();
3902 check_insn(env
, ctx
, ASE_MT
);
3903 gen_op_mtc0_tchalt();
3907 check_insn(env
, ctx
, ASE_MT
);
3908 gen_op_mtc0_tccontext();
3912 check_insn(env
, ctx
, ASE_MT
);
3913 gen_op_mtc0_tcschedule();
3917 check_insn(env
, ctx
, ASE_MT
);
3918 gen_op_mtc0_tcschefback();
3928 gen_op_mtc0_entrylo1();
3938 gen_op_mtc0_context();
3942 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3943 rn
= "ContextConfig";
3952 gen_op_mtc0_pagemask();
3956 check_insn(env
, ctx
, ISA_MIPS32R2
);
3957 gen_op_mtc0_pagegrain();
3967 gen_op_mtc0_wired();
3971 check_insn(env
, ctx
, ISA_MIPS32R2
);
3972 gen_op_mtc0_srsconf0();
3976 check_insn(env
, ctx
, ISA_MIPS32R2
);
3977 gen_op_mtc0_srsconf1();
3981 check_insn(env
, ctx
, ISA_MIPS32R2
);
3982 gen_op_mtc0_srsconf2();
3986 check_insn(env
, ctx
, ISA_MIPS32R2
);
3987 gen_op_mtc0_srsconf3();
3991 check_insn(env
, ctx
, ISA_MIPS32R2
);
3992 gen_op_mtc0_srsconf4();
4002 check_insn(env
, ctx
, ISA_MIPS32R2
);
4003 gen_op_mtc0_hwrena();
4017 gen_op_mtc0_count();
4020 /* 6,7 are implementation dependent */
4024 /* Stop translation as we may have switched the execution mode */
4025 ctx
->bstate
= BS_STOP
;
4030 gen_op_mtc0_entryhi();
4040 gen_op_mtc0_compare();
4043 /* 6,7 are implementation dependent */
4047 /* Stop translation as we may have switched the execution mode */
4048 ctx
->bstate
= BS_STOP
;
4053 gen_op_mtc0_status();
4054 /* BS_STOP isn't good enough here, hflags may have changed. */
4055 gen_save_pc(ctx
->pc
+ 4);
4056 ctx
->bstate
= BS_EXCP
;
4060 check_insn(env
, ctx
, ISA_MIPS32R2
);
4061 gen_op_mtc0_intctl();
4062 /* Stop translation as we may have switched the execution mode */
4063 ctx
->bstate
= BS_STOP
;
4067 check_insn(env
, ctx
, ISA_MIPS32R2
);
4068 gen_op_mtc0_srsctl();
4069 /* Stop translation as we may have switched the execution mode */
4070 ctx
->bstate
= BS_STOP
;
4074 check_insn(env
, ctx
, ISA_MIPS32R2
);
4075 gen_op_mtc0_srsmap();
4076 /* Stop translation as we may have switched the execution mode */
4077 ctx
->bstate
= BS_STOP
;
4087 gen_op_mtc0_cause();
4093 /* Stop translation as we may have switched the execution mode */
4094 ctx
->bstate
= BS_STOP
;
4113 check_insn(env
, ctx
, ISA_MIPS32R2
);
4114 gen_op_mtc0_ebase();
4124 gen_op_mtc0_config0();
4126 /* Stop translation as we may have switched the execution mode */
4127 ctx
->bstate
= BS_STOP
;
4134 gen_op_mtc0_config2();
4136 /* Stop translation as we may have switched the execution mode */
4137 ctx
->bstate
= BS_STOP
;
4143 /* 6,7 are implementation dependent */
4145 rn
= "Invalid config selector";
4162 gen_op_mtc0_watchlo(sel
);
4172 gen_op_mtc0_watchhi(sel
);
4182 check_insn(env
, ctx
, ISA_MIPS3
);
4183 gen_op_mtc0_xcontext();
4191 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4194 gen_op_mtc0_framemask();
4203 rn
= "Diagnostic"; /* implementation dependent */
4208 gen_op_mtc0_debug(); /* EJTAG support */
4209 /* BS_STOP isn't good enough here, hflags may have changed. */
4210 gen_save_pc(ctx
->pc
+ 4);
4211 ctx
->bstate
= BS_EXCP
;
4215 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4216 /* Stop translation as we may have switched the execution mode */
4217 ctx
->bstate
= BS_STOP
;
4218 rn
= "TraceControl";
4221 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4222 /* Stop translation as we may have switched the execution mode */
4223 ctx
->bstate
= BS_STOP
;
4224 rn
= "TraceControl2";
4227 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4228 /* Stop translation as we may have switched the execution mode */
4229 ctx
->bstate
= BS_STOP
;
4230 rn
= "UserTraceData";
4233 // gen_op_mtc0_debug(); /* PDtrace support */
4234 /* Stop translation as we may have switched the execution mode */
4235 ctx
->bstate
= BS_STOP
;
4245 gen_op_mtc0_depc(); /* EJTAG support */
4255 gen_op_mtc0_performance0();
4256 rn
= "Performance0";
4259 // gen_op_mtc0_performance1();
4260 rn
= "Performance1";
4263 // gen_op_mtc0_performance2();
4264 rn
= "Performance2";
4267 // gen_op_mtc0_performance3();
4268 rn
= "Performance3";
4271 // gen_op_mtc0_performance4();
4272 rn
= "Performance4";
4275 // gen_op_mtc0_performance5();
4276 rn
= "Performance5";
4279 // gen_op_mtc0_performance6();
4280 rn
= "Performance6";
4283 // gen_op_mtc0_performance7();
4284 rn
= "Performance7";
4310 gen_op_mtc0_taglo();
4317 gen_op_mtc0_datalo();
4330 gen_op_mtc0_taghi();
4337 gen_op_mtc0_datahi();
4348 gen_op_mtc0_errorepc();
4358 gen_op_mtc0_desave(); /* EJTAG support */
4364 /* Stop translation as we may have switched the execution mode */
4365 ctx
->bstate
= BS_STOP
;
4370 #if defined MIPS_DEBUG_DISAS
4371 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4372 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4379 #if defined MIPS_DEBUG_DISAS
4380 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4381 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4385 generate_exception(ctx
, EXCP_RI
);
4387 #endif /* TARGET_MIPS64 */
4389 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4390 int u
, int sel
, int h
)
4392 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4394 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4395 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4396 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4398 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4399 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4406 gen_op_mftc0_tcstatus();
4409 gen_op_mftc0_tcbind();
4412 gen_op_mftc0_tcrestart();
4415 gen_op_mftc0_tchalt();
4418 gen_op_mftc0_tccontext();
4421 gen_op_mftc0_tcschedule();
4424 gen_op_mftc0_tcschefback();
4427 gen_mfc0(env
, ctx
, rt
, sel
);
4434 gen_op_mftc0_entryhi();
4437 gen_mfc0(env
, ctx
, rt
, sel
);
4443 gen_op_mftc0_status();
4446 gen_mfc0(env
, ctx
, rt
, sel
);
4452 gen_op_mftc0_debug();
4455 gen_mfc0(env
, ctx
, rt
, sel
);
4460 gen_mfc0(env
, ctx
, rt
, sel
);
4462 } else switch (sel
) {
4463 /* GPR registers. */
4467 /* Auxiliary CPU registers */
4513 /* Floating point (COP1). */
4515 /* XXX: For now we support only a single FPU context. */
4517 GEN_LOAD_FREG_FTN(WT0
, rt
);
4520 GEN_LOAD_FREG_FTN(WTH0
, rt
);
4525 /* XXX: For now we support only a single FPU context. */
4528 /* COP2: Not implemented. */
4535 #if defined MIPS_DEBUG_DISAS
4536 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4537 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4544 #if defined MIPS_DEBUG_DISAS
4545 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4546 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4550 generate_exception(ctx
, EXCP_RI
);
4553 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
4554 int u
, int sel
, int h
)
4556 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4558 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4559 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4560 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4562 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4563 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4570 gen_op_mttc0_tcstatus();
4573 gen_op_mttc0_tcbind();
4576 gen_op_mttc0_tcrestart();
4579 gen_op_mttc0_tchalt();
4582 gen_op_mttc0_tccontext();
4585 gen_op_mttc0_tcschedule();
4588 gen_op_mttc0_tcschefback();
4591 gen_mtc0(env
, ctx
, rd
, sel
);
4598 gen_op_mttc0_entryhi();
4601 gen_mtc0(env
, ctx
, rd
, sel
);
4607 gen_op_mttc0_status();
4610 gen_mtc0(env
, ctx
, rd
, sel
);
4616 gen_op_mttc0_debug();
4619 gen_mtc0(env
, ctx
, rd
, sel
);
4624 gen_mtc0(env
, ctx
, rd
, sel
);
4626 } else switch (sel
) {
4627 /* GPR registers. */
4631 /* Auxiliary CPU registers */
4677 /* Floating point (COP1). */
4679 /* XXX: For now we support only a single FPU context. */
4682 GEN_STORE_FTN_FREG(rd
, WT0
);
4685 GEN_STORE_FTN_FREG(rd
, WTH0
);
4689 /* XXX: For now we support only a single FPU context. */
4692 /* COP2: Not implemented. */
4699 #if defined MIPS_DEBUG_DISAS
4700 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4701 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4708 #if defined MIPS_DEBUG_DISAS
4709 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4710 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4714 generate_exception(ctx
, EXCP_RI
);
4717 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4719 const char *opn
= "ldst";
4727 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4728 gen_op_store_T0_gpr(rt
);
4732 GEN_LOAD_REG_T0(rt
);
4733 save_cpu_state(ctx
, 1);
4734 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4737 #if defined(TARGET_MIPS64)
4739 check_insn(env
, ctx
, ISA_MIPS3
);
4744 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4745 gen_op_store_T0_gpr(rt
);
4749 check_insn(env
, ctx
, ISA_MIPS3
);
4750 GEN_LOAD_REG_T0(rt
);
4751 save_cpu_state(ctx
, 1);
4752 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4757 check_insn(env
, ctx
, ASE_MT
);
4762 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
4763 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4764 gen_op_store_T0_gpr(rd
);
4768 check_insn(env
, ctx
, ASE_MT
);
4769 GEN_LOAD_REG_T0(rt
);
4770 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
4771 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4776 if (!env
->tlb
->do_tlbwi
)
4782 if (!env
->tlb
->do_tlbwr
)
4788 if (!env
->tlb
->do_tlbp
)
4794 if (!env
->tlb
->do_tlbr
)
4800 check_insn(env
, ctx
, ISA_MIPS2
);
4801 save_cpu_state(ctx
, 1);
4803 ctx
->bstate
= BS_EXCP
;
4807 check_insn(env
, ctx
, ISA_MIPS32
);
4808 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4810 generate_exception(ctx
, EXCP_RI
);
4812 save_cpu_state(ctx
, 1);
4814 ctx
->bstate
= BS_EXCP
;
4819 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
4820 /* If we get an exception, we want to restart at next instruction */
4822 save_cpu_state(ctx
, 1);
4825 ctx
->bstate
= BS_EXCP
;
4830 generate_exception(ctx
, EXCP_RI
);
4833 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4836 /* CP1 Branches (before delay slot) */
4837 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
4838 int32_t cc
, int32_t offset
)
4840 target_ulong btarget
;
4841 const char *opn
= "cp1 cond branch";
4844 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
4846 btarget
= ctx
->pc
+ 4 + offset
;
4865 ctx
->hflags
|= MIPS_HFLAG_BL
;
4867 gen_op_save_bcond();
4870 gen_op_bc1any2f(cc
);
4874 gen_op_bc1any2t(cc
);
4878 gen_op_bc1any4f(cc
);
4882 gen_op_bc1any4t(cc
);
4885 ctx
->hflags
|= MIPS_HFLAG_BC
;
4890 generate_exception (ctx
, EXCP_RI
);
4893 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4894 ctx
->hflags
, btarget
);
4895 ctx
->btarget
= btarget
;
4898 /* Coprocessor 1 (FPU) */
4900 #define FOP(func, fmt) (((fmt) << 21) | (func))
4902 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4904 const char *opn
= "cp1 move";
4908 GEN_LOAD_FREG_FTN(WT0
, fs
);
4910 GEN_STORE_T0_REG(rt
);
4914 GEN_LOAD_REG_T0(rt
);
4916 GEN_STORE_FTN_FREG(fs
, WT0
);
4921 GEN_STORE_T0_REG(rt
);
4925 GEN_LOAD_REG_T0(rt
);
4930 GEN_LOAD_FREG_FTN(DT0
, fs
);
4932 GEN_STORE_T0_REG(rt
);
4936 GEN_LOAD_REG_T0(rt
);
4938 GEN_STORE_FTN_FREG(fs
, DT0
);
4942 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4944 GEN_STORE_T0_REG(rt
);
4948 GEN_LOAD_REG_T0(rt
);
4950 GEN_STORE_FTN_FREG(fs
, WTH0
);
4955 generate_exception (ctx
, EXCP_RI
);
4958 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4961 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4965 GEN_LOAD_REG_T0(rd
);
4966 GEN_LOAD_REG_T1(rs
);
4968 ccbit
= 1 << (24 + cc
);
4975 GEN_STORE_T0_REG(rd
);
4978 #define GEN_MOVCF(fmt) \
4979 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4984 ccbit = 1 << (24 + cc); \
4988 glue(gen_op_float_movf_, fmt)(ccbit); \
4990 glue(gen_op_float_movt_, fmt)(ccbit); \
4997 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4998 int ft
, int fs
, int fd
, int cc
)
5000 const char *opn
= "farith";
5001 const char *condnames
[] = {
5019 const char *condnames_abs
[] = {
5037 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5038 uint32_t func
= ctx
->opcode
& 0x3f;
5040 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5042 GEN_LOAD_FREG_FTN(WT0
, fs
);
5043 GEN_LOAD_FREG_FTN(WT1
, ft
);
5044 gen_op_float_add_s();
5045 GEN_STORE_FTN_FREG(fd
, WT2
);
5050 GEN_LOAD_FREG_FTN(WT0
, fs
);
5051 GEN_LOAD_FREG_FTN(WT1
, ft
);
5052 gen_op_float_sub_s();
5053 GEN_STORE_FTN_FREG(fd
, WT2
);
5058 GEN_LOAD_FREG_FTN(WT0
, fs
);
5059 GEN_LOAD_FREG_FTN(WT1
, ft
);
5060 gen_op_float_mul_s();
5061 GEN_STORE_FTN_FREG(fd
, WT2
);
5066 GEN_LOAD_FREG_FTN(WT0
, fs
);
5067 GEN_LOAD_FREG_FTN(WT1
, ft
);
5068 gen_op_float_div_s();
5069 GEN_STORE_FTN_FREG(fd
, WT2
);
5074 GEN_LOAD_FREG_FTN(WT0
, fs
);
5075 gen_op_float_sqrt_s();
5076 GEN_STORE_FTN_FREG(fd
, WT2
);
5080 GEN_LOAD_FREG_FTN(WT0
, fs
);
5081 gen_op_float_abs_s();
5082 GEN_STORE_FTN_FREG(fd
, WT2
);
5086 GEN_LOAD_FREG_FTN(WT0
, fs
);
5087 gen_op_float_mov_s();
5088 GEN_STORE_FTN_FREG(fd
, WT2
);
5092 GEN_LOAD_FREG_FTN(WT0
, fs
);
5093 gen_op_float_chs_s();
5094 GEN_STORE_FTN_FREG(fd
, WT2
);
5098 check_cp1_64bitmode(ctx
);
5099 GEN_LOAD_FREG_FTN(WT0
, fs
);
5100 gen_op_float_roundl_s();
5101 GEN_STORE_FTN_FREG(fd
, DT2
);
5105 check_cp1_64bitmode(ctx
);
5106 GEN_LOAD_FREG_FTN(WT0
, fs
);
5107 gen_op_float_truncl_s();
5108 GEN_STORE_FTN_FREG(fd
, DT2
);
5112 check_cp1_64bitmode(ctx
);
5113 GEN_LOAD_FREG_FTN(WT0
, fs
);
5114 gen_op_float_ceill_s();
5115 GEN_STORE_FTN_FREG(fd
, DT2
);
5119 check_cp1_64bitmode(ctx
);
5120 GEN_LOAD_FREG_FTN(WT0
, fs
);
5121 gen_op_float_floorl_s();
5122 GEN_STORE_FTN_FREG(fd
, DT2
);
5126 GEN_LOAD_FREG_FTN(WT0
, fs
);
5127 gen_op_float_roundw_s();
5128 GEN_STORE_FTN_FREG(fd
, WT2
);
5132 GEN_LOAD_FREG_FTN(WT0
, fs
);
5133 gen_op_float_truncw_s();
5134 GEN_STORE_FTN_FREG(fd
, WT2
);
5138 GEN_LOAD_FREG_FTN(WT0
, fs
);
5139 gen_op_float_ceilw_s();
5140 GEN_STORE_FTN_FREG(fd
, WT2
);
5144 GEN_LOAD_FREG_FTN(WT0
, fs
);
5145 gen_op_float_floorw_s();
5146 GEN_STORE_FTN_FREG(fd
, WT2
);
5150 GEN_LOAD_REG_T0(ft
);
5151 GEN_LOAD_FREG_FTN(WT0
, fs
);
5152 GEN_LOAD_FREG_FTN(WT2
, fd
);
5153 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5154 GEN_STORE_FTN_FREG(fd
, WT2
);
5158 GEN_LOAD_REG_T0(ft
);
5159 GEN_LOAD_FREG_FTN(WT0
, fs
);
5160 GEN_LOAD_FREG_FTN(WT2
, fd
);
5161 gen_op_float_movz_s();
5162 GEN_STORE_FTN_FREG(fd
, WT2
);
5166 GEN_LOAD_REG_T0(ft
);
5167 GEN_LOAD_FREG_FTN(WT0
, fs
);
5168 GEN_LOAD_FREG_FTN(WT2
, fd
);
5169 gen_op_float_movn_s();
5170 GEN_STORE_FTN_FREG(fd
, WT2
);
5175 GEN_LOAD_FREG_FTN(WT0
, fs
);
5176 gen_op_float_recip_s();
5177 GEN_STORE_FTN_FREG(fd
, WT2
);
5182 GEN_LOAD_FREG_FTN(WT0
, fs
);
5183 gen_op_float_rsqrt_s();
5184 GEN_STORE_FTN_FREG(fd
, WT2
);
5188 check_cp1_64bitmode(ctx
);
5189 GEN_LOAD_FREG_FTN(WT0
, fs
);
5190 GEN_LOAD_FREG_FTN(WT2
, fd
);
5191 gen_op_float_recip2_s();
5192 GEN_STORE_FTN_FREG(fd
, WT2
);
5196 check_cp1_64bitmode(ctx
);
5197 GEN_LOAD_FREG_FTN(WT0
, fs
);
5198 gen_op_float_recip1_s();
5199 GEN_STORE_FTN_FREG(fd
, WT2
);
5203 check_cp1_64bitmode(ctx
);
5204 GEN_LOAD_FREG_FTN(WT0
, fs
);
5205 gen_op_float_rsqrt1_s();
5206 GEN_STORE_FTN_FREG(fd
, WT2
);
5210 check_cp1_64bitmode(ctx
);
5211 GEN_LOAD_FREG_FTN(WT0
, fs
);
5212 GEN_LOAD_FREG_FTN(WT2
, ft
);
5213 gen_op_float_rsqrt2_s();
5214 GEN_STORE_FTN_FREG(fd
, WT2
);
5218 check_cp1_registers(ctx
, fd
);
5219 GEN_LOAD_FREG_FTN(WT0
, fs
);
5220 gen_op_float_cvtd_s();
5221 GEN_STORE_FTN_FREG(fd
, DT2
);
5225 GEN_LOAD_FREG_FTN(WT0
, fs
);
5226 gen_op_float_cvtw_s();
5227 GEN_STORE_FTN_FREG(fd
, WT2
);
5231 check_cp1_64bitmode(ctx
);
5232 GEN_LOAD_FREG_FTN(WT0
, fs
);
5233 gen_op_float_cvtl_s();
5234 GEN_STORE_FTN_FREG(fd
, DT2
);
5238 check_cp1_64bitmode(ctx
);
5239 GEN_LOAD_FREG_FTN(WT1
, fs
);
5240 GEN_LOAD_FREG_FTN(WT0
, ft
);
5241 gen_op_float_cvtps_s();
5242 GEN_STORE_FTN_FREG(fd
, DT2
);
5261 GEN_LOAD_FREG_FTN(WT0
, fs
);
5262 GEN_LOAD_FREG_FTN(WT1
, ft
);
5263 if (ctx
->opcode
& (1 << 6)) {
5265 gen_cmpabs_s(func
-48, cc
);
5266 opn
= condnames_abs
[func
-48];
5268 gen_cmp_s(func
-48, cc
);
5269 opn
= condnames
[func
-48];
5273 check_cp1_registers(ctx
, fs
| ft
| fd
);
5274 GEN_LOAD_FREG_FTN(DT0
, fs
);
5275 GEN_LOAD_FREG_FTN(DT1
, ft
);
5276 gen_op_float_add_d();
5277 GEN_STORE_FTN_FREG(fd
, DT2
);
5282 check_cp1_registers(ctx
, fs
| ft
| fd
);
5283 GEN_LOAD_FREG_FTN(DT0
, fs
);
5284 GEN_LOAD_FREG_FTN(DT1
, ft
);
5285 gen_op_float_sub_d();
5286 GEN_STORE_FTN_FREG(fd
, DT2
);
5291 check_cp1_registers(ctx
, fs
| ft
| fd
);
5292 GEN_LOAD_FREG_FTN(DT0
, fs
);
5293 GEN_LOAD_FREG_FTN(DT1
, ft
);
5294 gen_op_float_mul_d();
5295 GEN_STORE_FTN_FREG(fd
, DT2
);
5300 check_cp1_registers(ctx
, fs
| ft
| fd
);
5301 GEN_LOAD_FREG_FTN(DT0
, fs
);
5302 GEN_LOAD_FREG_FTN(DT1
, ft
);
5303 gen_op_float_div_d();
5304 GEN_STORE_FTN_FREG(fd
, DT2
);
5309 check_cp1_registers(ctx
, fs
| fd
);
5310 GEN_LOAD_FREG_FTN(DT0
, fs
);
5311 gen_op_float_sqrt_d();
5312 GEN_STORE_FTN_FREG(fd
, DT2
);
5316 check_cp1_registers(ctx
, fs
| fd
);
5317 GEN_LOAD_FREG_FTN(DT0
, fs
);
5318 gen_op_float_abs_d();
5319 GEN_STORE_FTN_FREG(fd
, DT2
);
5323 check_cp1_registers(ctx
, fs
| fd
);
5324 GEN_LOAD_FREG_FTN(DT0
, fs
);
5325 gen_op_float_mov_d();
5326 GEN_STORE_FTN_FREG(fd
, DT2
);
5330 check_cp1_registers(ctx
, fs
| fd
);
5331 GEN_LOAD_FREG_FTN(DT0
, fs
);
5332 gen_op_float_chs_d();
5333 GEN_STORE_FTN_FREG(fd
, DT2
);
5337 check_cp1_64bitmode(ctx
);
5338 GEN_LOAD_FREG_FTN(DT0
, fs
);
5339 gen_op_float_roundl_d();
5340 GEN_STORE_FTN_FREG(fd
, DT2
);
5344 check_cp1_64bitmode(ctx
);
5345 GEN_LOAD_FREG_FTN(DT0
, fs
);
5346 gen_op_float_truncl_d();
5347 GEN_STORE_FTN_FREG(fd
, DT2
);
5351 check_cp1_64bitmode(ctx
);
5352 GEN_LOAD_FREG_FTN(DT0
, fs
);
5353 gen_op_float_ceill_d();
5354 GEN_STORE_FTN_FREG(fd
, DT2
);
5358 check_cp1_64bitmode(ctx
);
5359 GEN_LOAD_FREG_FTN(DT0
, fs
);
5360 gen_op_float_floorl_d();
5361 GEN_STORE_FTN_FREG(fd
, DT2
);
5365 check_cp1_registers(ctx
, fs
);
5366 GEN_LOAD_FREG_FTN(DT0
, fs
);
5367 gen_op_float_roundw_d();
5368 GEN_STORE_FTN_FREG(fd
, WT2
);
5372 check_cp1_registers(ctx
, fs
);
5373 GEN_LOAD_FREG_FTN(DT0
, fs
);
5374 gen_op_float_truncw_d();
5375 GEN_STORE_FTN_FREG(fd
, WT2
);
5379 check_cp1_registers(ctx
, fs
);
5380 GEN_LOAD_FREG_FTN(DT0
, fs
);
5381 gen_op_float_ceilw_d();
5382 GEN_STORE_FTN_FREG(fd
, WT2
);
5386 check_cp1_registers(ctx
, fs
);
5387 GEN_LOAD_FREG_FTN(DT0
, fs
);
5388 gen_op_float_floorw_d();
5389 GEN_STORE_FTN_FREG(fd
, WT2
);
5393 GEN_LOAD_REG_T0(ft
);
5394 GEN_LOAD_FREG_FTN(DT0
, fs
);
5395 GEN_LOAD_FREG_FTN(DT2
, fd
);
5396 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5397 GEN_STORE_FTN_FREG(fd
, DT2
);
5401 GEN_LOAD_REG_T0(ft
);
5402 GEN_LOAD_FREG_FTN(DT0
, fs
);
5403 GEN_LOAD_FREG_FTN(DT2
, fd
);
5404 gen_op_float_movz_d();
5405 GEN_STORE_FTN_FREG(fd
, DT2
);
5409 GEN_LOAD_REG_T0(ft
);
5410 GEN_LOAD_FREG_FTN(DT0
, fs
);
5411 GEN_LOAD_FREG_FTN(DT2
, fd
);
5412 gen_op_float_movn_d();
5413 GEN_STORE_FTN_FREG(fd
, DT2
);
5417 check_cp1_64bitmode(ctx
);
5418 GEN_LOAD_FREG_FTN(DT0
, fs
);
5419 gen_op_float_recip_d();
5420 GEN_STORE_FTN_FREG(fd
, DT2
);
5424 check_cp1_64bitmode(ctx
);
5425 GEN_LOAD_FREG_FTN(DT0
, fs
);
5426 gen_op_float_rsqrt_d();
5427 GEN_STORE_FTN_FREG(fd
, DT2
);
5431 check_cp1_64bitmode(ctx
);
5432 GEN_LOAD_FREG_FTN(DT0
, fs
);
5433 GEN_LOAD_FREG_FTN(DT2
, ft
);
5434 gen_op_float_recip2_d();
5435 GEN_STORE_FTN_FREG(fd
, DT2
);
5439 check_cp1_64bitmode(ctx
);
5440 GEN_LOAD_FREG_FTN(DT0
, fs
);
5441 gen_op_float_recip1_d();
5442 GEN_STORE_FTN_FREG(fd
, DT2
);
5446 check_cp1_64bitmode(ctx
);
5447 GEN_LOAD_FREG_FTN(DT0
, fs
);
5448 gen_op_float_rsqrt1_d();
5449 GEN_STORE_FTN_FREG(fd
, DT2
);
5453 check_cp1_64bitmode(ctx
);
5454 GEN_LOAD_FREG_FTN(DT0
, fs
);
5455 GEN_LOAD_FREG_FTN(DT2
, ft
);
5456 gen_op_float_rsqrt2_d();
5457 GEN_STORE_FTN_FREG(fd
, DT2
);
5476 GEN_LOAD_FREG_FTN(DT0
, fs
);
5477 GEN_LOAD_FREG_FTN(DT1
, ft
);
5478 if (ctx
->opcode
& (1 << 6)) {
5480 check_cp1_registers(ctx
, fs
| ft
);
5481 gen_cmpabs_d(func
-48, cc
);
5482 opn
= condnames_abs
[func
-48];
5484 check_cp1_registers(ctx
, fs
| ft
);
5485 gen_cmp_d(func
-48, cc
);
5486 opn
= condnames
[func
-48];
5490 check_cp1_registers(ctx
, fs
);
5491 GEN_LOAD_FREG_FTN(DT0
, fs
);
5492 gen_op_float_cvts_d();
5493 GEN_STORE_FTN_FREG(fd
, WT2
);
5497 check_cp1_registers(ctx
, fs
);
5498 GEN_LOAD_FREG_FTN(DT0
, fs
);
5499 gen_op_float_cvtw_d();
5500 GEN_STORE_FTN_FREG(fd
, WT2
);
5504 check_cp1_64bitmode(ctx
);
5505 GEN_LOAD_FREG_FTN(DT0
, fs
);
5506 gen_op_float_cvtl_d();
5507 GEN_STORE_FTN_FREG(fd
, DT2
);
5511 GEN_LOAD_FREG_FTN(WT0
, fs
);
5512 gen_op_float_cvts_w();
5513 GEN_STORE_FTN_FREG(fd
, WT2
);
5517 check_cp1_registers(ctx
, fd
);
5518 GEN_LOAD_FREG_FTN(WT0
, fs
);
5519 gen_op_float_cvtd_w();
5520 GEN_STORE_FTN_FREG(fd
, DT2
);
5524 check_cp1_64bitmode(ctx
);
5525 GEN_LOAD_FREG_FTN(DT0
, fs
);
5526 gen_op_float_cvts_l();
5527 GEN_STORE_FTN_FREG(fd
, WT2
);
5531 check_cp1_64bitmode(ctx
);
5532 GEN_LOAD_FREG_FTN(DT0
, fs
);
5533 gen_op_float_cvtd_l();
5534 GEN_STORE_FTN_FREG(fd
, DT2
);
5538 check_cp1_64bitmode(ctx
);
5539 GEN_LOAD_FREG_FTN(WT0
, fs
);
5540 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5541 gen_op_float_cvtps_pw();
5542 GEN_STORE_FTN_FREG(fd
, WT2
);
5543 GEN_STORE_FTN_FREG(fd
, WTH2
);
5547 check_cp1_64bitmode(ctx
);
5548 GEN_LOAD_FREG_FTN(WT0
, fs
);
5549 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5550 GEN_LOAD_FREG_FTN(WT1
, ft
);
5551 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5552 gen_op_float_add_ps();
5553 GEN_STORE_FTN_FREG(fd
, WT2
);
5554 GEN_STORE_FTN_FREG(fd
, WTH2
);
5558 check_cp1_64bitmode(ctx
);
5559 GEN_LOAD_FREG_FTN(WT0
, fs
);
5560 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5561 GEN_LOAD_FREG_FTN(WT1
, ft
);
5562 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5563 gen_op_float_sub_ps();
5564 GEN_STORE_FTN_FREG(fd
, WT2
);
5565 GEN_STORE_FTN_FREG(fd
, WTH2
);
5569 check_cp1_64bitmode(ctx
);
5570 GEN_LOAD_FREG_FTN(WT0
, fs
);
5571 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5572 GEN_LOAD_FREG_FTN(WT1
, ft
);
5573 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5574 gen_op_float_mul_ps();
5575 GEN_STORE_FTN_FREG(fd
, WT2
);
5576 GEN_STORE_FTN_FREG(fd
, WTH2
);
5580 check_cp1_64bitmode(ctx
);
5581 GEN_LOAD_FREG_FTN(WT0
, fs
);
5582 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5583 gen_op_float_abs_ps();
5584 GEN_STORE_FTN_FREG(fd
, WT2
);
5585 GEN_STORE_FTN_FREG(fd
, WTH2
);
5589 check_cp1_64bitmode(ctx
);
5590 GEN_LOAD_FREG_FTN(WT0
, fs
);
5591 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5592 gen_op_float_mov_ps();
5593 GEN_STORE_FTN_FREG(fd
, WT2
);
5594 GEN_STORE_FTN_FREG(fd
, WTH2
);
5598 check_cp1_64bitmode(ctx
);
5599 GEN_LOAD_FREG_FTN(WT0
, fs
);
5600 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5601 gen_op_float_chs_ps();
5602 GEN_STORE_FTN_FREG(fd
, WT2
);
5603 GEN_STORE_FTN_FREG(fd
, WTH2
);
5607 check_cp1_64bitmode(ctx
);
5608 GEN_LOAD_REG_T0(ft
);
5609 GEN_LOAD_FREG_FTN(WT0
, fs
);
5610 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5611 GEN_LOAD_FREG_FTN(WT2
, fd
);
5612 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5613 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5614 GEN_STORE_FTN_FREG(fd
, WT2
);
5615 GEN_STORE_FTN_FREG(fd
, WTH2
);
5619 check_cp1_64bitmode(ctx
);
5620 GEN_LOAD_REG_T0(ft
);
5621 GEN_LOAD_FREG_FTN(WT0
, fs
);
5622 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5623 GEN_LOAD_FREG_FTN(WT2
, fd
);
5624 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5625 gen_op_float_movz_ps();
5626 GEN_STORE_FTN_FREG(fd
, WT2
);
5627 GEN_STORE_FTN_FREG(fd
, WTH2
);
5631 check_cp1_64bitmode(ctx
);
5632 GEN_LOAD_REG_T0(ft
);
5633 GEN_LOAD_FREG_FTN(WT0
, fs
);
5634 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5635 GEN_LOAD_FREG_FTN(WT2
, fd
);
5636 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5637 gen_op_float_movn_ps();
5638 GEN_STORE_FTN_FREG(fd
, WT2
);
5639 GEN_STORE_FTN_FREG(fd
, WTH2
);
5643 check_cp1_64bitmode(ctx
);
5644 GEN_LOAD_FREG_FTN(WT0
, ft
);
5645 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5646 GEN_LOAD_FREG_FTN(WT1
, fs
);
5647 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5648 gen_op_float_addr_ps();
5649 GEN_STORE_FTN_FREG(fd
, WT2
);
5650 GEN_STORE_FTN_FREG(fd
, WTH2
);
5654 check_cp1_64bitmode(ctx
);
5655 GEN_LOAD_FREG_FTN(WT0
, ft
);
5656 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5657 GEN_LOAD_FREG_FTN(WT1
, fs
);
5658 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5659 gen_op_float_mulr_ps();
5660 GEN_STORE_FTN_FREG(fd
, WT2
);
5661 GEN_STORE_FTN_FREG(fd
, WTH2
);
5665 check_cp1_64bitmode(ctx
);
5666 GEN_LOAD_FREG_FTN(WT0
, fs
);
5667 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5668 GEN_LOAD_FREG_FTN(WT2
, fd
);
5669 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5670 gen_op_float_recip2_ps();
5671 GEN_STORE_FTN_FREG(fd
, WT2
);
5672 GEN_STORE_FTN_FREG(fd
, WTH2
);
5676 check_cp1_64bitmode(ctx
);
5677 GEN_LOAD_FREG_FTN(WT0
, fs
);
5678 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5679 gen_op_float_recip1_ps();
5680 GEN_STORE_FTN_FREG(fd
, WT2
);
5681 GEN_STORE_FTN_FREG(fd
, WTH2
);
5685 check_cp1_64bitmode(ctx
);
5686 GEN_LOAD_FREG_FTN(WT0
, fs
);
5687 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5688 gen_op_float_rsqrt1_ps();
5689 GEN_STORE_FTN_FREG(fd
, WT2
);
5690 GEN_STORE_FTN_FREG(fd
, WTH2
);
5694 check_cp1_64bitmode(ctx
);
5695 GEN_LOAD_FREG_FTN(WT0
, fs
);
5696 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5697 GEN_LOAD_FREG_FTN(WT2
, ft
);
5698 GEN_LOAD_FREG_FTN(WTH2
, ft
);
5699 gen_op_float_rsqrt2_ps();
5700 GEN_STORE_FTN_FREG(fd
, WT2
);
5701 GEN_STORE_FTN_FREG(fd
, WTH2
);
5705 check_cp1_64bitmode(ctx
);
5706 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5707 gen_op_float_cvts_pu();
5708 GEN_STORE_FTN_FREG(fd
, WT2
);
5712 check_cp1_64bitmode(ctx
);
5713 GEN_LOAD_FREG_FTN(WT0
, fs
);
5714 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5715 gen_op_float_cvtpw_ps();
5716 GEN_STORE_FTN_FREG(fd
, WT2
);
5717 GEN_STORE_FTN_FREG(fd
, WTH2
);
5721 check_cp1_64bitmode(ctx
);
5722 GEN_LOAD_FREG_FTN(WT0
, fs
);
5723 gen_op_float_cvts_pl();
5724 GEN_STORE_FTN_FREG(fd
, WT2
);
5728 check_cp1_64bitmode(ctx
);
5729 GEN_LOAD_FREG_FTN(WT0
, fs
);
5730 GEN_LOAD_FREG_FTN(WT1
, ft
);
5731 gen_op_float_pll_ps();
5732 GEN_STORE_FTN_FREG(fd
, DT2
);
5736 check_cp1_64bitmode(ctx
);
5737 GEN_LOAD_FREG_FTN(WT0
, fs
);
5738 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5739 gen_op_float_plu_ps();
5740 GEN_STORE_FTN_FREG(fd
, DT2
);
5744 check_cp1_64bitmode(ctx
);
5745 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5746 GEN_LOAD_FREG_FTN(WT1
, ft
);
5747 gen_op_float_pul_ps();
5748 GEN_STORE_FTN_FREG(fd
, DT2
);
5752 check_cp1_64bitmode(ctx
);
5753 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5754 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5755 gen_op_float_puu_ps();
5756 GEN_STORE_FTN_FREG(fd
, DT2
);
5775 check_cp1_64bitmode(ctx
);
5776 GEN_LOAD_FREG_FTN(WT0
, fs
);
5777 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5778 GEN_LOAD_FREG_FTN(WT1
, ft
);
5779 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5780 if (ctx
->opcode
& (1 << 6)) {
5781 gen_cmpabs_ps(func
-48, cc
);
5782 opn
= condnames_abs
[func
-48];
5784 gen_cmp_ps(func
-48, cc
);
5785 opn
= condnames
[func
-48];
5790 generate_exception (ctx
, EXCP_RI
);
5795 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5798 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5801 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5806 /* Coprocessor 3 (FPU) */
5807 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5808 int fd
, int fs
, int base
, int index
)
5810 const char *opn
= "extended float load/store";
5817 GEN_LOAD_REG_T0(index
);
5818 } else if (index
== 0) {
5819 GEN_LOAD_REG_T0(base
);
5821 GEN_LOAD_REG_T0(base
);
5822 GEN_LOAD_REG_T1(index
);
5825 /* Don't do NOP if destination is zero: we must perform the actual
5831 GEN_STORE_FTN_FREG(fd
, WT0
);
5836 check_cp1_registers(ctx
, fd
);
5838 GEN_STORE_FTN_FREG(fd
, DT0
);
5842 check_cp1_64bitmode(ctx
);
5844 GEN_STORE_FTN_FREG(fd
, DT0
);
5849 GEN_LOAD_FREG_FTN(WT0
, fs
);
5856 check_cp1_registers(ctx
, fs
);
5857 GEN_LOAD_FREG_FTN(DT0
, fs
);
5863 check_cp1_64bitmode(ctx
);
5864 GEN_LOAD_FREG_FTN(DT0
, fs
);
5871 generate_exception(ctx
, EXCP_RI
);
5874 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5875 regnames
[index
], regnames
[base
]);
5878 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5879 int fd
, int fr
, int fs
, int ft
)
5881 const char *opn
= "flt3_arith";
5885 check_cp1_64bitmode(ctx
);
5886 GEN_LOAD_REG_T0(fr
);
5887 GEN_LOAD_FREG_FTN(DT0
, fs
);
5888 GEN_LOAD_FREG_FTN(DT1
, ft
);
5889 gen_op_float_alnv_ps();
5890 GEN_STORE_FTN_FREG(fd
, DT2
);
5895 GEN_LOAD_FREG_FTN(WT0
, fs
);
5896 GEN_LOAD_FREG_FTN(WT1
, ft
);
5897 GEN_LOAD_FREG_FTN(WT2
, fr
);
5898 gen_op_float_muladd_s();
5899 GEN_STORE_FTN_FREG(fd
, WT2
);
5904 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5905 GEN_LOAD_FREG_FTN(DT0
, fs
);
5906 GEN_LOAD_FREG_FTN(DT1
, ft
);
5907 GEN_LOAD_FREG_FTN(DT2
, fr
);
5908 gen_op_float_muladd_d();
5909 GEN_STORE_FTN_FREG(fd
, DT2
);
5913 check_cp1_64bitmode(ctx
);
5914 GEN_LOAD_FREG_FTN(WT0
, fs
);
5915 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5916 GEN_LOAD_FREG_FTN(WT1
, ft
);
5917 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5918 GEN_LOAD_FREG_FTN(WT2
, fr
);
5919 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5920 gen_op_float_muladd_ps();
5921 GEN_STORE_FTN_FREG(fd
, WT2
);
5922 GEN_STORE_FTN_FREG(fd
, WTH2
);
5927 GEN_LOAD_FREG_FTN(WT0
, fs
);
5928 GEN_LOAD_FREG_FTN(WT1
, ft
);
5929 GEN_LOAD_FREG_FTN(WT2
, fr
);
5930 gen_op_float_mulsub_s();
5931 GEN_STORE_FTN_FREG(fd
, WT2
);
5936 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5937 GEN_LOAD_FREG_FTN(DT0
, fs
);
5938 GEN_LOAD_FREG_FTN(DT1
, ft
);
5939 GEN_LOAD_FREG_FTN(DT2
, fr
);
5940 gen_op_float_mulsub_d();
5941 GEN_STORE_FTN_FREG(fd
, DT2
);
5945 check_cp1_64bitmode(ctx
);
5946 GEN_LOAD_FREG_FTN(WT0
, fs
);
5947 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5948 GEN_LOAD_FREG_FTN(WT1
, ft
);
5949 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5950 GEN_LOAD_FREG_FTN(WT2
, fr
);
5951 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5952 gen_op_float_mulsub_ps();
5953 GEN_STORE_FTN_FREG(fd
, WT2
);
5954 GEN_STORE_FTN_FREG(fd
, WTH2
);
5959 GEN_LOAD_FREG_FTN(WT0
, fs
);
5960 GEN_LOAD_FREG_FTN(WT1
, ft
);
5961 GEN_LOAD_FREG_FTN(WT2
, fr
);
5962 gen_op_float_nmuladd_s();
5963 GEN_STORE_FTN_FREG(fd
, WT2
);
5968 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5969 GEN_LOAD_FREG_FTN(DT0
, fs
);
5970 GEN_LOAD_FREG_FTN(DT1
, ft
);
5971 GEN_LOAD_FREG_FTN(DT2
, fr
);
5972 gen_op_float_nmuladd_d();
5973 GEN_STORE_FTN_FREG(fd
, DT2
);
5977 check_cp1_64bitmode(ctx
);
5978 GEN_LOAD_FREG_FTN(WT0
, fs
);
5979 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5980 GEN_LOAD_FREG_FTN(WT1
, ft
);
5981 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5982 GEN_LOAD_FREG_FTN(WT2
, fr
);
5983 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5984 gen_op_float_nmuladd_ps();
5985 GEN_STORE_FTN_FREG(fd
, WT2
);
5986 GEN_STORE_FTN_FREG(fd
, WTH2
);
5991 GEN_LOAD_FREG_FTN(WT0
, fs
);
5992 GEN_LOAD_FREG_FTN(WT1
, ft
);
5993 GEN_LOAD_FREG_FTN(WT2
, fr
);
5994 gen_op_float_nmulsub_s();
5995 GEN_STORE_FTN_FREG(fd
, WT2
);
6000 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6001 GEN_LOAD_FREG_FTN(DT0
, fs
);
6002 GEN_LOAD_FREG_FTN(DT1
, ft
);
6003 GEN_LOAD_FREG_FTN(DT2
, fr
);
6004 gen_op_float_nmulsub_d();
6005 GEN_STORE_FTN_FREG(fd
, DT2
);
6009 check_cp1_64bitmode(ctx
);
6010 GEN_LOAD_FREG_FTN(WT0
, fs
);
6011 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6012 GEN_LOAD_FREG_FTN(WT1
, ft
);
6013 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6014 GEN_LOAD_FREG_FTN(WT2
, fr
);
6015 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6016 gen_op_float_nmulsub_ps();
6017 GEN_STORE_FTN_FREG(fd
, WT2
);
6018 GEN_STORE_FTN_FREG(fd
, WTH2
);
6023 generate_exception (ctx
, EXCP_RI
);
6026 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6027 fregnames
[fs
], fregnames
[ft
]);
6030 /* ISA extensions (ASEs) */
6031 /* MIPS16 extension to MIPS32 */
6032 /* SmartMIPS extension to MIPS32 */
6034 #if defined(TARGET_MIPS64)
6036 /* MDMX extension to MIPS64 */
6040 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6044 uint32_t op
, op1
, op2
;
6047 /* make sure instructions are on a word boundary */
6048 if (ctx
->pc
& 0x3) {
6049 env
->CP0_BadVAddr
= ctx
->pc
;
6050 generate_exception(ctx
, EXCP_AdEL
);
6054 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6056 /* Handle blikely not taken case */
6057 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6058 l1
= gen_new_label();
6060 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6061 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6064 op
= MASK_OP_MAJOR(ctx
->opcode
);
6065 rs
= (ctx
->opcode
>> 21) & 0x1f;
6066 rt
= (ctx
->opcode
>> 16) & 0x1f;
6067 rd
= (ctx
->opcode
>> 11) & 0x1f;
6068 sa
= (ctx
->opcode
>> 6) & 0x1f;
6069 imm
= (int16_t)ctx
->opcode
;
6072 op1
= MASK_SPECIAL(ctx
->opcode
);
6074 case OPC_SLL
: /* Arithmetic with immediate */
6075 case OPC_SRL
... OPC_SRA
:
6076 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6078 case OPC_MOVZ
... OPC_MOVN
:
6079 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6080 case OPC_SLLV
: /* Arithmetic */
6081 case OPC_SRLV
... OPC_SRAV
:
6082 case OPC_ADD
... OPC_NOR
:
6083 case OPC_SLT
... OPC_SLTU
:
6084 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6086 case OPC_MULT
... OPC_DIVU
:
6088 check_insn(env
, ctx
, INSN_VR54XX
);
6089 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6090 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6092 gen_muldiv(ctx
, op1
, rs
, rt
);
6094 case OPC_JR
... OPC_JALR
:
6095 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6097 case OPC_TGE
... OPC_TEQ
: /* Traps */
6099 gen_trap(ctx
, op1
, rs
, rt
, -1);
6101 case OPC_MFHI
: /* Move from HI/LO */
6103 gen_HILO(ctx
, op1
, rd
);
6106 case OPC_MTLO
: /* Move to HI/LO */
6107 gen_HILO(ctx
, op1
, rs
);
6109 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6110 #ifdef MIPS_STRICT_STANDARD
6111 MIPS_INVAL("PMON / selsl");
6112 generate_exception(ctx
, EXCP_RI
);
6118 generate_exception(ctx
, EXCP_SYSCALL
);
6121 generate_exception(ctx
, EXCP_BREAK
);
6124 #ifdef MIPS_STRICT_STANDARD
6126 generate_exception(ctx
, EXCP_RI
);
6128 /* Implemented as RI exception for now. */
6129 MIPS_INVAL("spim (unofficial)");
6130 generate_exception(ctx
, EXCP_RI
);
6138 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6139 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6140 save_cpu_state(ctx
, 1);
6141 check_cp1_enabled(ctx
);
6142 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6143 (ctx
->opcode
>> 16) & 1);
6145 generate_exception_err(ctx
, EXCP_CpU
, 1);
6149 #if defined(TARGET_MIPS64)
6150 /* MIPS64 specific opcodes */
6152 case OPC_DSRL
... OPC_DSRA
:
6154 case OPC_DSRL32
... OPC_DSRA32
:
6155 check_insn(env
, ctx
, ISA_MIPS3
);
6157 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6160 case OPC_DSRLV
... OPC_DSRAV
:
6161 case OPC_DADD
... OPC_DSUBU
:
6162 check_insn(env
, ctx
, ISA_MIPS3
);
6164 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6166 case OPC_DMULT
... OPC_DDIVU
:
6167 check_insn(env
, ctx
, ISA_MIPS3
);
6169 gen_muldiv(ctx
, op1
, rs
, rt
);
6172 default: /* Invalid */
6173 MIPS_INVAL("special");
6174 generate_exception(ctx
, EXCP_RI
);
6179 op1
= MASK_SPECIAL2(ctx
->opcode
);
6181 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6182 case OPC_MSUB
... OPC_MSUBU
:
6183 check_insn(env
, ctx
, ISA_MIPS32
);
6184 gen_muldiv(ctx
, op1
, rs
, rt
);
6187 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6189 case OPC_CLZ
... OPC_CLO
:
6190 check_insn(env
, ctx
, ISA_MIPS32
);
6191 gen_cl(ctx
, op1
, rd
, rs
);
6194 /* XXX: not clear which exception should be raised
6195 * when in debug mode...
6197 check_insn(env
, ctx
, ISA_MIPS32
);
6198 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6199 generate_exception(ctx
, EXCP_DBp
);
6201 generate_exception(ctx
, EXCP_DBp
);
6205 #if defined(TARGET_MIPS64)
6206 case OPC_DCLZ
... OPC_DCLO
:
6207 check_insn(env
, ctx
, ISA_MIPS64
);
6209 gen_cl(ctx
, op1
, rd
, rs
);
6212 default: /* Invalid */
6213 MIPS_INVAL("special2");
6214 generate_exception(ctx
, EXCP_RI
);
6219 op1
= MASK_SPECIAL3(ctx
->opcode
);
6223 check_insn(env
, ctx
, ISA_MIPS32R2
);
6224 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6227 check_insn(env
, ctx
, ISA_MIPS32R2
);
6228 op2
= MASK_BSHFL(ctx
->opcode
);
6231 GEN_LOAD_REG_T1(rt
);
6235 GEN_LOAD_REG_T1(rt
);
6239 GEN_LOAD_REG_T1(rt
);
6242 default: /* Invalid */
6243 MIPS_INVAL("bshfl");
6244 generate_exception(ctx
, EXCP_RI
);
6247 GEN_STORE_T0_REG(rd
);
6250 check_insn(env
, ctx
, ISA_MIPS32R2
);
6253 save_cpu_state(ctx
, 1);
6254 gen_op_rdhwr_cpunum();
6257 save_cpu_state(ctx
, 1);
6258 gen_op_rdhwr_synci_step();
6261 save_cpu_state(ctx
, 1);
6265 save_cpu_state(ctx
, 1);
6266 gen_op_rdhwr_ccres();
6269 #if defined (CONFIG_USER_ONLY)
6273 default: /* Invalid */
6274 MIPS_INVAL("rdhwr");
6275 generate_exception(ctx
, EXCP_RI
);
6278 GEN_STORE_T0_REG(rt
);
6281 check_insn(env
, ctx
, ASE_MT
);
6282 GEN_LOAD_REG_T0(rt
);
6283 GEN_LOAD_REG_T1(rs
);
6287 check_insn(env
, ctx
, ASE_MT
);
6288 GEN_LOAD_REG_T0(rs
);
6290 GEN_STORE_T0_REG(rd
);
6292 #if defined(TARGET_MIPS64)
6293 case OPC_DEXTM
... OPC_DEXT
:
6294 case OPC_DINSM
... OPC_DINS
:
6295 check_insn(env
, ctx
, ISA_MIPS64R2
);
6297 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6300 check_insn(env
, ctx
, ISA_MIPS64R2
);
6302 op2
= MASK_DBSHFL(ctx
->opcode
);
6305 GEN_LOAD_REG_T1(rt
);
6309 GEN_LOAD_REG_T1(rt
);
6312 default: /* Invalid */
6313 MIPS_INVAL("dbshfl");
6314 generate_exception(ctx
, EXCP_RI
);
6317 GEN_STORE_T0_REG(rd
);
6320 default: /* Invalid */
6321 MIPS_INVAL("special3");
6322 generate_exception(ctx
, EXCP_RI
);
6327 op1
= MASK_REGIMM(ctx
->opcode
);
6329 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6330 case OPC_BLTZAL
... OPC_BGEZALL
:
6331 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6333 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6335 gen_trap(ctx
, op1
, rs
, -1, imm
);
6338 check_insn(env
, ctx
, ISA_MIPS32R2
);
6341 default: /* Invalid */
6342 MIPS_INVAL("regimm");
6343 generate_exception(ctx
, EXCP_RI
);
6348 check_cp0_enabled(ctx
);
6349 op1
= MASK_CP0(ctx
->opcode
);
6355 #if defined(TARGET_MIPS64)
6359 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6361 case OPC_C0_FIRST
... OPC_C0_LAST
:
6362 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6365 op2
= MASK_MFMC0(ctx
->opcode
);
6368 check_insn(env
, ctx
, ASE_MT
);
6372 check_insn(env
, ctx
, ASE_MT
);
6376 check_insn(env
, ctx
, ASE_MT
);
6380 check_insn(env
, ctx
, ASE_MT
);
6384 check_insn(env
, ctx
, ISA_MIPS32R2
);
6385 save_cpu_state(ctx
, 1);
6387 /* Stop translation as we may have switched the execution mode */
6388 ctx
->bstate
= BS_STOP
;
6391 check_insn(env
, ctx
, ISA_MIPS32R2
);
6392 save_cpu_state(ctx
, 1);
6394 /* Stop translation as we may have switched the execution mode */
6395 ctx
->bstate
= BS_STOP
;
6397 default: /* Invalid */
6398 MIPS_INVAL("mfmc0");
6399 generate_exception(ctx
, EXCP_RI
);
6402 GEN_STORE_T0_REG(rt
);
6405 check_insn(env
, ctx
, ISA_MIPS32R2
);
6406 GEN_LOAD_SRSREG_TN(T0
, rt
);
6407 GEN_STORE_T0_REG(rd
);
6410 check_insn(env
, ctx
, ISA_MIPS32R2
);
6411 GEN_LOAD_REG_T0(rt
);
6412 GEN_STORE_TN_SRSREG(rd
, T0
);
6416 generate_exception(ctx
, EXCP_RI
);
6420 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6421 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6423 case OPC_J
... OPC_JAL
: /* Jump */
6424 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6425 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6427 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6428 case OPC_BEQL
... OPC_BGTZL
:
6429 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6431 case OPC_LB
... OPC_LWR
: /* Load and stores */
6432 case OPC_SB
... OPC_SW
:
6436 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6439 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6443 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6447 /* Floating point (COP1). */
6452 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6453 save_cpu_state(ctx
, 1);
6454 check_cp1_enabled(ctx
);
6455 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6457 generate_exception_err(ctx
, EXCP_CpU
, 1);
6462 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6463 save_cpu_state(ctx
, 1);
6464 check_cp1_enabled(ctx
);
6465 op1
= MASK_CP1(ctx
->opcode
);
6469 check_insn(env
, ctx
, ISA_MIPS32R2
);
6474 gen_cp1(ctx
, op1
, rt
, rd
);
6476 #if defined(TARGET_MIPS64)
6479 check_insn(env
, ctx
, ISA_MIPS3
);
6480 gen_cp1(ctx
, op1
, rt
, rd
);
6486 check_insn(env
, ctx
, ASE_MIPS3D
);
6489 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6490 (rt
>> 2) & 0x7, imm
<< 2);
6497 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
6502 generate_exception (ctx
, EXCP_RI
);
6506 generate_exception_err(ctx
, EXCP_CpU
, 1);
6516 /* COP2: Not implemented. */
6517 generate_exception_err(ctx
, EXCP_CpU
, 2);
6521 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6522 save_cpu_state(ctx
, 1);
6523 check_cp1_enabled(ctx
);
6524 op1
= MASK_CP3(ctx
->opcode
);
6532 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
6550 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
6554 generate_exception (ctx
, EXCP_RI
);
6558 generate_exception_err(ctx
, EXCP_CpU
, 1);
6562 #if defined(TARGET_MIPS64)
6563 /* MIPS64 opcodes */
6565 case OPC_LDL
... OPC_LDR
:
6566 case OPC_SDL
... OPC_SDR
:
6571 check_insn(env
, ctx
, ISA_MIPS3
);
6573 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6575 case OPC_DADDI
... OPC_DADDIU
:
6576 check_insn(env
, ctx
, ISA_MIPS3
);
6578 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6582 check_insn(env
, ctx
, ASE_MIPS16
);
6583 /* MIPS16: Not implemented. */
6585 check_insn(env
, ctx
, ASE_MDMX
);
6586 /* MDMX: Not implemented. */
6587 default: /* Invalid */
6588 MIPS_INVAL("major opcode");
6589 generate_exception(ctx
, EXCP_RI
);
6592 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
6593 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
6594 /* Branches completion */
6595 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
6596 ctx
->bstate
= BS_BRANCH
;
6597 save_cpu_state(ctx
, 0);
6600 /* unconditional branch */
6601 MIPS_DEBUG("unconditional branch");
6602 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6605 /* blikely taken case */
6606 MIPS_DEBUG("blikely branch taken");
6607 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6610 /* Conditional branch */
6611 MIPS_DEBUG("conditional branch");
6614 l1
= gen_new_label();
6616 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6618 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6622 /* unconditional branch to register */
6623 MIPS_DEBUG("branch to register");
6628 MIPS_DEBUG("unknown branch");
6634 static always_inline
int
6635 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
6639 target_ulong pc_start
;
6640 uint16_t *gen_opc_end
;
6643 if (search_pc
&& loglevel
)
6644 fprintf (logfile
, "search pc %d\n", search_pc
);
6647 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6651 ctx
.bstate
= BS_NONE
;
6652 /* Restore delay slot state from the tb context. */
6653 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
6654 restore_cpu_state(env
, &ctx
);
6655 #if defined(CONFIG_USER_ONLY)
6656 ctx
.mem_idx
= MIPS_HFLAG_UM
;
6658 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
6661 if (loglevel
& CPU_LOG_TB_CPU
) {
6662 fprintf(logfile
, "------------------------------------------------\n");
6663 /* FIXME: This may print out stale hflags from env... */
6664 cpu_dump_state(env
, logfile
, fprintf
, 0);
6667 #ifdef MIPS_DEBUG_DISAS
6668 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6669 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
6670 tb
, ctx
.mem_idx
, ctx
.hflags
);
6672 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6673 if (env
->nb_breakpoints
> 0) {
6674 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6675 if (env
->breakpoints
[j
] == ctx
.pc
) {
6676 save_cpu_state(&ctx
, 1);
6677 ctx
.bstate
= BS_BRANCH
;
6679 /* Include the breakpoint location or the tb won't
6680 * be flushed when it must be. */
6682 goto done_generating
;
6688 j
= gen_opc_ptr
- gen_opc_buf
;
6692 gen_opc_instr_start
[lj
++] = 0;
6694 gen_opc_pc
[lj
] = ctx
.pc
;
6695 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6696 gen_opc_instr_start
[lj
] = 1;
6698 ctx
.opcode
= ldl_code(ctx
.pc
);
6699 decode_opc(env
, &ctx
);
6702 if (env
->singlestep_enabled
)
6705 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6708 #if defined (MIPS_SINGLE_STEP)
6712 if (env
->singlestep_enabled
) {
6713 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
6716 switch (ctx
.bstate
) {
6718 gen_op_interrupt_restart();
6719 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6722 save_cpu_state(&ctx
, 0);
6723 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6726 gen_op_interrupt_restart();
6735 ctx
.last_T0_store
= NULL
;
6736 *gen_opc_ptr
= INDEX_op_end
;
6738 j
= gen_opc_ptr
- gen_opc_buf
;
6741 gen_opc_instr_start
[lj
++] = 0;
6743 tb
->size
= ctx
.pc
- pc_start
;
6746 #if defined MIPS_DEBUG_DISAS
6747 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6748 fprintf(logfile
, "\n");
6750 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6751 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6752 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6753 fprintf(logfile
, "\n");
6755 if (loglevel
& CPU_LOG_TB_CPU
) {
6756 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6763 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6765 return gen_intermediate_code_internal(env
, tb
, 0);
6768 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6770 return gen_intermediate_code_internal(env
, tb
, 1);
6773 void fpu_dump_state(CPUState
*env
, FILE *f
,
6774 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6778 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6780 #define printfpr(fp) \
6783 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6784 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6785 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6788 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6789 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6790 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6791 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6792 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6797 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6798 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
6799 get_float_exception_flags(&env
->fpu
->fp_status
));
6800 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
6801 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
6802 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
6803 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6804 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6805 printfpr(&env
->fpu
->fpr
[i
]);
6811 void dump_fpu (CPUState
*env
)
6814 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6815 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0], env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
, env
->bcond
);
6816 fpu_dump_state(env
, logfile
, fprintf
, 0);
6820 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6821 /* Debug help: The architecture requires 32bit code to maintain proper
6822 sign-extened values on 64bit machines. */
6824 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6826 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6827 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6832 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
6833 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
6834 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
6835 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
6836 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
6837 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
6838 if (!SIGN_EXT_P(env
->btarget
))
6839 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6841 for (i
= 0; i
< 32; i
++) {
6842 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
6843 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6846 if (!SIGN_EXT_P(env
->CP0_EPC
))
6847 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6848 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6849 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6853 void cpu_dump_state (CPUState
*env
, FILE *f
,
6854 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6859 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",
6860 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6861 for (i
= 0; i
< 32; i
++) {
6863 cpu_fprintf(f
, "GPR%02d:", i
);
6864 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6866 cpu_fprintf(f
, "\n");
6869 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6870 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6871 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6872 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6873 if (env
->hflags
& MIPS_HFLAG_FPU
)
6874 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6875 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6876 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6880 #include "translate_init.c"
6882 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
6885 const mips_def_t
*def
;
6887 def
= cpu_mips_find_by_name(cpu_model
);
6890 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6893 env
->cpu_model
= def
;
6896 env
->cpu_model_str
= cpu_model
;
6901 void cpu_reset (CPUMIPSState
*env
)
6903 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6908 #if !defined(CONFIG_USER_ONLY)
6909 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6910 /* If the exception was raised from a delay slot,
6911 * come back to the jump. */
6912 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
6914 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
6916 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
6918 /* SMP not implemented */
6919 env
->CP0_EBase
= 0x80000000;
6920 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6921 /* vectored interrupts not implemented, timer on int 7,
6922 no performance counters. */
6923 env
->CP0_IntCtl
= 0xe0000000;
6927 for (i
= 0; i
< 7; i
++) {
6928 env
->CP0_WatchLo
[i
] = 0;
6929 env
->CP0_WatchHi
[i
] = 0x80000000;
6931 env
->CP0_WatchLo
[7] = 0;
6932 env
->CP0_WatchHi
[7] = 0;
6934 /* Count register increments in debug mode, EJTAG version 1 */
6935 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6937 env
->exception_index
= EXCP_NONE
;
6938 #if defined(CONFIG_USER_ONLY)
6939 env
->hflags
= MIPS_HFLAG_UM
;
6940 env
->user_mode_only
= 1;
6942 env
->hflags
= MIPS_HFLAG_CP0
;
6944 cpu_mips_register(env
, env
->cpu_model
);