]>
git.proxmox.com Git - mirror_qemu.git/blob - target-mips/translate.c
2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL
= (0x00 << 26),
46 OPC_REGIMM
= (0x01 << 26),
47 OPC_CP0
= (0x10 << 26),
48 OPC_CP1
= (0x11 << 26),
49 OPC_CP2
= (0x12 << 26),
50 OPC_CP3
= (0x13 << 26),
51 OPC_SPECIAL2
= (0x1C << 26),
52 OPC_SPECIAL3
= (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI
= (0x08 << 26),
55 OPC_ADDIU
= (0x09 << 26),
56 OPC_SLTI
= (0x0A << 26),
57 OPC_SLTIU
= (0x0B << 26),
58 OPC_ANDI
= (0x0C << 26),
59 OPC_ORI
= (0x0D << 26),
60 OPC_XORI
= (0x0E << 26),
61 OPC_LUI
= (0x0F << 26),
62 OPC_DADDI
= (0x18 << 26),
63 OPC_DADDIU
= (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL
= (0x03 << 26),
67 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL
= (0x14 << 26),
69 OPC_BNE
= (0x05 << 26),
70 OPC_BNEL
= (0x15 << 26),
71 OPC_BLEZ
= (0x06 << 26),
72 OPC_BLEZL
= (0x16 << 26),
73 OPC_BGTZ
= (0x07 << 26),
74 OPC_BGTZL
= (0x17 << 26),
75 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL
= (0x1A << 26),
78 OPC_LDR
= (0x1B << 26),
79 OPC_LB
= (0x20 << 26),
80 OPC_LH
= (0x21 << 26),
81 OPC_LWL
= (0x22 << 26),
82 OPC_LW
= (0x23 << 26),
83 OPC_LBU
= (0x24 << 26),
84 OPC_LHU
= (0x25 << 26),
85 OPC_LWR
= (0x26 << 26),
86 OPC_LWU
= (0x27 << 26),
87 OPC_SB
= (0x28 << 26),
88 OPC_SH
= (0x29 << 26),
89 OPC_SWL
= (0x2A << 26),
90 OPC_SW
= (0x2B << 26),
91 OPC_SDL
= (0x2C << 26),
92 OPC_SDR
= (0x2D << 26),
93 OPC_SWR
= (0x2E << 26),
94 OPC_LL
= (0x30 << 26),
95 OPC_LLD
= (0x34 << 26),
96 OPC_LD
= (0x37 << 26),
97 OPC_SC
= (0x38 << 26),
98 OPC_SCD
= (0x3C << 26),
99 OPC_SD
= (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1
= (0x31 << 26),
102 OPC_LWC2
= (0x32 << 26),
103 OPC_LDC1
= (0x35 << 26),
104 OPC_LDC2
= (0x36 << 26),
105 OPC_SWC1
= (0x39 << 26),
106 OPC_SWC2
= (0x3A << 26),
107 OPC_SDC1
= (0x3D << 26),
108 OPC_SDC2
= (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX
= (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE
= (0x2F << 26),
113 OPC_PREF
= (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL
= 0x00 | OPC_SPECIAL
,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
128 OPC_SRA
= 0x03 | OPC_SPECIAL
,
129 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
130 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
131 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
132 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
133 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
134 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
135 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
136 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
137 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
138 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
139 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
140 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
141 /* Multiplication / division */
142 OPC_MULT
= 0x18 | OPC_SPECIAL
,
143 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
144 OPC_DIV
= 0x1A | OPC_SPECIAL
,
145 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
146 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
147 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
148 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
149 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD
= 0x20 | OPC_SPECIAL
,
152 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
153 OPC_SUB
= 0x22 | OPC_SPECIAL
,
154 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
155 OPC_AND
= 0x24 | OPC_SPECIAL
,
156 OPC_OR
= 0x25 | OPC_SPECIAL
,
157 OPC_XOR
= 0x26 | OPC_SPECIAL
,
158 OPC_NOR
= 0x27 | OPC_SPECIAL
,
159 OPC_SLT
= 0x2A | OPC_SPECIAL
,
160 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
161 OPC_DADD
= 0x2C | OPC_SPECIAL
,
162 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
163 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
164 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
166 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
167 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
169 OPC_TGE
= 0x30 | OPC_SPECIAL
,
170 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
171 OPC_TLT
= 0x32 | OPC_SPECIAL
,
172 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
173 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
174 OPC_TNE
= 0x36 | OPC_SPECIAL
,
175 /* HI / LO registers load & stores */
176 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
177 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
178 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
179 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
180 /* Conditional moves */
181 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
182 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
184 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
187 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
188 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
189 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
190 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
191 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
193 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
194 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
195 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
196 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
197 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
198 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
199 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
207 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
208 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
209 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
210 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
211 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
213 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
214 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
215 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
216 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
217 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
218 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
219 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
227 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
228 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
229 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
230 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
231 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
232 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
233 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
234 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
235 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
236 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
237 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
238 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
239 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
240 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
249 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
250 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
251 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
252 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
254 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
255 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
256 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
257 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
259 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
267 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
268 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
269 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
270 OPC_INS
= 0x04 | OPC_SPECIAL3
,
271 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
272 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
273 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
274 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
275 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
276 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
277 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
278 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
286 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
287 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
295 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
303 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
304 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
305 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
306 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
307 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
308 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
309 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
310 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
311 OPC_C0
= (0x10 << 21) | OPC_CP0
,
312 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
313 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
321 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
322 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
323 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
324 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
325 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR
= 0x01 | OPC_C0
,
333 OPC_TLBWI
= 0x02 | OPC_C0
,
334 OPC_TLBWR
= 0x06 | OPC_C0
,
335 OPC_TLBP
= 0x08 | OPC_C0
,
336 OPC_RFE
= 0x10 | OPC_C0
,
337 OPC_ERET
= 0x18 | OPC_C0
,
338 OPC_DERET
= 0x1F | OPC_C0
,
339 OPC_WAIT
= 0x20 | OPC_C0
,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
347 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
348 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
349 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
350 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
351 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
352 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
353 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
354 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
355 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
356 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
357 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
358 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
359 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
360 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
361 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
362 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
371 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
372 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
373 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
377 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
378 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
382 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
383 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
390 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
391 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
392 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
393 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
394 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
395 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
396 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
397 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1
= 0x00 | OPC_CP3
,
404 OPC_LDXC1
= 0x01 | OPC_CP3
,
405 OPC_LUXC1
= 0x05 | OPC_CP3
,
406 OPC_SWXC1
= 0x08 | OPC_CP3
,
407 OPC_SDXC1
= 0x09 | OPC_CP3
,
408 OPC_SUXC1
= 0x0D | OPC_CP3
,
409 OPC_PREFX
= 0x0F | OPC_CP3
,
410 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
411 OPC_MADD_S
= 0x20 | OPC_CP3
,
412 OPC_MADD_D
= 0x21 | OPC_CP3
,
413 OPC_MADD_PS
= 0x26 | OPC_CP3
,
414 OPC_MSUB_S
= 0x28 | OPC_CP3
,
415 OPC_MSUB_D
= 0x29 | OPC_CP3
,
416 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
417 OPC_NMADD_S
= 0x30 | OPC_CP3
,
418 OPC_NMADD_D
= 0x31 | OPC_CP3
,
419 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
420 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
421 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
422 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
425 /* global register indices */
426 static TCGv cpu_env
, current_tc_gprs
, current_tc_hi
, current_fpu
, cpu_T
[2];
428 /* FPU TNs, global for now. */
429 static TCGv fpu32_T
[3], fpu64_T
[3], fpu32h_T
[3];
431 static inline void tcg_gen_helper_0_i(void *func
, TCGv arg
)
433 TCGv tmp
= tcg_const_i32(arg
);
435 tcg_gen_helper_0_1(func
, tmp
);
439 static inline void tcg_gen_helper_0_ii(void *func
, TCGv arg1
, TCGv arg2
)
441 TCGv tmp1
= tcg_const_i32(arg1
);
442 TCGv tmp2
= tcg_const_i32(arg2
);
444 tcg_gen_helper_0_2(func
, tmp1
, tmp2
);
449 static inline void tcg_gen_helper_0_1i(void *func
, TCGv arg1
, TCGv arg2
)
451 TCGv tmp
= tcg_const_i32(arg2
);
453 tcg_gen_helper_0_2(func
, arg1
, tmp
);
457 static inline void tcg_gen_helper_0_2i(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
459 TCGv tmp
= tcg_const_i32(arg3
);
461 tcg_gen_helper_0_3(func
, arg1
, arg2
, tmp
);
465 static inline void tcg_gen_helper_0_2ii(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
, TCGv arg4
)
467 TCGv tmp1
= tcg_const_i32(arg3
);
468 TCGv tmp2
= tcg_const_i32(arg3
);
470 tcg_gen_helper_0_4(func
, arg1
, arg2
, tmp1
, tmp2
);
475 static inline void tcg_gen_helper_1_1i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
)
477 TCGv tmp
= tcg_const_i32(arg2
);
479 tcg_gen_helper_1_2(func
, ret
, arg1
, tmp
);
483 static inline void tcg_gen_helper_1_2i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
485 TCGv tmp
= tcg_const_i32(arg3
);
487 tcg_gen_helper_1_3(func
, ret
, arg1
, arg2
, tmp
);
491 static inline void tcg_gen_helper_1_2ii(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
, TCGv arg4
)
493 TCGv tmp1
= tcg_const_i32(arg3
);
494 TCGv tmp2
= tcg_const_i32(arg3
);
496 tcg_gen_helper_1_4(func
, ret
, arg1
, arg2
, tmp1
, tmp2
);
501 typedef struct DisasContext
{
502 struct TranslationBlock
*tb
;
503 target_ulong pc
, saved_pc
;
506 /* Routine used to access memory */
508 uint32_t hflags
, saved_hflags
;
510 target_ulong btarget
;
514 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
515 * exception condition
517 BS_STOP
= 1, /* We want to stop translation for any reason */
518 BS_BRANCH
= 2, /* We reached a branch condition */
519 BS_EXCP
= 3, /* We reached an exception condition */
522 static const char *regnames
[] =
523 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
524 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
525 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
526 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
528 static const char *fregnames
[] =
529 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
530 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
531 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
532 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
534 #ifdef MIPS_DEBUG_DISAS
535 #define MIPS_DEBUG(fmt, args...) \
537 if (loglevel & CPU_LOG_TB_IN_ASM) { \
538 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
539 ctx->pc, ctx->opcode , ##args); \
543 #define MIPS_DEBUG(fmt, args...) do { } while(0)
546 #define MIPS_INVAL(op) \
548 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
549 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
552 /* General purpose registers moves. */
553 static inline void gen_load_gpr (TCGv t
, int reg
)
556 tcg_gen_movi_tl(t
, 0);
558 tcg_gen_ld_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
561 static inline void gen_store_gpr (TCGv t
, int reg
)
564 tcg_gen_st_tl(t
, current_tc_gprs
, sizeof(target_ulong
) * reg
);
567 /* Moves to/from HI and LO registers. */
568 static inline void gen_load_LO (TCGv t
, int reg
)
570 tcg_gen_ld_tl(t
, current_tc_hi
,
571 offsetof(CPUState
, LO
)
572 - offsetof(CPUState
, HI
)
573 + sizeof(target_ulong
) * reg
);
576 static inline void gen_store_LO (TCGv t
, int reg
)
578 tcg_gen_st_tl(t
, current_tc_hi
,
579 offsetof(CPUState
, LO
)
580 - offsetof(CPUState
, HI
)
581 + sizeof(target_ulong
) * reg
);
584 static inline void gen_load_HI (TCGv t
, int reg
)
586 tcg_gen_ld_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
589 static inline void gen_store_HI (TCGv t
, int reg
)
591 tcg_gen_st_tl(t
, current_tc_hi
, sizeof(target_ulong
) * reg
);
594 /* Moves to/from shadow registers. */
595 static inline void gen_load_srsgpr (int from
, int to
)
597 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
600 tcg_gen_movi_tl(r_tmp1
, 0);
602 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
604 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
605 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
606 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
607 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
608 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
610 tcg_gen_ld_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * from
);
611 tcg_temp_free(r_tmp2
);
613 gen_store_gpr(r_tmp1
, to
);
614 tcg_temp_free(r_tmp1
);
617 static inline void gen_store_srsgpr (int from
, int to
)
620 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
621 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
623 gen_load_gpr(r_tmp1
, from
);
624 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
625 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
626 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
627 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
628 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
630 tcg_gen_st_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * to
);
631 tcg_temp_free(r_tmp1
);
632 tcg_temp_free(r_tmp2
);
636 /* Floating point register moves. */
637 static inline void gen_load_fpr32 (TCGv t
, int reg
)
639 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
642 static inline void gen_store_fpr32 (TCGv t
, int reg
)
644 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
647 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
649 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
650 tcg_gen_ld_i64(t
, current_fpu
, 8 * reg
);
652 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
653 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
655 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
656 tcg_gen_extu_i32_i64(t
, r_tmp1
);
657 tcg_gen_shli_i64(t
, t
, 32);
658 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
659 tcg_gen_extu_i32_i64(r_tmp2
, r_tmp1
);
660 tcg_gen_or_i64(t
, t
, r_tmp2
);
661 tcg_temp_free(r_tmp1
);
662 tcg_temp_free(r_tmp2
);
666 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
668 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
669 tcg_gen_st_i64(t
, current_fpu
, 8 * reg
);
671 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
673 tcg_gen_trunc_i64_i32(r_tmp
, t
);
674 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
675 tcg_gen_shri_i64(t
, t
, 32);
676 tcg_gen_trunc_i64_i32(r_tmp
, t
);
677 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
678 tcg_temp_free(r_tmp
);
682 static inline void gen_load_fpr32h (TCGv t
, int reg
)
684 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
687 static inline void gen_store_fpr32h (TCGv t
, int reg
)
689 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
692 static inline void get_fp_cond (TCGv t
)
694 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
695 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
697 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
698 tcg_gen_shri_i32(r_tmp2
, r_tmp1
, 24);
699 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xfe);
700 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, 23);
701 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, 0x1);
702 tcg_gen_or_i32(t
, r_tmp1
, r_tmp2
);
703 tcg_temp_free(r_tmp1
);
704 tcg_temp_free(r_tmp2
);
707 #define FOP_CONDS(type, fmt) \
708 static GenOpFunc1 * fcmp ## type ## _ ## fmt ## _table[16] = { \
709 do_cmp ## type ## _ ## fmt ## _f, \
710 do_cmp ## type ## _ ## fmt ## _un, \
711 do_cmp ## type ## _ ## fmt ## _eq, \
712 do_cmp ## type ## _ ## fmt ## _ueq, \
713 do_cmp ## type ## _ ## fmt ## _olt, \
714 do_cmp ## type ## _ ## fmt ## _ult, \
715 do_cmp ## type ## _ ## fmt ## _ole, \
716 do_cmp ## type ## _ ## fmt ## _ule, \
717 do_cmp ## type ## _ ## fmt ## _sf, \
718 do_cmp ## type ## _ ## fmt ## _ngle, \
719 do_cmp ## type ## _ ## fmt ## _seq, \
720 do_cmp ## type ## _ ## fmt ## _ngl, \
721 do_cmp ## type ## _ ## fmt ## _lt, \
722 do_cmp ## type ## _ ## fmt ## _nge, \
723 do_cmp ## type ## _ ## fmt ## _le, \
724 do_cmp ## type ## _ ## fmt ## _ngt, \
726 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
728 tcg_gen_helper_0_i(fcmp ## type ## _ ## fmt ## _table[n], cc); \
740 #define OP_COND(name, cond) \
741 void glue(gen_op_, name) (TCGv t0, TCGv t1) \
743 int l1 = gen_new_label(); \
744 int l2 = gen_new_label(); \
746 tcg_gen_brcond_tl(cond, t0, t1, l1); \
747 tcg_gen_movi_tl(t0, 0); \
750 tcg_gen_movi_tl(t0, 1); \
753 OP_COND(eq
, TCG_COND_EQ
);
754 OP_COND(ne
, TCG_COND_NE
);
755 OP_COND(ge
, TCG_COND_GE
);
756 OP_COND(geu
, TCG_COND_GEU
);
757 OP_COND(lt
, TCG_COND_LT
);
758 OP_COND(ltu
, TCG_COND_LTU
);
761 #define OP_CONDI(name, cond) \
762 void glue(gen_op_, name) (TCGv t, target_ulong val) \
764 int l1 = gen_new_label(); \
765 int l2 = gen_new_label(); \
767 tcg_gen_brcondi_tl(cond, t, val, l1); \
768 tcg_gen_movi_tl(t, 0); \
771 tcg_gen_movi_tl(t, 1); \
774 OP_CONDI(lti
, TCG_COND_LT
);
775 OP_CONDI(ltiu
, TCG_COND_LTU
);
778 #define OP_CONDZ(name, cond) \
779 void glue(gen_op_, name) (TCGv t) \
781 int l1 = gen_new_label(); \
782 int l2 = gen_new_label(); \
784 tcg_gen_brcondi_tl(cond, t, 0, l1); \
785 tcg_gen_movi_tl(t, 0); \
788 tcg_gen_movi_tl(t, 1); \
791 OP_CONDZ(gez
, TCG_COND_GE
);
792 OP_CONDZ(gtz
, TCG_COND_GT
);
793 OP_CONDZ(lez
, TCG_COND_LE
);
794 OP_CONDZ(ltz
, TCG_COND_LT
);
797 static inline void gen_save_pc(target_ulong pc
)
799 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
800 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
801 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
802 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
804 tcg_gen_movi_tl(r_tmp
, pc
);
805 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
806 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
807 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
808 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
809 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
810 tcg_temp_free(r_tc_off
);
811 tcg_temp_free(r_tc_off_ptr
);
812 tcg_temp_free(r_ptr
);
813 tcg_temp_free(r_tmp
);
816 static inline void gen_breg_pc(void)
818 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
819 TCGv r_tc_off
= tcg_temp_new(TCG_TYPE_I32
);
820 TCGv r_tc_off_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
821 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
823 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
824 tcg_gen_ld_i32(r_tc_off
, cpu_env
, offsetof(CPUState
, current_tc
));
825 tcg_gen_muli_i32(r_tc_off
, r_tc_off
, sizeof(target_ulong
));
826 tcg_gen_ext_i32_ptr(r_tc_off_ptr
, r_tc_off
);
827 tcg_gen_add_ptr(r_ptr
, cpu_env
, r_tc_off_ptr
);
828 tcg_gen_st_tl(r_tmp
, r_ptr
, offsetof(CPUState
, PC
));
829 tcg_temp_free(r_tc_off
);
830 tcg_temp_free(r_tc_off_ptr
);
831 tcg_temp_free(r_ptr
);
832 tcg_temp_free(r_tmp
);
835 static inline void gen_save_btarget(target_ulong btarget
)
837 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
839 tcg_gen_movi_tl(r_tmp
, btarget
);
840 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
841 tcg_temp_free(r_tmp
);
844 static always_inline
void gen_save_breg_target(int reg
)
846 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
848 gen_load_gpr(r_tmp
, reg
);
849 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, btarget
));
850 tcg_temp_free(r_tmp
);
853 static always_inline
void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
855 #if defined MIPS_DEBUG_DISAS
856 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
857 fprintf(logfile
, "hflags %08x saved %08x\n",
858 ctx
->hflags
, ctx
->saved_hflags
);
861 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
862 gen_save_pc(ctx
->pc
);
863 ctx
->saved_pc
= ctx
->pc
;
865 if (ctx
->hflags
!= ctx
->saved_hflags
) {
866 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
868 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
);
869 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
870 tcg_temp_free(r_tmp
);
871 ctx
->saved_hflags
= ctx
->hflags
;
872 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
878 gen_save_btarget(ctx
->btarget
);
884 static always_inline
void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
886 ctx
->saved_hflags
= ctx
->hflags
;
887 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
893 ctx
->btarget
= env
->btarget
;
898 static always_inline
void
899 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
901 save_cpu_state(ctx
, 1);
902 tcg_gen_helper_0_ii(do_raise_exception_err
, excp
, err
);
903 tcg_gen_helper_0_0(do_interrupt_restart
);
907 static always_inline
void
908 generate_exception (DisasContext
*ctx
, int excp
)
910 save_cpu_state(ctx
, 1);
911 tcg_gen_helper_0_i(do_raise_exception
, excp
);
912 tcg_gen_helper_0_0(do_interrupt_restart
);
916 /* Addresses computation */
917 static inline void gen_op_addr_add (TCGv t0
, TCGv t1
)
919 tcg_gen_add_tl(t0
, t0
, t1
);
921 #if defined(TARGET_MIPS64)
922 /* For compatibility with 32-bit code, data reference in user mode
923 with Status_UX = 0 should be casted to 32-bit and sign extended.
924 See the MIPS64 PRA manual, section 4.10. */
926 int l1
= gen_new_label();
927 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
929 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
930 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
931 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, MIPS_HFLAG_UM
, l1
);
932 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
933 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
934 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, 0, l1
);
935 tcg_temp_free(r_tmp
);
936 tcg_gen_ext32s_i64(t0
, t0
);
942 static always_inline
void check_cp0_enabled(DisasContext
*ctx
)
944 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
945 generate_exception_err(ctx
, EXCP_CpU
, 1);
948 static always_inline
void check_cp1_enabled(DisasContext
*ctx
)
950 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
951 generate_exception_err(ctx
, EXCP_CpU
, 1);
954 /* Verify that the processor is running with COP1X instructions enabled.
955 This is associated with the nabla symbol in the MIPS32 and MIPS64
958 static always_inline
void check_cop1x(DisasContext
*ctx
)
960 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
961 generate_exception(ctx
, EXCP_RI
);
964 /* Verify that the processor is running with 64-bit floating-point
965 operations enabled. */
967 static always_inline
void check_cp1_64bitmode(DisasContext
*ctx
)
969 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
970 generate_exception(ctx
, EXCP_RI
);
974 * Verify if floating point register is valid; an operation is not defined
975 * if bit 0 of any register specification is set and the FR bit in the
976 * Status register equals zero, since the register numbers specify an
977 * even-odd pair of adjacent coprocessor general registers. When the FR bit
978 * in the Status register equals one, both even and odd register numbers
979 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
981 * Multiple 64 bit wide registers can be checked by calling
982 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
984 void check_cp1_registers(DisasContext
*ctx
, int regs
)
986 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
987 generate_exception(ctx
, EXCP_RI
);
990 /* This code generates a "reserved instruction" exception if the
991 CPU does not support the instruction set corresponding to flags. */
992 static always_inline
void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
994 if (unlikely(!(env
->insn_flags
& flags
)))
995 generate_exception(ctx
, EXCP_RI
);
998 /* This code generates a "reserved instruction" exception if 64-bit
999 instructions are not enabled. */
1000 static always_inline
void check_mips_64(DisasContext
*ctx
)
1002 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
1003 generate_exception(ctx
, EXCP_RI
);
1006 /* load/store instructions. */
1007 #define OP_LD(insn,fname) \
1008 void inline op_ldst_##insn(TCGv t0, DisasContext *ctx) \
1010 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1017 #if defined(TARGET_MIPS64)
1023 #define OP_ST(insn,fname) \
1024 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1026 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1031 #if defined(TARGET_MIPS64)
1036 #define OP_LD_ATOMIC(insn,fname) \
1037 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1039 tcg_gen_mov_tl(t1, t0); \
1040 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1041 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1043 OP_LD_ATOMIC(ll
,ld32s
);
1044 #if defined(TARGET_MIPS64)
1045 OP_LD_ATOMIC(lld
,ld64
);
1049 #define OP_ST_ATOMIC(insn,fname,almask) \
1050 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1052 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1053 int l1 = gen_new_label(); \
1054 int l2 = gen_new_label(); \
1055 int l3 = gen_new_label(); \
1057 tcg_gen_andi_tl(r_tmp, t0, almask); \
1058 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1059 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1060 generate_exception(ctx, EXCP_AdES); \
1061 gen_set_label(l1); \
1062 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1063 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1064 tcg_temp_free(r_tmp); \
1065 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1066 tcg_gen_movi_tl(t0, 1); \
1068 gen_set_label(l2); \
1069 tcg_gen_movi_tl(t0, 0); \
1070 gen_set_label(l3); \
1072 OP_ST_ATOMIC(sc
,st32
,0x3);
1073 #if defined(TARGET_MIPS64)
1074 OP_ST_ATOMIC(scd
,st64
,0x7);
1078 /* Load and store */
1079 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1080 int base
, int16_t offset
)
1082 const char *opn
= "ldst";
1085 tcg_gen_movi_tl(cpu_T
[0], offset
);
1086 } else if (offset
== 0) {
1087 gen_load_gpr(cpu_T
[0], base
);
1089 gen_load_gpr(cpu_T
[0], base
);
1090 tcg_gen_movi_tl(cpu_T
[1], offset
);
1091 gen_op_addr_add(cpu_T
[0], cpu_T
[1]);
1093 /* Don't do NOP if destination is zero: we must perform the actual
1096 #if defined(TARGET_MIPS64)
1098 op_ldst_lwu(cpu_T
[0], ctx
);
1099 gen_store_gpr(cpu_T
[0], rt
);
1103 op_ldst_ld(cpu_T
[0], ctx
);
1104 gen_store_gpr(cpu_T
[0], rt
);
1108 op_ldst_lld(cpu_T
[0], cpu_T
[1], ctx
);
1109 gen_store_gpr(cpu_T
[0], rt
);
1113 gen_load_gpr(cpu_T
[1], rt
);
1114 op_ldst_sd(cpu_T
[0], cpu_T
[1], ctx
);
1118 save_cpu_state(ctx
, 1);
1119 gen_load_gpr(cpu_T
[1], rt
);
1120 op_ldst_scd(cpu_T
[0], cpu_T
[1], ctx
);
1121 gen_store_gpr(cpu_T
[0], rt
);
1125 save_cpu_state(ctx
, 1);
1126 gen_load_gpr(cpu_T
[1], rt
);
1127 tcg_gen_helper_1_2i(do_ldl
, cpu_T
[1], cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1128 gen_store_gpr(cpu_T
[1], rt
);
1132 save_cpu_state(ctx
, 1);
1133 gen_load_gpr(cpu_T
[1], rt
);
1134 tcg_gen_helper_0_2i(do_sdl
, cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1138 save_cpu_state(ctx
, 1);
1139 gen_load_gpr(cpu_T
[1], rt
);
1140 tcg_gen_helper_1_2i(do_ldr
, cpu_T
[1], cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1141 gen_store_gpr(cpu_T
[1], rt
);
1145 save_cpu_state(ctx
, 1);
1146 gen_load_gpr(cpu_T
[1], rt
);
1147 tcg_gen_helper_0_2i(do_sdr
, cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1152 op_ldst_lw(cpu_T
[0], ctx
);
1153 gen_store_gpr(cpu_T
[0], rt
);
1157 gen_load_gpr(cpu_T
[1], rt
);
1158 op_ldst_sw(cpu_T
[0], cpu_T
[1], ctx
);
1162 op_ldst_lh(cpu_T
[0], ctx
);
1163 gen_store_gpr(cpu_T
[0], rt
);
1167 gen_load_gpr(cpu_T
[1], rt
);
1168 op_ldst_sh(cpu_T
[0], cpu_T
[1], ctx
);
1172 op_ldst_lhu(cpu_T
[0], ctx
);
1173 gen_store_gpr(cpu_T
[0], rt
);
1177 op_ldst_lb(cpu_T
[0], ctx
);
1178 gen_store_gpr(cpu_T
[0], rt
);
1182 gen_load_gpr(cpu_T
[1], rt
);
1183 op_ldst_sb(cpu_T
[0], cpu_T
[1], ctx
);
1187 op_ldst_lbu(cpu_T
[0], ctx
);
1188 gen_store_gpr(cpu_T
[0], rt
);
1192 save_cpu_state(ctx
, 1);
1193 gen_load_gpr(cpu_T
[1], rt
);
1194 tcg_gen_helper_1_2i(do_lwl
, cpu_T
[1], cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1195 gen_store_gpr(cpu_T
[1], rt
);
1199 save_cpu_state(ctx
, 1);
1200 gen_load_gpr(cpu_T
[1], rt
);
1201 tcg_gen_helper_0_2i(do_swl
, cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1205 save_cpu_state(ctx
, 1);
1206 gen_load_gpr(cpu_T
[1], rt
);
1207 tcg_gen_helper_1_2i(do_lwr
, cpu_T
[1], cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1208 gen_store_gpr(cpu_T
[1], rt
);
1212 save_cpu_state(ctx
, 1);
1213 gen_load_gpr(cpu_T
[1], rt
);
1214 tcg_gen_helper_0_2i(do_swr
, cpu_T
[0], cpu_T
[1], ctx
->mem_idx
);
1218 op_ldst_ll(cpu_T
[0], cpu_T
[1], ctx
);
1219 gen_store_gpr(cpu_T
[0], rt
);
1223 save_cpu_state(ctx
, 1);
1224 gen_load_gpr(cpu_T
[1], rt
);
1225 op_ldst_sc(cpu_T
[0], cpu_T
[1], ctx
);
1226 gen_store_gpr(cpu_T
[0], rt
);
1231 generate_exception(ctx
, EXCP_RI
);
1234 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1237 /* Load and store */
1238 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1239 int base
, int16_t offset
)
1241 const char *opn
= "flt_ldst";
1244 tcg_gen_movi_tl(cpu_T
[0], offset
);
1245 } else if (offset
== 0) {
1246 gen_load_gpr(cpu_T
[0], base
);
1248 gen_load_gpr(cpu_T
[0], base
);
1249 tcg_gen_movi_tl(cpu_T
[1], offset
);
1250 gen_op_addr_add(cpu_T
[0], cpu_T
[1]);
1252 /* Don't do NOP if destination is zero: we must perform the actual
1256 tcg_gen_qemu_ld32s(fpu32_T
[0], cpu_T
[0], ctx
->mem_idx
);
1257 gen_store_fpr32(fpu32_T
[0], ft
);
1261 gen_load_fpr32(fpu32_T
[0], ft
);
1262 tcg_gen_qemu_st32(fpu32_T
[0], cpu_T
[0], ctx
->mem_idx
);
1266 tcg_gen_qemu_ld64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
1267 gen_store_fpr64(ctx
, fpu64_T
[0], ft
);
1271 gen_load_fpr64(ctx
, fpu64_T
[0], ft
);
1272 tcg_gen_qemu_st64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
1277 generate_exception(ctx
, EXCP_RI
);
1280 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1283 /* Arithmetic with immediate operand */
1284 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1285 int rt
, int rs
, int16_t imm
)
1288 const char *opn
= "imm arith";
1290 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1291 /* If no destination, treat it as a NOP.
1292 For addi, we must generate the overflow exception when needed. */
1296 uimm
= (uint16_t)imm
;
1300 #if defined(TARGET_MIPS64)
1306 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1311 gen_load_gpr(cpu_T
[0], rs
);
1314 tcg_gen_movi_tl(cpu_T
[0], imm
<< 16);
1319 #if defined(TARGET_MIPS64)
1328 gen_load_gpr(cpu_T
[0], rs
);
1334 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1335 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1336 int l1
= gen_new_label();
1338 save_cpu_state(ctx
, 1);
1339 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1340 tcg_gen_addi_tl(cpu_T
[0], r_tmp1
, uimm
);
1342 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1343 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1344 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1345 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1346 tcg_temp_free(r_tmp2
);
1347 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1348 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1349 tcg_temp_free(r_tmp1
);
1350 /* operands of same sign, result different sign */
1351 generate_exception(ctx
, EXCP_OVERFLOW
);
1354 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1359 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1360 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1361 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1364 #if defined(TARGET_MIPS64)
1367 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1368 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1369 int l1
= gen_new_label();
1371 save_cpu_state(ctx
, 1);
1372 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1373 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1375 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1376 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1377 tcg_gen_xori_tl(r_tmp2
, cpu_T
[0], uimm
);
1378 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1379 tcg_temp_free(r_tmp2
);
1380 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1381 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1382 tcg_temp_free(r_tmp1
);
1383 /* operands of same sign, result different sign */
1384 generate_exception(ctx
, EXCP_OVERFLOW
);
1390 tcg_gen_addi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1395 gen_op_lti(cpu_T
[0], uimm
);
1399 gen_op_ltiu(cpu_T
[0], uimm
);
1403 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], uimm
);
1407 tcg_gen_ori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1411 tcg_gen_xori_tl(cpu_T
[0], cpu_T
[0], uimm
);
1418 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1419 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1420 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1424 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1425 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1426 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1430 switch ((ctx
->opcode
>> 21) & 0x1f) {
1432 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1433 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1434 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1438 /* rotr is decoded as srl on non-R2 CPUs */
1439 if (env
->insn_flags
& ISA_MIPS32R2
) {
1441 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1442 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1444 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1445 tcg_gen_movi_i32(r_tmp2
, 0x20);
1446 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1447 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1448 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1449 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1450 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
1451 tcg_temp_free(r_tmp1
);
1452 tcg_temp_free(r_tmp2
);
1456 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1457 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1458 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1463 MIPS_INVAL("invalid srl flag");
1464 generate_exception(ctx
, EXCP_RI
);
1468 #if defined(TARGET_MIPS64)
1470 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
);
1474 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
);
1478 switch ((ctx
->opcode
>> 21) & 0x1f) {
1480 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1484 /* drotr is decoded as dsrl on non-R2 CPUs */
1485 if (env
->insn_flags
& ISA_MIPS32R2
) {
1487 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1489 tcg_gen_movi_tl(r_tmp1
, 0x40);
1490 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1491 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1492 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1493 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1494 tcg_temp_free(r_tmp1
);
1498 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
);
1503 MIPS_INVAL("invalid dsrl flag");
1504 generate_exception(ctx
, EXCP_RI
);
1509 tcg_gen_shli_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1513 tcg_gen_sari_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1517 switch ((ctx
->opcode
>> 21) & 0x1f) {
1519 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1523 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1524 if (env
->insn_flags
& ISA_MIPS32R2
) {
1525 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1526 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1528 tcg_gen_movi_tl(r_tmp1
, 0x40);
1529 tcg_gen_movi_tl(r_tmp2
, 32);
1530 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1531 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1532 tcg_gen_shl_tl(r_tmp1
, cpu_T
[0], r_tmp1
);
1533 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[0], r_tmp2
);
1534 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1535 tcg_temp_free(r_tmp1
);
1536 tcg_temp_free(r_tmp2
);
1539 tcg_gen_shri_tl(cpu_T
[0], cpu_T
[0], uimm
+ 32);
1544 MIPS_INVAL("invalid dsrl32 flag");
1545 generate_exception(ctx
, EXCP_RI
);
1552 generate_exception(ctx
, EXCP_RI
);
1555 gen_store_gpr(cpu_T
[0], rt
);
1556 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1560 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1561 int rd
, int rs
, int rt
)
1563 const char *opn
= "arith";
1565 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1566 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1567 /* If no destination, treat it as a NOP.
1568 For add & sub, we must generate the overflow exception when needed. */
1572 gen_load_gpr(cpu_T
[0], rs
);
1573 /* Specialcase the conventional move operation. */
1574 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1575 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1576 gen_store_gpr(cpu_T
[0], rd
);
1579 gen_load_gpr(cpu_T
[1], rt
);
1583 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1584 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1585 int l1
= gen_new_label();
1587 save_cpu_state(ctx
, 1);
1588 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1589 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1590 tcg_gen_add_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1592 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1593 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1594 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1595 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1596 tcg_temp_free(r_tmp2
);
1597 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1598 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1599 tcg_temp_free(r_tmp1
);
1600 /* operands of same sign, result different sign */
1601 generate_exception(ctx
, EXCP_OVERFLOW
);
1604 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1609 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1610 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1611 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1612 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1617 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1618 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1619 int l1
= gen_new_label();
1621 save_cpu_state(ctx
, 1);
1622 tcg_gen_ext32s_tl(r_tmp1
, cpu_T
[0]);
1623 tcg_gen_ext32s_tl(r_tmp2
, cpu_T
[1]);
1624 tcg_gen_sub_tl(cpu_T
[0], r_tmp1
, r_tmp2
);
1626 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1627 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1628 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1629 tcg_temp_free(r_tmp2
);
1630 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1631 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1632 tcg_temp_free(r_tmp1
);
1633 /* operands of different sign, first operand and result different sign */
1634 generate_exception(ctx
, EXCP_OVERFLOW
);
1637 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1642 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1643 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1644 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1645 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1648 #if defined(TARGET_MIPS64)
1651 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1652 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1653 int l1
= gen_new_label();
1655 save_cpu_state(ctx
, 1);
1656 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1657 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1659 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[1]);
1660 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1661 tcg_gen_xor_tl(r_tmp2
, cpu_T
[0], cpu_T
[1]);
1662 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1663 tcg_temp_free(r_tmp2
);
1664 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1665 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1666 tcg_temp_free(r_tmp1
);
1667 /* operands of same sign, result different sign */
1668 generate_exception(ctx
, EXCP_OVERFLOW
);
1674 tcg_gen_add_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1679 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1680 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1681 int l1
= gen_new_label();
1683 save_cpu_state(ctx
, 1);
1684 tcg_gen_mov_tl(r_tmp1
, cpu_T
[0]);
1685 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1687 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, cpu_T
[1]);
1688 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1689 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1690 tcg_temp_free(r_tmp2
);
1691 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1692 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1693 tcg_temp_free(r_tmp1
);
1694 /* operands of different sign, first operand and result different sign */
1695 generate_exception(ctx
, EXCP_OVERFLOW
);
1701 tcg_gen_sub_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1706 gen_op_lt(cpu_T
[0], cpu_T
[1]);
1710 gen_op_ltu(cpu_T
[0], cpu_T
[1]);
1714 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1718 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1719 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
1723 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1727 tcg_gen_xor_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1731 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1732 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1733 tcg_gen_mul_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
1734 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1739 int l1
= gen_new_label();
1741 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1742 gen_store_gpr(cpu_T
[0], rd
);
1749 int l1
= gen_new_label();
1751 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[1], 0, l1
);
1752 gen_store_gpr(cpu_T
[0], rd
);
1758 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
1759 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1760 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1761 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1762 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1766 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1767 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1768 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1769 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1773 switch ((ctx
->opcode
>> 6) & 0x1f) {
1775 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1776 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1777 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1778 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1782 /* rotrv is decoded as srlv on non-R2 CPUs */
1783 if (env
->insn_flags
& ISA_MIPS32R2
) {
1784 int l1
= gen_new_label();
1785 int l2
= gen_new_label();
1787 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1788 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
1790 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1791 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1792 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1794 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1795 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1796 tcg_gen_movi_i32(r_tmp3
, 0x20);
1797 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1798 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1799 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1800 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1801 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
1802 tcg_temp_free(r_tmp1
);
1803 tcg_temp_free(r_tmp2
);
1804 tcg_temp_free(r_tmp3
);
1808 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1812 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
1813 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x1f);
1814 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1815 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1820 MIPS_INVAL("invalid srlv flag");
1821 generate_exception(ctx
, EXCP_RI
);
1825 #if defined(TARGET_MIPS64)
1827 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1828 tcg_gen_shl_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1832 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1833 tcg_gen_sar_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1837 switch ((ctx
->opcode
>> 6) & 0x1f) {
1839 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1840 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1844 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1845 if (env
->insn_flags
& ISA_MIPS32R2
) {
1846 int l1
= gen_new_label();
1847 int l2
= gen_new_label();
1849 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1850 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
1852 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1854 tcg_gen_movi_tl(r_tmp1
, 0x40);
1855 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, cpu_T
[0]);
1856 tcg_gen_shl_tl(r_tmp1
, cpu_T
[1], r_tmp1
);
1857 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1858 tcg_gen_or_tl(cpu_T
[0], cpu_T
[0], r_tmp1
);
1859 tcg_temp_free(r_tmp1
);
1863 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
1867 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x3f);
1868 tcg_gen_shr_tl(cpu_T
[0], cpu_T
[1], cpu_T
[0]);
1873 MIPS_INVAL("invalid dsrlv flag");
1874 generate_exception(ctx
, EXCP_RI
);
1881 generate_exception(ctx
, EXCP_RI
);
1884 gen_store_gpr(cpu_T
[0], rd
);
1886 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1889 /* Arithmetic on HI/LO registers */
1890 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1892 const char *opn
= "hilo";
1894 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1901 gen_load_HI(cpu_T
[0], 0);
1902 gen_store_gpr(cpu_T
[0], reg
);
1906 gen_load_LO(cpu_T
[0], 0);
1907 gen_store_gpr(cpu_T
[0], reg
);
1911 gen_load_gpr(cpu_T
[0], reg
);
1912 gen_store_HI(cpu_T
[0], 0);
1916 gen_load_gpr(cpu_T
[0], reg
);
1917 gen_store_LO(cpu_T
[0], 0);
1922 generate_exception(ctx
, EXCP_RI
);
1925 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1928 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1931 const char *opn
= "mul/div";
1933 gen_load_gpr(cpu_T
[0], rs
);
1934 gen_load_gpr(cpu_T
[1], rt
);
1938 int l1
= gen_new_label();
1940 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1941 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1942 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1944 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1945 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1946 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
1948 tcg_gen_ext_tl_i64(r_tmp1
, cpu_T
[0]);
1949 tcg_gen_ext_tl_i64(r_tmp2
, cpu_T
[1]);
1950 tcg_gen_div_i64(r_tmp3
, r_tmp1
, r_tmp2
);
1951 tcg_gen_rem_i64(r_tmp2
, r_tmp1
, r_tmp2
);
1952 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp3
);
1953 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp2
);
1954 tcg_temp_free(r_tmp1
);
1955 tcg_temp_free(r_tmp2
);
1956 tcg_temp_free(r_tmp3
);
1957 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1958 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1959 gen_store_LO(cpu_T
[0], 0);
1960 gen_store_HI(cpu_T
[1], 0);
1968 int l1
= gen_new_label();
1970 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
1971 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
1973 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1974 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1975 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1977 tcg_gen_trunc_tl_i32(r_tmp1
, cpu_T
[0]);
1978 tcg_gen_trunc_tl_i32(r_tmp2
, cpu_T
[1]);
1979 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1980 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1981 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp3
);
1982 tcg_gen_ext_i32_tl(cpu_T
[1], r_tmp1
);
1983 tcg_temp_free(r_tmp1
);
1984 tcg_temp_free(r_tmp2
);
1985 tcg_temp_free(r_tmp3
);
1986 gen_store_LO(cpu_T
[0], 0);
1987 gen_store_HI(cpu_T
[1], 0);
1995 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1996 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1998 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
1999 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2000 tcg_gen_ext_tl_i64(r_tmp1
, cpu_T
[0]);
2001 tcg_gen_ext_tl_i64(r_tmp2
, cpu_T
[1]);
2002 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2003 tcg_temp_free(r_tmp2
);
2004 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2005 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2006 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2007 tcg_temp_free(r_tmp1
);
2008 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2009 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2010 gen_store_LO(cpu_T
[0], 0);
2011 gen_store_HI(cpu_T
[1], 0);
2017 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2018 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2020 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
2021 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
2022 tcg_gen_extu_tl_i64(r_tmp1
, cpu_T
[0]);
2023 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[1]);
2024 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2025 tcg_temp_free(r_tmp2
);
2026 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2027 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2028 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2029 tcg_temp_free(r_tmp1
);
2030 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2031 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2032 gen_store_LO(cpu_T
[0], 0);
2033 gen_store_HI(cpu_T
[1], 0);
2037 #if defined(TARGET_MIPS64)
2040 int l1
= gen_new_label();
2042 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
2044 int l2
= gen_new_label();
2046 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], -1LL << 63, l2
);
2047 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[1], -1LL, l2
);
2049 tcg_gen_movi_tl(cpu_T
[1], 0);
2050 gen_store_LO(cpu_T
[0], 0);
2051 gen_store_HI(cpu_T
[1], 0);
2056 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2057 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2059 tcg_gen_div_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
2060 tcg_gen_rem_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
2061 gen_store_LO(r_tmp1
, 0);
2062 gen_store_HI(r_tmp2
, 0);
2063 tcg_temp_free(r_tmp1
);
2064 tcg_temp_free(r_tmp2
);
2073 int l1
= gen_new_label();
2075 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[1], 0, l1
);
2077 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2078 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2080 tcg_gen_divu_i64(r_tmp1
, cpu_T
[0], cpu_T
[1]);
2081 tcg_gen_remu_i64(r_tmp2
, cpu_T
[0], cpu_T
[1]);
2082 tcg_temp_free(r_tmp1
);
2083 tcg_temp_free(r_tmp2
);
2084 gen_store_LO(r_tmp1
, 0);
2085 gen_store_HI(r_tmp2
, 0);
2092 tcg_gen_helper_0_2(do_dmult
, cpu_T
[0], cpu_T
[1]);
2096 tcg_gen_helper_0_2(do_dmultu
, cpu_T
[0], cpu_T
[1]);
2102 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2103 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2104 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2106 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2107 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2108 tcg_gen_ext_tl_i64(r_tmp1
, cpu_T
[0]);
2109 tcg_gen_ext_tl_i64(r_tmp2
, cpu_T
[1]);
2110 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2111 gen_load_LO(cpu_T
[0], 0);
2112 gen_load_HI(cpu_T
[1], 0);
2113 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[0]);
2114 tcg_gen_extu_tl_i64(r_tmp3
, cpu_T
[1]);
2115 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2116 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2117 tcg_temp_free(r_tmp3
);
2118 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2119 tcg_temp_free(r_tmp2
);
2120 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2121 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2122 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2123 tcg_temp_free(r_tmp1
);
2124 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2125 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2126 gen_store_LO(cpu_T
[0], 0);
2127 gen_store_HI(cpu_T
[1], 0);
2133 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2134 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2135 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2137 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
2138 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
2139 tcg_gen_extu_tl_i64(r_tmp1
, cpu_T
[0]);
2140 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[1]);
2141 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2142 gen_load_LO(cpu_T
[0], 0);
2143 gen_load_HI(cpu_T
[1], 0);
2144 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[0]);
2145 tcg_gen_extu_tl_i64(r_tmp3
, cpu_T
[1]);
2146 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2147 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2148 tcg_temp_free(r_tmp3
);
2149 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2150 tcg_temp_free(r_tmp2
);
2151 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2152 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2153 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2154 tcg_temp_free(r_tmp1
);
2155 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2156 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2157 gen_store_LO(cpu_T
[0], 0);
2158 gen_store_HI(cpu_T
[1], 0);
2164 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2165 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2166 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2168 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2169 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2170 tcg_gen_ext_tl_i64(r_tmp1
, cpu_T
[0]);
2171 tcg_gen_ext_tl_i64(r_tmp2
, cpu_T
[1]);
2172 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2173 gen_load_LO(cpu_T
[0], 0);
2174 gen_load_HI(cpu_T
[1], 0);
2175 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[0]);
2176 tcg_gen_extu_tl_i64(r_tmp3
, cpu_T
[1]);
2177 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2178 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2179 tcg_temp_free(r_tmp3
);
2180 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2181 tcg_temp_free(r_tmp2
);
2182 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2183 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2184 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2185 tcg_temp_free(r_tmp1
);
2186 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2187 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2188 gen_store_LO(cpu_T
[0], 0);
2189 gen_store_HI(cpu_T
[1], 0);
2195 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2196 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2197 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2199 tcg_gen_ext32u_tl(cpu_T
[0], cpu_T
[0]);
2200 tcg_gen_ext32u_tl(cpu_T
[1], cpu_T
[1]);
2201 tcg_gen_extu_tl_i64(r_tmp1
, cpu_T
[0]);
2202 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[1]);
2203 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2204 gen_load_LO(cpu_T
[0], 0);
2205 gen_load_HI(cpu_T
[1], 0);
2206 tcg_gen_extu_tl_i64(r_tmp2
, cpu_T
[0]);
2207 tcg_gen_extu_tl_i64(r_tmp3
, cpu_T
[1]);
2208 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2209 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2210 tcg_temp_free(r_tmp3
);
2211 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2212 tcg_temp_free(r_tmp2
);
2213 tcg_gen_trunc_i64_tl(cpu_T
[0], r_tmp1
);
2214 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2215 tcg_gen_trunc_i64_tl(cpu_T
[1], r_tmp1
);
2216 tcg_temp_free(r_tmp1
);
2217 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2218 tcg_gen_ext32s_tl(cpu_T
[1], cpu_T
[1]);
2219 gen_store_LO(cpu_T
[0], 0);
2220 gen_store_HI(cpu_T
[1], 0);
2226 generate_exception(ctx
, EXCP_RI
);
2229 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2232 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2233 int rd
, int rs
, int rt
)
2235 const char *opn
= "mul vr54xx";
2237 gen_load_gpr(cpu_T
[0], rs
);
2238 gen_load_gpr(cpu_T
[1], rt
);
2241 case OPC_VR54XX_MULS
:
2242 tcg_gen_helper_1_2(do_muls
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2245 case OPC_VR54XX_MULSU
:
2246 tcg_gen_helper_1_2(do_mulsu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2249 case OPC_VR54XX_MACC
:
2250 tcg_gen_helper_1_2(do_macc
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2253 case OPC_VR54XX_MACCU
:
2254 tcg_gen_helper_1_2(do_maccu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2257 case OPC_VR54XX_MSAC
:
2258 tcg_gen_helper_1_2(do_msac
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2261 case OPC_VR54XX_MSACU
:
2262 tcg_gen_helper_1_2(do_msacu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2265 case OPC_VR54XX_MULHI
:
2266 tcg_gen_helper_1_2(do_mulhi
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2269 case OPC_VR54XX_MULHIU
:
2270 tcg_gen_helper_1_2(do_mulhiu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2273 case OPC_VR54XX_MULSHI
:
2274 tcg_gen_helper_1_2(do_mulshi
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2277 case OPC_VR54XX_MULSHIU
:
2278 tcg_gen_helper_1_2(do_mulshiu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2281 case OPC_VR54XX_MACCHI
:
2282 tcg_gen_helper_1_2(do_macchi
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2285 case OPC_VR54XX_MACCHIU
:
2286 tcg_gen_helper_1_2(do_macchiu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2289 case OPC_VR54XX_MSACHI
:
2290 tcg_gen_helper_1_2(do_msachi
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2293 case OPC_VR54XX_MSACHIU
:
2294 tcg_gen_helper_1_2(do_msachiu
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
2298 MIPS_INVAL("mul vr54xx");
2299 generate_exception(ctx
, EXCP_RI
);
2302 gen_store_gpr(cpu_T
[0], rd
);
2303 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2306 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2309 const char *opn
= "CLx";
2315 gen_load_gpr(cpu_T
[0], rs
);
2318 tcg_gen_helper_1_1(do_clo
, cpu_T
[0], cpu_T
[0]);
2322 tcg_gen_helper_1_1(do_clz
, cpu_T
[0], cpu_T
[0]);
2325 #if defined(TARGET_MIPS64)
2327 tcg_gen_helper_1_1(do_dclo
, cpu_T
[0], cpu_T
[0]);
2331 tcg_gen_helper_1_1(do_dclz
, cpu_T
[0], cpu_T
[0]);
2337 generate_exception(ctx
, EXCP_RI
);
2340 gen_store_gpr(cpu_T
[0], rd
);
2341 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2345 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2346 int rs
, int rt
, int16_t imm
)
2349 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2350 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2353 /* Load needed operands */
2361 /* Compare two registers */
2363 gen_load_gpr(t0
, rs
);
2364 gen_load_gpr(t1
, rt
);
2374 /* Compare register to immediate */
2375 if (rs
!= 0 || imm
!= 0) {
2376 gen_load_gpr(t0
, rs
);
2377 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2384 case OPC_TEQ
: /* rs == rs */
2385 case OPC_TEQI
: /* r0 == 0 */
2386 case OPC_TGE
: /* rs >= rs */
2387 case OPC_TGEI
: /* r0 >= 0 */
2388 case OPC_TGEU
: /* rs >= rs unsigned */
2389 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2391 tcg_gen_movi_tl(t0
, 1);
2393 case OPC_TLT
: /* rs < rs */
2394 case OPC_TLTI
: /* r0 < 0 */
2395 case OPC_TLTU
: /* rs < rs unsigned */
2396 case OPC_TLTIU
: /* r0 < 0 unsigned */
2397 case OPC_TNE
: /* rs != rs */
2398 case OPC_TNEI
: /* r0 != 0 */
2399 /* Never trap: treat as NOP. */
2403 generate_exception(ctx
, EXCP_RI
);
2434 generate_exception(ctx
, EXCP_RI
);
2438 save_cpu_state(ctx
, 1);
2440 int l1
= gen_new_label();
2442 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2443 tcg_gen_helper_0_i(do_raise_exception
, EXCP_TRAP
);
2446 ctx
->bstate
= BS_STOP
;
2452 static always_inline
void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2454 TranslationBlock
*tb
;
2456 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2459 tcg_gen_exit_tb((long)tb
+ n
);
2466 /* Branches (before delay slot) */
2467 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2468 int rs
, int rt
, int32_t offset
)
2470 target_ulong btarget
= -1;
2474 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2475 #ifdef MIPS_DEBUG_DISAS
2476 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2478 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2482 generate_exception(ctx
, EXCP_RI
);
2486 /* Load needed operands */
2492 /* Compare two registers */
2494 gen_load_gpr(cpu_T
[0], rs
);
2495 gen_load_gpr(cpu_T
[1], rt
);
2498 btarget
= ctx
->pc
+ 4 + offset
;
2512 /* Compare to zero */
2514 gen_load_gpr(cpu_T
[0], rs
);
2517 btarget
= ctx
->pc
+ 4 + offset
;
2521 /* Jump to immediate */
2522 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2526 /* Jump to register */
2527 if (offset
!= 0 && offset
!= 16) {
2528 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2529 others are reserved. */
2530 MIPS_INVAL("jump hint");
2531 generate_exception(ctx
, EXCP_RI
);
2534 gen_save_breg_target(rs
);
2537 MIPS_INVAL("branch/jump");
2538 generate_exception(ctx
, EXCP_RI
);
2542 /* No condition to be computed */
2544 case OPC_BEQ
: /* rx == rx */
2545 case OPC_BEQL
: /* rx == rx likely */
2546 case OPC_BGEZ
: /* 0 >= 0 */
2547 case OPC_BGEZL
: /* 0 >= 0 likely */
2548 case OPC_BLEZ
: /* 0 <= 0 */
2549 case OPC_BLEZL
: /* 0 <= 0 likely */
2551 ctx
->hflags
|= MIPS_HFLAG_B
;
2552 MIPS_DEBUG("balways");
2554 case OPC_BGEZAL
: /* 0 >= 0 */
2555 case OPC_BGEZALL
: /* 0 >= 0 likely */
2556 /* Always take and link */
2558 ctx
->hflags
|= MIPS_HFLAG_B
;
2559 MIPS_DEBUG("balways and link");
2561 case OPC_BNE
: /* rx != rx */
2562 case OPC_BGTZ
: /* 0 > 0 */
2563 case OPC_BLTZ
: /* 0 < 0 */
2565 MIPS_DEBUG("bnever (NOP)");
2567 case OPC_BLTZAL
: /* 0 < 0 */
2568 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2569 gen_store_gpr(cpu_T
[0], 31);
2570 MIPS_DEBUG("bnever and link");
2572 case OPC_BLTZALL
: /* 0 < 0 likely */
2573 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2574 gen_store_gpr(cpu_T
[0], 31);
2575 /* Skip the instruction in the delay slot */
2576 MIPS_DEBUG("bnever, link and skip");
2579 case OPC_BNEL
: /* rx != rx likely */
2580 case OPC_BGTZL
: /* 0 > 0 likely */
2581 case OPC_BLTZL
: /* 0 < 0 likely */
2582 /* Skip the instruction in the delay slot */
2583 MIPS_DEBUG("bnever and skip");
2587 ctx
->hflags
|= MIPS_HFLAG_B
;
2588 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
2592 ctx
->hflags
|= MIPS_HFLAG_B
;
2593 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
2596 ctx
->hflags
|= MIPS_HFLAG_BR
;
2597 MIPS_DEBUG("jr %s", regnames
[rs
]);
2601 ctx
->hflags
|= MIPS_HFLAG_BR
;
2602 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2605 MIPS_INVAL("branch/jump");
2606 generate_exception(ctx
, EXCP_RI
);
2612 gen_op_eq(cpu_T
[0], cpu_T
[1]);
2613 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2614 regnames
[rs
], regnames
[rt
], btarget
);
2617 gen_op_eq(cpu_T
[0], cpu_T
[1]);
2618 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2619 regnames
[rs
], regnames
[rt
], btarget
);
2622 gen_op_ne(cpu_T
[0], cpu_T
[1]);
2623 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2624 regnames
[rs
], regnames
[rt
], btarget
);
2627 gen_op_ne(cpu_T
[0], cpu_T
[1]);
2628 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2629 regnames
[rs
], regnames
[rt
], btarget
);
2632 gen_op_gez(cpu_T
[0]);
2633 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2636 gen_op_gez(cpu_T
[0]);
2637 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2640 gen_op_gez(cpu_T
[0]);
2641 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2645 gen_op_gez(cpu_T
[0]);
2647 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2650 gen_op_gtz(cpu_T
[0]);
2651 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2654 gen_op_gtz(cpu_T
[0]);
2655 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2658 gen_op_lez(cpu_T
[0]);
2659 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2662 gen_op_lez(cpu_T
[0]);
2663 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2666 gen_op_ltz(cpu_T
[0]);
2667 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2670 gen_op_ltz(cpu_T
[0]);
2671 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2674 gen_op_ltz(cpu_T
[0]);
2676 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2678 ctx
->hflags
|= MIPS_HFLAG_BC
;
2679 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2682 gen_op_ltz(cpu_T
[0]);
2684 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
2686 ctx
->hflags
|= MIPS_HFLAG_BL
;
2687 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
2690 MIPS_INVAL("conditional branch/jump");
2691 generate_exception(ctx
, EXCP_RI
);
2695 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2696 blink
, ctx
->hflags
, btarget
);
2698 ctx
->btarget
= btarget
;
2700 tcg_gen_movi_tl(cpu_T
[0], ctx
->pc
+ 8);
2701 gen_store_gpr(cpu_T
[0], blink
);
2705 /* special3 bitfield operations */
2706 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2707 int rs
, int lsb
, int msb
)
2709 gen_load_gpr(cpu_T
[1], rs
);
2714 tcg_gen_helper_1_2ii(do_ext
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
+ 1);
2716 #if defined(TARGET_MIPS64)
2720 tcg_gen_helper_1_2ii(do_dext
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
+ 1 + 32);
2725 tcg_gen_helper_1_2ii(do_dext
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
+ 32, msb
+ 1);
2730 tcg_gen_helper_1_2ii(do_dext
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
+ 1);
2736 gen_load_gpr(cpu_T
[0], rt
);
2737 tcg_gen_helper_1_2ii(do_ins
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
- lsb
+ 1);
2739 #if defined(TARGET_MIPS64)
2743 gen_load_gpr(cpu_T
[0], rt
);
2744 tcg_gen_helper_1_2ii(do_dins
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
- lsb
+ 1 + 32);
2749 gen_load_gpr(cpu_T
[0], rt
);
2750 tcg_gen_helper_1_2ii(do_dins
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
+ 32, msb
- lsb
+ 1);
2755 gen_load_gpr(cpu_T
[0], rt
);
2756 tcg_gen_helper_1_2ii(do_dins
, cpu_T
[0], cpu_T
[0], cpu_T
[1], lsb
, msb
- lsb
+ 1);
2761 MIPS_INVAL("bitops");
2762 generate_exception(ctx
, EXCP_RI
);
2765 gen_store_gpr(cpu_T
[0], rt
);
2768 /* CP0 (MMU and control) */
2769 #ifndef CONFIG_USER_ONLY
2770 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2772 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2774 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2775 tcg_gen_ext_i32_tl(t
, r_tmp
);
2776 tcg_temp_free(r_tmp
);
2779 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2781 tcg_gen_ld_tl(t
, cpu_env
, off
);
2782 tcg_gen_ext32s_tl(t
, t
);
2785 static inline void gen_mtc0_store32 (TCGv t
, target_ulong off
)
2787 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2789 tcg_gen_trunc_tl_i32(r_tmp
, t
);
2790 tcg_gen_st_i32(r_tmp
, cpu_env
, off
);
2791 tcg_temp_free(r_tmp
);
2794 static inline void gen_mtc0_store64 (TCGv t
, target_ulong off
)
2796 tcg_gen_ext32s_tl(t
, t
);
2797 tcg_gen_st_tl(t
, cpu_env
, off
);
2800 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
2802 const char *rn
= "invalid";
2805 check_insn(env
, ctx
, ISA_MIPS32
);
2811 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Index
));
2815 check_insn(env
, ctx
, ASE_MT
);
2816 tcg_gen_helper_1_1(do_mfc0_mvpcontrol
, cpu_T
[0], cpu_T
[0]);
2820 check_insn(env
, ctx
, ASE_MT
);
2821 tcg_gen_helper_1_1(do_mfc0_mvpconf0
, cpu_T
[0], cpu_T
[0]);
2825 check_insn(env
, ctx
, ASE_MT
);
2826 tcg_gen_helper_1_1(do_mfc0_mvpconf1
, cpu_T
[0], cpu_T
[0]);
2836 tcg_gen_helper_1_1(do_mfc0_random
, cpu_T
[0], cpu_T
[0]);
2840 check_insn(env
, ctx
, ASE_MT
);
2841 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEControl
));
2845 check_insn(env
, ctx
, ASE_MT
);
2846 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf0
));
2850 check_insn(env
, ctx
, ASE_MT
);
2851 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf1
));
2855 check_insn(env
, ctx
, ASE_MT
);
2856 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_YQMask
));
2860 check_insn(env
, ctx
, ASE_MT
);
2861 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_VPESchedule
));
2865 check_insn(env
, ctx
, ASE_MT
);
2866 gen_mfc0_load64(cpu_T
[0], offsetof(CPUState
, CP0_VPEScheFBack
));
2867 rn
= "VPEScheFBack";
2870 check_insn(env
, ctx
, ASE_MT
);
2871 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEOpt
));
2881 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2882 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2886 check_insn(env
, ctx
, ASE_MT
);
2887 tcg_gen_helper_1_1(do_mfc0_tcstatus
, cpu_T
[0], cpu_T
[0]);
2891 check_insn(env
, ctx
, ASE_MT
);
2892 tcg_gen_helper_1_1(do_mfc0_tcbind
, cpu_T
[0], cpu_T
[0]);
2896 check_insn(env
, ctx
, ASE_MT
);
2897 tcg_gen_helper_1_1(do_mfc0_tcrestart
, cpu_T
[0], cpu_T
[0]);
2901 check_insn(env
, ctx
, ASE_MT
);
2902 tcg_gen_helper_1_1(do_mfc0_tchalt
, cpu_T
[0], cpu_T
[0]);
2906 check_insn(env
, ctx
, ASE_MT
);
2907 tcg_gen_helper_1_1(do_mfc0_tccontext
, cpu_T
[0], cpu_T
[0]);
2911 check_insn(env
, ctx
, ASE_MT
);
2912 tcg_gen_helper_1_1(do_mfc0_tcschedule
, cpu_T
[0], cpu_T
[0]);
2916 check_insn(env
, ctx
, ASE_MT
);
2917 tcg_gen_helper_1_1(do_mfc0_tcschefback
, cpu_T
[0], cpu_T
[0]);
2927 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2928 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2938 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_Context
));
2939 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
2943 // tcg_gen_helper_1_1(do_mfc0_contextconfig, cpu_T[0], cpu_T[0]); /* SmartMIPS ASE */
2944 rn
= "ContextConfig";
2953 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageMask
));
2957 check_insn(env
, ctx
, ISA_MIPS32R2
);
2958 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageGrain
));
2968 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Wired
));
2972 check_insn(env
, ctx
, ISA_MIPS32R2
);
2973 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf0
));
2977 check_insn(env
, ctx
, ISA_MIPS32R2
);
2978 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf1
));
2982 check_insn(env
, ctx
, ISA_MIPS32R2
);
2983 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf2
));
2987 check_insn(env
, ctx
, ISA_MIPS32R2
);
2988 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf3
));
2992 check_insn(env
, ctx
, ISA_MIPS32R2
);
2993 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf4
));
3003 check_insn(env
, ctx
, ISA_MIPS32R2
);
3004 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_HWREna
));
3014 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3015 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3025 tcg_gen_helper_1_1(do_mfc0_count
, cpu_T
[0], cpu_T
[0]);
3028 /* 6,7 are implementation dependent */
3036 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3037 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3047 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Compare
));
3050 /* 6,7 are implementation dependent */
3058 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Status
));
3062 check_insn(env
, ctx
, ISA_MIPS32R2
);
3063 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_IntCtl
));
3067 check_insn(env
, ctx
, ISA_MIPS32R2
);
3068 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSCtl
));
3072 check_insn(env
, ctx
, ISA_MIPS32R2
);
3073 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
3083 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Cause
));
3093 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EPC
));
3094 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3104 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PRid
));
3108 check_insn(env
, ctx
, ISA_MIPS32R2
);
3109 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_EBase
));
3119 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config0
));
3123 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config1
));
3127 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config2
));
3131 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config3
));
3134 /* 4,5 are reserved */
3135 /* 6,7 are implementation dependent */
3137 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config6
));
3141 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config7
));
3151 tcg_gen_helper_1_1(do_mfc0_lladdr
, cpu_T
[0], cpu_T
[0]);
3161 tcg_gen_helper_1_1i(do_mfc0_watchlo
, cpu_T
[0], cpu_T
[0], sel
);
3171 tcg_gen_helper_1_1i(do_mfc0_watchhi
, cpu_T
[0], cpu_T
[0], sel
);
3181 #if defined(TARGET_MIPS64)
3182 check_insn(env
, ctx
, ISA_MIPS3
);
3183 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_XContext
));
3184 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3193 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3196 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Framemask
));
3205 rn
= "'Diagnostic"; /* implementation dependent */
3210 tcg_gen_helper_1_1(do_mfc0_debug
, cpu_T
[0], cpu_T
[0]); /* EJTAG support */
3214 // tcg_gen_helper_1_1(do_mfc0_tracecontrol, cpu_T[0], cpu_T[0]); /* PDtrace support */
3215 rn
= "TraceControl";
3218 // tcg_gen_helper_1_1(do_mfc0_tracecontrol2, cpu_T[0], cpu_T[0]); /* PDtrace support */
3219 rn
= "TraceControl2";
3222 // tcg_gen_helper_1_1(do_mfc0_usertracedata, cpu_T[0], cpu_T[0]); /* PDtrace support */
3223 rn
= "UserTraceData";
3226 // tcg_gen_helper_1_1(do_mfc0_tracebpc, cpu_T[0], cpu_T[0]); /* PDtrace support */
3237 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3238 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3248 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Performance0
));
3249 rn
= "Performance0";
3252 // tcg_gen_helper_1_1(do_mfc0_performance1, cpu_T[0], cpu_T[0]);
3253 rn
= "Performance1";
3256 // tcg_gen_helper_1_1(do_mfc0_performance2, cpu_T[0], cpu_T[0]);
3257 rn
= "Performance2";
3260 // tcg_gen_helper_1_1(do_mfc0_performance3, cpu_T[0], cpu_T[0]);
3261 rn
= "Performance3";
3264 // tcg_gen_helper_1_1(do_mfc0_performance4, cpu_T[0], cpu_T[0]);
3265 rn
= "Performance4";
3268 // tcg_gen_helper_1_1(do_mfc0_performance5, cpu_T[0], cpu_T[0]);
3269 rn
= "Performance5";
3272 // tcg_gen_helper_1_1(do_mfc0_performance6, cpu_T[0], cpu_T[0]);
3273 rn
= "Performance6";
3276 // tcg_gen_helper_1_1(do_mfc0_performance7, cpu_T[0], cpu_T[0]);
3277 rn
= "Performance7";
3302 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagLo
));
3309 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataLo
));
3322 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagHi
));
3329 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataHi
));
3339 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3340 tcg_gen_ext32s_tl(cpu_T
[0], cpu_T
[0]);
3351 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
3361 #if defined MIPS_DEBUG_DISAS
3362 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3363 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3370 #if defined MIPS_DEBUG_DISAS
3371 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3372 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3376 generate_exception(ctx
, EXCP_RI
);
3379 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3381 const char *rn
= "invalid";
3384 check_insn(env
, ctx
, ISA_MIPS32
);
3390 tcg_gen_helper_0_1(do_mtc0_index
, cpu_T
[0]);
3394 check_insn(env
, ctx
, ASE_MT
);
3395 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, cpu_T
[0]);
3399 check_insn(env
, ctx
, ASE_MT
);
3404 check_insn(env
, ctx
, ASE_MT
);
3419 check_insn(env
, ctx
, ASE_MT
);
3420 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, cpu_T
[0]);
3424 check_insn(env
, ctx
, ASE_MT
);
3425 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, cpu_T
[0]);
3429 check_insn(env
, ctx
, ASE_MT
);
3430 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, cpu_T
[0]);
3434 check_insn(env
, ctx
, ASE_MT
);
3435 tcg_gen_helper_0_1(do_mtc0_yqmask
, cpu_T
[0]);
3439 check_insn(env
, ctx
, ASE_MT
);
3440 gen_mtc0_store64(cpu_T
[0], offsetof(CPUState
, CP0_VPESchedule
));
3444 check_insn(env
, ctx
, ASE_MT
);
3445 gen_mtc0_store64(cpu_T
[0], offsetof(CPUState
, CP0_VPEScheFBack
));
3446 rn
= "VPEScheFBack";
3449 check_insn(env
, ctx
, ASE_MT
);
3450 tcg_gen_helper_0_1(do_mtc0_vpeopt
, cpu_T
[0]);
3460 tcg_gen_helper_0_1(do_mtc0_entrylo0
, cpu_T
[0]);
3464 check_insn(env
, ctx
, ASE_MT
);
3465 tcg_gen_helper_0_1(do_mtc0_tcstatus
, cpu_T
[0]);
3469 check_insn(env
, ctx
, ASE_MT
);
3470 tcg_gen_helper_0_1(do_mtc0_tcbind
, cpu_T
[0]);
3474 check_insn(env
, ctx
, ASE_MT
);
3475 tcg_gen_helper_0_1(do_mtc0_tcrestart
, cpu_T
[0]);
3479 check_insn(env
, ctx
, ASE_MT
);
3480 tcg_gen_helper_0_1(do_mtc0_tchalt
, cpu_T
[0]);
3484 check_insn(env
, ctx
, ASE_MT
);
3485 tcg_gen_helper_0_1(do_mtc0_tccontext
, cpu_T
[0]);
3489 check_insn(env
, ctx
, ASE_MT
);
3490 tcg_gen_helper_0_1(do_mtc0_tcschedule
, cpu_T
[0]);
3494 check_insn(env
, ctx
, ASE_MT
);
3495 tcg_gen_helper_0_1(do_mtc0_tcschefback
, cpu_T
[0]);
3505 tcg_gen_helper_0_1(do_mtc0_entrylo1
, cpu_T
[0]);
3515 tcg_gen_helper_0_1(do_mtc0_context
, cpu_T
[0]);
3519 // tcg_gen_helper_0_1(do_mtc0_contextconfig, cpu_T[0]); /* SmartMIPS ASE */
3520 rn
= "ContextConfig";
3529 tcg_gen_helper_0_1(do_mtc0_pagemask
, cpu_T
[0]);
3533 check_insn(env
, ctx
, ISA_MIPS32R2
);
3534 tcg_gen_helper_0_1(do_mtc0_pagegrain
, cpu_T
[0]);
3544 tcg_gen_helper_0_1(do_mtc0_wired
, cpu_T
[0]);
3548 check_insn(env
, ctx
, ISA_MIPS32R2
);
3549 tcg_gen_helper_0_1(do_mtc0_srsconf0
, cpu_T
[0]);
3553 check_insn(env
, ctx
, ISA_MIPS32R2
);
3554 tcg_gen_helper_0_1(do_mtc0_srsconf1
, cpu_T
[0]);
3558 check_insn(env
, ctx
, ISA_MIPS32R2
);
3559 tcg_gen_helper_0_1(do_mtc0_srsconf2
, cpu_T
[0]);
3563 check_insn(env
, ctx
, ISA_MIPS32R2
);
3564 tcg_gen_helper_0_1(do_mtc0_srsconf3
, cpu_T
[0]);
3568 check_insn(env
, ctx
, ISA_MIPS32R2
);
3569 tcg_gen_helper_0_1(do_mtc0_srsconf4
, cpu_T
[0]);
3579 check_insn(env
, ctx
, ISA_MIPS32R2
);
3580 tcg_gen_helper_0_1(do_mtc0_hwrena
, cpu_T
[0]);
3594 tcg_gen_helper_0_1(do_mtc0_count
, cpu_T
[0]);
3597 /* 6,7 are implementation dependent */
3601 /* Stop translation as we may have switched the execution mode */
3602 ctx
->bstate
= BS_STOP
;
3607 tcg_gen_helper_0_1(do_mtc0_entryhi
, cpu_T
[0]);
3617 tcg_gen_helper_0_1(do_mtc0_compare
, cpu_T
[0]);
3620 /* 6,7 are implementation dependent */
3624 /* Stop translation as we may have switched the execution mode */
3625 ctx
->bstate
= BS_STOP
;
3630 tcg_gen_helper_0_1(do_mtc0_status
, cpu_T
[0]);
3631 /* BS_STOP isn't good enough here, hflags may have changed. */
3632 gen_save_pc(ctx
->pc
+ 4);
3633 ctx
->bstate
= BS_EXCP
;
3637 check_insn(env
, ctx
, ISA_MIPS32R2
);
3638 tcg_gen_helper_0_1(do_mtc0_intctl
, cpu_T
[0]);
3639 /* Stop translation as we may have switched the execution mode */
3640 ctx
->bstate
= BS_STOP
;
3644 check_insn(env
, ctx
, ISA_MIPS32R2
);
3645 tcg_gen_helper_0_1(do_mtc0_srsctl
, cpu_T
[0]);
3646 /* Stop translation as we may have switched the execution mode */
3647 ctx
->bstate
= BS_STOP
;
3651 check_insn(env
, ctx
, ISA_MIPS32R2
);
3652 gen_mtc0_store32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
3653 /* Stop translation as we may have switched the execution mode */
3654 ctx
->bstate
= BS_STOP
;
3664 tcg_gen_helper_0_1(do_mtc0_cause
, cpu_T
[0]);
3670 /* Stop translation as we may have switched the execution mode */
3671 ctx
->bstate
= BS_STOP
;
3676 gen_mtc0_store64(cpu_T
[0], offsetof(CPUState
, CP0_EPC
));
3690 check_insn(env
, ctx
, ISA_MIPS32R2
);
3691 tcg_gen_helper_0_1(do_mtc0_ebase
, cpu_T
[0]);
3701 tcg_gen_helper_0_1(do_mtc0_config0
, cpu_T
[0]);
3703 /* Stop translation as we may have switched the execution mode */
3704 ctx
->bstate
= BS_STOP
;
3707 /* ignored, read only */
3711 tcg_gen_helper_0_1(do_mtc0_config2
, cpu_T
[0]);
3713 /* Stop translation as we may have switched the execution mode */
3714 ctx
->bstate
= BS_STOP
;
3717 /* ignored, read only */
3720 /* 4,5 are reserved */
3721 /* 6,7 are implementation dependent */
3731 rn
= "Invalid config selector";
3748 tcg_gen_helper_0_1i(do_mtc0_watchlo
, cpu_T
[0], sel
);
3758 tcg_gen_helper_0_1i(do_mtc0_watchhi
, cpu_T
[0], sel
);
3768 #if defined(TARGET_MIPS64)
3769 check_insn(env
, ctx
, ISA_MIPS3
);
3770 tcg_gen_helper_0_1(do_mtc0_xcontext
, cpu_T
[0]);
3779 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3782 tcg_gen_helper_0_1(do_mtc0_framemask
, cpu_T
[0]);
3791 rn
= "Diagnostic"; /* implementation dependent */
3796 tcg_gen_helper_0_1(do_mtc0_debug
, cpu_T
[0]); /* EJTAG support */
3797 /* BS_STOP isn't good enough here, hflags may have changed. */
3798 gen_save_pc(ctx
->pc
+ 4);
3799 ctx
->bstate
= BS_EXCP
;
3803 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, cpu_T[0]); /* PDtrace support */
3804 rn
= "TraceControl";
3805 /* Stop translation as we may have switched the execution mode */
3806 ctx
->bstate
= BS_STOP
;
3809 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, cpu_T[0]); /* PDtrace support */
3810 rn
= "TraceControl2";
3811 /* Stop translation as we may have switched the execution mode */
3812 ctx
->bstate
= BS_STOP
;
3815 /* Stop translation as we may have switched the execution mode */
3816 ctx
->bstate
= BS_STOP
;
3817 // tcg_gen_helper_0_1(do_mtc0_usertracedata, cpu_T[0]); /* PDtrace support */
3818 rn
= "UserTraceData";
3819 /* Stop translation as we may have switched the execution mode */
3820 ctx
->bstate
= BS_STOP
;
3823 // tcg_gen_helper_0_1(do_mtc0_tracebpc, cpu_T[0]); /* PDtrace support */
3824 /* Stop translation as we may have switched the execution mode */
3825 ctx
->bstate
= BS_STOP
;
3836 gen_mtc0_store64(cpu_T
[0], offsetof(CPUState
, CP0_DEPC
));
3846 tcg_gen_helper_0_1(do_mtc0_performance0
, cpu_T
[0]);
3847 rn
= "Performance0";
3850 // tcg_gen_helper_0_1(do_mtc0_performance1, cpu_T[0]);
3851 rn
= "Performance1";
3854 // tcg_gen_helper_0_1(do_mtc0_performance2, cpu_T[0]);
3855 rn
= "Performance2";
3858 // tcg_gen_helper_0_1(do_mtc0_performance3, cpu_T[0]);
3859 rn
= "Performance3";
3862 // tcg_gen_helper_0_1(do_mtc0_performance4, cpu_T[0]);
3863 rn
= "Performance4";
3866 // tcg_gen_helper_0_1(do_mtc0_performance5, cpu_T[0]);
3867 rn
= "Performance5";
3870 // tcg_gen_helper_0_1(do_mtc0_performance6, cpu_T[0]);
3871 rn
= "Performance6";
3874 // tcg_gen_helper_0_1(do_mtc0_performance7, cpu_T[0]);
3875 rn
= "Performance7";
3901 tcg_gen_helper_0_1(do_mtc0_taglo
, cpu_T
[0]);
3908 tcg_gen_helper_0_1(do_mtc0_datalo
, cpu_T
[0]);
3921 tcg_gen_helper_0_1(do_mtc0_taghi
, cpu_T
[0]);
3928 tcg_gen_helper_0_1(do_mtc0_datahi
, cpu_T
[0]);
3939 gen_mtc0_store64(cpu_T
[0], offsetof(CPUState
, CP0_ErrorEPC
));
3950 gen_mtc0_store32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
3956 /* Stop translation as we may have switched the execution mode */
3957 ctx
->bstate
= BS_STOP
;
3962 #if defined MIPS_DEBUG_DISAS
3963 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3964 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3971 #if defined MIPS_DEBUG_DISAS
3972 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3973 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
3977 generate_exception(ctx
, EXCP_RI
);
3980 #if defined(TARGET_MIPS64)
3981 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
3983 const char *rn
= "invalid";
3986 check_insn(env
, ctx
, ISA_MIPS64
);
3992 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Index
));
3996 check_insn(env
, ctx
, ASE_MT
);
3997 tcg_gen_helper_1_1(do_mfc0_mvpcontrol
, cpu_T
[0], cpu_T
[0]);
4001 check_insn(env
, ctx
, ASE_MT
);
4002 tcg_gen_helper_1_1(do_mfc0_mvpconf0
, cpu_T
[0], cpu_T
[0]);
4006 check_insn(env
, ctx
, ASE_MT
);
4007 tcg_gen_helper_1_1(do_mfc0_mvpconf1
, cpu_T
[0], cpu_T
[0]);
4017 tcg_gen_helper_1_1(do_mfc0_random
, cpu_T
[0], cpu_T
[0]);
4021 check_insn(env
, ctx
, ASE_MT
);
4022 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEControl
));
4026 check_insn(env
, ctx
, ASE_MT
);
4027 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf0
));
4031 check_insn(env
, ctx
, ASE_MT
);
4032 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEConf1
));
4036 check_insn(env
, ctx
, ASE_MT
);
4037 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4041 check_insn(env
, ctx
, ASE_MT
);
4042 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4046 check_insn(env
, ctx
, ASE_MT
);
4047 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4048 rn
= "VPEScheFBack";
4051 check_insn(env
, ctx
, ASE_MT
);
4052 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_VPEOpt
));
4062 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4066 check_insn(env
, ctx
, ASE_MT
);
4067 tcg_gen_helper_1_1(do_mfc0_tcstatus
, cpu_T
[0], cpu_T
[0]);
4071 check_insn(env
, ctx
, ASE_MT
);
4072 tcg_gen_helper_1_1(do_mfc0_tcbind
, cpu_T
[0], cpu_T
[0]);
4076 check_insn(env
, ctx
, ASE_MT
);
4077 tcg_gen_helper_1_1(do_dmfc0_tcrestart
, cpu_T
[0], cpu_T
[0]);
4081 check_insn(env
, ctx
, ASE_MT
);
4082 tcg_gen_helper_1_1(do_dmfc0_tchalt
, cpu_T
[0], cpu_T
[0]);
4086 check_insn(env
, ctx
, ASE_MT
);
4087 tcg_gen_helper_1_1(do_dmfc0_tccontext
, cpu_T
[0], cpu_T
[0]);
4091 check_insn(env
, ctx
, ASE_MT
);
4092 tcg_gen_helper_1_1(do_dmfc0_tcschedule
, cpu_T
[0], cpu_T
[0]);
4096 check_insn(env
, ctx
, ASE_MT
);
4097 tcg_gen_helper_1_1(do_dmfc0_tcschefback
, cpu_T
[0], cpu_T
[0]);
4107 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4117 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_Context
));
4121 // tcg_gen_helper_1_1(do_dmfc0_contextconfig, cpu_T[0], cpu_T[0]); /* SmartMIPS ASE */
4122 rn
= "ContextConfig";
4131 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageMask
));
4135 check_insn(env
, ctx
, ISA_MIPS32R2
);
4136 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PageGrain
));
4146 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Wired
));
4150 check_insn(env
, ctx
, ISA_MIPS32R2
);
4151 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf0
));
4155 check_insn(env
, ctx
, ISA_MIPS32R2
);
4156 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf1
));
4160 check_insn(env
, ctx
, ISA_MIPS32R2
);
4161 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf2
));
4165 check_insn(env
, ctx
, ISA_MIPS32R2
);
4166 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf3
));
4170 check_insn(env
, ctx
, ISA_MIPS32R2
);
4171 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSConf4
));
4181 check_insn(env
, ctx
, ISA_MIPS32R2
);
4182 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_HWREna
));
4192 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4202 tcg_gen_helper_1_1(do_mfc0_count
, cpu_T
[0], cpu_T
[0]);
4205 /* 6,7 are implementation dependent */
4213 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4223 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Compare
));
4226 /* 6,7 are implementation dependent */
4234 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Status
));
4238 check_insn(env
, ctx
, ISA_MIPS32R2
);
4239 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_IntCtl
));
4243 check_insn(env
, ctx
, ISA_MIPS32R2
);
4244 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSCtl
));
4248 check_insn(env
, ctx
, ISA_MIPS32R2
);
4249 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
4259 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Cause
));
4269 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EPC
));
4279 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_PRid
));
4283 check_insn(env
, ctx
, ISA_MIPS32R2
);
4284 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_EBase
));
4294 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config0
));
4298 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config1
));
4302 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config2
));
4306 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config3
));
4309 /* 6,7 are implementation dependent */
4311 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config6
));
4315 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Config7
));
4325 tcg_gen_helper_1_1(do_dmfc0_lladdr
, cpu_T
[0], cpu_T
[0]);
4335 tcg_gen_helper_1_1i(do_dmfc0_watchlo
, cpu_T
[0], cpu_T
[0], sel
);
4345 tcg_gen_helper_1_1i(do_mfc0_watchhi
, cpu_T
[0], cpu_T
[0], sel
);
4355 check_insn(env
, ctx
, ISA_MIPS3
);
4356 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_XContext
));
4364 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4367 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Framemask
));
4376 rn
= "'Diagnostic"; /* implementation dependent */
4381 tcg_gen_helper_1_1(do_mfc0_debug
, cpu_T
[0], cpu_T
[0]); /* EJTAG support */
4385 // tcg_gen_helper_1_1(do_dmfc0_tracecontrol, cpu_T[0], cpu_T[0]); /* PDtrace support */
4386 rn
= "TraceControl";
4389 // tcg_gen_helper_1_1(do_dmfc0_tracecontrol2, cpu_T[0], cpu_T[0]); /* PDtrace support */
4390 rn
= "TraceControl2";
4393 // tcg_gen_helper_1_1(do_dmfc0_usertracedata, cpu_T[0], cpu_T[0]); /* PDtrace support */
4394 rn
= "UserTraceData";
4397 // tcg_gen_helper_1_1(do_dmfc0_tracebpc, cpu_T[0], cpu_T[0]); /* PDtrace support */
4408 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4418 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_Performance0
));
4419 rn
= "Performance0";
4422 // tcg_gen_helper_1_1(do_dmfc0_performance1, cpu_T[0], cpu_T[0]);
4423 rn
= "Performance1";
4426 // tcg_gen_helper_1_1(do_dmfc0_performance2, cpu_T[0], cpu_T[0]);
4427 rn
= "Performance2";
4430 // tcg_gen_helper_1_1(do_dmfc0_performance3, cpu_T[0], cpu_T[0]);
4431 rn
= "Performance3";
4434 // tcg_gen_helper_1_1(do_dmfc0_performance4, cpu_T[0], cpu_T[0]);
4435 rn
= "Performance4";
4438 // tcg_gen_helper_1_1(do_dmfc0_performance5, cpu_T[0], cpu_T[0]);
4439 rn
= "Performance5";
4442 // tcg_gen_helper_1_1(do_dmfc0_performance6, cpu_T[0], cpu_T[0]);
4443 rn
= "Performance6";
4446 // tcg_gen_helper_1_1(do_dmfc0_performance7, cpu_T[0], cpu_T[0]);
4447 rn
= "Performance7";
4472 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagLo
));
4479 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataLo
));
4492 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_TagHi
));
4499 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DataHi
));
4509 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4520 gen_mfc0_load32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
4530 #if defined MIPS_DEBUG_DISAS
4531 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4532 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4539 #if defined MIPS_DEBUG_DISAS
4540 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4541 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4545 generate_exception(ctx
, EXCP_RI
);
4548 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, int reg
, int sel
)
4550 const char *rn
= "invalid";
4553 check_insn(env
, ctx
, ISA_MIPS64
);
4559 tcg_gen_helper_0_1(do_mtc0_index
, cpu_T
[0]);
4563 check_insn(env
, ctx
, ASE_MT
);
4564 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, cpu_T
[0]);
4568 check_insn(env
, ctx
, ASE_MT
);
4573 check_insn(env
, ctx
, ASE_MT
);
4588 check_insn(env
, ctx
, ASE_MT
);
4589 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, cpu_T
[0]);
4593 check_insn(env
, ctx
, ASE_MT
);
4594 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, cpu_T
[0]);
4598 check_insn(env
, ctx
, ASE_MT
);
4599 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, cpu_T
[0]);
4603 check_insn(env
, ctx
, ASE_MT
);
4604 tcg_gen_helper_0_1(do_mtc0_yqmask
, cpu_T
[0]);
4608 check_insn(env
, ctx
, ASE_MT
);
4609 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4613 check_insn(env
, ctx
, ASE_MT
);
4614 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4615 rn
= "VPEScheFBack";
4618 check_insn(env
, ctx
, ASE_MT
);
4619 tcg_gen_helper_0_1(do_mtc0_vpeopt
, cpu_T
[0]);
4629 tcg_gen_helper_0_1(do_mtc0_entrylo0
, cpu_T
[0]);
4633 check_insn(env
, ctx
, ASE_MT
);
4634 tcg_gen_helper_0_1(do_mtc0_tcstatus
, cpu_T
[0]);
4638 check_insn(env
, ctx
, ASE_MT
);
4639 tcg_gen_helper_0_1(do_mtc0_tcbind
, cpu_T
[0]);
4643 check_insn(env
, ctx
, ASE_MT
);
4644 tcg_gen_helper_0_1(do_mtc0_tcrestart
, cpu_T
[0]);
4648 check_insn(env
, ctx
, ASE_MT
);
4649 tcg_gen_helper_0_1(do_mtc0_tchalt
, cpu_T
[0]);
4653 check_insn(env
, ctx
, ASE_MT
);
4654 tcg_gen_helper_0_1(do_mtc0_tccontext
, cpu_T
[0]);
4658 check_insn(env
, ctx
, ASE_MT
);
4659 tcg_gen_helper_0_1(do_mtc0_tcschedule
, cpu_T
[0]);
4663 check_insn(env
, ctx
, ASE_MT
);
4664 tcg_gen_helper_0_1(do_mtc0_tcschefback
, cpu_T
[0]);
4674 tcg_gen_helper_0_1(do_mtc0_entrylo1
, cpu_T
[0]);
4684 tcg_gen_helper_0_1(do_mtc0_context
, cpu_T
[0]);
4688 // tcg_gen_helper_0_1(do_mtc0_contextconfig, cpu_T[0]); /* SmartMIPS ASE */
4689 rn
= "ContextConfig";
4698 tcg_gen_helper_0_1(do_mtc0_pagemask
, cpu_T
[0]);
4702 check_insn(env
, ctx
, ISA_MIPS32R2
);
4703 tcg_gen_helper_0_1(do_mtc0_pagegrain
, cpu_T
[0]);
4713 tcg_gen_helper_0_1(do_mtc0_wired
, cpu_T
[0]);
4717 check_insn(env
, ctx
, ISA_MIPS32R2
);
4718 tcg_gen_helper_0_1(do_mtc0_srsconf0
, cpu_T
[0]);
4722 check_insn(env
, ctx
, ISA_MIPS32R2
);
4723 tcg_gen_helper_0_1(do_mtc0_srsconf1
, cpu_T
[0]);
4727 check_insn(env
, ctx
, ISA_MIPS32R2
);
4728 tcg_gen_helper_0_1(do_mtc0_srsconf2
, cpu_T
[0]);
4732 check_insn(env
, ctx
, ISA_MIPS32R2
);
4733 tcg_gen_helper_0_1(do_mtc0_srsconf3
, cpu_T
[0]);
4737 check_insn(env
, ctx
, ISA_MIPS32R2
);
4738 tcg_gen_helper_0_1(do_mtc0_srsconf4
, cpu_T
[0]);
4748 check_insn(env
, ctx
, ISA_MIPS32R2
);
4749 tcg_gen_helper_0_1(do_mtc0_hwrena
, cpu_T
[0]);
4763 tcg_gen_helper_0_1(do_mtc0_count
, cpu_T
[0]);
4766 /* 6,7 are implementation dependent */
4770 /* Stop translation as we may have switched the execution mode */
4771 ctx
->bstate
= BS_STOP
;
4776 tcg_gen_helper_0_1(do_mtc0_entryhi
, cpu_T
[0]);
4786 tcg_gen_helper_0_1(do_mtc0_compare
, cpu_T
[0]);
4789 /* 6,7 are implementation dependent */
4793 /* Stop translation as we may have switched the execution mode */
4794 ctx
->bstate
= BS_STOP
;
4799 tcg_gen_helper_0_1(do_mtc0_status
, cpu_T
[0]);
4800 /* BS_STOP isn't good enough here, hflags may have changed. */
4801 gen_save_pc(ctx
->pc
+ 4);
4802 ctx
->bstate
= BS_EXCP
;
4806 check_insn(env
, ctx
, ISA_MIPS32R2
);
4807 tcg_gen_helper_0_1(do_mtc0_intctl
, cpu_T
[0]);
4808 /* Stop translation as we may have switched the execution mode */
4809 ctx
->bstate
= BS_STOP
;
4813 check_insn(env
, ctx
, ISA_MIPS32R2
);
4814 tcg_gen_helper_0_1(do_mtc0_srsctl
, cpu_T
[0]);
4815 /* Stop translation as we may have switched the execution mode */
4816 ctx
->bstate
= BS_STOP
;
4820 check_insn(env
, ctx
, ISA_MIPS32R2
);
4821 gen_mtc0_store32(cpu_T
[0], offsetof(CPUState
, CP0_SRSMap
));
4822 /* Stop translation as we may have switched the execution mode */
4823 ctx
->bstate
= BS_STOP
;
4833 tcg_gen_helper_0_1(do_mtc0_cause
, cpu_T
[0]);
4839 /* Stop translation as we may have switched the execution mode */
4840 ctx
->bstate
= BS_STOP
;
4845 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_EPC
));
4859 check_insn(env
, ctx
, ISA_MIPS32R2
);
4860 tcg_gen_helper_0_1(do_mtc0_ebase
, cpu_T
[0]);
4870 tcg_gen_helper_0_1(do_mtc0_config0
, cpu_T
[0]);
4872 /* Stop translation as we may have switched the execution mode */
4873 ctx
->bstate
= BS_STOP
;
4880 tcg_gen_helper_0_1(do_mtc0_config2
, cpu_T
[0]);
4882 /* Stop translation as we may have switched the execution mode */
4883 ctx
->bstate
= BS_STOP
;
4889 /* 6,7 are implementation dependent */
4891 rn
= "Invalid config selector";
4908 tcg_gen_helper_0_1i(do_mtc0_watchlo
, cpu_T
[0], sel
);
4918 tcg_gen_helper_0_1i(do_mtc0_watchhi
, cpu_T
[0], sel
);
4928 check_insn(env
, ctx
, ISA_MIPS3
);
4929 tcg_gen_helper_0_1(do_mtc0_xcontext
, cpu_T
[0]);
4937 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4940 tcg_gen_helper_0_1(do_mtc0_framemask
, cpu_T
[0]);
4949 rn
= "Diagnostic"; /* implementation dependent */
4954 tcg_gen_helper_0_1(do_mtc0_debug
, cpu_T
[0]); /* EJTAG support */
4955 /* BS_STOP isn't good enough here, hflags may have changed. */
4956 gen_save_pc(ctx
->pc
+ 4);
4957 ctx
->bstate
= BS_EXCP
;
4961 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, cpu_T[0]); /* PDtrace support */
4962 /* Stop translation as we may have switched the execution mode */
4963 ctx
->bstate
= BS_STOP
;
4964 rn
= "TraceControl";
4967 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, cpu_T[0]); /* PDtrace support */
4968 /* Stop translation as we may have switched the execution mode */
4969 ctx
->bstate
= BS_STOP
;
4970 rn
= "TraceControl2";
4973 // tcg_gen_helper_0_1(do_mtc0_usertracedata, cpu_T[0]); /* PDtrace support */
4974 /* Stop translation as we may have switched the execution mode */
4975 ctx
->bstate
= BS_STOP
;
4976 rn
= "UserTraceData";
4979 // tcg_gen_helper_0_1(do_mtc0_tracebpc, cpu_T[0]); /* PDtrace support */
4980 /* Stop translation as we may have switched the execution mode */
4981 ctx
->bstate
= BS_STOP
;
4992 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5002 tcg_gen_helper_0_1(do_mtc0_performance0
, cpu_T
[0]);
5003 rn
= "Performance0";
5006 // tcg_gen_helper_0_1(do_mtc0_performance1, cpu_T[0]);
5007 rn
= "Performance1";
5010 // tcg_gen_helper_0_1(do_mtc0_performance2, cpu_T[0]);
5011 rn
= "Performance2";
5014 // tcg_gen_helper_0_1(do_mtc0_performance3, cpu_T[0]);
5015 rn
= "Performance3";
5018 // tcg_gen_helper_0_1(do_mtc0_performance4, cpu_T[0]);
5019 rn
= "Performance4";
5022 // tcg_gen_helper_0_1(do_mtc0_performance5, cpu_T[0]);
5023 rn
= "Performance5";
5026 // tcg_gen_helper_0_1(do_mtc0_performance6, cpu_T[0]);
5027 rn
= "Performance6";
5030 // tcg_gen_helper_0_1(do_mtc0_performance7, cpu_T[0]);
5031 rn
= "Performance7";
5057 tcg_gen_helper_0_1(do_mtc0_taglo
, cpu_T
[0]);
5064 tcg_gen_helper_0_1(do_mtc0_datalo
, cpu_T
[0]);
5077 tcg_gen_helper_0_1(do_mtc0_taghi
, cpu_T
[0]);
5084 tcg_gen_helper_0_1(do_mtc0_datahi
, cpu_T
[0]);
5095 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5106 gen_mtc0_store32(cpu_T
[0], offsetof(CPUState
, CP0_DESAVE
));
5112 /* Stop translation as we may have switched the execution mode */
5113 ctx
->bstate
= BS_STOP
;
5118 #if defined MIPS_DEBUG_DISAS
5119 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5120 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5127 #if defined MIPS_DEBUG_DISAS
5128 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5129 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5133 generate_exception(ctx
, EXCP_RI
);
5135 #endif /* TARGET_MIPS64 */
5137 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
,
5138 int u
, int sel
, int h
)
5140 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5142 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5143 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5144 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5145 tcg_gen_movi_tl(cpu_T
[0], -1);
5146 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5147 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5148 tcg_gen_movi_tl(cpu_T
[0], -1);
5154 tcg_gen_helper_1_1(do_mftc0_tcstatus
, cpu_T
[0], cpu_T
[0]);
5157 tcg_gen_helper_1_1(do_mftc0_tcbind
, cpu_T
[0], cpu_T
[0]);
5160 tcg_gen_helper_1_1(do_mftc0_tcrestart
, cpu_T
[0], cpu_T
[0]);
5163 tcg_gen_helper_1_1(do_mftc0_tchalt
, cpu_T
[0], cpu_T
[0]);
5166 tcg_gen_helper_1_1(do_mftc0_tccontext
, cpu_T
[0], cpu_T
[0]);
5169 tcg_gen_helper_1_1(do_mftc0_tcschedule
, cpu_T
[0], cpu_T
[0]);
5172 tcg_gen_helper_1_1(do_mftc0_tcschefback
, cpu_T
[0], cpu_T
[0]);
5175 gen_mfc0(env
, ctx
, rt
, sel
);
5182 tcg_gen_helper_1_1(do_mftc0_entryhi
, cpu_T
[0], cpu_T
[0]);
5185 gen_mfc0(env
, ctx
, rt
, sel
);
5191 tcg_gen_helper_1_1(do_mftc0_status
, cpu_T
[0], cpu_T
[0]);
5194 gen_mfc0(env
, ctx
, rt
, sel
);
5200 tcg_gen_helper_1_1(do_mftc0_debug
, cpu_T
[0], cpu_T
[0]);
5203 gen_mfc0(env
, ctx
, rt
, sel
);
5208 gen_mfc0(env
, ctx
, rt
, sel
);
5210 } else switch (sel
) {
5211 /* GPR registers. */
5213 tcg_gen_helper_1_1i(do_mftgpr
, cpu_T
[0], cpu_T
[0], rt
);
5215 /* Auxiliary CPU registers */
5219 tcg_gen_helper_1_1i(do_mftlo
, cpu_T
[0], cpu_T
[0], 0);
5222 tcg_gen_helper_1_1i(do_mfthi
, cpu_T
[0], cpu_T
[0], 0);
5225 tcg_gen_helper_1_1i(do_mftacx
, cpu_T
[0], cpu_T
[0], 0);
5228 tcg_gen_helper_1_1i(do_mftlo
, cpu_T
[0], cpu_T
[0], 1);
5231 tcg_gen_helper_1_1i(do_mfthi
, cpu_T
[0], cpu_T
[0], 1);
5234 tcg_gen_helper_1_1i(do_mftacx
, cpu_T
[0], cpu_T
[0], 1);
5237 tcg_gen_helper_1_1i(do_mftlo
, cpu_T
[0], cpu_T
[0], 2);
5240 tcg_gen_helper_1_1i(do_mfthi
, cpu_T
[0], cpu_T
[0], 2);
5243 tcg_gen_helper_1_1i(do_mftacx
, cpu_T
[0], cpu_T
[0], 2);
5246 tcg_gen_helper_1_1i(do_mftlo
, cpu_T
[0], cpu_T
[0], 3);
5249 tcg_gen_helper_1_1i(do_mfthi
, cpu_T
[0], cpu_T
[0], 3);
5252 tcg_gen_helper_1_1i(do_mftacx
, cpu_T
[0], cpu_T
[0], 3);
5255 tcg_gen_helper_1_1(do_mftdsp
, cpu_T
[0], cpu_T
[0]);
5261 /* Floating point (COP1). */
5263 /* XXX: For now we support only a single FPU context. */
5265 gen_load_fpr32(fpu32_T
[0], rt
);
5266 tcg_gen_ext_i32_tl(cpu_T
[0], fpu32_T
[0]);
5268 gen_load_fpr32h(fpu32h_T
[0], rt
);
5269 tcg_gen_ext_i32_tl(cpu_T
[0], fpu32h_T
[0]);
5273 /* XXX: For now we support only a single FPU context. */
5274 tcg_gen_helper_1_1i(do_cfc1
, cpu_T
[0], cpu_T
[0], rt
);
5276 /* COP2: Not implemented. */
5283 #if defined MIPS_DEBUG_DISAS
5284 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5285 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5292 #if defined MIPS_DEBUG_DISAS
5293 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5294 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5298 generate_exception(ctx
, EXCP_RI
);
5301 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
,
5302 int u
, int sel
, int h
)
5304 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5306 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5307 ((env
->CP0_TCBind
[other_tc
] & (0xf << CP0TCBd_CurVPE
)) !=
5308 (env
->CP0_TCBind
[env
->current_tc
] & (0xf << CP0TCBd_CurVPE
))))
5310 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5311 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5318 tcg_gen_helper_0_1(do_mttc0_tcstatus
, cpu_T
[0]);
5321 tcg_gen_helper_0_1(do_mttc0_tcbind
, cpu_T
[0]);
5324 tcg_gen_helper_0_1(do_mttc0_tcrestart
, cpu_T
[0]);
5327 tcg_gen_helper_0_1(do_mttc0_tchalt
, cpu_T
[0]);
5330 tcg_gen_helper_0_1(do_mttc0_tccontext
, cpu_T
[0]);
5333 tcg_gen_helper_0_1(do_mttc0_tcschedule
, cpu_T
[0]);
5336 tcg_gen_helper_0_1(do_mttc0_tcschefback
, cpu_T
[0]);
5339 gen_mtc0(env
, ctx
, rd
, sel
);
5346 tcg_gen_helper_0_1(do_mttc0_entryhi
, cpu_T
[0]);
5349 gen_mtc0(env
, ctx
, rd
, sel
);
5355 tcg_gen_helper_0_1(do_mttc0_status
, cpu_T
[0]);
5358 gen_mtc0(env
, ctx
, rd
, sel
);
5364 tcg_gen_helper_0_1(do_mttc0_debug
, cpu_T
[0]);
5367 gen_mtc0(env
, ctx
, rd
, sel
);
5372 gen_mtc0(env
, ctx
, rd
, sel
);
5374 } else switch (sel
) {
5375 /* GPR registers. */
5377 tcg_gen_helper_0_1i(do_mttgpr
, cpu_T
[0], rd
);
5379 /* Auxiliary CPU registers */
5383 tcg_gen_helper_0_1i(do_mttlo
, cpu_T
[0], 0);
5386 tcg_gen_helper_0_1i(do_mtthi
, cpu_T
[0], 0);
5389 tcg_gen_helper_0_1i(do_mttacx
, cpu_T
[0], 0);
5392 tcg_gen_helper_0_1i(do_mttlo
, cpu_T
[0], 1);
5395 tcg_gen_helper_0_1i(do_mtthi
, cpu_T
[0], 1);
5398 tcg_gen_helper_0_1i(do_mttacx
, cpu_T
[0], 1);
5401 tcg_gen_helper_0_1i(do_mttlo
, cpu_T
[0], 2);
5404 tcg_gen_helper_0_1i(do_mtthi
, cpu_T
[0], 2);
5407 tcg_gen_helper_0_1i(do_mttacx
, cpu_T
[0], 2);
5410 tcg_gen_helper_0_1i(do_mttlo
, cpu_T
[0], 3);
5413 tcg_gen_helper_0_1i(do_mtthi
, cpu_T
[0], 3);
5416 tcg_gen_helper_0_1i(do_mttacx
, cpu_T
[0], 3);
5419 tcg_gen_helper_0_1(do_mttdsp
, cpu_T
[0]);
5425 /* Floating point (COP1). */
5427 /* XXX: For now we support only a single FPU context. */
5429 tcg_gen_trunc_tl_i32(fpu32_T
[0], cpu_T
[0]);
5430 gen_store_fpr32(fpu32_T
[0], rd
);
5432 tcg_gen_trunc_tl_i32(fpu32h_T
[0], cpu_T
[0]);
5433 gen_store_fpr32h(fpu32h_T
[0], rd
);
5437 /* XXX: For now we support only a single FPU context. */
5438 tcg_gen_helper_0_1i(do_ctc1
, cpu_T
[0], rd
);
5440 /* COP2: Not implemented. */
5447 #if defined MIPS_DEBUG_DISAS
5448 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5449 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5456 #if defined MIPS_DEBUG_DISAS
5457 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5458 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5462 generate_exception(ctx
, EXCP_RI
);
5465 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5467 const char *opn
= "ldst";
5475 gen_mfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5476 gen_store_gpr(cpu_T
[0], rt
);
5480 gen_load_gpr(cpu_T
[0], rt
);
5481 save_cpu_state(ctx
, 1);
5482 gen_mtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5485 #if defined(TARGET_MIPS64)
5487 check_insn(env
, ctx
, ISA_MIPS3
);
5492 gen_dmfc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5493 gen_store_gpr(cpu_T
[0], rt
);
5497 check_insn(env
, ctx
, ISA_MIPS3
);
5498 gen_load_gpr(cpu_T
[0], rt
);
5499 save_cpu_state(ctx
, 1);
5500 gen_dmtc0(env
, ctx
, rd
, ctx
->opcode
& 0x7);
5505 check_insn(env
, ctx
, ASE_MT
);
5510 gen_mftr(env
, ctx
, rt
, (ctx
->opcode
>> 5) & 1,
5511 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5512 gen_store_gpr(cpu_T
[0], rd
);
5516 check_insn(env
, ctx
, ASE_MT
);
5517 gen_load_gpr(cpu_T
[0], rt
);
5518 gen_mttr(env
, ctx
, rd
, (ctx
->opcode
>> 5) & 1,
5519 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5524 if (!env
->tlb
->do_tlbwi
)
5526 tcg_gen_helper_0_0(env
->tlb
->do_tlbwi
);
5530 if (!env
->tlb
->do_tlbwr
)
5532 tcg_gen_helper_0_0(env
->tlb
->do_tlbwr
);
5536 if (!env
->tlb
->do_tlbp
)
5538 tcg_gen_helper_0_0(env
->tlb
->do_tlbp
);
5542 if (!env
->tlb
->do_tlbr
)
5544 tcg_gen_helper_0_0(env
->tlb
->do_tlbr
);
5548 check_insn(env
, ctx
, ISA_MIPS2
);
5549 save_cpu_state(ctx
, 1);
5550 tcg_gen_helper_0_1(do_eret
, cpu_T
[0]);
5551 ctx
->bstate
= BS_EXCP
;
5555 check_insn(env
, ctx
, ISA_MIPS32
);
5556 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5558 generate_exception(ctx
, EXCP_RI
);
5560 save_cpu_state(ctx
, 1);
5561 tcg_gen_helper_0_1(do_deret
, cpu_T
[0]);
5562 ctx
->bstate
= BS_EXCP
;
5567 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5568 /* If we get an exception, we want to restart at next instruction */
5570 save_cpu_state(ctx
, 1);
5572 tcg_gen_helper_0_0(do_wait
);
5573 ctx
->bstate
= BS_EXCP
;
5578 generate_exception(ctx
, EXCP_RI
);
5581 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5583 #endif /* !CONFIG_USER_ONLY */
5585 /* CP1 Branches (before delay slot) */
5586 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5587 int32_t cc
, int32_t offset
)
5589 target_ulong btarget
;
5590 const char *opn
= "cp1 cond branch";
5593 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5595 btarget
= ctx
->pc
+ 4 + offset
;
5600 int l1
= gen_new_label();
5601 int l2
= gen_new_label();
5602 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5604 get_fp_cond(r_tmp1
);
5605 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5606 tcg_temp_free(r_tmp1
);
5607 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
5608 tcg_gen_movi_tl(cpu_T
[1], 0x1 << cc
);
5609 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5610 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5611 tcg_gen_movi_tl(cpu_T
[0], 0);
5614 tcg_gen_movi_tl(cpu_T
[0], 1);
5621 int l1
= gen_new_label();
5622 int l2
= gen_new_label();
5623 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5625 get_fp_cond(r_tmp1
);
5626 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5627 tcg_temp_free(r_tmp1
);
5628 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
5629 tcg_gen_movi_tl(cpu_T
[1], 0x1 << cc
);
5630 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5631 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5632 tcg_gen_movi_tl(cpu_T
[0], 0);
5635 tcg_gen_movi_tl(cpu_T
[0], 1);
5642 int l1
= gen_new_label();
5643 int l2
= gen_new_label();
5644 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5646 get_fp_cond(r_tmp1
);
5647 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5648 tcg_temp_free(r_tmp1
);
5649 tcg_gen_movi_tl(cpu_T
[1], 0x1 << cc
);
5650 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5651 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5652 tcg_gen_movi_tl(cpu_T
[0], 0);
5655 tcg_gen_movi_tl(cpu_T
[0], 1);
5662 int l1
= gen_new_label();
5663 int l2
= gen_new_label();
5664 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5666 get_fp_cond(r_tmp1
);
5667 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5668 tcg_temp_free(r_tmp1
);
5669 tcg_gen_movi_tl(cpu_T
[1], 0x1 << cc
);
5670 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5671 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5672 tcg_gen_movi_tl(cpu_T
[0], 0);
5675 tcg_gen_movi_tl(cpu_T
[0], 1);
5680 ctx
->hflags
|= MIPS_HFLAG_BL
;
5681 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5685 int l1
= gen_new_label();
5686 int l2
= gen_new_label();
5687 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5689 get_fp_cond(r_tmp1
);
5690 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5691 tcg_temp_free(r_tmp1
);
5692 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
5693 tcg_gen_movi_tl(cpu_T
[1], 0x3 << cc
);
5694 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5695 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5696 tcg_gen_movi_tl(cpu_T
[0], 0);
5699 tcg_gen_movi_tl(cpu_T
[0], 1);
5706 int l1
= gen_new_label();
5707 int l2
= gen_new_label();
5708 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5710 get_fp_cond(r_tmp1
);
5711 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5712 tcg_temp_free(r_tmp1
);
5713 tcg_gen_movi_tl(cpu_T
[1], 0x3 << cc
);
5714 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5715 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5716 tcg_gen_movi_tl(cpu_T
[0], 0);
5719 tcg_gen_movi_tl(cpu_T
[0], 1);
5726 int l1
= gen_new_label();
5727 int l2
= gen_new_label();
5728 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5730 get_fp_cond(r_tmp1
);
5731 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5732 tcg_temp_free(r_tmp1
);
5733 tcg_gen_not_tl(cpu_T
[0], cpu_T
[0]);
5734 tcg_gen_movi_tl(cpu_T
[1], 0xf << cc
);
5735 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5736 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5737 tcg_gen_movi_tl(cpu_T
[0], 0);
5740 tcg_gen_movi_tl(cpu_T
[0], 1);
5747 int l1
= gen_new_label();
5748 int l2
= gen_new_label();
5749 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5751 get_fp_cond(r_tmp1
);
5752 tcg_gen_ext_i32_tl(cpu_T
[0], r_tmp1
);
5753 tcg_temp_free(r_tmp1
);
5754 tcg_gen_movi_tl(cpu_T
[1], 0xf << cc
);
5755 tcg_gen_and_tl(cpu_T
[0], cpu_T
[0], cpu_T
[1]);
5756 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
5757 tcg_gen_movi_tl(cpu_T
[0], 0);
5760 tcg_gen_movi_tl(cpu_T
[0], 1);
5765 ctx
->hflags
|= MIPS_HFLAG_BC
;
5766 tcg_gen_st_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, bcond
));
5770 generate_exception (ctx
, EXCP_RI
);
5773 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5774 ctx
->hflags
, btarget
);
5775 ctx
->btarget
= btarget
;
5778 /* Coprocessor 1 (FPU) */
5780 #define FOP(func, fmt) (((fmt) << 21) | (func))
5782 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5784 const char *opn
= "cp1 move";
5788 gen_load_fpr32(fpu32_T
[0], fs
);
5789 tcg_gen_ext_i32_tl(cpu_T
[0], fpu32_T
[0]);
5790 gen_store_gpr(cpu_T
[0], rt
);
5794 gen_load_gpr(cpu_T
[0], rt
);
5795 tcg_gen_trunc_tl_i32(fpu32_T
[0], cpu_T
[0]);
5796 gen_store_fpr32(fpu32_T
[0], fs
);
5800 tcg_gen_helper_1_1i(do_cfc1
, cpu_T
[0], cpu_T
[0], fs
);
5801 gen_store_gpr(cpu_T
[0], rt
);
5805 gen_load_gpr(cpu_T
[0], rt
);
5806 tcg_gen_helper_0_1i(do_ctc1
, cpu_T
[0], fs
);
5810 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
5811 tcg_gen_mov_tl(cpu_T
[0], fpu64_T
[0]);
5812 gen_store_gpr(cpu_T
[0], rt
);
5816 gen_load_gpr(cpu_T
[0], rt
);
5817 tcg_gen_mov_tl(fpu64_T
[0], cpu_T
[0]);
5818 gen_store_fpr64(ctx
, fpu64_T
[0], fs
);
5822 gen_load_fpr32h(fpu32h_T
[0], fs
);
5823 tcg_gen_ext_i32_tl(cpu_T
[0], fpu32h_T
[0]);
5824 gen_store_gpr(cpu_T
[0], rt
);
5828 gen_load_gpr(cpu_T
[0], rt
);
5829 tcg_gen_trunc_tl_i32(fpu32h_T
[0], cpu_T
[0]);
5830 gen_store_fpr32h(fpu32h_T
[0], fs
);
5835 generate_exception (ctx
, EXCP_RI
);
5838 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5841 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5843 int l1
= gen_new_label();
5848 ccbit
= 1 << (24 + cc
);
5856 gen_load_gpr(cpu_T
[0], rd
);
5857 gen_load_gpr(cpu_T
[1], rs
);
5859 TCGv r_ptr
= tcg_temp_new(TCG_TYPE_PTR
);
5860 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
5862 tcg_gen_ld_ptr(r_ptr
, cpu_env
, offsetof(CPUState
, fpu
));
5863 tcg_gen_ld_i32(r_tmp
, r_ptr
, offsetof(CPUMIPSFPUContext
, fcr31
));
5864 tcg_temp_free(r_ptr
);
5865 tcg_gen_andi_i32(r_tmp
, r_tmp
, ccbit
);
5866 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
5867 tcg_temp_free(r_tmp
);
5869 tcg_gen_mov_tl(cpu_T
[0], cpu_T
[1]);
5872 gen_store_gpr(cpu_T
[0], rd
);
5875 static inline void gen_movcf_s (int cc
, int tf
)
5879 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5880 int l1
= gen_new_label();
5883 ccbit
= 1 << (24 + cc
);
5892 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
5893 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
5894 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5895 tcg_gen_movi_i32(fpu32_T
[2], fpu32_T
[0]);
5897 tcg_temp_free(r_tmp1
);
5900 static inline void gen_movcf_d (int cc
, int tf
)
5904 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5905 int l1
= gen_new_label();
5908 ccbit
= 1 << (24 + cc
);
5917 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
5918 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
5919 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5920 tcg_gen_movi_i64(fpu64_T
[2], fpu64_T
[0]);
5922 tcg_temp_free(r_tmp1
);
5925 static inline void gen_movcf_ps (int cc
, int tf
)
5928 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_I32
);
5929 TCGv r_tmp2
= tcg_temp_local_new(TCG_TYPE_I32
);
5930 int l1
= gen_new_label();
5931 int l2
= gen_new_label();
5938 get_fp_cond(r_tmp1
);
5939 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, cc
);
5940 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x1);
5941 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l1
);
5942 tcg_gen_movi_i32(fpu32_T
[2], fpu32_T
[0]);
5944 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x2);
5945 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l2
);
5946 tcg_gen_movi_i32(fpu32h_T
[2], fpu32h_T
[0]);
5948 tcg_temp_free(r_tmp1
);
5949 tcg_temp_free(r_tmp2
);
5953 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5954 int ft
, int fs
, int fd
, int cc
)
5956 const char *opn
= "farith";
5957 const char *condnames
[] = {
5975 const char *condnames_abs
[] = {
5993 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5994 uint32_t func
= ctx
->opcode
& 0x3f;
5996 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5998 gen_load_fpr32(fpu32_T
[0], fs
);
5999 gen_load_fpr32(fpu32_T
[1], ft
);
6000 tcg_gen_helper_0_0(do_float_add_s
);
6001 gen_store_fpr32(fpu32_T
[2], fd
);
6006 gen_load_fpr32(fpu32_T
[0], fs
);
6007 gen_load_fpr32(fpu32_T
[1], ft
);
6008 tcg_gen_helper_0_0(do_float_sub_s
);
6009 gen_store_fpr32(fpu32_T
[2], fd
);
6014 gen_load_fpr32(fpu32_T
[0], fs
);
6015 gen_load_fpr32(fpu32_T
[1], ft
);
6016 tcg_gen_helper_0_0(do_float_mul_s
);
6017 gen_store_fpr32(fpu32_T
[2], fd
);
6022 gen_load_fpr32(fpu32_T
[0], fs
);
6023 gen_load_fpr32(fpu32_T
[1], ft
);
6024 tcg_gen_helper_0_0(do_float_div_s
);
6025 gen_store_fpr32(fpu32_T
[2], fd
);
6030 gen_load_fpr32(fpu32_T
[0], fs
);
6031 tcg_gen_helper_0_0(do_float_sqrt_s
);
6032 gen_store_fpr32(fpu32_T
[2], fd
);
6036 gen_load_fpr32(fpu32_T
[0], fs
);
6037 tcg_gen_helper_0_0(do_float_abs_s
);
6038 gen_store_fpr32(fpu32_T
[2], fd
);
6042 gen_load_fpr32(fpu32_T
[0], fs
);
6043 gen_store_fpr32(fpu32_T
[0], fd
);
6047 gen_load_fpr32(fpu32_T
[0], fs
);
6048 tcg_gen_helper_0_0(do_float_chs_s
);
6049 gen_store_fpr32(fpu32_T
[2], fd
);
6053 check_cp1_64bitmode(ctx
);
6054 gen_load_fpr32(fpu32_T
[0], fs
);
6055 tcg_gen_helper_0_0(do_float_roundl_s
);
6056 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6060 check_cp1_64bitmode(ctx
);
6061 gen_load_fpr32(fpu32_T
[0], fs
);
6062 tcg_gen_helper_0_0(do_float_truncl_s
);
6063 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6067 check_cp1_64bitmode(ctx
);
6068 gen_load_fpr32(fpu32_T
[0], fs
);
6069 tcg_gen_helper_0_0(do_float_ceill_s
);
6070 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6074 check_cp1_64bitmode(ctx
);
6075 gen_load_fpr32(fpu32_T
[0], fs
);
6076 tcg_gen_helper_0_0(do_float_floorl_s
);
6077 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6081 gen_load_fpr32(fpu32_T
[0], fs
);
6082 tcg_gen_helper_0_0(do_float_roundw_s
);
6083 gen_store_fpr32(fpu32_T
[2], fd
);
6087 gen_load_fpr32(fpu32_T
[0], fs
);
6088 tcg_gen_helper_0_0(do_float_truncw_s
);
6089 gen_store_fpr32(fpu32_T
[2], fd
);
6093 gen_load_fpr32(fpu32_T
[0], fs
);
6094 tcg_gen_helper_0_0(do_float_ceilw_s
);
6095 gen_store_fpr32(fpu32_T
[2], fd
);
6099 gen_load_fpr32(fpu32_T
[0], fs
);
6100 tcg_gen_helper_0_0(do_float_floorw_s
);
6101 gen_store_fpr32(fpu32_T
[2], fd
);
6105 gen_load_fpr32(fpu32_T
[0], fs
);
6106 gen_load_fpr32(fpu32_T
[2], fd
);
6107 gen_movcf_s((ft
>> 2) & 0x7, ft
& 0x1);
6108 gen_store_fpr32(fpu32_T
[2], fd
);
6112 gen_load_gpr(cpu_T
[0], ft
);
6113 gen_load_fpr32(fpu32_T
[0], fs
);
6114 gen_load_fpr32(fpu32_T
[2], fd
);
6116 int l1
= gen_new_label();
6118 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
6119 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6122 gen_store_fpr32(fpu32_T
[2], fd
);
6126 gen_load_gpr(cpu_T
[0], ft
);
6127 gen_load_fpr32(fpu32_T
[0], fs
);
6128 gen_load_fpr32(fpu32_T
[2], fd
);
6130 int l1
= gen_new_label();
6132 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
6133 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6136 gen_store_fpr32(fpu32_T
[2], fd
);
6141 gen_load_fpr32(fpu32_T
[0], fs
);
6142 tcg_gen_helper_0_0(do_float_recip_s
);
6143 gen_store_fpr32(fpu32_T
[2], fd
);
6148 gen_load_fpr32(fpu32_T
[0], fs
);
6149 tcg_gen_helper_0_0(do_float_rsqrt_s
);
6150 gen_store_fpr32(fpu32_T
[2], fd
);
6154 check_cp1_64bitmode(ctx
);
6155 gen_load_fpr32(fpu32_T
[0], fs
);
6156 gen_load_fpr32(fpu32_T
[2], fd
);
6157 tcg_gen_helper_0_0(do_float_recip2_s
);
6158 gen_store_fpr32(fpu32_T
[2], fd
);
6162 check_cp1_64bitmode(ctx
);
6163 gen_load_fpr32(fpu32_T
[0], fs
);
6164 tcg_gen_helper_0_0(do_float_recip1_s
);
6165 gen_store_fpr32(fpu32_T
[2], fd
);
6169 check_cp1_64bitmode(ctx
);
6170 gen_load_fpr32(fpu32_T
[0], fs
);
6171 tcg_gen_helper_0_0(do_float_rsqrt1_s
);
6172 gen_store_fpr32(fpu32_T
[2], fd
);
6176 check_cp1_64bitmode(ctx
);
6177 gen_load_fpr32(fpu32_T
[0], fs
);
6178 gen_load_fpr32(fpu32_T
[2], ft
);
6179 tcg_gen_helper_0_0(do_float_rsqrt2_s
);
6180 gen_store_fpr32(fpu32_T
[2], fd
);
6184 check_cp1_registers(ctx
, fd
);
6185 gen_load_fpr32(fpu32_T
[0], fs
);
6186 tcg_gen_helper_0_0(do_float_cvtd_s
);
6187 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6191 gen_load_fpr32(fpu32_T
[0], fs
);
6192 tcg_gen_helper_0_0(do_float_cvtw_s
);
6193 gen_store_fpr32(fpu32_T
[2], fd
);
6197 check_cp1_64bitmode(ctx
);
6198 gen_load_fpr32(fpu32_T
[0], fs
);
6199 tcg_gen_helper_0_0(do_float_cvtl_s
);
6200 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6204 check_cp1_64bitmode(ctx
);
6205 gen_load_fpr32(fpu32_T
[0], fs
);
6206 gen_load_fpr32(fpu32_T
[1], ft
);
6207 tcg_gen_extu_i32_i64(fpu64_T
[0], fpu32_T
[0]);
6208 tcg_gen_extu_i32_i64(fpu64_T
[1], fpu32_T
[1]);
6209 tcg_gen_shli_i64(fpu64_T
[1], fpu64_T
[1], 32);
6210 tcg_gen_or_i64(fpu64_T
[2], fpu64_T
[0], fpu64_T
[1]);
6211 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6230 gen_load_fpr32(fpu32_T
[0], fs
);
6231 gen_load_fpr32(fpu32_T
[1], ft
);
6232 if (ctx
->opcode
& (1 << 6)) {
6234 gen_cmpabs_s(func
-48, cc
);
6235 opn
= condnames_abs
[func
-48];
6237 gen_cmp_s(func
-48, cc
);
6238 opn
= condnames
[func
-48];
6242 check_cp1_registers(ctx
, fs
| ft
| fd
);
6243 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6244 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6245 tcg_gen_helper_0_0(do_float_add_d
);
6246 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6251 check_cp1_registers(ctx
, fs
| ft
| fd
);
6252 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6253 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6254 tcg_gen_helper_0_0(do_float_sub_d
);
6255 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6260 check_cp1_registers(ctx
, fs
| ft
| fd
);
6261 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6262 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6263 tcg_gen_helper_0_0(do_float_mul_d
);
6264 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6269 check_cp1_registers(ctx
, fs
| ft
| fd
);
6270 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6271 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6272 tcg_gen_helper_0_0(do_float_div_d
);
6273 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6278 check_cp1_registers(ctx
, fs
| fd
);
6279 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6280 tcg_gen_helper_0_0(do_float_sqrt_d
);
6281 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6285 check_cp1_registers(ctx
, fs
| fd
);
6286 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6287 tcg_gen_helper_0_0(do_float_abs_d
);
6288 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6292 check_cp1_registers(ctx
, fs
| fd
);
6293 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6294 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6298 check_cp1_registers(ctx
, fs
| fd
);
6299 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6300 tcg_gen_helper_0_0(do_float_chs_d
);
6301 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6305 check_cp1_64bitmode(ctx
);
6306 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6307 tcg_gen_helper_0_0(do_float_roundl_d
);
6308 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6312 check_cp1_64bitmode(ctx
);
6313 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6314 tcg_gen_helper_0_0(do_float_truncl_d
);
6315 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6319 check_cp1_64bitmode(ctx
);
6320 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6321 tcg_gen_helper_0_0(do_float_ceill_d
);
6322 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6326 check_cp1_64bitmode(ctx
);
6327 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6328 tcg_gen_helper_0_0(do_float_floorl_d
);
6329 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6333 check_cp1_registers(ctx
, fs
);
6334 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6335 tcg_gen_helper_0_0(do_float_roundw_d
);
6336 gen_store_fpr32(fpu32_T
[2], fd
);
6340 check_cp1_registers(ctx
, fs
);
6341 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6342 tcg_gen_helper_0_0(do_float_truncw_d
);
6343 gen_store_fpr32(fpu32_T
[2], fd
);
6347 check_cp1_registers(ctx
, fs
);
6348 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6349 tcg_gen_helper_0_0(do_float_ceilw_d
);
6350 gen_store_fpr32(fpu32_T
[2], fd
);
6354 check_cp1_registers(ctx
, fs
);
6355 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6356 tcg_gen_helper_0_0(do_float_floorw_d
);
6357 gen_store_fpr32(fpu32_T
[2], fd
);
6361 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6362 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6363 gen_movcf_d((ft
>> 2) & 0x7, ft
& 0x1);
6364 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6368 gen_load_gpr(cpu_T
[0], ft
);
6369 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6370 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6372 int l1
= gen_new_label();
6374 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
6375 tcg_gen_mov_i64(fpu64_T
[2], fpu64_T
[0]);
6378 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6382 gen_load_gpr(cpu_T
[0], ft
);
6383 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6384 gen_load_fpr64(ctx
, fpu64_T
[2], fd
);
6386 int l1
= gen_new_label();
6388 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
6389 tcg_gen_mov_i64(fpu64_T
[2], fpu64_T
[0]);
6392 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6396 check_cp1_64bitmode(ctx
);
6397 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6398 tcg_gen_helper_0_0(do_float_recip_d
);
6399 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6403 check_cp1_64bitmode(ctx
);
6404 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6405 tcg_gen_helper_0_0(do_float_rsqrt_d
);
6406 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6410 check_cp1_64bitmode(ctx
);
6411 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6412 gen_load_fpr64(ctx
, fpu64_T
[2], ft
);
6413 tcg_gen_helper_0_0(do_float_recip2_d
);
6414 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6418 check_cp1_64bitmode(ctx
);
6419 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6420 tcg_gen_helper_0_0(do_float_recip1_d
);
6421 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6425 check_cp1_64bitmode(ctx
);
6426 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6427 tcg_gen_helper_0_0(do_float_rsqrt1_d
);
6428 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6432 check_cp1_64bitmode(ctx
);
6433 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6434 gen_load_fpr64(ctx
, fpu64_T
[2], ft
);
6435 tcg_gen_helper_0_0(do_float_rsqrt2_d
);
6436 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6455 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6456 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6457 if (ctx
->opcode
& (1 << 6)) {
6459 check_cp1_registers(ctx
, fs
| ft
);
6460 gen_cmpabs_d(func
-48, cc
);
6461 opn
= condnames_abs
[func
-48];
6463 check_cp1_registers(ctx
, fs
| ft
);
6464 gen_cmp_d(func
-48, cc
);
6465 opn
= condnames
[func
-48];
6469 check_cp1_registers(ctx
, fs
);
6470 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6471 tcg_gen_helper_0_0(do_float_cvts_d
);
6472 gen_store_fpr32(fpu32_T
[2], fd
);
6476 check_cp1_registers(ctx
, fs
);
6477 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6478 tcg_gen_helper_0_0(do_float_cvtw_d
);
6479 gen_store_fpr32(fpu32_T
[2], fd
);
6483 check_cp1_64bitmode(ctx
);
6484 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6485 tcg_gen_helper_0_0(do_float_cvtl_d
);
6486 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6490 gen_load_fpr32(fpu32_T
[0], fs
);
6491 tcg_gen_helper_0_0(do_float_cvts_w
);
6492 gen_store_fpr32(fpu32_T
[2], fd
);
6496 check_cp1_registers(ctx
, fd
);
6497 gen_load_fpr32(fpu32_T
[0], fs
);
6498 tcg_gen_helper_0_0(do_float_cvtd_w
);
6499 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6503 check_cp1_64bitmode(ctx
);
6504 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6505 tcg_gen_helper_0_0(do_float_cvts_l
);
6506 gen_store_fpr32(fpu32_T
[2], fd
);
6510 check_cp1_64bitmode(ctx
);
6511 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6512 tcg_gen_helper_0_0(do_float_cvtd_l
);
6513 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6517 check_cp1_64bitmode(ctx
);
6518 gen_load_fpr32(fpu32_T
[0], fs
);
6519 gen_load_fpr32h(fpu32h_T
[0], fs
);
6520 tcg_gen_helper_0_0(do_float_cvtps_pw
);
6521 gen_store_fpr32(fpu32_T
[2], fd
);
6522 gen_store_fpr32h(fpu32h_T
[2], fd
);
6526 check_cp1_64bitmode(ctx
);
6527 gen_load_fpr32(fpu32_T
[0], fs
);
6528 gen_load_fpr32h(fpu32h_T
[0], fs
);
6529 gen_load_fpr32(fpu32_T
[1], ft
);
6530 gen_load_fpr32h(fpu32h_T
[1], ft
);
6531 tcg_gen_helper_0_0(do_float_add_ps
);
6532 gen_store_fpr32(fpu32_T
[2], fd
);
6533 gen_store_fpr32h(fpu32h_T
[2], fd
);
6537 check_cp1_64bitmode(ctx
);
6538 gen_load_fpr32(fpu32_T
[0], fs
);
6539 gen_load_fpr32h(fpu32h_T
[0], fs
);
6540 gen_load_fpr32(fpu32_T
[1], ft
);
6541 gen_load_fpr32h(fpu32h_T
[1], ft
);
6542 tcg_gen_helper_0_0(do_float_sub_ps
);
6543 gen_store_fpr32(fpu32_T
[2], fd
);
6544 gen_store_fpr32h(fpu32h_T
[2], fd
);
6548 check_cp1_64bitmode(ctx
);
6549 gen_load_fpr32(fpu32_T
[0], fs
);
6550 gen_load_fpr32h(fpu32h_T
[0], fs
);
6551 gen_load_fpr32(fpu32_T
[1], ft
);
6552 gen_load_fpr32h(fpu32h_T
[1], ft
);
6553 tcg_gen_helper_0_0(do_float_mul_ps
);
6554 gen_store_fpr32(fpu32_T
[2], fd
);
6555 gen_store_fpr32h(fpu32h_T
[2], fd
);
6559 check_cp1_64bitmode(ctx
);
6560 gen_load_fpr32(fpu32_T
[0], fs
);
6561 gen_load_fpr32h(fpu32h_T
[0], fs
);
6562 tcg_gen_helper_0_0(do_float_abs_ps
);
6563 gen_store_fpr32(fpu32_T
[2], fd
);
6564 gen_store_fpr32h(fpu32h_T
[2], fd
);
6568 check_cp1_64bitmode(ctx
);
6569 gen_load_fpr32(fpu32_T
[0], fs
);
6570 gen_load_fpr32h(fpu32h_T
[0], fs
);
6571 gen_store_fpr32(fpu32_T
[0], fd
);
6572 gen_store_fpr32h(fpu32h_T
[0], fd
);
6576 check_cp1_64bitmode(ctx
);
6577 gen_load_fpr32(fpu32_T
[0], fs
);
6578 gen_load_fpr32h(fpu32h_T
[0], fs
);
6579 tcg_gen_helper_0_0(do_float_chs_ps
);
6580 gen_store_fpr32(fpu32_T
[2], fd
);
6581 gen_store_fpr32h(fpu32h_T
[2], fd
);
6585 check_cp1_64bitmode(ctx
);
6586 gen_load_fpr32(fpu32_T
[0], fs
);
6587 gen_load_fpr32h(fpu32h_T
[0], fs
);
6588 gen_load_fpr32(fpu32_T
[2], fd
);
6589 gen_load_fpr32h(fpu32h_T
[2], fd
);
6590 gen_movcf_ps((ft
>> 2) & 0x7, ft
& 0x1);
6591 gen_store_fpr32(fpu32_T
[2], fd
);
6592 gen_store_fpr32h(fpu32h_T
[2], fd
);
6596 check_cp1_64bitmode(ctx
);
6597 gen_load_gpr(cpu_T
[0], ft
);
6598 gen_load_fpr32(fpu32_T
[0], fs
);
6599 gen_load_fpr32h(fpu32h_T
[0], fs
);
6600 gen_load_fpr32(fpu32_T
[2], fd
);
6601 gen_load_fpr32h(fpu32h_T
[2], fd
);
6603 int l1
= gen_new_label();
6605 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
6606 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6607 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
6610 gen_store_fpr32(fpu32_T
[2], fd
);
6611 gen_store_fpr32h(fpu32h_T
[2], fd
);
6615 check_cp1_64bitmode(ctx
);
6616 gen_load_gpr(cpu_T
[0], ft
);
6617 gen_load_fpr32(fpu32_T
[0], fs
);
6618 gen_load_fpr32h(fpu32h_T
[0], fs
);
6619 gen_load_fpr32(fpu32_T
[2], fd
);
6620 gen_load_fpr32h(fpu32h_T
[2], fd
);
6622 int l1
= gen_new_label();
6624 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_T
[0], 0, l1
);
6625 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6626 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
6629 gen_store_fpr32(fpu32_T
[2], fd
);
6630 gen_store_fpr32h(fpu32h_T
[2], fd
);
6634 check_cp1_64bitmode(ctx
);
6635 gen_load_fpr32(fpu32_T
[0], ft
);
6636 gen_load_fpr32h(fpu32h_T
[0], ft
);
6637 gen_load_fpr32(fpu32_T
[1], fs
);
6638 gen_load_fpr32h(fpu32h_T
[1], fs
);
6639 tcg_gen_helper_0_0(do_float_addr_ps
);
6640 gen_store_fpr32(fpu32_T
[2], fd
);
6641 gen_store_fpr32h(fpu32h_T
[2], fd
);
6645 check_cp1_64bitmode(ctx
);
6646 gen_load_fpr32(fpu32_T
[0], ft
);
6647 gen_load_fpr32h(fpu32h_T
[0], ft
);
6648 gen_load_fpr32(fpu32_T
[1], fs
);
6649 gen_load_fpr32h(fpu32h_T
[1], fs
);
6650 tcg_gen_helper_0_0(do_float_mulr_ps
);
6651 gen_store_fpr32(fpu32_T
[2], fd
);
6652 gen_store_fpr32h(fpu32h_T
[2], fd
);
6656 check_cp1_64bitmode(ctx
);
6657 gen_load_fpr32(fpu32_T
[0], fs
);
6658 gen_load_fpr32h(fpu32h_T
[0], fs
);
6659 gen_load_fpr32(fpu32_T
[2], fd
);
6660 gen_load_fpr32h(fpu32h_T
[2], fd
);
6661 tcg_gen_helper_0_0(do_float_recip2_ps
);
6662 gen_store_fpr32(fpu32_T
[2], fd
);
6663 gen_store_fpr32h(fpu32h_T
[2], fd
);
6667 check_cp1_64bitmode(ctx
);
6668 gen_load_fpr32(fpu32_T
[0], fs
);
6669 gen_load_fpr32h(fpu32h_T
[0], fs
);
6670 tcg_gen_helper_0_0(do_float_recip1_ps
);
6671 gen_store_fpr32(fpu32_T
[2], fd
);
6672 gen_store_fpr32h(fpu32h_T
[2], fd
);
6676 check_cp1_64bitmode(ctx
);
6677 gen_load_fpr32(fpu32_T
[0], fs
);
6678 gen_load_fpr32h(fpu32h_T
[0], fs
);
6679 tcg_gen_helper_0_0(do_float_rsqrt1_ps
);
6680 gen_store_fpr32(fpu32_T
[2], fd
);
6681 gen_store_fpr32h(fpu32h_T
[2], fd
);
6685 check_cp1_64bitmode(ctx
);
6686 gen_load_fpr32(fpu32_T
[0], fs
);
6687 gen_load_fpr32h(fpu32h_T
[0], fs
);
6688 gen_load_fpr32(fpu32_T
[2], ft
);
6689 gen_load_fpr32h(fpu32h_T
[2], ft
);
6690 tcg_gen_helper_0_0(do_float_rsqrt2_ps
);
6691 gen_store_fpr32(fpu32_T
[2], fd
);
6692 gen_store_fpr32h(fpu32h_T
[2], fd
);
6696 check_cp1_64bitmode(ctx
);
6697 gen_load_fpr32h(fpu32h_T
[0], fs
);
6698 tcg_gen_helper_0_0(do_float_cvts_pu
);
6699 gen_store_fpr32(fpu32_T
[2], fd
);
6703 check_cp1_64bitmode(ctx
);
6704 gen_load_fpr32(fpu32_T
[0], fs
);
6705 gen_load_fpr32h(fpu32h_T
[0], fs
);
6706 tcg_gen_helper_0_0(do_float_cvtpw_ps
);
6707 gen_store_fpr32(fpu32_T
[2], fd
);
6708 gen_store_fpr32h(fpu32h_T
[2], fd
);
6712 check_cp1_64bitmode(ctx
);
6713 gen_load_fpr32(fpu32_T
[0], fs
);
6714 tcg_gen_helper_0_0(do_float_cvts_pl
);
6715 gen_store_fpr32(fpu32_T
[2], fd
);
6719 check_cp1_64bitmode(ctx
);
6720 gen_load_fpr32(fpu32_T
[0], fs
);
6721 gen_load_fpr32(fpu32_T
[1], ft
);
6722 gen_store_fpr32h(fpu32_T
[0], fd
);
6723 gen_store_fpr32(fpu32_T
[1], fd
);
6727 check_cp1_64bitmode(ctx
);
6728 gen_load_fpr32(fpu32_T
[0], fs
);
6729 gen_load_fpr32h(fpu32h_T
[1], ft
);
6730 gen_store_fpr32(fpu32h_T
[1], fd
);
6731 gen_store_fpr32h(fpu32_T
[0], fd
);
6735 check_cp1_64bitmode(ctx
);
6736 gen_load_fpr32h(fpu32h_T
[0], fs
);
6737 gen_load_fpr32(fpu32_T
[1], ft
);
6738 gen_store_fpr32(fpu32_T
[1], fd
);
6739 gen_store_fpr32h(fpu32h_T
[0], fd
);
6743 check_cp1_64bitmode(ctx
);
6744 gen_load_fpr32h(fpu32h_T
[0], fs
);
6745 gen_load_fpr32h(fpu32h_T
[1], ft
);
6746 gen_store_fpr32(fpu32h_T
[1], fd
);
6747 gen_store_fpr32h(fpu32h_T
[0], fd
);
6766 check_cp1_64bitmode(ctx
);
6767 gen_load_fpr32(fpu32_T
[0], fs
);
6768 gen_load_fpr32h(fpu32h_T
[0], fs
);
6769 gen_load_fpr32(fpu32_T
[1], ft
);
6770 gen_load_fpr32h(fpu32h_T
[1], ft
);
6771 if (ctx
->opcode
& (1 << 6)) {
6772 gen_cmpabs_ps(func
-48, cc
);
6773 opn
= condnames_abs
[func
-48];
6775 gen_cmp_ps(func
-48, cc
);
6776 opn
= condnames
[func
-48];
6781 generate_exception (ctx
, EXCP_RI
);
6786 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
6789 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
6792 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
6797 /* Coprocessor 3 (FPU) */
6798 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
6799 int fd
, int fs
, int base
, int index
)
6801 const char *opn
= "extended float load/store";
6805 gen_load_gpr(cpu_T
[0], index
);
6806 } else if (index
== 0) {
6807 gen_load_gpr(cpu_T
[0], base
);
6809 gen_load_gpr(cpu_T
[0], base
);
6810 gen_load_gpr(cpu_T
[1], index
);
6811 gen_op_addr_add(cpu_T
[0], cpu_T
[1]);
6813 /* Don't do NOP if destination is zero: we must perform the actual
6818 tcg_gen_qemu_ld32s(fpu32_T
[0], cpu_T
[0], ctx
->mem_idx
);
6819 gen_store_fpr32(fpu32_T
[0], fd
);
6824 check_cp1_registers(ctx
, fd
);
6825 tcg_gen_qemu_ld64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
6826 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6830 check_cp1_64bitmode(ctx
);
6831 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], ~0x7);
6832 tcg_gen_qemu_ld64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
6833 gen_store_fpr64(ctx
, fpu64_T
[0], fd
);
6838 gen_load_fpr32(fpu32_T
[0], fs
);
6839 tcg_gen_qemu_st32(fpu32_T
[0], cpu_T
[0], ctx
->mem_idx
);
6845 check_cp1_registers(ctx
, fs
);
6846 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6847 tcg_gen_qemu_st64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
6852 check_cp1_64bitmode(ctx
);
6853 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6854 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], ~0x7);
6855 tcg_gen_qemu_st64(fpu64_T
[0], cpu_T
[0], ctx
->mem_idx
);
6861 generate_exception(ctx
, EXCP_RI
);
6864 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
6865 regnames
[index
], regnames
[base
]);
6868 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
6869 int fd
, int fr
, int fs
, int ft
)
6871 const char *opn
= "flt3_arith";
6875 check_cp1_64bitmode(ctx
);
6876 gen_load_gpr(cpu_T
[0], fr
);
6877 tcg_gen_andi_tl(cpu_T
[0], cpu_T
[0], 0x7);
6878 gen_load_fpr32(fpu32_T
[0], fs
);
6879 gen_load_fpr32h(fpu32h_T
[0], fs
);
6880 gen_load_fpr32(fpu32_T
[1], ft
);
6881 gen_load_fpr32h(fpu32h_T
[1], ft
);
6883 int l1
= gen_new_label();
6884 int l2
= gen_new_label();
6886 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 0, l1
);
6887 tcg_gen_mov_i32(fpu32_T
[2], fpu32_T
[0]);
6888 tcg_gen_mov_i32(fpu32h_T
[2], fpu32h_T
[0]);
6891 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_T
[0], 4, l2
);
6892 #ifdef TARGET_WORDS_BIGENDIAN
6893 tcg_gen_mov_i32(fpu32h_T
[2], fpu32_T
[0]);
6894 tcg_gen_mov_i32(fpu32_T
[2], fpu32h_T
[1]);
6896 tcg_gen_mov_i32(fpu32h_T
[2], fpu32_T
[1]);
6897 tcg_gen_mov_i32(fpu32_T
[2], fpu32h_T
[0]);
6901 gen_store_fpr32(fpu32_T
[2], fd
);
6902 gen_store_fpr32h(fpu32h_T
[2], fd
);
6907 gen_load_fpr32(fpu32_T
[0], fs
);
6908 gen_load_fpr32(fpu32_T
[1], ft
);
6909 gen_load_fpr32(fpu32_T
[2], fr
);
6910 tcg_gen_helper_0_0(do_float_muladd_s
);
6911 gen_store_fpr32(fpu32_T
[2], fd
);
6916 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6917 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6918 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6919 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
6920 tcg_gen_helper_0_0(do_float_muladd_d
);
6921 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6925 check_cp1_64bitmode(ctx
);
6926 gen_load_fpr32(fpu32_T
[0], fs
);
6927 gen_load_fpr32h(fpu32h_T
[0], fs
);
6928 gen_load_fpr32(fpu32_T
[1], ft
);
6929 gen_load_fpr32h(fpu32h_T
[1], ft
);
6930 gen_load_fpr32(fpu32_T
[2], fr
);
6931 gen_load_fpr32h(fpu32h_T
[2], fr
);
6932 tcg_gen_helper_0_0(do_float_muladd_ps
);
6933 gen_store_fpr32(fpu32_T
[2], fd
);
6934 gen_store_fpr32h(fpu32h_T
[2], fd
);
6939 gen_load_fpr32(fpu32_T
[0], fs
);
6940 gen_load_fpr32(fpu32_T
[1], ft
);
6941 gen_load_fpr32(fpu32_T
[2], fr
);
6942 tcg_gen_helper_0_0(do_float_mulsub_s
);
6943 gen_store_fpr32(fpu32_T
[2], fd
);
6948 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6949 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6950 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6951 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
6952 tcg_gen_helper_0_0(do_float_mulsub_d
);
6953 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6957 check_cp1_64bitmode(ctx
);
6958 gen_load_fpr32(fpu32_T
[0], fs
);
6959 gen_load_fpr32h(fpu32h_T
[0], fs
);
6960 gen_load_fpr32(fpu32_T
[1], ft
);
6961 gen_load_fpr32h(fpu32h_T
[1], ft
);
6962 gen_load_fpr32(fpu32_T
[2], fr
);
6963 gen_load_fpr32h(fpu32h_T
[2], fr
);
6964 tcg_gen_helper_0_0(do_float_mulsub_ps
);
6965 gen_store_fpr32(fpu32_T
[2], fd
);
6966 gen_store_fpr32h(fpu32h_T
[2], fd
);
6971 gen_load_fpr32(fpu32_T
[0], fs
);
6972 gen_load_fpr32(fpu32_T
[1], ft
);
6973 gen_load_fpr32(fpu32_T
[2], fr
);
6974 tcg_gen_helper_0_0(do_float_nmuladd_s
);
6975 gen_store_fpr32(fpu32_T
[2], fd
);
6980 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
6981 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
6982 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
6983 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
6984 tcg_gen_helper_0_0(do_float_nmuladd_d
);
6985 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
6989 check_cp1_64bitmode(ctx
);
6990 gen_load_fpr32(fpu32_T
[0], fs
);
6991 gen_load_fpr32h(fpu32h_T
[0], fs
);
6992 gen_load_fpr32(fpu32_T
[1], ft
);
6993 gen_load_fpr32h(fpu32h_T
[1], ft
);
6994 gen_load_fpr32(fpu32_T
[2], fr
);
6995 gen_load_fpr32h(fpu32h_T
[2], fr
);
6996 tcg_gen_helper_0_0(do_float_nmuladd_ps
);
6997 gen_store_fpr32(fpu32_T
[2], fd
);
6998 gen_store_fpr32h(fpu32h_T
[2], fd
);
7003 gen_load_fpr32(fpu32_T
[0], fs
);
7004 gen_load_fpr32(fpu32_T
[1], ft
);
7005 gen_load_fpr32(fpu32_T
[2], fr
);
7006 tcg_gen_helper_0_0(do_float_nmulsub_s
);
7007 gen_store_fpr32(fpu32_T
[2], fd
);
7012 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7013 gen_load_fpr64(ctx
, fpu64_T
[0], fs
);
7014 gen_load_fpr64(ctx
, fpu64_T
[1], ft
);
7015 gen_load_fpr64(ctx
, fpu64_T
[2], fr
);
7016 tcg_gen_helper_0_0(do_float_nmulsub_d
);
7017 gen_store_fpr64(ctx
, fpu64_T
[2], fd
);
7021 check_cp1_64bitmode(ctx
);
7022 gen_load_fpr32(fpu32_T
[0], fs
);
7023 gen_load_fpr32h(fpu32h_T
[0], fs
);
7024 gen_load_fpr32(fpu32_T
[1], ft
);
7025 gen_load_fpr32h(fpu32h_T
[1], ft
);
7026 gen_load_fpr32(fpu32_T
[2], fr
);
7027 gen_load_fpr32h(fpu32h_T
[2], fr
);
7028 tcg_gen_helper_0_0(do_float_nmulsub_ps
);
7029 gen_store_fpr32(fpu32_T
[2], fd
);
7030 gen_store_fpr32h(fpu32h_T
[2], fd
);
7035 generate_exception (ctx
, EXCP_RI
);
7038 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7039 fregnames
[fs
], fregnames
[ft
]);
7042 /* ISA extensions (ASEs) */
7043 /* MIPS16 extension to MIPS32 */
7044 /* SmartMIPS extension to MIPS32 */
7046 #if defined(TARGET_MIPS64)
7048 /* MDMX extension to MIPS64 */
7052 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7056 uint32_t op
, op1
, op2
;
7059 /* make sure instructions are on a word boundary */
7060 if (ctx
->pc
& 0x3) {
7061 env
->CP0_BadVAddr
= ctx
->pc
;
7062 generate_exception(ctx
, EXCP_AdEL
);
7066 /* Handle blikely not taken case */
7067 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7068 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
7069 int l1
= gen_new_label();
7071 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7072 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7073 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
7074 tcg_temp_free(r_tmp
);
7076 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
7078 tcg_gen_movi_i32(r_tmp2
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7079 tcg_gen_st_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, hflags
));
7080 tcg_temp_free(r_tmp2
);
7082 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7085 op
= MASK_OP_MAJOR(ctx
->opcode
);
7086 rs
= (ctx
->opcode
>> 21) & 0x1f;
7087 rt
= (ctx
->opcode
>> 16) & 0x1f;
7088 rd
= (ctx
->opcode
>> 11) & 0x1f;
7089 sa
= (ctx
->opcode
>> 6) & 0x1f;
7090 imm
= (int16_t)ctx
->opcode
;
7093 op1
= MASK_SPECIAL(ctx
->opcode
);
7095 case OPC_SLL
: /* Arithmetic with immediate */
7096 case OPC_SRL
... OPC_SRA
:
7097 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7099 case OPC_MOVZ
... OPC_MOVN
:
7100 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7101 case OPC_SLLV
: /* Arithmetic */
7102 case OPC_SRLV
... OPC_SRAV
:
7103 case OPC_ADD
... OPC_NOR
:
7104 case OPC_SLT
... OPC_SLTU
:
7105 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7107 case OPC_MULT
... OPC_DIVU
:
7109 check_insn(env
, ctx
, INSN_VR54XX
);
7110 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7111 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7113 gen_muldiv(ctx
, op1
, rs
, rt
);
7115 case OPC_JR
... OPC_JALR
:
7116 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7118 case OPC_TGE
... OPC_TEQ
: /* Traps */
7120 gen_trap(ctx
, op1
, rs
, rt
, -1);
7122 case OPC_MFHI
: /* Move from HI/LO */
7124 gen_HILO(ctx
, op1
, rd
);
7127 case OPC_MTLO
: /* Move to HI/LO */
7128 gen_HILO(ctx
, op1
, rs
);
7130 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7131 #ifdef MIPS_STRICT_STANDARD
7132 MIPS_INVAL("PMON / selsl");
7133 generate_exception(ctx
, EXCP_RI
);
7135 tcg_gen_helper_0_i(do_pmon
, sa
);
7139 generate_exception(ctx
, EXCP_SYSCALL
);
7142 generate_exception(ctx
, EXCP_BREAK
);
7145 #ifdef MIPS_STRICT_STANDARD
7147 generate_exception(ctx
, EXCP_RI
);
7149 /* Implemented as RI exception for now. */
7150 MIPS_INVAL("spim (unofficial)");
7151 generate_exception(ctx
, EXCP_RI
);
7159 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7160 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7161 save_cpu_state(ctx
, 1);
7162 check_cp1_enabled(ctx
);
7163 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7164 (ctx
->opcode
>> 16) & 1);
7166 generate_exception_err(ctx
, EXCP_CpU
, 1);
7170 #if defined(TARGET_MIPS64)
7171 /* MIPS64 specific opcodes */
7173 case OPC_DSRL
... OPC_DSRA
:
7175 case OPC_DSRL32
... OPC_DSRA32
:
7176 check_insn(env
, ctx
, ISA_MIPS3
);
7178 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7181 case OPC_DSRLV
... OPC_DSRAV
:
7182 case OPC_DADD
... OPC_DSUBU
:
7183 check_insn(env
, ctx
, ISA_MIPS3
);
7185 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7187 case OPC_DMULT
... OPC_DDIVU
:
7188 check_insn(env
, ctx
, ISA_MIPS3
);
7190 gen_muldiv(ctx
, op1
, rs
, rt
);
7193 default: /* Invalid */
7194 MIPS_INVAL("special");
7195 generate_exception(ctx
, EXCP_RI
);
7200 op1
= MASK_SPECIAL2(ctx
->opcode
);
7202 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7203 case OPC_MSUB
... OPC_MSUBU
:
7204 check_insn(env
, ctx
, ISA_MIPS32
);
7205 gen_muldiv(ctx
, op1
, rs
, rt
);
7208 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7210 case OPC_CLZ
... OPC_CLO
:
7211 check_insn(env
, ctx
, ISA_MIPS32
);
7212 gen_cl(ctx
, op1
, rd
, rs
);
7215 /* XXX: not clear which exception should be raised
7216 * when in debug mode...
7218 check_insn(env
, ctx
, ISA_MIPS32
);
7219 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7220 generate_exception(ctx
, EXCP_DBp
);
7222 generate_exception(ctx
, EXCP_DBp
);
7226 #if defined(TARGET_MIPS64)
7227 case OPC_DCLZ
... OPC_DCLO
:
7228 check_insn(env
, ctx
, ISA_MIPS64
);
7230 gen_cl(ctx
, op1
, rd
, rs
);
7233 default: /* Invalid */
7234 MIPS_INVAL("special2");
7235 generate_exception(ctx
, EXCP_RI
);
7240 op1
= MASK_SPECIAL3(ctx
->opcode
);
7244 check_insn(env
, ctx
, ISA_MIPS32R2
);
7245 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7248 check_insn(env
, ctx
, ISA_MIPS32R2
);
7249 op2
= MASK_BSHFL(ctx
->opcode
);
7252 gen_load_gpr(cpu_T
[1], rt
);
7253 tcg_gen_helper_1_2(do_wsbh
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
7256 gen_load_gpr(cpu_T
[1], rt
);
7257 tcg_gen_ext8s_tl(cpu_T
[0], cpu_T
[1]);
7260 gen_load_gpr(cpu_T
[1], rt
);
7261 tcg_gen_ext16s_tl(cpu_T
[0], cpu_T
[1]);
7263 default: /* Invalid */
7264 MIPS_INVAL("bshfl");
7265 generate_exception(ctx
, EXCP_RI
);
7268 gen_store_gpr(cpu_T
[0], rd
);
7271 check_insn(env
, ctx
, ISA_MIPS32R2
);
7274 save_cpu_state(ctx
, 1);
7275 tcg_gen_helper_1_1(do_rdhwr_cpunum
, cpu_T
[0], cpu_T
[0]);
7278 save_cpu_state(ctx
, 1);
7279 tcg_gen_helper_1_1(do_rdhwr_synci_step
, cpu_T
[0], cpu_T
[0]);
7282 save_cpu_state(ctx
, 1);
7283 tcg_gen_helper_1_1(do_rdhwr_cc
, cpu_T
[0], cpu_T
[0]);
7286 save_cpu_state(ctx
, 1);
7287 tcg_gen_helper_1_1(do_rdhwr_ccres
, cpu_T
[0], cpu_T
[0]);
7290 #if defined (CONFIG_USER_ONLY)
7291 tcg_gen_ld_tl(cpu_T
[0], cpu_env
, offsetof(CPUState
, tls_value
));
7294 /* XXX: Some CPUs implement this in hardware. Not supported yet. */
7296 default: /* Invalid */
7297 MIPS_INVAL("rdhwr");
7298 generate_exception(ctx
, EXCP_RI
);
7301 gen_store_gpr(cpu_T
[0], rt
);
7304 check_insn(env
, ctx
, ASE_MT
);
7305 gen_load_gpr(cpu_T
[0], rt
);
7306 gen_load_gpr(cpu_T
[1], rs
);
7307 tcg_gen_helper_1_2(do_fork
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
7310 check_insn(env
, ctx
, ASE_MT
);
7311 gen_load_gpr(cpu_T
[0], rs
);
7312 tcg_gen_helper_1_1(do_yield
, cpu_T
[0], cpu_T
[0]);
7313 gen_store_gpr(cpu_T
[0], rd
);
7315 #if defined(TARGET_MIPS64)
7316 case OPC_DEXTM
... OPC_DEXT
:
7317 case OPC_DINSM
... OPC_DINS
:
7318 check_insn(env
, ctx
, ISA_MIPS64R2
);
7320 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7323 check_insn(env
, ctx
, ISA_MIPS64R2
);
7325 op2
= MASK_DBSHFL(ctx
->opcode
);
7328 gen_load_gpr(cpu_T
[1], rt
);
7329 tcg_gen_helper_1_2(do_dsbh
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
7332 gen_load_gpr(cpu_T
[1], rt
);
7333 tcg_gen_helper_1_2(do_dshd
, cpu_T
[0], cpu_T
[0], cpu_T
[1]);
7335 default: /* Invalid */
7336 MIPS_INVAL("dbshfl");
7337 generate_exception(ctx
, EXCP_RI
);
7340 gen_store_gpr(cpu_T
[0], rd
);
7343 default: /* Invalid */
7344 MIPS_INVAL("special3");
7345 generate_exception(ctx
, EXCP_RI
);
7350 op1
= MASK_REGIMM(ctx
->opcode
);
7352 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7353 case OPC_BLTZAL
... OPC_BGEZALL
:
7354 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7356 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7358 gen_trap(ctx
, op1
, rs
, -1, imm
);
7361 check_insn(env
, ctx
, ISA_MIPS32R2
);
7364 default: /* Invalid */
7365 MIPS_INVAL("regimm");
7366 generate_exception(ctx
, EXCP_RI
);
7371 check_cp0_enabled(ctx
);
7372 op1
= MASK_CP0(ctx
->opcode
);
7378 #if defined(TARGET_MIPS64)
7382 #ifndef CONFIG_USER_ONLY
7383 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7386 case OPC_C0_FIRST
... OPC_C0_LAST
:
7387 #ifndef CONFIG_USER_ONLY
7388 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7392 op2
= MASK_MFMC0(ctx
->opcode
);
7395 check_insn(env
, ctx
, ASE_MT
);
7396 tcg_gen_helper_1_1(do_dmt
, cpu_T
[0], cpu_T
[0]);
7399 check_insn(env
, ctx
, ASE_MT
);
7400 tcg_gen_helper_1_1(do_emt
, cpu_T
[0], cpu_T
[0]);
7403 check_insn(env
, ctx
, ASE_MT
);
7404 tcg_gen_helper_1_1(do_dvpe
, cpu_T
[0], cpu_T
[0]);
7407 check_insn(env
, ctx
, ASE_MT
);
7408 tcg_gen_helper_1_1(do_evpe
, cpu_T
[0], cpu_T
[0]);
7411 check_insn(env
, ctx
, ISA_MIPS32R2
);
7412 save_cpu_state(ctx
, 1);
7413 tcg_gen_helper_1_1(do_di
, cpu_T
[0], cpu_T
[0]);
7414 /* Stop translation as we may have switched the execution mode */
7415 ctx
->bstate
= BS_STOP
;
7418 check_insn(env
, ctx
, ISA_MIPS32R2
);
7419 save_cpu_state(ctx
, 1);
7420 tcg_gen_helper_1_1(do_ei
, cpu_T
[0], cpu_T
[0]);
7421 /* Stop translation as we may have switched the execution mode */
7422 ctx
->bstate
= BS_STOP
;
7424 default: /* Invalid */
7425 MIPS_INVAL("mfmc0");
7426 generate_exception(ctx
, EXCP_RI
);
7429 gen_store_gpr(cpu_T
[0], rt
);
7432 check_insn(env
, ctx
, ISA_MIPS32R2
);
7433 gen_load_srsgpr(rt
, rd
);
7436 check_insn(env
, ctx
, ISA_MIPS32R2
);
7437 gen_store_srsgpr(rt
, rd
);
7441 generate_exception(ctx
, EXCP_RI
);
7445 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
7446 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7448 case OPC_J
... OPC_JAL
: /* Jump */
7449 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
7450 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
7452 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
7453 case OPC_BEQL
... OPC_BGTZL
:
7454 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
7456 case OPC_LB
... OPC_LWR
: /* Load and stores */
7457 case OPC_SB
... OPC_SW
:
7461 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7464 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
7468 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7472 /* Floating point (COP1). */
7477 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7478 save_cpu_state(ctx
, 1);
7479 check_cp1_enabled(ctx
);
7480 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
7482 generate_exception_err(ctx
, EXCP_CpU
, 1);
7487 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7488 save_cpu_state(ctx
, 1);
7489 check_cp1_enabled(ctx
);
7490 op1
= MASK_CP1(ctx
->opcode
);
7494 check_insn(env
, ctx
, ISA_MIPS32R2
);
7499 gen_cp1(ctx
, op1
, rt
, rd
);
7501 #if defined(TARGET_MIPS64)
7504 check_insn(env
, ctx
, ISA_MIPS3
);
7505 gen_cp1(ctx
, op1
, rt
, rd
);
7511 check_insn(env
, ctx
, ASE_MIPS3D
);
7514 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
7515 (rt
>> 2) & 0x7, imm
<< 2);
7522 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
7527 generate_exception (ctx
, EXCP_RI
);
7531 generate_exception_err(ctx
, EXCP_CpU
, 1);
7541 /* COP2: Not implemented. */
7542 generate_exception_err(ctx
, EXCP_CpU
, 2);
7546 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7547 save_cpu_state(ctx
, 1);
7548 check_cp1_enabled(ctx
);
7549 op1
= MASK_CP3(ctx
->opcode
);
7557 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
7575 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
7579 generate_exception (ctx
, EXCP_RI
);
7583 generate_exception_err(ctx
, EXCP_CpU
, 1);
7587 #if defined(TARGET_MIPS64)
7588 /* MIPS64 opcodes */
7590 case OPC_LDL
... OPC_LDR
:
7591 case OPC_SDL
... OPC_SDR
:
7596 check_insn(env
, ctx
, ISA_MIPS3
);
7598 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7600 case OPC_DADDI
... OPC_DADDIU
:
7601 check_insn(env
, ctx
, ISA_MIPS3
);
7603 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7607 check_insn(env
, ctx
, ASE_MIPS16
);
7608 /* MIPS16: Not implemented. */
7610 check_insn(env
, ctx
, ASE_MDMX
);
7611 /* MDMX: Not implemented. */
7612 default: /* Invalid */
7613 MIPS_INVAL("major opcode");
7614 generate_exception(ctx
, EXCP_RI
);
7617 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
7618 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
7619 /* Branches completion */
7620 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
7621 ctx
->bstate
= BS_BRANCH
;
7622 save_cpu_state(ctx
, 0);
7625 /* unconditional branch */
7626 MIPS_DEBUG("unconditional branch");
7627 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7630 /* blikely taken case */
7631 MIPS_DEBUG("blikely branch taken");
7632 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7635 /* Conditional branch */
7636 MIPS_DEBUG("conditional branch");
7638 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_TL
);
7639 int l1
= gen_new_label();
7641 tcg_gen_ld_tl(r_tmp
, cpu_env
, offsetof(CPUState
, bcond
));
7642 tcg_gen_brcondi_tl(TCG_COND_NE
, r_tmp
, 0, l1
);
7643 tcg_temp_free(r_tmp
);
7644 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7646 gen_goto_tb(ctx
, 0, ctx
->btarget
);
7650 /* unconditional branch to register */
7651 MIPS_DEBUG("branch to register");
7656 MIPS_DEBUG("unknown branch");
7662 static always_inline
int
7663 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
7667 target_ulong pc_start
;
7668 uint16_t *gen_opc_end
;
7671 if (search_pc
&& loglevel
)
7672 fprintf (logfile
, "search pc %d\n", search_pc
);
7675 /* Leave some spare opc slots for branch handling. */
7676 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
7680 ctx
.bstate
= BS_NONE
;
7681 /* Restore delay slot state from the tb context. */
7682 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
7683 restore_cpu_state(env
, &ctx
);
7684 #if defined(CONFIG_USER_ONLY)
7685 ctx
.mem_idx
= MIPS_HFLAG_UM
;
7687 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
7690 if (loglevel
& CPU_LOG_TB_CPU
) {
7691 fprintf(logfile
, "------------------------------------------------\n");
7692 /* FIXME: This may print out stale hflags from env... */
7693 cpu_dump_state(env
, logfile
, fprintf
, 0);
7696 #ifdef MIPS_DEBUG_DISAS
7697 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7698 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
7699 tb
, ctx
.mem_idx
, ctx
.hflags
);
7701 while (ctx
.bstate
== BS_NONE
) {
7702 if (env
->nb_breakpoints
> 0) {
7703 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
7704 if (env
->breakpoints
[j
] == ctx
.pc
) {
7705 save_cpu_state(&ctx
, 1);
7706 ctx
.bstate
= BS_BRANCH
;
7707 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
7708 /* Include the breakpoint location or the tb won't
7709 * be flushed when it must be. */
7711 goto done_generating
;
7717 j
= gen_opc_ptr
- gen_opc_buf
;
7721 gen_opc_instr_start
[lj
++] = 0;
7723 gen_opc_pc
[lj
] = ctx
.pc
;
7724 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
7725 gen_opc_instr_start
[lj
] = 1;
7727 ctx
.opcode
= ldl_code(ctx
.pc
);
7728 decode_opc(env
, &ctx
);
7731 if (env
->singlestep_enabled
)
7734 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
7737 if (gen_opc_ptr
>= gen_opc_end
)
7740 if (gen_opc_ptr
>= gen_opc_end
)
7743 #if defined (MIPS_SINGLE_STEP)
7747 if (env
->singlestep_enabled
) {
7748 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
7749 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
7751 switch (ctx
.bstate
) {
7753 tcg_gen_helper_0_0(do_interrupt_restart
);
7754 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7757 save_cpu_state(&ctx
, 0);
7758 gen_goto_tb(&ctx
, 0, ctx
.pc
);
7761 tcg_gen_helper_0_0(do_interrupt_restart
);
7770 *gen_opc_ptr
= INDEX_op_end
;
7772 j
= gen_opc_ptr
- gen_opc_buf
;
7775 gen_opc_instr_start
[lj
++] = 0;
7777 tb
->size
= ctx
.pc
- pc_start
;
7780 #if defined MIPS_DEBUG_DISAS
7781 if (loglevel
& CPU_LOG_TB_IN_ASM
)
7782 fprintf(logfile
, "\n");
7784 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7785 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7786 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
7787 fprintf(logfile
, "\n");
7789 if (loglevel
& CPU_LOG_TB_CPU
) {
7790 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
7797 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7799 return gen_intermediate_code_internal(env
, tb
, 0);
7802 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7804 return gen_intermediate_code_internal(env
, tb
, 1);
7807 void fpu_dump_state(CPUState
*env
, FILE *f
,
7808 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7812 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
7814 #define printfpr(fp) \
7817 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7818 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7819 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7822 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7823 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7824 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7825 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7826 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7831 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7832 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
7833 get_float_exception_flags(&env
->fpu
->fp_status
));
7834 fpu_fprintf(f
, "FT0: "); printfpr(&env
->ft0
);
7835 fpu_fprintf(f
, "FT1: "); printfpr(&env
->ft1
);
7836 fpu_fprintf(f
, "FT2: "); printfpr(&env
->ft2
);
7837 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
7838 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
7839 printfpr(&env
->fpu
->fpr
[i
]);
7845 void dump_fpu (CPUState
*env
)
7849 "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
7850 " LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
7852 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
][0],
7853 env
->LO
[env
->current_tc
][0], env
->hflags
, env
->btarget
,
7855 fpu_dump_state(env
, logfile
, fprintf
, 0);
7859 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7860 /* Debug help: The architecture requires 32bit code to maintain proper
7861 sign-extened values on 64bit machines. */
7863 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7865 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
7866 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7871 if (!SIGN_EXT_P(env
->PC
[env
->current_tc
]))
7872 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
[env
->current_tc
]);
7873 if (!SIGN_EXT_P(env
->HI
[env
->current_tc
][0]))
7874 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
[env
->current_tc
][0]);
7875 if (!SIGN_EXT_P(env
->LO
[env
->current_tc
][0]))
7876 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
[env
->current_tc
][0]);
7877 if (!SIGN_EXT_P(env
->btarget
))
7878 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
7880 for (i
= 0; i
< 32; i
++) {
7881 if (!SIGN_EXT_P(env
->gpr
[env
->current_tc
][i
]))
7882 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7885 if (!SIGN_EXT_P(env
->CP0_EPC
))
7886 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
7887 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
7888 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
7892 void cpu_dump_state (CPUState
*env
, FILE *f
,
7893 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7898 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",
7899 env
->PC
[env
->current_tc
], env
->HI
[env
->current_tc
], env
->LO
[env
->current_tc
], env
->hflags
, env
->btarget
, env
->bcond
);
7900 for (i
= 0; i
< 32; i
++) {
7902 cpu_fprintf(f
, "GPR%02d:", i
);
7903 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[env
->current_tc
][i
]);
7905 cpu_fprintf(f
, "\n");
7908 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
7909 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
7910 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
7911 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
7912 if (env
->hflags
& MIPS_HFLAG_FPU
)
7913 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
7914 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7915 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
7919 static void mips_tcg_init(void)
7923 /* Initialize various static tables. */
7927 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
7928 current_tc_gprs
= tcg_global_mem_new(TCG_TYPE_PTR
,
7930 offsetof(CPUState
, current_tc_gprs
),
7932 current_tc_hi
= tcg_global_mem_new(TCG_TYPE_PTR
,
7934 offsetof(CPUState
, current_tc_hi
),
7936 current_fpu
= tcg_global_mem_new(TCG_TYPE_PTR
,
7938 offsetof(CPUState
, fpu
),
7940 #if TARGET_LONG_BITS > HOST_LONG_BITS
7941 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
7942 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
7943 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
7944 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
7946 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
7947 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
7950 /* register helpers */
7952 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
7955 fpu32_T
[0] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft0
.w
[FP_ENDIAN_IDX
]), "WT0");
7956 fpu32_T
[1] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft1
.w
[FP_ENDIAN_IDX
]), "WT1");
7957 fpu32_T
[2] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft2
.w
[FP_ENDIAN_IDX
]), "WT2");
7958 fpu64_T
[0] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft0
.d
), "DT0");
7959 fpu64_T
[1] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft1
.d
), "DT1");
7960 fpu64_T
[2] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
, offsetof(CPUState
, ft2
.d
), "DT2");
7961 fpu32h_T
[0] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft0
.w
[!FP_ENDIAN_IDX
]), "WTH0");
7962 fpu32h_T
[1] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft1
.w
[!FP_ENDIAN_IDX
]), "WTH1");
7963 fpu32h_T
[2] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
, offsetof(CPUState
, ft2
.w
[!FP_ENDIAN_IDX
]), "WTH2");
7968 #include "translate_init.c"
7970 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
7973 const mips_def_t
*def
;
7975 def
= cpu_mips_find_by_name(cpu_model
);
7978 env
= qemu_mallocz(sizeof(CPUMIPSState
));
7981 env
->cpu_model
= def
;
7984 env
->cpu_model_str
= cpu_model
;
7990 void cpu_reset (CPUMIPSState
*env
)
7992 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
7997 #if !defined(CONFIG_USER_ONLY)
7998 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
7999 /* If the exception was raised from a delay slot,
8000 * come back to the jump. */
8001 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
] - 4;
8003 env
->CP0_ErrorEPC
= env
->PC
[env
->current_tc
];
8005 env
->PC
[env
->current_tc
] = (int32_t)0xBFC00000;
8007 /* SMP not implemented */
8008 env
->CP0_EBase
= 0x80000000;
8009 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8010 /* vectored interrupts not implemented, timer on int 7,
8011 no performance counters. */
8012 env
->CP0_IntCtl
= 0xe0000000;
8016 for (i
= 0; i
< 7; i
++) {
8017 env
->CP0_WatchLo
[i
] = 0;
8018 env
->CP0_WatchHi
[i
] = 0x80000000;
8020 env
->CP0_WatchLo
[7] = 0;
8021 env
->CP0_WatchHi
[7] = 0;
8023 /* Count register increments in debug mode, EJTAG version 1 */
8024 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8026 env
->exception_index
= EXCP_NONE
;
8027 #if defined(CONFIG_USER_ONLY)
8028 env
->hflags
= MIPS_HFLAG_UM
;
8029 env
->user_mode_only
= 1;
8031 env
->hflags
= MIPS_HFLAG_CP0
;
8033 cpu_mips_register(env
, env
->cpu_model
);
8036 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8037 unsigned long searched_pc
, int pc_pos
, void *puc
)
8039 env
->PC
[env
->current_tc
] = gen_opc_pc
[pc_pos
];
8040 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8041 env
->hflags
|= gen_opc_hflags
[pc_pos
];