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 */
2886 /* Stop translation as we may have switched the execution mode */
2887 ctx
->bstate
= BS_STOP
;
2892 gen_op_mtc0_status();
2893 /* BS_STOP isn't good enough here, hflags may have changed. */
2894 gen_save_pc(ctx
->pc
+ 4);
2895 ctx
->bstate
= BS_EXCP
;
2899 check_insn(env
, ctx
, ISA_MIPS32R2
);
2900 gen_op_mtc0_intctl();
2901 /* Stop translation as we may have switched the execution mode */
2902 ctx
->bstate
= BS_STOP
;
2906 check_insn(env
, ctx
, ISA_MIPS32R2
);
2907 gen_op_mtc0_srsctl();
2908 /* Stop translation as we may have switched the execution mode */
2909 ctx
->bstate
= BS_STOP
;
2913 check_insn(env
, ctx
, ISA_MIPS32R2
);
2914 gen_op_mtc0_srsmap();
2915 /* Stop translation as we may have switched the execution mode */
2916 ctx
->bstate
= BS_STOP
;
2926 gen_op_mtc0_cause();
2932 /* Stop translation as we may have switched the execution mode */
2933 ctx
->bstate
= BS_STOP
;
2952 check_insn(env
, ctx
, ISA_MIPS32R2
);
2953 gen_op_mtc0_ebase();
2963 gen_op_mtc0_config0();
2965 /* Stop translation as we may have switched the execution mode */
2966 ctx
->bstate
= BS_STOP
;
2969 /* ignored, read only */
2973 gen_op_mtc0_config2();
2975 /* Stop translation as we may have switched the execution mode */
2976 ctx
->bstate
= BS_STOP
;
2979 /* ignored, read only */
2982 /* 4,5 are reserved */
2983 /* 6,7 are implementation dependent */
2993 rn
= "Invalid config selector";
3010 gen_op_mtc0_watchlo(sel
);
3020 gen_op_mtc0_watchhi(sel
);
3030 #if defined(TARGET_MIPS64)
3031 check_insn(env
, ctx
, ISA_MIPS3
);
3032 gen_op_mtc0_xcontext();
3041 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3044 gen_op_mtc0_framemask();
3053 rn
= "Diagnostic"; /* implementation dependent */
3058 gen_op_mtc0_debug(); /* EJTAG support */
3059 /* BS_STOP isn't good enough here, hflags may have changed. */
3060 gen_save_pc(ctx
->pc
+ 4);
3061 ctx
->bstate
= BS_EXCP
;
3065 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3066 rn
= "TraceControl";
3067 /* Stop translation as we may have switched the execution mode */
3068 ctx
->bstate
= BS_STOP
;
3071 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3072 rn
= "TraceControl2";
3073 /* Stop translation as we may have switched the execution mode */
3074 ctx
->bstate
= BS_STOP
;
3077 /* Stop translation as we may have switched the execution mode */
3078 ctx
->bstate
= BS_STOP
;
3079 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3080 rn
= "UserTraceData";
3081 /* Stop translation as we may have switched the execution mode */
3082 ctx
->bstate
= BS_STOP
;
3085 // gen_op_mtc0_debug(); /* PDtrace support */
3086 /* Stop translation as we may have switched the execution mode */
3087 ctx
->bstate
= BS_STOP
;
3097 gen_op_mtc0_depc(); /* EJTAG support */
3107 gen_op_mtc0_performance0();
3108 rn
= "Performance0";
3111 // gen_op_mtc0_performance1();
3112 rn
= "Performance1";
3115 // gen_op_mtc0_performance2();
3116 rn
= "Performance2";
3119 // gen_op_mtc0_performance3();
3120 rn
= "Performance3";
3123 // gen_op_mtc0_performance4();
3124 rn
= "Performance4";
3127 // gen_op_mtc0_performance5();
3128 rn
= "Performance5";
3131 // gen_op_mtc0_performance6();
3132 rn
= "Performance6";
3135 // gen_op_mtc0_performance7();
3136 rn
= "Performance7";
3162 gen_op_mtc0_taglo();
3169 gen_op_mtc0_datalo();
3182 gen_op_mtc0_taghi();
3189 gen_op_mtc0_datahi();
3200 gen_op_mtc0_errorepc();
3210 gen_op_mtc0_desave(); /* EJTAG support */
3216 /* Stop translation as we may have switched the execution mode */
3217 ctx
->bstate
= BS_STOP
;
3222 #if defined MIPS_DEBUG_DISAS
3223 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3224 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3231 #if defined MIPS_DEBUG_DISAS
3232 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3233 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3237 generate_exception(ctx
, EXCP_RI
);
3240 #if defined(TARGET_MIPS64)
3241 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3243 const char *rn
= "invalid";
3246 check_insn(env
, ctx
, ISA_MIPS64
);
3252 gen_op_mfc0_index();
3256 check_insn(env
, ctx
, ASE_MT
);
3257 gen_op_mfc0_mvpcontrol();
3261 check_insn(env
, ctx
, ASE_MT
);
3262 gen_op_mfc0_mvpconf0();
3266 check_insn(env
, ctx
, ASE_MT
);
3267 gen_op_mfc0_mvpconf1();
3277 gen_op_mfc0_random();
3281 check_insn(env
, ctx
, ASE_MT
);
3282 gen_op_mfc0_vpecontrol();
3286 check_insn(env
, ctx
, ASE_MT
);
3287 gen_op_mfc0_vpeconf0();
3291 check_insn(env
, ctx
, ASE_MT
);
3292 gen_op_mfc0_vpeconf1();
3296 check_insn(env
, ctx
, ASE_MT
);
3297 gen_op_dmfc0_yqmask();
3301 check_insn(env
, ctx
, ASE_MT
);
3302 gen_op_dmfc0_vpeschedule();
3306 check_insn(env
, ctx
, ASE_MT
);
3307 gen_op_dmfc0_vpeschefback();
3308 rn
= "VPEScheFBack";
3311 check_insn(env
, ctx
, ASE_MT
);
3312 gen_op_mfc0_vpeopt();
3322 gen_op_dmfc0_entrylo0();
3326 check_insn(env
, ctx
, ASE_MT
);
3327 gen_op_mfc0_tcstatus();
3331 check_insn(env
, ctx
, ASE_MT
);
3332 gen_op_mfc0_tcbind();
3336 check_insn(env
, ctx
, ASE_MT
);
3337 gen_op_dmfc0_tcrestart();
3341 check_insn(env
, ctx
, ASE_MT
);
3342 gen_op_dmfc0_tchalt();
3346 check_insn(env
, ctx
, ASE_MT
);
3347 gen_op_dmfc0_tccontext();
3351 check_insn(env
, ctx
, ASE_MT
);
3352 gen_op_dmfc0_tcschedule();
3356 check_insn(env
, ctx
, ASE_MT
);
3357 gen_op_dmfc0_tcschefback();
3367 gen_op_dmfc0_entrylo1();
3377 gen_op_dmfc0_context();
3381 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3382 rn
= "ContextConfig";
3391 gen_op_mfc0_pagemask();
3395 check_insn(env
, ctx
, ISA_MIPS32R2
);
3396 gen_op_mfc0_pagegrain();
3406 gen_op_mfc0_wired();
3410 check_insn(env
, ctx
, ISA_MIPS32R2
);
3411 gen_op_mfc0_srsconf0();
3415 check_insn(env
, ctx
, ISA_MIPS32R2
);
3416 gen_op_mfc0_srsconf1();
3420 check_insn(env
, ctx
, ISA_MIPS32R2
);
3421 gen_op_mfc0_srsconf2();
3425 check_insn(env
, ctx
, ISA_MIPS32R2
);
3426 gen_op_mfc0_srsconf3();
3430 check_insn(env
, ctx
, ISA_MIPS32R2
);
3431 gen_op_mfc0_srsconf4();
3441 check_insn(env
, ctx
, ISA_MIPS32R2
);
3442 gen_op_mfc0_hwrena();
3452 gen_op_dmfc0_badvaddr();
3462 gen_op_mfc0_count();
3465 /* 6,7 are implementation dependent */
3473 gen_op_dmfc0_entryhi();
3483 gen_op_mfc0_compare();
3486 /* 6,7 are implementation dependent */
3494 gen_op_mfc0_status();
3498 check_insn(env
, ctx
, ISA_MIPS32R2
);
3499 gen_op_mfc0_intctl();
3503 check_insn(env
, ctx
, ISA_MIPS32R2
);
3504 gen_op_mfc0_srsctl();
3508 check_insn(env
, ctx
, ISA_MIPS32R2
);
3509 gen_op_mfc0_srsmap();
3519 gen_op_mfc0_cause();
3543 check_insn(env
, ctx
, ISA_MIPS32R2
);
3544 gen_op_mfc0_ebase();
3554 gen_op_mfc0_config0();
3558 gen_op_mfc0_config1();
3562 gen_op_mfc0_config2();
3566 gen_op_mfc0_config3();
3569 /* 6,7 are implementation dependent */
3577 gen_op_dmfc0_lladdr();
3587 gen_op_dmfc0_watchlo(sel
);
3597 gen_op_mfc0_watchhi(sel
);
3607 check_insn(env
, ctx
, ISA_MIPS3
);
3608 gen_op_dmfc0_xcontext();
3616 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3619 gen_op_mfc0_framemask();
3628 rn
= "'Diagnostic"; /* implementation dependent */
3633 gen_op_mfc0_debug(); /* EJTAG support */
3637 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3638 rn
= "TraceControl";
3641 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3642 rn
= "TraceControl2";
3645 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3646 rn
= "UserTraceData";
3649 // gen_op_dmfc0_debug(); /* PDtrace support */
3659 gen_op_dmfc0_depc(); /* EJTAG support */
3669 gen_op_mfc0_performance0();
3670 rn
= "Performance0";
3673 // gen_op_dmfc0_performance1();
3674 rn
= "Performance1";
3677 // gen_op_dmfc0_performance2();
3678 rn
= "Performance2";
3681 // gen_op_dmfc0_performance3();
3682 rn
= "Performance3";
3685 // gen_op_dmfc0_performance4();
3686 rn
= "Performance4";
3689 // gen_op_dmfc0_performance5();
3690 rn
= "Performance5";
3693 // gen_op_dmfc0_performance6();
3694 rn
= "Performance6";
3697 // gen_op_dmfc0_performance7();
3698 rn
= "Performance7";
3723 gen_op_mfc0_taglo();
3730 gen_op_mfc0_datalo();
3743 gen_op_mfc0_taghi();
3750 gen_op_mfc0_datahi();
3760 gen_op_dmfc0_errorepc();
3770 gen_op_mfc0_desave(); /* EJTAG support */
3780 #if defined MIPS_DEBUG_DISAS
3781 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3782 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3789 #if defined MIPS_DEBUG_DISAS
3790 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3791 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3795 generate_exception(ctx
, EXCP_RI
);
3798 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3800 const char *rn
= "invalid";
3803 check_insn(env
, ctx
, ISA_MIPS64
);
3809 gen_op_mtc0_index();
3813 check_insn(env
, ctx
, ASE_MT
);
3814 gen_op_mtc0_mvpcontrol();
3818 check_insn(env
, ctx
, ASE_MT
);
3823 check_insn(env
, ctx
, ASE_MT
);
3838 check_insn(env
, ctx
, ASE_MT
);
3839 gen_op_mtc0_vpecontrol();
3843 check_insn(env
, ctx
, ASE_MT
);
3844 gen_op_mtc0_vpeconf0();
3848 check_insn(env
, ctx
, ASE_MT
);
3849 gen_op_mtc0_vpeconf1();
3853 check_insn(env
, ctx
, ASE_MT
);
3854 gen_op_mtc0_yqmask();
3858 check_insn(env
, ctx
, ASE_MT
);
3859 gen_op_mtc0_vpeschedule();
3863 check_insn(env
, ctx
, ASE_MT
);
3864 gen_op_mtc0_vpeschefback();
3865 rn
= "VPEScheFBack";
3868 check_insn(env
, ctx
, ASE_MT
);
3869 gen_op_mtc0_vpeopt();
3879 gen_op_mtc0_entrylo0();
3883 check_insn(env
, ctx
, ASE_MT
);
3884 gen_op_mtc0_tcstatus();
3888 check_insn(env
, ctx
, ASE_MT
);
3889 gen_op_mtc0_tcbind();
3893 check_insn(env
, ctx
, ASE_MT
);
3894 gen_op_mtc0_tcrestart();
3898 check_insn(env
, ctx
, ASE_MT
);
3899 gen_op_mtc0_tchalt();
3903 check_insn(env
, ctx
, ASE_MT
);
3904 gen_op_mtc0_tccontext();
3908 check_insn(env
, ctx
, ASE_MT
);
3909 gen_op_mtc0_tcschedule();
3913 check_insn(env
, ctx
, ASE_MT
);
3914 gen_op_mtc0_tcschefback();
3924 gen_op_mtc0_entrylo1();
3934 gen_op_mtc0_context();
3938 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3939 rn
= "ContextConfig";
3948 gen_op_mtc0_pagemask();
3952 check_insn(env
, ctx
, ISA_MIPS32R2
);
3953 gen_op_mtc0_pagegrain();
3963 gen_op_mtc0_wired();
3967 check_insn(env
, ctx
, ISA_MIPS32R2
);
3968 gen_op_mtc0_srsconf0();
3972 check_insn(env
, ctx
, ISA_MIPS32R2
);
3973 gen_op_mtc0_srsconf1();
3977 check_insn(env
, ctx
, ISA_MIPS32R2
);
3978 gen_op_mtc0_srsconf2();
3982 check_insn(env
, ctx
, ISA_MIPS32R2
);
3983 gen_op_mtc0_srsconf3();
3987 check_insn(env
, ctx
, ISA_MIPS32R2
);
3988 gen_op_mtc0_srsconf4();
3998 check_insn(env
, ctx
, ISA_MIPS32R2
);
3999 gen_op_mtc0_hwrena();
4013 gen_op_mtc0_count();
4016 /* 6,7 are implementation dependent */
4020 /* Stop translation as we may have switched the execution mode */
4021 ctx
->bstate
= BS_STOP
;
4026 gen_op_mtc0_entryhi();
4036 gen_op_mtc0_compare();
4039 /* 6,7 are implementation dependent */
4043 /* Stop translation as we may have switched the execution mode */
4044 ctx
->bstate
= BS_STOP
;
4049 gen_op_mtc0_status();
4050 /* BS_STOP isn't good enough here, hflags may have changed. */
4051 gen_save_pc(ctx
->pc
+ 4);
4052 ctx
->bstate
= BS_EXCP
;
4056 check_insn(env
, ctx
, ISA_MIPS32R2
);
4057 gen_op_mtc0_intctl();
4058 /* Stop translation as we may have switched the execution mode */
4059 ctx
->bstate
= BS_STOP
;
4063 check_insn(env
, ctx
, ISA_MIPS32R2
);
4064 gen_op_mtc0_srsctl();
4065 /* Stop translation as we may have switched the execution mode */
4066 ctx
->bstate
= BS_STOP
;
4070 check_insn(env
, ctx
, ISA_MIPS32R2
);
4071 gen_op_mtc0_srsmap();
4072 /* Stop translation as we may have switched the execution mode */
4073 ctx
->bstate
= BS_STOP
;
4083 gen_op_mtc0_cause();
4089 /* Stop translation as we may have switched the execution mode */
4090 ctx
->bstate
= BS_STOP
;
4109 check_insn(env
, ctx
, ISA_MIPS32R2
);
4110 gen_op_mtc0_ebase();
4120 gen_op_mtc0_config0();
4122 /* Stop translation as we may have switched the execution mode */
4123 ctx
->bstate
= BS_STOP
;
4130 gen_op_mtc0_config2();
4132 /* Stop translation as we may have switched the execution mode */
4133 ctx
->bstate
= BS_STOP
;
4139 /* 6,7 are implementation dependent */
4141 rn
= "Invalid config selector";
4158 gen_op_mtc0_watchlo(sel
);
4168 gen_op_mtc0_watchhi(sel
);
4178 check_insn(env
, ctx
, ISA_MIPS3
);
4179 gen_op_mtc0_xcontext();
4187 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4190 gen_op_mtc0_framemask();
4199 rn
= "Diagnostic"; /* implementation dependent */
4204 gen_op_mtc0_debug(); /* EJTAG support */
4205 /* BS_STOP isn't good enough here, hflags may have changed. */
4206 gen_save_pc(ctx
->pc
+ 4);
4207 ctx
->bstate
= BS_EXCP
;
4211 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4212 /* Stop translation as we may have switched the execution mode */
4213 ctx
->bstate
= BS_STOP
;
4214 rn
= "TraceControl";
4217 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4218 /* Stop translation as we may have switched the execution mode */
4219 ctx
->bstate
= BS_STOP
;
4220 rn
= "TraceControl2";
4223 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4224 /* Stop translation as we may have switched the execution mode */
4225 ctx
->bstate
= BS_STOP
;
4226 rn
= "UserTraceData";
4229 // gen_op_mtc0_debug(); /* PDtrace support */
4230 /* Stop translation as we may have switched the execution mode */
4231 ctx
->bstate
= BS_STOP
;
4241 gen_op_mtc0_depc(); /* EJTAG support */
4251 gen_op_mtc0_performance0();
4252 rn
= "Performance0";
4255 // gen_op_mtc0_performance1();
4256 rn
= "Performance1";
4259 // gen_op_mtc0_performance2();
4260 rn
= "Performance2";
4263 // gen_op_mtc0_performance3();
4264 rn
= "Performance3";
4267 // gen_op_mtc0_performance4();
4268 rn
= "Performance4";
4271 // gen_op_mtc0_performance5();
4272 rn
= "Performance5";
4275 // gen_op_mtc0_performance6();
4276 rn
= "Performance6";
4279 // gen_op_mtc0_performance7();
4280 rn
= "Performance7";
4306 gen_op_mtc0_taglo();
4313 gen_op_mtc0_datalo();
4326 gen_op_mtc0_taghi();
4333 gen_op_mtc0_datahi();
4344 gen_op_mtc0_errorepc();
4354 gen_op_mtc0_desave(); /* EJTAG support */
4360 /* Stop translation as we may have switched the execution mode */
4361 ctx
->bstate
= BS_STOP
;
4366 #if defined MIPS_DEBUG_DISAS
4367 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4368 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4375 #if defined MIPS_DEBUG_DISAS
4376 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4377 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4381 generate_exception(ctx
, EXCP_RI
);
4383 #endif /* TARGET_MIPS64 */
4385 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4386 int u
, int sel
, int h
)
4388 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4390 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4391 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4392 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4394 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4395 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4402 gen_op_mftc0_tcstatus();
4405 gen_op_mftc0_tcbind();
4408 gen_op_mftc0_tcrestart();
4411 gen_op_mftc0_tchalt();
4414 gen_op_mftc0_tccontext();
4417 gen_op_mftc0_tcschedule();
4420 gen_op_mftc0_tcschefback();
4423 gen_mfc0(env
, ctx
, rt
, sel
);
4430 gen_op_mftc0_entryhi();
4433 gen_mfc0(env
, ctx
, rt
, sel
);
4439 gen_op_mftc0_status();
4442 gen_mfc0(env
, ctx
, rt
, sel
);
4448 gen_op_mftc0_debug();
4451 gen_mfc0(env
, ctx
, rt
, sel
);
4456 gen_mfc0(env
, ctx
, rt
, sel
);
4458 } else switch (sel
) {
4459 /* GPR registers. */
4463 /* Auxiliary CPU registers */
4509 /* Floating point (COP1). */
4511 /* XXX: For now we support only a single FPU context. */
4513 GEN_LOAD_FREG_FTN(WT0
, rt
);
4516 GEN_LOAD_FREG_FTN(WTH0
, rt
);
4521 /* XXX: For now we support only a single FPU context. */
4524 /* COP2: Not implemented. */
4531 #if defined MIPS_DEBUG_DISAS
4532 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4533 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4540 #if defined MIPS_DEBUG_DISAS
4541 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4542 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4546 generate_exception(ctx
, EXCP_RI
);
4549 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
4550 int u
, int sel
, int h
)
4552 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4554 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4555 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4556 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4558 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4559 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4566 gen_op_mttc0_tcstatus();
4569 gen_op_mttc0_tcbind();
4572 gen_op_mttc0_tcrestart();
4575 gen_op_mttc0_tchalt();
4578 gen_op_mttc0_tccontext();
4581 gen_op_mttc0_tcschedule();
4584 gen_op_mttc0_tcschefback();
4587 gen_mtc0(env
, ctx
, rd
, sel
);
4594 gen_op_mttc0_entryhi();
4597 gen_mtc0(env
, ctx
, rd
, sel
);
4603 gen_op_mttc0_status();
4606 gen_mtc0(env
, ctx
, rd
, sel
);
4612 gen_op_mttc0_debug();
4615 gen_mtc0(env
, ctx
, rd
, sel
);
4620 gen_mtc0(env
, ctx
, rd
, sel
);
4622 } else switch (sel
) {
4623 /* GPR registers. */
4627 /* Auxiliary CPU registers */
4673 /* Floating point (COP1). */
4675 /* XXX: For now we support only a single FPU context. */
4678 GEN_STORE_FTN_FREG(rd
, WT0
);
4681 GEN_STORE_FTN_FREG(rd
, WTH0
);
4685 /* XXX: For now we support only a single FPU context. */
4688 /* COP2: Not implemented. */
4695 #if defined MIPS_DEBUG_DISAS
4696 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4697 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4704 #if defined MIPS_DEBUG_DISAS
4705 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4706 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4710 generate_exception(ctx
, EXCP_RI
);
4713 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4715 const char *opn
= "ldst";
4723 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4724 gen_op_store_T0_gpr(rt
);
4728 GEN_LOAD_REG_T0(rt
);
4729 save_cpu_state(ctx
, 1);
4730 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4733 #if defined(TARGET_MIPS64)
4735 check_insn(env
, ctx
, ISA_MIPS3
);
4740 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4741 gen_op_store_T0_gpr(rt
);
4745 check_insn(env
, ctx
, ISA_MIPS3
);
4746 GEN_LOAD_REG_T0(rt
);
4747 save_cpu_state(ctx
, 1);
4748 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4753 check_insn(env
, ctx
, ASE_MT
);
4758 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
4759 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4760 gen_op_store_T0_gpr(rd
);
4764 check_insn(env
, ctx
, ASE_MT
);
4765 GEN_LOAD_REG_T0(rt
);
4766 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
4767 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4772 if (!env
->tlb
->do_tlbwi
)
4778 if (!env
->tlb
->do_tlbwr
)
4784 if (!env
->tlb
->do_tlbp
)
4790 if (!env
->tlb
->do_tlbr
)
4796 check_insn(env
, ctx
, ISA_MIPS2
);
4797 save_cpu_state(ctx
, 1);
4799 ctx
->bstate
= BS_EXCP
;
4803 check_insn(env
, ctx
, ISA_MIPS32
);
4804 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4806 generate_exception(ctx
, EXCP_RI
);
4808 save_cpu_state(ctx
, 1);
4810 ctx
->bstate
= BS_EXCP
;
4815 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
4816 /* If we get an exception, we want to restart at next instruction */
4818 save_cpu_state(ctx
, 1);
4821 ctx
->bstate
= BS_EXCP
;
4826 generate_exception(ctx
, EXCP_RI
);
4829 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4832 /* CP1 Branches (before delay slot) */
4833 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
4834 int32_t cc
, int32_t offset
)
4836 target_ulong btarget
;
4837 const char *opn
= "cp1 cond branch";
4840 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
4842 btarget
= ctx
->pc
+ 4 + offset
;
4861 ctx
->hflags
|= MIPS_HFLAG_BL
;
4862 tcg_gen_set_bcond();
4865 gen_op_bc1any2f(cc
);
4869 gen_op_bc1any2t(cc
);
4873 gen_op_bc1any4f(cc
);
4877 gen_op_bc1any4t(cc
);
4880 ctx
->hflags
|= MIPS_HFLAG_BC
;
4881 tcg_gen_set_bcond();
4885 generate_exception (ctx
, EXCP_RI
);
4888 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4889 ctx
->hflags
, btarget
);
4890 ctx
->btarget
= btarget
;
4893 /* Coprocessor 1 (FPU) */
4895 #define FOP(func, fmt) (((fmt) << 21) | (func))
4897 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4899 const char *opn
= "cp1 move";
4903 GEN_LOAD_FREG_FTN(WT0
, fs
);
4905 GEN_STORE_T0_REG(rt
);
4909 GEN_LOAD_REG_T0(rt
);
4911 GEN_STORE_FTN_FREG(fs
, WT0
);
4916 GEN_STORE_T0_REG(rt
);
4920 GEN_LOAD_REG_T0(rt
);
4925 GEN_LOAD_FREG_FTN(DT0
, fs
);
4927 GEN_STORE_T0_REG(rt
);
4931 GEN_LOAD_REG_T0(rt
);
4933 GEN_STORE_FTN_FREG(fs
, DT0
);
4937 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4939 GEN_STORE_T0_REG(rt
);
4943 GEN_LOAD_REG_T0(rt
);
4945 GEN_STORE_FTN_FREG(fs
, WTH0
);
4950 generate_exception (ctx
, EXCP_RI
);
4953 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4956 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4960 GEN_LOAD_REG_T0(rd
);
4961 GEN_LOAD_REG_T1(rs
);
4963 ccbit
= 1 << (24 + cc
);
4970 GEN_STORE_T0_REG(rd
);
4973 #define GEN_MOVCF(fmt) \
4974 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4979 ccbit = 1 << (24 + cc); \
4983 glue(gen_op_float_movf_, fmt)(ccbit); \
4985 glue(gen_op_float_movt_, fmt)(ccbit); \
4992 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4993 int ft
, int fs
, int fd
, int cc
)
4995 const char *opn
= "farith";
4996 const char *condnames
[] = {
5014 const char *condnames_abs
[] = {
5032 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5033 uint32_t func
= ctx
->opcode
& 0x3f;
5035 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5037 GEN_LOAD_FREG_FTN(WT0
, fs
);
5038 GEN_LOAD_FREG_FTN(WT1
, ft
);
5039 gen_op_float_add_s();
5040 GEN_STORE_FTN_FREG(fd
, WT2
);
5045 GEN_LOAD_FREG_FTN(WT0
, fs
);
5046 GEN_LOAD_FREG_FTN(WT1
, ft
);
5047 gen_op_float_sub_s();
5048 GEN_STORE_FTN_FREG(fd
, WT2
);
5053 GEN_LOAD_FREG_FTN(WT0
, fs
);
5054 GEN_LOAD_FREG_FTN(WT1
, ft
);
5055 gen_op_float_mul_s();
5056 GEN_STORE_FTN_FREG(fd
, WT2
);
5061 GEN_LOAD_FREG_FTN(WT0
, fs
);
5062 GEN_LOAD_FREG_FTN(WT1
, ft
);
5063 gen_op_float_div_s();
5064 GEN_STORE_FTN_FREG(fd
, WT2
);
5069 GEN_LOAD_FREG_FTN(WT0
, fs
);
5070 gen_op_float_sqrt_s();
5071 GEN_STORE_FTN_FREG(fd
, WT2
);
5075 GEN_LOAD_FREG_FTN(WT0
, fs
);
5076 gen_op_float_abs_s();
5077 GEN_STORE_FTN_FREG(fd
, WT2
);
5081 GEN_LOAD_FREG_FTN(WT0
, fs
);
5082 gen_op_float_mov_s();
5083 GEN_STORE_FTN_FREG(fd
, WT2
);
5087 GEN_LOAD_FREG_FTN(WT0
, fs
);
5088 gen_op_float_chs_s();
5089 GEN_STORE_FTN_FREG(fd
, WT2
);
5093 check_cp1_64bitmode(ctx
);
5094 GEN_LOAD_FREG_FTN(WT0
, fs
);
5095 gen_op_float_roundl_s();
5096 GEN_STORE_FTN_FREG(fd
, DT2
);
5100 check_cp1_64bitmode(ctx
);
5101 GEN_LOAD_FREG_FTN(WT0
, fs
);
5102 gen_op_float_truncl_s();
5103 GEN_STORE_FTN_FREG(fd
, DT2
);
5107 check_cp1_64bitmode(ctx
);
5108 GEN_LOAD_FREG_FTN(WT0
, fs
);
5109 gen_op_float_ceill_s();
5110 GEN_STORE_FTN_FREG(fd
, DT2
);
5114 check_cp1_64bitmode(ctx
);
5115 GEN_LOAD_FREG_FTN(WT0
, fs
);
5116 gen_op_float_floorl_s();
5117 GEN_STORE_FTN_FREG(fd
, DT2
);
5121 GEN_LOAD_FREG_FTN(WT0
, fs
);
5122 gen_op_float_roundw_s();
5123 GEN_STORE_FTN_FREG(fd
, WT2
);
5127 GEN_LOAD_FREG_FTN(WT0
, fs
);
5128 gen_op_float_truncw_s();
5129 GEN_STORE_FTN_FREG(fd
, WT2
);
5133 GEN_LOAD_FREG_FTN(WT0
, fs
);
5134 gen_op_float_ceilw_s();
5135 GEN_STORE_FTN_FREG(fd
, WT2
);
5139 GEN_LOAD_FREG_FTN(WT0
, fs
);
5140 gen_op_float_floorw_s();
5141 GEN_STORE_FTN_FREG(fd
, WT2
);
5145 GEN_LOAD_REG_T0(ft
);
5146 GEN_LOAD_FREG_FTN(WT0
, fs
);
5147 GEN_LOAD_FREG_FTN(WT2
, fd
);
5148 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5149 GEN_STORE_FTN_FREG(fd
, WT2
);
5153 GEN_LOAD_REG_T0(ft
);
5154 GEN_LOAD_FREG_FTN(WT0
, fs
);
5155 GEN_LOAD_FREG_FTN(WT2
, fd
);
5156 gen_op_float_movz_s();
5157 GEN_STORE_FTN_FREG(fd
, WT2
);
5161 GEN_LOAD_REG_T0(ft
);
5162 GEN_LOAD_FREG_FTN(WT0
, fs
);
5163 GEN_LOAD_FREG_FTN(WT2
, fd
);
5164 gen_op_float_movn_s();
5165 GEN_STORE_FTN_FREG(fd
, WT2
);
5170 GEN_LOAD_FREG_FTN(WT0
, fs
);
5171 gen_op_float_recip_s();
5172 GEN_STORE_FTN_FREG(fd
, WT2
);
5177 GEN_LOAD_FREG_FTN(WT0
, fs
);
5178 gen_op_float_rsqrt_s();
5179 GEN_STORE_FTN_FREG(fd
, WT2
);
5183 check_cp1_64bitmode(ctx
);
5184 GEN_LOAD_FREG_FTN(WT0
, fs
);
5185 GEN_LOAD_FREG_FTN(WT2
, fd
);
5186 gen_op_float_recip2_s();
5187 GEN_STORE_FTN_FREG(fd
, WT2
);
5191 check_cp1_64bitmode(ctx
);
5192 GEN_LOAD_FREG_FTN(WT0
, fs
);
5193 gen_op_float_recip1_s();
5194 GEN_STORE_FTN_FREG(fd
, WT2
);
5198 check_cp1_64bitmode(ctx
);
5199 GEN_LOAD_FREG_FTN(WT0
, fs
);
5200 gen_op_float_rsqrt1_s();
5201 GEN_STORE_FTN_FREG(fd
, WT2
);
5205 check_cp1_64bitmode(ctx
);
5206 GEN_LOAD_FREG_FTN(WT0
, fs
);
5207 GEN_LOAD_FREG_FTN(WT2
, ft
);
5208 gen_op_float_rsqrt2_s();
5209 GEN_STORE_FTN_FREG(fd
, WT2
);
5213 check_cp1_registers(ctx
, fd
);
5214 GEN_LOAD_FREG_FTN(WT0
, fs
);
5215 gen_op_float_cvtd_s();
5216 GEN_STORE_FTN_FREG(fd
, DT2
);
5220 GEN_LOAD_FREG_FTN(WT0
, fs
);
5221 gen_op_float_cvtw_s();
5222 GEN_STORE_FTN_FREG(fd
, WT2
);
5226 check_cp1_64bitmode(ctx
);
5227 GEN_LOAD_FREG_FTN(WT0
, fs
);
5228 gen_op_float_cvtl_s();
5229 GEN_STORE_FTN_FREG(fd
, DT2
);
5233 check_cp1_64bitmode(ctx
);
5234 GEN_LOAD_FREG_FTN(WT1
, fs
);
5235 GEN_LOAD_FREG_FTN(WT0
, ft
);
5236 gen_op_float_cvtps_s();
5237 GEN_STORE_FTN_FREG(fd
, DT2
);
5256 GEN_LOAD_FREG_FTN(WT0
, fs
);
5257 GEN_LOAD_FREG_FTN(WT1
, ft
);
5258 if (ctx
->opcode
& (1 << 6)) {
5260 gen_cmpabs_s(func
-48, cc
);
5261 opn
= condnames_abs
[func
-48];
5263 gen_cmp_s(func
-48, cc
);
5264 opn
= condnames
[func
-48];
5268 check_cp1_registers(ctx
, fs
| ft
| fd
);
5269 GEN_LOAD_FREG_FTN(DT0
, fs
);
5270 GEN_LOAD_FREG_FTN(DT1
, ft
);
5271 gen_op_float_add_d();
5272 GEN_STORE_FTN_FREG(fd
, DT2
);
5277 check_cp1_registers(ctx
, fs
| ft
| fd
);
5278 GEN_LOAD_FREG_FTN(DT0
, fs
);
5279 GEN_LOAD_FREG_FTN(DT1
, ft
);
5280 gen_op_float_sub_d();
5281 GEN_STORE_FTN_FREG(fd
, DT2
);
5286 check_cp1_registers(ctx
, fs
| ft
| fd
);
5287 GEN_LOAD_FREG_FTN(DT0
, fs
);
5288 GEN_LOAD_FREG_FTN(DT1
, ft
);
5289 gen_op_float_mul_d();
5290 GEN_STORE_FTN_FREG(fd
, DT2
);
5295 check_cp1_registers(ctx
, fs
| ft
| fd
);
5296 GEN_LOAD_FREG_FTN(DT0
, fs
);
5297 GEN_LOAD_FREG_FTN(DT1
, ft
);
5298 gen_op_float_div_d();
5299 GEN_STORE_FTN_FREG(fd
, DT2
);
5304 check_cp1_registers(ctx
, fs
| fd
);
5305 GEN_LOAD_FREG_FTN(DT0
, fs
);
5306 gen_op_float_sqrt_d();
5307 GEN_STORE_FTN_FREG(fd
, DT2
);
5311 check_cp1_registers(ctx
, fs
| fd
);
5312 GEN_LOAD_FREG_FTN(DT0
, fs
);
5313 gen_op_float_abs_d();
5314 GEN_STORE_FTN_FREG(fd
, DT2
);
5318 check_cp1_registers(ctx
, fs
| fd
);
5319 GEN_LOAD_FREG_FTN(DT0
, fs
);
5320 gen_op_float_mov_d();
5321 GEN_STORE_FTN_FREG(fd
, DT2
);
5325 check_cp1_registers(ctx
, fs
| fd
);
5326 GEN_LOAD_FREG_FTN(DT0
, fs
);
5327 gen_op_float_chs_d();
5328 GEN_STORE_FTN_FREG(fd
, DT2
);
5332 check_cp1_64bitmode(ctx
);
5333 GEN_LOAD_FREG_FTN(DT0
, fs
);
5334 gen_op_float_roundl_d();
5335 GEN_STORE_FTN_FREG(fd
, DT2
);
5339 check_cp1_64bitmode(ctx
);
5340 GEN_LOAD_FREG_FTN(DT0
, fs
);
5341 gen_op_float_truncl_d();
5342 GEN_STORE_FTN_FREG(fd
, DT2
);
5346 check_cp1_64bitmode(ctx
);
5347 GEN_LOAD_FREG_FTN(DT0
, fs
);
5348 gen_op_float_ceill_d();
5349 GEN_STORE_FTN_FREG(fd
, DT2
);
5353 check_cp1_64bitmode(ctx
);
5354 GEN_LOAD_FREG_FTN(DT0
, fs
);
5355 gen_op_float_floorl_d();
5356 GEN_STORE_FTN_FREG(fd
, DT2
);
5360 check_cp1_registers(ctx
, fs
);
5361 GEN_LOAD_FREG_FTN(DT0
, fs
);
5362 gen_op_float_roundw_d();
5363 GEN_STORE_FTN_FREG(fd
, WT2
);
5367 check_cp1_registers(ctx
, fs
);
5368 GEN_LOAD_FREG_FTN(DT0
, fs
);
5369 gen_op_float_truncw_d();
5370 GEN_STORE_FTN_FREG(fd
, WT2
);
5374 check_cp1_registers(ctx
, fs
);
5375 GEN_LOAD_FREG_FTN(DT0
, fs
);
5376 gen_op_float_ceilw_d();
5377 GEN_STORE_FTN_FREG(fd
, WT2
);
5381 check_cp1_registers(ctx
, fs
);
5382 GEN_LOAD_FREG_FTN(DT0
, fs
);
5383 gen_op_float_floorw_d();
5384 GEN_STORE_FTN_FREG(fd
, WT2
);
5388 GEN_LOAD_REG_T0(ft
);
5389 GEN_LOAD_FREG_FTN(DT0
, fs
);
5390 GEN_LOAD_FREG_FTN(DT2
, fd
);
5391 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5392 GEN_STORE_FTN_FREG(fd
, DT2
);
5396 GEN_LOAD_REG_T0(ft
);
5397 GEN_LOAD_FREG_FTN(DT0
, fs
);
5398 GEN_LOAD_FREG_FTN(DT2
, fd
);
5399 gen_op_float_movz_d();
5400 GEN_STORE_FTN_FREG(fd
, DT2
);
5404 GEN_LOAD_REG_T0(ft
);
5405 GEN_LOAD_FREG_FTN(DT0
, fs
);
5406 GEN_LOAD_FREG_FTN(DT2
, fd
);
5407 gen_op_float_movn_d();
5408 GEN_STORE_FTN_FREG(fd
, DT2
);
5412 check_cp1_64bitmode(ctx
);
5413 GEN_LOAD_FREG_FTN(DT0
, fs
);
5414 gen_op_float_recip_d();
5415 GEN_STORE_FTN_FREG(fd
, DT2
);
5419 check_cp1_64bitmode(ctx
);
5420 GEN_LOAD_FREG_FTN(DT0
, fs
);
5421 gen_op_float_rsqrt_d();
5422 GEN_STORE_FTN_FREG(fd
, DT2
);
5426 check_cp1_64bitmode(ctx
);
5427 GEN_LOAD_FREG_FTN(DT0
, fs
);
5428 GEN_LOAD_FREG_FTN(DT2
, ft
);
5429 gen_op_float_recip2_d();
5430 GEN_STORE_FTN_FREG(fd
, DT2
);
5434 check_cp1_64bitmode(ctx
);
5435 GEN_LOAD_FREG_FTN(DT0
, fs
);
5436 gen_op_float_recip1_d();
5437 GEN_STORE_FTN_FREG(fd
, DT2
);
5441 check_cp1_64bitmode(ctx
);
5442 GEN_LOAD_FREG_FTN(DT0
, fs
);
5443 gen_op_float_rsqrt1_d();
5444 GEN_STORE_FTN_FREG(fd
, DT2
);
5448 check_cp1_64bitmode(ctx
);
5449 GEN_LOAD_FREG_FTN(DT0
, fs
);
5450 GEN_LOAD_FREG_FTN(DT2
, ft
);
5451 gen_op_float_rsqrt2_d();
5452 GEN_STORE_FTN_FREG(fd
, DT2
);
5471 GEN_LOAD_FREG_FTN(DT0
, fs
);
5472 GEN_LOAD_FREG_FTN(DT1
, ft
);
5473 if (ctx
->opcode
& (1 << 6)) {
5475 check_cp1_registers(ctx
, fs
| ft
);
5476 gen_cmpabs_d(func
-48, cc
);
5477 opn
= condnames_abs
[func
-48];
5479 check_cp1_registers(ctx
, fs
| ft
);
5480 gen_cmp_d(func
-48, cc
);
5481 opn
= condnames
[func
-48];
5485 check_cp1_registers(ctx
, fs
);
5486 GEN_LOAD_FREG_FTN(DT0
, fs
);
5487 gen_op_float_cvts_d();
5488 GEN_STORE_FTN_FREG(fd
, WT2
);
5492 check_cp1_registers(ctx
, fs
);
5493 GEN_LOAD_FREG_FTN(DT0
, fs
);
5494 gen_op_float_cvtw_d();
5495 GEN_STORE_FTN_FREG(fd
, WT2
);
5499 check_cp1_64bitmode(ctx
);
5500 GEN_LOAD_FREG_FTN(DT0
, fs
);
5501 gen_op_float_cvtl_d();
5502 GEN_STORE_FTN_FREG(fd
, DT2
);
5506 GEN_LOAD_FREG_FTN(WT0
, fs
);
5507 gen_op_float_cvts_w();
5508 GEN_STORE_FTN_FREG(fd
, WT2
);
5512 check_cp1_registers(ctx
, fd
);
5513 GEN_LOAD_FREG_FTN(WT0
, fs
);
5514 gen_op_float_cvtd_w();
5515 GEN_STORE_FTN_FREG(fd
, DT2
);
5519 check_cp1_64bitmode(ctx
);
5520 GEN_LOAD_FREG_FTN(DT0
, fs
);
5521 gen_op_float_cvts_l();
5522 GEN_STORE_FTN_FREG(fd
, WT2
);
5526 check_cp1_64bitmode(ctx
);
5527 GEN_LOAD_FREG_FTN(DT0
, fs
);
5528 gen_op_float_cvtd_l();
5529 GEN_STORE_FTN_FREG(fd
, DT2
);
5533 check_cp1_64bitmode(ctx
);
5534 GEN_LOAD_FREG_FTN(WT0
, fs
);
5535 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5536 gen_op_float_cvtps_pw();
5537 GEN_STORE_FTN_FREG(fd
, WT2
);
5538 GEN_STORE_FTN_FREG(fd
, WTH2
);
5542 check_cp1_64bitmode(ctx
);
5543 GEN_LOAD_FREG_FTN(WT0
, fs
);
5544 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5545 GEN_LOAD_FREG_FTN(WT1
, ft
);
5546 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5547 gen_op_float_add_ps();
5548 GEN_STORE_FTN_FREG(fd
, WT2
);
5549 GEN_STORE_FTN_FREG(fd
, WTH2
);
5553 check_cp1_64bitmode(ctx
);
5554 GEN_LOAD_FREG_FTN(WT0
, fs
);
5555 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5556 GEN_LOAD_FREG_FTN(WT1
, ft
);
5557 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5558 gen_op_float_sub_ps();
5559 GEN_STORE_FTN_FREG(fd
, WT2
);
5560 GEN_STORE_FTN_FREG(fd
, WTH2
);
5564 check_cp1_64bitmode(ctx
);
5565 GEN_LOAD_FREG_FTN(WT0
, fs
);
5566 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5567 GEN_LOAD_FREG_FTN(WT1
, ft
);
5568 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5569 gen_op_float_mul_ps();
5570 GEN_STORE_FTN_FREG(fd
, WT2
);
5571 GEN_STORE_FTN_FREG(fd
, WTH2
);
5575 check_cp1_64bitmode(ctx
);
5576 GEN_LOAD_FREG_FTN(WT0
, fs
);
5577 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5578 gen_op_float_abs_ps();
5579 GEN_STORE_FTN_FREG(fd
, WT2
);
5580 GEN_STORE_FTN_FREG(fd
, WTH2
);
5584 check_cp1_64bitmode(ctx
);
5585 GEN_LOAD_FREG_FTN(WT0
, fs
);
5586 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5587 gen_op_float_mov_ps();
5588 GEN_STORE_FTN_FREG(fd
, WT2
);
5589 GEN_STORE_FTN_FREG(fd
, WTH2
);
5593 check_cp1_64bitmode(ctx
);
5594 GEN_LOAD_FREG_FTN(WT0
, fs
);
5595 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5596 gen_op_float_chs_ps();
5597 GEN_STORE_FTN_FREG(fd
, WT2
);
5598 GEN_STORE_FTN_FREG(fd
, WTH2
);
5602 check_cp1_64bitmode(ctx
);
5603 GEN_LOAD_REG_T0(ft
);
5604 GEN_LOAD_FREG_FTN(WT0
, fs
);
5605 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5606 GEN_LOAD_FREG_FTN(WT2
, fd
);
5607 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5608 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5609 GEN_STORE_FTN_FREG(fd
, WT2
);
5610 GEN_STORE_FTN_FREG(fd
, WTH2
);
5614 check_cp1_64bitmode(ctx
);
5615 GEN_LOAD_REG_T0(ft
);
5616 GEN_LOAD_FREG_FTN(WT0
, fs
);
5617 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5618 GEN_LOAD_FREG_FTN(WT2
, fd
);
5619 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5620 gen_op_float_movz_ps();
5621 GEN_STORE_FTN_FREG(fd
, WT2
);
5622 GEN_STORE_FTN_FREG(fd
, WTH2
);
5626 check_cp1_64bitmode(ctx
);
5627 GEN_LOAD_REG_T0(ft
);
5628 GEN_LOAD_FREG_FTN(WT0
, fs
);
5629 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5630 GEN_LOAD_FREG_FTN(WT2
, fd
);
5631 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5632 gen_op_float_movn_ps();
5633 GEN_STORE_FTN_FREG(fd
, WT2
);
5634 GEN_STORE_FTN_FREG(fd
, WTH2
);
5638 check_cp1_64bitmode(ctx
);
5639 GEN_LOAD_FREG_FTN(WT0
, ft
);
5640 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5641 GEN_LOAD_FREG_FTN(WT1
, fs
);
5642 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5643 gen_op_float_addr_ps();
5644 GEN_STORE_FTN_FREG(fd
, WT2
);
5645 GEN_STORE_FTN_FREG(fd
, WTH2
);
5649 check_cp1_64bitmode(ctx
);
5650 GEN_LOAD_FREG_FTN(WT0
, ft
);
5651 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5652 GEN_LOAD_FREG_FTN(WT1
, fs
);
5653 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5654 gen_op_float_mulr_ps();
5655 GEN_STORE_FTN_FREG(fd
, WT2
);
5656 GEN_STORE_FTN_FREG(fd
, WTH2
);
5660 check_cp1_64bitmode(ctx
);
5661 GEN_LOAD_FREG_FTN(WT0
, fs
);
5662 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5663 GEN_LOAD_FREG_FTN(WT2
, fd
);
5664 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5665 gen_op_float_recip2_ps();
5666 GEN_STORE_FTN_FREG(fd
, WT2
);
5667 GEN_STORE_FTN_FREG(fd
, WTH2
);
5671 check_cp1_64bitmode(ctx
);
5672 GEN_LOAD_FREG_FTN(WT0
, fs
);
5673 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5674 gen_op_float_recip1_ps();
5675 GEN_STORE_FTN_FREG(fd
, WT2
);
5676 GEN_STORE_FTN_FREG(fd
, WTH2
);
5680 check_cp1_64bitmode(ctx
);
5681 GEN_LOAD_FREG_FTN(WT0
, fs
);
5682 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5683 gen_op_float_rsqrt1_ps();
5684 GEN_STORE_FTN_FREG(fd
, WT2
);
5685 GEN_STORE_FTN_FREG(fd
, WTH2
);
5689 check_cp1_64bitmode(ctx
);
5690 GEN_LOAD_FREG_FTN(WT0
, fs
);
5691 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5692 GEN_LOAD_FREG_FTN(WT2
, ft
);
5693 GEN_LOAD_FREG_FTN(WTH2
, ft
);
5694 gen_op_float_rsqrt2_ps();
5695 GEN_STORE_FTN_FREG(fd
, WT2
);
5696 GEN_STORE_FTN_FREG(fd
, WTH2
);
5700 check_cp1_64bitmode(ctx
);
5701 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5702 gen_op_float_cvts_pu();
5703 GEN_STORE_FTN_FREG(fd
, WT2
);
5707 check_cp1_64bitmode(ctx
);
5708 GEN_LOAD_FREG_FTN(WT0
, fs
);
5709 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5710 gen_op_float_cvtpw_ps();
5711 GEN_STORE_FTN_FREG(fd
, WT2
);
5712 GEN_STORE_FTN_FREG(fd
, WTH2
);
5716 check_cp1_64bitmode(ctx
);
5717 GEN_LOAD_FREG_FTN(WT0
, fs
);
5718 gen_op_float_cvts_pl();
5719 GEN_STORE_FTN_FREG(fd
, WT2
);
5723 check_cp1_64bitmode(ctx
);
5724 GEN_LOAD_FREG_FTN(WT0
, fs
);
5725 GEN_LOAD_FREG_FTN(WT1
, ft
);
5726 gen_op_float_pll_ps();
5727 GEN_STORE_FTN_FREG(fd
, DT2
);
5731 check_cp1_64bitmode(ctx
);
5732 GEN_LOAD_FREG_FTN(WT0
, fs
);
5733 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5734 gen_op_float_plu_ps();
5735 GEN_STORE_FTN_FREG(fd
, DT2
);
5739 check_cp1_64bitmode(ctx
);
5740 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5741 GEN_LOAD_FREG_FTN(WT1
, ft
);
5742 gen_op_float_pul_ps();
5743 GEN_STORE_FTN_FREG(fd
, DT2
);
5747 check_cp1_64bitmode(ctx
);
5748 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5749 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5750 gen_op_float_puu_ps();
5751 GEN_STORE_FTN_FREG(fd
, DT2
);
5770 check_cp1_64bitmode(ctx
);
5771 GEN_LOAD_FREG_FTN(WT0
, fs
);
5772 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5773 GEN_LOAD_FREG_FTN(WT1
, ft
);
5774 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5775 if (ctx
->opcode
& (1 << 6)) {
5776 gen_cmpabs_ps(func
-48, cc
);
5777 opn
= condnames_abs
[func
-48];
5779 gen_cmp_ps(func
-48, cc
);
5780 opn
= condnames
[func
-48];
5785 generate_exception (ctx
, EXCP_RI
);
5790 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5793 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5796 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5801 /* Coprocessor 3 (FPU) */
5802 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5803 int fd
, int fs
, int base
, int index
)
5805 const char *opn
= "extended float load/store";
5812 GEN_LOAD_REG_T0(index
);
5813 } else if (index
== 0) {
5814 GEN_LOAD_REG_T0(base
);
5816 GEN_LOAD_REG_T0(base
);
5817 GEN_LOAD_REG_T1(index
);
5820 /* Don't do NOP if destination is zero: we must perform the actual
5826 GEN_STORE_FTN_FREG(fd
, WT0
);
5831 check_cp1_registers(ctx
, fd
);
5833 GEN_STORE_FTN_FREG(fd
, DT0
);
5837 check_cp1_64bitmode(ctx
);
5839 GEN_STORE_FTN_FREG(fd
, DT0
);
5844 GEN_LOAD_FREG_FTN(WT0
, fs
);
5851 check_cp1_registers(ctx
, fs
);
5852 GEN_LOAD_FREG_FTN(DT0
, fs
);
5858 check_cp1_64bitmode(ctx
);
5859 GEN_LOAD_FREG_FTN(DT0
, fs
);
5866 generate_exception(ctx
, EXCP_RI
);
5869 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5870 regnames
[index
], regnames
[base
]);
5873 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5874 int fd
, int fr
, int fs
, int ft
)
5876 const char *opn
= "flt3_arith";
5880 check_cp1_64bitmode(ctx
);
5881 GEN_LOAD_REG_T0(fr
);
5882 GEN_LOAD_FREG_FTN(DT0
, fs
);
5883 GEN_LOAD_FREG_FTN(DT1
, ft
);
5884 gen_op_float_alnv_ps();
5885 GEN_STORE_FTN_FREG(fd
, DT2
);
5890 GEN_LOAD_FREG_FTN(WT0
, fs
);
5891 GEN_LOAD_FREG_FTN(WT1
, ft
);
5892 GEN_LOAD_FREG_FTN(WT2
, fr
);
5893 gen_op_float_muladd_s();
5894 GEN_STORE_FTN_FREG(fd
, WT2
);
5899 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5900 GEN_LOAD_FREG_FTN(DT0
, fs
);
5901 GEN_LOAD_FREG_FTN(DT1
, ft
);
5902 GEN_LOAD_FREG_FTN(DT2
, fr
);
5903 gen_op_float_muladd_d();
5904 GEN_STORE_FTN_FREG(fd
, DT2
);
5908 check_cp1_64bitmode(ctx
);
5909 GEN_LOAD_FREG_FTN(WT0
, fs
);
5910 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5911 GEN_LOAD_FREG_FTN(WT1
, ft
);
5912 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5913 GEN_LOAD_FREG_FTN(WT2
, fr
);
5914 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5915 gen_op_float_muladd_ps();
5916 GEN_STORE_FTN_FREG(fd
, WT2
);
5917 GEN_STORE_FTN_FREG(fd
, WTH2
);
5922 GEN_LOAD_FREG_FTN(WT0
, fs
);
5923 GEN_LOAD_FREG_FTN(WT1
, ft
);
5924 GEN_LOAD_FREG_FTN(WT2
, fr
);
5925 gen_op_float_mulsub_s();
5926 GEN_STORE_FTN_FREG(fd
, WT2
);
5931 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5932 GEN_LOAD_FREG_FTN(DT0
, fs
);
5933 GEN_LOAD_FREG_FTN(DT1
, ft
);
5934 GEN_LOAD_FREG_FTN(DT2
, fr
);
5935 gen_op_float_mulsub_d();
5936 GEN_STORE_FTN_FREG(fd
, DT2
);
5940 check_cp1_64bitmode(ctx
);
5941 GEN_LOAD_FREG_FTN(WT0
, fs
);
5942 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5943 GEN_LOAD_FREG_FTN(WT1
, ft
);
5944 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5945 GEN_LOAD_FREG_FTN(WT2
, fr
);
5946 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5947 gen_op_float_mulsub_ps();
5948 GEN_STORE_FTN_FREG(fd
, WT2
);
5949 GEN_STORE_FTN_FREG(fd
, WTH2
);
5954 GEN_LOAD_FREG_FTN(WT0
, fs
);
5955 GEN_LOAD_FREG_FTN(WT1
, ft
);
5956 GEN_LOAD_FREG_FTN(WT2
, fr
);
5957 gen_op_float_nmuladd_s();
5958 GEN_STORE_FTN_FREG(fd
, WT2
);
5963 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5964 GEN_LOAD_FREG_FTN(DT0
, fs
);
5965 GEN_LOAD_FREG_FTN(DT1
, ft
);
5966 GEN_LOAD_FREG_FTN(DT2
, fr
);
5967 gen_op_float_nmuladd_d();
5968 GEN_STORE_FTN_FREG(fd
, DT2
);
5972 check_cp1_64bitmode(ctx
);
5973 GEN_LOAD_FREG_FTN(WT0
, fs
);
5974 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5975 GEN_LOAD_FREG_FTN(WT1
, ft
);
5976 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5977 GEN_LOAD_FREG_FTN(WT2
, fr
);
5978 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5979 gen_op_float_nmuladd_ps();
5980 GEN_STORE_FTN_FREG(fd
, WT2
);
5981 GEN_STORE_FTN_FREG(fd
, WTH2
);
5986 GEN_LOAD_FREG_FTN(WT0
, fs
);
5987 GEN_LOAD_FREG_FTN(WT1
, ft
);
5988 GEN_LOAD_FREG_FTN(WT2
, fr
);
5989 gen_op_float_nmulsub_s();
5990 GEN_STORE_FTN_FREG(fd
, WT2
);
5995 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5996 GEN_LOAD_FREG_FTN(DT0
, fs
);
5997 GEN_LOAD_FREG_FTN(DT1
, ft
);
5998 GEN_LOAD_FREG_FTN(DT2
, fr
);
5999 gen_op_float_nmulsub_d();
6000 GEN_STORE_FTN_FREG(fd
, DT2
);
6004 check_cp1_64bitmode(ctx
);
6005 GEN_LOAD_FREG_FTN(WT0
, fs
);
6006 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6007 GEN_LOAD_FREG_FTN(WT1
, ft
);
6008 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6009 GEN_LOAD_FREG_FTN(WT2
, fr
);
6010 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6011 gen_op_float_nmulsub_ps();
6012 GEN_STORE_FTN_FREG(fd
, WT2
);
6013 GEN_STORE_FTN_FREG(fd
, WTH2
);
6018 generate_exception (ctx
, EXCP_RI
);
6021 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6022 fregnames
[fs
], fregnames
[ft
]);
6025 /* ISA extensions (ASEs) */
6026 /* MIPS16 extension to MIPS32 */
6027 /* SmartMIPS extension to MIPS32 */
6029 #if defined(TARGET_MIPS64)
6031 /* MDMX extension to MIPS64 */
6035 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6039 uint32_t op
, op1
, op2
;
6042 /* make sure instructions are on a word boundary */
6043 if (ctx
->pc
& 0x3) {
6044 env
->CP0_BadVAddr
= ctx
->pc
;
6045 generate_exception(ctx
, EXCP_AdEL
);
6049 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6051 /* Handle blikely not taken case */
6052 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6053 l1
= gen_new_label();
6054 tcg_gen_jnz_bcond(l1
);
6055 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6056 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6059 op
= MASK_OP_MAJOR(ctx
->opcode
);
6060 rs
= (ctx
->opcode
>> 21) & 0x1f;
6061 rt
= (ctx
->opcode
>> 16) & 0x1f;
6062 rd
= (ctx
->opcode
>> 11) & 0x1f;
6063 sa
= (ctx
->opcode
>> 6) & 0x1f;
6064 imm
= (int16_t)ctx
->opcode
;
6067 op1
= MASK_SPECIAL(ctx
->opcode
);
6069 case OPC_SLL
: /* Arithmetic with immediate */
6070 case OPC_SRL
... OPC_SRA
:
6071 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6073 case OPC_MOVZ
... OPC_MOVN
:
6074 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6075 case OPC_SLLV
: /* Arithmetic */
6076 case OPC_SRLV
... OPC_SRAV
:
6077 case OPC_ADD
... OPC_NOR
:
6078 case OPC_SLT
... OPC_SLTU
:
6079 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6081 case OPC_MULT
... OPC_DIVU
:
6083 check_insn(env
, ctx
, INSN_VR54XX
);
6084 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6085 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6087 gen_muldiv(ctx
, op1
, rs
, rt
);
6089 case OPC_JR
... OPC_JALR
:
6090 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6092 case OPC_TGE
... OPC_TEQ
: /* Traps */
6094 gen_trap(ctx
, op1
, rs
, rt
, -1);
6096 case OPC_MFHI
: /* Move from HI/LO */
6098 gen_HILO(ctx
, op1
, rd
);
6101 case OPC_MTLO
: /* Move to HI/LO */
6102 gen_HILO(ctx
, op1
, rs
);
6104 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6105 #ifdef MIPS_STRICT_STANDARD
6106 MIPS_INVAL("PMON / selsl");
6107 generate_exception(ctx
, EXCP_RI
);
6113 generate_exception(ctx
, EXCP_SYSCALL
);
6116 generate_exception(ctx
, EXCP_BREAK
);
6119 #ifdef MIPS_STRICT_STANDARD
6121 generate_exception(ctx
, EXCP_RI
);
6123 /* Implemented as RI exception for now. */
6124 MIPS_INVAL("spim (unofficial)");
6125 generate_exception(ctx
, EXCP_RI
);
6133 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6134 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6135 save_cpu_state(ctx
, 1);
6136 check_cp1_enabled(ctx
);
6137 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6138 (ctx
->opcode
>> 16) & 1);
6140 generate_exception_err(ctx
, EXCP_CpU
, 1);
6144 #if defined(TARGET_MIPS64)
6145 /* MIPS64 specific opcodes */
6147 case OPC_DSRL
... OPC_DSRA
:
6149 case OPC_DSRL32
... OPC_DSRA32
:
6150 check_insn(env
, ctx
, ISA_MIPS3
);
6152 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6155 case OPC_DSRLV
... OPC_DSRAV
:
6156 case OPC_DADD
... OPC_DSUBU
:
6157 check_insn(env
, ctx
, ISA_MIPS3
);
6159 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6161 case OPC_DMULT
... OPC_DDIVU
:
6162 check_insn(env
, ctx
, ISA_MIPS3
);
6164 gen_muldiv(ctx
, op1
, rs
, rt
);
6167 default: /* Invalid */
6168 MIPS_INVAL("special");
6169 generate_exception(ctx
, EXCP_RI
);
6174 op1
= MASK_SPECIAL2(ctx
->opcode
);
6176 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6177 case OPC_MSUB
... OPC_MSUBU
:
6178 check_insn(env
, ctx
, ISA_MIPS32
);
6179 gen_muldiv(ctx
, op1
, rs
, rt
);
6182 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6184 case OPC_CLZ
... OPC_CLO
:
6185 check_insn(env
, ctx
, ISA_MIPS32
);
6186 gen_cl(ctx
, op1
, rd
, rs
);
6189 /* XXX: not clear which exception should be raised
6190 * when in debug mode...
6192 check_insn(env
, ctx
, ISA_MIPS32
);
6193 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6194 generate_exception(ctx
, EXCP_DBp
);
6196 generate_exception(ctx
, EXCP_DBp
);
6200 #if defined(TARGET_MIPS64)
6201 case OPC_DCLZ
... OPC_DCLO
:
6202 check_insn(env
, ctx
, ISA_MIPS64
);
6204 gen_cl(ctx
, op1
, rd
, rs
);
6207 default: /* Invalid */
6208 MIPS_INVAL("special2");
6209 generate_exception(ctx
, EXCP_RI
);
6214 op1
= MASK_SPECIAL3(ctx
->opcode
);
6218 check_insn(env
, ctx
, ISA_MIPS32R2
);
6219 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6222 check_insn(env
, ctx
, ISA_MIPS32R2
);
6223 op2
= MASK_BSHFL(ctx
->opcode
);
6226 GEN_LOAD_REG_T1(rt
);
6230 GEN_LOAD_REG_T1(rt
);
6234 GEN_LOAD_REG_T1(rt
);
6237 default: /* Invalid */
6238 MIPS_INVAL("bshfl");
6239 generate_exception(ctx
, EXCP_RI
);
6242 GEN_STORE_T0_REG(rd
);
6245 check_insn(env
, ctx
, ISA_MIPS32R2
);
6248 save_cpu_state(ctx
, 1);
6249 gen_op_rdhwr_cpunum();
6252 save_cpu_state(ctx
, 1);
6253 gen_op_rdhwr_synci_step();
6256 save_cpu_state(ctx
, 1);
6260 save_cpu_state(ctx
, 1);
6261 gen_op_rdhwr_ccres();
6264 #if defined (CONFIG_USER_ONLY)
6268 default: /* Invalid */
6269 MIPS_INVAL("rdhwr");
6270 generate_exception(ctx
, EXCP_RI
);
6273 GEN_STORE_T0_REG(rt
);
6276 check_insn(env
, ctx
, ASE_MT
);
6277 GEN_LOAD_REG_T0(rt
);
6278 GEN_LOAD_REG_T1(rs
);
6282 check_insn(env
, ctx
, ASE_MT
);
6283 GEN_LOAD_REG_T0(rs
);
6285 GEN_STORE_T0_REG(rd
);
6287 #if defined(TARGET_MIPS64)
6288 case OPC_DEXTM
... OPC_DEXT
:
6289 case OPC_DINSM
... OPC_DINS
:
6290 check_insn(env
, ctx
, ISA_MIPS64R2
);
6292 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6295 check_insn(env
, ctx
, ISA_MIPS64R2
);
6297 op2
= MASK_DBSHFL(ctx
->opcode
);
6300 GEN_LOAD_REG_T1(rt
);
6304 GEN_LOAD_REG_T1(rt
);
6307 default: /* Invalid */
6308 MIPS_INVAL("dbshfl");
6309 generate_exception(ctx
, EXCP_RI
);
6312 GEN_STORE_T0_REG(rd
);
6315 default: /* Invalid */
6316 MIPS_INVAL("special3");
6317 generate_exception(ctx
, EXCP_RI
);
6322 op1
= MASK_REGIMM(ctx
->opcode
);
6324 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6325 case OPC_BLTZAL
... OPC_BGEZALL
:
6326 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6328 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6330 gen_trap(ctx
, op1
, rs
, -1, imm
);
6333 check_insn(env
, ctx
, ISA_MIPS32R2
);
6336 default: /* Invalid */
6337 MIPS_INVAL("regimm");
6338 generate_exception(ctx
, EXCP_RI
);
6343 check_cp0_enabled(ctx
);
6344 op1
= MASK_CP0(ctx
->opcode
);
6350 #if defined(TARGET_MIPS64)
6354 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6356 case OPC_C0_FIRST
... OPC_C0_LAST
:
6357 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6360 op2
= MASK_MFMC0(ctx
->opcode
);
6363 check_insn(env
, ctx
, ASE_MT
);
6367 check_insn(env
, ctx
, ASE_MT
);
6371 check_insn(env
, ctx
, ASE_MT
);
6375 check_insn(env
, ctx
, ASE_MT
);
6379 check_insn(env
, ctx
, ISA_MIPS32R2
);
6380 save_cpu_state(ctx
, 1);
6382 /* Stop translation as we may have switched the execution mode */
6383 ctx
->bstate
= BS_STOP
;
6386 check_insn(env
, ctx
, ISA_MIPS32R2
);
6387 save_cpu_state(ctx
, 1);
6389 /* Stop translation as we may have switched the execution mode */
6390 ctx
->bstate
= BS_STOP
;
6392 default: /* Invalid */
6393 MIPS_INVAL("mfmc0");
6394 generate_exception(ctx
, EXCP_RI
);
6397 GEN_STORE_T0_REG(rt
);
6400 check_insn(env
, ctx
, ISA_MIPS32R2
);
6401 GEN_LOAD_SRSREG_TN(T0
, rt
);
6402 GEN_STORE_T0_REG(rd
);
6405 check_insn(env
, ctx
, ISA_MIPS32R2
);
6406 GEN_LOAD_REG_T0(rt
);
6407 GEN_STORE_TN_SRSREG(rd
, T0
);
6411 generate_exception(ctx
, EXCP_RI
);
6415 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6416 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6418 case OPC_J
... OPC_JAL
: /* Jump */
6419 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6420 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6422 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6423 case OPC_BEQL
... OPC_BGTZL
:
6424 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6426 case OPC_LB
... OPC_LWR
: /* Load and stores */
6427 case OPC_SB
... OPC_SW
:
6431 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6434 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6438 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6442 /* Floating point (COP1). */
6447 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6448 save_cpu_state(ctx
, 1);
6449 check_cp1_enabled(ctx
);
6450 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6452 generate_exception_err(ctx
, EXCP_CpU
, 1);
6457 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6458 save_cpu_state(ctx
, 1);
6459 check_cp1_enabled(ctx
);
6460 op1
= MASK_CP1(ctx
->opcode
);
6464 check_insn(env
, ctx
, ISA_MIPS32R2
);
6469 gen_cp1(ctx
, op1
, rt
, rd
);
6471 #if defined(TARGET_MIPS64)
6474 check_insn(env
, ctx
, ISA_MIPS3
);
6475 gen_cp1(ctx
, op1
, rt
, rd
);
6481 check_insn(env
, ctx
, ASE_MIPS3D
);
6484 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6485 (rt
>> 2) & 0x7, imm
<< 2);
6492 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
6497 generate_exception (ctx
, EXCP_RI
);
6501 generate_exception_err(ctx
, EXCP_CpU
, 1);
6511 /* COP2: Not implemented. */
6512 generate_exception_err(ctx
, EXCP_CpU
, 2);
6516 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6517 save_cpu_state(ctx
, 1);
6518 check_cp1_enabled(ctx
);
6519 op1
= MASK_CP3(ctx
->opcode
);
6527 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
6545 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
6549 generate_exception (ctx
, EXCP_RI
);
6553 generate_exception_err(ctx
, EXCP_CpU
, 1);
6557 #if defined(TARGET_MIPS64)
6558 /* MIPS64 opcodes */
6560 case OPC_LDL
... OPC_LDR
:
6561 case OPC_SDL
... OPC_SDR
:
6566 check_insn(env
, ctx
, ISA_MIPS3
);
6568 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6570 case OPC_DADDI
... OPC_DADDIU
:
6571 check_insn(env
, ctx
, ISA_MIPS3
);
6573 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6577 check_insn(env
, ctx
, ASE_MIPS16
);
6578 /* MIPS16: Not implemented. */
6580 check_insn(env
, ctx
, ASE_MDMX
);
6581 /* MDMX: Not implemented. */
6582 default: /* Invalid */
6583 MIPS_INVAL("major opcode");
6584 generate_exception(ctx
, EXCP_RI
);
6587 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
6588 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
6589 /* Branches completion */
6590 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
6591 ctx
->bstate
= BS_BRANCH
;
6592 save_cpu_state(ctx
, 0);
6595 /* unconditional branch */
6596 MIPS_DEBUG("unconditional branch");
6597 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6600 /* blikely taken case */
6601 MIPS_DEBUG("blikely branch taken");
6602 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6605 /* Conditional branch */
6606 MIPS_DEBUG("conditional branch");
6609 l1
= gen_new_label();
6610 tcg_gen_jnz_bcond(l1
);
6611 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6613 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6617 /* unconditional branch to register */
6618 MIPS_DEBUG("branch to register");
6623 MIPS_DEBUG("unknown branch");
6629 static always_inline
int
6630 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
6634 target_ulong pc_start
;
6635 uint16_t *gen_opc_end
;
6638 if (search_pc
&& loglevel
)
6639 fprintf (logfile
, "search pc %d\n", search_pc
);
6642 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6646 ctx
.bstate
= BS_NONE
;
6647 /* Restore delay slot state from the tb context. */
6648 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
6649 restore_cpu_state(env
, &ctx
);
6650 #if defined(CONFIG_USER_ONLY)
6651 ctx
.mem_idx
= MIPS_HFLAG_UM
;
6653 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
6656 if (loglevel
& CPU_LOG_TB_CPU
) {
6657 fprintf(logfile
, "------------------------------------------------\n");
6658 /* FIXME: This may print out stale hflags from env... */
6659 cpu_dump_state(env
, logfile
, fprintf
, 0);
6662 #ifdef MIPS_DEBUG_DISAS
6663 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6664 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
6665 tb
, ctx
.mem_idx
, ctx
.hflags
);
6667 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6668 if (env
->nb_breakpoints
> 0) {
6669 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6670 if (env
->breakpoints
[j
] == ctx
.pc
) {
6671 save_cpu_state(&ctx
, 1);
6672 ctx
.bstate
= BS_BRANCH
;
6674 /* Include the breakpoint location or the tb won't
6675 * be flushed when it must be. */
6677 goto done_generating
;
6683 j
= gen_opc_ptr
- gen_opc_buf
;
6687 gen_opc_instr_start
[lj
++] = 0;
6689 gen_opc_pc
[lj
] = ctx
.pc
;
6690 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6691 gen_opc_instr_start
[lj
] = 1;
6693 ctx
.opcode
= ldl_code(ctx
.pc
);
6694 decode_opc(env
, &ctx
);
6697 if (env
->singlestep_enabled
)
6700 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6703 #if defined (MIPS_SINGLE_STEP)
6707 if (env
->singlestep_enabled
) {
6708 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
6711 switch (ctx
.bstate
) {
6713 gen_op_interrupt_restart();
6714 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6717 save_cpu_state(&ctx
, 0);
6718 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6721 gen_op_interrupt_restart();
6730 ctx
.last_T0_store
= NULL
;
6731 *gen_opc_ptr
= INDEX_op_end
;
6733 j
= gen_opc_ptr
- gen_opc_buf
;
6736 gen_opc_instr_start
[lj
++] = 0;
6738 tb
->size
= ctx
.pc
- pc_start
;
6741 #if defined MIPS_DEBUG_DISAS
6742 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6743 fprintf(logfile
, "\n");
6745 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6746 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6747 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6748 fprintf(logfile
, "\n");
6750 if (loglevel
& CPU_LOG_TB_CPU
) {
6751 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6758 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6760 return gen_intermediate_code_internal(env
, tb
, 0);
6763 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6765 return gen_intermediate_code_internal(env
, tb
, 1);
6768 void fpu_dump_state(CPUState
*env
, FILE *f
,
6769 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6773 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6775 #define printfpr(fp) \
6778 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6779 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6780 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6783 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6784 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6785 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6786 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6787 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6792 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6793 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
6794 get_float_exception_flags(&env
->fpu
->fp_status
));
6795 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
6796 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
6797 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
6798 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6799 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6800 printfpr(&env
->fpu
->fpr
[i
]);
6806 void dump_fpu (CPUState
*env
)
6809 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6810 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0], env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
, env
->bcond
);
6811 fpu_dump_state(env
, logfile
, fprintf
, 0);
6815 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6816 /* Debug help: The architecture requires 32bit code to maintain proper
6817 sign-extened values on 64bit machines. */
6819 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6821 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6822 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6827 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
6828 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
6829 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
6830 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
6831 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
6832 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
6833 if (!SIGN_EXT_P(env
->btarget
))
6834 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6836 for (i
= 0; i
< 32; i
++) {
6837 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
6838 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6841 if (!SIGN_EXT_P(env
->CP0_EPC
))
6842 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6843 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6844 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6848 void cpu_dump_state (CPUState
*env
, FILE *f
,
6849 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6854 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",
6855 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6856 for (i
= 0; i
< 32; i
++) {
6858 cpu_fprintf(f
, "GPR%02d:", i
);
6859 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6861 cpu_fprintf(f
, "\n");
6864 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6865 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6866 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6867 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6868 if (env
->hflags
& MIPS_HFLAG_FPU
)
6869 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6870 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6871 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6875 static void mips_tcg_init(void)
6879 /* Initialize various static tables. */
6883 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
6884 current_tc_regs
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG1
, "current_tc_regs");
6885 #if TARGET_LONG_BITS > HOST_LONG_BITS
6886 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
6887 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
6888 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
6889 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
6891 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T0");
6892 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG3
, "T1");
6898 #include "translate_init.c"
6900 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
6903 const mips_def_t
*def
;
6905 def
= cpu_mips_find_by_name(cpu_model
);
6908 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6911 env
->cpu_model
= def
;
6914 env
->cpu_model_str
= cpu_model
;
6920 void cpu_reset (CPUMIPSState
*env
)
6922 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6927 #if !defined(CONFIG_USER_ONLY)
6928 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6929 /* If the exception was raised from a delay slot,
6930 * come back to the jump. */
6931 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
6933 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
6935 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
6937 /* SMP not implemented */
6938 env
->CP0_EBase
= 0x80000000;
6939 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6940 /* vectored interrupts not implemented, timer on int 7,
6941 no performance counters. */
6942 env
->CP0_IntCtl
= 0xe0000000;
6946 for (i
= 0; i
< 7; i
++) {
6947 env
->CP0_WatchLo
[i
] = 0;
6948 env
->CP0_WatchHi
[i
] = 0x80000000;
6950 env
->CP0_WatchLo
[7] = 0;
6951 env
->CP0_WatchHi
[7] = 0;
6953 /* Count register increments in debug mode, EJTAG version 1 */
6954 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6956 env
->exception_index
= EXCP_NONE
;
6957 #if defined(CONFIG_USER_ONLY)
6958 env
->hflags
= MIPS_HFLAG_UM
;
6959 env
->user_mode_only
= 1;
6961 env
->hflags
= MIPS_HFLAG_CP0
;
6963 cpu_mips_register(env
, env
->cpu_model
);
6966 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
6967 unsigned long searched_pc
, int pc_pos
, void *puc
)
6969 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
6970 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
6971 env
->hflags
|= gen_opc_hflags
[pc_pos
];