2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 //#define MIPS_DEBUG_DISAS
34 //#define MIPS_DEBUG_SIGN_EXTENSIONS
35 //#define MIPS_SINGLE_STEP
37 #ifdef USE_DIRECT_JUMP
40 #define TBPARAM(x) (long)(x)
44 #define DEF(s, n, copy_size) INDEX_op_ ## s,
50 static uint16_t *gen_opc_ptr
;
51 static uint32_t *gen_opparam_ptr
;
55 /* MIPS major opcodes */
56 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
59 /* indirect opcode tables */
60 OPC_SPECIAL
= (0x00 << 26),
61 OPC_REGIMM
= (0x01 << 26),
62 OPC_CP0
= (0x10 << 26),
63 OPC_CP1
= (0x11 << 26),
64 OPC_CP2
= (0x12 << 26),
65 OPC_CP3
= (0x13 << 26),
66 OPC_SPECIAL2
= (0x1C << 26),
67 OPC_SPECIAL3
= (0x1F << 26),
68 /* arithmetic with immediate */
69 OPC_ADDI
= (0x08 << 26),
70 OPC_ADDIU
= (0x09 << 26),
71 OPC_SLTI
= (0x0A << 26),
72 OPC_SLTIU
= (0x0B << 26),
73 OPC_ANDI
= (0x0C << 26),
74 OPC_ORI
= (0x0D << 26),
75 OPC_XORI
= (0x0E << 26),
76 OPC_LUI
= (0x0F << 26),
77 OPC_DADDI
= (0x18 << 26),
78 OPC_DADDIU
= (0x19 << 26),
79 /* Jump and branches */
81 OPC_JAL
= (0x03 << 26),
82 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
83 OPC_BEQL
= (0x14 << 26),
84 OPC_BNE
= (0x05 << 26),
85 OPC_BNEL
= (0x15 << 26),
86 OPC_BLEZ
= (0x06 << 26),
87 OPC_BLEZL
= (0x16 << 26),
88 OPC_BGTZ
= (0x07 << 26),
89 OPC_BGTZL
= (0x17 << 26),
90 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
92 OPC_LDL
= (0x1A << 26),
93 OPC_LDR
= (0x1B << 26),
94 OPC_LB
= (0x20 << 26),
95 OPC_LH
= (0x21 << 26),
96 OPC_LWL
= (0x22 << 26),
97 OPC_LW
= (0x23 << 26),
98 OPC_LBU
= (0x24 << 26),
99 OPC_LHU
= (0x25 << 26),
100 OPC_LWR
= (0x26 << 26),
101 OPC_LWU
= (0x27 << 26),
102 OPC_SB
= (0x28 << 26),
103 OPC_SH
= (0x29 << 26),
104 OPC_SWL
= (0x2A << 26),
105 OPC_SW
= (0x2B << 26),
106 OPC_SDL
= (0x2C << 26),
107 OPC_SDR
= (0x2D << 26),
108 OPC_SWR
= (0x2E << 26),
109 OPC_LL
= (0x30 << 26),
110 OPC_LLD
= (0x34 << 26),
111 OPC_LD
= (0x37 << 26),
112 OPC_SC
= (0x38 << 26),
113 OPC_SCD
= (0x3C << 26),
114 OPC_SD
= (0x3F << 26),
115 /* Floating point load/store */
116 OPC_LWC1
= (0x31 << 26),
117 OPC_LWC2
= (0x32 << 26),
118 OPC_LDC1
= (0x35 << 26),
119 OPC_LDC2
= (0x36 << 26),
120 OPC_SWC1
= (0x39 << 26),
121 OPC_SWC2
= (0x3A << 26),
122 OPC_SDC1
= (0x3D << 26),
123 OPC_SDC2
= (0x3E << 26),
124 /* MDMX ASE specific */
125 OPC_MDMX
= (0x1E << 26),
126 /* Cache and prefetch */
127 OPC_CACHE
= (0x2F << 26),
128 OPC_PREF
= (0x33 << 26),
129 /* Reserved major opcode */
130 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
133 /* MIPS special opcodes */
134 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
138 OPC_SLL
= 0x00 | OPC_SPECIAL
,
139 /* NOP is SLL r0, r0, 0 */
140 /* SSNOP is SLL r0, r0, 1 */
141 /* EHB is SLL r0, r0, 3 */
142 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
143 OPC_SRA
= 0x03 | OPC_SPECIAL
,
144 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
145 OPC_SRLV
= 0x06 | OPC_SPECIAL
,
146 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
147 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
148 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
149 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
150 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
151 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
152 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
153 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
154 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
155 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
156 /* Multiplication / division */
157 OPC_MULT
= 0x18 | OPC_SPECIAL
,
158 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
159 OPC_DIV
= 0x1A | OPC_SPECIAL
,
160 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
161 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
162 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
163 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
164 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
165 /* 2 registers arithmetic / logic */
166 OPC_ADD
= 0x20 | OPC_SPECIAL
,
167 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
168 OPC_SUB
= 0x22 | OPC_SPECIAL
,
169 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
170 OPC_AND
= 0x24 | OPC_SPECIAL
,
171 OPC_OR
= 0x25 | OPC_SPECIAL
,
172 OPC_XOR
= 0x26 | OPC_SPECIAL
,
173 OPC_NOR
= 0x27 | OPC_SPECIAL
,
174 OPC_SLT
= 0x2A | OPC_SPECIAL
,
175 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
176 OPC_DADD
= 0x2C | OPC_SPECIAL
,
177 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
178 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
179 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
181 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
182 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
184 OPC_TGE
= 0x30 | OPC_SPECIAL
,
185 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
186 OPC_TLT
= 0x32 | OPC_SPECIAL
,
187 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
188 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
189 OPC_TNE
= 0x36 | OPC_SPECIAL
,
190 /* HI / LO registers load & stores */
191 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
192 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
193 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
194 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
195 /* Conditional moves */
196 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
197 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
199 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
202 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
203 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
204 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
205 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
206 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
208 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
209 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
210 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
211 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
212 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
213 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
214 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
217 /* REGIMM (rt field) opcodes */
218 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
221 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
222 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
223 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
224 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
225 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
226 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
227 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
228 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
229 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
230 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
231 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
232 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
233 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
234 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
235 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
238 /* Special2 opcodes */
239 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
242 /* Multiply & xxx operations */
243 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
244 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
245 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
246 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
247 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
249 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
250 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
251 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
252 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
254 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
257 /* Special3 opcodes */
258 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
261 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
262 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
263 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
264 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
265 OPC_INS
= 0x04 | OPC_SPECIAL3
,
266 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
267 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
268 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
269 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
270 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
271 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
275 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
278 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
279 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
280 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
284 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
287 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
288 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
291 /* Coprocessor 0 (rs field) */
292 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
295 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
296 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
297 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
298 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
299 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
300 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
301 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
302 OPC_C0
= (0x10 << 21) | OPC_CP0
,
303 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
304 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
308 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
311 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
312 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
315 /* Coprocessor 0 (with rs == C0) */
316 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
319 OPC_TLBR
= 0x01 | OPC_C0
,
320 OPC_TLBWI
= 0x02 | OPC_C0
,
321 OPC_TLBWR
= 0x06 | OPC_C0
,
322 OPC_TLBP
= 0x08 | OPC_C0
,
323 OPC_RFE
= 0x10 | OPC_C0
,
324 OPC_ERET
= 0x18 | OPC_C0
,
325 OPC_DERET
= 0x1F | OPC_C0
,
326 OPC_WAIT
= 0x20 | OPC_C0
,
329 /* Coprocessor 1 (rs field) */
330 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
333 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
334 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
335 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
336 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
337 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
338 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
339 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
340 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
341 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
342 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
343 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
344 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
345 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
346 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
347 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
348 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
349 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
350 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
353 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
354 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
357 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
358 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
359 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
360 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
364 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
365 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
369 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
370 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
373 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
376 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
377 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
378 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
379 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
380 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
381 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
382 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
383 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
384 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
387 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
390 OPC_LWXC1
= 0x00 | OPC_CP3
,
391 OPC_LDXC1
= 0x01 | OPC_CP3
,
392 OPC_LUXC1
= 0x05 | OPC_CP3
,
393 OPC_SWXC1
= 0x08 | OPC_CP3
,
394 OPC_SDXC1
= 0x09 | OPC_CP3
,
395 OPC_SUXC1
= 0x0D | OPC_CP3
,
396 OPC_PREFX
= 0x0F | OPC_CP3
,
397 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
398 OPC_MADD_S
= 0x20 | OPC_CP3
,
399 OPC_MADD_D
= 0x21 | OPC_CP3
,
400 OPC_MADD_PS
= 0x26 | OPC_CP3
,
401 OPC_MSUB_S
= 0x28 | OPC_CP3
,
402 OPC_MSUB_D
= 0x29 | OPC_CP3
,
403 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
404 OPC_NMADD_S
= 0x30 | OPC_CP3
,
405 OPC_NMADD_D
= 0x31 | OPC_CP3
,
406 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
407 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
408 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
409 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
413 const unsigned char *regnames
[] =
414 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
415 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
416 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
417 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
419 /* Warning: no function for r0 register (hard wired to zero) */
420 #define GEN32(func, NAME) \
421 static GenOpFunc *NAME ## _table [32] = { \
422 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
423 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
424 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
425 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
426 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
427 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
428 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
429 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
431 static inline void func(int n) \
433 NAME ## _table[n](); \
436 /* General purpose registers moves */
437 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
438 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
439 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
441 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
442 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
444 static const char *fregnames
[] =
445 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
446 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
447 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
448 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
450 #define FGEN32(func, NAME) \
451 static GenOpFunc *NAME ## _table [32] = { \
452 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
453 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
454 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
455 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
456 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
457 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
458 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
459 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
461 static inline void func(int n) \
463 NAME ## _table[n](); \
466 FGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
467 FGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
469 FGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
470 FGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
472 FGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
473 FGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
475 FGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
476 FGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
478 FGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
479 FGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
481 FGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
482 FGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
484 FGEN32(gen_op_load_fpr_WTH0
, gen_op_load_fpr_WTH0_fpr
);
485 FGEN32(gen_op_store_fpr_WTH0
, gen_op_store_fpr_WTH0_fpr
);
487 FGEN32(gen_op_load_fpr_WTH1
, gen_op_load_fpr_WTH1_fpr
);
488 FGEN32(gen_op_store_fpr_WTH1
, gen_op_store_fpr_WTH1_fpr
);
490 FGEN32(gen_op_load_fpr_WTH2
, gen_op_load_fpr_WTH2_fpr
);
491 FGEN32(gen_op_store_fpr_WTH2
, gen_op_store_fpr_WTH2_fpr
);
493 #define FOP_CONDS(type, fmt) \
494 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
495 gen_op_cmp ## type ## _ ## fmt ## _f, \
496 gen_op_cmp ## type ## _ ## fmt ## _un, \
497 gen_op_cmp ## type ## _ ## fmt ## _eq, \
498 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
499 gen_op_cmp ## type ## _ ## fmt ## _olt, \
500 gen_op_cmp ## type ## _ ## fmt ## _ult, \
501 gen_op_cmp ## type ## _ ## fmt ## _ole, \
502 gen_op_cmp ## type ## _ ## fmt ## _ule, \
503 gen_op_cmp ## type ## _ ## fmt ## _sf, \
504 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
505 gen_op_cmp ## type ## _ ## fmt ## _seq, \
506 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
507 gen_op_cmp ## type ## _ ## fmt ## _lt, \
508 gen_op_cmp ## type ## _ ## fmt ## _nge, \
509 gen_op_cmp ## type ## _ ## fmt ## _le, \
510 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
512 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
514 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
524 typedef struct DisasContext
{
525 struct TranslationBlock
*tb
;
526 target_ulong pc
, saved_pc
;
529 /* Routine used to access memory */
531 uint32_t hflags
, saved_hflags
;
533 target_ulong btarget
;
537 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
538 * exception condition
540 BS_STOP
= 1, /* We want to stop translation for any reason */
541 BS_BRANCH
= 2, /* We reached a branch condition */
542 BS_EXCP
= 3, /* We reached an exception condition */
545 #ifdef MIPS_DEBUG_DISAS
546 #define MIPS_DEBUG(fmt, args...) \
548 if (loglevel & CPU_LOG_TB_IN_ASM) { \
549 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
550 ctx->pc, ctx->opcode , ##args); \
554 #define MIPS_DEBUG(fmt, args...) do { } while(0)
557 #define MIPS_INVAL(op) \
559 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
560 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
563 #define GEN_LOAD_REG_TN(Tn, Rn) \
566 glue(gen_op_reset_, Tn)(); \
568 glue(gen_op_load_gpr_, Tn)(Rn); \
573 #define GEN_LOAD_IMM_TN(Tn, Imm) \
576 glue(gen_op_reset_, Tn)(); \
577 } else if ((int32_t)Imm == Imm) { \
578 glue(gen_op_set_, Tn)(Imm); \
580 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
584 #define GEN_LOAD_IMM_TN(Tn, Imm) \
587 glue(gen_op_reset_, Tn)(); \
589 glue(gen_op_set_, Tn)(Imm); \
594 #define GEN_STORE_TN_REG(Rn, Tn) \
597 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
601 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
603 glue(gen_op_load_fpr_, FTn)(Fn); \
606 #define GEN_STORE_FTN_FREG(Fn, FTn) \
608 glue(gen_op_store_fpr_, FTn)(Fn); \
611 static inline void gen_save_pc(target_ulong pc
)
614 if (pc
== (int32_t)pc
) {
617 gen_op_save_pc64(pc
>> 32, (uint32_t)pc
);
624 static inline void gen_save_btarget(target_ulong btarget
)
627 if (btarget
== (int32_t)btarget
) {
628 gen_op_save_btarget(btarget
);
630 gen_op_save_btarget64(btarget
>> 32, (uint32_t)btarget
);
633 gen_op_save_btarget(btarget
);
637 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
639 #if defined MIPS_DEBUG_DISAS
640 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
641 fprintf(logfile
, "hflags %08x saved %08x\n",
642 ctx
->hflags
, ctx
->saved_hflags
);
645 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
646 gen_save_pc(ctx
->pc
);
647 ctx
->saved_pc
= ctx
->pc
;
649 if (ctx
->hflags
!= ctx
->saved_hflags
) {
650 gen_op_save_state(ctx
->hflags
);
651 ctx
->saved_hflags
= ctx
->hflags
;
652 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
654 gen_op_save_breg_target();
660 /* bcond was already saved by the BL insn */
663 gen_save_btarget(ctx
->btarget
);
669 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
671 ctx
->saved_hflags
= ctx
->hflags
;
672 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
674 gen_op_restore_breg_target();
677 ctx
->btarget
= env
->btarget
;
681 ctx
->btarget
= env
->btarget
;
682 gen_op_restore_bcond();
687 static inline void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
689 #if defined MIPS_DEBUG_DISAS
690 if (loglevel
& CPU_LOG_TB_IN_ASM
)
691 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
693 save_cpu_state(ctx
, 1);
695 gen_op_raise_exception(excp
);
697 gen_op_raise_exception_err(excp
, err
);
698 ctx
->bstate
= BS_EXCP
;
701 static inline void generate_exception (DisasContext
*ctx
, int excp
)
703 generate_exception_err (ctx
, excp
, 0);
706 static inline void check_cp1_enabled(DisasContext
*ctx
)
708 if (!(ctx
->hflags
& MIPS_HFLAG_FPU
))
709 generate_exception_err(ctx
, EXCP_CpU
, 1);
712 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
714 if (!(ctx
->hflags
& MIPS_HFLAG_F64
))
715 generate_exception(ctx
, EXCP_RI
);
719 * Verify if floating point register is valid; an operation is not defined
720 * if bit 0 of any register specification is set and the FR bit in the
721 * Status register equals zero, since the register numbers specify an
722 * even-odd pair of adjacent coprocessor general registers. When the FR bit
723 * in the Status register equals one, both even and odd register numbers
724 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
726 * Multiple 64 bit wide registers can be checked by calling
727 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
729 void check_cp1_registers(DisasContext
*ctx
, int regs
)
731 if (!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1))
732 generate_exception(ctx
, EXCP_RI
);
735 #if defined(CONFIG_USER_ONLY)
736 #define op_ldst(name) gen_op_##name##_raw()
737 #define OP_LD_TABLE(width)
738 #define OP_ST_TABLE(width)
740 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
741 #define OP_LD_TABLE(width) \
742 static GenOpFunc *gen_op_l##width[] = { \
743 &gen_op_l##width##_user, \
744 &gen_op_l##width##_kernel, \
746 #define OP_ST_TABLE(width) \
747 static GenOpFunc *gen_op_s##width[] = { \
748 &gen_op_s##width##_user, \
749 &gen_op_s##width##_kernel, \
786 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
787 int base
, int16_t offset
)
789 const char *opn
= "ldst";
792 GEN_LOAD_IMM_TN(T0
, offset
);
793 } else if (offset
== 0) {
794 gen_op_load_gpr_T0(base
);
796 gen_op_load_gpr_T0(base
);
797 gen_op_set_T1(offset
);
800 /* Don't do NOP if destination is zero: we must perform the actual
807 GEN_STORE_TN_REG(rt
, T0
);
812 GEN_STORE_TN_REG(rt
, T0
);
817 GEN_STORE_TN_REG(rt
, T0
);
821 GEN_LOAD_REG_TN(T1
, rt
);
826 save_cpu_state(ctx
, 1);
827 GEN_LOAD_REG_TN(T1
, rt
);
829 GEN_STORE_TN_REG(rt
, T0
);
833 GEN_LOAD_REG_TN(T1
, rt
);
835 GEN_STORE_TN_REG(rt
, T0
);
839 GEN_LOAD_REG_TN(T1
, rt
);
844 GEN_LOAD_REG_TN(T1
, rt
);
846 GEN_STORE_TN_REG(rt
, T0
);
850 GEN_LOAD_REG_TN(T1
, rt
);
857 GEN_STORE_TN_REG(rt
, T0
);
861 GEN_LOAD_REG_TN(T1
, rt
);
867 GEN_STORE_TN_REG(rt
, T0
);
871 GEN_LOAD_REG_TN(T1
, rt
);
877 GEN_STORE_TN_REG(rt
, T0
);
882 GEN_STORE_TN_REG(rt
, T0
);
886 GEN_LOAD_REG_TN(T1
, rt
);
892 GEN_STORE_TN_REG(rt
, T0
);
896 GEN_LOAD_REG_TN(T1
, rt
);
898 GEN_STORE_TN_REG(rt
, T0
);
902 GEN_LOAD_REG_TN(T1
, rt
);
907 GEN_LOAD_REG_TN(T1
, rt
);
909 GEN_STORE_TN_REG(rt
, T0
);
913 GEN_LOAD_REG_TN(T1
, rt
);
919 GEN_STORE_TN_REG(rt
, T0
);
923 save_cpu_state(ctx
, 1);
924 GEN_LOAD_REG_TN(T1
, rt
);
926 GEN_STORE_TN_REG(rt
, T0
);
931 generate_exception(ctx
, EXCP_RI
);
934 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
938 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
939 int base
, int16_t offset
)
941 const char *opn
= "flt_ldst";
944 GEN_LOAD_IMM_TN(T0
, offset
);
945 } else if (offset
== 0) {
946 gen_op_load_gpr_T0(base
);
948 gen_op_load_gpr_T0(base
);
949 gen_op_set_T1(offset
);
952 /* Don't do NOP if destination is zero: we must perform the actual
958 GEN_STORE_FTN_FREG(ft
, WT0
);
962 GEN_LOAD_FREG_FTN(WT0
, ft
);
968 GEN_STORE_FTN_FREG(ft
, DT0
);
972 GEN_LOAD_FREG_FTN(DT0
, ft
);
978 generate_exception(ctx
, EXCP_RI
);
981 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
984 /* Arithmetic with immediate operand */
985 static void gen_arith_imm (DisasContext
*ctx
, uint32_t opc
, int rt
,
989 const char *opn
= "imm arith";
991 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
992 /* if no destination, treat it as a NOP
993 * For addi, we must generate the overflow exception when needed.
998 uimm
= (uint16_t)imm
;
1002 #ifdef TARGET_MIPS64
1008 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1013 GEN_LOAD_REG_TN(T0
, rs
);
1014 GEN_LOAD_IMM_TN(T1
, uimm
);
1017 GEN_LOAD_IMM_TN(T0
, imm
<< 16);
1022 #ifdef TARGET_MIPS64
1031 GEN_LOAD_REG_TN(T0
, rs
);
1032 GEN_LOAD_IMM_TN(T1
, uimm
);
1037 save_cpu_state(ctx
, 1);
1045 #ifdef TARGET_MIPS64
1047 save_cpu_state(ctx
, 1);
1088 switch ((ctx
->opcode
>> 21) & 0x1f) {
1098 MIPS_INVAL("invalid srl flag");
1099 generate_exception(ctx
, EXCP_RI
);
1103 #ifdef TARGET_MIPS64
1113 switch ((ctx
->opcode
>> 21) & 0x1f) {
1123 MIPS_INVAL("invalid dsrl flag");
1124 generate_exception(ctx
, EXCP_RI
);
1137 switch ((ctx
->opcode
>> 21) & 0x1f) {
1147 MIPS_INVAL("invalid dsrl32 flag");
1148 generate_exception(ctx
, EXCP_RI
);
1155 generate_exception(ctx
, EXCP_RI
);
1158 GEN_STORE_TN_REG(rt
, T0
);
1159 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1163 static void gen_arith (DisasContext
*ctx
, uint32_t opc
,
1164 int rd
, int rs
, int rt
)
1166 const char *opn
= "arith";
1168 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1169 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1170 /* if no destination, treat it as a NOP
1171 * For add & sub, we must generate the overflow exception when needed.
1176 GEN_LOAD_REG_TN(T0
, rs
);
1177 GEN_LOAD_REG_TN(T1
, rt
);
1180 save_cpu_state(ctx
, 1);
1189 save_cpu_state(ctx
, 1);
1197 #ifdef TARGET_MIPS64
1199 save_cpu_state(ctx
, 1);
1208 save_cpu_state(ctx
, 1);
1262 switch ((ctx
->opcode
>> 6) & 0x1f) {
1272 MIPS_INVAL("invalid srlv flag");
1273 generate_exception(ctx
, EXCP_RI
);
1277 #ifdef TARGET_MIPS64
1287 switch ((ctx
->opcode
>> 6) & 0x1f) {
1297 MIPS_INVAL("invalid dsrlv flag");
1298 generate_exception(ctx
, EXCP_RI
);
1305 generate_exception(ctx
, EXCP_RI
);
1308 GEN_STORE_TN_REG(rd
, T0
);
1310 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1313 /* Arithmetic on HI/LO registers */
1314 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1316 const char *opn
= "hilo";
1318 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1319 /* Treat as a NOP */
1326 GEN_STORE_TN_REG(reg
, T0
);
1331 GEN_STORE_TN_REG(reg
, T0
);
1335 GEN_LOAD_REG_TN(T0
, reg
);
1340 GEN_LOAD_REG_TN(T0
, reg
);
1346 generate_exception(ctx
, EXCP_RI
);
1349 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1352 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1355 const char *opn
= "mul/div";
1357 GEN_LOAD_REG_TN(T0
, rs
);
1358 GEN_LOAD_REG_TN(T1
, rt
);
1376 #ifdef TARGET_MIPS64
1412 generate_exception(ctx
, EXCP_RI
);
1415 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1418 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1421 const char *opn
= "CLx";
1423 /* Treat as a NOP */
1427 GEN_LOAD_REG_TN(T0
, rs
);
1437 #ifdef TARGET_MIPS64
1449 generate_exception(ctx
, EXCP_RI
);
1452 gen_op_store_T0_gpr(rd
);
1453 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1457 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1458 int rs
, int rt
, int16_t imm
)
1463 /* Load needed operands */
1471 /* Compare two registers */
1473 GEN_LOAD_REG_TN(T0
, rs
);
1474 GEN_LOAD_REG_TN(T1
, rt
);
1484 /* Compare register to immediate */
1485 if (rs
!= 0 || imm
!= 0) {
1486 GEN_LOAD_REG_TN(T0
, rs
);
1487 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1494 case OPC_TEQ
: /* rs == rs */
1495 case OPC_TEQI
: /* r0 == 0 */
1496 case OPC_TGE
: /* rs >= rs */
1497 case OPC_TGEI
: /* r0 >= 0 */
1498 case OPC_TGEU
: /* rs >= rs unsigned */
1499 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1503 case OPC_TLT
: /* rs < rs */
1504 case OPC_TLTI
: /* r0 < 0 */
1505 case OPC_TLTU
: /* rs < rs unsigned */
1506 case OPC_TLTIU
: /* r0 < 0 unsigned */
1507 case OPC_TNE
: /* rs != rs */
1508 case OPC_TNEI
: /* r0 != 0 */
1509 /* Never trap: treat as NOP */
1513 generate_exception(ctx
, EXCP_RI
);
1544 generate_exception(ctx
, EXCP_RI
);
1548 save_cpu_state(ctx
, 1);
1550 ctx
->bstate
= BS_STOP
;
1553 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1555 TranslationBlock
*tb
;
1557 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1559 gen_op_goto_tb0(TBPARAM(tb
));
1561 gen_op_goto_tb1(TBPARAM(tb
));
1563 gen_op_set_T0((long)tb
+ n
);
1571 /* Branches (before delay slot) */
1572 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1573 int rs
, int rt
, int32_t offset
)
1575 target_ulong btarget
= -1;
1579 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1580 #ifdef MIPS_DEBUG_DISAS
1581 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1583 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1587 generate_exception(ctx
, EXCP_RI
);
1591 /* Load needed operands */
1597 /* Compare two registers */
1599 GEN_LOAD_REG_TN(T0
, rs
);
1600 GEN_LOAD_REG_TN(T1
, rt
);
1603 btarget
= ctx
->pc
+ 4 + offset
;
1617 /* Compare to zero */
1619 gen_op_load_gpr_T0(rs
);
1622 btarget
= ctx
->pc
+ 4 + offset
;
1626 /* Jump to immediate */
1627 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
1631 /* Jump to register */
1632 if (offset
!= 0 && offset
!= 16) {
1633 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1634 others are reserved. */
1635 MIPS_INVAL("jump hint");
1636 generate_exception(ctx
, EXCP_RI
);
1639 GEN_LOAD_REG_TN(T2
, rs
);
1642 MIPS_INVAL("branch/jump");
1643 generate_exception(ctx
, EXCP_RI
);
1647 /* No condition to be computed */
1649 case OPC_BEQ
: /* rx == rx */
1650 case OPC_BEQL
: /* rx == rx likely */
1651 case OPC_BGEZ
: /* 0 >= 0 */
1652 case OPC_BGEZL
: /* 0 >= 0 likely */
1653 case OPC_BLEZ
: /* 0 <= 0 */
1654 case OPC_BLEZL
: /* 0 <= 0 likely */
1656 ctx
->hflags
|= MIPS_HFLAG_B
;
1657 MIPS_DEBUG("balways");
1659 case OPC_BGEZAL
: /* 0 >= 0 */
1660 case OPC_BGEZALL
: /* 0 >= 0 likely */
1661 /* Always take and link */
1663 ctx
->hflags
|= MIPS_HFLAG_B
;
1664 MIPS_DEBUG("balways and link");
1666 case OPC_BNE
: /* rx != rx */
1667 case OPC_BGTZ
: /* 0 > 0 */
1668 case OPC_BLTZ
: /* 0 < 0 */
1669 /* Treated as NOP */
1670 MIPS_DEBUG("bnever (NOP)");
1672 case OPC_BLTZAL
: /* 0 < 0 */
1673 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1674 gen_op_store_T0_gpr(31);
1675 MIPS_DEBUG("bnever and link");
1677 case OPC_BLTZALL
: /* 0 < 0 likely */
1678 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1679 gen_op_store_T0_gpr(31);
1680 /* Skip the instruction in the delay slot */
1681 MIPS_DEBUG("bnever, link and skip");
1684 case OPC_BNEL
: /* rx != rx likely */
1685 case OPC_BGTZL
: /* 0 > 0 likely */
1686 case OPC_BLTZL
: /* 0 < 0 likely */
1687 /* Skip the instruction in the delay slot */
1688 MIPS_DEBUG("bnever and skip");
1692 ctx
->hflags
|= MIPS_HFLAG_B
;
1693 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1697 ctx
->hflags
|= MIPS_HFLAG_B
;
1698 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1701 ctx
->hflags
|= MIPS_HFLAG_BR
;
1702 MIPS_DEBUG("jr %s", regnames
[rs
]);
1706 ctx
->hflags
|= MIPS_HFLAG_BR
;
1707 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1710 MIPS_INVAL("branch/jump");
1711 generate_exception(ctx
, EXCP_RI
);
1718 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1719 regnames
[rs
], regnames
[rt
], btarget
);
1723 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1724 regnames
[rs
], regnames
[rt
], btarget
);
1728 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1729 regnames
[rs
], regnames
[rt
], btarget
);
1733 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1734 regnames
[rs
], regnames
[rt
], btarget
);
1738 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1742 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1746 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1752 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1756 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1760 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1764 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1768 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1772 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1776 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1781 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1783 ctx
->hflags
|= MIPS_HFLAG_BC
;
1789 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1791 ctx
->hflags
|= MIPS_HFLAG_BL
;
1793 gen_op_save_bcond();
1796 MIPS_INVAL("conditional branch/jump");
1797 generate_exception(ctx
, EXCP_RI
);
1801 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
1802 blink
, ctx
->hflags
, btarget
);
1804 ctx
->btarget
= btarget
;
1806 GEN_LOAD_IMM_TN(T0
, ctx
->pc
+ 8);
1807 gen_op_store_T0_gpr(blink
);
1811 /* special3 bitfield operations */
1812 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
1813 int rs
, int lsb
, int msb
)
1815 GEN_LOAD_REG_TN(T1
, rs
);
1820 gen_op_ext(lsb
, msb
+ 1);
1825 gen_op_ext(lsb
, msb
+ 1 + 32);
1830 gen_op_ext(lsb
+ 32, msb
+ 1);
1833 gen_op_ext(lsb
, msb
+ 1);
1838 GEN_LOAD_REG_TN(T0
, rt
);
1839 gen_op_ins(lsb
, msb
- lsb
+ 1);
1844 GEN_LOAD_REG_TN(T0
, rt
);
1845 gen_op_ins(lsb
, msb
- lsb
+ 1 + 32);
1850 GEN_LOAD_REG_TN(T0
, rt
);
1851 gen_op_ins(lsb
+ 32, msb
- lsb
+ 1);
1856 GEN_LOAD_REG_TN(T0
, rt
);
1857 gen_op_ins(lsb
, msb
- lsb
+ 1);
1861 MIPS_INVAL("bitops");
1862 generate_exception(ctx
, EXCP_RI
);
1865 GEN_STORE_TN_REG(rt
, T0
);
1868 /* CP0 (MMU and control) */
1869 static void gen_mfc0 (DisasContext
*ctx
, int reg
, int sel
)
1871 const char *rn
= "invalid";
1877 gen_op_mfc0_index();
1881 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1885 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1889 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1899 gen_op_mfc0_random();
1903 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1907 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1911 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1915 // gen_op_mfc0_YQMask(); /* MT ASE */
1919 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1923 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1924 rn
= "VPEScheFBack";
1927 // gen_op_mfc0_vpeopt(); /* MT ASE */
1937 gen_op_mfc0_entrylo0();
1941 // gen_op_mfc0_tcstatus(); /* MT ASE */
1945 // gen_op_mfc0_tcbind(); /* MT ASE */
1949 // gen_op_mfc0_tcrestart(); /* MT ASE */
1953 // gen_op_mfc0_tchalt(); /* MT ASE */
1957 // gen_op_mfc0_tccontext(); /* MT ASE */
1961 // gen_op_mfc0_tcschedule(); /* MT ASE */
1965 // gen_op_mfc0_tcschefback(); /* MT ASE */
1975 gen_op_mfc0_entrylo1();
1985 gen_op_mfc0_context();
1989 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1990 rn
= "ContextConfig";
1999 gen_op_mfc0_pagemask();
2003 gen_op_mfc0_pagegrain();
2013 gen_op_mfc0_wired();
2017 // gen_op_mfc0_srsconf0(); /* shadow registers */
2021 // gen_op_mfc0_srsconf1(); /* shadow registers */
2025 // gen_op_mfc0_srsconf2(); /* shadow registers */
2029 // gen_op_mfc0_srsconf3(); /* shadow registers */
2033 // gen_op_mfc0_srsconf4(); /* shadow registers */
2043 gen_op_mfc0_hwrena();
2053 gen_op_mfc0_badvaddr();
2063 gen_op_mfc0_count();
2066 /* 6,7 are implementation dependent */
2074 gen_op_mfc0_entryhi();
2084 gen_op_mfc0_compare();
2087 /* 6,7 are implementation dependent */
2095 gen_op_mfc0_status();
2099 gen_op_mfc0_intctl();
2103 gen_op_mfc0_srsctl();
2107 gen_op_mfc0_srsmap();
2117 gen_op_mfc0_cause();
2141 gen_op_mfc0_ebase();
2151 gen_op_mfc0_config0();
2155 gen_op_mfc0_config1();
2159 gen_op_mfc0_config2();
2163 gen_op_mfc0_config3();
2166 /* 4,5 are reserved */
2167 /* 6,7 are implementation dependent */
2169 gen_op_mfc0_config6();
2173 gen_op_mfc0_config7();
2183 gen_op_mfc0_lladdr();
2193 gen_op_mfc0_watchlo(sel
);
2203 gen_op_mfc0_watchhi(sel
);
2213 #ifdef TARGET_MIPS64
2214 gen_op_mfc0_xcontext();
2223 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2226 gen_op_mfc0_framemask();
2235 rn
= "'Diagnostic"; /* implementation dependent */
2240 gen_op_mfc0_debug(); /* EJTAG support */
2244 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2245 rn
= "TraceControl";
2248 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2249 rn
= "TraceControl2";
2252 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2253 rn
= "UserTraceData";
2256 // gen_op_mfc0_debug(); /* PDtrace support */
2266 gen_op_mfc0_depc(); /* EJTAG support */
2276 gen_op_mfc0_performance0();
2277 rn
= "Performance0";
2280 // gen_op_mfc0_performance1();
2281 rn
= "Performance1";
2284 // gen_op_mfc0_performance2();
2285 rn
= "Performance2";
2288 // gen_op_mfc0_performance3();
2289 rn
= "Performance3";
2292 // gen_op_mfc0_performance4();
2293 rn
= "Performance4";
2296 // gen_op_mfc0_performance5();
2297 rn
= "Performance5";
2300 // gen_op_mfc0_performance6();
2301 rn
= "Performance6";
2304 // gen_op_mfc0_performance7();
2305 rn
= "Performance7";
2330 gen_op_mfc0_taglo();
2337 gen_op_mfc0_datalo();
2350 gen_op_mfc0_taghi();
2357 gen_op_mfc0_datahi();
2367 gen_op_mfc0_errorepc();
2377 gen_op_mfc0_desave(); /* EJTAG support */
2387 #if defined MIPS_DEBUG_DISAS
2388 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2389 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2396 #if defined MIPS_DEBUG_DISAS
2397 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2398 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2402 generate_exception(ctx
, EXCP_RI
);
2405 static void gen_mtc0 (DisasContext
*ctx
, int reg
, int sel
)
2407 const char *rn
= "invalid";
2413 gen_op_mtc0_index();
2417 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2421 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2425 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2439 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2443 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2447 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2451 // gen_op_mtc0_YQMask(); /* MT ASE */
2455 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2459 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2460 rn
= "VPEScheFBack";
2463 // gen_op_mtc0_vpeopt(); /* MT ASE */
2473 gen_op_mtc0_entrylo0();
2477 // gen_op_mtc0_tcstatus(); /* MT ASE */
2481 // gen_op_mtc0_tcbind(); /* MT ASE */
2485 // gen_op_mtc0_tcrestart(); /* MT ASE */
2489 // gen_op_mtc0_tchalt(); /* MT ASE */
2493 // gen_op_mtc0_tccontext(); /* MT ASE */
2497 // gen_op_mtc0_tcschedule(); /* MT ASE */
2501 // gen_op_mtc0_tcschefback(); /* MT ASE */
2511 gen_op_mtc0_entrylo1();
2521 gen_op_mtc0_context();
2525 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2526 rn
= "ContextConfig";
2535 gen_op_mtc0_pagemask();
2539 gen_op_mtc0_pagegrain();
2549 gen_op_mtc0_wired();
2553 // gen_op_mtc0_srsconf0(); /* shadow registers */
2557 // gen_op_mtc0_srsconf1(); /* shadow registers */
2561 // gen_op_mtc0_srsconf2(); /* shadow registers */
2565 // gen_op_mtc0_srsconf3(); /* shadow registers */
2569 // gen_op_mtc0_srsconf4(); /* shadow registers */
2579 gen_op_mtc0_hwrena();
2593 gen_op_mtc0_count();
2596 /* 6,7 are implementation dependent */
2600 /* Stop translation as we may have switched the execution mode */
2601 ctx
->bstate
= BS_STOP
;
2606 gen_op_mtc0_entryhi();
2616 gen_op_mtc0_compare();
2619 /* 6,7 are implementation dependent */
2623 /* Stop translation as we may have switched the execution mode */
2624 ctx
->bstate
= BS_STOP
;
2629 gen_op_mtc0_status();
2630 /* BS_STOP isn't good enough here, hflags may have changed. */
2631 gen_save_pc(ctx
->pc
+ 4);
2632 ctx
->bstate
= BS_EXCP
;
2636 gen_op_mtc0_intctl();
2637 /* Stop translation as we may have switched the execution mode */
2638 ctx
->bstate
= BS_STOP
;
2642 gen_op_mtc0_srsctl();
2643 /* Stop translation as we may have switched the execution mode */
2644 ctx
->bstate
= BS_STOP
;
2648 gen_op_mtc0_srsmap();
2649 /* Stop translation as we may have switched the execution mode */
2650 ctx
->bstate
= BS_STOP
;
2660 gen_op_mtc0_cause();
2666 /* Stop translation as we may have switched the execution mode */
2667 ctx
->bstate
= BS_STOP
;
2686 gen_op_mtc0_ebase();
2696 gen_op_mtc0_config0();
2698 /* Stop translation as we may have switched the execution mode */
2699 ctx
->bstate
= BS_STOP
;
2702 /* ignored, read only */
2706 gen_op_mtc0_config2();
2708 /* Stop translation as we may have switched the execution mode */
2709 ctx
->bstate
= BS_STOP
;
2712 /* ignored, read only */
2715 /* 4,5 are reserved */
2716 /* 6,7 are implementation dependent */
2726 rn
= "Invalid config selector";
2743 gen_op_mtc0_watchlo(sel
);
2753 gen_op_mtc0_watchhi(sel
);
2763 #ifdef TARGET_MIPS64
2764 gen_op_mtc0_xcontext();
2773 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2776 gen_op_mtc0_framemask();
2785 rn
= "Diagnostic"; /* implementation dependent */
2790 gen_op_mtc0_debug(); /* EJTAG support */
2791 /* BS_STOP isn't good enough here, hflags may have changed. */
2792 gen_save_pc(ctx
->pc
+ 4);
2793 ctx
->bstate
= BS_EXCP
;
2797 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2798 rn
= "TraceControl";
2799 /* Stop translation as we may have switched the execution mode */
2800 ctx
->bstate
= BS_STOP
;
2803 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2804 rn
= "TraceControl2";
2805 /* Stop translation as we may have switched the execution mode */
2806 ctx
->bstate
= BS_STOP
;
2809 /* Stop translation as we may have switched the execution mode */
2810 ctx
->bstate
= BS_STOP
;
2811 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2812 rn
= "UserTraceData";
2813 /* Stop translation as we may have switched the execution mode */
2814 ctx
->bstate
= BS_STOP
;
2817 // gen_op_mtc0_debug(); /* PDtrace support */
2818 /* Stop translation as we may have switched the execution mode */
2819 ctx
->bstate
= BS_STOP
;
2829 gen_op_mtc0_depc(); /* EJTAG support */
2839 gen_op_mtc0_performance0();
2840 rn
= "Performance0";
2843 // gen_op_mtc0_performance1();
2844 rn
= "Performance1";
2847 // gen_op_mtc0_performance2();
2848 rn
= "Performance2";
2851 // gen_op_mtc0_performance3();
2852 rn
= "Performance3";
2855 // gen_op_mtc0_performance4();
2856 rn
= "Performance4";
2859 // gen_op_mtc0_performance5();
2860 rn
= "Performance5";
2863 // gen_op_mtc0_performance6();
2864 rn
= "Performance6";
2867 // gen_op_mtc0_performance7();
2868 rn
= "Performance7";
2894 gen_op_mtc0_taglo();
2901 gen_op_mtc0_datalo();
2914 gen_op_mtc0_taghi();
2921 gen_op_mtc0_datahi();
2932 gen_op_mtc0_errorepc();
2942 gen_op_mtc0_desave(); /* EJTAG support */
2948 /* Stop translation as we may have switched the execution mode */
2949 ctx
->bstate
= BS_STOP
;
2954 #if defined MIPS_DEBUG_DISAS
2955 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2956 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2963 #if defined MIPS_DEBUG_DISAS
2964 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2965 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2969 generate_exception(ctx
, EXCP_RI
);
2972 #ifdef TARGET_MIPS64
2973 static void gen_dmfc0 (DisasContext
*ctx
, int reg
, int sel
)
2975 const char *rn
= "invalid";
2981 gen_op_mfc0_index();
2985 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
2989 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
2993 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
3003 gen_op_mfc0_random();
3007 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
3011 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
3015 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
3019 // gen_op_dmfc0_YQMask(); /* MT ASE */
3023 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3027 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3028 rn
= "VPEScheFBack";
3031 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3041 gen_op_dmfc0_entrylo0();
3045 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3049 // gen_op_dmfc0_tcbind(); /* MT ASE */
3053 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3057 // gen_op_dmfc0_tchalt(); /* MT ASE */
3061 // gen_op_dmfc0_tccontext(); /* MT ASE */
3065 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3069 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3079 gen_op_dmfc0_entrylo1();
3089 gen_op_dmfc0_context();
3093 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3094 rn
= "ContextConfig";
3103 gen_op_mfc0_pagemask();
3107 gen_op_mfc0_pagegrain();
3117 gen_op_mfc0_wired();
3121 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3125 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3129 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3133 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3137 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3147 gen_op_mfc0_hwrena();
3157 gen_op_dmfc0_badvaddr();
3167 gen_op_mfc0_count();
3170 /* 6,7 are implementation dependent */
3178 gen_op_dmfc0_entryhi();
3188 gen_op_mfc0_compare();
3191 /* 6,7 are implementation dependent */
3199 gen_op_mfc0_status();
3203 gen_op_mfc0_intctl();
3207 gen_op_mfc0_srsctl();
3211 gen_op_mfc0_srsmap(); /* shadow registers */
3221 gen_op_mfc0_cause();
3245 gen_op_mfc0_ebase();
3255 gen_op_mfc0_config0();
3259 gen_op_mfc0_config1();
3263 gen_op_mfc0_config2();
3267 gen_op_mfc0_config3();
3270 /* 6,7 are implementation dependent */
3278 gen_op_dmfc0_lladdr();
3288 gen_op_dmfc0_watchlo(sel
);
3298 gen_op_mfc0_watchhi(sel
);
3308 #ifdef TARGET_MIPS64
3309 gen_op_dmfc0_xcontext();
3318 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3321 gen_op_mfc0_framemask();
3330 rn
= "'Diagnostic"; /* implementation dependent */
3335 gen_op_mfc0_debug(); /* EJTAG support */
3339 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3340 rn
= "TraceControl";
3343 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3344 rn
= "TraceControl2";
3347 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3348 rn
= "UserTraceData";
3351 // gen_op_dmfc0_debug(); /* PDtrace support */
3361 gen_op_dmfc0_depc(); /* EJTAG support */
3371 gen_op_mfc0_performance0();
3372 rn
= "Performance0";
3375 // gen_op_dmfc0_performance1();
3376 rn
= "Performance1";
3379 // gen_op_dmfc0_performance2();
3380 rn
= "Performance2";
3383 // gen_op_dmfc0_performance3();
3384 rn
= "Performance3";
3387 // gen_op_dmfc0_performance4();
3388 rn
= "Performance4";
3391 // gen_op_dmfc0_performance5();
3392 rn
= "Performance5";
3395 // gen_op_dmfc0_performance6();
3396 rn
= "Performance6";
3399 // gen_op_dmfc0_performance7();
3400 rn
= "Performance7";
3425 gen_op_mfc0_taglo();
3432 gen_op_mfc0_datalo();
3445 gen_op_mfc0_taghi();
3452 gen_op_mfc0_datahi();
3462 gen_op_dmfc0_errorepc();
3472 gen_op_mfc0_desave(); /* EJTAG support */
3482 #if defined MIPS_DEBUG_DISAS
3483 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3484 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3491 #if defined MIPS_DEBUG_DISAS
3492 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3493 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3497 generate_exception(ctx
, EXCP_RI
);
3500 static void gen_dmtc0 (DisasContext
*ctx
, int reg
, int sel
)
3502 const char *rn
= "invalid";
3508 gen_op_mtc0_index();
3512 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
3516 // gen_op_mtc0_mvpconf0(); /* MT ASE */
3520 // gen_op_mtc0_mvpconf1(); /* MT ASE */
3534 // gen_op_mtc0_vpecontrol(); /* MT ASE */
3538 // gen_op_mtc0_vpeconf0(); /* MT ASE */
3542 // gen_op_mtc0_vpeconf1(); /* MT ASE */
3546 // gen_op_mtc0_YQMask(); /* MT ASE */
3550 // gen_op_mtc0_vpeschedule(); /* MT ASE */
3554 // gen_op_mtc0_vpeschefback(); /* MT ASE */
3555 rn
= "VPEScheFBack";
3558 // gen_op_mtc0_vpeopt(); /* MT ASE */
3568 gen_op_mtc0_entrylo0();
3572 // gen_op_mtc0_tcstatus(); /* MT ASE */
3576 // gen_op_mtc0_tcbind(); /* MT ASE */
3580 // gen_op_mtc0_tcrestart(); /* MT ASE */
3584 // gen_op_mtc0_tchalt(); /* MT ASE */
3588 // gen_op_mtc0_tccontext(); /* MT ASE */
3592 // gen_op_mtc0_tcschedule(); /* MT ASE */
3596 // gen_op_mtc0_tcschefback(); /* MT ASE */
3606 gen_op_mtc0_entrylo1();
3616 gen_op_mtc0_context();
3620 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3621 rn
= "ContextConfig";
3630 gen_op_mtc0_pagemask();
3634 gen_op_mtc0_pagegrain();
3644 gen_op_mtc0_wired();
3648 // gen_op_mtc0_srsconf0(); /* shadow registers */
3652 // gen_op_mtc0_srsconf1(); /* shadow registers */
3656 // gen_op_mtc0_srsconf2(); /* shadow registers */
3660 // gen_op_mtc0_srsconf3(); /* shadow registers */
3664 // gen_op_mtc0_srsconf4(); /* shadow registers */
3674 gen_op_mtc0_hwrena();
3688 gen_op_mtc0_count();
3691 /* 6,7 are implementation dependent */
3695 /* Stop translation as we may have switched the execution mode */
3696 ctx
->bstate
= BS_STOP
;
3701 gen_op_mtc0_entryhi();
3711 gen_op_mtc0_compare();
3714 /* 6,7 are implementation dependent */
3718 /* Stop translation as we may have switched the execution mode */
3719 ctx
->bstate
= BS_STOP
;
3724 gen_op_mtc0_status();
3725 /* BS_STOP isn't good enough here, hflags may have changed. */
3726 gen_save_pc(ctx
->pc
+ 4);
3727 ctx
->bstate
= BS_EXCP
;
3731 gen_op_mtc0_intctl();
3732 /* Stop translation as we may have switched the execution mode */
3733 ctx
->bstate
= BS_STOP
;
3737 gen_op_mtc0_srsctl();
3738 /* Stop translation as we may have switched the execution mode */
3739 ctx
->bstate
= BS_STOP
;
3743 gen_op_mtc0_srsmap();
3744 /* Stop translation as we may have switched the execution mode */
3745 ctx
->bstate
= BS_STOP
;
3755 gen_op_mtc0_cause();
3761 /* Stop translation as we may have switched the execution mode */
3762 ctx
->bstate
= BS_STOP
;
3781 gen_op_mtc0_ebase();
3791 gen_op_mtc0_config0();
3793 /* Stop translation as we may have switched the execution mode */
3794 ctx
->bstate
= BS_STOP
;
3801 gen_op_mtc0_config2();
3803 /* Stop translation as we may have switched the execution mode */
3804 ctx
->bstate
= BS_STOP
;
3810 /* 6,7 are implementation dependent */
3812 rn
= "Invalid config selector";
3829 gen_op_mtc0_watchlo(sel
);
3839 gen_op_mtc0_watchhi(sel
);
3849 #ifdef TARGET_MIPS64
3850 gen_op_mtc0_xcontext();
3859 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3862 gen_op_mtc0_framemask();
3871 rn
= "Diagnostic"; /* implementation dependent */
3876 gen_op_mtc0_debug(); /* EJTAG support */
3877 /* BS_STOP isn't good enough here, hflags may have changed. */
3878 gen_save_pc(ctx
->pc
+ 4);
3879 ctx
->bstate
= BS_EXCP
;
3883 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3884 /* Stop translation as we may have switched the execution mode */
3885 ctx
->bstate
= BS_STOP
;
3886 rn
= "TraceControl";
3889 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3890 /* Stop translation as we may have switched the execution mode */
3891 ctx
->bstate
= BS_STOP
;
3892 rn
= "TraceControl2";
3895 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3896 /* Stop translation as we may have switched the execution mode */
3897 ctx
->bstate
= BS_STOP
;
3898 rn
= "UserTraceData";
3901 // gen_op_mtc0_debug(); /* PDtrace support */
3902 /* Stop translation as we may have switched the execution mode */
3903 ctx
->bstate
= BS_STOP
;
3913 gen_op_mtc0_depc(); /* EJTAG support */
3923 gen_op_mtc0_performance0();
3924 rn
= "Performance0";
3927 // gen_op_mtc0_performance1();
3928 rn
= "Performance1";
3931 // gen_op_mtc0_performance2();
3932 rn
= "Performance2";
3935 // gen_op_mtc0_performance3();
3936 rn
= "Performance3";
3939 // gen_op_mtc0_performance4();
3940 rn
= "Performance4";
3943 // gen_op_mtc0_performance5();
3944 rn
= "Performance5";
3947 // gen_op_mtc0_performance6();
3948 rn
= "Performance6";
3951 // gen_op_mtc0_performance7();
3952 rn
= "Performance7";
3978 gen_op_mtc0_taglo();
3985 gen_op_mtc0_datalo();
3998 gen_op_mtc0_taghi();
4005 gen_op_mtc0_datahi();
4016 gen_op_mtc0_errorepc();
4026 gen_op_mtc0_desave(); /* EJTAG support */
4032 /* Stop translation as we may have switched the execution mode */
4033 ctx
->bstate
= BS_STOP
;
4038 #if defined MIPS_DEBUG_DISAS
4039 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4040 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4047 #if defined MIPS_DEBUG_DISAS
4048 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4049 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4053 generate_exception(ctx
, EXCP_RI
);
4055 #endif /* TARGET_MIPS64 */
4057 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4059 const char *opn
= "ldst";
4067 gen_mfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4068 gen_op_store_T0_gpr(rt
);
4072 GEN_LOAD_REG_TN(T0
, rt
);
4073 gen_mtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4076 #ifdef TARGET_MIPS64
4082 gen_dmfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4083 gen_op_store_T0_gpr(rt
);
4087 GEN_LOAD_REG_TN(T0
, rt
);
4088 gen_dmtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4119 ctx
->bstate
= BS_EXCP
;
4123 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4125 generate_exception(ctx
, EXCP_RI
);
4128 ctx
->bstate
= BS_EXCP
;
4133 /* If we get an exception, we want to restart at next instruction */
4135 save_cpu_state(ctx
, 1);
4138 ctx
->bstate
= BS_EXCP
;
4143 generate_exception(ctx
, EXCP_RI
);
4146 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4149 /* CP1 Branches (before delay slot) */
4150 static void gen_compute_branch1 (DisasContext
*ctx
, uint32_t op
,
4151 int32_t cc
, int32_t offset
)
4153 target_ulong btarget
;
4154 const char *opn
= "cp1 cond branch";
4156 btarget
= ctx
->pc
+ 4 + offset
;
4175 ctx
->hflags
|= MIPS_HFLAG_BL
;
4177 gen_op_save_bcond();
4180 gen_op_bc1any2f(cc
);
4184 gen_op_bc1any2t(cc
);
4188 gen_op_bc1any4f(cc
);
4192 gen_op_bc1any4t(cc
);
4195 ctx
->hflags
|= MIPS_HFLAG_BC
;
4200 generate_exception (ctx
, EXCP_RI
);
4203 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4204 ctx
->hflags
, btarget
);
4205 ctx
->btarget
= btarget
;
4208 /* Coprocessor 1 (FPU) */
4210 #define FOP(func, fmt) (((fmt) << 21) | (func))
4212 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4214 const char *opn
= "cp1 move";
4218 GEN_LOAD_FREG_FTN(WT0
, fs
);
4220 GEN_STORE_TN_REG(rt
, T0
);
4224 GEN_LOAD_REG_TN(T0
, rt
);
4226 GEN_STORE_FTN_FREG(fs
, WT0
);
4230 GEN_LOAD_IMM_TN(T1
, fs
);
4232 GEN_STORE_TN_REG(rt
, T0
);
4236 GEN_LOAD_IMM_TN(T1
, fs
);
4237 GEN_LOAD_REG_TN(T0
, rt
);
4242 GEN_LOAD_FREG_FTN(DT0
, fs
);
4244 GEN_STORE_TN_REG(rt
, T0
);
4248 GEN_LOAD_REG_TN(T0
, rt
);
4250 GEN_STORE_FTN_FREG(fs
, DT0
);
4254 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4256 GEN_STORE_TN_REG(rt
, T0
);
4260 GEN_LOAD_REG_TN(T0
, rt
);
4262 GEN_STORE_FTN_FREG(fs
, WTH0
);
4267 generate_exception (ctx
, EXCP_RI
);
4270 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4273 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4277 GEN_LOAD_REG_TN(T0
, rd
);
4278 GEN_LOAD_REG_TN(T1
, rs
);
4280 ccbit
= 1 << (24 + cc
);
4287 GEN_STORE_TN_REG(rd
, T0
);
4290 #define GEN_MOVCF(fmt) \
4291 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4296 ccbit = 1 << (24 + cc); \
4300 glue(gen_op_float_movf_, fmt)(ccbit); \
4302 glue(gen_op_float_movt_, fmt)(ccbit); \
4309 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
4310 int ft
, int fs
, int fd
, int cc
)
4312 const char *opn
= "farith";
4313 const char *condnames
[] = {
4331 const char *condnames_abs
[] = {
4349 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
4350 uint32_t func
= ctx
->opcode
& 0x3f;
4352 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
4354 GEN_LOAD_FREG_FTN(WT0
, fs
);
4355 GEN_LOAD_FREG_FTN(WT1
, ft
);
4356 gen_op_float_add_s();
4357 GEN_STORE_FTN_FREG(fd
, WT2
);
4362 GEN_LOAD_FREG_FTN(WT0
, fs
);
4363 GEN_LOAD_FREG_FTN(WT1
, ft
);
4364 gen_op_float_sub_s();
4365 GEN_STORE_FTN_FREG(fd
, WT2
);
4370 GEN_LOAD_FREG_FTN(WT0
, fs
);
4371 GEN_LOAD_FREG_FTN(WT1
, ft
);
4372 gen_op_float_mul_s();
4373 GEN_STORE_FTN_FREG(fd
, WT2
);
4378 GEN_LOAD_FREG_FTN(WT0
, fs
);
4379 GEN_LOAD_FREG_FTN(WT1
, ft
);
4380 gen_op_float_div_s();
4381 GEN_STORE_FTN_FREG(fd
, WT2
);
4386 GEN_LOAD_FREG_FTN(WT0
, fs
);
4387 gen_op_float_sqrt_s();
4388 GEN_STORE_FTN_FREG(fd
, WT2
);
4392 GEN_LOAD_FREG_FTN(WT0
, fs
);
4393 gen_op_float_abs_s();
4394 GEN_STORE_FTN_FREG(fd
, WT2
);
4398 GEN_LOAD_FREG_FTN(WT0
, fs
);
4399 gen_op_float_mov_s();
4400 GEN_STORE_FTN_FREG(fd
, WT2
);
4404 GEN_LOAD_FREG_FTN(WT0
, fs
);
4405 gen_op_float_chs_s();
4406 GEN_STORE_FTN_FREG(fd
, WT2
);
4410 check_cp1_64bitmode(ctx
);
4411 GEN_LOAD_FREG_FTN(WT0
, fs
);
4412 gen_op_float_roundl_s();
4413 GEN_STORE_FTN_FREG(fd
, DT2
);
4417 check_cp1_64bitmode(ctx
);
4418 GEN_LOAD_FREG_FTN(WT0
, fs
);
4419 gen_op_float_truncl_s();
4420 GEN_STORE_FTN_FREG(fd
, DT2
);
4424 check_cp1_64bitmode(ctx
);
4425 GEN_LOAD_FREG_FTN(WT0
, fs
);
4426 gen_op_float_ceill_s();
4427 GEN_STORE_FTN_FREG(fd
, DT2
);
4431 check_cp1_64bitmode(ctx
);
4432 GEN_LOAD_FREG_FTN(WT0
, fs
);
4433 gen_op_float_floorl_s();
4434 GEN_STORE_FTN_FREG(fd
, DT2
);
4438 GEN_LOAD_FREG_FTN(WT0
, fs
);
4439 gen_op_float_roundw_s();
4440 GEN_STORE_FTN_FREG(fd
, WT2
);
4444 GEN_LOAD_FREG_FTN(WT0
, fs
);
4445 gen_op_float_truncw_s();
4446 GEN_STORE_FTN_FREG(fd
, WT2
);
4450 GEN_LOAD_FREG_FTN(WT0
, fs
);
4451 gen_op_float_ceilw_s();
4452 GEN_STORE_FTN_FREG(fd
, WT2
);
4456 GEN_LOAD_FREG_FTN(WT0
, fs
);
4457 gen_op_float_floorw_s();
4458 GEN_STORE_FTN_FREG(fd
, WT2
);
4462 GEN_LOAD_REG_TN(T0
, ft
);
4463 GEN_LOAD_FREG_FTN(WT0
, fs
);
4464 GEN_LOAD_FREG_FTN(WT2
, fd
);
4465 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
4466 GEN_STORE_FTN_FREG(fd
, WT2
);
4470 GEN_LOAD_REG_TN(T0
, ft
);
4471 GEN_LOAD_FREG_FTN(WT0
, fs
);
4472 GEN_LOAD_FREG_FTN(WT2
, fd
);
4473 gen_op_float_movz_s();
4474 GEN_STORE_FTN_FREG(fd
, WT2
);
4478 GEN_LOAD_REG_TN(T0
, ft
);
4479 GEN_LOAD_FREG_FTN(WT0
, fs
);
4480 GEN_LOAD_FREG_FTN(WT2
, fd
);
4481 gen_op_float_movn_s();
4482 GEN_STORE_FTN_FREG(fd
, WT2
);
4486 GEN_LOAD_FREG_FTN(WT0
, fs
);
4487 gen_op_float_recip_s();
4488 GEN_STORE_FTN_FREG(fd
, WT2
);
4492 GEN_LOAD_FREG_FTN(WT0
, fs
);
4493 gen_op_float_rsqrt_s();
4494 GEN_STORE_FTN_FREG(fd
, WT2
);
4498 check_cp1_64bitmode(ctx
);
4499 GEN_LOAD_FREG_FTN(WT0
, fs
);
4500 GEN_LOAD_FREG_FTN(WT2
, fd
);
4501 gen_op_float_recip2_s();
4502 GEN_STORE_FTN_FREG(fd
, WT2
);
4506 check_cp1_64bitmode(ctx
);
4507 GEN_LOAD_FREG_FTN(WT0
, fs
);
4508 gen_op_float_recip1_s();
4509 GEN_STORE_FTN_FREG(fd
, WT2
);
4513 check_cp1_64bitmode(ctx
);
4514 GEN_LOAD_FREG_FTN(WT0
, fs
);
4515 gen_op_float_rsqrt1_s();
4516 GEN_STORE_FTN_FREG(fd
, WT2
);
4520 check_cp1_64bitmode(ctx
);
4521 GEN_LOAD_FREG_FTN(WT0
, fs
);
4522 GEN_LOAD_FREG_FTN(WT2
, fd
);
4523 gen_op_float_rsqrt2_s();
4524 GEN_STORE_FTN_FREG(fd
, WT2
);
4528 check_cp1_registers(ctx
, fd
);
4529 GEN_LOAD_FREG_FTN(WT0
, fs
);
4530 gen_op_float_cvtd_s();
4531 GEN_STORE_FTN_FREG(fd
, DT2
);
4535 GEN_LOAD_FREG_FTN(WT0
, fs
);
4536 gen_op_float_cvtw_s();
4537 GEN_STORE_FTN_FREG(fd
, WT2
);
4541 check_cp1_64bitmode(ctx
);
4542 GEN_LOAD_FREG_FTN(WT0
, fs
);
4543 gen_op_float_cvtl_s();
4544 GEN_STORE_FTN_FREG(fd
, DT2
);
4548 check_cp1_64bitmode(ctx
);
4549 GEN_LOAD_FREG_FTN(WT1
, fs
);
4550 GEN_LOAD_FREG_FTN(WT0
, ft
);
4551 gen_op_float_cvtps_s();
4552 GEN_STORE_FTN_FREG(fd
, DT2
);
4571 GEN_LOAD_FREG_FTN(WT0
, fs
);
4572 GEN_LOAD_FREG_FTN(WT1
, ft
);
4573 if (ctx
->opcode
& (1 << 6)) {
4574 check_cp1_64bitmode(ctx
);
4575 gen_cmpabs_s(func
-48, cc
);
4576 opn
= condnames_abs
[func
-48];
4578 gen_cmp_s(func
-48, cc
);
4579 opn
= condnames
[func
-48];
4583 check_cp1_registers(ctx
, fs
| ft
| fd
);
4584 GEN_LOAD_FREG_FTN(DT0
, fs
);
4585 GEN_LOAD_FREG_FTN(DT1
, ft
);
4586 gen_op_float_add_d();
4587 GEN_STORE_FTN_FREG(fd
, DT2
);
4592 check_cp1_registers(ctx
, fs
| ft
| fd
);
4593 GEN_LOAD_FREG_FTN(DT0
, fs
);
4594 GEN_LOAD_FREG_FTN(DT1
, ft
);
4595 gen_op_float_sub_d();
4596 GEN_STORE_FTN_FREG(fd
, DT2
);
4601 check_cp1_registers(ctx
, fs
| ft
| fd
);
4602 GEN_LOAD_FREG_FTN(DT0
, fs
);
4603 GEN_LOAD_FREG_FTN(DT1
, ft
);
4604 gen_op_float_mul_d();
4605 GEN_STORE_FTN_FREG(fd
, DT2
);
4610 check_cp1_registers(ctx
, fs
| ft
| fd
);
4611 GEN_LOAD_FREG_FTN(DT0
, fs
);
4612 GEN_LOAD_FREG_FTN(DT1
, ft
);
4613 gen_op_float_div_d();
4614 GEN_STORE_FTN_FREG(fd
, DT2
);
4619 check_cp1_registers(ctx
, fs
| fd
);
4620 GEN_LOAD_FREG_FTN(DT0
, fs
);
4621 gen_op_float_sqrt_d();
4622 GEN_STORE_FTN_FREG(fd
, DT2
);
4626 check_cp1_registers(ctx
, fs
| fd
);
4627 GEN_LOAD_FREG_FTN(DT0
, fs
);
4628 gen_op_float_abs_d();
4629 GEN_STORE_FTN_FREG(fd
, DT2
);
4633 check_cp1_registers(ctx
, fs
| fd
);
4634 GEN_LOAD_FREG_FTN(DT0
, fs
);
4635 gen_op_float_mov_d();
4636 GEN_STORE_FTN_FREG(fd
, DT2
);
4640 check_cp1_registers(ctx
, fs
| fd
);
4641 GEN_LOAD_FREG_FTN(DT0
, fs
);
4642 gen_op_float_chs_d();
4643 GEN_STORE_FTN_FREG(fd
, DT2
);
4647 check_cp1_64bitmode(ctx
);
4648 GEN_LOAD_FREG_FTN(DT0
, fs
);
4649 gen_op_float_roundl_d();
4650 GEN_STORE_FTN_FREG(fd
, DT2
);
4654 check_cp1_64bitmode(ctx
);
4655 GEN_LOAD_FREG_FTN(DT0
, fs
);
4656 gen_op_float_truncl_d();
4657 GEN_STORE_FTN_FREG(fd
, DT2
);
4661 check_cp1_64bitmode(ctx
);
4662 GEN_LOAD_FREG_FTN(DT0
, fs
);
4663 gen_op_float_ceill_d();
4664 GEN_STORE_FTN_FREG(fd
, DT2
);
4668 check_cp1_64bitmode(ctx
);
4669 GEN_LOAD_FREG_FTN(DT0
, fs
);
4670 gen_op_float_floorl_d();
4671 GEN_STORE_FTN_FREG(fd
, DT2
);
4675 check_cp1_registers(ctx
, fs
);
4676 GEN_LOAD_FREG_FTN(DT0
, fs
);
4677 gen_op_float_roundw_d();
4678 GEN_STORE_FTN_FREG(fd
, WT2
);
4682 check_cp1_registers(ctx
, fs
);
4683 GEN_LOAD_FREG_FTN(DT0
, fs
);
4684 gen_op_float_truncw_d();
4685 GEN_STORE_FTN_FREG(fd
, WT2
);
4689 check_cp1_registers(ctx
, fs
);
4690 GEN_LOAD_FREG_FTN(DT0
, fs
);
4691 gen_op_float_ceilw_d();
4692 GEN_STORE_FTN_FREG(fd
, WT2
);
4696 check_cp1_registers(ctx
, fs
);
4697 GEN_LOAD_FREG_FTN(DT0
, fs
);
4698 gen_op_float_floorw_d();
4699 GEN_STORE_FTN_FREG(fd
, WT2
);
4703 GEN_LOAD_REG_TN(T0
, ft
);
4704 GEN_LOAD_FREG_FTN(DT0
, fs
);
4705 GEN_LOAD_FREG_FTN(DT2
, fd
);
4706 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
4707 GEN_STORE_FTN_FREG(fd
, DT2
);
4711 GEN_LOAD_REG_TN(T0
, ft
);
4712 GEN_LOAD_FREG_FTN(DT0
, fs
);
4713 GEN_LOAD_FREG_FTN(DT2
, fd
);
4714 gen_op_float_movz_d();
4715 GEN_STORE_FTN_FREG(fd
, DT2
);
4719 GEN_LOAD_REG_TN(T0
, ft
);
4720 GEN_LOAD_FREG_FTN(DT0
, fs
);
4721 GEN_LOAD_FREG_FTN(DT2
, fd
);
4722 gen_op_float_movn_d();
4723 GEN_STORE_FTN_FREG(fd
, DT2
);
4727 check_cp1_registers(ctx
, fs
| fd
);
4728 GEN_LOAD_FREG_FTN(DT0
, fs
);
4729 gen_op_float_recip_d();
4730 GEN_STORE_FTN_FREG(fd
, DT2
);
4734 check_cp1_registers(ctx
, fs
| fd
);
4735 GEN_LOAD_FREG_FTN(DT0
, fs
);
4736 gen_op_float_rsqrt_d();
4737 GEN_STORE_FTN_FREG(fd
, DT2
);
4741 check_cp1_64bitmode(ctx
);
4742 GEN_LOAD_FREG_FTN(DT0
, fs
);
4743 GEN_LOAD_FREG_FTN(DT2
, ft
);
4744 gen_op_float_recip2_d();
4745 GEN_STORE_FTN_FREG(fd
, DT2
);
4749 check_cp1_64bitmode(ctx
);
4750 GEN_LOAD_FREG_FTN(DT0
, fs
);
4751 gen_op_float_recip1_d();
4752 GEN_STORE_FTN_FREG(fd
, DT2
);
4756 check_cp1_64bitmode(ctx
);
4757 GEN_LOAD_FREG_FTN(DT0
, fs
);
4758 gen_op_float_rsqrt1_d();
4759 GEN_STORE_FTN_FREG(fd
, DT2
);
4763 check_cp1_64bitmode(ctx
);
4764 GEN_LOAD_FREG_FTN(DT0
, fs
);
4765 GEN_LOAD_FREG_FTN(DT2
, ft
);
4766 gen_op_float_rsqrt2_d();
4767 GEN_STORE_FTN_FREG(fd
, DT2
);
4786 GEN_LOAD_FREG_FTN(DT0
, fs
);
4787 GEN_LOAD_FREG_FTN(DT1
, ft
);
4788 if (ctx
->opcode
& (1 << 6)) {
4789 check_cp1_64bitmode(ctx
);
4790 gen_cmpabs_d(func
-48, cc
);
4791 opn
= condnames_abs
[func
-48];
4793 check_cp1_registers(ctx
, fs
| ft
);
4794 gen_cmp_d(func
-48, cc
);
4795 opn
= condnames
[func
-48];
4799 check_cp1_registers(ctx
, fs
);
4800 GEN_LOAD_FREG_FTN(DT0
, fs
);
4801 gen_op_float_cvts_d();
4802 GEN_STORE_FTN_FREG(fd
, WT2
);
4806 check_cp1_registers(ctx
, fs
);
4807 GEN_LOAD_FREG_FTN(DT0
, fs
);
4808 gen_op_float_cvtw_d();
4809 GEN_STORE_FTN_FREG(fd
, WT2
);
4813 check_cp1_64bitmode(ctx
);
4814 GEN_LOAD_FREG_FTN(DT0
, fs
);
4815 gen_op_float_cvtl_d();
4816 GEN_STORE_FTN_FREG(fd
, DT2
);
4820 GEN_LOAD_FREG_FTN(WT0
, fs
);
4821 gen_op_float_cvts_w();
4822 GEN_STORE_FTN_FREG(fd
, WT2
);
4826 check_cp1_registers(ctx
, fd
);
4827 GEN_LOAD_FREG_FTN(WT0
, fs
);
4828 gen_op_float_cvtd_w();
4829 GEN_STORE_FTN_FREG(fd
, DT2
);
4833 check_cp1_64bitmode(ctx
);
4834 GEN_LOAD_FREG_FTN(DT0
, fs
);
4835 gen_op_float_cvts_l();
4836 GEN_STORE_FTN_FREG(fd
, WT2
);
4840 check_cp1_64bitmode(ctx
);
4841 GEN_LOAD_FREG_FTN(DT0
, fs
);
4842 gen_op_float_cvtd_l();
4843 GEN_STORE_FTN_FREG(fd
, DT2
);
4848 check_cp1_64bitmode(ctx
);
4849 GEN_LOAD_FREG_FTN(WT0
, fs
);
4850 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4851 gen_op_float_cvtps_pw();
4852 GEN_STORE_FTN_FREG(fd
, WT2
);
4853 GEN_STORE_FTN_FREG(fd
, WTH2
);
4857 check_cp1_64bitmode(ctx
);
4858 GEN_LOAD_FREG_FTN(WT0
, fs
);
4859 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4860 GEN_LOAD_FREG_FTN(WT1
, ft
);
4861 GEN_LOAD_FREG_FTN(WTH1
, ft
);
4862 gen_op_float_add_ps();
4863 GEN_STORE_FTN_FREG(fd
, WT2
);
4864 GEN_STORE_FTN_FREG(fd
, WTH2
);
4868 check_cp1_64bitmode(ctx
);
4869 GEN_LOAD_FREG_FTN(WT0
, fs
);
4870 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4871 GEN_LOAD_FREG_FTN(WT1
, ft
);
4872 GEN_LOAD_FREG_FTN(WTH1
, ft
);
4873 gen_op_float_sub_ps();
4874 GEN_STORE_FTN_FREG(fd
, WT2
);
4875 GEN_STORE_FTN_FREG(fd
, WTH2
);
4879 check_cp1_64bitmode(ctx
);
4880 GEN_LOAD_FREG_FTN(WT0
, fs
);
4881 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4882 GEN_LOAD_FREG_FTN(WT1
, ft
);
4883 GEN_LOAD_FREG_FTN(WTH1
, ft
);
4884 gen_op_float_mul_ps();
4885 GEN_STORE_FTN_FREG(fd
, WT2
);
4886 GEN_STORE_FTN_FREG(fd
, WTH2
);
4890 check_cp1_64bitmode(ctx
);
4891 GEN_LOAD_FREG_FTN(WT0
, fs
);
4892 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4893 gen_op_float_abs_ps();
4894 GEN_STORE_FTN_FREG(fd
, WT2
);
4895 GEN_STORE_FTN_FREG(fd
, WTH2
);
4899 check_cp1_64bitmode(ctx
);
4900 GEN_LOAD_FREG_FTN(WT0
, fs
);
4901 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4902 gen_op_float_mov_ps();
4903 GEN_STORE_FTN_FREG(fd
, WT2
);
4904 GEN_STORE_FTN_FREG(fd
, WTH2
);
4908 check_cp1_64bitmode(ctx
);
4909 GEN_LOAD_FREG_FTN(WT0
, fs
);
4910 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4911 gen_op_float_chs_ps();
4912 GEN_STORE_FTN_FREG(fd
, WT2
);
4913 GEN_STORE_FTN_FREG(fd
, WTH2
);
4917 check_cp1_64bitmode(ctx
);
4918 GEN_LOAD_REG_TN(T0
, ft
);
4919 GEN_LOAD_FREG_FTN(WT0
, fs
);
4920 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4921 GEN_LOAD_FREG_FTN(WT2
, fd
);
4922 GEN_LOAD_FREG_FTN(WTH2
, fd
);
4923 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
4924 GEN_STORE_FTN_FREG(fd
, WT2
);
4925 GEN_STORE_FTN_FREG(fd
, WTH2
);
4929 check_cp1_64bitmode(ctx
);
4930 GEN_LOAD_REG_TN(T0
, ft
);
4931 GEN_LOAD_FREG_FTN(WT0
, fs
);
4932 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4933 GEN_LOAD_FREG_FTN(WT2
, fd
);
4934 GEN_LOAD_FREG_FTN(WTH2
, fd
);
4935 gen_op_float_movz_ps();
4936 GEN_STORE_FTN_FREG(fd
, WT2
);
4937 GEN_STORE_FTN_FREG(fd
, WTH2
);
4941 check_cp1_64bitmode(ctx
);
4942 GEN_LOAD_REG_TN(T0
, ft
);
4943 GEN_LOAD_FREG_FTN(WT0
, fs
);
4944 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4945 GEN_LOAD_FREG_FTN(WT2
, fd
);
4946 GEN_LOAD_FREG_FTN(WTH2
, fd
);
4947 gen_op_float_movn_ps();
4948 GEN_STORE_FTN_FREG(fd
, WT2
);
4949 GEN_STORE_FTN_FREG(fd
, WTH2
);
4953 check_cp1_64bitmode(ctx
);
4954 GEN_LOAD_FREG_FTN(WT0
, ft
);
4955 GEN_LOAD_FREG_FTN(WTH0
, ft
);
4956 GEN_LOAD_FREG_FTN(WT1
, fs
);
4957 GEN_LOAD_FREG_FTN(WTH1
, fs
);
4958 gen_op_float_addr_ps();
4959 GEN_STORE_FTN_FREG(fd
, WT2
);
4960 GEN_STORE_FTN_FREG(fd
, WTH2
);
4964 check_cp1_64bitmode(ctx
);
4965 GEN_LOAD_FREG_FTN(WT0
, ft
);
4966 GEN_LOAD_FREG_FTN(WTH0
, ft
);
4967 GEN_LOAD_FREG_FTN(WT1
, fs
);
4968 GEN_LOAD_FREG_FTN(WTH1
, fs
);
4969 gen_op_float_mulr_ps();
4970 GEN_STORE_FTN_FREG(fd
, WT2
);
4971 GEN_STORE_FTN_FREG(fd
, WTH2
);
4975 check_cp1_64bitmode(ctx
);
4976 GEN_LOAD_FREG_FTN(WT0
, fs
);
4977 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4978 GEN_LOAD_FREG_FTN(WT2
, fd
);
4979 GEN_LOAD_FREG_FTN(WTH2
, fd
);
4980 gen_op_float_recip2_ps();
4981 GEN_STORE_FTN_FREG(fd
, WT2
);
4982 GEN_STORE_FTN_FREG(fd
, WTH2
);
4986 check_cp1_64bitmode(ctx
);
4987 GEN_LOAD_FREG_FTN(WT0
, fs
);
4988 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4989 gen_op_float_recip1_ps();
4990 GEN_STORE_FTN_FREG(fd
, WT2
);
4991 GEN_STORE_FTN_FREG(fd
, WTH2
);
4995 check_cp1_64bitmode(ctx
);
4996 GEN_LOAD_FREG_FTN(WT0
, fs
);
4997 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4998 gen_op_float_rsqrt1_ps();
4999 GEN_STORE_FTN_FREG(fd
, WT2
);
5000 GEN_STORE_FTN_FREG(fd
, WTH2
);
5004 check_cp1_64bitmode(ctx
);
5005 GEN_LOAD_FREG_FTN(WT0
, fs
);
5006 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5007 GEN_LOAD_FREG_FTN(WT2
, fd
);
5008 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5009 gen_op_float_rsqrt2_ps();
5010 GEN_STORE_FTN_FREG(fd
, WT2
);
5011 GEN_STORE_FTN_FREG(fd
, WTH2
);
5015 check_cp1_64bitmode(ctx
);
5016 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5017 gen_op_float_cvts_pu();
5018 GEN_STORE_FTN_FREG(fd
, WT2
);
5022 check_cp1_64bitmode(ctx
);
5023 GEN_LOAD_FREG_FTN(WT0
, fs
);
5024 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5025 gen_op_float_cvtpw_ps();
5026 GEN_STORE_FTN_FREG(fd
, WT2
);
5027 GEN_STORE_FTN_FREG(fd
, WTH2
);
5031 check_cp1_64bitmode(ctx
);
5032 GEN_LOAD_FREG_FTN(WT0
, fs
);
5033 gen_op_float_cvts_pl();
5034 GEN_STORE_FTN_FREG(fd
, WT2
);
5038 check_cp1_64bitmode(ctx
);
5039 GEN_LOAD_FREG_FTN(WT0
, fs
);
5040 GEN_LOAD_FREG_FTN(WT1
, ft
);
5041 gen_op_float_pll_ps();
5042 GEN_STORE_FTN_FREG(fd
, DT2
);
5046 check_cp1_64bitmode(ctx
);
5047 GEN_LOAD_FREG_FTN(WT0
, fs
);
5048 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5049 gen_op_float_plu_ps();
5050 GEN_STORE_FTN_FREG(fd
, DT2
);
5054 check_cp1_64bitmode(ctx
);
5055 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5056 GEN_LOAD_FREG_FTN(WT1
, ft
);
5057 gen_op_float_pul_ps();
5058 GEN_STORE_FTN_FREG(fd
, DT2
);
5062 check_cp1_64bitmode(ctx
);
5063 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5064 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5065 gen_op_float_puu_ps();
5066 GEN_STORE_FTN_FREG(fd
, DT2
);
5085 check_cp1_64bitmode(ctx
);
5086 GEN_LOAD_FREG_FTN(WT0
, fs
);
5087 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5088 GEN_LOAD_FREG_FTN(WT1
, ft
);
5089 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5090 if (ctx
->opcode
& (1 << 6)) {
5091 gen_cmpabs_ps(func
-48, cc
);
5092 opn
= condnames_abs
[func
-48];
5094 gen_cmp_ps(func
-48, cc
);
5095 opn
= condnames
[func
-48];
5100 generate_exception (ctx
, EXCP_RI
);
5105 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5108 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5111 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5116 /* Coprocessor 3 (FPU) */
5117 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
5118 int fd
, int fs
, int base
, int index
)
5120 const char *opn
= "extended float load/store";
5123 /* All of those work only on 64bit FPUs. */
5124 check_cp1_64bitmode(ctx
);
5129 GEN_LOAD_REG_TN(T0
, index
);
5130 } else if (index
== 0) {
5131 GEN_LOAD_REG_TN(T0
, base
);
5133 GEN_LOAD_REG_TN(T0
, base
);
5134 GEN_LOAD_REG_TN(T1
, index
);
5137 /* Don't do NOP if destination is zero: we must perform the actual
5143 GEN_STORE_FTN_FREG(fd
, WT0
);
5148 GEN_STORE_FTN_FREG(fd
, DT0
);
5153 GEN_STORE_FTN_FREG(fd
, DT0
);
5157 GEN_LOAD_FREG_FTN(WT0
, fs
);
5163 GEN_LOAD_FREG_FTN(DT0
, fs
);
5169 GEN_LOAD_FREG_FTN(DT0
, fs
);
5176 generate_exception(ctx
, EXCP_RI
);
5179 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
5180 regnames
[index
], regnames
[base
]);
5183 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
5184 int fd
, int fr
, int fs
, int ft
)
5186 const char *opn
= "flt3_arith";
5188 /* All of those work only on 64bit FPUs. */
5189 check_cp1_64bitmode(ctx
);
5192 GEN_LOAD_REG_TN(T0
, fr
);
5193 GEN_LOAD_FREG_FTN(DT0
, fs
);
5194 GEN_LOAD_FREG_FTN(DT1
, ft
);
5195 gen_op_float_alnv_ps();
5196 GEN_STORE_FTN_FREG(fd
, DT2
);
5200 GEN_LOAD_FREG_FTN(WT0
, fs
);
5201 GEN_LOAD_FREG_FTN(WT1
, ft
);
5202 GEN_LOAD_FREG_FTN(WT2
, fr
);
5203 gen_op_float_muladd_s();
5204 GEN_STORE_FTN_FREG(fd
, WT2
);
5208 GEN_LOAD_FREG_FTN(DT0
, fs
);
5209 GEN_LOAD_FREG_FTN(DT1
, ft
);
5210 GEN_LOAD_FREG_FTN(DT2
, fr
);
5211 gen_op_float_muladd_d();
5212 GEN_STORE_FTN_FREG(fd
, DT2
);
5216 GEN_LOAD_FREG_FTN(WT0
, fs
);
5217 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5218 GEN_LOAD_FREG_FTN(WT1
, ft
);
5219 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5220 GEN_LOAD_FREG_FTN(WT2
, fr
);
5221 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5222 gen_op_float_muladd_ps();
5223 GEN_STORE_FTN_FREG(fd
, WT2
);
5224 GEN_STORE_FTN_FREG(fd
, WTH2
);
5228 GEN_LOAD_FREG_FTN(WT0
, fs
);
5229 GEN_LOAD_FREG_FTN(WT1
, ft
);
5230 GEN_LOAD_FREG_FTN(WT2
, fr
);
5231 gen_op_float_mulsub_s();
5232 GEN_STORE_FTN_FREG(fd
, WT2
);
5236 GEN_LOAD_FREG_FTN(DT0
, fs
);
5237 GEN_LOAD_FREG_FTN(DT1
, ft
);
5238 GEN_LOAD_FREG_FTN(DT2
, fr
);
5239 gen_op_float_mulsub_d();
5240 GEN_STORE_FTN_FREG(fd
, DT2
);
5244 GEN_LOAD_FREG_FTN(WT0
, fs
);
5245 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5246 GEN_LOAD_FREG_FTN(WT1
, ft
);
5247 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5248 GEN_LOAD_FREG_FTN(WT2
, fr
);
5249 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5250 gen_op_float_mulsub_ps();
5251 GEN_STORE_FTN_FREG(fd
, WT2
);
5252 GEN_STORE_FTN_FREG(fd
, WTH2
);
5256 GEN_LOAD_FREG_FTN(WT0
, fs
);
5257 GEN_LOAD_FREG_FTN(WT1
, ft
);
5258 GEN_LOAD_FREG_FTN(WT2
, fr
);
5259 gen_op_float_nmuladd_s();
5260 GEN_STORE_FTN_FREG(fd
, WT2
);
5264 GEN_LOAD_FREG_FTN(DT0
, fs
);
5265 GEN_LOAD_FREG_FTN(DT1
, ft
);
5266 GEN_LOAD_FREG_FTN(DT2
, fr
);
5267 gen_op_float_nmuladd_d();
5268 GEN_STORE_FTN_FREG(fd
, DT2
);
5272 GEN_LOAD_FREG_FTN(WT0
, fs
);
5273 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5274 GEN_LOAD_FREG_FTN(WT1
, ft
);
5275 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5276 GEN_LOAD_FREG_FTN(WT2
, fr
);
5277 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5278 gen_op_float_nmuladd_ps();
5279 GEN_STORE_FTN_FREG(fd
, WT2
);
5280 GEN_STORE_FTN_FREG(fd
, WTH2
);
5284 GEN_LOAD_FREG_FTN(WT0
, fs
);
5285 GEN_LOAD_FREG_FTN(WT1
, ft
);
5286 GEN_LOAD_FREG_FTN(WT2
, fr
);
5287 gen_op_float_nmulsub_s();
5288 GEN_STORE_FTN_FREG(fd
, WT2
);
5292 GEN_LOAD_FREG_FTN(DT0
, fs
);
5293 GEN_LOAD_FREG_FTN(DT1
, ft
);
5294 GEN_LOAD_FREG_FTN(DT2
, fr
);
5295 gen_op_float_nmulsub_d();
5296 GEN_STORE_FTN_FREG(fd
, DT2
);
5300 GEN_LOAD_FREG_FTN(WT0
, fs
);
5301 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5302 GEN_LOAD_FREG_FTN(WT1
, ft
);
5303 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5304 GEN_LOAD_FREG_FTN(WT2
, fr
);
5305 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5306 gen_op_float_nmulsub_ps();
5307 GEN_STORE_FTN_FREG(fd
, WT2
);
5308 GEN_STORE_FTN_FREG(fd
, WTH2
);
5313 generate_exception (ctx
, EXCP_RI
);
5316 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
5317 fregnames
[fs
], fregnames
[ft
]);
5320 /* ISA extensions (ASEs) */
5321 /* MIPS16 extension to MIPS32 */
5322 /* SmartMIPS extension to MIPS32 */
5324 #ifdef TARGET_MIPS64
5326 /* MDMX extension to MIPS64 */
5327 /* MIPS-3D extension to MIPS64 */
5331 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
5335 uint32_t op
, op1
, op2
;
5338 /* make sure instructions are on a word boundary */
5339 if (ctx
->pc
& 0x3) {
5340 env
->CP0_BadVAddr
= ctx
->pc
;
5341 generate_exception(ctx
, EXCP_AdEL
);
5345 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
5347 /* Handle blikely not taken case */
5348 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
5349 l1
= gen_new_label();
5351 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
5352 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5355 op
= MASK_OP_MAJOR(ctx
->opcode
);
5356 rs
= (ctx
->opcode
>> 21) & 0x1f;
5357 rt
= (ctx
->opcode
>> 16) & 0x1f;
5358 rd
= (ctx
->opcode
>> 11) & 0x1f;
5359 sa
= (ctx
->opcode
>> 6) & 0x1f;
5360 imm
= (int16_t)ctx
->opcode
;
5363 op1
= MASK_SPECIAL(ctx
->opcode
);
5365 case OPC_SLL
: /* Arithmetic with immediate */
5366 case OPC_SRL
... OPC_SRA
:
5367 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
5369 case OPC_SLLV
: /* Arithmetic */
5370 case OPC_SRLV
... OPC_SRAV
:
5371 case OPC_MOVZ
... OPC_MOVN
:
5372 case OPC_ADD
... OPC_NOR
:
5373 case OPC_SLT
... OPC_SLTU
:
5374 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5376 case OPC_MULT
... OPC_DIVU
:
5377 gen_muldiv(ctx
, op1
, rs
, rt
);
5379 case OPC_JR
... OPC_JALR
:
5380 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
5382 case OPC_TGE
... OPC_TEQ
: /* Traps */
5384 gen_trap(ctx
, op1
, rs
, rt
, -1);
5386 case OPC_MFHI
: /* Move from HI/LO */
5388 gen_HILO(ctx
, op1
, rd
);
5391 case OPC_MTLO
: /* Move to HI/LO */
5392 gen_HILO(ctx
, op1
, rs
);
5394 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
5395 #ifdef MIPS_STRICT_STANDARD
5396 MIPS_INVAL("PMON / selsl");
5397 generate_exception(ctx
, EXCP_RI
);
5403 generate_exception(ctx
, EXCP_SYSCALL
);
5406 /* XXX: Hack to work around wrong handling of self-modifying code. */
5408 save_cpu_state(ctx
, 1);
5410 generate_exception(ctx
, EXCP_BREAK
);
5413 #ifdef MIPS_STRICT_STANDARD
5415 generate_exception(ctx
, EXCP_RI
);
5417 /* Implemented as RI exception for now. */
5418 MIPS_INVAL("spim (unofficial)");
5419 generate_exception(ctx
, EXCP_RI
);
5423 /* Treat as a noop. */
5427 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5428 save_cpu_state(ctx
, 1);
5429 check_cp1_enabled(ctx
);
5430 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
5431 (ctx
->opcode
>> 16) & 1);
5433 generate_exception_err(ctx
, EXCP_CpU
, 1);
5437 #ifdef TARGET_MIPS64
5438 /* MIPS64 specific opcodes */
5440 case OPC_DSRL
... OPC_DSRA
:
5442 case OPC_DSRL32
... OPC_DSRA32
:
5443 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5444 generate_exception(ctx
, EXCP_RI
);
5445 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
5448 case OPC_DSRLV
... OPC_DSRAV
:
5449 case OPC_DADD
... OPC_DSUBU
:
5450 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5451 generate_exception(ctx
, EXCP_RI
);
5452 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5454 case OPC_DMULT
... OPC_DDIVU
:
5455 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5456 generate_exception(ctx
, EXCP_RI
);
5457 gen_muldiv(ctx
, op1
, rs
, rt
);
5460 default: /* Invalid */
5461 MIPS_INVAL("special");
5462 generate_exception(ctx
, EXCP_RI
);
5467 op1
= MASK_SPECIAL2(ctx
->opcode
);
5469 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
5470 case OPC_MSUB
... OPC_MSUBU
:
5471 gen_muldiv(ctx
, op1
, rs
, rt
);
5474 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5476 case OPC_CLZ
... OPC_CLO
:
5477 gen_cl(ctx
, op1
, rd
, rs
);
5480 /* XXX: not clear which exception should be raised
5481 * when in debug mode...
5483 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5484 generate_exception(ctx
, EXCP_DBp
);
5486 generate_exception(ctx
, EXCP_DBp
);
5488 /* Treat as a noop */
5490 #ifdef TARGET_MIPS64
5491 case OPC_DCLZ
... OPC_DCLO
:
5492 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5493 generate_exception(ctx
, EXCP_RI
);
5494 gen_cl(ctx
, op1
, rd
, rs
);
5497 default: /* Invalid */
5498 MIPS_INVAL("special2");
5499 generate_exception(ctx
, EXCP_RI
);
5504 op1
= MASK_SPECIAL3(ctx
->opcode
);
5508 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
5511 op2
= MASK_BSHFL(ctx
->opcode
);
5514 GEN_LOAD_REG_TN(T1
, rt
);
5518 GEN_LOAD_REG_TN(T1
, rt
);
5522 GEN_LOAD_REG_TN(T1
, rt
);
5525 default: /* Invalid */
5526 MIPS_INVAL("bshfl");
5527 generate_exception(ctx
, EXCP_RI
);
5530 GEN_STORE_TN_REG(rd
, T0
);
5535 save_cpu_state(ctx
, 1);
5536 gen_op_rdhwr_cpunum();
5539 save_cpu_state(ctx
, 1);
5540 gen_op_rdhwr_synci_step();
5543 save_cpu_state(ctx
, 1);
5547 save_cpu_state(ctx
, 1);
5548 gen_op_rdhwr_ccres();
5551 #if defined (CONFIG_USER_ONLY)
5552 gen_op_tls_value ();
5555 default: /* Invalid */
5556 MIPS_INVAL("rdhwr");
5557 generate_exception(ctx
, EXCP_RI
);
5560 GEN_STORE_TN_REG(rt
, T0
);
5562 #ifdef TARGET_MIPS64
5563 case OPC_DEXTM
... OPC_DEXT
:
5564 case OPC_DINSM
... OPC_DINS
:
5565 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5566 generate_exception(ctx
, EXCP_RI
);
5567 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
5570 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5571 generate_exception(ctx
, EXCP_RI
);
5572 op2
= MASK_DBSHFL(ctx
->opcode
);
5575 GEN_LOAD_REG_TN(T1
, rt
);
5579 GEN_LOAD_REG_TN(T1
, rt
);
5582 default: /* Invalid */
5583 MIPS_INVAL("dbshfl");
5584 generate_exception(ctx
, EXCP_RI
);
5587 GEN_STORE_TN_REG(rd
, T0
);
5589 default: /* Invalid */
5590 MIPS_INVAL("special3");
5591 generate_exception(ctx
, EXCP_RI
);
5596 op1
= MASK_REGIMM(ctx
->opcode
);
5598 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
5599 case OPC_BLTZAL
... OPC_BGEZALL
:
5600 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
5602 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
5604 gen_trap(ctx
, op1
, rs
, -1, imm
);
5609 default: /* Invalid */
5610 MIPS_INVAL("regimm");
5611 generate_exception(ctx
, EXCP_RI
);
5616 save_cpu_state(ctx
, 1);
5617 gen_op_cp0_enabled();
5618 op1
= MASK_CP0(ctx
->opcode
);
5622 #ifdef TARGET_MIPS64
5626 gen_cp0(env
, ctx
, op1
, rt
, rd
);
5628 case OPC_C0_FIRST
... OPC_C0_LAST
:
5629 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
5632 op2
= MASK_MFMC0(ctx
->opcode
);
5636 /* Stop translation as we may have switched the execution mode */
5637 ctx
->bstate
= BS_STOP
;
5641 /* Stop translation as we may have switched the execution mode */
5642 ctx
->bstate
= BS_STOP
;
5644 default: /* Invalid */
5645 MIPS_INVAL("mfmc0");
5646 generate_exception(ctx
, EXCP_RI
);
5649 GEN_STORE_TN_REG(rt
, T0
);
5653 if ((env
->CP0_Config0
& (0x7 << CP0C0_AR
)) == (1 << CP0C0_AR
)) {
5654 /* Shadow registers not implemented. */
5655 GEN_LOAD_REG_TN(T0
, rt
);
5656 GEN_STORE_TN_REG(rd
, T0
);
5658 MIPS_INVAL("shadow register move");
5659 generate_exception(ctx
, EXCP_RI
);
5664 generate_exception(ctx
, EXCP_RI
);
5668 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
5669 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
5671 case OPC_J
... OPC_JAL
: /* Jump */
5672 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
5673 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
5675 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
5676 case OPC_BEQL
... OPC_BGTZL
:
5677 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
5679 case OPC_LB
... OPC_LWR
: /* Load and stores */
5680 case OPC_SB
... OPC_SW
:
5684 gen_ldst(ctx
, op
, rt
, rs
, imm
);
5687 /* Treat as a noop */
5690 /* Treat as a noop */
5693 /* Floating point (COP1). */
5698 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5699 save_cpu_state(ctx
, 1);
5700 check_cp1_enabled(ctx
);
5701 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
5703 generate_exception_err(ctx
, EXCP_CpU
, 1);
5708 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5709 save_cpu_state(ctx
, 1);
5710 check_cp1_enabled(ctx
);
5711 op1
= MASK_CP1(ctx
->opcode
);
5717 #ifdef TARGET_MIPS64
5723 gen_cp1(ctx
, op1
, rt
, rd
);
5728 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
5729 (rt
>> 2) & 0x7, imm
<< 2);
5736 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
5741 generate_exception (ctx
, EXCP_RI
);
5745 generate_exception_err(ctx
, EXCP_CpU
, 1);
5755 /* COP2: Not implemented. */
5756 generate_exception_err(ctx
, EXCP_CpU
, 2);
5760 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5761 save_cpu_state(ctx
, 1);
5762 check_cp1_enabled(ctx
);
5763 op1
= MASK_CP3(ctx
->opcode
);
5771 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
5789 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
5793 generate_exception (ctx
, EXCP_RI
);
5797 generate_exception_err(ctx
, EXCP_CpU
, 1);
5801 #ifdef TARGET_MIPS64
5802 /* MIPS64 opcodes */
5804 case OPC_LDL
... OPC_LDR
:
5805 case OPC_SDL
... OPC_SDR
:
5810 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5811 generate_exception(ctx
, EXCP_RI
);
5812 gen_ldst(ctx
, op
, rt
, rs
, imm
);
5814 case OPC_DADDI
... OPC_DADDIU
:
5815 if (!(ctx
->hflags
& MIPS_HFLAG_64
))
5816 generate_exception(ctx
, EXCP_RI
);
5817 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
5820 #ifdef MIPS_HAS_MIPS16
5822 /* MIPS16: Not implemented. */
5824 #ifdef MIPS_HAS_MDMX
5826 /* MDMX: Not implemented. */
5828 default: /* Invalid */
5829 MIPS_INVAL("major opcode");
5830 generate_exception(ctx
, EXCP_RI
);
5833 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
5834 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
5835 /* Branches completion */
5836 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
5837 ctx
->bstate
= BS_BRANCH
;
5838 save_cpu_state(ctx
, 0);
5841 /* unconditional branch */
5842 MIPS_DEBUG("unconditional branch");
5843 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5846 /* blikely taken case */
5847 MIPS_DEBUG("blikely branch taken");
5848 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5851 /* Conditional branch */
5852 MIPS_DEBUG("conditional branch");
5855 l1
= gen_new_label();
5857 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5859 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5863 /* unconditional branch to register */
5864 MIPS_DEBUG("branch to register");
5870 MIPS_DEBUG("unknown branch");
5877 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
5881 target_ulong pc_start
;
5882 uint16_t *gen_opc_end
;
5885 if (search_pc
&& loglevel
)
5886 fprintf (logfile
, "search pc %d\n", search_pc
);
5889 gen_opc_ptr
= gen_opc_buf
;
5890 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
5891 gen_opparam_ptr
= gen_opparam_buf
;
5896 ctx
.bstate
= BS_NONE
;
5897 /* Restore delay slot state from the tb context. */
5898 ctx
.hflags
= tb
->flags
;
5899 restore_cpu_state(env
, &ctx
);
5900 #if defined(CONFIG_USER_ONLY)
5903 ctx
.mem_idx
= !((ctx
.hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_UM
);
5906 if (loglevel
& CPU_LOG_TB_CPU
) {
5907 fprintf(logfile
, "------------------------------------------------\n");
5908 /* FIXME: This may print out stale hflags from env... */
5909 cpu_dump_state(env
, logfile
, fprintf
, 0);
5912 #ifdef MIPS_DEBUG_DISAS
5913 if (loglevel
& CPU_LOG_TB_IN_ASM
)
5914 fprintf(logfile
, "\ntb %p super %d cond %04x\n",
5915 tb
, ctx
.mem_idx
, ctx
.hflags
);
5917 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
5918 if (env
->nb_breakpoints
> 0) {
5919 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
5920 if (env
->breakpoints
[j
] == ctx
.pc
) {
5921 save_cpu_state(&ctx
, 1);
5922 ctx
.bstate
= BS_BRANCH
;
5924 goto done_generating
;
5930 j
= gen_opc_ptr
- gen_opc_buf
;
5934 gen_opc_instr_start
[lj
++] = 0;
5936 gen_opc_pc
[lj
] = ctx
.pc
;
5937 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
5938 gen_opc_instr_start
[lj
] = 1;
5940 ctx
.opcode
= ldl_code(ctx
.pc
);
5941 decode_opc(env
, &ctx
);
5944 if (env
->singlestep_enabled
)
5947 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
5950 #if defined (MIPS_SINGLE_STEP)
5954 if (env
->singlestep_enabled
) {
5955 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
5958 switch (ctx
.bstate
) {
5960 gen_op_interrupt_restart();
5961 gen_goto_tb(&ctx
, 0, ctx
.pc
);
5964 save_cpu_state(&ctx
, 0);
5965 gen_goto_tb(&ctx
, 0, ctx
.pc
);
5968 gen_op_interrupt_restart();
5978 *gen_opc_ptr
= INDEX_op_end
;
5980 j
= gen_opc_ptr
- gen_opc_buf
;
5983 gen_opc_instr_start
[lj
++] = 0;
5986 tb
->size
= ctx
.pc
- pc_start
;
5989 #if defined MIPS_DEBUG_DISAS
5990 if (loglevel
& CPU_LOG_TB_IN_ASM
)
5991 fprintf(logfile
, "\n");
5993 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5994 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
5995 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
5996 fprintf(logfile
, "\n");
5998 if (loglevel
& CPU_LOG_TB_OP
) {
5999 fprintf(logfile
, "OP:\n");
6000 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6001 fprintf(logfile
, "\n");
6003 if (loglevel
& CPU_LOG_TB_CPU
) {
6004 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6011 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6013 return gen_intermediate_code_internal(env
, tb
, 0);
6016 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6018 return gen_intermediate_code_internal(env
, tb
, 1);
6021 void fpu_dump_state(CPUState
*env
, FILE *f
,
6022 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6026 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
6028 #define printfpr(fp) \
6031 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6032 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6033 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6036 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6037 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6038 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6039 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6040 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6045 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6046 env
->fcr0
, env
->fcr31
, is_fpu64
, env
->fp_status
, get_float_exception_flags(&env
->fp_status
));
6047 fpu_fprintf(f
, "FT0: "); printfpr(&env
->ft0
);
6048 fpu_fprintf(f
, "FT1: "); printfpr(&env
->ft1
);
6049 fpu_fprintf(f
, "FT2: "); printfpr(&env
->ft2
);
6050 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6051 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6052 printfpr(&env
->fpr
[i
]);
6058 void dump_fpu (CPUState
*env
)
6061 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6062 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
6063 fpu_dump_state(env
, logfile
, fprintf
, 0);
6067 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6068 /* Debug help: The architecture requires 32bit code to maintain proper
6069 sign-extened values on 64bit machines. */
6071 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6073 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6074 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6079 if (!SIGN_EXT_P(env
->PC
))
6080 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
);
6081 if (!SIGN_EXT_P(env
->HI
))
6082 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
);
6083 if (!SIGN_EXT_P(env
->LO
))
6084 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
);
6085 if (!SIGN_EXT_P(env
->btarget
))
6086 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6088 for (i
= 0; i
< 32; i
++) {
6089 if (!SIGN_EXT_P(env
->gpr
[i
]))
6090 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[i
]);
6093 if (!SIGN_EXT_P(env
->CP0_EPC
))
6094 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6095 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6096 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6100 void cpu_dump_state (CPUState
*env
, FILE *f
,
6101 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6106 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",
6107 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
6108 for (i
= 0; i
< 32; i
++) {
6110 cpu_fprintf(f
, "GPR%02d:", i
);
6111 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[i
]);
6113 cpu_fprintf(f
, "\n");
6116 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6117 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
6118 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6119 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6120 if (env
->hflags
& MIPS_HFLAG_FPU
)
6121 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6122 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6123 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6127 CPUMIPSState
*cpu_mips_init (void)
6131 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6139 void cpu_reset (CPUMIPSState
*env
)
6141 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6146 #if !defined(CONFIG_USER_ONLY)
6147 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6148 /* If the exception was raised from a delay slot,
6149 * come back to the jump. */
6150 env
->CP0_ErrorEPC
= env
->PC
- 4;
6152 env
->CP0_ErrorEPC
= env
->PC
;
6154 #ifdef TARGET_MIPS64
6155 env
->hflags
= MIPS_HFLAG_64
;
6159 env
->PC
= (int32_t)0xBFC00000;
6161 /* SMP not implemented */
6162 env
->CP0_EBase
= 0x80000000;
6163 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6164 /* vectored interrupts not implemented, timer on int 7,
6165 no performance counters. */
6166 env
->CP0_IntCtl
= 0xe0000000;
6170 for (i
= 0; i
< 7; i
++) {
6171 env
->CP0_WatchLo
[i
] = 0;
6172 env
->CP0_WatchHi
[i
] = 0x80000000;
6174 env
->CP0_WatchLo
[7] = 0;
6175 env
->CP0_WatchHi
[7] = 0;
6177 /* Count register increments in debug mode, EJTAG version 1 */
6178 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6180 env
->exception_index
= EXCP_NONE
;
6181 #if defined(CONFIG_USER_ONLY)
6182 env
->hflags
|= MIPS_HFLAG_UM
;
6183 env
->user_mode_only
= 1;
6187 #include "translate_init.c"