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
,
424 /* global register indices */
425 static TCGv cpu_env
, current_tc_regs
, cpu_T
[2];
427 const unsigned char *regnames
[] =
428 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
429 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
430 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
431 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
433 /* Warning: no function for r0 register (hard wired to zero) */
434 #define GEN32(func, NAME) \
435 static GenOpFunc *NAME ## _table [32] = { \
436 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
437 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
438 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
439 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
440 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
441 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
442 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
443 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
445 static always_inline void func(int n) \
447 NAME ## _table[n](); \
450 /* General purpose registers moves */
451 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
452 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
454 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
455 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
457 /* Moves to/from shadow registers */
458 GEN32(gen_op_load_srsgpr_T0
, gen_op_load_srsgpr_T0_gpr
);
459 GEN32(gen_op_store_T0_srsgpr
, gen_op_store_T0_srsgpr_gpr
);
461 static const char *fregnames
[] =
462 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
463 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
464 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
465 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
467 #define FGEN32(func, NAME) \
468 static GenOpFunc *NAME ## _table [32] = { \
469 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
470 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
471 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
472 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
473 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
474 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
475 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
476 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
478 static always_inline void func(int n) \
480 NAME ## _table[n](); \
483 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
484 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
486 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
487 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
489 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
490 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
492 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
493 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
495 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
496 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
498 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
499 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
501 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
502 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
504 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
505 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
507 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
508 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
510 #define FOP_CONDS(type, fmt) \
511 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
512 gen_op_cmp ## type ## _ ## fmt ## _f, \
513 gen_op_cmp ## type ## _ ## fmt ## _un, \
514 gen_op_cmp ## type ## _ ## fmt ## _eq, \
515 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
516 gen_op_cmp ## type ## _ ## fmt ## _olt, \
517 gen_op_cmp ## type ## _ ## fmt ## _ult, \
518 gen_op_cmp ## type ## _ ## fmt ## _ole, \
519 gen_op_cmp ## type ## _ ## fmt ## _ule, \
520 gen_op_cmp ## type ## _ ## fmt ## _sf, \
521 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
522 gen_op_cmp ## type ## _ ## fmt ## _seq, \
523 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
524 gen_op_cmp ## type ## _ ## fmt ## _lt, \
525 gen_op_cmp ## type ## _ ## fmt ## _nge, \
526 gen_op_cmp ## type ## _ ## fmt ## _le, \
527 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
529 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
531 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
541 typedef struct DisasContext
{
542 struct TranslationBlock
*tb
;
543 target_ulong pc
, saved_pc
;
546 /* Routine used to access memory */
548 uint32_t hflags
, saved_hflags
;
550 target_ulong btarget
;
556 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
557 * exception condition
559 BS_STOP
= 1, /* We want to stop translation for any reason */
560 BS_BRANCH
= 2, /* We reached a branch condition */
561 BS_EXCP
= 3, /* We reached an exception condition */
564 #ifdef MIPS_DEBUG_DISAS
565 #define MIPS_DEBUG(fmt, args...) \
567 if (loglevel & CPU_LOG_TB_IN_ASM) { \
568 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
569 ctx->pc, ctx->opcode , ##args); \
573 #define MIPS_DEBUG(fmt, args...) do { } while(0)
576 #define MIPS_INVAL(op) \
578 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
579 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
582 #define GEN_LOAD_REG_T0(Rn) \
587 if (ctx->glue(last_T0, _store) != gen_opc_ptr \
588 || ctx->glue(last_T0, _gpr) != Rn) { \
589 gen_op_load_gpr_T0(Rn); \
594 #define GEN_LOAD_REG_T1(Rn) \
599 gen_op_load_gpr_T1(Rn); \
603 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
606 glue(gen_op_reset_, Tn)(); \
608 glue(gen_op_load_srsgpr_, Tn)(Rn); \
612 #if defined(TARGET_MIPS64)
613 #define GEN_LOAD_IMM_TN(Tn, Imm) \
616 glue(gen_op_reset_, Tn)(); \
617 } else if ((int32_t)Imm == Imm) { \
618 glue(gen_op_set_, Tn)(Imm); \
620 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
624 #define GEN_LOAD_IMM_TN(Tn, Imm) \
627 glue(gen_op_reset_, Tn)(); \
629 glue(gen_op_set_, Tn)(Imm); \
634 #define GEN_STORE_T0_REG(Rn) \
637 glue(gen_op_store_T0,_gpr)(Rn); \
638 ctx->glue(last_T0,_store) = gen_opc_ptr; \
639 ctx->glue(last_T0,_gpr) = Rn; \
643 #define GEN_STORE_T1_REG(Rn) \
646 glue(gen_op_store_T1,_gpr)(Rn); \
649 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
652 glue(glue(gen_op_store_, Tn),_srsgpr)(Rn); \
656 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
658 glue(gen_op_load_fpr_, FTn)(Fn); \
661 #define GEN_STORE_FTN_FREG(Fn, FTn) \
663 glue(gen_op_store_fpr_, FTn)(Fn); \
666 static always_inline
void gen_save_pc(target_ulong pc
)
668 #if defined(TARGET_MIPS64)
669 if (pc
== (int32_t)pc
) {
672 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
679 static always_inline
void gen_save_btarget(target_ulong btarget
)
681 #if defined(TARGET_MIPS64)
682 if (btarget
== (int32_t)btarget
) {
683 gen_op_save_btarget(btarget
);
685 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
688 gen_op_save_btarget(btarget
);
692 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
694 #if defined MIPS_DEBUG_DISAS
695 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
696 fprintf(logfile
, "hflags %08x saved %08x\n",
697 ctx
->hflags
, ctx
->saved_hflags
);
700 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
701 gen_save_pc(ctx
->pc
);
702 ctx
->saved_pc
= ctx
->pc
;
704 if (ctx
->hflags
!= ctx
->saved_hflags
) {
705 gen_op_save_state(ctx
->hflags
);
706 ctx
->saved_hflags
= ctx
->hflags
;
707 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
713 gen_save_btarget(ctx
->btarget
);
719 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
721 ctx
->saved_hflags
= ctx
->hflags
;
722 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
728 ctx
->btarget
= env
->btarget
;
733 static always_inline
void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
735 #if defined MIPS_DEBUG_DISAS
736 if (loglevel
& CPU_LOG_TB_IN_ASM
)
737 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
739 save_cpu_state(ctx
, 1);
741 gen_op_raise_exception(excp
);
743 gen_op_raise_exception_err(excp
, err
);
744 ctx
->bstate
= BS_EXCP
;
747 static always_inline
void generate_exception (DisasContext
*ctx
, int excp
)
749 generate_exception_err (ctx
, excp
, 0);
752 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
754 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
755 generate_exception_err(ctx
, EXCP_CpU
, 1);
758 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
760 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
761 generate_exception_err(ctx
, EXCP_CpU
, 1);
764 /* Verify that the processor is running with COP1X instructions enabled.
765 This is associated with the nabla symbol in the MIPS32 and MIPS64
768 static always_inline
void check_cop1x(DisasContext
*ctx
)
770 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
771 generate_exception(ctx
, EXCP_RI
);
774 /* Verify that the processor is running with 64-bit floating-point
775 operations enabled. */
777 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
779 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
780 generate_exception(ctx
, EXCP_RI
);
784 * Verify if floating point register is valid; an operation is not defined
785 * if bit 0 of any register specification is set and the FR bit in the
786 * Status register equals zero, since the register numbers specify an
787 * even-odd pair of adjacent coprocessor general registers. When the FR bit
788 * in the Status register equals one, both even and odd register numbers
789 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
791 * Multiple 64 bit wide registers can be checked by calling
792 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
794 void check_cp1_registers(DisasContext
*ctx
, int regs
)
796 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
797 generate_exception(ctx
, EXCP_RI
);
800 /* This code generates a "reserved instruction" exception if the
801 CPU does not support the instruction set corresponding to flags. */
802 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
804 if (unlikely(!(env
->insn_flags
& flags
)))
805 generate_exception(ctx
, EXCP_RI
);
808 /* This code generates a "reserved instruction" exception if 64-bit
809 instructions are not enabled. */
810 static always_inline
void check_mips_64(DisasContext
*ctx
)
812 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
813 generate_exception(ctx
, EXCP_RI
);
816 #if defined(CONFIG_USER_ONLY)
817 #define op_ldst(name) gen_op_##name##_raw()
818 #define OP_LD_TABLE(width)
819 #define OP_ST_TABLE(width)
821 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
822 #define OP_LD_TABLE(width) \
823 static GenOpFunc *gen_op_l##width[] = { \
824 &gen_op_l##width##_kernel, \
825 &gen_op_l##width##_super, \
826 &gen_op_l##width##_user, \
828 #define OP_ST_TABLE(width) \
829 static GenOpFunc *gen_op_s##width[] = { \
830 &gen_op_s##width##_kernel, \
831 &gen_op_s##width##_super, \
832 &gen_op_s##width##_user, \
836 #if defined(TARGET_MIPS64)
869 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
870 int base
, int16_t offset
)
872 const char *opn
= "ldst";
875 GEN_LOAD_IMM_TN(T0
, offset
);
876 } else if (offset
== 0) {
877 gen_op_load_gpr_T0(base
);
879 gen_op_load_gpr_T0(base
);
880 gen_op_set_T1(offset
);
883 /* Don't do NOP if destination is zero: we must perform the actual
886 #if defined(TARGET_MIPS64)
889 GEN_STORE_T0_REG(rt
);
894 GEN_STORE_T0_REG(rt
);
899 GEN_STORE_T0_REG(rt
);
908 save_cpu_state(ctx
, 1);
911 GEN_STORE_T0_REG(rt
);
917 GEN_STORE_T1_REG(rt
);
928 GEN_STORE_T1_REG(rt
);
939 GEN_STORE_T0_REG(rt
);
949 GEN_STORE_T0_REG(rt
);
959 GEN_STORE_T0_REG(rt
);
964 GEN_STORE_T0_REG(rt
);
974 GEN_STORE_T0_REG(rt
);
980 GEN_STORE_T1_REG(rt
);
991 GEN_STORE_T1_REG(rt
);
1001 GEN_STORE_T0_REG(rt
);
1005 save_cpu_state(ctx
, 1);
1006 GEN_LOAD_REG_T1(rt
);
1008 GEN_STORE_T0_REG(rt
);
1013 generate_exception(ctx
, EXCP_RI
);
1016 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1019 /* Load and store */
1020 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1021 int base
, int16_t offset
)
1023 const char *opn
= "flt_ldst";
1026 GEN_LOAD_IMM_TN(T0
, offset
);
1027 } else if (offset
== 0) {
1028 gen_op_load_gpr_T0(base
);
1030 gen_op_load_gpr_T0(base
);
1031 gen_op_set_T1(offset
);
1034 /* Don't do NOP if destination is zero: we must perform the actual
1039 GEN_STORE_FTN_FREG(ft
, WT0
);
1043 GEN_LOAD_FREG_FTN(WT0
, ft
);
1049 GEN_STORE_FTN_FREG(ft
, DT0
);
1053 GEN_LOAD_FREG_FTN(DT0
, ft
);
1059 generate_exception(ctx
, EXCP_RI
);
1062 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1065 /* Arithmetic with immediate operand */
1066 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1067 int rt
, int rs
, int16_t imm
)
1070 const char *opn
= "imm arith";
1072 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1073 /* If no destination, treat it as a NOP.
1074 For addi, we must generate the overflow exception when needed. */
1078 uimm
= (uint16_t)imm
;
1082 #if defined(TARGET_MIPS64)
1088 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1093 GEN_LOAD_REG_T0(rs
);
1094 GEN_LOAD_IMM_TN(T1
, uimm
);
1097 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1102 #if defined(TARGET_MIPS64)
1111 GEN_LOAD_REG_T0(rs
);
1112 GEN_LOAD_IMM_TN(T1
, uimm
);
1117 save_cpu_state(ctx
, 1);
1125 #if defined(TARGET_MIPS64)
1127 save_cpu_state(ctx
, 1);
1168 switch ((ctx
->opcode
>> 21) & 0x1f) {
1174 /* rotr is decoded as srl on non-R2 CPUs */
1175 if (env
->insn_flags
& ISA_MIPS32R2
) {
1184 MIPS_INVAL("invalid srl flag");
1185 generate_exception(ctx
, EXCP_RI
);
1189 #if defined(TARGET_MIPS64)
1199 switch ((ctx
->opcode
>> 21) & 0x1f) {
1205 /* drotr is decoded as dsrl on non-R2 CPUs */
1206 if (env
->insn_flags
& ISA_MIPS32R2
) {
1215 MIPS_INVAL("invalid dsrl flag");
1216 generate_exception(ctx
, EXCP_RI
);
1229 switch ((ctx
->opcode
>> 21) & 0x1f) {
1235 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1236 if (env
->insn_flags
& ISA_MIPS32R2
) {
1245 MIPS_INVAL("invalid dsrl32 flag");
1246 generate_exception(ctx
, EXCP_RI
);
1253 generate_exception(ctx
, EXCP_RI
);
1256 GEN_STORE_T0_REG(rt
);
1257 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1261 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1262 int rd
, int rs
, int rt
)
1264 const char *opn
= "arith";
1266 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1267 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1268 /* If no destination, treat it as a NOP.
1269 For add & sub, we must generate the overflow exception when needed. */
1273 GEN_LOAD_REG_T0(rs
);
1274 /* Specialcase the conventional move operation. */
1275 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1276 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1277 GEN_STORE_T0_REG(rd
);
1280 GEN_LOAD_REG_T1(rt
);
1283 save_cpu_state(ctx
, 1);
1292 save_cpu_state(ctx
, 1);
1300 #if defined(TARGET_MIPS64)
1302 save_cpu_state(ctx
, 1);
1311 save_cpu_state(ctx
, 1);
1365 switch ((ctx
->opcode
>> 6) & 0x1f) {
1371 /* rotrv is decoded as srlv on non-R2 CPUs */
1372 if (env
->insn_flags
& ISA_MIPS32R2
) {
1381 MIPS_INVAL("invalid srlv flag");
1382 generate_exception(ctx
, EXCP_RI
);
1386 #if defined(TARGET_MIPS64)
1396 switch ((ctx
->opcode
>> 6) & 0x1f) {
1402 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1403 if (env
->insn_flags
& ISA_MIPS32R2
) {
1412 MIPS_INVAL("invalid dsrlv flag");
1413 generate_exception(ctx
, EXCP_RI
);
1420 generate_exception(ctx
, EXCP_RI
);
1423 GEN_STORE_T0_REG(rd
);
1425 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1428 /* Arithmetic on HI/LO registers */
1429 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1431 const char *opn
= "hilo";
1433 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1441 GEN_STORE_T0_REG(reg
);
1446 GEN_STORE_T0_REG(reg
);
1450 GEN_LOAD_REG_T0(reg
);
1455 GEN_LOAD_REG_T0(reg
);
1461 generate_exception(ctx
, EXCP_RI
);
1464 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1467 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1470 const char *opn
= "mul/div";
1472 GEN_LOAD_REG_T0(rs
);
1473 GEN_LOAD_REG_T1(rt
);
1491 #if defined(TARGET_MIPS64)
1527 generate_exception(ctx
, EXCP_RI
);
1530 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1533 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
1534 int rd
, int rs
, int rt
)
1536 const char *opn
= "mul vr54xx";
1538 GEN_LOAD_REG_T0(rs
);
1539 GEN_LOAD_REG_T1(rt
);
1542 case OPC_VR54XX_MULS
:
1546 case OPC_VR54XX_MULSU
:
1550 case OPC_VR54XX_MACC
:
1554 case OPC_VR54XX_MACCU
:
1558 case OPC_VR54XX_MSAC
:
1562 case OPC_VR54XX_MSACU
:
1566 case OPC_VR54XX_MULHI
:
1570 case OPC_VR54XX_MULHIU
:
1574 case OPC_VR54XX_MULSHI
:
1578 case OPC_VR54XX_MULSHIU
:
1582 case OPC_VR54XX_MACCHI
:
1586 case OPC_VR54XX_MACCHIU
:
1590 case OPC_VR54XX_MSACHI
:
1594 case OPC_VR54XX_MSACHIU
:
1599 MIPS_INVAL("mul vr54xx");
1600 generate_exception(ctx
, EXCP_RI
);
1603 GEN_STORE_T0_REG(rd
);
1604 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1607 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1610 const char *opn
= "CLx";
1616 GEN_LOAD_REG_T0(rs
);
1626 #if defined(TARGET_MIPS64)
1638 generate_exception(ctx
, EXCP_RI
);
1641 gen_op_store_T0_gpr(rd
);
1642 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1646 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1647 int rs
, int rt
, int16_t imm
)
1652 /* Load needed operands */
1660 /* Compare two registers */
1662 GEN_LOAD_REG_T0(rs
);
1663 GEN_LOAD_REG_T1(rt
);
1673 /* Compare register to immediate */
1674 if (rs
!= 0 || imm
!= 0) {
1675 GEN_LOAD_REG_T0(rs
);
1676 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1683 case OPC_TEQ
: /* rs == rs */
1684 case OPC_TEQI
: /* r0 == 0 */
1685 case OPC_TGE
: /* rs >= rs */
1686 case OPC_TGEI
: /* r0 >= 0 */
1687 case OPC_TGEU
: /* rs >= rs unsigned */
1688 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1692 case OPC_TLT
: /* rs < rs */
1693 case OPC_TLTI
: /* r0 < 0 */
1694 case OPC_TLTU
: /* rs < rs unsigned */
1695 case OPC_TLTIU
: /* r0 < 0 unsigned */
1696 case OPC_TNE
: /* rs != rs */
1697 case OPC_TNEI
: /* r0 != 0 */
1698 /* Never trap: treat as NOP. */
1702 generate_exception(ctx
, EXCP_RI
);
1733 generate_exception(ctx
, EXCP_RI
);
1737 save_cpu_state(ctx
, 1);
1739 ctx
->bstate
= BS_STOP
;
1742 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1744 TranslationBlock
*tb
;
1746 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1749 tcg_gen_exit_tb((long)tb
+ n
);
1756 static inline void tcg_gen_set_bcond(void)
1758 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
1761 static inline void tcg_gen_jnz_bcond(int label
)
1763 int r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
1765 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
1766 tcg_gen_brcond_tl(TCG_COND_NE
, r_tmp
, tcg_const_i32(0), label
);
1769 /* Branches (before delay slot) */
1770 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1771 int rs
, int rt
, int32_t offset
)
1773 target_ulong btarget
= -1;
1777 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1778 #ifdef MIPS_DEBUG_DISAS
1779 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1781 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1785 generate_exception(ctx
, EXCP_RI
);
1789 /* Load needed operands */
1795 /* Compare two registers */
1797 GEN_LOAD_REG_T0(rs
);
1798 GEN_LOAD_REG_T1(rt
);
1801 btarget
= ctx
->pc
+ 4 + offset
;
1815 /* Compare to zero */
1817 gen_op_load_gpr_T0(rs
);
1820 btarget
= ctx
->pc
+ 4 + offset
;
1824 /* Jump to immediate */
1825 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
1829 /* Jump to register */
1830 if (offset
!= 0 && offset
!= 16) {
1831 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1832 others are reserved. */
1833 MIPS_INVAL("jump hint");
1834 generate_exception(ctx
, EXCP_RI
);
1837 GEN_LOAD_REG_T1(rs
);
1838 gen_op_save_breg_target();
1841 MIPS_INVAL("branch/jump");
1842 generate_exception(ctx
, EXCP_RI
);
1846 /* No condition to be computed */
1848 case OPC_BEQ
: /* rx == rx */
1849 case OPC_BEQL
: /* rx == rx likely */
1850 case OPC_BGEZ
: /* 0 >= 0 */
1851 case OPC_BGEZL
: /* 0 >= 0 likely */
1852 case OPC_BLEZ
: /* 0 <= 0 */
1853 case OPC_BLEZL
: /* 0 <= 0 likely */
1855 ctx
->hflags
|= MIPS_HFLAG_B
;
1856 MIPS_DEBUG("balways");
1858 case OPC_BGEZAL
: /* 0 >= 0 */
1859 case OPC_BGEZALL
: /* 0 >= 0 likely */
1860 /* Always take and link */
1862 ctx
->hflags
|= MIPS_HFLAG_B
;
1863 MIPS_DEBUG("balways and link");
1865 case OPC_BNE
: /* rx != rx */
1866 case OPC_BGTZ
: /* 0 > 0 */
1867 case OPC_BLTZ
: /* 0 < 0 */
1869 MIPS_DEBUG("bnever (NOP)");
1871 case OPC_BLTZAL
: /* 0 < 0 */
1872 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1873 gen_op_store_T0_gpr(31);
1874 MIPS_DEBUG("bnever and link");
1876 case OPC_BLTZALL
: /* 0 < 0 likely */
1877 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1878 gen_op_store_T0_gpr(31);
1879 /* Skip the instruction in the delay slot */
1880 MIPS_DEBUG("bnever, link and skip");
1883 case OPC_BNEL
: /* rx != rx likely */
1884 case OPC_BGTZL
: /* 0 > 0 likely */
1885 case OPC_BLTZL
: /* 0 < 0 likely */
1886 /* Skip the instruction in the delay slot */
1887 MIPS_DEBUG("bnever and skip");
1891 ctx
->hflags
|= MIPS_HFLAG_B
;
1892 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1896 ctx
->hflags
|= MIPS_HFLAG_B
;
1897 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1900 ctx
->hflags
|= MIPS_HFLAG_BR
;
1901 MIPS_DEBUG("jr %s", regnames
[rs
]);
1905 ctx
->hflags
|= MIPS_HFLAG_BR
;
1906 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1909 MIPS_INVAL("branch/jump");
1910 generate_exception(ctx
, EXCP_RI
);
1917 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1918 regnames
[rs
], regnames
[rt
], btarget
);
1922 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1923 regnames
[rs
], regnames
[rt
], btarget
);
1927 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1928 regnames
[rs
], regnames
[rt
], btarget
);
1932 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1933 regnames
[rs
], regnames
[rt
], btarget
);
1937 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1941 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1945 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1951 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1955 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1959 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1963 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1967 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1971 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1975 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1980 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1982 ctx
->hflags
|= MIPS_HFLAG_BC
;
1983 tcg_gen_set_bcond();
1988 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1990 ctx
->hflags
|= MIPS_HFLAG_BL
;
1991 tcg_gen_set_bcond();
1994 MIPS_INVAL("conditional branch/jump");
1995 generate_exception(ctx
, EXCP_RI
);
1999 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2000 blink
, ctx
->hflags
, btarget
);
2002 ctx
->btarget
= btarget
;
2004 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2005 gen_op_store_T0_gpr(blink
);
2009 /* special3 bitfield operations */
2010 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2011 int rs
, int lsb
, int msb
)
2013 GEN_LOAD_REG_T1(rs
);
2018 gen_op_ext(lsb
, msb
+ 1);
2020 #if defined(TARGET_MIPS64)
2024 gen_op_dext(lsb
, msb
+ 1 + 32);
2029 gen_op_dext(lsb
+ 32, msb
+ 1);
2034 gen_op_dext(lsb
, msb
+ 1);
2040 GEN_LOAD_REG_T0(rt
);
2041 gen_op_ins(lsb
, msb
- lsb
+ 1);
2043 #if defined(TARGET_MIPS64)
2047 GEN_LOAD_REG_T0(rt
);
2048 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2053 GEN_LOAD_REG_T0(rt
);
2054 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2059 GEN_LOAD_REG_T0(rt
);
2060 gen_op_dins(lsb
, msb
- lsb
+ 1);
2065 MIPS_INVAL("bitops");
2066 generate_exception(ctx
, EXCP_RI
);
2069 GEN_STORE_T0_REG(rt
);
2072 /* CP0 (MMU and control) */
2073 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2075 const char *rn
= "invalid";
2078 check_insn(env
, ctx
, ISA_MIPS32
);
2084 gen_op_mfc0_index();
2088 check_insn(env
, ctx
, ASE_MT
);
2089 gen_op_mfc0_mvpcontrol();
2093 check_insn(env
, ctx
, ASE_MT
);
2094 gen_op_mfc0_mvpconf0();
2098 check_insn(env
, ctx
, ASE_MT
);
2099 gen_op_mfc0_mvpconf1();
2109 gen_op_mfc0_random();
2113 check_insn(env
, ctx
, ASE_MT
);
2114 gen_op_mfc0_vpecontrol();
2118 check_insn(env
, ctx
, ASE_MT
);
2119 gen_op_mfc0_vpeconf0();
2123 check_insn(env
, ctx
, ASE_MT
);
2124 gen_op_mfc0_vpeconf1();
2128 check_insn(env
, ctx
, ASE_MT
);
2129 gen_op_mfc0_yqmask();
2133 check_insn(env
, ctx
, ASE_MT
);
2134 gen_op_mfc0_vpeschedule();
2138 check_insn(env
, ctx
, ASE_MT
);
2139 gen_op_mfc0_vpeschefback();
2140 rn
= "VPEScheFBack";
2143 check_insn(env
, ctx
, ASE_MT
);
2144 gen_op_mfc0_vpeopt();
2154 gen_op_mfc0_entrylo0();
2158 check_insn(env
, ctx
, ASE_MT
);
2159 gen_op_mfc0_tcstatus();
2163 check_insn(env
, ctx
, ASE_MT
);
2164 gen_op_mfc0_tcbind();
2168 check_insn(env
, ctx
, ASE_MT
);
2169 gen_op_mfc0_tcrestart();
2173 check_insn(env
, ctx
, ASE_MT
);
2174 gen_op_mfc0_tchalt();
2178 check_insn(env
, ctx
, ASE_MT
);
2179 gen_op_mfc0_tccontext();
2183 check_insn(env
, ctx
, ASE_MT
);
2184 gen_op_mfc0_tcschedule();
2188 check_insn(env
, ctx
, ASE_MT
);
2189 gen_op_mfc0_tcschefback();
2199 gen_op_mfc0_entrylo1();
2209 gen_op_mfc0_context();
2213 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2214 rn
= "ContextConfig";
2223 gen_op_mfc0_pagemask();
2227 check_insn(env
, ctx
, ISA_MIPS32R2
);
2228 gen_op_mfc0_pagegrain();
2238 gen_op_mfc0_wired();
2242 check_insn(env
, ctx
, ISA_MIPS32R2
);
2243 gen_op_mfc0_srsconf0();
2247 check_insn(env
, ctx
, ISA_MIPS32R2
);
2248 gen_op_mfc0_srsconf1();
2252 check_insn(env
, ctx
, ISA_MIPS32R2
);
2253 gen_op_mfc0_srsconf2();
2257 check_insn(env
, ctx
, ISA_MIPS32R2
);
2258 gen_op_mfc0_srsconf3();
2262 check_insn(env
, ctx
, ISA_MIPS32R2
);
2263 gen_op_mfc0_srsconf4();
2273 check_insn(env
, ctx
, ISA_MIPS32R2
);
2274 gen_op_mfc0_hwrena();
2284 gen_op_mfc0_badvaddr();
2294 gen_op_mfc0_count();
2297 /* 6,7 are implementation dependent */
2305 gen_op_mfc0_entryhi();
2315 gen_op_mfc0_compare();
2318 /* 6,7 are implementation dependent */
2326 gen_op_mfc0_status();
2330 check_insn(env
, ctx
, ISA_MIPS32R2
);
2331 gen_op_mfc0_intctl();
2335 check_insn(env
, ctx
, ISA_MIPS32R2
);
2336 gen_op_mfc0_srsctl();
2340 check_insn(env
, ctx
, ISA_MIPS32R2
);
2341 gen_op_mfc0_srsmap();
2351 gen_op_mfc0_cause();
2375 check_insn(env
, ctx
, ISA_MIPS32R2
);
2376 gen_op_mfc0_ebase();
2386 gen_op_mfc0_config0();
2390 gen_op_mfc0_config1();
2394 gen_op_mfc0_config2();
2398 gen_op_mfc0_config3();
2401 /* 4,5 are reserved */
2402 /* 6,7 are implementation dependent */
2404 gen_op_mfc0_config6();
2408 gen_op_mfc0_config7();
2418 gen_op_mfc0_lladdr();
2428 gen_op_mfc0_watchlo(sel
);
2438 gen_op_mfc0_watchhi(sel
);
2448 #if defined(TARGET_MIPS64)
2449 check_insn(env
, ctx
, ISA_MIPS3
);
2450 gen_op_mfc0_xcontext();
2459 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2462 gen_op_mfc0_framemask();
2471 rn
= "'Diagnostic"; /* implementation dependent */
2476 gen_op_mfc0_debug(); /* EJTAG support */
2480 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2481 rn
= "TraceControl";
2484 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2485 rn
= "TraceControl2";
2488 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2489 rn
= "UserTraceData";
2492 // gen_op_mfc0_debug(); /* PDtrace support */
2502 gen_op_mfc0_depc(); /* EJTAG support */
2512 gen_op_mfc0_performance0();
2513 rn
= "Performance0";
2516 // gen_op_mfc0_performance1();
2517 rn
= "Performance1";
2520 // gen_op_mfc0_performance2();
2521 rn
= "Performance2";
2524 // gen_op_mfc0_performance3();
2525 rn
= "Performance3";
2528 // gen_op_mfc0_performance4();
2529 rn
= "Performance4";
2532 // gen_op_mfc0_performance5();
2533 rn
= "Performance5";
2536 // gen_op_mfc0_performance6();
2537 rn
= "Performance6";
2540 // gen_op_mfc0_performance7();
2541 rn
= "Performance7";
2566 gen_op_mfc0_taglo();
2573 gen_op_mfc0_datalo();
2586 gen_op_mfc0_taghi();
2593 gen_op_mfc0_datahi();
2603 gen_op_mfc0_errorepc();
2613 gen_op_mfc0_desave(); /* EJTAG support */
2623 #if defined MIPS_DEBUG_DISAS
2624 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2625 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2632 #if defined MIPS_DEBUG_DISAS
2633 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2634 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2638 generate_exception(ctx
, EXCP_RI
);
2641 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2643 const char *rn
= "invalid";
2646 check_insn(env
, ctx
, ISA_MIPS32
);
2652 gen_op_mtc0_index();
2656 check_insn(env
, ctx
, ASE_MT
);
2657 gen_op_mtc0_mvpcontrol();
2661 check_insn(env
, ctx
, ASE_MT
);
2666 check_insn(env
, ctx
, ASE_MT
);
2681 check_insn(env
, ctx
, ASE_MT
);
2682 gen_op_mtc0_vpecontrol();
2686 check_insn(env
, ctx
, ASE_MT
);
2687 gen_op_mtc0_vpeconf0();
2691 check_insn(env
, ctx
, ASE_MT
);
2692 gen_op_mtc0_vpeconf1();
2696 check_insn(env
, ctx
, ASE_MT
);
2697 gen_op_mtc0_yqmask();
2701 check_insn(env
, ctx
, ASE_MT
);
2702 gen_op_mtc0_vpeschedule();
2706 check_insn(env
, ctx
, ASE_MT
);
2707 gen_op_mtc0_vpeschefback();
2708 rn
= "VPEScheFBack";
2711 check_insn(env
, ctx
, ASE_MT
);
2712 gen_op_mtc0_vpeopt();
2722 gen_op_mtc0_entrylo0();
2726 check_insn(env
, ctx
, ASE_MT
);
2727 gen_op_mtc0_tcstatus();
2731 check_insn(env
, ctx
, ASE_MT
);
2732 gen_op_mtc0_tcbind();
2736 check_insn(env
, ctx
, ASE_MT
);
2737 gen_op_mtc0_tcrestart();
2741 check_insn(env
, ctx
, ASE_MT
);
2742 gen_op_mtc0_tchalt();
2746 check_insn(env
, ctx
, ASE_MT
);
2747 gen_op_mtc0_tccontext();
2751 check_insn(env
, ctx
, ASE_MT
);
2752 gen_op_mtc0_tcschedule();
2756 check_insn(env
, ctx
, ASE_MT
);
2757 gen_op_mtc0_tcschefback();
2767 gen_op_mtc0_entrylo1();
2777 gen_op_mtc0_context();
2781 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2782 rn
= "ContextConfig";
2791 gen_op_mtc0_pagemask();
2795 check_insn(env
, ctx
, ISA_MIPS32R2
);
2796 gen_op_mtc0_pagegrain();
2806 gen_op_mtc0_wired();
2810 check_insn(env
, ctx
, ISA_MIPS32R2
);
2811 gen_op_mtc0_srsconf0();
2815 check_insn(env
, ctx
, ISA_MIPS32R2
);
2816 gen_op_mtc0_srsconf1();
2820 check_insn(env
, ctx
, ISA_MIPS32R2
);
2821 gen_op_mtc0_srsconf2();
2825 check_insn(env
, ctx
, ISA_MIPS32R2
);
2826 gen_op_mtc0_srsconf3();
2830 check_insn(env
, ctx
, ISA_MIPS32R2
);
2831 gen_op_mtc0_srsconf4();
2841 check_insn(env
, ctx
, ISA_MIPS32R2
);
2842 gen_op_mtc0_hwrena();
2856 gen_op_mtc0_count();
2859 /* 6,7 are implementation dependent */
2863 /* Stop translation as we may have switched the execution mode */
2864 ctx
->bstate
= BS_STOP
;
2869 gen_op_mtc0_entryhi();
2879 gen_op_mtc0_compare();
2882 /* 6,7 are implementation dependent */
2890 gen_op_mtc0_status();
2891 /* BS_STOP isn't good enough here, hflags may have changed. */
2892 gen_save_pc(ctx
->pc
+ 4);
2893 ctx
->bstate
= BS_EXCP
;
2897 check_insn(env
, ctx
, ISA_MIPS32R2
);
2898 gen_op_mtc0_intctl();
2899 /* Stop translation as we may have switched the execution mode */
2900 ctx
->bstate
= BS_STOP
;
2904 check_insn(env
, ctx
, ISA_MIPS32R2
);
2905 gen_op_mtc0_srsctl();
2906 /* Stop translation as we may have switched the execution mode */
2907 ctx
->bstate
= BS_STOP
;
2911 check_insn(env
, ctx
, ISA_MIPS32R2
);
2912 gen_op_mtc0_srsmap();
2913 /* Stop translation as we may have switched the execution mode */
2914 ctx
->bstate
= BS_STOP
;
2924 gen_op_mtc0_cause();
2930 /* Stop translation as we may have switched the execution mode */
2931 ctx
->bstate
= BS_STOP
;
2950 check_insn(env
, ctx
, ISA_MIPS32R2
);
2951 gen_op_mtc0_ebase();
2961 gen_op_mtc0_config0();
2963 /* Stop translation as we may have switched the execution mode */
2964 ctx
->bstate
= BS_STOP
;
2967 /* ignored, read only */
2971 gen_op_mtc0_config2();
2973 /* Stop translation as we may have switched the execution mode */
2974 ctx
->bstate
= BS_STOP
;
2977 /* ignored, read only */
2980 /* 4,5 are reserved */
2981 /* 6,7 are implementation dependent */
2991 rn
= "Invalid config selector";
3008 gen_op_mtc0_watchlo(sel
);
3018 gen_op_mtc0_watchhi(sel
);
3028 #if defined(TARGET_MIPS64)
3029 check_insn(env
, ctx
, ISA_MIPS3
);
3030 gen_op_mtc0_xcontext();
3039 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3042 gen_op_mtc0_framemask();
3051 rn
= "Diagnostic"; /* implementation dependent */
3056 gen_op_mtc0_debug(); /* EJTAG support */
3057 /* BS_STOP isn't good enough here, hflags may have changed. */
3058 gen_save_pc(ctx
->pc
+ 4);
3059 ctx
->bstate
= BS_EXCP
;
3063 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3064 rn
= "TraceControl";
3065 /* Stop translation as we may have switched the execution mode */
3066 ctx
->bstate
= BS_STOP
;
3069 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3070 rn
= "TraceControl2";
3071 /* Stop translation as we may have switched the execution mode */
3072 ctx
->bstate
= BS_STOP
;
3075 /* Stop translation as we may have switched the execution mode */
3076 ctx
->bstate
= BS_STOP
;
3077 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3078 rn
= "UserTraceData";
3079 /* Stop translation as we may have switched the execution mode */
3080 ctx
->bstate
= BS_STOP
;
3083 // gen_op_mtc0_debug(); /* PDtrace support */
3084 /* Stop translation as we may have switched the execution mode */
3085 ctx
->bstate
= BS_STOP
;
3095 gen_op_mtc0_depc(); /* EJTAG support */
3105 gen_op_mtc0_performance0();
3106 rn
= "Performance0";
3109 // gen_op_mtc0_performance1();
3110 rn
= "Performance1";
3113 // gen_op_mtc0_performance2();
3114 rn
= "Performance2";
3117 // gen_op_mtc0_performance3();
3118 rn
= "Performance3";
3121 // gen_op_mtc0_performance4();
3122 rn
= "Performance4";
3125 // gen_op_mtc0_performance5();
3126 rn
= "Performance5";
3129 // gen_op_mtc0_performance6();
3130 rn
= "Performance6";
3133 // gen_op_mtc0_performance7();
3134 rn
= "Performance7";
3160 gen_op_mtc0_taglo();
3167 gen_op_mtc0_datalo();
3180 gen_op_mtc0_taghi();
3187 gen_op_mtc0_datahi();
3198 gen_op_mtc0_errorepc();
3208 gen_op_mtc0_desave(); /* EJTAG support */
3214 /* Stop translation as we may have switched the execution mode */
3215 ctx
->bstate
= BS_STOP
;
3220 #if defined MIPS_DEBUG_DISAS
3221 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3222 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3229 #if defined MIPS_DEBUG_DISAS
3230 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3231 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3235 generate_exception(ctx
, EXCP_RI
);
3238 #if defined(TARGET_MIPS64)
3239 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3241 const char *rn
= "invalid";
3244 check_insn(env
, ctx
, ISA_MIPS64
);
3250 gen_op_mfc0_index();
3254 check_insn(env
, ctx
, ASE_MT
);
3255 gen_op_mfc0_mvpcontrol();
3259 check_insn(env
, ctx
, ASE_MT
);
3260 gen_op_mfc0_mvpconf0();
3264 check_insn(env
, ctx
, ASE_MT
);
3265 gen_op_mfc0_mvpconf1();
3275 gen_op_mfc0_random();
3279 check_insn(env
, ctx
, ASE_MT
);
3280 gen_op_mfc0_vpecontrol();
3284 check_insn(env
, ctx
, ASE_MT
);
3285 gen_op_mfc0_vpeconf0();
3289 check_insn(env
, ctx
, ASE_MT
);
3290 gen_op_mfc0_vpeconf1();
3294 check_insn(env
, ctx
, ASE_MT
);
3295 gen_op_dmfc0_yqmask();
3299 check_insn(env
, ctx
, ASE_MT
);
3300 gen_op_dmfc0_vpeschedule();
3304 check_insn(env
, ctx
, ASE_MT
);
3305 gen_op_dmfc0_vpeschefback();
3306 rn
= "VPEScheFBack";
3309 check_insn(env
, ctx
, ASE_MT
);
3310 gen_op_mfc0_vpeopt();
3320 gen_op_dmfc0_entrylo0();
3324 check_insn(env
, ctx
, ASE_MT
);
3325 gen_op_mfc0_tcstatus();
3329 check_insn(env
, ctx
, ASE_MT
);
3330 gen_op_mfc0_tcbind();
3334 check_insn(env
, ctx
, ASE_MT
);
3335 gen_op_dmfc0_tcrestart();
3339 check_insn(env
, ctx
, ASE_MT
);
3340 gen_op_dmfc0_tchalt();
3344 check_insn(env
, ctx
, ASE_MT
);
3345 gen_op_dmfc0_tccontext();
3349 check_insn(env
, ctx
, ASE_MT
);
3350 gen_op_dmfc0_tcschedule();
3354 check_insn(env
, ctx
, ASE_MT
);
3355 gen_op_dmfc0_tcschefback();
3365 gen_op_dmfc0_entrylo1();
3375 gen_op_dmfc0_context();
3379 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3380 rn
= "ContextConfig";
3389 gen_op_mfc0_pagemask();
3393 check_insn(env
, ctx
, ISA_MIPS32R2
);
3394 gen_op_mfc0_pagegrain();
3404 gen_op_mfc0_wired();
3408 check_insn(env
, ctx
, ISA_MIPS32R2
);
3409 gen_op_mfc0_srsconf0();
3413 check_insn(env
, ctx
, ISA_MIPS32R2
);
3414 gen_op_mfc0_srsconf1();
3418 check_insn(env
, ctx
, ISA_MIPS32R2
);
3419 gen_op_mfc0_srsconf2();
3423 check_insn(env
, ctx
, ISA_MIPS32R2
);
3424 gen_op_mfc0_srsconf3();
3428 check_insn(env
, ctx
, ISA_MIPS32R2
);
3429 gen_op_mfc0_srsconf4();
3439 check_insn(env
, ctx
, ISA_MIPS32R2
);
3440 gen_op_mfc0_hwrena();
3450 gen_op_dmfc0_badvaddr();
3460 gen_op_mfc0_count();
3463 /* 6,7 are implementation dependent */
3471 gen_op_dmfc0_entryhi();
3481 gen_op_mfc0_compare();
3484 /* 6,7 are implementation dependent */
3492 gen_op_mfc0_status();
3496 check_insn(env
, ctx
, ISA_MIPS32R2
);
3497 gen_op_mfc0_intctl();
3501 check_insn(env
, ctx
, ISA_MIPS32R2
);
3502 gen_op_mfc0_srsctl();
3506 check_insn(env
, ctx
, ISA_MIPS32R2
);
3507 gen_op_mfc0_srsmap();
3517 gen_op_mfc0_cause();
3541 check_insn(env
, ctx
, ISA_MIPS32R2
);
3542 gen_op_mfc0_ebase();
3552 gen_op_mfc0_config0();
3556 gen_op_mfc0_config1();
3560 gen_op_mfc0_config2();
3564 gen_op_mfc0_config3();
3567 /* 6,7 are implementation dependent */
3575 gen_op_dmfc0_lladdr();
3585 gen_op_dmfc0_watchlo(sel
);
3595 gen_op_mfc0_watchhi(sel
);
3605 check_insn(env
, ctx
, ISA_MIPS3
);
3606 gen_op_dmfc0_xcontext();
3614 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3617 gen_op_mfc0_framemask();
3626 rn
= "'Diagnostic"; /* implementation dependent */
3631 gen_op_mfc0_debug(); /* EJTAG support */
3635 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3636 rn
= "TraceControl";
3639 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3640 rn
= "TraceControl2";
3643 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3644 rn
= "UserTraceData";
3647 // gen_op_dmfc0_debug(); /* PDtrace support */
3657 gen_op_dmfc0_depc(); /* EJTAG support */
3667 gen_op_mfc0_performance0();
3668 rn
= "Performance0";
3671 // gen_op_dmfc0_performance1();
3672 rn
= "Performance1";
3675 // gen_op_dmfc0_performance2();
3676 rn
= "Performance2";
3679 // gen_op_dmfc0_performance3();
3680 rn
= "Performance3";
3683 // gen_op_dmfc0_performance4();
3684 rn
= "Performance4";
3687 // gen_op_dmfc0_performance5();
3688 rn
= "Performance5";
3691 // gen_op_dmfc0_performance6();
3692 rn
= "Performance6";
3695 // gen_op_dmfc0_performance7();
3696 rn
= "Performance7";
3721 gen_op_mfc0_taglo();
3728 gen_op_mfc0_datalo();
3741 gen_op_mfc0_taghi();
3748 gen_op_mfc0_datahi();
3758 gen_op_dmfc0_errorepc();
3768 gen_op_mfc0_desave(); /* EJTAG support */
3778 #if defined MIPS_DEBUG_DISAS
3779 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3780 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3787 #if defined MIPS_DEBUG_DISAS
3788 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3789 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3793 generate_exception(ctx
, EXCP_RI
);
3796 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3798 const char *rn
= "invalid";
3801 check_insn(env
, ctx
, ISA_MIPS64
);
3807 gen_op_mtc0_index();
3811 check_insn(env
, ctx
, ASE_MT
);
3812 gen_op_mtc0_mvpcontrol();
3816 check_insn(env
, ctx
, ASE_MT
);
3821 check_insn(env
, ctx
, ASE_MT
);
3836 check_insn(env
, ctx
, ASE_MT
);
3837 gen_op_mtc0_vpecontrol();
3841 check_insn(env
, ctx
, ASE_MT
);
3842 gen_op_mtc0_vpeconf0();
3846 check_insn(env
, ctx
, ASE_MT
);
3847 gen_op_mtc0_vpeconf1();
3851 check_insn(env
, ctx
, ASE_MT
);
3852 gen_op_mtc0_yqmask();
3856 check_insn(env
, ctx
, ASE_MT
);
3857 gen_op_mtc0_vpeschedule();
3861 check_insn(env
, ctx
, ASE_MT
);
3862 gen_op_mtc0_vpeschefback();
3863 rn
= "VPEScheFBack";
3866 check_insn(env
, ctx
, ASE_MT
);
3867 gen_op_mtc0_vpeopt();
3877 gen_op_mtc0_entrylo0();
3881 check_insn(env
, ctx
, ASE_MT
);
3882 gen_op_mtc0_tcstatus();
3886 check_insn(env
, ctx
, ASE_MT
);
3887 gen_op_mtc0_tcbind();
3891 check_insn(env
, ctx
, ASE_MT
);
3892 gen_op_mtc0_tcrestart();
3896 check_insn(env
, ctx
, ASE_MT
);
3897 gen_op_mtc0_tchalt();
3901 check_insn(env
, ctx
, ASE_MT
);
3902 gen_op_mtc0_tccontext();
3906 check_insn(env
, ctx
, ASE_MT
);
3907 gen_op_mtc0_tcschedule();
3911 check_insn(env
, ctx
, ASE_MT
);
3912 gen_op_mtc0_tcschefback();
3922 gen_op_mtc0_entrylo1();
3932 gen_op_mtc0_context();
3936 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3937 rn
= "ContextConfig";
3946 gen_op_mtc0_pagemask();
3950 check_insn(env
, ctx
, ISA_MIPS32R2
);
3951 gen_op_mtc0_pagegrain();
3961 gen_op_mtc0_wired();
3965 check_insn(env
, ctx
, ISA_MIPS32R2
);
3966 gen_op_mtc0_srsconf0();
3970 check_insn(env
, ctx
, ISA_MIPS32R2
);
3971 gen_op_mtc0_srsconf1();
3975 check_insn(env
, ctx
, ISA_MIPS32R2
);
3976 gen_op_mtc0_srsconf2();
3980 check_insn(env
, ctx
, ISA_MIPS32R2
);
3981 gen_op_mtc0_srsconf3();
3985 check_insn(env
, ctx
, ISA_MIPS32R2
);
3986 gen_op_mtc0_srsconf4();
3996 check_insn(env
, ctx
, ISA_MIPS32R2
);
3997 gen_op_mtc0_hwrena();
4011 gen_op_mtc0_count();
4014 /* 6,7 are implementation dependent */
4018 /* Stop translation as we may have switched the execution mode */
4019 ctx
->bstate
= BS_STOP
;
4024 gen_op_mtc0_entryhi();
4034 gen_op_mtc0_compare();
4037 /* 6,7 are implementation dependent */
4041 /* Stop translation as we may have switched the execution mode */
4042 ctx
->bstate
= BS_STOP
;
4047 gen_op_mtc0_status();
4048 /* BS_STOP isn't good enough here, hflags may have changed. */
4049 gen_save_pc(ctx
->pc
+ 4);
4050 ctx
->bstate
= BS_EXCP
;
4054 check_insn(env
, ctx
, ISA_MIPS32R2
);
4055 gen_op_mtc0_intctl();
4056 /* Stop translation as we may have switched the execution mode */
4057 ctx
->bstate
= BS_STOP
;
4061 check_insn(env
, ctx
, ISA_MIPS32R2
);
4062 gen_op_mtc0_srsctl();
4063 /* Stop translation as we may have switched the execution mode */
4064 ctx
->bstate
= BS_STOP
;
4068 check_insn(env
, ctx
, ISA_MIPS32R2
);
4069 gen_op_mtc0_srsmap();
4070 /* Stop translation as we may have switched the execution mode */
4071 ctx
->bstate
= BS_STOP
;
4081 gen_op_mtc0_cause();
4087 /* Stop translation as we may have switched the execution mode */
4088 ctx
->bstate
= BS_STOP
;
4107 check_insn(env
, ctx
, ISA_MIPS32R2
);
4108 gen_op_mtc0_ebase();
4118 gen_op_mtc0_config0();
4120 /* Stop translation as we may have switched the execution mode */
4121 ctx
->bstate
= BS_STOP
;
4128 gen_op_mtc0_config2();
4130 /* Stop translation as we may have switched the execution mode */
4131 ctx
->bstate
= BS_STOP
;
4137 /* 6,7 are implementation dependent */
4139 rn
= "Invalid config selector";
4156 gen_op_mtc0_watchlo(sel
);
4166 gen_op_mtc0_watchhi(sel
);
4176 check_insn(env
, ctx
, ISA_MIPS3
);
4177 gen_op_mtc0_xcontext();
4185 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4188 gen_op_mtc0_framemask();
4197 rn
= "Diagnostic"; /* implementation dependent */
4202 gen_op_mtc0_debug(); /* EJTAG support */
4203 /* BS_STOP isn't good enough here, hflags may have changed. */
4204 gen_save_pc(ctx
->pc
+ 4);
4205 ctx
->bstate
= BS_EXCP
;
4209 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4210 /* Stop translation as we may have switched the execution mode */
4211 ctx
->bstate
= BS_STOP
;
4212 rn
= "TraceControl";
4215 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4216 /* Stop translation as we may have switched the execution mode */
4217 ctx
->bstate
= BS_STOP
;
4218 rn
= "TraceControl2";
4221 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4222 /* Stop translation as we may have switched the execution mode */
4223 ctx
->bstate
= BS_STOP
;
4224 rn
= "UserTraceData";
4227 // gen_op_mtc0_debug(); /* PDtrace support */
4228 /* Stop translation as we may have switched the execution mode */
4229 ctx
->bstate
= BS_STOP
;
4239 gen_op_mtc0_depc(); /* EJTAG support */
4249 gen_op_mtc0_performance0();
4250 rn
= "Performance0";
4253 // gen_op_mtc0_performance1();
4254 rn
= "Performance1";
4257 // gen_op_mtc0_performance2();
4258 rn
= "Performance2";
4261 // gen_op_mtc0_performance3();
4262 rn
= "Performance3";
4265 // gen_op_mtc0_performance4();
4266 rn
= "Performance4";
4269 // gen_op_mtc0_performance5();
4270 rn
= "Performance5";
4273 // gen_op_mtc0_performance6();
4274 rn
= "Performance6";
4277 // gen_op_mtc0_performance7();
4278 rn
= "Performance7";
4304 gen_op_mtc0_taglo();
4311 gen_op_mtc0_datalo();
4324 gen_op_mtc0_taghi();
4331 gen_op_mtc0_datahi();
4342 gen_op_mtc0_errorepc();
4352 gen_op_mtc0_desave(); /* EJTAG support */
4358 /* Stop translation as we may have switched the execution mode */
4359 ctx
->bstate
= BS_STOP
;
4364 #if defined MIPS_DEBUG_DISAS
4365 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4366 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4373 #if defined MIPS_DEBUG_DISAS
4374 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4375 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4379 generate_exception(ctx
, EXCP_RI
);
4381 #endif /* TARGET_MIPS64 */
4383 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4384 int u
, int sel
, int h
)
4386 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4388 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4389 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4390 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4392 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4393 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4400 gen_op_mftc0_tcstatus();
4403 gen_op_mftc0_tcbind();
4406 gen_op_mftc0_tcrestart();
4409 gen_op_mftc0_tchalt();
4412 gen_op_mftc0_tccontext();
4415 gen_op_mftc0_tcschedule();
4418 gen_op_mftc0_tcschefback();
4421 gen_mfc0(env
, ctx
, rt
, sel
);
4428 gen_op_mftc0_entryhi();
4431 gen_mfc0(env
, ctx
, rt
, sel
);
4437 gen_op_mftc0_status();
4440 gen_mfc0(env
, ctx
, rt
, sel
);
4446 gen_op_mftc0_debug();
4449 gen_mfc0(env
, ctx
, rt
, sel
);
4454 gen_mfc0(env
, ctx
, rt
, sel
);
4456 } else switch (sel
) {
4457 /* GPR registers. */
4461 /* Auxiliary CPU registers */
4507 /* Floating point (COP1). */
4509 /* XXX: For now we support only a single FPU context. */
4511 GEN_LOAD_FREG_FTN(WT0
, rt
);
4514 GEN_LOAD_FREG_FTN(WTH0
, rt
);
4519 /* XXX: For now we support only a single FPU context. */
4522 /* COP2: Not implemented. */
4529 #if defined MIPS_DEBUG_DISAS
4530 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4531 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4538 #if defined MIPS_DEBUG_DISAS
4539 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4540 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4544 generate_exception(ctx
, EXCP_RI
);
4547 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
4548 int u
, int sel
, int h
)
4550 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4552 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4553 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4554 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4556 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4557 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4564 gen_op_mttc0_tcstatus();
4567 gen_op_mttc0_tcbind();
4570 gen_op_mttc0_tcrestart();
4573 gen_op_mttc0_tchalt();
4576 gen_op_mttc0_tccontext();
4579 gen_op_mttc0_tcschedule();
4582 gen_op_mttc0_tcschefback();
4585 gen_mtc0(env
, ctx
, rd
, sel
);
4592 gen_op_mttc0_entryhi();
4595 gen_mtc0(env
, ctx
, rd
, sel
);
4601 gen_op_mttc0_status();
4604 gen_mtc0(env
, ctx
, rd
, sel
);
4610 gen_op_mttc0_debug();
4613 gen_mtc0(env
, ctx
, rd
, sel
);
4618 gen_mtc0(env
, ctx
, rd
, sel
);
4620 } else switch (sel
) {
4621 /* GPR registers. */
4625 /* Auxiliary CPU registers */
4671 /* Floating point (COP1). */
4673 /* XXX: For now we support only a single FPU context. */
4676 GEN_STORE_FTN_FREG(rd
, WT0
);
4679 GEN_STORE_FTN_FREG(rd
, WTH0
);
4683 /* XXX: For now we support only a single FPU context. */
4686 /* COP2: Not implemented. */
4693 #if defined MIPS_DEBUG_DISAS
4694 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4695 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4702 #if defined MIPS_DEBUG_DISAS
4703 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4704 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4708 generate_exception(ctx
, EXCP_RI
);
4711 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4713 const char *opn
= "ldst";
4721 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4722 gen_op_store_T0_gpr(rt
);
4726 GEN_LOAD_REG_T0(rt
);
4727 save_cpu_state(ctx
, 1);
4728 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4731 #if defined(TARGET_MIPS64)
4733 check_insn(env
, ctx
, ISA_MIPS3
);
4738 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4739 gen_op_store_T0_gpr(rt
);
4743 check_insn(env
, ctx
, ISA_MIPS3
);
4744 GEN_LOAD_REG_T0(rt
);
4745 save_cpu_state(ctx
, 1);
4746 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4751 check_insn(env
, ctx
, ASE_MT
);
4756 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
4757 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4758 gen_op_store_T0_gpr(rd
);
4762 check_insn(env
, ctx
, ASE_MT
);
4763 GEN_LOAD_REG_T0(rt
);
4764 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
4765 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4770 if (!env
->tlb
->do_tlbwi
)
4776 if (!env
->tlb
->do_tlbwr
)
4782 if (!env
->tlb
->do_tlbp
)
4788 if (!env
->tlb
->do_tlbr
)
4794 check_insn(env
, ctx
, ISA_MIPS2
);
4795 save_cpu_state(ctx
, 1);
4797 ctx
->bstate
= BS_EXCP
;
4801 check_insn(env
, ctx
, ISA_MIPS32
);
4802 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4804 generate_exception(ctx
, EXCP_RI
);
4806 save_cpu_state(ctx
, 1);
4808 ctx
->bstate
= BS_EXCP
;
4813 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
4814 /* If we get an exception, we want to restart at next instruction */
4816 save_cpu_state(ctx
, 1);
4819 ctx
->bstate
= BS_EXCP
;
4824 generate_exception(ctx
, EXCP_RI
);
4827 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4830 /* CP1 Branches (before delay slot) */
4831 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
4832 int32_t cc
, int32_t offset
)
4834 target_ulong btarget
;
4835 const char *opn
= "cp1 cond branch";
4838 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
4840 btarget
= ctx
->pc
+ 4 + offset
;
4859 ctx
->hflags
|= MIPS_HFLAG_BL
;
4860 tcg_gen_set_bcond();
4863 gen_op_bc1any2f(cc
);
4867 gen_op_bc1any2t(cc
);
4871 gen_op_bc1any4f(cc
);
4875 gen_op_bc1any4t(cc
);
4878 ctx
->hflags
|= MIPS_HFLAG_BC
;
4879 tcg_gen_set_bcond();
4883 generate_exception (ctx
, EXCP_RI
);
4886 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4887 ctx
->hflags
, btarget
);
4888 ctx
->btarget
= btarget
;
4891 /* Coprocessor 1 (FPU) */
4893 #define FOP(func, fmt) (((fmt) << 21) | (func))
4895 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4897 const char *opn
= "cp1 move";
4901 GEN_LOAD_FREG_FTN(WT0
, fs
);
4903 GEN_STORE_T0_REG(rt
);
4907 GEN_LOAD_REG_T0(rt
);
4909 GEN_STORE_FTN_FREG(fs
, WT0
);
4914 GEN_STORE_T0_REG(rt
);
4918 GEN_LOAD_REG_T0(rt
);
4923 GEN_LOAD_FREG_FTN(DT0
, fs
);
4925 GEN_STORE_T0_REG(rt
);
4929 GEN_LOAD_REG_T0(rt
);
4931 GEN_STORE_FTN_FREG(fs
, DT0
);
4935 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4937 GEN_STORE_T0_REG(rt
);
4941 GEN_LOAD_REG_T0(rt
);
4943 GEN_STORE_FTN_FREG(fs
, WTH0
);
4948 generate_exception (ctx
, EXCP_RI
);
4951 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4954 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4958 GEN_LOAD_REG_T0(rd
);
4959 GEN_LOAD_REG_T1(rs
);
4961 ccbit
= 1 << (24 + cc
);
4968 GEN_STORE_T0_REG(rd
);
4971 #define GEN_MOVCF(fmt) \
4972 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4977 ccbit = 1 << (24 + cc); \
4981 glue(gen_op_float_movf_, fmt)(ccbit); \
4983 glue(gen_op_float_movt_, fmt)(ccbit); \
4990 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4991 int ft
, int fs
, int fd
, int cc
)
4993 const char *opn
= "farith";
4994 const char *condnames
[] = {
5012 const char *condnames_abs
[] = {
5030 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5031 uint32_t func
= ctx
->opcode
& 0x3f;
5033 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5035 GEN_LOAD_FREG_FTN(WT0
, fs
);
5036 GEN_LOAD_FREG_FTN(WT1
, ft
);
5037 gen_op_float_add_s();
5038 GEN_STORE_FTN_FREG(fd
, WT2
);
5043 GEN_LOAD_FREG_FTN(WT0
, fs
);
5044 GEN_LOAD_FREG_FTN(WT1
, ft
);
5045 gen_op_float_sub_s();
5046 GEN_STORE_FTN_FREG(fd
, WT2
);
5051 GEN_LOAD_FREG_FTN(WT0
, fs
);
5052 GEN_LOAD_FREG_FTN(WT1
, ft
);
5053 gen_op_float_mul_s();
5054 GEN_STORE_FTN_FREG(fd
, WT2
);
5059 GEN_LOAD_FREG_FTN(WT0
, fs
);
5060 GEN_LOAD_FREG_FTN(WT1
, ft
);
5061 gen_op_float_div_s();
5062 GEN_STORE_FTN_FREG(fd
, WT2
);
5067 GEN_LOAD_FREG_FTN(WT0
, fs
);
5068 gen_op_float_sqrt_s();
5069 GEN_STORE_FTN_FREG(fd
, WT2
);
5073 GEN_LOAD_FREG_FTN(WT0
, fs
);
5074 gen_op_float_abs_s();
5075 GEN_STORE_FTN_FREG(fd
, WT2
);
5079 GEN_LOAD_FREG_FTN(WT0
, fs
);
5080 gen_op_float_mov_s();
5081 GEN_STORE_FTN_FREG(fd
, WT2
);
5085 GEN_LOAD_FREG_FTN(WT0
, fs
);
5086 gen_op_float_chs_s();
5087 GEN_STORE_FTN_FREG(fd
, WT2
);
5091 check_cp1_64bitmode(ctx
);
5092 GEN_LOAD_FREG_FTN(WT0
, fs
);
5093 gen_op_float_roundl_s();
5094 GEN_STORE_FTN_FREG(fd
, DT2
);
5098 check_cp1_64bitmode(ctx
);
5099 GEN_LOAD_FREG_FTN(WT0
, fs
);
5100 gen_op_float_truncl_s();
5101 GEN_STORE_FTN_FREG(fd
, DT2
);
5105 check_cp1_64bitmode(ctx
);
5106 GEN_LOAD_FREG_FTN(WT0
, fs
);
5107 gen_op_float_ceill_s();
5108 GEN_STORE_FTN_FREG(fd
, DT2
);
5112 check_cp1_64bitmode(ctx
);
5113 GEN_LOAD_FREG_FTN(WT0
, fs
);
5114 gen_op_float_floorl_s();
5115 GEN_STORE_FTN_FREG(fd
, DT2
);
5119 GEN_LOAD_FREG_FTN(WT0
, fs
);
5120 gen_op_float_roundw_s();
5121 GEN_STORE_FTN_FREG(fd
, WT2
);
5125 GEN_LOAD_FREG_FTN(WT0
, fs
);
5126 gen_op_float_truncw_s();
5127 GEN_STORE_FTN_FREG(fd
, WT2
);
5131 GEN_LOAD_FREG_FTN(WT0
, fs
);
5132 gen_op_float_ceilw_s();
5133 GEN_STORE_FTN_FREG(fd
, WT2
);
5137 GEN_LOAD_FREG_FTN(WT0
, fs
);
5138 gen_op_float_floorw_s();
5139 GEN_STORE_FTN_FREG(fd
, WT2
);
5143 GEN_LOAD_REG_T0(ft
);
5144 GEN_LOAD_FREG_FTN(WT0
, fs
);
5145 GEN_LOAD_FREG_FTN(WT2
, fd
);
5146 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5147 GEN_STORE_FTN_FREG(fd
, WT2
);
5151 GEN_LOAD_REG_T0(ft
);
5152 GEN_LOAD_FREG_FTN(WT0
, fs
);
5153 GEN_LOAD_FREG_FTN(WT2
, fd
);
5154 gen_op_float_movz_s();
5155 GEN_STORE_FTN_FREG(fd
, WT2
);
5159 GEN_LOAD_REG_T0(ft
);
5160 GEN_LOAD_FREG_FTN(WT0
, fs
);
5161 GEN_LOAD_FREG_FTN(WT2
, fd
);
5162 gen_op_float_movn_s();
5163 GEN_STORE_FTN_FREG(fd
, WT2
);
5168 GEN_LOAD_FREG_FTN(WT0
, fs
);
5169 gen_op_float_recip_s();
5170 GEN_STORE_FTN_FREG(fd
, WT2
);
5175 GEN_LOAD_FREG_FTN(WT0
, fs
);
5176 gen_op_float_rsqrt_s();
5177 GEN_STORE_FTN_FREG(fd
, WT2
);
5181 check_cp1_64bitmode(ctx
);
5182 GEN_LOAD_FREG_FTN(WT0
, fs
);
5183 GEN_LOAD_FREG_FTN(WT2
, fd
);
5184 gen_op_float_recip2_s();
5185 GEN_STORE_FTN_FREG(fd
, WT2
);
5189 check_cp1_64bitmode(ctx
);
5190 GEN_LOAD_FREG_FTN(WT0
, fs
);
5191 gen_op_float_recip1_s();
5192 GEN_STORE_FTN_FREG(fd
, WT2
);
5196 check_cp1_64bitmode(ctx
);
5197 GEN_LOAD_FREG_FTN(WT0
, fs
);
5198 gen_op_float_rsqrt1_s();
5199 GEN_STORE_FTN_FREG(fd
, WT2
);
5203 check_cp1_64bitmode(ctx
);
5204 GEN_LOAD_FREG_FTN(WT0
, fs
);
5205 GEN_LOAD_FREG_FTN(WT2
, ft
);
5206 gen_op_float_rsqrt2_s();
5207 GEN_STORE_FTN_FREG(fd
, WT2
);
5211 check_cp1_registers(ctx
, fd
);
5212 GEN_LOAD_FREG_FTN(WT0
, fs
);
5213 gen_op_float_cvtd_s();
5214 GEN_STORE_FTN_FREG(fd
, DT2
);
5218 GEN_LOAD_FREG_FTN(WT0
, fs
);
5219 gen_op_float_cvtw_s();
5220 GEN_STORE_FTN_FREG(fd
, WT2
);
5224 check_cp1_64bitmode(ctx
);
5225 GEN_LOAD_FREG_FTN(WT0
, fs
);
5226 gen_op_float_cvtl_s();
5227 GEN_STORE_FTN_FREG(fd
, DT2
);
5231 check_cp1_64bitmode(ctx
);
5232 GEN_LOAD_FREG_FTN(WT1
, fs
);
5233 GEN_LOAD_FREG_FTN(WT0
, ft
);
5234 gen_op_float_cvtps_s();
5235 GEN_STORE_FTN_FREG(fd
, DT2
);
5254 GEN_LOAD_FREG_FTN(WT0
, fs
);
5255 GEN_LOAD_FREG_FTN(WT1
, ft
);
5256 if (ctx
->opcode
& (1 << 6)) {
5258 gen_cmpabs_s(func
-48, cc
);
5259 opn
= condnames_abs
[func
-48];
5261 gen_cmp_s(func
-48, cc
);
5262 opn
= condnames
[func
-48];
5266 check_cp1_registers(ctx
, fs
| ft
| fd
);
5267 GEN_LOAD_FREG_FTN(DT0
, fs
);
5268 GEN_LOAD_FREG_FTN(DT1
, ft
);
5269 gen_op_float_add_d();
5270 GEN_STORE_FTN_FREG(fd
, DT2
);
5275 check_cp1_registers(ctx
, fs
| ft
| fd
);
5276 GEN_LOAD_FREG_FTN(DT0
, fs
);
5277 GEN_LOAD_FREG_FTN(DT1
, ft
);
5278 gen_op_float_sub_d();
5279 GEN_STORE_FTN_FREG(fd
, DT2
);
5284 check_cp1_registers(ctx
, fs
| ft
| fd
);
5285 GEN_LOAD_FREG_FTN(DT0
, fs
);
5286 GEN_LOAD_FREG_FTN(DT1
, ft
);
5287 gen_op_float_mul_d();
5288 GEN_STORE_FTN_FREG(fd
, DT2
);
5293 check_cp1_registers(ctx
, fs
| ft
| fd
);
5294 GEN_LOAD_FREG_FTN(DT0
, fs
);
5295 GEN_LOAD_FREG_FTN(DT1
, ft
);
5296 gen_op_float_div_d();
5297 GEN_STORE_FTN_FREG(fd
, DT2
);
5302 check_cp1_registers(ctx
, fs
| fd
);
5303 GEN_LOAD_FREG_FTN(DT0
, fs
);
5304 gen_op_float_sqrt_d();
5305 GEN_STORE_FTN_FREG(fd
, DT2
);
5309 check_cp1_registers(ctx
, fs
| fd
);
5310 GEN_LOAD_FREG_FTN(DT0
, fs
);
5311 gen_op_float_abs_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_mov_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_chs_d();
5326 GEN_STORE_FTN_FREG(fd
, DT2
);
5330 check_cp1_64bitmode(ctx
);
5331 GEN_LOAD_FREG_FTN(DT0
, fs
);
5332 gen_op_float_roundl_d();
5333 GEN_STORE_FTN_FREG(fd
, DT2
);
5337 check_cp1_64bitmode(ctx
);
5338 GEN_LOAD_FREG_FTN(DT0
, fs
);
5339 gen_op_float_truncl_d();
5340 GEN_STORE_FTN_FREG(fd
, DT2
);
5344 check_cp1_64bitmode(ctx
);
5345 GEN_LOAD_FREG_FTN(DT0
, fs
);
5346 gen_op_float_ceill_d();
5347 GEN_STORE_FTN_FREG(fd
, DT2
);
5351 check_cp1_64bitmode(ctx
);
5352 GEN_LOAD_FREG_FTN(DT0
, fs
);
5353 gen_op_float_floorl_d();
5354 GEN_STORE_FTN_FREG(fd
, DT2
);
5358 check_cp1_registers(ctx
, fs
);
5359 GEN_LOAD_FREG_FTN(DT0
, fs
);
5360 gen_op_float_roundw_d();
5361 GEN_STORE_FTN_FREG(fd
, WT2
);
5365 check_cp1_registers(ctx
, fs
);
5366 GEN_LOAD_FREG_FTN(DT0
, fs
);
5367 gen_op_float_truncw_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_ceilw_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_floorw_d();
5382 GEN_STORE_FTN_FREG(fd
, WT2
);
5386 GEN_LOAD_REG_T0(ft
);
5387 GEN_LOAD_FREG_FTN(DT0
, fs
);
5388 GEN_LOAD_FREG_FTN(DT2
, fd
);
5389 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5390 GEN_STORE_FTN_FREG(fd
, DT2
);
5394 GEN_LOAD_REG_T0(ft
);
5395 GEN_LOAD_FREG_FTN(DT0
, fs
);
5396 GEN_LOAD_FREG_FTN(DT2
, fd
);
5397 gen_op_float_movz_d();
5398 GEN_STORE_FTN_FREG(fd
, DT2
);
5402 GEN_LOAD_REG_T0(ft
);
5403 GEN_LOAD_FREG_FTN(DT0
, fs
);
5404 GEN_LOAD_FREG_FTN(DT2
, fd
);
5405 gen_op_float_movn_d();
5406 GEN_STORE_FTN_FREG(fd
, DT2
);
5410 check_cp1_64bitmode(ctx
);
5411 GEN_LOAD_FREG_FTN(DT0
, fs
);
5412 gen_op_float_recip_d();
5413 GEN_STORE_FTN_FREG(fd
, DT2
);
5417 check_cp1_64bitmode(ctx
);
5418 GEN_LOAD_FREG_FTN(DT0
, fs
);
5419 gen_op_float_rsqrt_d();
5420 GEN_STORE_FTN_FREG(fd
, DT2
);
5424 check_cp1_64bitmode(ctx
);
5425 GEN_LOAD_FREG_FTN(DT0
, fs
);
5426 GEN_LOAD_FREG_FTN(DT2
, ft
);
5427 gen_op_float_recip2_d();
5428 GEN_STORE_FTN_FREG(fd
, DT2
);
5432 check_cp1_64bitmode(ctx
);
5433 GEN_LOAD_FREG_FTN(DT0
, fs
);
5434 gen_op_float_recip1_d();
5435 GEN_STORE_FTN_FREG(fd
, DT2
);
5439 check_cp1_64bitmode(ctx
);
5440 GEN_LOAD_FREG_FTN(DT0
, fs
);
5441 gen_op_float_rsqrt1_d();
5442 GEN_STORE_FTN_FREG(fd
, DT2
);
5446 check_cp1_64bitmode(ctx
);
5447 GEN_LOAD_FREG_FTN(DT0
, fs
);
5448 GEN_LOAD_FREG_FTN(DT2
, ft
);
5449 gen_op_float_rsqrt2_d();
5450 GEN_STORE_FTN_FREG(fd
, DT2
);
5469 GEN_LOAD_FREG_FTN(DT0
, fs
);
5470 GEN_LOAD_FREG_FTN(DT1
, ft
);
5471 if (ctx
->opcode
& (1 << 6)) {
5473 check_cp1_registers(ctx
, fs
| ft
);
5474 gen_cmpabs_d(func
-48, cc
);
5475 opn
= condnames_abs
[func
-48];
5477 check_cp1_registers(ctx
, fs
| ft
);
5478 gen_cmp_d(func
-48, cc
);
5479 opn
= condnames
[func
-48];
5483 check_cp1_registers(ctx
, fs
);
5484 GEN_LOAD_FREG_FTN(DT0
, fs
);
5485 gen_op_float_cvts_d();
5486 GEN_STORE_FTN_FREG(fd
, WT2
);
5490 check_cp1_registers(ctx
, fs
);
5491 GEN_LOAD_FREG_FTN(DT0
, fs
);
5492 gen_op_float_cvtw_d();
5493 GEN_STORE_FTN_FREG(fd
, WT2
);
5497 check_cp1_64bitmode(ctx
);
5498 GEN_LOAD_FREG_FTN(DT0
, fs
);
5499 gen_op_float_cvtl_d();
5500 GEN_STORE_FTN_FREG(fd
, DT2
);
5504 GEN_LOAD_FREG_FTN(WT0
, fs
);
5505 gen_op_float_cvts_w();
5506 GEN_STORE_FTN_FREG(fd
, WT2
);
5510 check_cp1_registers(ctx
, fd
);
5511 GEN_LOAD_FREG_FTN(WT0
, fs
);
5512 gen_op_float_cvtd_w();
5513 GEN_STORE_FTN_FREG(fd
, DT2
);
5517 check_cp1_64bitmode(ctx
);
5518 GEN_LOAD_FREG_FTN(DT0
, fs
);
5519 gen_op_float_cvts_l();
5520 GEN_STORE_FTN_FREG(fd
, WT2
);
5524 check_cp1_64bitmode(ctx
);
5525 GEN_LOAD_FREG_FTN(DT0
, fs
);
5526 gen_op_float_cvtd_l();
5527 GEN_STORE_FTN_FREG(fd
, DT2
);
5531 check_cp1_64bitmode(ctx
);
5532 GEN_LOAD_FREG_FTN(WT0
, fs
);
5533 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5534 gen_op_float_cvtps_pw();
5535 GEN_STORE_FTN_FREG(fd
, WT2
);
5536 GEN_STORE_FTN_FREG(fd
, WTH2
);
5540 check_cp1_64bitmode(ctx
);
5541 GEN_LOAD_FREG_FTN(WT0
, fs
);
5542 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5543 GEN_LOAD_FREG_FTN(WT1
, ft
);
5544 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5545 gen_op_float_add_ps();
5546 GEN_STORE_FTN_FREG(fd
, WT2
);
5547 GEN_STORE_FTN_FREG(fd
, WTH2
);
5551 check_cp1_64bitmode(ctx
);
5552 GEN_LOAD_FREG_FTN(WT0
, fs
);
5553 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5554 GEN_LOAD_FREG_FTN(WT1
, ft
);
5555 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5556 gen_op_float_sub_ps();
5557 GEN_STORE_FTN_FREG(fd
, WT2
);
5558 GEN_STORE_FTN_FREG(fd
, WTH2
);
5562 check_cp1_64bitmode(ctx
);
5563 GEN_LOAD_FREG_FTN(WT0
, fs
);
5564 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5565 GEN_LOAD_FREG_FTN(WT1
, ft
);
5566 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5567 gen_op_float_mul_ps();
5568 GEN_STORE_FTN_FREG(fd
, WT2
);
5569 GEN_STORE_FTN_FREG(fd
, WTH2
);
5573 check_cp1_64bitmode(ctx
);
5574 GEN_LOAD_FREG_FTN(WT0
, fs
);
5575 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5576 gen_op_float_abs_ps();
5577 GEN_STORE_FTN_FREG(fd
, WT2
);
5578 GEN_STORE_FTN_FREG(fd
, WTH2
);
5582 check_cp1_64bitmode(ctx
);
5583 GEN_LOAD_FREG_FTN(WT0
, fs
);
5584 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5585 gen_op_float_mov_ps();
5586 GEN_STORE_FTN_FREG(fd
, WT2
);
5587 GEN_STORE_FTN_FREG(fd
, WTH2
);
5591 check_cp1_64bitmode(ctx
);
5592 GEN_LOAD_FREG_FTN(WT0
, fs
);
5593 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5594 gen_op_float_chs_ps();
5595 GEN_STORE_FTN_FREG(fd
, WT2
);
5596 GEN_STORE_FTN_FREG(fd
, WTH2
);
5600 check_cp1_64bitmode(ctx
);
5601 GEN_LOAD_REG_T0(ft
);
5602 GEN_LOAD_FREG_FTN(WT0
, fs
);
5603 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5604 GEN_LOAD_FREG_FTN(WT2
, fd
);
5605 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5606 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5607 GEN_STORE_FTN_FREG(fd
, WT2
);
5608 GEN_STORE_FTN_FREG(fd
, WTH2
);
5612 check_cp1_64bitmode(ctx
);
5613 GEN_LOAD_REG_T0(ft
);
5614 GEN_LOAD_FREG_FTN(WT0
, fs
);
5615 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5616 GEN_LOAD_FREG_FTN(WT2
, fd
);
5617 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5618 gen_op_float_movz_ps();
5619 GEN_STORE_FTN_FREG(fd
, WT2
);
5620 GEN_STORE_FTN_FREG(fd
, WTH2
);
5624 check_cp1_64bitmode(ctx
);
5625 GEN_LOAD_REG_T0(ft
);
5626 GEN_LOAD_FREG_FTN(WT0
, fs
);
5627 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5628 GEN_LOAD_FREG_FTN(WT2
, fd
);
5629 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5630 gen_op_float_movn_ps();
5631 GEN_STORE_FTN_FREG(fd
, WT2
);
5632 GEN_STORE_FTN_FREG(fd
, WTH2
);
5636 check_cp1_64bitmode(ctx
);
5637 GEN_LOAD_FREG_FTN(WT0
, ft
);
5638 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5639 GEN_LOAD_FREG_FTN(WT1
, fs
);
5640 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5641 gen_op_float_addr_ps();
5642 GEN_STORE_FTN_FREG(fd
, WT2
);
5643 GEN_STORE_FTN_FREG(fd
, WTH2
);
5647 check_cp1_64bitmode(ctx
);
5648 GEN_LOAD_FREG_FTN(WT0
, ft
);
5649 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5650 GEN_LOAD_FREG_FTN(WT1
, fs
);
5651 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5652 gen_op_float_mulr_ps();
5653 GEN_STORE_FTN_FREG(fd
, WT2
);
5654 GEN_STORE_FTN_FREG(fd
, WTH2
);
5658 check_cp1_64bitmode(ctx
);
5659 GEN_LOAD_FREG_FTN(WT0
, fs
);
5660 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5661 GEN_LOAD_FREG_FTN(WT2
, fd
);
5662 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5663 gen_op_float_recip2_ps();
5664 GEN_STORE_FTN_FREG(fd
, WT2
);
5665 GEN_STORE_FTN_FREG(fd
, WTH2
);
5669 check_cp1_64bitmode(ctx
);
5670 GEN_LOAD_FREG_FTN(WT0
, fs
);
5671 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5672 gen_op_float_recip1_ps();
5673 GEN_STORE_FTN_FREG(fd
, WT2
);
5674 GEN_STORE_FTN_FREG(fd
, WTH2
);
5678 check_cp1_64bitmode(ctx
);
5679 GEN_LOAD_FREG_FTN(WT0
, fs
);
5680 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5681 gen_op_float_rsqrt1_ps();
5682 GEN_STORE_FTN_FREG(fd
, WT2
);
5683 GEN_STORE_FTN_FREG(fd
, WTH2
);
5687 check_cp1_64bitmode(ctx
);
5688 GEN_LOAD_FREG_FTN(WT0
, fs
);
5689 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5690 GEN_LOAD_FREG_FTN(WT2
, ft
);
5691 GEN_LOAD_FREG_FTN(WTH2
, ft
);
5692 gen_op_float_rsqrt2_ps();
5693 GEN_STORE_FTN_FREG(fd
, WT2
);
5694 GEN_STORE_FTN_FREG(fd
, WTH2
);
5698 check_cp1_64bitmode(ctx
);
5699 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5700 gen_op_float_cvts_pu();
5701 GEN_STORE_FTN_FREG(fd
, WT2
);
5705 check_cp1_64bitmode(ctx
);
5706 GEN_LOAD_FREG_FTN(WT0
, fs
);
5707 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5708 gen_op_float_cvtpw_ps();
5709 GEN_STORE_FTN_FREG(fd
, WT2
);
5710 GEN_STORE_FTN_FREG(fd
, WTH2
);
5714 check_cp1_64bitmode(ctx
);
5715 GEN_LOAD_FREG_FTN(WT0
, fs
);
5716 gen_op_float_cvts_pl();
5717 GEN_STORE_FTN_FREG(fd
, WT2
);
5721 check_cp1_64bitmode(ctx
);
5722 GEN_LOAD_FREG_FTN(WT0
, fs
);
5723 GEN_LOAD_FREG_FTN(WT1
, ft
);
5724 gen_op_float_pll_ps();
5725 GEN_STORE_FTN_FREG(fd
, DT2
);
5729 check_cp1_64bitmode(ctx
);
5730 GEN_LOAD_FREG_FTN(WT0
, fs
);
5731 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5732 gen_op_float_plu_ps();
5733 GEN_STORE_FTN_FREG(fd
, DT2
);
5737 check_cp1_64bitmode(ctx
);
5738 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5739 GEN_LOAD_FREG_FTN(WT1
, ft
);
5740 gen_op_float_pul_ps();
5741 GEN_STORE_FTN_FREG(fd
, DT2
);
5745 check_cp1_64bitmode(ctx
);
5746 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5747 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5748 gen_op_float_puu_ps();
5749 GEN_STORE_FTN_FREG(fd
, DT2
);
5768 check_cp1_64bitmode(ctx
);
5769 GEN_LOAD_FREG_FTN(WT0
, fs
);
5770 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5771 GEN_LOAD_FREG_FTN(WT1
, ft
);
5772 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5773 if (ctx
->opcode
& (1 << 6)) {
5774 gen_cmpabs_ps(func
-48, cc
);
5775 opn
= condnames_abs
[func
-48];
5777 gen_cmp_ps(func
-48, cc
);
5778 opn
= condnames
[func
-48];
5783 generate_exception (ctx
, EXCP_RI
);
5788 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5791 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5794 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5799 /* Coprocessor 3 (FPU) */
5800 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5801 int fd
, int fs
, int base
, int index
)
5803 const char *opn
= "extended float load/store";
5810 GEN_LOAD_REG_T0(index
);
5811 } else if (index
== 0) {
5812 GEN_LOAD_REG_T0(base
);
5814 GEN_LOAD_REG_T0(base
);
5815 GEN_LOAD_REG_T1(index
);
5818 /* Don't do NOP if destination is zero: we must perform the actual
5824 GEN_STORE_FTN_FREG(fd
, WT0
);
5829 check_cp1_registers(ctx
, fd
);
5831 GEN_STORE_FTN_FREG(fd
, DT0
);
5835 check_cp1_64bitmode(ctx
);
5837 GEN_STORE_FTN_FREG(fd
, DT0
);
5842 GEN_LOAD_FREG_FTN(WT0
, fs
);
5849 check_cp1_registers(ctx
, fs
);
5850 GEN_LOAD_FREG_FTN(DT0
, fs
);
5856 check_cp1_64bitmode(ctx
);
5857 GEN_LOAD_FREG_FTN(DT0
, fs
);
5864 generate_exception(ctx
, EXCP_RI
);
5867 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5868 regnames
[index
], regnames
[base
]);
5871 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5872 int fd
, int fr
, int fs
, int ft
)
5874 const char *opn
= "flt3_arith";
5878 check_cp1_64bitmode(ctx
);
5879 GEN_LOAD_REG_T0(fr
);
5880 GEN_LOAD_FREG_FTN(DT0
, fs
);
5881 GEN_LOAD_FREG_FTN(DT1
, ft
);
5882 gen_op_float_alnv_ps();
5883 GEN_STORE_FTN_FREG(fd
, DT2
);
5888 GEN_LOAD_FREG_FTN(WT0
, fs
);
5889 GEN_LOAD_FREG_FTN(WT1
, ft
);
5890 GEN_LOAD_FREG_FTN(WT2
, fr
);
5891 gen_op_float_muladd_s();
5892 GEN_STORE_FTN_FREG(fd
, WT2
);
5897 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5898 GEN_LOAD_FREG_FTN(DT0
, fs
);
5899 GEN_LOAD_FREG_FTN(DT1
, ft
);
5900 GEN_LOAD_FREG_FTN(DT2
, fr
);
5901 gen_op_float_muladd_d();
5902 GEN_STORE_FTN_FREG(fd
, DT2
);
5906 check_cp1_64bitmode(ctx
);
5907 GEN_LOAD_FREG_FTN(WT0
, fs
);
5908 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5909 GEN_LOAD_FREG_FTN(WT1
, ft
);
5910 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5911 GEN_LOAD_FREG_FTN(WT2
, fr
);
5912 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5913 gen_op_float_muladd_ps();
5914 GEN_STORE_FTN_FREG(fd
, WT2
);
5915 GEN_STORE_FTN_FREG(fd
, WTH2
);
5920 GEN_LOAD_FREG_FTN(WT0
, fs
);
5921 GEN_LOAD_FREG_FTN(WT1
, ft
);
5922 GEN_LOAD_FREG_FTN(WT2
, fr
);
5923 gen_op_float_mulsub_s();
5924 GEN_STORE_FTN_FREG(fd
, WT2
);
5929 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5930 GEN_LOAD_FREG_FTN(DT0
, fs
);
5931 GEN_LOAD_FREG_FTN(DT1
, ft
);
5932 GEN_LOAD_FREG_FTN(DT2
, fr
);
5933 gen_op_float_mulsub_d();
5934 GEN_STORE_FTN_FREG(fd
, DT2
);
5938 check_cp1_64bitmode(ctx
);
5939 GEN_LOAD_FREG_FTN(WT0
, fs
);
5940 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5941 GEN_LOAD_FREG_FTN(WT1
, ft
);
5942 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5943 GEN_LOAD_FREG_FTN(WT2
, fr
);
5944 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5945 gen_op_float_mulsub_ps();
5946 GEN_STORE_FTN_FREG(fd
, WT2
);
5947 GEN_STORE_FTN_FREG(fd
, WTH2
);
5952 GEN_LOAD_FREG_FTN(WT0
, fs
);
5953 GEN_LOAD_FREG_FTN(WT1
, ft
);
5954 GEN_LOAD_FREG_FTN(WT2
, fr
);
5955 gen_op_float_nmuladd_s();
5956 GEN_STORE_FTN_FREG(fd
, WT2
);
5961 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5962 GEN_LOAD_FREG_FTN(DT0
, fs
);
5963 GEN_LOAD_FREG_FTN(DT1
, ft
);
5964 GEN_LOAD_FREG_FTN(DT2
, fr
);
5965 gen_op_float_nmuladd_d();
5966 GEN_STORE_FTN_FREG(fd
, DT2
);
5970 check_cp1_64bitmode(ctx
);
5971 GEN_LOAD_FREG_FTN(WT0
, fs
);
5972 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5973 GEN_LOAD_FREG_FTN(WT1
, ft
);
5974 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5975 GEN_LOAD_FREG_FTN(WT2
, fr
);
5976 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5977 gen_op_float_nmuladd_ps();
5978 GEN_STORE_FTN_FREG(fd
, WT2
);
5979 GEN_STORE_FTN_FREG(fd
, WTH2
);
5984 GEN_LOAD_FREG_FTN(WT0
, fs
);
5985 GEN_LOAD_FREG_FTN(WT1
, ft
);
5986 GEN_LOAD_FREG_FTN(WT2
, fr
);
5987 gen_op_float_nmulsub_s();
5988 GEN_STORE_FTN_FREG(fd
, WT2
);
5993 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5994 GEN_LOAD_FREG_FTN(DT0
, fs
);
5995 GEN_LOAD_FREG_FTN(DT1
, ft
);
5996 GEN_LOAD_FREG_FTN(DT2
, fr
);
5997 gen_op_float_nmulsub_d();
5998 GEN_STORE_FTN_FREG(fd
, DT2
);
6002 check_cp1_64bitmode(ctx
);
6003 GEN_LOAD_FREG_FTN(WT0
, fs
);
6004 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6005 GEN_LOAD_FREG_FTN(WT1
, ft
);
6006 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6007 GEN_LOAD_FREG_FTN(WT2
, fr
);
6008 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6009 gen_op_float_nmulsub_ps();
6010 GEN_STORE_FTN_FREG(fd
, WT2
);
6011 GEN_STORE_FTN_FREG(fd
, WTH2
);
6016 generate_exception (ctx
, EXCP_RI
);
6019 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6020 fregnames
[fs
], fregnames
[ft
]);
6023 /* ISA extensions (ASEs) */
6024 /* MIPS16 extension to MIPS32 */
6025 /* SmartMIPS extension to MIPS32 */
6027 #if defined(TARGET_MIPS64)
6029 /* MDMX extension to MIPS64 */
6033 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6037 uint32_t op
, op1
, op2
;
6040 /* make sure instructions are on a word boundary */
6041 if (ctx
->pc
& 0x3) {
6042 env
->CP0_BadVAddr
= ctx
->pc
;
6043 generate_exception(ctx
, EXCP_AdEL
);
6047 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6049 /* Handle blikely not taken case */
6050 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6051 l1
= gen_new_label();
6052 tcg_gen_jnz_bcond(l1
);
6053 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6054 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6057 op
= MASK_OP_MAJOR(ctx
->opcode
);
6058 rs
= (ctx
->opcode
>> 21) & 0x1f;
6059 rt
= (ctx
->opcode
>> 16) & 0x1f;
6060 rd
= (ctx
->opcode
>> 11) & 0x1f;
6061 sa
= (ctx
->opcode
>> 6) & 0x1f;
6062 imm
= (int16_t)ctx
->opcode
;
6065 op1
= MASK_SPECIAL(ctx
->opcode
);
6067 case OPC_SLL
: /* Arithmetic with immediate */
6068 case OPC_SRL
... OPC_SRA
:
6069 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6071 case OPC_MOVZ
... OPC_MOVN
:
6072 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6073 case OPC_SLLV
: /* Arithmetic */
6074 case OPC_SRLV
... OPC_SRAV
:
6075 case OPC_ADD
... OPC_NOR
:
6076 case OPC_SLT
... OPC_SLTU
:
6077 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6079 case OPC_MULT
... OPC_DIVU
:
6081 check_insn(env
, ctx
, INSN_VR54XX
);
6082 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6083 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6085 gen_muldiv(ctx
, op1
, rs
, rt
);
6087 case OPC_JR
... OPC_JALR
:
6088 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6090 case OPC_TGE
... OPC_TEQ
: /* Traps */
6092 gen_trap(ctx
, op1
, rs
, rt
, -1);
6094 case OPC_MFHI
: /* Move from HI/LO */
6096 gen_HILO(ctx
, op1
, rd
);
6099 case OPC_MTLO
: /* Move to HI/LO */
6100 gen_HILO(ctx
, op1
, rs
);
6102 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6103 #ifdef MIPS_STRICT_STANDARD
6104 MIPS_INVAL("PMON / selsl");
6105 generate_exception(ctx
, EXCP_RI
);
6111 generate_exception(ctx
, EXCP_SYSCALL
);
6114 generate_exception(ctx
, EXCP_BREAK
);
6117 #ifdef MIPS_STRICT_STANDARD
6119 generate_exception(ctx
, EXCP_RI
);
6121 /* Implemented as RI exception for now. */
6122 MIPS_INVAL("spim (unofficial)");
6123 generate_exception(ctx
, EXCP_RI
);
6131 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6132 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6133 save_cpu_state(ctx
, 1);
6134 check_cp1_enabled(ctx
);
6135 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6136 (ctx
->opcode
>> 16) & 1);
6138 generate_exception_err(ctx
, EXCP_CpU
, 1);
6142 #if defined(TARGET_MIPS64)
6143 /* MIPS64 specific opcodes */
6145 case OPC_DSRL
... OPC_DSRA
:
6147 case OPC_DSRL32
... OPC_DSRA32
:
6148 check_insn(env
, ctx
, ISA_MIPS3
);
6150 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6153 case OPC_DSRLV
... OPC_DSRAV
:
6154 case OPC_DADD
... OPC_DSUBU
:
6155 check_insn(env
, ctx
, ISA_MIPS3
);
6157 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6159 case OPC_DMULT
... OPC_DDIVU
:
6160 check_insn(env
, ctx
, ISA_MIPS3
);
6162 gen_muldiv(ctx
, op1
, rs
, rt
);
6165 default: /* Invalid */
6166 MIPS_INVAL("special");
6167 generate_exception(ctx
, EXCP_RI
);
6172 op1
= MASK_SPECIAL2(ctx
->opcode
);
6174 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6175 case OPC_MSUB
... OPC_MSUBU
:
6176 check_insn(env
, ctx
, ISA_MIPS32
);
6177 gen_muldiv(ctx
, op1
, rs
, rt
);
6180 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6182 case OPC_CLZ
... OPC_CLO
:
6183 check_insn(env
, ctx
, ISA_MIPS32
);
6184 gen_cl(ctx
, op1
, rd
, rs
);
6187 /* XXX: not clear which exception should be raised
6188 * when in debug mode...
6190 check_insn(env
, ctx
, ISA_MIPS32
);
6191 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6192 generate_exception(ctx
, EXCP_DBp
);
6194 generate_exception(ctx
, EXCP_DBp
);
6198 #if defined(TARGET_MIPS64)
6199 case OPC_DCLZ
... OPC_DCLO
:
6200 check_insn(env
, ctx
, ISA_MIPS64
);
6202 gen_cl(ctx
, op1
, rd
, rs
);
6205 default: /* Invalid */
6206 MIPS_INVAL("special2");
6207 generate_exception(ctx
, EXCP_RI
);
6212 op1
= MASK_SPECIAL3(ctx
->opcode
);
6216 check_insn(env
, ctx
, ISA_MIPS32R2
);
6217 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6220 check_insn(env
, ctx
, ISA_MIPS32R2
);
6221 op2
= MASK_BSHFL(ctx
->opcode
);
6224 GEN_LOAD_REG_T1(rt
);
6228 GEN_LOAD_REG_T1(rt
);
6232 GEN_LOAD_REG_T1(rt
);
6235 default: /* Invalid */
6236 MIPS_INVAL("bshfl");
6237 generate_exception(ctx
, EXCP_RI
);
6240 GEN_STORE_T0_REG(rd
);
6243 check_insn(env
, ctx
, ISA_MIPS32R2
);
6246 save_cpu_state(ctx
, 1);
6247 gen_op_rdhwr_cpunum();
6250 save_cpu_state(ctx
, 1);
6251 gen_op_rdhwr_synci_step();
6254 save_cpu_state(ctx
, 1);
6258 save_cpu_state(ctx
, 1);
6259 gen_op_rdhwr_ccres();
6262 #if defined (CONFIG_USER_ONLY)
6266 default: /* Invalid */
6267 MIPS_INVAL("rdhwr");
6268 generate_exception(ctx
, EXCP_RI
);
6271 GEN_STORE_T0_REG(rt
);
6274 check_insn(env
, ctx
, ASE_MT
);
6275 GEN_LOAD_REG_T0(rt
);
6276 GEN_LOAD_REG_T1(rs
);
6280 check_insn(env
, ctx
, ASE_MT
);
6281 GEN_LOAD_REG_T0(rs
);
6283 GEN_STORE_T0_REG(rd
);
6285 #if defined(TARGET_MIPS64)
6286 case OPC_DEXTM
... OPC_DEXT
:
6287 case OPC_DINSM
... OPC_DINS
:
6288 check_insn(env
, ctx
, ISA_MIPS64R2
);
6290 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6293 check_insn(env
, ctx
, ISA_MIPS64R2
);
6295 op2
= MASK_DBSHFL(ctx
->opcode
);
6298 GEN_LOAD_REG_T1(rt
);
6302 GEN_LOAD_REG_T1(rt
);
6305 default: /* Invalid */
6306 MIPS_INVAL("dbshfl");
6307 generate_exception(ctx
, EXCP_RI
);
6310 GEN_STORE_T0_REG(rd
);
6313 default: /* Invalid */
6314 MIPS_INVAL("special3");
6315 generate_exception(ctx
, EXCP_RI
);
6320 op1
= MASK_REGIMM(ctx
->opcode
);
6322 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6323 case OPC_BLTZAL
... OPC_BGEZALL
:
6324 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6326 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6328 gen_trap(ctx
, op1
, rs
, -1, imm
);
6331 check_insn(env
, ctx
, ISA_MIPS32R2
);
6334 default: /* Invalid */
6335 MIPS_INVAL("regimm");
6336 generate_exception(ctx
, EXCP_RI
);
6341 check_cp0_enabled(ctx
);
6342 op1
= MASK_CP0(ctx
->opcode
);
6348 #if defined(TARGET_MIPS64)
6352 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6354 case OPC_C0_FIRST
... OPC_C0_LAST
:
6355 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6358 op2
= MASK_MFMC0(ctx
->opcode
);
6361 check_insn(env
, ctx
, ASE_MT
);
6365 check_insn(env
, ctx
, ASE_MT
);
6369 check_insn(env
, ctx
, ASE_MT
);
6373 check_insn(env
, ctx
, ASE_MT
);
6377 check_insn(env
, ctx
, ISA_MIPS32R2
);
6378 save_cpu_state(ctx
, 1);
6380 /* Stop translation as we may have switched the execution mode */
6381 ctx
->bstate
= BS_STOP
;
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
;
6390 default: /* Invalid */
6391 MIPS_INVAL("mfmc0");
6392 generate_exception(ctx
, EXCP_RI
);
6395 GEN_STORE_T0_REG(rt
);
6398 check_insn(env
, ctx
, ISA_MIPS32R2
);
6399 GEN_LOAD_SRSREG_TN(T0
, rt
);
6400 GEN_STORE_T0_REG(rd
);
6403 check_insn(env
, ctx
, ISA_MIPS32R2
);
6404 GEN_LOAD_REG_T0(rt
);
6405 GEN_STORE_TN_SRSREG(rd
, T0
);
6409 generate_exception(ctx
, EXCP_RI
);
6413 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6414 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6416 case OPC_J
... OPC_JAL
: /* Jump */
6417 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6418 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6420 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6421 case OPC_BEQL
... OPC_BGTZL
:
6422 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6424 case OPC_LB
... OPC_LWR
: /* Load and stores */
6425 case OPC_SB
... OPC_SW
:
6429 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6432 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6436 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6440 /* Floating point (COP1). */
6445 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6446 save_cpu_state(ctx
, 1);
6447 check_cp1_enabled(ctx
);
6448 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6450 generate_exception_err(ctx
, EXCP_CpU
, 1);
6455 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6456 save_cpu_state(ctx
, 1);
6457 check_cp1_enabled(ctx
);
6458 op1
= MASK_CP1(ctx
->opcode
);
6462 check_insn(env
, ctx
, ISA_MIPS32R2
);
6467 gen_cp1(ctx
, op1
, rt
, rd
);
6469 #if defined(TARGET_MIPS64)
6472 check_insn(env
, ctx
, ISA_MIPS3
);
6473 gen_cp1(ctx
, op1
, rt
, rd
);
6479 check_insn(env
, ctx
, ASE_MIPS3D
);
6482 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6483 (rt
>> 2) & 0x7, imm
<< 2);
6490 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
6495 generate_exception (ctx
, EXCP_RI
);
6499 generate_exception_err(ctx
, EXCP_CpU
, 1);
6509 /* COP2: Not implemented. */
6510 generate_exception_err(ctx
, EXCP_CpU
, 2);
6514 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6515 save_cpu_state(ctx
, 1);
6516 check_cp1_enabled(ctx
);
6517 op1
= MASK_CP3(ctx
->opcode
);
6525 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
6543 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
6547 generate_exception (ctx
, EXCP_RI
);
6551 generate_exception_err(ctx
, EXCP_CpU
, 1);
6555 #if defined(TARGET_MIPS64)
6556 /* MIPS64 opcodes */
6558 case OPC_LDL
... OPC_LDR
:
6559 case OPC_SDL
... OPC_SDR
:
6564 check_insn(env
, ctx
, ISA_MIPS3
);
6566 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6568 case OPC_DADDI
... OPC_DADDIU
:
6569 check_insn(env
, ctx
, ISA_MIPS3
);
6571 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6575 check_insn(env
, ctx
, ASE_MIPS16
);
6576 /* MIPS16: Not implemented. */
6578 check_insn(env
, ctx
, ASE_MDMX
);
6579 /* MDMX: Not implemented. */
6580 default: /* Invalid */
6581 MIPS_INVAL("major opcode");
6582 generate_exception(ctx
, EXCP_RI
);
6585 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
6586 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
6587 /* Branches completion */
6588 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
6589 ctx
->bstate
= BS_BRANCH
;
6590 save_cpu_state(ctx
, 0);
6593 /* unconditional branch */
6594 MIPS_DEBUG("unconditional branch");
6595 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6598 /* blikely taken case */
6599 MIPS_DEBUG("blikely branch taken");
6600 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6603 /* Conditional branch */
6604 MIPS_DEBUG("conditional branch");
6607 l1
= gen_new_label();
6608 tcg_gen_jnz_bcond(l1
);
6609 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6611 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6615 /* unconditional branch to register */
6616 MIPS_DEBUG("branch to register");
6621 MIPS_DEBUG("unknown branch");
6627 static always_inline
int
6628 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
6632 target_ulong pc_start
;
6633 uint16_t *gen_opc_end
;
6636 if (search_pc
&& loglevel
)
6637 fprintf (logfile
, "search pc %d\n", search_pc
);
6640 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6644 ctx
.bstate
= BS_NONE
;
6645 /* Restore delay slot state from the tb context. */
6646 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
6647 restore_cpu_state(env
, &ctx
);
6648 #if defined(CONFIG_USER_ONLY)
6649 ctx
.mem_idx
= MIPS_HFLAG_UM
;
6651 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
6654 if (loglevel
& CPU_LOG_TB_CPU
) {
6655 fprintf(logfile
, "------------------------------------------------\n");
6656 /* FIXME: This may print out stale hflags from env... */
6657 cpu_dump_state(env
, logfile
, fprintf
, 0);
6660 #ifdef MIPS_DEBUG_DISAS
6661 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6662 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
6663 tb
, ctx
.mem_idx
, ctx
.hflags
);
6665 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6666 if (env
->nb_breakpoints
> 0) {
6667 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6668 if (env
->breakpoints
[j
] == ctx
.pc
) {
6669 save_cpu_state(&ctx
, 1);
6670 ctx
.bstate
= BS_BRANCH
;
6672 /* Include the breakpoint location or the tb won't
6673 * be flushed when it must be. */
6675 goto done_generating
;
6681 j
= gen_opc_ptr
- gen_opc_buf
;
6685 gen_opc_instr_start
[lj
++] = 0;
6687 gen_opc_pc
[lj
] = ctx
.pc
;
6688 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6689 gen_opc_instr_start
[lj
] = 1;
6691 ctx
.opcode
= ldl_code(ctx
.pc
);
6692 decode_opc(env
, &ctx
);
6695 if (env
->singlestep_enabled
)
6698 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6701 #if defined (MIPS_SINGLE_STEP)
6705 if (env
->singlestep_enabled
) {
6706 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
6709 switch (ctx
.bstate
) {
6711 gen_op_interrupt_restart();
6712 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6715 save_cpu_state(&ctx
, 0);
6716 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6719 gen_op_interrupt_restart();
6728 ctx
.last_T0_store
= NULL
;
6729 *gen_opc_ptr
= INDEX_op_end
;
6731 j
= gen_opc_ptr
- gen_opc_buf
;
6734 gen_opc_instr_start
[lj
++] = 0;
6736 tb
->size
= ctx
.pc
- pc_start
;
6739 #if defined MIPS_DEBUG_DISAS
6740 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6741 fprintf(logfile
, "\n");
6743 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6744 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6745 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6746 fprintf(logfile
, "\n");
6748 if (loglevel
& CPU_LOG_TB_CPU
) {
6749 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6756 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6758 return gen_intermediate_code_internal(env
, tb
, 0);
6761 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6763 return gen_intermediate_code_internal(env
, tb
, 1);
6766 void fpu_dump_state(CPUState
*env
, FILE *f
,
6767 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6771 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6773 #define printfpr(fp) \
6776 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6777 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6778 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6781 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6782 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6783 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6784 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6785 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6790 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6791 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
6792 get_float_exception_flags(&env
->fpu
->fp_status
));
6793 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
6794 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
6795 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
6796 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6797 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6798 printfpr(&env
->fpu
->fpr
[i
]);
6804 void dump_fpu (CPUState
*env
)
6807 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6808 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0], env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
, env
->bcond
);
6809 fpu_dump_state(env
, logfile
, fprintf
, 0);
6813 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6814 /* Debug help: The architecture requires 32bit code to maintain proper
6815 sign-extened values on 64bit machines. */
6817 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6819 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6820 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6825 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
6826 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
6827 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
6828 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
6829 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
6830 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
6831 if (!SIGN_EXT_P(env
->btarget
))
6832 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6834 for (i
= 0; i
< 32; i
++) {
6835 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
6836 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6839 if (!SIGN_EXT_P(env
->CP0_EPC
))
6840 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6841 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6842 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6846 void cpu_dump_state (CPUState
*env
, FILE *f
,
6847 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6852 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",
6853 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6854 for (i
= 0; i
< 32; i
++) {
6856 cpu_fprintf(f
, "GPR%02d:", i
);
6857 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6859 cpu_fprintf(f
, "\n");
6862 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6863 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6864 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6865 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6866 if (env
->hflags
& MIPS_HFLAG_FPU
)
6867 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6868 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6869 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6873 static void mips_tcg_init(void)
6877 /* Initialize various static tables. */
6881 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
6882 current_tc_regs
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG1
, "current_tc_regs");
6883 #if TARGET_LONG_BITS > HOST_LONG_BITS
6884 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
6885 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
6886 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
6887 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
6889 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T0");
6890 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG3
, "T1");
6896 #include "translate_init.c"
6898 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
6901 const mips_def_t
*def
;
6903 def
= cpu_mips_find_by_name(cpu_model
);
6906 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6909 env
->cpu_model
= def
;
6912 env
->cpu_model_str
= cpu_model
;
6918 void cpu_reset (CPUMIPSState
*env
)
6920 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6925 #if !defined(CONFIG_USER_ONLY)
6926 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6927 /* If the exception was raised from a delay slot,
6928 * come back to the jump. */
6929 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
6931 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
6933 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
6935 /* SMP not implemented */
6936 env
->CP0_EBase
= 0x80000000;
6937 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6938 /* vectored interrupts not implemented, timer on int 7,
6939 no performance counters. */
6940 env
->CP0_IntCtl
= 0xe0000000;
6944 for (i
= 0; i
< 7; i
++) {
6945 env
->CP0_WatchLo
[i
] = 0;
6946 env
->CP0_WatchHi
[i
] = 0x80000000;
6948 env
->CP0_WatchLo
[7] = 0;
6949 env
->CP0_WatchHi
[7] = 0;
6951 /* Count register increments in debug mode, EJTAG version 1 */
6952 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6954 env
->exception_index
= EXCP_NONE
;
6955 #if defined(CONFIG_USER_ONLY)
6956 env
->hflags
= MIPS_HFLAG_UM
;
6957 env
->user_mode_only
= 1;
6959 env
->hflags
= MIPS_HFLAG_CP0
;
6961 cpu_mips_register(env
, env
->cpu_model
);
6964 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
6965 unsigned long searched_pc
, int pc_pos
, void *puc
)
6967 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
6968 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
6969 env
->hflags
|= gen_opc_hflags
[pc_pos
];