2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 //#define MIPS_DEBUG_DISAS
35 //#define MIPS_DEBUG_SIGN_EXTENSIONS
36 //#define MIPS_SINGLE_STEP
38 /* MIPS major opcodes */
39 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
42 /* indirect opcode tables */
43 OPC_SPECIAL
= (0x00 << 26),
44 OPC_REGIMM
= (0x01 << 26),
45 OPC_CP0
= (0x10 << 26),
46 OPC_CP1
= (0x11 << 26),
47 OPC_CP2
= (0x12 << 26),
48 OPC_CP3
= (0x13 << 26),
49 OPC_SPECIAL2
= (0x1C << 26),
50 OPC_SPECIAL3
= (0x1F << 26),
51 /* arithmetic with immediate */
52 OPC_ADDI
= (0x08 << 26),
53 OPC_ADDIU
= (0x09 << 26),
54 OPC_SLTI
= (0x0A << 26),
55 OPC_SLTIU
= (0x0B << 26),
56 OPC_ANDI
= (0x0C << 26),
57 OPC_ORI
= (0x0D << 26),
58 OPC_XORI
= (0x0E << 26),
59 OPC_LUI
= (0x0F << 26),
60 OPC_DADDI
= (0x18 << 26),
61 OPC_DADDIU
= (0x19 << 26),
62 /* Jump and branches */
64 OPC_JAL
= (0x03 << 26),
65 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
66 OPC_BEQL
= (0x14 << 26),
67 OPC_BNE
= (0x05 << 26),
68 OPC_BNEL
= (0x15 << 26),
69 OPC_BLEZ
= (0x06 << 26),
70 OPC_BLEZL
= (0x16 << 26),
71 OPC_BGTZ
= (0x07 << 26),
72 OPC_BGTZL
= (0x17 << 26),
73 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
75 OPC_LDL
= (0x1A << 26),
76 OPC_LDR
= (0x1B << 26),
77 OPC_LB
= (0x20 << 26),
78 OPC_LH
= (0x21 << 26),
79 OPC_LWL
= (0x22 << 26),
80 OPC_LW
= (0x23 << 26),
81 OPC_LBU
= (0x24 << 26),
82 OPC_LHU
= (0x25 << 26),
83 OPC_LWR
= (0x26 << 26),
84 OPC_LWU
= (0x27 << 26),
85 OPC_SB
= (0x28 << 26),
86 OPC_SH
= (0x29 << 26),
87 OPC_SWL
= (0x2A << 26),
88 OPC_SW
= (0x2B << 26),
89 OPC_SDL
= (0x2C << 26),
90 OPC_SDR
= (0x2D << 26),
91 OPC_SWR
= (0x2E << 26),
92 OPC_LL
= (0x30 << 26),
93 OPC_LLD
= (0x34 << 26),
94 OPC_LD
= (0x37 << 26),
95 OPC_SC
= (0x38 << 26),
96 OPC_SCD
= (0x3C << 26),
97 OPC_SD
= (0x3F << 26),
98 /* Floating point load/store */
99 OPC_LWC1
= (0x31 << 26),
100 OPC_LWC2
= (0x32 << 26),
101 OPC_LDC1
= (0x35 << 26),
102 OPC_LDC2
= (0x36 << 26),
103 OPC_SWC1
= (0x39 << 26),
104 OPC_SWC2
= (0x3A << 26),
105 OPC_SDC1
= (0x3D << 26),
106 OPC_SDC2
= (0x3E << 26),
107 /* MDMX ASE specific */
108 OPC_MDMX
= (0x1E << 26),
109 /* Cache and prefetch */
110 OPC_CACHE
= (0x2F << 26),
111 OPC_PREF
= (0x33 << 26),
112 /* Reserved major opcode */
113 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
116 /* MIPS special opcodes */
117 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
121 OPC_SLL
= 0x00 | OPC_SPECIAL
,
122 /* NOP is SLL r0, r0, 0 */
123 /* SSNOP is SLL r0, r0, 1 */
124 /* EHB is SLL r0, r0, 3 */
125 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
126 OPC_SRA
= 0x03 | OPC_SPECIAL
,
127 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
128 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
129 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
130 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
131 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
132 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
133 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
134 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
135 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
136 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
137 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
138 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
139 /* Multiplication / division */
140 OPC_MULT
= 0x18 | OPC_SPECIAL
,
141 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
142 OPC_DIV
= 0x1A | OPC_SPECIAL
,
143 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
144 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
145 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
146 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
147 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
148 /* 2 registers arithmetic / logic */
149 OPC_ADD
= 0x20 | OPC_SPECIAL
,
150 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
151 OPC_SUB
= 0x22 | OPC_SPECIAL
,
152 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
153 OPC_AND
= 0x24 | OPC_SPECIAL
,
154 OPC_OR
= 0x25 | OPC_SPECIAL
,
155 OPC_XOR
= 0x26 | OPC_SPECIAL
,
156 OPC_NOR
= 0x27 | OPC_SPECIAL
,
157 OPC_SLT
= 0x2A | OPC_SPECIAL
,
158 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
159 OPC_DADD
= 0x2C | OPC_SPECIAL
,
160 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
161 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
162 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
164 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
165 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
167 OPC_TGE
= 0x30 | OPC_SPECIAL
,
168 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
169 OPC_TLT
= 0x32 | OPC_SPECIAL
,
170 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
171 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
172 OPC_TNE
= 0x36 | OPC_SPECIAL
,
173 /* HI / LO registers load & stores */
174 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
175 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
176 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
177 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
178 /* Conditional moves */
179 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
180 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
182 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
185 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
186 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
187 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
188 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
189 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
191 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
192 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
193 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
194 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
195 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
196 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
197 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
200 /* Multiplication variants of the vr54xx. */
201 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
204 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
205 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
206 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
207 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
208 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
209 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
210 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
211 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
213 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
214 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
215 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
216 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
217 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
220 /* REGIMM (rt field) opcodes */
221 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
224 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
225 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
226 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
227 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
228 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
229 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
230 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
231 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
232 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
233 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
234 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
235 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
236 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
237 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
238 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
241 /* Special2 opcodes */
242 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
245 /* Multiply & xxx operations */
246 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
247 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
248 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
249 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
250 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
252 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
253 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
254 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
255 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
257 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
260 /* Special3 opcodes */
261 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
264 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
265 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
266 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
267 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
268 OPC_INS
= 0x04 | OPC_SPECIAL3
,
269 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
270 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
271 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
272 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
273 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
274 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
275 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
276 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
280 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
283 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
284 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
285 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
289 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
292 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
293 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
296 /* Coprocessor 0 (rs field) */
297 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
300 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
301 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
302 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
303 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
304 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
305 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
306 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
307 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
308 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
309 OPC_C0
= (0x10 << 21) | OPC_CP0
,
310 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
311 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
315 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
318 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
319 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
320 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
321 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
322 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
323 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
326 /* Coprocessor 0 (with rs == C0) */
327 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
330 OPC_TLBR
= 0x01 | OPC_C0
,
331 OPC_TLBWI
= 0x02 | OPC_C0
,
332 OPC_TLBWR
= 0x06 | OPC_C0
,
333 OPC_TLBP
= 0x08 | OPC_C0
,
334 OPC_RFE
= 0x10 | OPC_C0
,
335 OPC_ERET
= 0x18 | OPC_C0
,
336 OPC_DERET
= 0x1F | OPC_C0
,
337 OPC_WAIT
= 0x20 | OPC_C0
,
340 /* Coprocessor 1 (rs field) */
341 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
344 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
345 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
346 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
347 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
348 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
349 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
350 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
351 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
352 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
353 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
354 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
355 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
356 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
357 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
358 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
359 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
360 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
361 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
364 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
365 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
368 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
369 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
370 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
371 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
375 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
376 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
380 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
381 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
384 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
387 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
388 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
389 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
390 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
391 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
392 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
393 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
394 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
395 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
398 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
401 OPC_LWXC1
= 0x00 | OPC_CP3
,
402 OPC_LDXC1
= 0x01 | OPC_CP3
,
403 OPC_LUXC1
= 0x05 | OPC_CP3
,
404 OPC_SWXC1
= 0x08 | OPC_CP3
,
405 OPC_SDXC1
= 0x09 | OPC_CP3
,
406 OPC_SUXC1
= 0x0D | OPC_CP3
,
407 OPC_PREFX
= 0x0F | OPC_CP3
,
408 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
409 OPC_MADD_S
= 0x20 | OPC_CP3
,
410 OPC_MADD_D
= 0x21 | OPC_CP3
,
411 OPC_MADD_PS
= 0x26 | OPC_CP3
,
412 OPC_MSUB_S
= 0x28 | OPC_CP3
,
413 OPC_MSUB_D
= 0x29 | OPC_CP3
,
414 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
415 OPC_NMADD_S
= 0x30 | OPC_CP3
,
416 OPC_NMADD_D
= 0x31 | OPC_CP3
,
417 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
418 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
419 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
420 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
424 const unsigned char *regnames
[] =
425 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
426 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
427 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
428 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
430 /* Warning: no function for r0 register (hard wired to zero) */
431 #define GEN32(func, NAME) \
432 static GenOpFunc *NAME ## _table [32] = { \
433 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
434 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
435 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
436 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
437 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
438 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
439 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
440 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
442 static always_inline void func(int n) \
444 NAME ## _table[n](); \
447 /* General purpose registers moves */
448 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
449 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
450 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
452 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
453 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
455 /* Moves to/from shadow registers */
456 GEN32(gen_op_load_srsgpr_T0
, gen_op_load_srsgpr_T0_gpr
);
457 GEN32(gen_op_store_T0_srsgpr
, gen_op_store_T0_srsgpr_gpr
);
459 static const char *fregnames
[] =
460 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
461 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
462 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
463 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
465 #define FGEN32(func, NAME) \
466 static GenOpFunc *NAME ## _table [32] = { \
467 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
468 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
469 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
470 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
471 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
472 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
473 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
474 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
476 static always_inline void func(int n) \
478 NAME ## _table[n](); \
481 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
482 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
484 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
485 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
487 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
488 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
490 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
491 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
493 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
494 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
496 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
497 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
499 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
500 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
502 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
503 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
505 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
506 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
508 #define FOP_CONDS(type, fmt) \
509 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
510 gen_op_cmp ## type ## _ ## fmt ## _f, \
511 gen_op_cmp ## type ## _ ## fmt ## _un, \
512 gen_op_cmp ## type ## _ ## fmt ## _eq, \
513 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
514 gen_op_cmp ## type ## _ ## fmt ## _olt, \
515 gen_op_cmp ## type ## _ ## fmt ## _ult, \
516 gen_op_cmp ## type ## _ ## fmt ## _ole, \
517 gen_op_cmp ## type ## _ ## fmt ## _ule, \
518 gen_op_cmp ## type ## _ ## fmt ## _sf, \
519 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
520 gen_op_cmp ## type ## _ ## fmt ## _seq, \
521 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
522 gen_op_cmp ## type ## _ ## fmt ## _lt, \
523 gen_op_cmp ## type ## _ ## fmt ## _nge, \
524 gen_op_cmp ## type ## _ ## fmt ## _le, \
525 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
527 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
529 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
539 typedef struct DisasContext
{
540 struct TranslationBlock
*tb
;
541 target_ulong pc
, saved_pc
;
544 /* Routine used to access memory */
546 uint32_t hflags
, saved_hflags
;
548 target_ulong btarget
;
554 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
555 * exception condition
557 BS_STOP
= 1, /* We want to stop translation for any reason */
558 BS_BRANCH
= 2, /* We reached a branch condition */
559 BS_EXCP
= 3, /* We reached an exception condition */
562 #ifdef MIPS_DEBUG_DISAS
563 #define MIPS_DEBUG(fmt, args...) \
565 if (loglevel & CPU_LOG_TB_IN_ASM) { \
566 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
567 ctx->pc, ctx->opcode , ##args); \
571 #define MIPS_DEBUG(fmt, args...) do { } while(0)
574 #define MIPS_INVAL(op) \
576 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
577 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
580 #define GEN_LOAD_REG_T0(Rn) \
585 if (ctx->glue(last_T0, _store) != gen_opc_ptr \
586 || ctx->glue(last_T0, _gpr) != Rn) { \
587 gen_op_load_gpr_T0(Rn); \
592 #define GEN_LOAD_REG_T1(Rn) \
597 gen_op_load_gpr_T1(Rn); \
601 #define GEN_LOAD_REG_T2(Rn) \
606 gen_op_load_gpr_T2(Rn); \
610 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
613 glue(gen_op_reset_, Tn)(); \
615 glue(gen_op_load_srsgpr_, Tn)(Rn); \
619 #if defined(TARGET_MIPS64)
620 #define GEN_LOAD_IMM_TN(Tn, Imm) \
623 glue(gen_op_reset_, Tn)(); \
624 } else if ((int32_t)Imm == Imm) { \
625 glue(gen_op_set_, Tn)(Imm); \
627 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
631 #define GEN_LOAD_IMM_TN(Tn, Imm) \
634 glue(gen_op_reset_, Tn)(); \
636 glue(gen_op_set_, Tn)(Imm); \
641 #define GEN_STORE_T0_REG(Rn) \
644 glue(gen_op_store_T0,_gpr)(Rn); \
645 ctx->glue(last_T0,_store) = gen_opc_ptr; \
646 ctx->glue(last_T0,_gpr) = Rn; \
650 #define GEN_STORE_T1_REG(Rn) \
653 glue(gen_op_store_T1,_gpr)(Rn); \
656 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
659 glue(glue(gen_op_store_, Tn),_srsgpr)(Rn); \
663 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
665 glue(gen_op_load_fpr_, FTn)(Fn); \
668 #define GEN_STORE_FTN_FREG(Fn, FTn) \
670 glue(gen_op_store_fpr_, FTn)(Fn); \
673 static always_inline
void gen_save_pc(target_ulong pc
)
675 #if defined(TARGET_MIPS64)
676 if (pc
== (int32_t)pc
) {
679 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
686 static always_inline
void gen_save_btarget(target_ulong btarget
)
688 #if defined(TARGET_MIPS64)
689 if (btarget
== (int32_t)btarget
) {
690 gen_op_save_btarget(btarget
);
692 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
695 gen_op_save_btarget(btarget
);
699 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
701 #if defined MIPS_DEBUG_DISAS
702 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
703 fprintf(logfile
, "hflags %08x saved %08x\n",
704 ctx
->hflags
, ctx
->saved_hflags
);
707 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
708 gen_save_pc(ctx
->pc
);
709 ctx
->saved_pc
= ctx
->pc
;
711 if (ctx
->hflags
!= ctx
->saved_hflags
) {
712 gen_op_save_state(ctx
->hflags
);
713 ctx
->saved_hflags
= ctx
->hflags
;
714 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
716 gen_op_save_breg_target();
722 /* bcond was already saved by the BL insn */
725 gen_save_btarget(ctx
->btarget
);
731 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
733 ctx
->saved_hflags
= ctx
->hflags
;
734 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
736 gen_op_restore_breg_target();
739 ctx
->btarget
= env
->btarget
;
743 ctx
->btarget
= env
->btarget
;
744 gen_op_restore_bcond();
749 static always_inline
void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
751 #if defined MIPS_DEBUG_DISAS
752 if (loglevel
& CPU_LOG_TB_IN_ASM
)
753 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
755 save_cpu_state(ctx
, 1);
757 gen_op_raise_exception(excp
);
759 gen_op_raise_exception_err(excp
, err
);
760 ctx
->bstate
= BS_EXCP
;
763 static always_inline
void generate_exception (DisasContext
*ctx
, int excp
)
765 generate_exception_err (ctx
, excp
, 0);
768 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
770 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
771 generate_exception_err(ctx
, EXCP_CpU
, 1);
774 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
776 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
777 generate_exception_err(ctx
, EXCP_CpU
, 1);
780 /* Verify that the processor is running with COP1X instructions enabled.
781 This is associated with the nabla symbol in the MIPS32 and MIPS64
784 static always_inline
void check_cop1x(DisasContext
*ctx
)
786 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
787 generate_exception(ctx
, EXCP_RI
);
790 /* Verify that the processor is running with 64-bit floating-point
791 operations enabled. */
793 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
795 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
796 generate_exception(ctx
, EXCP_RI
);
800 * Verify if floating point register is valid; an operation is not defined
801 * if bit 0 of any register specification is set and the FR bit in the
802 * Status register equals zero, since the register numbers specify an
803 * even-odd pair of adjacent coprocessor general registers. When the FR bit
804 * in the Status register equals one, both even and odd register numbers
805 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
807 * Multiple 64 bit wide registers can be checked by calling
808 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
810 void check_cp1_registers(DisasContext
*ctx
, int regs
)
812 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
813 generate_exception(ctx
, EXCP_RI
);
816 /* This code generates a "reserved instruction" exception if the
817 CPU does not support the instruction set corresponding to flags. */
818 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
820 if (unlikely(!(env
->insn_flags
& flags
)))
821 generate_exception(ctx
, EXCP_RI
);
824 /* This code generates a "reserved instruction" exception if 64-bit
825 instructions are not enabled. */
826 static always_inline
void check_mips_64(DisasContext
*ctx
)
828 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
829 generate_exception(ctx
, EXCP_RI
);
832 #if defined(CONFIG_USER_ONLY)
833 #define op_ldst(name) gen_op_##name##_raw()
834 #define OP_LD_TABLE(width)
835 #define OP_ST_TABLE(width)
837 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
838 #define OP_LD_TABLE(width) \
839 static GenOpFunc *gen_op_l##width[] = { \
840 &gen_op_l##width##_kernel, \
841 &gen_op_l##width##_super, \
842 &gen_op_l##width##_user, \
844 #define OP_ST_TABLE(width) \
845 static GenOpFunc *gen_op_s##width[] = { \
846 &gen_op_s##width##_kernel, \
847 &gen_op_s##width##_super, \
848 &gen_op_s##width##_user, \
852 #if defined(TARGET_MIPS64)
885 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
886 int base
, int16_t offset
)
888 const char *opn
= "ldst";
891 GEN_LOAD_IMM_TN(T0
, offset
);
892 } else if (offset
== 0) {
893 gen_op_load_gpr_T0(base
);
895 gen_op_load_gpr_T0(base
);
896 gen_op_set_T1(offset
);
899 /* Don't do NOP if destination is zero: we must perform the actual
902 #if defined(TARGET_MIPS64)
905 GEN_STORE_T0_REG(rt
);
910 GEN_STORE_T0_REG(rt
);
915 GEN_STORE_T0_REG(rt
);
924 save_cpu_state(ctx
, 1);
927 GEN_STORE_T0_REG(rt
);
933 GEN_STORE_T1_REG(rt
);
944 GEN_STORE_T1_REG(rt
);
955 GEN_STORE_T0_REG(rt
);
965 GEN_STORE_T0_REG(rt
);
975 GEN_STORE_T0_REG(rt
);
980 GEN_STORE_T0_REG(rt
);
990 GEN_STORE_T0_REG(rt
);
996 GEN_STORE_T1_REG(rt
);
1000 GEN_LOAD_REG_T1(rt
);
1005 GEN_LOAD_REG_T1(rt
);
1007 GEN_STORE_T1_REG(rt
);
1011 GEN_LOAD_REG_T1(rt
);
1017 GEN_STORE_T0_REG(rt
);
1021 save_cpu_state(ctx
, 1);
1022 GEN_LOAD_REG_T1(rt
);
1024 GEN_STORE_T0_REG(rt
);
1029 generate_exception(ctx
, EXCP_RI
);
1032 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1035 /* Load and store */
1036 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1037 int base
, int16_t offset
)
1039 const char *opn
= "flt_ldst";
1042 GEN_LOAD_IMM_TN(T0
, offset
);
1043 } else if (offset
== 0) {
1044 gen_op_load_gpr_T0(base
);
1046 gen_op_load_gpr_T0(base
);
1047 gen_op_set_T1(offset
);
1050 /* Don't do NOP if destination is zero: we must perform the actual
1055 GEN_STORE_FTN_FREG(ft
, WT0
);
1059 GEN_LOAD_FREG_FTN(WT0
, ft
);
1065 GEN_STORE_FTN_FREG(ft
, DT0
);
1069 GEN_LOAD_FREG_FTN(DT0
, ft
);
1075 generate_exception(ctx
, EXCP_RI
);
1078 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1081 /* Arithmetic with immediate operand */
1082 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1083 int rt
, int rs
, int16_t imm
)
1086 const char *opn
= "imm arith";
1088 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1089 /* If no destination, treat it as a NOP.
1090 For addi, we must generate the overflow exception when needed. */
1094 uimm
= (uint16_t)imm
;
1098 #if defined(TARGET_MIPS64)
1104 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1109 GEN_LOAD_REG_T0(rs
);
1110 GEN_LOAD_IMM_TN(T1
, uimm
);
1113 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1118 #if defined(TARGET_MIPS64)
1127 GEN_LOAD_REG_T0(rs
);
1128 GEN_LOAD_IMM_TN(T1
, uimm
);
1133 save_cpu_state(ctx
, 1);
1141 #if defined(TARGET_MIPS64)
1143 save_cpu_state(ctx
, 1);
1184 switch ((ctx
->opcode
>> 21) & 0x1f) {
1190 /* rotr is decoded as srl on non-R2 CPUs */
1191 if (env
->insn_flags
& ISA_MIPS32R2
) {
1200 MIPS_INVAL("invalid srl flag");
1201 generate_exception(ctx
, EXCP_RI
);
1205 #if defined(TARGET_MIPS64)
1215 switch ((ctx
->opcode
>> 21) & 0x1f) {
1221 /* drotr is decoded as dsrl on non-R2 CPUs */
1222 if (env
->insn_flags
& ISA_MIPS32R2
) {
1231 MIPS_INVAL("invalid dsrl flag");
1232 generate_exception(ctx
, EXCP_RI
);
1245 switch ((ctx
->opcode
>> 21) & 0x1f) {
1251 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1252 if (env
->insn_flags
& ISA_MIPS32R2
) {
1261 MIPS_INVAL("invalid dsrl32 flag");
1262 generate_exception(ctx
, EXCP_RI
);
1269 generate_exception(ctx
, EXCP_RI
);
1272 GEN_STORE_T0_REG(rt
);
1273 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1277 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1278 int rd
, int rs
, int rt
)
1280 const char *opn
= "arith";
1282 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1283 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1284 /* If no destination, treat it as a NOP.
1285 For add & sub, we must generate the overflow exception when needed. */
1289 GEN_LOAD_REG_T0(rs
);
1290 /* Specialcase the conventional move operation. */
1291 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1292 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1293 GEN_STORE_T0_REG(rd
);
1296 GEN_LOAD_REG_T1(rt
);
1299 save_cpu_state(ctx
, 1);
1308 save_cpu_state(ctx
, 1);
1316 #if defined(TARGET_MIPS64)
1318 save_cpu_state(ctx
, 1);
1327 save_cpu_state(ctx
, 1);
1381 switch ((ctx
->opcode
>> 6) & 0x1f) {
1387 /* rotrv is decoded as srlv on non-R2 CPUs */
1388 if (env
->insn_flags
& ISA_MIPS32R2
) {
1397 MIPS_INVAL("invalid srlv flag");
1398 generate_exception(ctx
, EXCP_RI
);
1402 #if defined(TARGET_MIPS64)
1412 switch ((ctx
->opcode
>> 6) & 0x1f) {
1418 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1419 if (env
->insn_flags
& ISA_MIPS32R2
) {
1428 MIPS_INVAL("invalid dsrlv flag");
1429 generate_exception(ctx
, EXCP_RI
);
1436 generate_exception(ctx
, EXCP_RI
);
1439 GEN_STORE_T0_REG(rd
);
1441 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1444 /* Arithmetic on HI/LO registers */
1445 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1447 const char *opn
= "hilo";
1449 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1457 GEN_STORE_T0_REG(reg
);
1462 GEN_STORE_T0_REG(reg
);
1466 GEN_LOAD_REG_T0(reg
);
1471 GEN_LOAD_REG_T0(reg
);
1477 generate_exception(ctx
, EXCP_RI
);
1480 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1483 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1486 const char *opn
= "mul/div";
1488 GEN_LOAD_REG_T0(rs
);
1489 GEN_LOAD_REG_T1(rt
);
1507 #if defined(TARGET_MIPS64)
1543 generate_exception(ctx
, EXCP_RI
);
1546 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1549 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
1550 int rd
, int rs
, int rt
)
1552 const char *opn
= "mul vr54xx";
1554 GEN_LOAD_REG_T0(rs
);
1555 GEN_LOAD_REG_T1(rt
);
1558 case OPC_VR54XX_MULS
:
1562 case OPC_VR54XX_MULSU
:
1566 case OPC_VR54XX_MACC
:
1570 case OPC_VR54XX_MACCU
:
1574 case OPC_VR54XX_MSAC
:
1578 case OPC_VR54XX_MSACU
:
1582 case OPC_VR54XX_MULHI
:
1586 case OPC_VR54XX_MULHIU
:
1590 case OPC_VR54XX_MULSHI
:
1594 case OPC_VR54XX_MULSHIU
:
1598 case OPC_VR54XX_MACCHI
:
1602 case OPC_VR54XX_MACCHIU
:
1606 case OPC_VR54XX_MSACHI
:
1610 case OPC_VR54XX_MSACHIU
:
1615 MIPS_INVAL("mul vr54xx");
1616 generate_exception(ctx
, EXCP_RI
);
1619 GEN_STORE_T0_REG(rd
);
1620 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1623 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1626 const char *opn
= "CLx";
1632 GEN_LOAD_REG_T0(rs
);
1642 #if defined(TARGET_MIPS64)
1654 generate_exception(ctx
, EXCP_RI
);
1657 gen_op_store_T0_gpr(rd
);
1658 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1662 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1663 int rs
, int rt
, int16_t imm
)
1668 /* Load needed operands */
1676 /* Compare two registers */
1678 GEN_LOAD_REG_T0(rs
);
1679 GEN_LOAD_REG_T1(rt
);
1689 /* Compare register to immediate */
1690 if (rs
!= 0 || imm
!= 0) {
1691 GEN_LOAD_REG_T0(rs
);
1692 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1699 case OPC_TEQ
: /* rs == rs */
1700 case OPC_TEQI
: /* r0 == 0 */
1701 case OPC_TGE
: /* rs >= rs */
1702 case OPC_TGEI
: /* r0 >= 0 */
1703 case OPC_TGEU
: /* rs >= rs unsigned */
1704 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1708 case OPC_TLT
: /* rs < rs */
1709 case OPC_TLTI
: /* r0 < 0 */
1710 case OPC_TLTU
: /* rs < rs unsigned */
1711 case OPC_TLTIU
: /* r0 < 0 unsigned */
1712 case OPC_TNE
: /* rs != rs */
1713 case OPC_TNEI
: /* r0 != 0 */
1714 /* Never trap: treat as NOP. */
1718 generate_exception(ctx
, EXCP_RI
);
1749 generate_exception(ctx
, EXCP_RI
);
1753 save_cpu_state(ctx
, 1);
1755 ctx
->bstate
= BS_STOP
;
1758 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1760 TranslationBlock
*tb
;
1762 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1765 tcg_gen_exit_tb((long)tb
+ n
);
1772 /* Branches (before delay slot) */
1773 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1774 int rs
, int rt
, int32_t offset
)
1776 target_ulong btarget
= -1;
1780 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1781 #ifdef MIPS_DEBUG_DISAS
1782 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1784 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1788 generate_exception(ctx
, EXCP_RI
);
1792 /* Load needed operands */
1798 /* Compare two registers */
1800 GEN_LOAD_REG_T0(rs
);
1801 GEN_LOAD_REG_T1(rt
);
1804 btarget
= ctx
->pc
+ 4 + offset
;
1818 /* Compare to zero */
1820 gen_op_load_gpr_T0(rs
);
1823 btarget
= ctx
->pc
+ 4 + offset
;
1827 /* Jump to immediate */
1828 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
1832 /* Jump to register */
1833 if (offset
!= 0 && offset
!= 16) {
1834 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1835 others are reserved. */
1836 MIPS_INVAL("jump hint");
1837 generate_exception(ctx
, EXCP_RI
);
1840 GEN_LOAD_REG_T2(rs
);
1843 MIPS_INVAL("branch/jump");
1844 generate_exception(ctx
, EXCP_RI
);
1848 /* No condition to be computed */
1850 case OPC_BEQ
: /* rx == rx */
1851 case OPC_BEQL
: /* rx == rx likely */
1852 case OPC_BGEZ
: /* 0 >= 0 */
1853 case OPC_BGEZL
: /* 0 >= 0 likely */
1854 case OPC_BLEZ
: /* 0 <= 0 */
1855 case OPC_BLEZL
: /* 0 <= 0 likely */
1857 ctx
->hflags
|= MIPS_HFLAG_B
;
1858 MIPS_DEBUG("balways");
1860 case OPC_BGEZAL
: /* 0 >= 0 */
1861 case OPC_BGEZALL
: /* 0 >= 0 likely */
1862 /* Always take and link */
1864 ctx
->hflags
|= MIPS_HFLAG_B
;
1865 MIPS_DEBUG("balways and link");
1867 case OPC_BNE
: /* rx != rx */
1868 case OPC_BGTZ
: /* 0 > 0 */
1869 case OPC_BLTZ
: /* 0 < 0 */
1871 MIPS_DEBUG("bnever (NOP)");
1873 case OPC_BLTZAL
: /* 0 < 0 */
1874 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1875 gen_op_store_T0_gpr(31);
1876 MIPS_DEBUG("bnever and link");
1878 case OPC_BLTZALL
: /* 0 < 0 likely */
1879 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1880 gen_op_store_T0_gpr(31);
1881 /* Skip the instruction in the delay slot */
1882 MIPS_DEBUG("bnever, link and skip");
1885 case OPC_BNEL
: /* rx != rx likely */
1886 case OPC_BGTZL
: /* 0 > 0 likely */
1887 case OPC_BLTZL
: /* 0 < 0 likely */
1888 /* Skip the instruction in the delay slot */
1889 MIPS_DEBUG("bnever and skip");
1893 ctx
->hflags
|= MIPS_HFLAG_B
;
1894 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1898 ctx
->hflags
|= MIPS_HFLAG_B
;
1899 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1902 ctx
->hflags
|= MIPS_HFLAG_BR
;
1903 MIPS_DEBUG("jr %s", regnames
[rs
]);
1907 ctx
->hflags
|= MIPS_HFLAG_BR
;
1908 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1911 MIPS_INVAL("branch/jump");
1912 generate_exception(ctx
, EXCP_RI
);
1919 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1920 regnames
[rs
], regnames
[rt
], btarget
);
1924 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1925 regnames
[rs
], regnames
[rt
], btarget
);
1929 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1930 regnames
[rs
], regnames
[rt
], btarget
);
1934 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1935 regnames
[rs
], regnames
[rt
], btarget
);
1939 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1943 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1947 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1953 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1957 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1961 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1965 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1969 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1973 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1977 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1982 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1984 ctx
->hflags
|= MIPS_HFLAG_BC
;
1990 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1992 ctx
->hflags
|= MIPS_HFLAG_BL
;
1994 gen_op_save_bcond();
1997 MIPS_INVAL("conditional branch/jump");
1998 generate_exception(ctx
, EXCP_RI
);
2002 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2003 blink
, ctx
->hflags
, btarget
);
2005 ctx
->btarget
= btarget
;
2007 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
2008 gen_op_store_T0_gpr(blink
);
2012 /* special3 bitfield operations */
2013 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2014 int rs
, int lsb
, int msb
)
2016 GEN_LOAD_REG_T1(rs
);
2021 gen_op_ext(lsb
, msb
+ 1);
2023 #if defined(TARGET_MIPS64)
2027 gen_op_dext(lsb
, msb
+ 1 + 32);
2032 gen_op_dext(lsb
+ 32, msb
+ 1);
2037 gen_op_dext(lsb
, msb
+ 1);
2043 GEN_LOAD_REG_T0(rt
);
2044 gen_op_ins(lsb
, msb
- lsb
+ 1);
2046 #if defined(TARGET_MIPS64)
2050 GEN_LOAD_REG_T0(rt
);
2051 gen_op_dins(lsb
, msb
- lsb
+ 1 + 32);
2056 GEN_LOAD_REG_T0(rt
);
2057 gen_op_dins(lsb
+ 32, msb
- lsb
+ 1);
2062 GEN_LOAD_REG_T0(rt
);
2063 gen_op_dins(lsb
, msb
- lsb
+ 1);
2068 MIPS_INVAL("bitops");
2069 generate_exception(ctx
, EXCP_RI
);
2072 GEN_STORE_T0_REG(rt
);
2075 /* CP0 (MMU and control) */
2076 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2078 const char *rn
= "invalid";
2081 check_insn(env
, ctx
, ISA_MIPS32
);
2087 gen_op_mfc0_index();
2091 check_insn(env
, ctx
, ASE_MT
);
2092 gen_op_mfc0_mvpcontrol();
2096 check_insn(env
, ctx
, ASE_MT
);
2097 gen_op_mfc0_mvpconf0();
2101 check_insn(env
, ctx
, ASE_MT
);
2102 gen_op_mfc0_mvpconf1();
2112 gen_op_mfc0_random();
2116 check_insn(env
, ctx
, ASE_MT
);
2117 gen_op_mfc0_vpecontrol();
2121 check_insn(env
, ctx
, ASE_MT
);
2122 gen_op_mfc0_vpeconf0();
2126 check_insn(env
, ctx
, ASE_MT
);
2127 gen_op_mfc0_vpeconf1();
2131 check_insn(env
, ctx
, ASE_MT
);
2132 gen_op_mfc0_yqmask();
2136 check_insn(env
, ctx
, ASE_MT
);
2137 gen_op_mfc0_vpeschedule();
2141 check_insn(env
, ctx
, ASE_MT
);
2142 gen_op_mfc0_vpeschefback();
2143 rn
= "VPEScheFBack";
2146 check_insn(env
, ctx
, ASE_MT
);
2147 gen_op_mfc0_vpeopt();
2157 gen_op_mfc0_entrylo0();
2161 check_insn(env
, ctx
, ASE_MT
);
2162 gen_op_mfc0_tcstatus();
2166 check_insn(env
, ctx
, ASE_MT
);
2167 gen_op_mfc0_tcbind();
2171 check_insn(env
, ctx
, ASE_MT
);
2172 gen_op_mfc0_tcrestart();
2176 check_insn(env
, ctx
, ASE_MT
);
2177 gen_op_mfc0_tchalt();
2181 check_insn(env
, ctx
, ASE_MT
);
2182 gen_op_mfc0_tccontext();
2186 check_insn(env
, ctx
, ASE_MT
);
2187 gen_op_mfc0_tcschedule();
2191 check_insn(env
, ctx
, ASE_MT
);
2192 gen_op_mfc0_tcschefback();
2202 gen_op_mfc0_entrylo1();
2212 gen_op_mfc0_context();
2216 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2217 rn
= "ContextConfig";
2226 gen_op_mfc0_pagemask();
2230 check_insn(env
, ctx
, ISA_MIPS32R2
);
2231 gen_op_mfc0_pagegrain();
2241 gen_op_mfc0_wired();
2245 check_insn(env
, ctx
, ISA_MIPS32R2
);
2246 gen_op_mfc0_srsconf0();
2250 check_insn(env
, ctx
, ISA_MIPS32R2
);
2251 gen_op_mfc0_srsconf1();
2255 check_insn(env
, ctx
, ISA_MIPS32R2
);
2256 gen_op_mfc0_srsconf2();
2260 check_insn(env
, ctx
, ISA_MIPS32R2
);
2261 gen_op_mfc0_srsconf3();
2265 check_insn(env
, ctx
, ISA_MIPS32R2
);
2266 gen_op_mfc0_srsconf4();
2276 check_insn(env
, ctx
, ISA_MIPS32R2
);
2277 gen_op_mfc0_hwrena();
2287 gen_op_mfc0_badvaddr();
2297 gen_op_mfc0_count();
2300 /* 6,7 are implementation dependent */
2308 gen_op_mfc0_entryhi();
2318 gen_op_mfc0_compare();
2321 /* 6,7 are implementation dependent */
2329 gen_op_mfc0_status();
2333 check_insn(env
, ctx
, ISA_MIPS32R2
);
2334 gen_op_mfc0_intctl();
2338 check_insn(env
, ctx
, ISA_MIPS32R2
);
2339 gen_op_mfc0_srsctl();
2343 check_insn(env
, ctx
, ISA_MIPS32R2
);
2344 gen_op_mfc0_srsmap();
2354 gen_op_mfc0_cause();
2378 check_insn(env
, ctx
, ISA_MIPS32R2
);
2379 gen_op_mfc0_ebase();
2389 gen_op_mfc0_config0();
2393 gen_op_mfc0_config1();
2397 gen_op_mfc0_config2();
2401 gen_op_mfc0_config3();
2404 /* 4,5 are reserved */
2405 /* 6,7 are implementation dependent */
2407 gen_op_mfc0_config6();
2411 gen_op_mfc0_config7();
2421 gen_op_mfc0_lladdr();
2431 gen_op_mfc0_watchlo(sel
);
2441 gen_op_mfc0_watchhi(sel
);
2451 #if defined(TARGET_MIPS64)
2452 check_insn(env
, ctx
, ISA_MIPS3
);
2453 gen_op_mfc0_xcontext();
2462 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2465 gen_op_mfc0_framemask();
2474 rn
= "'Diagnostic"; /* implementation dependent */
2479 gen_op_mfc0_debug(); /* EJTAG support */
2483 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2484 rn
= "TraceControl";
2487 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2488 rn
= "TraceControl2";
2491 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2492 rn
= "UserTraceData";
2495 // gen_op_mfc0_debug(); /* PDtrace support */
2505 gen_op_mfc0_depc(); /* EJTAG support */
2515 gen_op_mfc0_performance0();
2516 rn
= "Performance0";
2519 // gen_op_mfc0_performance1();
2520 rn
= "Performance1";
2523 // gen_op_mfc0_performance2();
2524 rn
= "Performance2";
2527 // gen_op_mfc0_performance3();
2528 rn
= "Performance3";
2531 // gen_op_mfc0_performance4();
2532 rn
= "Performance4";
2535 // gen_op_mfc0_performance5();
2536 rn
= "Performance5";
2539 // gen_op_mfc0_performance6();
2540 rn
= "Performance6";
2543 // gen_op_mfc0_performance7();
2544 rn
= "Performance7";
2569 gen_op_mfc0_taglo();
2576 gen_op_mfc0_datalo();
2589 gen_op_mfc0_taghi();
2596 gen_op_mfc0_datahi();
2606 gen_op_mfc0_errorepc();
2616 gen_op_mfc0_desave(); /* EJTAG support */
2626 #if defined MIPS_DEBUG_DISAS
2627 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2628 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2635 #if defined MIPS_DEBUG_DISAS
2636 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2637 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2641 generate_exception(ctx
, EXCP_RI
);
2644 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2646 const char *rn
= "invalid";
2649 check_insn(env
, ctx
, ISA_MIPS32
);
2655 gen_op_mtc0_index();
2659 check_insn(env
, ctx
, ASE_MT
);
2660 gen_op_mtc0_mvpcontrol();
2664 check_insn(env
, ctx
, ASE_MT
);
2669 check_insn(env
, ctx
, ASE_MT
);
2684 check_insn(env
, ctx
, ASE_MT
);
2685 gen_op_mtc0_vpecontrol();
2689 check_insn(env
, ctx
, ASE_MT
);
2690 gen_op_mtc0_vpeconf0();
2694 check_insn(env
, ctx
, ASE_MT
);
2695 gen_op_mtc0_vpeconf1();
2699 check_insn(env
, ctx
, ASE_MT
);
2700 gen_op_mtc0_yqmask();
2704 check_insn(env
, ctx
, ASE_MT
);
2705 gen_op_mtc0_vpeschedule();
2709 check_insn(env
, ctx
, ASE_MT
);
2710 gen_op_mtc0_vpeschefback();
2711 rn
= "VPEScheFBack";
2714 check_insn(env
, ctx
, ASE_MT
);
2715 gen_op_mtc0_vpeopt();
2725 gen_op_mtc0_entrylo0();
2729 check_insn(env
, ctx
, ASE_MT
);
2730 gen_op_mtc0_tcstatus();
2734 check_insn(env
, ctx
, ASE_MT
);
2735 gen_op_mtc0_tcbind();
2739 check_insn(env
, ctx
, ASE_MT
);
2740 gen_op_mtc0_tcrestart();
2744 check_insn(env
, ctx
, ASE_MT
);
2745 gen_op_mtc0_tchalt();
2749 check_insn(env
, ctx
, ASE_MT
);
2750 gen_op_mtc0_tccontext();
2754 check_insn(env
, ctx
, ASE_MT
);
2755 gen_op_mtc0_tcschedule();
2759 check_insn(env
, ctx
, ASE_MT
);
2760 gen_op_mtc0_tcschefback();
2770 gen_op_mtc0_entrylo1();
2780 gen_op_mtc0_context();
2784 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2785 rn
= "ContextConfig";
2794 gen_op_mtc0_pagemask();
2798 check_insn(env
, ctx
, ISA_MIPS32R2
);
2799 gen_op_mtc0_pagegrain();
2809 gen_op_mtc0_wired();
2813 check_insn(env
, ctx
, ISA_MIPS32R2
);
2814 gen_op_mtc0_srsconf0();
2818 check_insn(env
, ctx
, ISA_MIPS32R2
);
2819 gen_op_mtc0_srsconf1();
2823 check_insn(env
, ctx
, ISA_MIPS32R2
);
2824 gen_op_mtc0_srsconf2();
2828 check_insn(env
, ctx
, ISA_MIPS32R2
);
2829 gen_op_mtc0_srsconf3();
2833 check_insn(env
, ctx
, ISA_MIPS32R2
);
2834 gen_op_mtc0_srsconf4();
2844 check_insn(env
, ctx
, ISA_MIPS32R2
);
2845 gen_op_mtc0_hwrena();
2859 gen_op_mtc0_count();
2862 /* 6,7 are implementation dependent */
2866 /* Stop translation as we may have switched the execution mode */
2867 ctx
->bstate
= BS_STOP
;
2872 gen_op_mtc0_entryhi();
2882 gen_op_mtc0_compare();
2885 /* 6,7 are implementation dependent */
2889 /* Stop translation as we may have switched the execution mode */
2890 ctx
->bstate
= BS_STOP
;
2895 gen_op_mtc0_status();
2896 /* BS_STOP isn't good enough here, hflags may have changed. */
2897 gen_save_pc(ctx
->pc
+ 4);
2898 ctx
->bstate
= BS_EXCP
;
2902 check_insn(env
, ctx
, ISA_MIPS32R2
);
2903 gen_op_mtc0_intctl();
2904 /* Stop translation as we may have switched the execution mode */
2905 ctx
->bstate
= BS_STOP
;
2909 check_insn(env
, ctx
, ISA_MIPS32R2
);
2910 gen_op_mtc0_srsctl();
2911 /* Stop translation as we may have switched the execution mode */
2912 ctx
->bstate
= BS_STOP
;
2916 check_insn(env
, ctx
, ISA_MIPS32R2
);
2917 gen_op_mtc0_srsmap();
2918 /* Stop translation as we may have switched the execution mode */
2919 ctx
->bstate
= BS_STOP
;
2929 gen_op_mtc0_cause();
2935 /* Stop translation as we may have switched the execution mode */
2936 ctx
->bstate
= BS_STOP
;
2955 check_insn(env
, ctx
, ISA_MIPS32R2
);
2956 gen_op_mtc0_ebase();
2966 gen_op_mtc0_config0();
2968 /* Stop translation as we may have switched the execution mode */
2969 ctx
->bstate
= BS_STOP
;
2972 /* ignored, read only */
2976 gen_op_mtc0_config2();
2978 /* Stop translation as we may have switched the execution mode */
2979 ctx
->bstate
= BS_STOP
;
2982 /* ignored, read only */
2985 /* 4,5 are reserved */
2986 /* 6,7 are implementation dependent */
2996 rn
= "Invalid config selector";
3013 gen_op_mtc0_watchlo(sel
);
3023 gen_op_mtc0_watchhi(sel
);
3033 #if defined(TARGET_MIPS64)
3034 check_insn(env
, ctx
, ISA_MIPS3
);
3035 gen_op_mtc0_xcontext();
3044 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3047 gen_op_mtc0_framemask();
3056 rn
= "Diagnostic"; /* implementation dependent */
3061 gen_op_mtc0_debug(); /* EJTAG support */
3062 /* BS_STOP isn't good enough here, hflags may have changed. */
3063 gen_save_pc(ctx
->pc
+ 4);
3064 ctx
->bstate
= BS_EXCP
;
3068 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3069 rn
= "TraceControl";
3070 /* Stop translation as we may have switched the execution mode */
3071 ctx
->bstate
= BS_STOP
;
3074 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3075 rn
= "TraceControl2";
3076 /* Stop translation as we may have switched the execution mode */
3077 ctx
->bstate
= BS_STOP
;
3080 /* Stop translation as we may have switched the execution mode */
3081 ctx
->bstate
= BS_STOP
;
3082 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3083 rn
= "UserTraceData";
3084 /* Stop translation as we may have switched the execution mode */
3085 ctx
->bstate
= BS_STOP
;
3088 // gen_op_mtc0_debug(); /* PDtrace support */
3089 /* Stop translation as we may have switched the execution mode */
3090 ctx
->bstate
= BS_STOP
;
3100 gen_op_mtc0_depc(); /* EJTAG support */
3110 gen_op_mtc0_performance0();
3111 rn
= "Performance0";
3114 // gen_op_mtc0_performance1();
3115 rn
= "Performance1";
3118 // gen_op_mtc0_performance2();
3119 rn
= "Performance2";
3122 // gen_op_mtc0_performance3();
3123 rn
= "Performance3";
3126 // gen_op_mtc0_performance4();
3127 rn
= "Performance4";
3130 // gen_op_mtc0_performance5();
3131 rn
= "Performance5";
3134 // gen_op_mtc0_performance6();
3135 rn
= "Performance6";
3138 // gen_op_mtc0_performance7();
3139 rn
= "Performance7";
3165 gen_op_mtc0_taglo();
3172 gen_op_mtc0_datalo();
3185 gen_op_mtc0_taghi();
3192 gen_op_mtc0_datahi();
3203 gen_op_mtc0_errorepc();
3213 gen_op_mtc0_desave(); /* EJTAG support */
3219 /* Stop translation as we may have switched the execution mode */
3220 ctx
->bstate
= BS_STOP
;
3225 #if defined MIPS_DEBUG_DISAS
3226 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3227 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3234 #if defined MIPS_DEBUG_DISAS
3235 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3236 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3240 generate_exception(ctx
, EXCP_RI
);
3243 #if defined(TARGET_MIPS64)
3244 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3246 const char *rn
= "invalid";
3249 check_insn(env
, ctx
, ISA_MIPS64
);
3255 gen_op_mfc0_index();
3259 check_insn(env
, ctx
, ASE_MT
);
3260 gen_op_mfc0_mvpcontrol();
3264 check_insn(env
, ctx
, ASE_MT
);
3265 gen_op_mfc0_mvpconf0();
3269 check_insn(env
, ctx
, ASE_MT
);
3270 gen_op_mfc0_mvpconf1();
3280 gen_op_mfc0_random();
3284 check_insn(env
, ctx
, ASE_MT
);
3285 gen_op_mfc0_vpecontrol();
3289 check_insn(env
, ctx
, ASE_MT
);
3290 gen_op_mfc0_vpeconf0();
3294 check_insn(env
, ctx
, ASE_MT
);
3295 gen_op_mfc0_vpeconf1();
3299 check_insn(env
, ctx
, ASE_MT
);
3300 gen_op_dmfc0_yqmask();
3304 check_insn(env
, ctx
, ASE_MT
);
3305 gen_op_dmfc0_vpeschedule();
3309 check_insn(env
, ctx
, ASE_MT
);
3310 gen_op_dmfc0_vpeschefback();
3311 rn
= "VPEScheFBack";
3314 check_insn(env
, ctx
, ASE_MT
);
3315 gen_op_mfc0_vpeopt();
3325 gen_op_dmfc0_entrylo0();
3329 check_insn(env
, ctx
, ASE_MT
);
3330 gen_op_mfc0_tcstatus();
3334 check_insn(env
, ctx
, ASE_MT
);
3335 gen_op_mfc0_tcbind();
3339 check_insn(env
, ctx
, ASE_MT
);
3340 gen_op_dmfc0_tcrestart();
3344 check_insn(env
, ctx
, ASE_MT
);
3345 gen_op_dmfc0_tchalt();
3349 check_insn(env
, ctx
, ASE_MT
);
3350 gen_op_dmfc0_tccontext();
3354 check_insn(env
, ctx
, ASE_MT
);
3355 gen_op_dmfc0_tcschedule();
3359 check_insn(env
, ctx
, ASE_MT
);
3360 gen_op_dmfc0_tcschefback();
3370 gen_op_dmfc0_entrylo1();
3380 gen_op_dmfc0_context();
3384 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3385 rn
= "ContextConfig";
3394 gen_op_mfc0_pagemask();
3398 check_insn(env
, ctx
, ISA_MIPS32R2
);
3399 gen_op_mfc0_pagegrain();
3409 gen_op_mfc0_wired();
3413 check_insn(env
, ctx
, ISA_MIPS32R2
);
3414 gen_op_mfc0_srsconf0();
3418 check_insn(env
, ctx
, ISA_MIPS32R2
);
3419 gen_op_mfc0_srsconf1();
3423 check_insn(env
, ctx
, ISA_MIPS32R2
);
3424 gen_op_mfc0_srsconf2();
3428 check_insn(env
, ctx
, ISA_MIPS32R2
);
3429 gen_op_mfc0_srsconf3();
3433 check_insn(env
, ctx
, ISA_MIPS32R2
);
3434 gen_op_mfc0_srsconf4();
3444 check_insn(env
, ctx
, ISA_MIPS32R2
);
3445 gen_op_mfc0_hwrena();
3455 gen_op_dmfc0_badvaddr();
3465 gen_op_mfc0_count();
3468 /* 6,7 are implementation dependent */
3476 gen_op_dmfc0_entryhi();
3486 gen_op_mfc0_compare();
3489 /* 6,7 are implementation dependent */
3497 gen_op_mfc0_status();
3501 check_insn(env
, ctx
, ISA_MIPS32R2
);
3502 gen_op_mfc0_intctl();
3506 check_insn(env
, ctx
, ISA_MIPS32R2
);
3507 gen_op_mfc0_srsctl();
3511 check_insn(env
, ctx
, ISA_MIPS32R2
);
3512 gen_op_mfc0_srsmap();
3522 gen_op_mfc0_cause();
3546 check_insn(env
, ctx
, ISA_MIPS32R2
);
3547 gen_op_mfc0_ebase();
3557 gen_op_mfc0_config0();
3561 gen_op_mfc0_config1();
3565 gen_op_mfc0_config2();
3569 gen_op_mfc0_config3();
3572 /* 6,7 are implementation dependent */
3580 gen_op_dmfc0_lladdr();
3590 gen_op_dmfc0_watchlo(sel
);
3600 gen_op_mfc0_watchhi(sel
);
3610 check_insn(env
, ctx
, ISA_MIPS3
);
3611 gen_op_dmfc0_xcontext();
3619 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3622 gen_op_mfc0_framemask();
3631 rn
= "'Diagnostic"; /* implementation dependent */
3636 gen_op_mfc0_debug(); /* EJTAG support */
3640 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3641 rn
= "TraceControl";
3644 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3645 rn
= "TraceControl2";
3648 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3649 rn
= "UserTraceData";
3652 // gen_op_dmfc0_debug(); /* PDtrace support */
3662 gen_op_dmfc0_depc(); /* EJTAG support */
3672 gen_op_mfc0_performance0();
3673 rn
= "Performance0";
3676 // gen_op_dmfc0_performance1();
3677 rn
= "Performance1";
3680 // gen_op_dmfc0_performance2();
3681 rn
= "Performance2";
3684 // gen_op_dmfc0_performance3();
3685 rn
= "Performance3";
3688 // gen_op_dmfc0_performance4();
3689 rn
= "Performance4";
3692 // gen_op_dmfc0_performance5();
3693 rn
= "Performance5";
3696 // gen_op_dmfc0_performance6();
3697 rn
= "Performance6";
3700 // gen_op_dmfc0_performance7();
3701 rn
= "Performance7";
3726 gen_op_mfc0_taglo();
3733 gen_op_mfc0_datalo();
3746 gen_op_mfc0_taghi();
3753 gen_op_mfc0_datahi();
3763 gen_op_dmfc0_errorepc();
3773 gen_op_mfc0_desave(); /* EJTAG support */
3783 #if defined MIPS_DEBUG_DISAS
3784 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3785 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3792 #if defined MIPS_DEBUG_DISAS
3793 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3794 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3798 generate_exception(ctx
, EXCP_RI
);
3801 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3803 const char *rn
= "invalid";
3806 check_insn(env
, ctx
, ISA_MIPS64
);
3812 gen_op_mtc0_index();
3816 check_insn(env
, ctx
, ASE_MT
);
3817 gen_op_mtc0_mvpcontrol();
3821 check_insn(env
, ctx
, ASE_MT
);
3826 check_insn(env
, ctx
, ASE_MT
);
3841 check_insn(env
, ctx
, ASE_MT
);
3842 gen_op_mtc0_vpecontrol();
3846 check_insn(env
, ctx
, ASE_MT
);
3847 gen_op_mtc0_vpeconf0();
3851 check_insn(env
, ctx
, ASE_MT
);
3852 gen_op_mtc0_vpeconf1();
3856 check_insn(env
, ctx
, ASE_MT
);
3857 gen_op_mtc0_yqmask();
3861 check_insn(env
, ctx
, ASE_MT
);
3862 gen_op_mtc0_vpeschedule();
3866 check_insn(env
, ctx
, ASE_MT
);
3867 gen_op_mtc0_vpeschefback();
3868 rn
= "VPEScheFBack";
3871 check_insn(env
, ctx
, ASE_MT
);
3872 gen_op_mtc0_vpeopt();
3882 gen_op_mtc0_entrylo0();
3886 check_insn(env
, ctx
, ASE_MT
);
3887 gen_op_mtc0_tcstatus();
3891 check_insn(env
, ctx
, ASE_MT
);
3892 gen_op_mtc0_tcbind();
3896 check_insn(env
, ctx
, ASE_MT
);
3897 gen_op_mtc0_tcrestart();
3901 check_insn(env
, ctx
, ASE_MT
);
3902 gen_op_mtc0_tchalt();
3906 check_insn(env
, ctx
, ASE_MT
);
3907 gen_op_mtc0_tccontext();
3911 check_insn(env
, ctx
, ASE_MT
);
3912 gen_op_mtc0_tcschedule();
3916 check_insn(env
, ctx
, ASE_MT
);
3917 gen_op_mtc0_tcschefback();
3927 gen_op_mtc0_entrylo1();
3937 gen_op_mtc0_context();
3941 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3942 rn
= "ContextConfig";
3951 gen_op_mtc0_pagemask();
3955 check_insn(env
, ctx
, ISA_MIPS32R2
);
3956 gen_op_mtc0_pagegrain();
3966 gen_op_mtc0_wired();
3970 check_insn(env
, ctx
, ISA_MIPS32R2
);
3971 gen_op_mtc0_srsconf0();
3975 check_insn(env
, ctx
, ISA_MIPS32R2
);
3976 gen_op_mtc0_srsconf1();
3980 check_insn(env
, ctx
, ISA_MIPS32R2
);
3981 gen_op_mtc0_srsconf2();
3985 check_insn(env
, ctx
, ISA_MIPS32R2
);
3986 gen_op_mtc0_srsconf3();
3990 check_insn(env
, ctx
, ISA_MIPS32R2
);
3991 gen_op_mtc0_srsconf4();
4001 check_insn(env
, ctx
, ISA_MIPS32R2
);
4002 gen_op_mtc0_hwrena();
4016 gen_op_mtc0_count();
4019 /* 6,7 are implementation dependent */
4023 /* Stop translation as we may have switched the execution mode */
4024 ctx
->bstate
= BS_STOP
;
4029 gen_op_mtc0_entryhi();
4039 gen_op_mtc0_compare();
4042 /* 6,7 are implementation dependent */
4046 /* Stop translation as we may have switched the execution mode */
4047 ctx
->bstate
= BS_STOP
;
4052 gen_op_mtc0_status();
4053 /* BS_STOP isn't good enough here, hflags may have changed. */
4054 gen_save_pc(ctx
->pc
+ 4);
4055 ctx
->bstate
= BS_EXCP
;
4059 check_insn(env
, ctx
, ISA_MIPS32R2
);
4060 gen_op_mtc0_intctl();
4061 /* Stop translation as we may have switched the execution mode */
4062 ctx
->bstate
= BS_STOP
;
4066 check_insn(env
, ctx
, ISA_MIPS32R2
);
4067 gen_op_mtc0_srsctl();
4068 /* Stop translation as we may have switched the execution mode */
4069 ctx
->bstate
= BS_STOP
;
4073 check_insn(env
, ctx
, ISA_MIPS32R2
);
4074 gen_op_mtc0_srsmap();
4075 /* Stop translation as we may have switched the execution mode */
4076 ctx
->bstate
= BS_STOP
;
4086 gen_op_mtc0_cause();
4092 /* Stop translation as we may have switched the execution mode */
4093 ctx
->bstate
= BS_STOP
;
4112 check_insn(env
, ctx
, ISA_MIPS32R2
);
4113 gen_op_mtc0_ebase();
4123 gen_op_mtc0_config0();
4125 /* Stop translation as we may have switched the execution mode */
4126 ctx
->bstate
= BS_STOP
;
4133 gen_op_mtc0_config2();
4135 /* Stop translation as we may have switched the execution mode */
4136 ctx
->bstate
= BS_STOP
;
4142 /* 6,7 are implementation dependent */
4144 rn
= "Invalid config selector";
4161 gen_op_mtc0_watchlo(sel
);
4171 gen_op_mtc0_watchhi(sel
);
4181 check_insn(env
, ctx
, ISA_MIPS3
);
4182 gen_op_mtc0_xcontext();
4190 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4193 gen_op_mtc0_framemask();
4202 rn
= "Diagnostic"; /* implementation dependent */
4207 gen_op_mtc0_debug(); /* EJTAG support */
4208 /* BS_STOP isn't good enough here, hflags may have changed. */
4209 gen_save_pc(ctx
->pc
+ 4);
4210 ctx
->bstate
= BS_EXCP
;
4214 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4215 /* Stop translation as we may have switched the execution mode */
4216 ctx
->bstate
= BS_STOP
;
4217 rn
= "TraceControl";
4220 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4221 /* Stop translation as we may have switched the execution mode */
4222 ctx
->bstate
= BS_STOP
;
4223 rn
= "TraceControl2";
4226 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4227 /* Stop translation as we may have switched the execution mode */
4228 ctx
->bstate
= BS_STOP
;
4229 rn
= "UserTraceData";
4232 // gen_op_mtc0_debug(); /* PDtrace support */
4233 /* Stop translation as we may have switched the execution mode */
4234 ctx
->bstate
= BS_STOP
;
4244 gen_op_mtc0_depc(); /* EJTAG support */
4254 gen_op_mtc0_performance0();
4255 rn
= "Performance0";
4258 // gen_op_mtc0_performance1();
4259 rn
= "Performance1";
4262 // gen_op_mtc0_performance2();
4263 rn
= "Performance2";
4266 // gen_op_mtc0_performance3();
4267 rn
= "Performance3";
4270 // gen_op_mtc0_performance4();
4271 rn
= "Performance4";
4274 // gen_op_mtc0_performance5();
4275 rn
= "Performance5";
4278 // gen_op_mtc0_performance6();
4279 rn
= "Performance6";
4282 // gen_op_mtc0_performance7();
4283 rn
= "Performance7";
4309 gen_op_mtc0_taglo();
4316 gen_op_mtc0_datalo();
4329 gen_op_mtc0_taghi();
4336 gen_op_mtc0_datahi();
4347 gen_op_mtc0_errorepc();
4357 gen_op_mtc0_desave(); /* EJTAG support */
4363 /* Stop translation as we may have switched the execution mode */
4364 ctx
->bstate
= BS_STOP
;
4369 #if defined MIPS_DEBUG_DISAS
4370 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4371 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4378 #if defined MIPS_DEBUG_DISAS
4379 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4380 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4384 generate_exception(ctx
, EXCP_RI
);
4386 #endif /* TARGET_MIPS64 */
4388 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
4389 int u
, int sel
, int h
)
4391 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4393 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4394 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4395 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4397 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4398 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4405 gen_op_mftc0_tcstatus();
4408 gen_op_mftc0_tcbind();
4411 gen_op_mftc0_tcrestart();
4414 gen_op_mftc0_tchalt();
4417 gen_op_mftc0_tccontext();
4420 gen_op_mftc0_tcschedule();
4423 gen_op_mftc0_tcschefback();
4426 gen_mfc0(env
, ctx
, rt
, sel
);
4433 gen_op_mftc0_entryhi();
4436 gen_mfc0(env
, ctx
, rt
, sel
);
4442 gen_op_mftc0_status();
4445 gen_mfc0(env
, ctx
, rt
, sel
);
4451 gen_op_mftc0_debug();
4454 gen_mfc0(env
, ctx
, rt
, sel
);
4459 gen_mfc0(env
, ctx
, rt
, sel
);
4461 } else switch (sel
) {
4462 /* GPR registers. */
4466 /* Auxiliary CPU registers */
4512 /* Floating point (COP1). */
4514 /* XXX: For now we support only a single FPU context. */
4516 GEN_LOAD_FREG_FTN(WT0
, rt
);
4519 GEN_LOAD_FREG_FTN(WTH0
, rt
);
4524 /* XXX: For now we support only a single FPU context. */
4527 /* COP2: Not implemented. */
4534 #if defined MIPS_DEBUG_DISAS
4535 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4536 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4543 #if defined MIPS_DEBUG_DISAS
4544 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4545 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
4549 generate_exception(ctx
, EXCP_RI
);
4552 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
4553 int u
, int sel
, int h
)
4555 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
4557 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
4558 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
4559 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
4561 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
4562 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
4569 gen_op_mttc0_tcstatus();
4572 gen_op_mttc0_tcbind();
4575 gen_op_mttc0_tcrestart();
4578 gen_op_mttc0_tchalt();
4581 gen_op_mttc0_tccontext();
4584 gen_op_mttc0_tcschedule();
4587 gen_op_mttc0_tcschefback();
4590 gen_mtc0(env
, ctx
, rd
, sel
);
4597 gen_op_mttc0_entryhi();
4600 gen_mtc0(env
, ctx
, rd
, sel
);
4606 gen_op_mttc0_status();
4609 gen_mtc0(env
, ctx
, rd
, sel
);
4615 gen_op_mttc0_debug();
4618 gen_mtc0(env
, ctx
, rd
, sel
);
4623 gen_mtc0(env
, ctx
, rd
, sel
);
4625 } else switch (sel
) {
4626 /* GPR registers. */
4630 /* Auxiliary CPU registers */
4676 /* Floating point (COP1). */
4678 /* XXX: For now we support only a single FPU context. */
4681 GEN_STORE_FTN_FREG(rd
, WT0
);
4684 GEN_STORE_FTN_FREG(rd
, WTH0
);
4688 /* XXX: For now we support only a single FPU context. */
4691 /* COP2: Not implemented. */
4698 #if defined MIPS_DEBUG_DISAS
4699 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4700 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4707 #if defined MIPS_DEBUG_DISAS
4708 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4709 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
4713 generate_exception(ctx
, EXCP_RI
);
4716 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4718 const char *opn
= "ldst";
4726 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4727 gen_op_store_T0_gpr(rt
);
4731 GEN_LOAD_REG_T0(rt
);
4732 save_cpu_state(ctx
, 1);
4733 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4736 #if defined(TARGET_MIPS64)
4738 check_insn(env
, ctx
, ISA_MIPS3
);
4743 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4744 gen_op_store_T0_gpr(rt
);
4748 check_insn(env
, ctx
, ISA_MIPS3
);
4749 GEN_LOAD_REG_T0(rt
);
4750 save_cpu_state(ctx
, 1);
4751 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
4756 check_insn(env
, ctx
, ASE_MT
);
4761 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
4762 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4763 gen_op_store_T0_gpr(rd
);
4767 check_insn(env
, ctx
, ASE_MT
);
4768 GEN_LOAD_REG_T0(rt
);
4769 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
4770 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
4775 if (!env
->tlb
->do_tlbwi
)
4781 if (!env
->tlb
->do_tlbwr
)
4787 if (!env
->tlb
->do_tlbp
)
4793 if (!env
->tlb
->do_tlbr
)
4799 check_insn(env
, ctx
, ISA_MIPS2
);
4800 save_cpu_state(ctx
, 1);
4802 ctx
->bstate
= BS_EXCP
;
4806 check_insn(env
, ctx
, ISA_MIPS32
);
4807 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4809 generate_exception(ctx
, EXCP_RI
);
4811 save_cpu_state(ctx
, 1);
4813 ctx
->bstate
= BS_EXCP
;
4818 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
4819 /* If we get an exception, we want to restart at next instruction */
4821 save_cpu_state(ctx
, 1);
4824 ctx
->bstate
= BS_EXCP
;
4829 generate_exception(ctx
, EXCP_RI
);
4832 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4835 /* CP1 Branches (before delay slot) */
4836 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
4837 int32_t cc
, int32_t offset
)
4839 target_ulong btarget
;
4840 const char *opn
= "cp1 cond branch";
4843 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
4845 btarget
= ctx
->pc
+ 4 + offset
;
4864 ctx
->hflags
|= MIPS_HFLAG_BL
;
4866 gen_op_save_bcond();
4869 gen_op_bc1any2f(cc
);
4873 gen_op_bc1any2t(cc
);
4877 gen_op_bc1any4f(cc
);
4881 gen_op_bc1any4t(cc
);
4884 ctx
->hflags
|= MIPS_HFLAG_BC
;
4889 generate_exception (ctx
, EXCP_RI
);
4892 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4893 ctx
->hflags
, btarget
);
4894 ctx
->btarget
= btarget
;
4897 /* Coprocessor 1 (FPU) */
4899 #define FOP(func, fmt) (((fmt) << 21) | (func))
4901 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4903 const char *opn
= "cp1 move";
4907 GEN_LOAD_FREG_FTN(WT0
, fs
);
4909 GEN_STORE_T0_REG(rt
);
4913 GEN_LOAD_REG_T0(rt
);
4915 GEN_STORE_FTN_FREG(fs
, WT0
);
4920 GEN_STORE_T0_REG(rt
);
4924 GEN_LOAD_REG_T0(rt
);
4929 GEN_LOAD_FREG_FTN(DT0
, fs
);
4931 GEN_STORE_T0_REG(rt
);
4935 GEN_LOAD_REG_T0(rt
);
4937 GEN_STORE_FTN_FREG(fs
, DT0
);
4941 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4943 GEN_STORE_T0_REG(rt
);
4947 GEN_LOAD_REG_T0(rt
);
4949 GEN_STORE_FTN_FREG(fs
, WTH0
);
4954 generate_exception (ctx
, EXCP_RI
);
4957 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4960 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4964 GEN_LOAD_REG_T0(rd
);
4965 GEN_LOAD_REG_T1(rs
);
4967 ccbit
= 1 << (24 + cc
);
4974 GEN_STORE_T0_REG(rd
);
4977 #define GEN_MOVCF(fmt) \
4978 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4983 ccbit = 1 << (24 + cc); \
4987 glue(gen_op_float_movf_, fmt)(ccbit); \
4989 glue(gen_op_float_movt_, fmt)(ccbit); \
4996 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4997 int ft
, int fs
, int fd
, int cc
)
4999 const char *opn
= "farith";
5000 const char *condnames
[] = {
5018 const char *condnames_abs
[] = {
5036 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5037 uint32_t func
= ctx
->opcode
& 0x3f;
5039 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5041 GEN_LOAD_FREG_FTN(WT0
, fs
);
5042 GEN_LOAD_FREG_FTN(WT1
, ft
);
5043 gen_op_float_add_s();
5044 GEN_STORE_FTN_FREG(fd
, WT2
);
5049 GEN_LOAD_FREG_FTN(WT0
, fs
);
5050 GEN_LOAD_FREG_FTN(WT1
, ft
);
5051 gen_op_float_sub_s();
5052 GEN_STORE_FTN_FREG(fd
, WT2
);
5057 GEN_LOAD_FREG_FTN(WT0
, fs
);
5058 GEN_LOAD_FREG_FTN(WT1
, ft
);
5059 gen_op_float_mul_s();
5060 GEN_STORE_FTN_FREG(fd
, WT2
);
5065 GEN_LOAD_FREG_FTN(WT0
, fs
);
5066 GEN_LOAD_FREG_FTN(WT1
, ft
);
5067 gen_op_float_div_s();
5068 GEN_STORE_FTN_FREG(fd
, WT2
);
5073 GEN_LOAD_FREG_FTN(WT0
, fs
);
5074 gen_op_float_sqrt_s();
5075 GEN_STORE_FTN_FREG(fd
, WT2
);
5079 GEN_LOAD_FREG_FTN(WT0
, fs
);
5080 gen_op_float_abs_s();
5081 GEN_STORE_FTN_FREG(fd
, WT2
);
5085 GEN_LOAD_FREG_FTN(WT0
, fs
);
5086 gen_op_float_mov_s();
5087 GEN_STORE_FTN_FREG(fd
, WT2
);
5091 GEN_LOAD_FREG_FTN(WT0
, fs
);
5092 gen_op_float_chs_s();
5093 GEN_STORE_FTN_FREG(fd
, WT2
);
5097 check_cp1_64bitmode(ctx
);
5098 GEN_LOAD_FREG_FTN(WT0
, fs
);
5099 gen_op_float_roundl_s();
5100 GEN_STORE_FTN_FREG(fd
, DT2
);
5104 check_cp1_64bitmode(ctx
);
5105 GEN_LOAD_FREG_FTN(WT0
, fs
);
5106 gen_op_float_truncl_s();
5107 GEN_STORE_FTN_FREG(fd
, DT2
);
5111 check_cp1_64bitmode(ctx
);
5112 GEN_LOAD_FREG_FTN(WT0
, fs
);
5113 gen_op_float_ceill_s();
5114 GEN_STORE_FTN_FREG(fd
, DT2
);
5118 check_cp1_64bitmode(ctx
);
5119 GEN_LOAD_FREG_FTN(WT0
, fs
);
5120 gen_op_float_floorl_s();
5121 GEN_STORE_FTN_FREG(fd
, DT2
);
5125 GEN_LOAD_FREG_FTN(WT0
, fs
);
5126 gen_op_float_roundw_s();
5127 GEN_STORE_FTN_FREG(fd
, WT2
);
5131 GEN_LOAD_FREG_FTN(WT0
, fs
);
5132 gen_op_float_truncw_s();
5133 GEN_STORE_FTN_FREG(fd
, WT2
);
5137 GEN_LOAD_FREG_FTN(WT0
, fs
);
5138 gen_op_float_ceilw_s();
5139 GEN_STORE_FTN_FREG(fd
, WT2
);
5143 GEN_LOAD_FREG_FTN(WT0
, fs
);
5144 gen_op_float_floorw_s();
5145 GEN_STORE_FTN_FREG(fd
, WT2
);
5149 GEN_LOAD_REG_T0(ft
);
5150 GEN_LOAD_FREG_FTN(WT0
, fs
);
5151 GEN_LOAD_FREG_FTN(WT2
, fd
);
5152 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5153 GEN_STORE_FTN_FREG(fd
, WT2
);
5157 GEN_LOAD_REG_T0(ft
);
5158 GEN_LOAD_FREG_FTN(WT0
, fs
);
5159 GEN_LOAD_FREG_FTN(WT2
, fd
);
5160 gen_op_float_movz_s();
5161 GEN_STORE_FTN_FREG(fd
, WT2
);
5165 GEN_LOAD_REG_T0(ft
);
5166 GEN_LOAD_FREG_FTN(WT0
, fs
);
5167 GEN_LOAD_FREG_FTN(WT2
, fd
);
5168 gen_op_float_movn_s();
5169 GEN_STORE_FTN_FREG(fd
, WT2
);
5174 GEN_LOAD_FREG_FTN(WT0
, fs
);
5175 gen_op_float_recip_s();
5176 GEN_STORE_FTN_FREG(fd
, WT2
);
5181 GEN_LOAD_FREG_FTN(WT0
, fs
);
5182 gen_op_float_rsqrt_s();
5183 GEN_STORE_FTN_FREG(fd
, WT2
);
5187 check_cp1_64bitmode(ctx
);
5188 GEN_LOAD_FREG_FTN(WT0
, fs
);
5189 GEN_LOAD_FREG_FTN(WT2
, fd
);
5190 gen_op_float_recip2_s();
5191 GEN_STORE_FTN_FREG(fd
, WT2
);
5195 check_cp1_64bitmode(ctx
);
5196 GEN_LOAD_FREG_FTN(WT0
, fs
);
5197 gen_op_float_recip1_s();
5198 GEN_STORE_FTN_FREG(fd
, WT2
);
5202 check_cp1_64bitmode(ctx
);
5203 GEN_LOAD_FREG_FTN(WT0
, fs
);
5204 gen_op_float_rsqrt1_s();
5205 GEN_STORE_FTN_FREG(fd
, WT2
);
5209 check_cp1_64bitmode(ctx
);
5210 GEN_LOAD_FREG_FTN(WT0
, fs
);
5211 GEN_LOAD_FREG_FTN(WT2
, ft
);
5212 gen_op_float_rsqrt2_s();
5213 GEN_STORE_FTN_FREG(fd
, WT2
);
5217 check_cp1_registers(ctx
, fd
);
5218 GEN_LOAD_FREG_FTN(WT0
, fs
);
5219 gen_op_float_cvtd_s();
5220 GEN_STORE_FTN_FREG(fd
, DT2
);
5224 GEN_LOAD_FREG_FTN(WT0
, fs
);
5225 gen_op_float_cvtw_s();
5226 GEN_STORE_FTN_FREG(fd
, WT2
);
5230 check_cp1_64bitmode(ctx
);
5231 GEN_LOAD_FREG_FTN(WT0
, fs
);
5232 gen_op_float_cvtl_s();
5233 GEN_STORE_FTN_FREG(fd
, DT2
);
5237 check_cp1_64bitmode(ctx
);
5238 GEN_LOAD_FREG_FTN(WT1
, fs
);
5239 GEN_LOAD_FREG_FTN(WT0
, ft
);
5240 gen_op_float_cvtps_s();
5241 GEN_STORE_FTN_FREG(fd
, DT2
);
5260 GEN_LOAD_FREG_FTN(WT0
, fs
);
5261 GEN_LOAD_FREG_FTN(WT1
, ft
);
5262 if (ctx
->opcode
& (1 << 6)) {
5264 gen_cmpabs_s(func
-48, cc
);
5265 opn
= condnames_abs
[func
-48];
5267 gen_cmp_s(func
-48, cc
);
5268 opn
= condnames
[func
-48];
5272 check_cp1_registers(ctx
, fs
| ft
| fd
);
5273 GEN_LOAD_FREG_FTN(DT0
, fs
);
5274 GEN_LOAD_FREG_FTN(DT1
, ft
);
5275 gen_op_float_add_d();
5276 GEN_STORE_FTN_FREG(fd
, DT2
);
5281 check_cp1_registers(ctx
, fs
| ft
| fd
);
5282 GEN_LOAD_FREG_FTN(DT0
, fs
);
5283 GEN_LOAD_FREG_FTN(DT1
, ft
);
5284 gen_op_float_sub_d();
5285 GEN_STORE_FTN_FREG(fd
, DT2
);
5290 check_cp1_registers(ctx
, fs
| ft
| fd
);
5291 GEN_LOAD_FREG_FTN(DT0
, fs
);
5292 GEN_LOAD_FREG_FTN(DT1
, ft
);
5293 gen_op_float_mul_d();
5294 GEN_STORE_FTN_FREG(fd
, DT2
);
5299 check_cp1_registers(ctx
, fs
| ft
| fd
);
5300 GEN_LOAD_FREG_FTN(DT0
, fs
);
5301 GEN_LOAD_FREG_FTN(DT1
, ft
);
5302 gen_op_float_div_d();
5303 GEN_STORE_FTN_FREG(fd
, DT2
);
5308 check_cp1_registers(ctx
, fs
| fd
);
5309 GEN_LOAD_FREG_FTN(DT0
, fs
);
5310 gen_op_float_sqrt_d();
5311 GEN_STORE_FTN_FREG(fd
, DT2
);
5315 check_cp1_registers(ctx
, fs
| fd
);
5316 GEN_LOAD_FREG_FTN(DT0
, fs
);
5317 gen_op_float_abs_d();
5318 GEN_STORE_FTN_FREG(fd
, DT2
);
5322 check_cp1_registers(ctx
, fs
| fd
);
5323 GEN_LOAD_FREG_FTN(DT0
, fs
);
5324 gen_op_float_mov_d();
5325 GEN_STORE_FTN_FREG(fd
, DT2
);
5329 check_cp1_registers(ctx
, fs
| fd
);
5330 GEN_LOAD_FREG_FTN(DT0
, fs
);
5331 gen_op_float_chs_d();
5332 GEN_STORE_FTN_FREG(fd
, DT2
);
5336 check_cp1_64bitmode(ctx
);
5337 GEN_LOAD_FREG_FTN(DT0
, fs
);
5338 gen_op_float_roundl_d();
5339 GEN_STORE_FTN_FREG(fd
, DT2
);
5343 check_cp1_64bitmode(ctx
);
5344 GEN_LOAD_FREG_FTN(DT0
, fs
);
5345 gen_op_float_truncl_d();
5346 GEN_STORE_FTN_FREG(fd
, DT2
);
5350 check_cp1_64bitmode(ctx
);
5351 GEN_LOAD_FREG_FTN(DT0
, fs
);
5352 gen_op_float_ceill_d();
5353 GEN_STORE_FTN_FREG(fd
, DT2
);
5357 check_cp1_64bitmode(ctx
);
5358 GEN_LOAD_FREG_FTN(DT0
, fs
);
5359 gen_op_float_floorl_d();
5360 GEN_STORE_FTN_FREG(fd
, DT2
);
5364 check_cp1_registers(ctx
, fs
);
5365 GEN_LOAD_FREG_FTN(DT0
, fs
);
5366 gen_op_float_roundw_d();
5367 GEN_STORE_FTN_FREG(fd
, WT2
);
5371 check_cp1_registers(ctx
, fs
);
5372 GEN_LOAD_FREG_FTN(DT0
, fs
);
5373 gen_op_float_truncw_d();
5374 GEN_STORE_FTN_FREG(fd
, WT2
);
5378 check_cp1_registers(ctx
, fs
);
5379 GEN_LOAD_FREG_FTN(DT0
, fs
);
5380 gen_op_float_ceilw_d();
5381 GEN_STORE_FTN_FREG(fd
, WT2
);
5385 check_cp1_registers(ctx
, fs
);
5386 GEN_LOAD_FREG_FTN(DT0
, fs
);
5387 gen_op_float_floorw_d();
5388 GEN_STORE_FTN_FREG(fd
, WT2
);
5392 GEN_LOAD_REG_T0(ft
);
5393 GEN_LOAD_FREG_FTN(DT0
, fs
);
5394 GEN_LOAD_FREG_FTN(DT2
, fd
);
5395 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5396 GEN_STORE_FTN_FREG(fd
, DT2
);
5400 GEN_LOAD_REG_T0(ft
);
5401 GEN_LOAD_FREG_FTN(DT0
, fs
);
5402 GEN_LOAD_FREG_FTN(DT2
, fd
);
5403 gen_op_float_movz_d();
5404 GEN_STORE_FTN_FREG(fd
, DT2
);
5408 GEN_LOAD_REG_T0(ft
);
5409 GEN_LOAD_FREG_FTN(DT0
, fs
);
5410 GEN_LOAD_FREG_FTN(DT2
, fd
);
5411 gen_op_float_movn_d();
5412 GEN_STORE_FTN_FREG(fd
, DT2
);
5416 check_cp1_64bitmode(ctx
);
5417 GEN_LOAD_FREG_FTN(DT0
, fs
);
5418 gen_op_float_recip_d();
5419 GEN_STORE_FTN_FREG(fd
, DT2
);
5423 check_cp1_64bitmode(ctx
);
5424 GEN_LOAD_FREG_FTN(DT0
, fs
);
5425 gen_op_float_rsqrt_d();
5426 GEN_STORE_FTN_FREG(fd
, DT2
);
5430 check_cp1_64bitmode(ctx
);
5431 GEN_LOAD_FREG_FTN(DT0
, fs
);
5432 GEN_LOAD_FREG_FTN(DT2
, ft
);
5433 gen_op_float_recip2_d();
5434 GEN_STORE_FTN_FREG(fd
, DT2
);
5438 check_cp1_64bitmode(ctx
);
5439 GEN_LOAD_FREG_FTN(DT0
, fs
);
5440 gen_op_float_recip1_d();
5441 GEN_STORE_FTN_FREG(fd
, DT2
);
5445 check_cp1_64bitmode(ctx
);
5446 GEN_LOAD_FREG_FTN(DT0
, fs
);
5447 gen_op_float_rsqrt1_d();
5448 GEN_STORE_FTN_FREG(fd
, DT2
);
5452 check_cp1_64bitmode(ctx
);
5453 GEN_LOAD_FREG_FTN(DT0
, fs
);
5454 GEN_LOAD_FREG_FTN(DT2
, ft
);
5455 gen_op_float_rsqrt2_d();
5456 GEN_STORE_FTN_FREG(fd
, DT2
);
5475 GEN_LOAD_FREG_FTN(DT0
, fs
);
5476 GEN_LOAD_FREG_FTN(DT1
, ft
);
5477 if (ctx
->opcode
& (1 << 6)) {
5479 check_cp1_registers(ctx
, fs
| ft
);
5480 gen_cmpabs_d(func
-48, cc
);
5481 opn
= condnames_abs
[func
-48];
5483 check_cp1_registers(ctx
, fs
| ft
);
5484 gen_cmp_d(func
-48, cc
);
5485 opn
= condnames
[func
-48];
5489 check_cp1_registers(ctx
, fs
);
5490 GEN_LOAD_FREG_FTN(DT0
, fs
);
5491 gen_op_float_cvts_d();
5492 GEN_STORE_FTN_FREG(fd
, WT2
);
5496 check_cp1_registers(ctx
, fs
);
5497 GEN_LOAD_FREG_FTN(DT0
, fs
);
5498 gen_op_float_cvtw_d();
5499 GEN_STORE_FTN_FREG(fd
, WT2
);
5503 check_cp1_64bitmode(ctx
);
5504 GEN_LOAD_FREG_FTN(DT0
, fs
);
5505 gen_op_float_cvtl_d();
5506 GEN_STORE_FTN_FREG(fd
, DT2
);
5510 GEN_LOAD_FREG_FTN(WT0
, fs
);
5511 gen_op_float_cvts_w();
5512 GEN_STORE_FTN_FREG(fd
, WT2
);
5516 check_cp1_registers(ctx
, fd
);
5517 GEN_LOAD_FREG_FTN(WT0
, fs
);
5518 gen_op_float_cvtd_w();
5519 GEN_STORE_FTN_FREG(fd
, DT2
);
5523 check_cp1_64bitmode(ctx
);
5524 GEN_LOAD_FREG_FTN(DT0
, fs
);
5525 gen_op_float_cvts_l();
5526 GEN_STORE_FTN_FREG(fd
, WT2
);
5530 check_cp1_64bitmode(ctx
);
5531 GEN_LOAD_FREG_FTN(DT0
, fs
);
5532 gen_op_float_cvtd_l();
5533 GEN_STORE_FTN_FREG(fd
, DT2
);
5537 check_cp1_64bitmode(ctx
);
5538 GEN_LOAD_FREG_FTN(WT0
, fs
);
5539 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5540 gen_op_float_cvtps_pw();
5541 GEN_STORE_FTN_FREG(fd
, WT2
);
5542 GEN_STORE_FTN_FREG(fd
, WTH2
);
5546 check_cp1_64bitmode(ctx
);
5547 GEN_LOAD_FREG_FTN(WT0
, fs
);
5548 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5549 GEN_LOAD_FREG_FTN(WT1
, ft
);
5550 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5551 gen_op_float_add_ps();
5552 GEN_STORE_FTN_FREG(fd
, WT2
);
5553 GEN_STORE_FTN_FREG(fd
, WTH2
);
5557 check_cp1_64bitmode(ctx
);
5558 GEN_LOAD_FREG_FTN(WT0
, fs
);
5559 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5560 GEN_LOAD_FREG_FTN(WT1
, ft
);
5561 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5562 gen_op_float_sub_ps();
5563 GEN_STORE_FTN_FREG(fd
, WT2
);
5564 GEN_STORE_FTN_FREG(fd
, WTH2
);
5568 check_cp1_64bitmode(ctx
);
5569 GEN_LOAD_FREG_FTN(WT0
, fs
);
5570 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5571 GEN_LOAD_FREG_FTN(WT1
, ft
);
5572 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5573 gen_op_float_mul_ps();
5574 GEN_STORE_FTN_FREG(fd
, WT2
);
5575 GEN_STORE_FTN_FREG(fd
, WTH2
);
5579 check_cp1_64bitmode(ctx
);
5580 GEN_LOAD_FREG_FTN(WT0
, fs
);
5581 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5582 gen_op_float_abs_ps();
5583 GEN_STORE_FTN_FREG(fd
, WT2
);
5584 GEN_STORE_FTN_FREG(fd
, WTH2
);
5588 check_cp1_64bitmode(ctx
);
5589 GEN_LOAD_FREG_FTN(WT0
, fs
);
5590 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5591 gen_op_float_mov_ps();
5592 GEN_STORE_FTN_FREG(fd
, WT2
);
5593 GEN_STORE_FTN_FREG(fd
, WTH2
);
5597 check_cp1_64bitmode(ctx
);
5598 GEN_LOAD_FREG_FTN(WT0
, fs
);
5599 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5600 gen_op_float_chs_ps();
5601 GEN_STORE_FTN_FREG(fd
, WT2
);
5602 GEN_STORE_FTN_FREG(fd
, WTH2
);
5606 check_cp1_64bitmode(ctx
);
5607 GEN_LOAD_REG_T0(ft
);
5608 GEN_LOAD_FREG_FTN(WT0
, fs
);
5609 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5610 GEN_LOAD_FREG_FTN(WT2
, fd
);
5611 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5612 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5613 GEN_STORE_FTN_FREG(fd
, WT2
);
5614 GEN_STORE_FTN_FREG(fd
, WTH2
);
5618 check_cp1_64bitmode(ctx
);
5619 GEN_LOAD_REG_T0(ft
);
5620 GEN_LOAD_FREG_FTN(WT0
, fs
);
5621 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5622 GEN_LOAD_FREG_FTN(WT2
, fd
);
5623 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5624 gen_op_float_movz_ps();
5625 GEN_STORE_FTN_FREG(fd
, WT2
);
5626 GEN_STORE_FTN_FREG(fd
, WTH2
);
5630 check_cp1_64bitmode(ctx
);
5631 GEN_LOAD_REG_T0(ft
);
5632 GEN_LOAD_FREG_FTN(WT0
, fs
);
5633 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5634 GEN_LOAD_FREG_FTN(WT2
, fd
);
5635 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5636 gen_op_float_movn_ps();
5637 GEN_STORE_FTN_FREG(fd
, WT2
);
5638 GEN_STORE_FTN_FREG(fd
, WTH2
);
5642 check_cp1_64bitmode(ctx
);
5643 GEN_LOAD_FREG_FTN(WT0
, ft
);
5644 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5645 GEN_LOAD_FREG_FTN(WT1
, fs
);
5646 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5647 gen_op_float_addr_ps();
5648 GEN_STORE_FTN_FREG(fd
, WT2
);
5649 GEN_STORE_FTN_FREG(fd
, WTH2
);
5653 check_cp1_64bitmode(ctx
);
5654 GEN_LOAD_FREG_FTN(WT0
, ft
);
5655 GEN_LOAD_FREG_FTN(WTH0
, ft
);
5656 GEN_LOAD_FREG_FTN(WT1
, fs
);
5657 GEN_LOAD_FREG_FTN(WTH1
, fs
);
5658 gen_op_float_mulr_ps();
5659 GEN_STORE_FTN_FREG(fd
, WT2
);
5660 GEN_STORE_FTN_FREG(fd
, WTH2
);
5664 check_cp1_64bitmode(ctx
);
5665 GEN_LOAD_FREG_FTN(WT0
, fs
);
5666 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5667 GEN_LOAD_FREG_FTN(WT2
, fd
);
5668 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5669 gen_op_float_recip2_ps();
5670 GEN_STORE_FTN_FREG(fd
, WT2
);
5671 GEN_STORE_FTN_FREG(fd
, WTH2
);
5675 check_cp1_64bitmode(ctx
);
5676 GEN_LOAD_FREG_FTN(WT0
, fs
);
5677 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5678 gen_op_float_recip1_ps();
5679 GEN_STORE_FTN_FREG(fd
, WT2
);
5680 GEN_STORE_FTN_FREG(fd
, WTH2
);
5684 check_cp1_64bitmode(ctx
);
5685 GEN_LOAD_FREG_FTN(WT0
, fs
);
5686 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5687 gen_op_float_rsqrt1_ps();
5688 GEN_STORE_FTN_FREG(fd
, WT2
);
5689 GEN_STORE_FTN_FREG(fd
, WTH2
);
5693 check_cp1_64bitmode(ctx
);
5694 GEN_LOAD_FREG_FTN(WT0
, fs
);
5695 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5696 GEN_LOAD_FREG_FTN(WT2
, ft
);
5697 GEN_LOAD_FREG_FTN(WTH2
, ft
);
5698 gen_op_float_rsqrt2_ps();
5699 GEN_STORE_FTN_FREG(fd
, WT2
);
5700 GEN_STORE_FTN_FREG(fd
, WTH2
);
5704 check_cp1_64bitmode(ctx
);
5705 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5706 gen_op_float_cvts_pu();
5707 GEN_STORE_FTN_FREG(fd
, WT2
);
5711 check_cp1_64bitmode(ctx
);
5712 GEN_LOAD_FREG_FTN(WT0
, fs
);
5713 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5714 gen_op_float_cvtpw_ps();
5715 GEN_STORE_FTN_FREG(fd
, WT2
);
5716 GEN_STORE_FTN_FREG(fd
, WTH2
);
5720 check_cp1_64bitmode(ctx
);
5721 GEN_LOAD_FREG_FTN(WT0
, fs
);
5722 gen_op_float_cvts_pl();
5723 GEN_STORE_FTN_FREG(fd
, WT2
);
5727 check_cp1_64bitmode(ctx
);
5728 GEN_LOAD_FREG_FTN(WT0
, fs
);
5729 GEN_LOAD_FREG_FTN(WT1
, ft
);
5730 gen_op_float_pll_ps();
5731 GEN_STORE_FTN_FREG(fd
, DT2
);
5735 check_cp1_64bitmode(ctx
);
5736 GEN_LOAD_FREG_FTN(WT0
, fs
);
5737 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5738 gen_op_float_plu_ps();
5739 GEN_STORE_FTN_FREG(fd
, DT2
);
5743 check_cp1_64bitmode(ctx
);
5744 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5745 GEN_LOAD_FREG_FTN(WT1
, ft
);
5746 gen_op_float_pul_ps();
5747 GEN_STORE_FTN_FREG(fd
, DT2
);
5751 check_cp1_64bitmode(ctx
);
5752 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5753 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5754 gen_op_float_puu_ps();
5755 GEN_STORE_FTN_FREG(fd
, DT2
);
5774 check_cp1_64bitmode(ctx
);
5775 GEN_LOAD_FREG_FTN(WT0
, fs
);
5776 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5777 GEN_LOAD_FREG_FTN(WT1
, ft
);
5778 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5779 if (ctx
->opcode
& (1 << 6)) {
5780 gen_cmpabs_ps(func
-48, cc
);
5781 opn
= condnames_abs
[func
-48];
5783 gen_cmp_ps(func
-48, cc
);
5784 opn
= condnames
[func
-48];
5789 generate_exception (ctx
, EXCP_RI
);
5794 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5797 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5800 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5805 /* Coprocessor 3 (FPU) */
5806 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5807 int fd
, int fs
, int base
, int index
)
5809 const char *opn
= "extended float load/store";
5816 GEN_LOAD_REG_T0(index
);
5817 } else if (index
== 0) {
5818 GEN_LOAD_REG_T0(base
);
5820 GEN_LOAD_REG_T0(base
);
5821 GEN_LOAD_REG_T1(index
);
5824 /* Don't do NOP if destination is zero: we must perform the actual
5830 GEN_STORE_FTN_FREG(fd
, WT0
);
5835 check_cp1_registers(ctx
, fd
);
5837 GEN_STORE_FTN_FREG(fd
, DT0
);
5841 check_cp1_64bitmode(ctx
);
5843 GEN_STORE_FTN_FREG(fd
, DT0
);
5848 GEN_LOAD_FREG_FTN(WT0
, fs
);
5855 check_cp1_registers(ctx
, fs
);
5856 GEN_LOAD_FREG_FTN(DT0
, fs
);
5862 check_cp1_64bitmode(ctx
);
5863 GEN_LOAD_FREG_FTN(DT0
, fs
);
5870 generate_exception(ctx
, EXCP_RI
);
5873 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5874 regnames
[index
], regnames
[base
]);
5877 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5878 int fd
, int fr
, int fs
, int ft
)
5880 const char *opn
= "flt3_arith";
5884 check_cp1_64bitmode(ctx
);
5885 GEN_LOAD_REG_T0(fr
);
5886 GEN_LOAD_FREG_FTN(DT0
, fs
);
5887 GEN_LOAD_FREG_FTN(DT1
, ft
);
5888 gen_op_float_alnv_ps();
5889 GEN_STORE_FTN_FREG(fd
, DT2
);
5894 GEN_LOAD_FREG_FTN(WT0
, fs
);
5895 GEN_LOAD_FREG_FTN(WT1
, ft
);
5896 GEN_LOAD_FREG_FTN(WT2
, fr
);
5897 gen_op_float_muladd_s();
5898 GEN_STORE_FTN_FREG(fd
, WT2
);
5903 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5904 GEN_LOAD_FREG_FTN(DT0
, fs
);
5905 GEN_LOAD_FREG_FTN(DT1
, ft
);
5906 GEN_LOAD_FREG_FTN(DT2
, fr
);
5907 gen_op_float_muladd_d();
5908 GEN_STORE_FTN_FREG(fd
, DT2
);
5912 check_cp1_64bitmode(ctx
);
5913 GEN_LOAD_FREG_FTN(WT0
, fs
);
5914 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5915 GEN_LOAD_FREG_FTN(WT1
, ft
);
5916 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5917 GEN_LOAD_FREG_FTN(WT2
, fr
);
5918 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5919 gen_op_float_muladd_ps();
5920 GEN_STORE_FTN_FREG(fd
, WT2
);
5921 GEN_STORE_FTN_FREG(fd
, WTH2
);
5926 GEN_LOAD_FREG_FTN(WT0
, fs
);
5927 GEN_LOAD_FREG_FTN(WT1
, ft
);
5928 GEN_LOAD_FREG_FTN(WT2
, fr
);
5929 gen_op_float_mulsub_s();
5930 GEN_STORE_FTN_FREG(fd
, WT2
);
5935 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5936 GEN_LOAD_FREG_FTN(DT0
, fs
);
5937 GEN_LOAD_FREG_FTN(DT1
, ft
);
5938 GEN_LOAD_FREG_FTN(DT2
, fr
);
5939 gen_op_float_mulsub_d();
5940 GEN_STORE_FTN_FREG(fd
, DT2
);
5944 check_cp1_64bitmode(ctx
);
5945 GEN_LOAD_FREG_FTN(WT0
, fs
);
5946 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5947 GEN_LOAD_FREG_FTN(WT1
, ft
);
5948 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5949 GEN_LOAD_FREG_FTN(WT2
, fr
);
5950 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5951 gen_op_float_mulsub_ps();
5952 GEN_STORE_FTN_FREG(fd
, WT2
);
5953 GEN_STORE_FTN_FREG(fd
, WTH2
);
5958 GEN_LOAD_FREG_FTN(WT0
, fs
);
5959 GEN_LOAD_FREG_FTN(WT1
, ft
);
5960 GEN_LOAD_FREG_FTN(WT2
, fr
);
5961 gen_op_float_nmuladd_s();
5962 GEN_STORE_FTN_FREG(fd
, WT2
);
5967 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
5968 GEN_LOAD_FREG_FTN(DT0
, fs
);
5969 GEN_LOAD_FREG_FTN(DT1
, ft
);
5970 GEN_LOAD_FREG_FTN(DT2
, fr
);
5971 gen_op_float_nmuladd_d();
5972 GEN_STORE_FTN_FREG(fd
, DT2
);
5976 check_cp1_64bitmode(ctx
);
5977 GEN_LOAD_FREG_FTN(WT0
, fs
);
5978 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5979 GEN_LOAD_FREG_FTN(WT1
, ft
);
5980 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5981 GEN_LOAD_FREG_FTN(WT2
, fr
);
5982 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5983 gen_op_float_nmuladd_ps();
5984 GEN_STORE_FTN_FREG(fd
, WT2
);
5985 GEN_STORE_FTN_FREG(fd
, WTH2
);
5990 GEN_LOAD_FREG_FTN(WT0
, fs
);
5991 GEN_LOAD_FREG_FTN(WT1
, ft
);
5992 GEN_LOAD_FREG_FTN(WT2
, fr
);
5993 gen_op_float_nmulsub_s();
5994 GEN_STORE_FTN_FREG(fd
, WT2
);
5999 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6000 GEN_LOAD_FREG_FTN(DT0
, fs
);
6001 GEN_LOAD_FREG_FTN(DT1
, ft
);
6002 GEN_LOAD_FREG_FTN(DT2
, fr
);
6003 gen_op_float_nmulsub_d();
6004 GEN_STORE_FTN_FREG(fd
, DT2
);
6008 check_cp1_64bitmode(ctx
);
6009 GEN_LOAD_FREG_FTN(WT0
, fs
);
6010 GEN_LOAD_FREG_FTN(WTH0
, fs
);
6011 GEN_LOAD_FREG_FTN(WT1
, ft
);
6012 GEN_LOAD_FREG_FTN(WTH1
, ft
);
6013 GEN_LOAD_FREG_FTN(WT2
, fr
);
6014 GEN_LOAD_FREG_FTN(WTH2
, fr
);
6015 gen_op_float_nmulsub_ps();
6016 GEN_STORE_FTN_FREG(fd
, WT2
);
6017 GEN_STORE_FTN_FREG(fd
, WTH2
);
6022 generate_exception (ctx
, EXCP_RI
);
6025 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
6026 fregnames
[fs
], fregnames
[ft
]);
6029 /* ISA extensions (ASEs) */
6030 /* MIPS16 extension to MIPS32 */
6031 /* SmartMIPS extension to MIPS32 */
6033 #if defined(TARGET_MIPS64)
6035 /* MDMX extension to MIPS64 */
6039 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
6043 uint32_t op
, op1
, op2
;
6046 /* make sure instructions are on a word boundary */
6047 if (ctx
->pc
& 0x3) {
6048 env
->CP0_BadVAddr
= ctx
->pc
;
6049 generate_exception(ctx
, EXCP_AdEL
);
6053 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
6055 /* Handle blikely not taken case */
6056 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
6057 l1
= gen_new_label();
6059 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
6060 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6063 op
= MASK_OP_MAJOR(ctx
->opcode
);
6064 rs
= (ctx
->opcode
>> 21) & 0x1f;
6065 rt
= (ctx
->opcode
>> 16) & 0x1f;
6066 rd
= (ctx
->opcode
>> 11) & 0x1f;
6067 sa
= (ctx
->opcode
>> 6) & 0x1f;
6068 imm
= (int16_t)ctx
->opcode
;
6071 op1
= MASK_SPECIAL(ctx
->opcode
);
6073 case OPC_SLL
: /* Arithmetic with immediate */
6074 case OPC_SRL
... OPC_SRA
:
6075 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6077 case OPC_MOVZ
... OPC_MOVN
:
6078 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6079 case OPC_SLLV
: /* Arithmetic */
6080 case OPC_SRLV
... OPC_SRAV
:
6081 case OPC_ADD
... OPC_NOR
:
6082 case OPC_SLT
... OPC_SLTU
:
6083 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6085 case OPC_MULT
... OPC_DIVU
:
6087 check_insn(env
, ctx
, INSN_VR54XX
);
6088 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
6089 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
6091 gen_muldiv(ctx
, op1
, rs
, rt
);
6093 case OPC_JR
... OPC_JALR
:
6094 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
6096 case OPC_TGE
... OPC_TEQ
: /* Traps */
6098 gen_trap(ctx
, op1
, rs
, rt
, -1);
6100 case OPC_MFHI
: /* Move from HI/LO */
6102 gen_HILO(ctx
, op1
, rd
);
6105 case OPC_MTLO
: /* Move to HI/LO */
6106 gen_HILO(ctx
, op1
, rs
);
6108 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
6109 #ifdef MIPS_STRICT_STANDARD
6110 MIPS_INVAL("PMON / selsl");
6111 generate_exception(ctx
, EXCP_RI
);
6117 generate_exception(ctx
, EXCP_SYSCALL
);
6120 generate_exception(ctx
, EXCP_BREAK
);
6123 #ifdef MIPS_STRICT_STANDARD
6125 generate_exception(ctx
, EXCP_RI
);
6127 /* Implemented as RI exception for now. */
6128 MIPS_INVAL("spim (unofficial)");
6129 generate_exception(ctx
, EXCP_RI
);
6137 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6138 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6139 save_cpu_state(ctx
, 1);
6140 check_cp1_enabled(ctx
);
6141 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
6142 (ctx
->opcode
>> 16) & 1);
6144 generate_exception_err(ctx
, EXCP_CpU
, 1);
6148 #if defined(TARGET_MIPS64)
6149 /* MIPS64 specific opcodes */
6151 case OPC_DSRL
... OPC_DSRA
:
6153 case OPC_DSRL32
... OPC_DSRA32
:
6154 check_insn(env
, ctx
, ISA_MIPS3
);
6156 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
6159 case OPC_DSRLV
... OPC_DSRAV
:
6160 case OPC_DADD
... OPC_DSUBU
:
6161 check_insn(env
, ctx
, ISA_MIPS3
);
6163 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6165 case OPC_DMULT
... OPC_DDIVU
:
6166 check_insn(env
, ctx
, ISA_MIPS3
);
6168 gen_muldiv(ctx
, op1
, rs
, rt
);
6171 default: /* Invalid */
6172 MIPS_INVAL("special");
6173 generate_exception(ctx
, EXCP_RI
);
6178 op1
= MASK_SPECIAL2(ctx
->opcode
);
6180 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
6181 case OPC_MSUB
... OPC_MSUBU
:
6182 check_insn(env
, ctx
, ISA_MIPS32
);
6183 gen_muldiv(ctx
, op1
, rs
, rt
);
6186 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
6188 case OPC_CLZ
... OPC_CLO
:
6189 check_insn(env
, ctx
, ISA_MIPS32
);
6190 gen_cl(ctx
, op1
, rd
, rs
);
6193 /* XXX: not clear which exception should be raised
6194 * when in debug mode...
6196 check_insn(env
, ctx
, ISA_MIPS32
);
6197 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
6198 generate_exception(ctx
, EXCP_DBp
);
6200 generate_exception(ctx
, EXCP_DBp
);
6204 #if defined(TARGET_MIPS64)
6205 case OPC_DCLZ
... OPC_DCLO
:
6206 check_insn(env
, ctx
, ISA_MIPS64
);
6208 gen_cl(ctx
, op1
, rd
, rs
);
6211 default: /* Invalid */
6212 MIPS_INVAL("special2");
6213 generate_exception(ctx
, EXCP_RI
);
6218 op1
= MASK_SPECIAL3(ctx
->opcode
);
6222 check_insn(env
, ctx
, ISA_MIPS32R2
);
6223 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6226 check_insn(env
, ctx
, ISA_MIPS32R2
);
6227 op2
= MASK_BSHFL(ctx
->opcode
);
6230 GEN_LOAD_REG_T1(rt
);
6234 GEN_LOAD_REG_T1(rt
);
6238 GEN_LOAD_REG_T1(rt
);
6241 default: /* Invalid */
6242 MIPS_INVAL("bshfl");
6243 generate_exception(ctx
, EXCP_RI
);
6246 GEN_STORE_T0_REG(rd
);
6249 check_insn(env
, ctx
, ISA_MIPS32R2
);
6252 save_cpu_state(ctx
, 1);
6253 gen_op_rdhwr_cpunum();
6256 save_cpu_state(ctx
, 1);
6257 gen_op_rdhwr_synci_step();
6260 save_cpu_state(ctx
, 1);
6264 save_cpu_state(ctx
, 1);
6265 gen_op_rdhwr_ccres();
6268 #if defined (CONFIG_USER_ONLY)
6272 default: /* Invalid */
6273 MIPS_INVAL("rdhwr");
6274 generate_exception(ctx
, EXCP_RI
);
6277 GEN_STORE_T0_REG(rt
);
6280 check_insn(env
, ctx
, ASE_MT
);
6281 GEN_LOAD_REG_T0(rt
);
6282 GEN_LOAD_REG_T1(rs
);
6286 check_insn(env
, ctx
, ASE_MT
);
6287 GEN_LOAD_REG_T0(rs
);
6289 GEN_STORE_T0_REG(rd
);
6291 #if defined(TARGET_MIPS64)
6292 case OPC_DEXTM
... OPC_DEXT
:
6293 case OPC_DINSM
... OPC_DINS
:
6294 check_insn(env
, ctx
, ISA_MIPS64R2
);
6296 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
6299 check_insn(env
, ctx
, ISA_MIPS64R2
);
6301 op2
= MASK_DBSHFL(ctx
->opcode
);
6304 GEN_LOAD_REG_T1(rt
);
6308 GEN_LOAD_REG_T1(rt
);
6311 default: /* Invalid */
6312 MIPS_INVAL("dbshfl");
6313 generate_exception(ctx
, EXCP_RI
);
6316 GEN_STORE_T0_REG(rd
);
6319 default: /* Invalid */
6320 MIPS_INVAL("special3");
6321 generate_exception(ctx
, EXCP_RI
);
6326 op1
= MASK_REGIMM(ctx
->opcode
);
6328 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
6329 case OPC_BLTZAL
... OPC_BGEZALL
:
6330 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
6332 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
6334 gen_trap(ctx
, op1
, rs
, -1, imm
);
6337 check_insn(env
, ctx
, ISA_MIPS32R2
);
6340 default: /* Invalid */
6341 MIPS_INVAL("regimm");
6342 generate_exception(ctx
, EXCP_RI
);
6347 check_cp0_enabled(ctx
);
6348 op1
= MASK_CP0(ctx
->opcode
);
6354 #if defined(TARGET_MIPS64)
6358 gen_cp0(env
, ctx
, op1
, rt
, rd
);
6360 case OPC_C0_FIRST
... OPC_C0_LAST
:
6361 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
6364 op2
= MASK_MFMC0(ctx
->opcode
);
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
, ASE_MT
);
6383 check_insn(env
, ctx
, ISA_MIPS32R2
);
6384 save_cpu_state(ctx
, 1);
6386 /* Stop translation as we may have switched the execution mode */
6387 ctx
->bstate
= BS_STOP
;
6390 check_insn(env
, ctx
, ISA_MIPS32R2
);
6391 save_cpu_state(ctx
, 1);
6393 /* Stop translation as we may have switched the execution mode */
6394 ctx
->bstate
= BS_STOP
;
6396 default: /* Invalid */
6397 MIPS_INVAL("mfmc0");
6398 generate_exception(ctx
, EXCP_RI
);
6401 GEN_STORE_T0_REG(rt
);
6404 check_insn(env
, ctx
, ISA_MIPS32R2
);
6405 GEN_LOAD_SRSREG_TN(T0
, rt
);
6406 GEN_STORE_T0_REG(rd
);
6409 check_insn(env
, ctx
, ISA_MIPS32R2
);
6410 GEN_LOAD_REG_T0(rt
);
6411 GEN_STORE_TN_SRSREG(rd
, T0
);
6415 generate_exception(ctx
, EXCP_RI
);
6419 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
6420 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6422 case OPC_J
... OPC_JAL
: /* Jump */
6423 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
6424 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
6426 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
6427 case OPC_BEQL
... OPC_BGTZL
:
6428 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
6430 case OPC_LB
... OPC_LWR
: /* Load and stores */
6431 case OPC_SB
... OPC_SW
:
6435 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6438 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
6442 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
6446 /* Floating point (COP1). */
6451 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6452 save_cpu_state(ctx
, 1);
6453 check_cp1_enabled(ctx
);
6454 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
6456 generate_exception_err(ctx
, EXCP_CpU
, 1);
6461 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6462 save_cpu_state(ctx
, 1);
6463 check_cp1_enabled(ctx
);
6464 op1
= MASK_CP1(ctx
->opcode
);
6468 check_insn(env
, ctx
, ISA_MIPS32R2
);
6473 gen_cp1(ctx
, op1
, rt
, rd
);
6475 #if defined(TARGET_MIPS64)
6478 check_insn(env
, ctx
, ISA_MIPS3
);
6479 gen_cp1(ctx
, op1
, rt
, rd
);
6485 check_insn(env
, ctx
, ASE_MIPS3D
);
6488 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
6489 (rt
>> 2) & 0x7, imm
<< 2);
6496 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
6501 generate_exception (ctx
, EXCP_RI
);
6505 generate_exception_err(ctx
, EXCP_CpU
, 1);
6515 /* COP2: Not implemented. */
6516 generate_exception_err(ctx
, EXCP_CpU
, 2);
6520 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
6521 save_cpu_state(ctx
, 1);
6522 check_cp1_enabled(ctx
);
6523 op1
= MASK_CP3(ctx
->opcode
);
6531 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
6549 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
6553 generate_exception (ctx
, EXCP_RI
);
6557 generate_exception_err(ctx
, EXCP_CpU
, 1);
6561 #if defined(TARGET_MIPS64)
6562 /* MIPS64 opcodes */
6564 case OPC_LDL
... OPC_LDR
:
6565 case OPC_SDL
... OPC_SDR
:
6570 check_insn(env
, ctx
, ISA_MIPS3
);
6572 gen_ldst(ctx
, op
, rt
, rs
, imm
);
6574 case OPC_DADDI
... OPC_DADDIU
:
6575 check_insn(env
, ctx
, ISA_MIPS3
);
6577 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
6581 check_insn(env
, ctx
, ASE_MIPS16
);
6582 /* MIPS16: Not implemented. */
6584 check_insn(env
, ctx
, ASE_MDMX
);
6585 /* MDMX: Not implemented. */
6586 default: /* Invalid */
6587 MIPS_INVAL("major opcode");
6588 generate_exception(ctx
, EXCP_RI
);
6591 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
6592 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
6593 /* Branches completion */
6594 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
6595 ctx
->bstate
= BS_BRANCH
;
6596 save_cpu_state(ctx
, 0);
6599 /* unconditional branch */
6600 MIPS_DEBUG("unconditional branch");
6601 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6604 /* blikely taken case */
6605 MIPS_DEBUG("blikely branch taken");
6606 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6609 /* Conditional branch */
6610 MIPS_DEBUG("conditional branch");
6613 l1
= gen_new_label();
6615 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
6617 gen_goto_tb(ctx
, 0, ctx
->btarget
);
6621 /* unconditional branch to register */
6622 MIPS_DEBUG("branch to register");
6627 MIPS_DEBUG("unknown branch");
6633 static always_inline
int
6634 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
6638 target_ulong pc_start
;
6639 uint16_t *gen_opc_end
;
6642 if (search_pc
&& loglevel
)
6643 fprintf (logfile
, "search pc %d\n", search_pc
);
6646 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6650 ctx
.bstate
= BS_NONE
;
6651 /* Restore delay slot state from the tb context. */
6652 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
6653 restore_cpu_state(env
, &ctx
);
6654 #if defined(CONFIG_USER_ONLY)
6655 ctx
.mem_idx
= MIPS_HFLAG_UM
;
6657 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
6660 if (loglevel
& CPU_LOG_TB_CPU
) {
6661 fprintf(logfile
, "------------------------------------------------\n");
6662 /* FIXME: This may print out stale hflags from env... */
6663 cpu_dump_state(env
, logfile
, fprintf
, 0);
6666 #ifdef MIPS_DEBUG_DISAS
6667 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6668 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
6669 tb
, ctx
.mem_idx
, ctx
.hflags
);
6671 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6672 if (env
->nb_breakpoints
> 0) {
6673 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6674 if (env
->breakpoints
[j
] == ctx
.pc
) {
6675 save_cpu_state(&ctx
, 1);
6676 ctx
.bstate
= BS_BRANCH
;
6678 /* Include the breakpoint location or the tb won't
6679 * be flushed when it must be. */
6681 goto done_generating
;
6687 j
= gen_opc_ptr
- gen_opc_buf
;
6691 gen_opc_instr_start
[lj
++] = 0;
6693 gen_opc_pc
[lj
] = ctx
.pc
;
6694 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6695 gen_opc_instr_start
[lj
] = 1;
6697 ctx
.opcode
= ldl_code(ctx
.pc
);
6698 decode_opc(env
, &ctx
);
6701 if (env
->singlestep_enabled
)
6704 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6707 #if defined (MIPS_SINGLE_STEP)
6711 if (env
->singlestep_enabled
) {
6712 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
6715 switch (ctx
.bstate
) {
6717 gen_op_interrupt_restart();
6718 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6721 save_cpu_state(&ctx
, 0);
6722 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6725 gen_op_interrupt_restart();
6734 ctx
.last_T0_store
= NULL
;
6735 *gen_opc_ptr
= INDEX_op_end
;
6737 j
= gen_opc_ptr
- gen_opc_buf
;
6740 gen_opc_instr_start
[lj
++] = 0;
6742 tb
->size
= ctx
.pc
- pc_start
;
6745 #if defined MIPS_DEBUG_DISAS
6746 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6747 fprintf(logfile
, "\n");
6749 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6750 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6751 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6752 fprintf(logfile
, "\n");
6754 if (loglevel
& CPU_LOG_TB_CPU
) {
6755 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6762 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6764 return gen_intermediate_code_internal(env
, tb
, 0);
6767 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6769 return gen_intermediate_code_internal(env
, tb
, 1);
6772 void fpu_dump_state(CPUState
*env
, FILE *f
,
6773 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6777 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6779 #define printfpr(fp) \
6782 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6783 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6784 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6787 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6788 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6789 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6790 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6791 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6796 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6797 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
6798 get_float_exception_flags(&env
->fpu
->fp_status
));
6799 fpu_fprintf(f
, "FT0: "); printfpr(&env
->fpu
->ft0
);
6800 fpu_fprintf(f
, "FT1: "); printfpr(&env
->fpu
->ft1
);
6801 fpu_fprintf(f
, "FT2: "); printfpr(&env
->fpu
->ft2
);
6802 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6803 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6804 printfpr(&env
->fpu
->fpr
[i
]);
6810 void dump_fpu (CPUState
*env
)
6813 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6814 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0], env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
, env
->bcond
);
6815 fpu_dump_state(env
, logfile
, fprintf
, 0);
6819 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6820 /* Debug help: The architecture requires 32bit code to maintain proper
6821 sign-extened values on 64bit machines. */
6823 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6825 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6826 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6831 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
6832 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
6833 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
6834 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
6835 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
6836 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
6837 if (!SIGN_EXT_P(env
->btarget
))
6838 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6840 for (i
= 0; i
< 32; i
++) {
6841 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
6842 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6845 if (!SIGN_EXT_P(env
->CP0_EPC
))
6846 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6847 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6848 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6852 void cpu_dump_state (CPUState
*env
, FILE *f
,
6853 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6858 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",
6859 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
6860 for (i
= 0; i
< 32; i
++) {
6862 cpu_fprintf(f
, "GPR%02d:", i
);
6863 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
6865 cpu_fprintf(f
, "\n");
6868 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6869 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6870 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6871 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6872 if (env
->hflags
& MIPS_HFLAG_FPU
)
6873 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6874 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6875 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6879 #include "translate_init.c"
6881 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
6884 const mips_def_t
*def
;
6886 def
= cpu_mips_find_by_name(cpu_model
);
6889 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6892 env
->cpu_model
= def
;
6895 env
->cpu_model_str
= cpu_model
;
6900 void cpu_reset (CPUMIPSState
*env
)
6902 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6907 #if !defined(CONFIG_USER_ONLY)
6908 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6909 /* If the exception was raised from a delay slot,
6910 * come back to the jump. */
6911 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
6913 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
6915 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
6917 /* SMP not implemented */
6918 env
->CP0_EBase
= 0x80000000;
6919 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6920 /* vectored interrupts not implemented, timer on int 7,
6921 no performance counters. */
6922 env
->CP0_IntCtl
= 0xe0000000;
6926 for (i
= 0; i
< 7; i
++) {
6927 env
->CP0_WatchLo
[i
] = 0;
6928 env
->CP0_WatchHi
[i
] = 0x80000000;
6930 env
->CP0_WatchLo
[7] = 0;
6931 env
->CP0_WatchHi
[7] = 0;
6933 /* Count register increments in debug mode, EJTAG version 1 */
6934 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6936 env
->exception_index
= EXCP_NONE
;
6937 #if defined(CONFIG_USER_ONLY)
6938 env
->hflags
= MIPS_HFLAG_UM
;
6939 env
->user_mode_only
= 1;
6941 env
->hflags
= MIPS_HFLAG_CP0
;
6943 cpu_mips_register(env
, env
->cpu_model
);