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); \
572 #define GEN_LOAD_IMM_TN(Tn, Imm) \
575 glue(gen_op_reset_, Tn)(); \
577 glue(gen_op_set_, Tn)(Imm); \
581 #define GEN_STORE_TN_REG(Rn, Tn) \
584 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
588 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
590 glue(gen_op_load_fpr_, FTn)(Fn); \
593 #define GEN_STORE_FTN_FREG(Fn, FTn) \
595 glue(gen_op_store_fpr_, FTn)(Fn); \
598 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
600 #if defined MIPS_DEBUG_DISAS
601 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
602 fprintf(logfile
, "hflags %08x saved %08x\n",
603 ctx
->hflags
, ctx
->saved_hflags
);
606 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
607 gen_op_save_pc(ctx
->pc
);
608 ctx
->saved_pc
= ctx
->pc
;
610 if (ctx
->hflags
!= ctx
->saved_hflags
) {
611 gen_op_save_state(ctx
->hflags
);
612 ctx
->saved_hflags
= ctx
->hflags
;
613 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
615 gen_op_save_breg_target();
621 /* bcond was already saved by the BL insn */
624 gen_op_save_btarget(ctx
->btarget
);
630 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
632 ctx
->saved_hflags
= ctx
->hflags
;
633 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
635 gen_op_restore_breg_target();
638 ctx
->btarget
= env
->btarget
;
642 ctx
->btarget
= env
->btarget
;
643 gen_op_restore_bcond();
648 static inline void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
650 #if defined MIPS_DEBUG_DISAS
651 if (loglevel
& CPU_LOG_TB_IN_ASM
)
652 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
654 save_cpu_state(ctx
, 1);
656 gen_op_raise_exception(excp
);
658 gen_op_raise_exception_err(excp
, err
);
659 ctx
->bstate
= BS_EXCP
;
662 static inline void generate_exception (DisasContext
*ctx
, int excp
)
664 generate_exception_err (ctx
, excp
, 0);
667 #if defined(CONFIG_USER_ONLY)
668 #define op_ldst(name) gen_op_##name##_raw()
669 #define OP_LD_TABLE(width)
670 #define OP_ST_TABLE(width)
672 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
673 #define OP_LD_TABLE(width) \
674 static GenOpFunc *gen_op_l##width[] = { \
675 &gen_op_l##width##_user, \
676 &gen_op_l##width##_kernel, \
678 #define OP_ST_TABLE(width) \
679 static GenOpFunc *gen_op_s##width[] = { \
680 &gen_op_s##width##_user, \
681 &gen_op_s##width##_kernel, \
722 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
723 int base
, int16_t offset
)
725 const char *opn
= "ldst";
728 GEN_LOAD_IMM_TN(T0
, offset
);
729 } else if (offset
== 0) {
730 gen_op_load_gpr_T0(base
);
732 gen_op_load_gpr_T0(base
);
733 gen_op_set_T1(offset
);
736 /* Don't do NOP if destination is zero: we must perform the actual
743 GEN_STORE_TN_REG(rt
, T0
);
748 GEN_STORE_TN_REG(rt
, T0
);
752 GEN_LOAD_REG_TN(T1
, rt
);
757 save_cpu_state(ctx
, 1);
758 GEN_LOAD_REG_TN(T1
, rt
);
760 GEN_STORE_TN_REG(rt
, T0
);
764 GEN_LOAD_REG_TN(T1
, rt
);
766 GEN_STORE_TN_REG(rt
, T0
);
770 GEN_LOAD_REG_TN(T1
, rt
);
775 GEN_LOAD_REG_TN(T1
, rt
);
777 GEN_STORE_TN_REG(rt
, T0
);
781 GEN_LOAD_REG_TN(T1
, rt
);
788 GEN_STORE_TN_REG(rt
, T0
);
793 GEN_STORE_TN_REG(rt
, T0
);
797 GEN_LOAD_REG_TN(T1
, rt
);
803 GEN_STORE_TN_REG(rt
, T0
);
807 GEN_LOAD_REG_TN(T1
, rt
);
813 GEN_STORE_TN_REG(rt
, T0
);
818 GEN_STORE_TN_REG(rt
, T0
);
822 GEN_LOAD_REG_TN(T1
, rt
);
828 GEN_STORE_TN_REG(rt
, T0
);
832 GEN_LOAD_REG_TN(T1
, rt
);
834 GEN_STORE_TN_REG(rt
, T0
);
838 GEN_LOAD_REG_TN(T1
, rt
);
843 GEN_LOAD_REG_TN(T1
, rt
);
845 GEN_STORE_TN_REG(rt
, T0
);
849 GEN_LOAD_REG_TN(T1
, rt
);
855 GEN_STORE_TN_REG(rt
, T0
);
859 save_cpu_state(ctx
, 1);
860 GEN_LOAD_REG_TN(T1
, rt
);
862 GEN_STORE_TN_REG(rt
, T0
);
867 generate_exception(ctx
, EXCP_RI
);
870 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
874 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
875 int base
, int16_t offset
)
877 const char *opn
= "flt_ldst";
880 GEN_LOAD_IMM_TN(T0
, offset
);
881 } else if (offset
== 0) {
882 gen_op_load_gpr_T0(base
);
884 gen_op_load_gpr_T0(base
);
885 gen_op_set_T1(offset
);
888 /* Don't do NOP if destination is zero: we must perform the actual
894 GEN_STORE_FTN_FREG(ft
, WT0
);
898 GEN_LOAD_FREG_FTN(WT0
, ft
);
904 GEN_STORE_FTN_FREG(ft
, DT0
);
908 GEN_LOAD_FREG_FTN(DT0
, ft
);
914 generate_exception(ctx
, EXCP_RI
);
917 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
920 /* Arithmetic with immediate operand */
921 static void gen_arith_imm (DisasContext
*ctx
, uint32_t opc
, int rt
,
925 const char *opn
= "imm arith";
927 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
928 /* if no destination, treat it as a NOP
929 * For addi, we must generate the overflow exception when needed.
934 uimm
= (uint16_t)imm
;
944 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
949 GEN_LOAD_REG_TN(T0
, rs
);
950 GEN_LOAD_IMM_TN(T1
, uimm
);
953 GEN_LOAD_IMM_TN(T0
, uimm
<< 16);
967 GEN_LOAD_REG_TN(T0
, rs
);
968 GEN_LOAD_IMM_TN(T1
, uimm
);
973 save_cpu_state(ctx
, 1);
983 save_cpu_state(ctx
, 1);
1024 switch ((ctx
->opcode
>> 21) & 0x1f) {
1034 MIPS_INVAL("invalid srl flag");
1035 generate_exception(ctx
, EXCP_RI
);
1039 #ifdef TARGET_MIPS64
1049 switch ((ctx
->opcode
>> 21) & 0x1f) {
1059 MIPS_INVAL("invalid dsrl flag");
1060 generate_exception(ctx
, EXCP_RI
);
1073 switch ((ctx
->opcode
>> 21) & 0x1f) {
1083 MIPS_INVAL("invalid dsrl32 flag");
1084 generate_exception(ctx
, EXCP_RI
);
1091 generate_exception(ctx
, EXCP_RI
);
1094 GEN_STORE_TN_REG(rt
, T0
);
1095 MIPS_DEBUG("%s %s, %s, %x", opn
, regnames
[rt
], regnames
[rs
], uimm
);
1099 static void gen_arith (DisasContext
*ctx
, uint32_t opc
,
1100 int rd
, int rs
, int rt
)
1102 const char *opn
= "arith";
1104 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1105 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1106 /* if no destination, treat it as a NOP
1107 * For add & sub, we must generate the overflow exception when needed.
1112 GEN_LOAD_REG_TN(T0
, rs
);
1113 GEN_LOAD_REG_TN(T1
, rt
);
1116 save_cpu_state(ctx
, 1);
1125 save_cpu_state(ctx
, 1);
1133 #ifdef TARGET_MIPS64
1135 save_cpu_state(ctx
, 1);
1144 save_cpu_state(ctx
, 1);
1198 switch ((ctx
->opcode
>> 6) & 0x1f) {
1208 MIPS_INVAL("invalid srlv flag");
1209 generate_exception(ctx
, EXCP_RI
);
1213 #ifdef TARGET_MIPS64
1223 switch ((ctx
->opcode
>> 6) & 0x1f) {
1233 MIPS_INVAL("invalid dsrlv flag");
1234 generate_exception(ctx
, EXCP_RI
);
1241 generate_exception(ctx
, EXCP_RI
);
1244 GEN_STORE_TN_REG(rd
, T0
);
1246 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1249 /* Arithmetic on HI/LO registers */
1250 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1252 const char *opn
= "hilo";
1254 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1255 /* Treat as a NOP */
1262 GEN_STORE_TN_REG(reg
, T0
);
1267 GEN_STORE_TN_REG(reg
, T0
);
1271 GEN_LOAD_REG_TN(T0
, reg
);
1276 GEN_LOAD_REG_TN(T0
, reg
);
1282 generate_exception(ctx
, EXCP_RI
);
1285 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1288 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1291 const char *opn
= "mul/div";
1293 GEN_LOAD_REG_TN(T0
, rs
);
1294 GEN_LOAD_REG_TN(T1
, rt
);
1312 #ifdef TARGET_MIPS64
1348 generate_exception(ctx
, EXCP_RI
);
1351 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1354 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1357 const char *opn
= "CLx";
1359 /* Treat as a NOP */
1363 GEN_LOAD_REG_TN(T0
, rs
);
1373 #ifdef TARGET_MIPS64
1385 generate_exception(ctx
, EXCP_RI
);
1388 gen_op_store_T0_gpr(rd
);
1389 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1393 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1394 int rs
, int rt
, int16_t imm
)
1399 /* Load needed operands */
1407 /* Compare two registers */
1409 GEN_LOAD_REG_TN(T0
, rs
);
1410 GEN_LOAD_REG_TN(T1
, rt
);
1420 /* Compare register to immediate */
1421 if (rs
!= 0 || imm
!= 0) {
1422 GEN_LOAD_REG_TN(T0
, rs
);
1423 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1430 case OPC_TEQ
: /* rs == rs */
1431 case OPC_TEQI
: /* r0 == 0 */
1432 case OPC_TGE
: /* rs >= rs */
1433 case OPC_TGEI
: /* r0 >= 0 */
1434 case OPC_TGEU
: /* rs >= rs unsigned */
1435 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1439 case OPC_TLT
: /* rs < rs */
1440 case OPC_TLTI
: /* r0 < 0 */
1441 case OPC_TLTU
: /* rs < rs unsigned */
1442 case OPC_TLTIU
: /* r0 < 0 unsigned */
1443 case OPC_TNE
: /* rs != rs */
1444 case OPC_TNEI
: /* r0 != 0 */
1445 /* Never trap: treat as NOP */
1449 generate_exception(ctx
, EXCP_RI
);
1480 generate_exception(ctx
, EXCP_RI
);
1484 save_cpu_state(ctx
, 1);
1486 ctx
->bstate
= BS_STOP
;
1489 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1491 TranslationBlock
*tb
;
1493 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1495 gen_op_goto_tb0(TBPARAM(tb
));
1497 gen_op_goto_tb1(TBPARAM(tb
));
1498 gen_op_save_pc(dest
);
1499 gen_op_set_T0((long)tb
+ n
);
1501 gen_op_save_pc(dest
);
1507 /* Branches (before delay slot) */
1508 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1509 int rs
, int rt
, int32_t offset
)
1511 target_ulong btarget
= -1;
1515 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1516 #ifdef MIPS_DEBUG_DISAS
1517 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1519 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
1523 generate_exception(ctx
, EXCP_RI
);
1527 /* Load needed operands */
1533 /* Compare two registers */
1535 GEN_LOAD_REG_TN(T0
, rs
);
1536 GEN_LOAD_REG_TN(T1
, rt
);
1539 btarget
= ctx
->pc
+ 4 + offset
;
1553 /* Compare to zero */
1555 gen_op_load_gpr_T0(rs
);
1558 btarget
= ctx
->pc
+ 4 + offset
;
1562 /* Jump to immediate */
1563 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | offset
;
1567 /* Jump to register */
1568 if (offset
!= 0 && offset
!= 16) {
1569 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1570 others are reserved. */
1571 MIPS_INVAL("jump hint");
1572 generate_exception(ctx
, EXCP_RI
);
1575 GEN_LOAD_REG_TN(T2
, rs
);
1578 MIPS_INVAL("branch/jump");
1579 generate_exception(ctx
, EXCP_RI
);
1583 /* No condition to be computed */
1585 case OPC_BEQ
: /* rx == rx */
1586 case OPC_BEQL
: /* rx == rx likely */
1587 case OPC_BGEZ
: /* 0 >= 0 */
1588 case OPC_BGEZL
: /* 0 >= 0 likely */
1589 case OPC_BLEZ
: /* 0 <= 0 */
1590 case OPC_BLEZL
: /* 0 <= 0 likely */
1592 ctx
->hflags
|= MIPS_HFLAG_B
;
1593 MIPS_DEBUG("balways");
1595 case OPC_BGEZAL
: /* 0 >= 0 */
1596 case OPC_BGEZALL
: /* 0 >= 0 likely */
1597 /* Always take and link */
1599 ctx
->hflags
|= MIPS_HFLAG_B
;
1600 MIPS_DEBUG("balways and link");
1602 case OPC_BNE
: /* rx != rx */
1603 case OPC_BGTZ
: /* 0 > 0 */
1604 case OPC_BLTZ
: /* 0 < 0 */
1605 /* Treated as NOP */
1606 MIPS_DEBUG("bnever (NOP)");
1608 case OPC_BLTZAL
: /* 0 < 0 */
1609 gen_op_set_T0(ctx
->pc
+ 8);
1610 gen_op_store_T0_gpr(31);
1611 MIPS_DEBUG("bnever and link");
1613 case OPC_BLTZALL
: /* 0 < 0 likely */
1614 gen_op_set_T0(ctx
->pc
+ 8);
1615 gen_op_store_T0_gpr(31);
1616 /* Skip the instruction in the delay slot */
1617 MIPS_DEBUG("bnever, link and skip");
1620 case OPC_BNEL
: /* rx != rx likely */
1621 case OPC_BGTZL
: /* 0 > 0 likely */
1622 case OPC_BLTZL
: /* 0 < 0 likely */
1623 /* Skip the instruction in the delay slot */
1624 MIPS_DEBUG("bnever and skip");
1628 ctx
->hflags
|= MIPS_HFLAG_B
;
1629 MIPS_DEBUG("j " TARGET_FMT_lx
, btarget
);
1633 ctx
->hflags
|= MIPS_HFLAG_B
;
1634 MIPS_DEBUG("jal " TARGET_FMT_lx
, btarget
);
1637 ctx
->hflags
|= MIPS_HFLAG_BR
;
1638 MIPS_DEBUG("jr %s", regnames
[rs
]);
1642 ctx
->hflags
|= MIPS_HFLAG_BR
;
1643 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1646 MIPS_INVAL("branch/jump");
1647 generate_exception(ctx
, EXCP_RI
);
1654 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
1655 regnames
[rs
], regnames
[rt
], btarget
);
1659 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
1660 regnames
[rs
], regnames
[rt
], btarget
);
1664 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
1665 regnames
[rs
], regnames
[rt
], btarget
);
1669 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
1670 regnames
[rs
], regnames
[rt
], btarget
);
1674 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1678 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1682 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1688 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1692 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1696 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1700 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1704 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1708 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1712 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1717 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1719 ctx
->hflags
|= MIPS_HFLAG_BC
;
1725 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btarget
);
1727 ctx
->hflags
|= MIPS_HFLAG_BL
;
1729 gen_op_save_bcond();
1732 MIPS_INVAL("conditional branch/jump");
1733 generate_exception(ctx
, EXCP_RI
);
1737 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
1738 blink
, ctx
->hflags
, btarget
);
1739 ctx
->btarget
= btarget
;
1741 gen_op_set_T0(ctx
->pc
+ 8);
1742 gen_op_store_T0_gpr(blink
);
1746 /* special3 bitfield operations */
1747 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
1748 int rs
, int lsb
, int msb
)
1750 GEN_LOAD_REG_TN(T1
, rs
);
1755 gen_op_ext(lsb
, msb
+ 1);
1760 gen_op_ext(lsb
, msb
+ 1 + 32);
1765 gen_op_ext(lsb
+ 32, msb
+ 1);
1768 gen_op_ext(lsb
, msb
+ 1);
1773 GEN_LOAD_REG_TN(T0
, rt
);
1774 gen_op_ins(lsb
, msb
- lsb
+ 1);
1779 GEN_LOAD_REG_TN(T0
, rt
);
1780 gen_op_ins(lsb
, msb
- lsb
+ 1 + 32);
1785 GEN_LOAD_REG_TN(T0
, rt
);
1786 gen_op_ins(lsb
+ 32, msb
- lsb
+ 1);
1791 GEN_LOAD_REG_TN(T0
, rt
);
1792 gen_op_ins(lsb
, msb
- lsb
+ 1);
1796 MIPS_INVAL("bitops");
1797 generate_exception(ctx
, EXCP_RI
);
1800 GEN_STORE_TN_REG(rt
, T0
);
1803 /* CP0 (MMU and control) */
1804 static void gen_mfc0 (DisasContext
*ctx
, int reg
, int sel
)
1806 const char *rn
= "invalid";
1812 gen_op_mfc0_index();
1816 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1820 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1824 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1834 gen_op_mfc0_random();
1838 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1842 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1846 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1850 // gen_op_mfc0_YQMask(); /* MT ASE */
1854 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1858 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1859 rn
= "VPEScheFBack";
1862 // gen_op_mfc0_vpeopt(); /* MT ASE */
1872 gen_op_mfc0_entrylo0();
1876 // gen_op_mfc0_tcstatus(); /* MT ASE */
1880 // gen_op_mfc0_tcbind(); /* MT ASE */
1884 // gen_op_mfc0_tcrestart(); /* MT ASE */
1888 // gen_op_mfc0_tchalt(); /* MT ASE */
1892 // gen_op_mfc0_tccontext(); /* MT ASE */
1896 // gen_op_mfc0_tcschedule(); /* MT ASE */
1900 // gen_op_mfc0_tcschefback(); /* MT ASE */
1910 gen_op_mfc0_entrylo1();
1920 gen_op_mfc0_context();
1924 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1925 rn
= "ContextConfig";
1934 gen_op_mfc0_pagemask();
1938 gen_op_mfc0_pagegrain();
1948 gen_op_mfc0_wired();
1952 // gen_op_mfc0_srsconf0(); /* shadow registers */
1956 // gen_op_mfc0_srsconf1(); /* shadow registers */
1960 // gen_op_mfc0_srsconf2(); /* shadow registers */
1964 // gen_op_mfc0_srsconf3(); /* shadow registers */
1968 // gen_op_mfc0_srsconf4(); /* shadow registers */
1978 gen_op_mfc0_hwrena();
1988 gen_op_mfc0_badvaddr();
1998 gen_op_mfc0_count();
2001 /* 6,7 are implementation dependent */
2009 gen_op_mfc0_entryhi();
2019 gen_op_mfc0_compare();
2022 /* 6,7 are implementation dependent */
2030 gen_op_mfc0_status();
2034 gen_op_mfc0_intctl();
2038 gen_op_mfc0_srsctl();
2042 // gen_op_mfc0_srsmap(); /* shadow registers */
2052 gen_op_mfc0_cause();
2076 gen_op_mfc0_ebase();
2086 gen_op_mfc0_config0();
2090 gen_op_mfc0_config1();
2094 gen_op_mfc0_config2();
2098 gen_op_mfc0_config3();
2101 /* 4,5 are reserved */
2102 /* 6,7 are implementation dependent */
2104 gen_op_mfc0_config6();
2108 gen_op_mfc0_config7();
2118 gen_op_mfc0_lladdr();
2128 gen_op_mfc0_watchlo0();
2132 // gen_op_mfc0_watchlo1();
2136 // gen_op_mfc0_watchlo2();
2140 // gen_op_mfc0_watchlo3();
2144 // gen_op_mfc0_watchlo4();
2148 // gen_op_mfc0_watchlo5();
2152 // gen_op_mfc0_watchlo6();
2156 // gen_op_mfc0_watchlo7();
2166 gen_op_mfc0_watchhi0();
2170 // gen_op_mfc0_watchhi1();
2174 // gen_op_mfc0_watchhi2();
2178 // gen_op_mfc0_watchhi3();
2182 // gen_op_mfc0_watchhi4();
2186 // gen_op_mfc0_watchhi5();
2190 // gen_op_mfc0_watchhi6();
2194 // gen_op_mfc0_watchhi7();
2204 #ifdef TARGET_MIPS64
2205 gen_op_mfc0_xcontext();
2214 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2217 gen_op_mfc0_framemask();
2226 rn
= "'Diagnostic"; /* implementation dependent */
2231 gen_op_mfc0_debug(); /* EJTAG support */
2235 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2236 rn
= "TraceControl";
2239 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2240 rn
= "TraceControl2";
2243 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2244 rn
= "UserTraceData";
2247 // gen_op_mfc0_debug(); /* PDtrace support */
2257 gen_op_mfc0_depc(); /* EJTAG support */
2267 gen_op_mfc0_performance0();
2268 rn
= "Performance0";
2271 // gen_op_mfc0_performance1();
2272 rn
= "Performance1";
2275 // gen_op_mfc0_performance2();
2276 rn
= "Performance2";
2279 // gen_op_mfc0_performance3();
2280 rn
= "Performance3";
2283 // gen_op_mfc0_performance4();
2284 rn
= "Performance4";
2287 // gen_op_mfc0_performance5();
2288 rn
= "Performance5";
2291 // gen_op_mfc0_performance6();
2292 rn
= "Performance6";
2295 // gen_op_mfc0_performance7();
2296 rn
= "Performance7";
2321 gen_op_mfc0_taglo();
2328 gen_op_mfc0_datalo();
2341 gen_op_mfc0_taghi();
2348 gen_op_mfc0_datahi();
2358 gen_op_mfc0_errorepc();
2368 gen_op_mfc0_desave(); /* EJTAG support */
2378 #if defined MIPS_DEBUG_DISAS
2379 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2380 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2387 #if defined MIPS_DEBUG_DISAS
2388 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2389 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2393 generate_exception(ctx
, EXCP_RI
);
2396 static void gen_mtc0 (DisasContext
*ctx
, int reg
, int sel
)
2398 const char *rn
= "invalid";
2404 gen_op_mtc0_index();
2408 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2412 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2416 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2430 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2434 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2438 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2442 // gen_op_mtc0_YQMask(); /* MT ASE */
2446 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2450 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2451 rn
= "VPEScheFBack";
2454 // gen_op_mtc0_vpeopt(); /* MT ASE */
2464 gen_op_mtc0_entrylo0();
2468 // gen_op_mtc0_tcstatus(); /* MT ASE */
2472 // gen_op_mtc0_tcbind(); /* MT ASE */
2476 // gen_op_mtc0_tcrestart(); /* MT ASE */
2480 // gen_op_mtc0_tchalt(); /* MT ASE */
2484 // gen_op_mtc0_tccontext(); /* MT ASE */
2488 // gen_op_mtc0_tcschedule(); /* MT ASE */
2492 // gen_op_mtc0_tcschefback(); /* MT ASE */
2502 gen_op_mtc0_entrylo1();
2512 gen_op_mtc0_context();
2516 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2517 rn
= "ContextConfig";
2526 gen_op_mtc0_pagemask();
2530 gen_op_mtc0_pagegrain();
2540 gen_op_mtc0_wired();
2544 // gen_op_mtc0_srsconf0(); /* shadow registers */
2548 // gen_op_mtc0_srsconf1(); /* shadow registers */
2552 // gen_op_mtc0_srsconf2(); /* shadow registers */
2556 // gen_op_mtc0_srsconf3(); /* shadow registers */
2560 // gen_op_mtc0_srsconf4(); /* shadow registers */
2570 gen_op_mtc0_hwrena();
2584 gen_op_mtc0_count();
2587 /* 6,7 are implementation dependent */
2591 /* Stop translation as we may have switched the execution mode */
2592 ctx
->bstate
= BS_STOP
;
2597 gen_op_mtc0_entryhi();
2607 gen_op_mtc0_compare();
2610 /* 6,7 are implementation dependent */
2614 /* Stop translation as we may have switched the execution mode */
2615 ctx
->bstate
= BS_STOP
;
2620 gen_op_mtc0_status();
2624 gen_op_mtc0_intctl();
2628 gen_op_mtc0_srsctl();
2632 // gen_op_mtc0_srsmap(); /* shadow registers */
2638 /* Stop translation as we may have switched the execution mode */
2639 ctx
->bstate
= BS_STOP
;
2644 gen_op_mtc0_cause();
2650 /* Stop translation as we may have switched the execution mode */
2651 ctx
->bstate
= BS_STOP
;
2670 gen_op_mtc0_ebase();
2680 gen_op_mtc0_config0();
2682 /* Stop translation as we may have switched the execution mode */
2683 ctx
->bstate
= BS_STOP
;
2686 /* ignored, read only */
2690 gen_op_mtc0_config2();
2692 /* Stop translation as we may have switched the execution mode */
2693 ctx
->bstate
= BS_STOP
;
2696 /* ignored, read only */
2699 /* 4,5 are reserved */
2700 /* 6,7 are implementation dependent */
2710 rn
= "Invalid config selector";
2727 gen_op_mtc0_watchlo0();
2731 // gen_op_mtc0_watchlo1();
2735 // gen_op_mtc0_watchlo2();
2739 // gen_op_mtc0_watchlo3();
2743 // gen_op_mtc0_watchlo4();
2747 // gen_op_mtc0_watchlo5();
2751 // gen_op_mtc0_watchlo6();
2755 // gen_op_mtc0_watchlo7();
2765 gen_op_mtc0_watchhi0();
2769 // gen_op_mtc0_watchhi1();
2773 // gen_op_mtc0_watchhi2();
2777 // gen_op_mtc0_watchhi3();
2781 // gen_op_mtc0_watchhi4();
2785 // gen_op_mtc0_watchhi5();
2789 // gen_op_mtc0_watchhi6();
2793 // gen_op_mtc0_watchhi7();
2803 #ifdef TARGET_MIPS64
2804 gen_op_mtc0_xcontext();
2813 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2816 gen_op_mtc0_framemask();
2825 rn
= "Diagnostic"; /* implementation dependent */
2830 gen_op_mtc0_debug(); /* EJTAG support */
2834 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2835 rn
= "TraceControl";
2838 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2839 rn
= "TraceControl2";
2842 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2843 rn
= "UserTraceData";
2846 // gen_op_mtc0_debug(); /* PDtrace support */
2852 /* Stop translation as we may have switched the execution mode */
2853 ctx
->bstate
= BS_STOP
;
2858 gen_op_mtc0_depc(); /* EJTAG support */
2868 gen_op_mtc0_performance0();
2869 rn
= "Performance0";
2872 // gen_op_mtc0_performance1();
2873 rn
= "Performance1";
2876 // gen_op_mtc0_performance2();
2877 rn
= "Performance2";
2880 // gen_op_mtc0_performance3();
2881 rn
= "Performance3";
2884 // gen_op_mtc0_performance4();
2885 rn
= "Performance4";
2888 // gen_op_mtc0_performance5();
2889 rn
= "Performance5";
2892 // gen_op_mtc0_performance6();
2893 rn
= "Performance6";
2896 // gen_op_mtc0_performance7();
2897 rn
= "Performance7";
2923 gen_op_mtc0_taglo();
2930 gen_op_mtc0_datalo();
2943 gen_op_mtc0_taghi();
2950 gen_op_mtc0_datahi();
2961 gen_op_mtc0_errorepc();
2971 gen_op_mtc0_desave(); /* EJTAG support */
2977 /* Stop translation as we may have switched the execution mode */
2978 ctx
->bstate
= BS_STOP
;
2983 #if defined MIPS_DEBUG_DISAS
2984 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2985 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2992 #if defined MIPS_DEBUG_DISAS
2993 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2994 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2998 generate_exception(ctx
, EXCP_RI
);
3001 #ifdef TARGET_MIPS64
3002 static void gen_dmfc0 (DisasContext
*ctx
, int reg
, int sel
)
3004 const char *rn
= "invalid";
3010 gen_op_mfc0_index();
3014 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
3018 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
3022 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
3032 gen_op_mfc0_random();
3036 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
3040 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
3044 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
3048 // gen_op_dmfc0_YQMask(); /* MT ASE */
3052 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3056 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3057 rn
= "VPEScheFBack";
3060 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3070 gen_op_dmfc0_entrylo0();
3074 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3078 // gen_op_dmfc0_tcbind(); /* MT ASE */
3082 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3086 // gen_op_dmfc0_tchalt(); /* MT ASE */
3090 // gen_op_dmfc0_tccontext(); /* MT ASE */
3094 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3098 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3108 gen_op_dmfc0_entrylo1();
3118 gen_op_dmfc0_context();
3122 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3123 rn
= "ContextConfig";
3132 gen_op_mfc0_pagemask();
3136 gen_op_mfc0_pagegrain();
3146 gen_op_mfc0_wired();
3150 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3154 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3158 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3162 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3166 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3176 gen_op_mfc0_hwrena();
3186 gen_op_dmfc0_badvaddr();
3196 gen_op_mfc0_count();
3199 /* 6,7 are implementation dependent */
3207 gen_op_dmfc0_entryhi();
3217 gen_op_mfc0_compare();
3220 /* 6,7 are implementation dependent */
3228 gen_op_mfc0_status();
3232 gen_op_mfc0_intctl();
3236 gen_op_mfc0_srsctl();
3240 gen_op_mfc0_srsmap(); /* shadow registers */
3250 gen_op_mfc0_cause();
3274 gen_op_mfc0_ebase();
3284 gen_op_mfc0_config0();
3288 gen_op_mfc0_config1();
3292 gen_op_mfc0_config2();
3296 gen_op_mfc0_config3();
3299 /* 6,7 are implementation dependent */
3307 gen_op_dmfc0_lladdr();
3317 gen_op_dmfc0_watchlo0();
3321 // gen_op_dmfc0_watchlo1();
3325 // gen_op_dmfc0_watchlo2();
3329 // gen_op_dmfc0_watchlo3();
3333 // gen_op_dmfc0_watchlo4();
3337 // gen_op_dmfc0_watchlo5();
3341 // gen_op_dmfc0_watchlo6();
3345 // gen_op_dmfc0_watchlo7();
3355 gen_op_mfc0_watchhi0();
3359 // gen_op_mfc0_watchhi1();
3363 // gen_op_mfc0_watchhi2();
3367 // gen_op_mfc0_watchhi3();
3371 // gen_op_mfc0_watchhi4();
3375 // gen_op_mfc0_watchhi5();
3379 // gen_op_mfc0_watchhi6();
3383 // gen_op_mfc0_watchhi7();
3393 #ifdef TARGET_MIPS64
3394 gen_op_dmfc0_xcontext();
3403 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3406 gen_op_mfc0_framemask();
3415 rn
= "'Diagnostic"; /* implementation dependent */
3420 gen_op_mfc0_debug(); /* EJTAG support */
3424 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3425 rn
= "TraceControl";
3428 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3429 rn
= "TraceControl2";
3432 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3433 rn
= "UserTraceData";
3436 // gen_op_dmfc0_debug(); /* PDtrace support */
3446 gen_op_dmfc0_depc(); /* EJTAG support */
3456 gen_op_mfc0_performance0();
3457 rn
= "Performance0";
3460 // gen_op_dmfc0_performance1();
3461 rn
= "Performance1";
3464 // gen_op_dmfc0_performance2();
3465 rn
= "Performance2";
3468 // gen_op_dmfc0_performance3();
3469 rn
= "Performance3";
3472 // gen_op_dmfc0_performance4();
3473 rn
= "Performance4";
3476 // gen_op_dmfc0_performance5();
3477 rn
= "Performance5";
3480 // gen_op_dmfc0_performance6();
3481 rn
= "Performance6";
3484 // gen_op_dmfc0_performance7();
3485 rn
= "Performance7";
3510 gen_op_mfc0_taglo();
3517 gen_op_mfc0_datalo();
3530 gen_op_mfc0_taghi();
3537 gen_op_mfc0_datahi();
3547 gen_op_dmfc0_errorepc();
3557 gen_op_mfc0_desave(); /* EJTAG support */
3567 #if defined MIPS_DEBUG_DISAS
3568 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3569 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3576 #if defined MIPS_DEBUG_DISAS
3577 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3578 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3582 generate_exception(ctx
, EXCP_RI
);
3585 static void gen_dmtc0 (DisasContext
*ctx
, int reg
, int sel
)
3587 const char *rn
= "invalid";
3593 gen_op_mtc0_index();
3597 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
3601 // gen_op_mtc0_mvpconf0(); /* MT ASE */
3605 // gen_op_mtc0_mvpconf1(); /* MT ASE */
3619 // gen_op_mtc0_vpecontrol(); /* MT ASE */
3623 // gen_op_mtc0_vpeconf0(); /* MT ASE */
3627 // gen_op_mtc0_vpeconf1(); /* MT ASE */
3631 // gen_op_mtc0_YQMask(); /* MT ASE */
3635 // gen_op_mtc0_vpeschedule(); /* MT ASE */
3639 // gen_op_mtc0_vpeschefback(); /* MT ASE */
3640 rn
= "VPEScheFBack";
3643 // gen_op_mtc0_vpeopt(); /* MT ASE */
3653 gen_op_mtc0_entrylo0();
3657 // gen_op_mtc0_tcstatus(); /* MT ASE */
3661 // gen_op_mtc0_tcbind(); /* MT ASE */
3665 // gen_op_mtc0_tcrestart(); /* MT ASE */
3669 // gen_op_mtc0_tchalt(); /* MT ASE */
3673 // gen_op_mtc0_tccontext(); /* MT ASE */
3677 // gen_op_mtc0_tcschedule(); /* MT ASE */
3681 // gen_op_mtc0_tcschefback(); /* MT ASE */
3691 gen_op_mtc0_entrylo1();
3701 gen_op_mtc0_context();
3705 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3706 rn
= "ContextConfig";
3715 gen_op_mtc0_pagemask();
3719 gen_op_mtc0_pagegrain();
3729 gen_op_mtc0_wired();
3733 // gen_op_mtc0_srsconf0(); /* shadow registers */
3737 // gen_op_mtc0_srsconf1(); /* shadow registers */
3741 // gen_op_mtc0_srsconf2(); /* shadow registers */
3745 // gen_op_mtc0_srsconf3(); /* shadow registers */
3749 // gen_op_mtc0_srsconf4(); /* shadow registers */
3759 gen_op_mtc0_hwrena();
3773 gen_op_mtc0_count();
3776 /* 6,7 are implementation dependent */
3780 /* Stop translation as we may have switched the execution mode */
3781 ctx
->bstate
= BS_STOP
;
3786 gen_op_mtc0_entryhi();
3796 gen_op_mtc0_compare();
3799 /* 6,7 are implementation dependent */
3803 /* Stop translation as we may have switched the execution mode */
3804 ctx
->bstate
= BS_STOP
;
3809 gen_op_mtc0_status();
3813 gen_op_mtc0_intctl();
3817 gen_op_mtc0_srsctl();
3821 gen_op_mtc0_srsmap(); /* shadow registers */
3827 /* Stop translation as we may have switched the execution mode */
3828 ctx
->bstate
= BS_STOP
;
3833 gen_op_mtc0_cause();
3839 /* Stop translation as we may have switched the execution mode */
3840 ctx
->bstate
= BS_STOP
;
3859 gen_op_mtc0_ebase();
3869 gen_op_mtc0_config0();
3871 /* Stop translation as we may have switched the execution mode */
3872 ctx
->bstate
= BS_STOP
;
3879 gen_op_mtc0_config2();
3881 /* Stop translation as we may have switched the execution mode */
3882 ctx
->bstate
= BS_STOP
;
3888 /* 6,7 are implementation dependent */
3890 rn
= "Invalid config selector";
3907 gen_op_mtc0_watchlo0();
3911 // gen_op_mtc0_watchlo1();
3915 // gen_op_mtc0_watchlo2();
3919 // gen_op_mtc0_watchlo3();
3923 // gen_op_mtc0_watchlo4();
3927 // gen_op_mtc0_watchlo5();
3931 // gen_op_mtc0_watchlo6();
3935 // gen_op_mtc0_watchlo7();
3945 gen_op_mtc0_watchhi0();
3949 // gen_op_mtc0_watchhi1();
3953 // gen_op_mtc0_watchhi2();
3957 // gen_op_mtc0_watchhi3();
3961 // gen_op_mtc0_watchhi4();
3965 // gen_op_mtc0_watchhi5();
3969 // gen_op_mtc0_watchhi6();
3973 // gen_op_mtc0_watchhi7();
3983 #ifdef TARGET_MIPS64
3984 gen_op_mtc0_xcontext();
3993 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3996 gen_op_mtc0_framemask();
4005 rn
= "Diagnostic"; /* implementation dependent */
4010 gen_op_mtc0_debug(); /* EJTAG support */
4014 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4015 rn
= "TraceControl";
4018 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4019 rn
= "TraceControl2";
4022 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4023 rn
= "UserTraceData";
4026 // gen_op_mtc0_debug(); /* PDtrace support */
4032 /* Stop translation as we may have switched the execution mode */
4033 ctx
->bstate
= BS_STOP
;
4038 gen_op_mtc0_depc(); /* EJTAG support */
4048 gen_op_mtc0_performance0();
4049 rn
= "Performance0";
4052 // gen_op_mtc0_performance1();
4053 rn
= "Performance1";
4056 // gen_op_mtc0_performance2();
4057 rn
= "Performance2";
4060 // gen_op_mtc0_performance3();
4061 rn
= "Performance3";
4064 // gen_op_mtc0_performance4();
4065 rn
= "Performance4";
4068 // gen_op_mtc0_performance5();
4069 rn
= "Performance5";
4072 // gen_op_mtc0_performance6();
4073 rn
= "Performance6";
4076 // gen_op_mtc0_performance7();
4077 rn
= "Performance7";
4103 gen_op_mtc0_taglo();
4110 gen_op_mtc0_datalo();
4123 gen_op_mtc0_taghi();
4130 gen_op_mtc0_datahi();
4141 gen_op_mtc0_errorepc();
4151 gen_op_mtc0_desave(); /* EJTAG support */
4157 /* Stop translation as we may have switched the execution mode */
4158 ctx
->bstate
= BS_STOP
;
4163 #if defined MIPS_DEBUG_DISAS
4164 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4165 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4172 #if defined MIPS_DEBUG_DISAS
4173 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4174 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4178 generate_exception(ctx
, EXCP_RI
);
4180 #endif /* TARGET_MIPS64 */
4182 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4184 const char *opn
= "ldst";
4192 gen_mfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4193 gen_op_store_T0_gpr(rt
);
4197 GEN_LOAD_REG_TN(T0
, rt
);
4198 gen_mtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4201 #ifdef TARGET_MIPS64
4207 gen_dmfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4208 gen_op_store_T0_gpr(rt
);
4212 GEN_LOAD_REG_TN(T0
, rt
);
4213 gen_dmtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4243 save_cpu_state(ctx
, 0);
4245 ctx
->bstate
= BS_EXCP
;
4249 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4251 generate_exception(ctx
, EXCP_RI
);
4253 save_cpu_state(ctx
, 0);
4255 ctx
->bstate
= BS_EXCP
;
4260 /* If we get an exception, we want to restart at next instruction */
4262 save_cpu_state(ctx
, 1);
4265 ctx
->bstate
= BS_EXCP
;
4270 generate_exception(ctx
, EXCP_RI
);
4273 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4276 /* CP1 Branches (before delay slot) */
4277 static void gen_compute_branch1 (DisasContext
*ctx
, uint32_t op
,
4278 int32_t cc
, int32_t offset
)
4280 target_ulong btarget
;
4281 const char *opn
= "cp1 cond branch";
4283 btarget
= ctx
->pc
+ 4 + offset
;
4302 ctx
->hflags
|= MIPS_HFLAG_BL
;
4304 gen_op_save_bcond();
4307 gen_op_bc1any2f(cc
);
4311 gen_op_bc1any2t(cc
);
4315 gen_op_bc1any4f(cc
);
4319 gen_op_bc1any4t(cc
);
4322 ctx
->hflags
|= MIPS_HFLAG_BC
;
4327 generate_exception (ctx
, EXCP_RI
);
4330 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
4331 ctx
->hflags
, btarget
);
4332 ctx
->btarget
= btarget
;
4335 /* Coprocessor 1 (FPU) */
4337 #define FOP(func, fmt) (((fmt) << 21) | (func))
4339 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4341 const char *opn
= "cp1 move";
4345 GEN_LOAD_FREG_FTN(WT0
, fs
);
4347 GEN_STORE_TN_REG(rt
, T0
);
4351 GEN_LOAD_REG_TN(T0
, rt
);
4353 GEN_STORE_FTN_FREG(fs
, WT0
);
4357 GEN_LOAD_IMM_TN(T1
, fs
);
4359 GEN_STORE_TN_REG(rt
, T0
);
4363 GEN_LOAD_IMM_TN(T1
, fs
);
4364 GEN_LOAD_REG_TN(T0
, rt
);
4369 GEN_LOAD_FREG_FTN(DT0
, fs
);
4371 GEN_STORE_TN_REG(rt
, T0
);
4375 GEN_LOAD_REG_TN(T0
, rt
);
4377 GEN_STORE_FTN_FREG(fs
, DT0
);
4381 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4383 GEN_STORE_TN_REG(rt
, T0
);
4387 GEN_LOAD_REG_TN(T0
, rt
);
4389 GEN_STORE_FTN_FREG(fs
, WTH0
);
4394 generate_exception (ctx
, EXCP_RI
);
4397 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4400 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4404 GEN_LOAD_REG_TN(T0
, rd
);
4405 GEN_LOAD_REG_TN(T1
, rs
);
4407 ccbit
= 1 << (24 + cc
);
4414 GEN_STORE_TN_REG(rd
, T0
);
4417 #define GEN_MOVCF(fmt) \
4418 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4423 ccbit = 1 << (24 + cc); \
4427 glue(gen_op_float_movf_, fmt)(ccbit); \
4429 glue(gen_op_float_movt_, fmt)(ccbit); \
4436 static void gen_farith (DisasContext
*ctx
, uint32_t op1
, int ft
,
4437 int fs
, int fd
, int cc
)
4439 const char *opn
= "farith";
4440 const char *condnames
[] = {
4458 const char *condnames_abs
[] = {
4476 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
4477 uint32_t func
= ctx
->opcode
& 0x3f;
4479 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
4481 GEN_LOAD_FREG_FTN(WT0
, fs
);
4482 GEN_LOAD_FREG_FTN(WT1
, ft
);
4483 gen_op_float_add_s();
4484 GEN_STORE_FTN_FREG(fd
, WT2
);
4489 GEN_LOAD_FREG_FTN(WT0
, fs
);
4490 GEN_LOAD_FREG_FTN(WT1
, ft
);
4491 gen_op_float_sub_s();
4492 GEN_STORE_FTN_FREG(fd
, WT2
);
4497 GEN_LOAD_FREG_FTN(WT0
, fs
);
4498 GEN_LOAD_FREG_FTN(WT1
, ft
);
4499 gen_op_float_mul_s();
4500 GEN_STORE_FTN_FREG(fd
, WT2
);
4505 GEN_LOAD_FREG_FTN(WT0
, fs
);
4506 GEN_LOAD_FREG_FTN(WT1
, ft
);
4507 gen_op_float_div_s();
4508 GEN_STORE_FTN_FREG(fd
, WT2
);
4513 GEN_LOAD_FREG_FTN(WT0
, fs
);
4514 gen_op_float_sqrt_s();
4515 GEN_STORE_FTN_FREG(fd
, WT2
);
4519 GEN_LOAD_FREG_FTN(WT0
, fs
);
4520 gen_op_float_abs_s();
4521 GEN_STORE_FTN_FREG(fd
, WT2
);
4525 GEN_LOAD_FREG_FTN(WT0
, fs
);
4526 gen_op_float_mov_s();
4527 GEN_STORE_FTN_FREG(fd
, WT2
);
4531 GEN_LOAD_FREG_FTN(WT0
, fs
);
4532 gen_op_float_chs_s();
4533 GEN_STORE_FTN_FREG(fd
, WT2
);
4537 gen_op_cp1_64bitmode();
4538 GEN_LOAD_FREG_FTN(WT0
, fs
);
4539 gen_op_float_roundl_s();
4540 GEN_STORE_FTN_FREG(fd
, DT2
);
4544 gen_op_cp1_64bitmode();
4545 GEN_LOAD_FREG_FTN(WT0
, fs
);
4546 gen_op_float_truncl_s();
4547 GEN_STORE_FTN_FREG(fd
, DT2
);
4551 gen_op_cp1_64bitmode();
4552 GEN_LOAD_FREG_FTN(WT0
, fs
);
4553 gen_op_float_ceill_s();
4554 GEN_STORE_FTN_FREG(fd
, DT2
);
4558 gen_op_cp1_64bitmode();
4559 GEN_LOAD_FREG_FTN(WT0
, fs
);
4560 gen_op_float_floorl_s();
4561 GEN_STORE_FTN_FREG(fd
, DT2
);
4565 GEN_LOAD_FREG_FTN(WT0
, fs
);
4566 gen_op_float_roundw_s();
4567 GEN_STORE_FTN_FREG(fd
, WT2
);
4571 GEN_LOAD_FREG_FTN(WT0
, fs
);
4572 gen_op_float_truncw_s();
4573 GEN_STORE_FTN_FREG(fd
, WT2
);
4577 GEN_LOAD_FREG_FTN(WT0
, fs
);
4578 gen_op_float_ceilw_s();
4579 GEN_STORE_FTN_FREG(fd
, WT2
);
4583 GEN_LOAD_FREG_FTN(WT0
, fs
);
4584 gen_op_float_floorw_s();
4585 GEN_STORE_FTN_FREG(fd
, WT2
);
4589 GEN_LOAD_REG_TN(T0
, ft
);
4590 GEN_LOAD_FREG_FTN(WT0
, fs
);
4591 GEN_LOAD_FREG_FTN(WT2
, fd
);
4592 gen_movcf_s(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
4593 GEN_STORE_FTN_FREG(fd
, WT2
);
4597 GEN_LOAD_REG_TN(T0
, ft
);
4598 GEN_LOAD_FREG_FTN(WT0
, fs
);
4599 GEN_LOAD_FREG_FTN(WT2
, fd
);
4600 gen_op_float_movz_s();
4601 GEN_STORE_FTN_FREG(fd
, WT2
);
4605 GEN_LOAD_REG_TN(T0
, ft
);
4606 GEN_LOAD_FREG_FTN(WT0
, fs
);
4607 GEN_LOAD_FREG_FTN(WT2
, fd
);
4608 gen_op_float_movn_s();
4609 GEN_STORE_FTN_FREG(fd
, WT2
);
4613 GEN_LOAD_FREG_FTN(WT0
, fs
);
4614 gen_op_float_recip_s();
4615 GEN_STORE_FTN_FREG(fd
, WT2
);
4619 GEN_LOAD_FREG_FTN(WT0
, fs
);
4620 gen_op_float_rsqrt_s();
4621 GEN_STORE_FTN_FREG(fd
, WT2
);
4625 gen_op_cp1_64bitmode();
4626 GEN_LOAD_FREG_FTN(WT0
, fs
);
4627 GEN_LOAD_FREG_FTN(WT2
, fd
);
4628 gen_op_float_recip2_s();
4629 GEN_STORE_FTN_FREG(fd
, WT2
);
4633 gen_op_cp1_64bitmode();
4634 GEN_LOAD_FREG_FTN(WT0
, fs
);
4635 gen_op_float_recip1_s();
4636 GEN_STORE_FTN_FREG(fd
, WT2
);
4640 gen_op_cp1_64bitmode();
4641 GEN_LOAD_FREG_FTN(WT0
, fs
);
4642 gen_op_float_rsqrt1_s();
4643 GEN_STORE_FTN_FREG(fd
, WT2
);
4647 gen_op_cp1_64bitmode();
4648 GEN_LOAD_FREG_FTN(WT0
, fs
);
4649 GEN_LOAD_FREG_FTN(WT2
, fd
);
4650 gen_op_float_rsqrt2_s();
4651 GEN_STORE_FTN_FREG(fd
, WT2
);
4655 gen_op_cp1_registers(fd
);
4656 GEN_LOAD_FREG_FTN(WT0
, fs
);
4657 gen_op_float_cvtd_s();
4658 GEN_STORE_FTN_FREG(fd
, DT2
);
4662 GEN_LOAD_FREG_FTN(WT0
, fs
);
4663 gen_op_float_cvtw_s();
4664 GEN_STORE_FTN_FREG(fd
, WT2
);
4668 gen_op_cp1_64bitmode();
4669 GEN_LOAD_FREG_FTN(WT0
, fs
);
4670 gen_op_float_cvtl_s();
4671 GEN_STORE_FTN_FREG(fd
, DT2
);
4675 gen_op_cp1_64bitmode();
4676 GEN_LOAD_FREG_FTN(WT1
, fs
);
4677 GEN_LOAD_FREG_FTN(WT0
, ft
);
4678 gen_op_float_cvtps_s();
4679 GEN_STORE_FTN_FREG(fd
, DT2
);
4698 GEN_LOAD_FREG_FTN(WT0
, fs
);
4699 GEN_LOAD_FREG_FTN(WT1
, ft
);
4700 if (ctx
->opcode
& (1 << 6)) {
4701 gen_op_cp1_64bitmode();
4702 gen_cmpabs_s(func
-48, cc
);
4703 opn
= condnames_abs
[func
-48];
4705 gen_cmp_s(func
-48, cc
);
4706 opn
= condnames
[func
-48];
4710 gen_op_cp1_registers(fs
| ft
| fd
);
4711 GEN_LOAD_FREG_FTN(DT0
, fs
);
4712 GEN_LOAD_FREG_FTN(DT1
, ft
);
4713 gen_op_float_add_d();
4714 GEN_STORE_FTN_FREG(fd
, DT2
);
4719 gen_op_cp1_registers(fs
| ft
| fd
);
4720 GEN_LOAD_FREG_FTN(DT0
, fs
);
4721 GEN_LOAD_FREG_FTN(DT1
, ft
);
4722 gen_op_float_sub_d();
4723 GEN_STORE_FTN_FREG(fd
, DT2
);
4728 gen_op_cp1_registers(fs
| ft
| fd
);
4729 GEN_LOAD_FREG_FTN(DT0
, fs
);
4730 GEN_LOAD_FREG_FTN(DT1
, ft
);
4731 gen_op_float_mul_d();
4732 GEN_STORE_FTN_FREG(fd
, DT2
);
4737 gen_op_cp1_registers(fs
| ft
| fd
);
4738 GEN_LOAD_FREG_FTN(DT0
, fs
);
4739 GEN_LOAD_FREG_FTN(DT1
, ft
);
4740 gen_op_float_div_d();
4741 GEN_STORE_FTN_FREG(fd
, DT2
);
4746 gen_op_cp1_registers(fs
| fd
);
4747 GEN_LOAD_FREG_FTN(DT0
, fs
);
4748 gen_op_float_sqrt_d();
4749 GEN_STORE_FTN_FREG(fd
, DT2
);
4753 gen_op_cp1_registers(fs
| fd
);
4754 GEN_LOAD_FREG_FTN(DT0
, fs
);
4755 gen_op_float_abs_d();
4756 GEN_STORE_FTN_FREG(fd
, DT2
);
4760 gen_op_cp1_registers(fs
| fd
);
4761 GEN_LOAD_FREG_FTN(DT0
, fs
);
4762 gen_op_float_mov_d();
4763 GEN_STORE_FTN_FREG(fd
, DT2
);
4767 gen_op_cp1_registers(fs
| fd
);
4768 GEN_LOAD_FREG_FTN(DT0
, fs
);
4769 gen_op_float_chs_d();
4770 GEN_STORE_FTN_FREG(fd
, DT2
);
4774 gen_op_cp1_64bitmode();
4775 GEN_LOAD_FREG_FTN(DT0
, fs
);
4776 gen_op_float_roundl_d();
4777 GEN_STORE_FTN_FREG(fd
, DT2
);
4781 gen_op_cp1_64bitmode();
4782 GEN_LOAD_FREG_FTN(DT0
, fs
);
4783 gen_op_float_truncl_d();
4784 GEN_STORE_FTN_FREG(fd
, DT2
);
4788 gen_op_cp1_64bitmode();
4789 GEN_LOAD_FREG_FTN(DT0
, fs
);
4790 gen_op_float_ceill_d();
4791 GEN_STORE_FTN_FREG(fd
, DT2
);
4795 gen_op_cp1_64bitmode();
4796 GEN_LOAD_FREG_FTN(DT0
, fs
);
4797 gen_op_float_floorl_d();
4798 GEN_STORE_FTN_FREG(fd
, DT2
);
4802 gen_op_cp1_registers(fs
);
4803 GEN_LOAD_FREG_FTN(DT0
, fs
);
4804 gen_op_float_roundw_d();
4805 GEN_STORE_FTN_FREG(fd
, WT2
);
4809 gen_op_cp1_registers(fs
);
4810 GEN_LOAD_FREG_FTN(DT0
, fs
);
4811 gen_op_float_truncw_d();
4812 GEN_STORE_FTN_FREG(fd
, WT2
);
4816 gen_op_cp1_registers(fs
);
4817 GEN_LOAD_FREG_FTN(DT0
, fs
);
4818 gen_op_float_ceilw_d();
4819 GEN_STORE_FTN_FREG(fd
, WT2
);
4823 gen_op_cp1_registers(fs
);
4824 GEN_LOAD_FREG_FTN(DT0
, fs
);
4825 gen_op_float_floorw_d();
4826 GEN_STORE_FTN_FREG(fd
, WT2
);
4830 GEN_LOAD_REG_TN(T0
, ft
);
4831 GEN_LOAD_FREG_FTN(DT0
, fs
);
4832 GEN_LOAD_FREG_FTN(DT2
, fd
);
4833 gen_movcf_d(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
4834 GEN_STORE_FTN_FREG(fd
, DT2
);
4838 GEN_LOAD_REG_TN(T0
, ft
);
4839 GEN_LOAD_FREG_FTN(DT0
, fs
);
4840 GEN_LOAD_FREG_FTN(DT2
, fd
);
4841 gen_op_float_movz_d();
4842 GEN_STORE_FTN_FREG(fd
, DT2
);
4846 GEN_LOAD_REG_TN(T0
, ft
);
4847 GEN_LOAD_FREG_FTN(DT0
, fs
);
4848 GEN_LOAD_FREG_FTN(DT2
, fd
);
4849 gen_op_float_movn_d();
4850 GEN_STORE_FTN_FREG(fd
, DT2
);
4854 gen_op_cp1_registers(fs
| fd
);
4855 GEN_LOAD_FREG_FTN(DT0
, fs
);
4856 gen_op_float_recip_d();
4857 GEN_STORE_FTN_FREG(fd
, DT2
);
4861 gen_op_cp1_registers(fs
| fd
);
4862 GEN_LOAD_FREG_FTN(DT0
, fs
);
4863 gen_op_float_rsqrt_d();
4864 GEN_STORE_FTN_FREG(fd
, DT2
);
4868 gen_op_cp1_64bitmode();
4869 GEN_LOAD_FREG_FTN(DT0
, fs
);
4870 GEN_LOAD_FREG_FTN(DT2
, ft
);
4871 gen_op_float_recip2_d();
4872 GEN_STORE_FTN_FREG(fd
, DT2
);
4876 gen_op_cp1_64bitmode();
4877 GEN_LOAD_FREG_FTN(DT0
, fs
);
4878 gen_op_float_recip1_d();
4879 GEN_STORE_FTN_FREG(fd
, DT2
);
4883 gen_op_cp1_64bitmode();
4884 GEN_LOAD_FREG_FTN(DT0
, fs
);
4885 gen_op_float_rsqrt1_d();
4886 GEN_STORE_FTN_FREG(fd
, DT2
);
4890 gen_op_cp1_64bitmode();
4891 GEN_LOAD_FREG_FTN(DT0
, fs
);
4892 GEN_LOAD_FREG_FTN(DT2
, ft
);
4893 gen_op_float_rsqrt2_d();
4894 GEN_STORE_FTN_FREG(fd
, DT2
);
4913 GEN_LOAD_FREG_FTN(DT0
, fs
);
4914 GEN_LOAD_FREG_FTN(DT1
, ft
);
4915 if (ctx
->opcode
& (1 << 6)) {
4916 gen_op_cp1_64bitmode();
4917 gen_cmpabs_d(func
-48, cc
);
4918 opn
= condnames_abs
[func
-48];
4920 gen_op_cp1_registers(fs
| ft
);
4921 gen_cmp_d(func
-48, cc
);
4922 opn
= condnames
[func
-48];
4926 gen_op_cp1_registers(fs
);
4927 GEN_LOAD_FREG_FTN(DT0
, fs
);
4928 gen_op_float_cvts_d();
4929 GEN_STORE_FTN_FREG(fd
, WT2
);
4933 gen_op_cp1_registers(fs
);
4934 GEN_LOAD_FREG_FTN(DT0
, fs
);
4935 gen_op_float_cvtw_d();
4936 GEN_STORE_FTN_FREG(fd
, WT2
);
4940 gen_op_cp1_64bitmode();
4941 GEN_LOAD_FREG_FTN(DT0
, fs
);
4942 gen_op_float_cvtl_d();
4943 GEN_STORE_FTN_FREG(fd
, DT2
);
4947 GEN_LOAD_FREG_FTN(WT0
, fs
);
4948 gen_op_float_cvts_w();
4949 GEN_STORE_FTN_FREG(fd
, WT2
);
4953 gen_op_cp1_registers(fd
);
4954 GEN_LOAD_FREG_FTN(WT0
, fs
);
4955 gen_op_float_cvtd_w();
4956 GEN_STORE_FTN_FREG(fd
, DT2
);
4960 gen_op_cp1_64bitmode();
4961 GEN_LOAD_FREG_FTN(DT0
, fs
);
4962 gen_op_float_cvts_l();
4963 GEN_STORE_FTN_FREG(fd
, WT2
);
4967 gen_op_cp1_64bitmode();
4968 GEN_LOAD_FREG_FTN(DT0
, fs
);
4969 gen_op_float_cvtd_l();
4970 GEN_STORE_FTN_FREG(fd
, DT2
);
4975 gen_op_cp1_64bitmode();
4976 GEN_LOAD_FREG_FTN(WT0
, fs
);
4977 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4978 gen_op_float_cvtps_pw();
4979 GEN_STORE_FTN_FREG(fd
, WT2
);
4980 GEN_STORE_FTN_FREG(fd
, WTH2
);
4984 gen_op_cp1_64bitmode();
4985 GEN_LOAD_FREG_FTN(WT0
, fs
);
4986 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4987 GEN_LOAD_FREG_FTN(WT1
, ft
);
4988 GEN_LOAD_FREG_FTN(WTH1
, ft
);
4989 gen_op_float_add_ps();
4990 GEN_STORE_FTN_FREG(fd
, WT2
);
4991 GEN_STORE_FTN_FREG(fd
, WTH2
);
4995 gen_op_cp1_64bitmode();
4996 GEN_LOAD_FREG_FTN(WT0
, fs
);
4997 GEN_LOAD_FREG_FTN(WTH0
, fs
);
4998 GEN_LOAD_FREG_FTN(WT1
, ft
);
4999 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5000 gen_op_float_sub_ps();
5001 GEN_STORE_FTN_FREG(fd
, WT2
);
5002 GEN_STORE_FTN_FREG(fd
, WTH2
);
5006 gen_op_cp1_64bitmode();
5007 GEN_LOAD_FREG_FTN(WT0
, fs
);
5008 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5009 GEN_LOAD_FREG_FTN(WT1
, ft
);
5010 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5011 gen_op_float_mul_ps();
5012 GEN_STORE_FTN_FREG(fd
, WT2
);
5013 GEN_STORE_FTN_FREG(fd
, WTH2
);
5017 gen_op_cp1_64bitmode();
5018 GEN_LOAD_FREG_FTN(WT0
, fs
);
5019 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5020 gen_op_float_abs_ps();
5021 GEN_STORE_FTN_FREG(fd
, WT2
);
5022 GEN_STORE_FTN_FREG(fd
, WTH2
);
5026 gen_op_cp1_64bitmode();
5027 GEN_LOAD_FREG_FTN(WT0
, fs
);
5028 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5029 gen_op_float_mov_ps();
5030 GEN_STORE_FTN_FREG(fd
, WT2
);
5031 GEN_STORE_FTN_FREG(fd
, WTH2
);
5035 gen_op_cp1_64bitmode();
5036 GEN_LOAD_FREG_FTN(WT0
, fs
);
5037 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5038 gen_op_float_chs_ps();
5039 GEN_STORE_FTN_FREG(fd
, WT2
);
5040 GEN_STORE_FTN_FREG(fd
, WTH2
);
5044 gen_op_cp1_64bitmode();
5045 GEN_LOAD_REG_TN(T0
, ft
);
5046 GEN_LOAD_FREG_FTN(WT0
, fs
);
5047 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5048 GEN_LOAD_FREG_FTN(WT2
, fd
);
5049 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5050 gen_movcf_ps(ctx
, (ft
>> 2) & 0x7, ft
& 0x1);
5051 GEN_STORE_FTN_FREG(fd
, WT2
);
5052 GEN_STORE_FTN_FREG(fd
, WTH2
);
5056 gen_op_cp1_64bitmode();
5057 GEN_LOAD_REG_TN(T0
, ft
);
5058 GEN_LOAD_FREG_FTN(WT0
, fs
);
5059 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5060 GEN_LOAD_FREG_FTN(WT2
, fd
);
5061 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5062 gen_op_float_movz_ps();
5063 GEN_STORE_FTN_FREG(fd
, WT2
);
5064 GEN_STORE_FTN_FREG(fd
, WTH2
);
5068 gen_op_cp1_64bitmode();
5069 GEN_LOAD_REG_TN(T0
, ft
);
5070 GEN_LOAD_FREG_FTN(WT0
, fs
);
5071 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5072 GEN_LOAD_FREG_FTN(WT2
, fd
);
5073 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5074 gen_op_float_movn_ps();
5075 GEN_STORE_FTN_FREG(fd
, WT2
);
5076 GEN_STORE_FTN_FREG(fd
, WTH2
);
5080 gen_op_cp1_64bitmode();
5081 GEN_LOAD_FREG_FTN(WT0
, fs
);
5082 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5083 GEN_LOAD_FREG_FTN(WT1
, ft
);
5084 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5085 gen_op_float_addr_ps();
5086 GEN_STORE_FTN_FREG(fd
, WT2
);
5087 GEN_STORE_FTN_FREG(fd
, WTH2
);
5091 gen_op_cp1_64bitmode();
5092 GEN_LOAD_FREG_FTN(WT0
, fs
);
5093 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5094 GEN_LOAD_FREG_FTN(WT1
, ft
);
5095 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5096 gen_op_float_mulr_ps();
5097 GEN_STORE_FTN_FREG(fd
, WT2
);
5098 GEN_STORE_FTN_FREG(fd
, WTH2
);
5102 gen_op_cp1_64bitmode();
5103 GEN_LOAD_FREG_FTN(WT0
, fs
);
5104 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5105 GEN_LOAD_FREG_FTN(WT2
, fd
);
5106 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5107 gen_op_float_recip2_ps();
5108 GEN_STORE_FTN_FREG(fd
, WT2
);
5109 GEN_STORE_FTN_FREG(fd
, WTH2
);
5113 gen_op_cp1_64bitmode();
5114 GEN_LOAD_FREG_FTN(WT0
, fs
);
5115 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5116 gen_op_float_recip1_ps();
5117 GEN_STORE_FTN_FREG(fd
, WT2
);
5118 GEN_STORE_FTN_FREG(fd
, WTH2
);
5122 gen_op_cp1_64bitmode();
5123 GEN_LOAD_FREG_FTN(WT0
, fs
);
5124 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5125 gen_op_float_rsqrt1_ps();
5126 GEN_STORE_FTN_FREG(fd
, WT2
);
5127 GEN_STORE_FTN_FREG(fd
, WTH2
);
5131 gen_op_cp1_64bitmode();
5132 GEN_LOAD_FREG_FTN(WT0
, fs
);
5133 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5134 GEN_LOAD_FREG_FTN(WT2
, fd
);
5135 GEN_LOAD_FREG_FTN(WTH2
, fd
);
5136 gen_op_float_rsqrt2_ps();
5137 GEN_STORE_FTN_FREG(fd
, WT2
);
5138 GEN_STORE_FTN_FREG(fd
, WTH2
);
5142 gen_op_cp1_64bitmode();
5143 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5144 gen_op_float_cvts_pu();
5145 GEN_STORE_FTN_FREG(fd
, WT2
);
5149 gen_op_cp1_64bitmode();
5150 GEN_LOAD_FREG_FTN(WT0
, fs
);
5151 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5152 gen_op_float_cvtpw_ps();
5153 GEN_STORE_FTN_FREG(fd
, WT2
);
5154 GEN_STORE_FTN_FREG(fd
, WTH2
);
5158 gen_op_cp1_64bitmode();
5159 GEN_LOAD_FREG_FTN(WT0
, fs
);
5160 gen_op_float_cvts_pl();
5161 GEN_STORE_FTN_FREG(fd
, WT2
);
5165 gen_op_cp1_64bitmode();
5166 GEN_LOAD_FREG_FTN(WT0
, fs
);
5167 GEN_LOAD_FREG_FTN(WT1
, ft
);
5168 gen_op_float_pll_ps();
5169 GEN_STORE_FTN_FREG(fd
, DT2
);
5173 gen_op_cp1_64bitmode();
5174 GEN_LOAD_FREG_FTN(WT0
, fs
);
5175 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5176 gen_op_float_plu_ps();
5177 GEN_STORE_FTN_FREG(fd
, DT2
);
5181 gen_op_cp1_64bitmode();
5182 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5183 GEN_LOAD_FREG_FTN(WT1
, ft
);
5184 gen_op_float_pul_ps();
5185 GEN_STORE_FTN_FREG(fd
, DT2
);
5189 gen_op_cp1_64bitmode();
5190 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5191 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5192 gen_op_float_puu_ps();
5193 GEN_STORE_FTN_FREG(fd
, DT2
);
5212 gen_op_cp1_64bitmode();
5213 GEN_LOAD_FREG_FTN(WT0
, fs
);
5214 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5215 GEN_LOAD_FREG_FTN(WT1
, ft
);
5216 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5217 if (ctx
->opcode
& (1 << 6)) {
5218 gen_cmpabs_ps(func
-48, cc
);
5219 opn
= condnames_abs
[func
-48];
5221 gen_cmp_ps(func
-48, cc
);
5222 opn
= condnames
[func
-48];
5227 generate_exception (ctx
, EXCP_RI
);
5232 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
5235 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
5238 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
5243 /* Coprocessor 3 (FPU) */
5244 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
, int fd
,
5245 int base
, int index
)
5247 const char *opn
= "extended float load/store";
5249 /* All of those work only on 64bit FPUs. */
5250 gen_op_cp1_64bitmode();
5251 GEN_LOAD_REG_TN(T0
, base
);
5252 GEN_LOAD_REG_TN(T1
, index
);
5253 /* Don't do NOP if destination is zero: we must perform the actual
5259 GEN_STORE_FTN_FREG(fd
, WT0
);
5264 GEN_STORE_FTN_FREG(fd
, DT0
);
5269 GEN_STORE_FTN_FREG(fd
, DT0
);
5273 GEN_LOAD_FREG_FTN(WT0
, fd
);
5278 GEN_LOAD_FREG_FTN(DT0
, fd
);
5283 GEN_LOAD_FREG_FTN(DT0
, fd
);
5289 generate_exception(ctx
, EXCP_RI
);
5292 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[fd
],regnames
[index
], regnames
[base
]);
5295 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
, int fd
,
5296 int fr
, int fs
, int ft
)
5298 const char *opn
= "flt3_arith";
5300 /* All of those work only on 64bit FPUs. */
5301 gen_op_cp1_64bitmode();
5304 GEN_LOAD_REG_TN(T0
, fr
);
5305 GEN_LOAD_FREG_FTN(DT0
, fs
);
5306 GEN_LOAD_FREG_FTN(DT1
, ft
);
5307 gen_op_float_alnv_ps();
5308 GEN_STORE_FTN_FREG(fd
, DT2
);
5312 GEN_LOAD_FREG_FTN(WT0
, fs
);
5313 GEN_LOAD_FREG_FTN(WT1
, ft
);
5314 GEN_LOAD_FREG_FTN(WT2
, fr
);
5315 gen_op_float_muladd_s();
5316 GEN_STORE_FTN_FREG(fd
, WT2
);
5320 GEN_LOAD_FREG_FTN(DT0
, fs
);
5321 GEN_LOAD_FREG_FTN(DT1
, ft
);
5322 GEN_LOAD_FREG_FTN(DT2
, fr
);
5323 gen_op_float_muladd_d();
5324 GEN_STORE_FTN_FREG(fd
, DT2
);
5328 GEN_LOAD_FREG_FTN(WT0
, fs
);
5329 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5330 GEN_LOAD_FREG_FTN(WT1
, ft
);
5331 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5332 GEN_LOAD_FREG_FTN(WT2
, fr
);
5333 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5334 gen_op_float_muladd_ps();
5335 GEN_STORE_FTN_FREG(fd
, WT2
);
5336 GEN_STORE_FTN_FREG(fd
, WTH2
);
5340 GEN_LOAD_FREG_FTN(WT0
, fs
);
5341 GEN_LOAD_FREG_FTN(WT1
, ft
);
5342 GEN_LOAD_FREG_FTN(WT2
, fr
);
5343 gen_op_float_mulsub_s();
5344 GEN_STORE_FTN_FREG(fd
, WT2
);
5348 GEN_LOAD_FREG_FTN(DT0
, fs
);
5349 GEN_LOAD_FREG_FTN(DT1
, ft
);
5350 GEN_LOAD_FREG_FTN(DT2
, fr
);
5351 gen_op_float_mulsub_d();
5352 GEN_STORE_FTN_FREG(fd
, DT2
);
5356 GEN_LOAD_FREG_FTN(WT0
, fs
);
5357 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5358 GEN_LOAD_FREG_FTN(WT1
, ft
);
5359 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5360 GEN_LOAD_FREG_FTN(WT2
, fr
);
5361 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5362 gen_op_float_mulsub_ps();
5363 GEN_STORE_FTN_FREG(fd
, WT2
);
5364 GEN_STORE_FTN_FREG(fd
, WTH2
);
5368 GEN_LOAD_FREG_FTN(WT0
, fs
);
5369 GEN_LOAD_FREG_FTN(WT1
, ft
);
5370 GEN_LOAD_FREG_FTN(WT2
, fr
);
5371 gen_op_float_nmuladd_s();
5372 GEN_STORE_FTN_FREG(fd
, WT2
);
5376 GEN_LOAD_FREG_FTN(DT0
, fs
);
5377 GEN_LOAD_FREG_FTN(DT1
, ft
);
5378 GEN_LOAD_FREG_FTN(DT2
, fr
);
5379 gen_op_float_nmuladd_d();
5380 GEN_STORE_FTN_FREG(fd
, DT2
);
5384 GEN_LOAD_FREG_FTN(WT0
, fs
);
5385 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5386 GEN_LOAD_FREG_FTN(WT1
, ft
);
5387 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5388 GEN_LOAD_FREG_FTN(WT2
, fr
);
5389 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5390 gen_op_float_nmuladd_ps();
5391 GEN_STORE_FTN_FREG(fd
, WT2
);
5392 GEN_STORE_FTN_FREG(fd
, WTH2
);
5396 GEN_LOAD_FREG_FTN(WT0
, fs
);
5397 GEN_LOAD_FREG_FTN(WT1
, ft
);
5398 GEN_LOAD_FREG_FTN(WT2
, fr
);
5399 gen_op_float_nmulsub_s();
5400 GEN_STORE_FTN_FREG(fd
, WT2
);
5404 GEN_LOAD_FREG_FTN(DT0
, fs
);
5405 GEN_LOAD_FREG_FTN(DT1
, ft
);
5406 GEN_LOAD_FREG_FTN(DT2
, fr
);
5407 gen_op_float_nmulsub_d();
5408 GEN_STORE_FTN_FREG(fd
, DT2
);
5412 GEN_LOAD_FREG_FTN(WT0
, fs
);
5413 GEN_LOAD_FREG_FTN(WTH0
, fs
);
5414 GEN_LOAD_FREG_FTN(WT1
, ft
);
5415 GEN_LOAD_FREG_FTN(WTH1
, ft
);
5416 GEN_LOAD_FREG_FTN(WT2
, fr
);
5417 GEN_LOAD_FREG_FTN(WTH2
, fr
);
5418 gen_op_float_nmulsub_ps();
5419 GEN_STORE_FTN_FREG(fd
, WT2
);
5420 GEN_STORE_FTN_FREG(fd
, WTH2
);
5425 generate_exception (ctx
, EXCP_RI
);
5428 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
5429 fregnames
[fs
], fregnames
[ft
]);
5432 /* ISA extensions (ASEs) */
5433 /* MIPS16 extension to MIPS32 */
5434 /* SmartMIPS extension to MIPS32 */
5436 #ifdef TARGET_MIPS64
5438 /* MDMX extension to MIPS64 */
5439 /* MIPS-3D extension to MIPS64 */
5443 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
5447 uint32_t op
, op1
, op2
;
5450 /* make sure instructions are on a word boundary */
5451 if (ctx
->pc
& 0x3) {
5452 env
->CP0_BadVAddr
= ctx
->pc
;
5453 generate_exception(ctx
, EXCP_AdEL
);
5457 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
5459 /* Handle blikely not taken case */
5460 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
5461 l1
= gen_new_label();
5463 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
5464 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5467 op
= MASK_OP_MAJOR(ctx
->opcode
);
5468 rs
= (ctx
->opcode
>> 21) & 0x1f;
5469 rt
= (ctx
->opcode
>> 16) & 0x1f;
5470 rd
= (ctx
->opcode
>> 11) & 0x1f;
5471 sa
= (ctx
->opcode
>> 6) & 0x1f;
5472 imm
= (int16_t)ctx
->opcode
;
5475 op1
= MASK_SPECIAL(ctx
->opcode
);
5477 case OPC_SLL
: /* Arithmetic with immediate */
5478 case OPC_SRL
... OPC_SRA
:
5479 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
5481 case OPC_SLLV
: /* Arithmetic */
5482 case OPC_SRLV
... OPC_SRAV
:
5483 case OPC_MOVZ
... OPC_MOVN
:
5484 case OPC_ADD
... OPC_NOR
:
5485 case OPC_SLT
... OPC_SLTU
:
5486 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5488 case OPC_MULT
... OPC_DIVU
:
5489 gen_muldiv(ctx
, op1
, rs
, rt
);
5491 case OPC_JR
... OPC_JALR
:
5492 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
5494 case OPC_TGE
... OPC_TEQ
: /* Traps */
5496 gen_trap(ctx
, op1
, rs
, rt
, -1);
5498 case OPC_MFHI
: /* Move from HI/LO */
5500 gen_HILO(ctx
, op1
, rd
);
5503 case OPC_MTLO
: /* Move to HI/LO */
5504 gen_HILO(ctx
, op1
, rs
);
5506 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
5507 #ifdef MIPS_STRICT_STANDARD
5508 MIPS_INVAL("PMON / selsl");
5509 generate_exception(ctx
, EXCP_RI
);
5515 generate_exception(ctx
, EXCP_SYSCALL
);
5518 generate_exception(ctx
, EXCP_BREAK
);
5521 #ifdef MIPS_STRICT_STANDARD
5523 generate_exception(ctx
, EXCP_RI
);
5525 /* Implemented as RI exception for now. */
5526 MIPS_INVAL("spim (unofficial)");
5527 generate_exception(ctx
, EXCP_RI
);
5531 /* Treat as a noop. */
5535 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5536 save_cpu_state(ctx
, 1);
5537 gen_op_cp1_enabled();
5538 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
5539 (ctx
->opcode
>> 16) & 1);
5541 generate_exception_err(ctx
, EXCP_CpU
, 1);
5545 #ifdef TARGET_MIPS64
5546 /* MIPS64 specific opcodes */
5548 case OPC_DSRL
... OPC_DSRA
:
5550 case OPC_DSRL32
... OPC_DSRA32
:
5551 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
5554 case OPC_DSRLV
... OPC_DSRAV
:
5555 case OPC_DADD
... OPC_DSUBU
:
5556 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5558 case OPC_DMULT
... OPC_DDIVU
:
5559 gen_muldiv(ctx
, op1
, rs
, rt
);
5562 default: /* Invalid */
5563 MIPS_INVAL("special");
5564 generate_exception(ctx
, EXCP_RI
);
5569 op1
= MASK_SPECIAL2(ctx
->opcode
);
5571 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
5572 case OPC_MSUB
... OPC_MSUBU
:
5573 gen_muldiv(ctx
, op1
, rs
, rt
);
5576 gen_arith(ctx
, op1
, rd
, rs
, rt
);
5578 case OPC_CLZ
... OPC_CLO
:
5579 gen_cl(ctx
, op1
, rd
, rs
);
5582 /* XXX: not clear which exception should be raised
5583 * when in debug mode...
5585 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5586 generate_exception(ctx
, EXCP_DBp
);
5588 generate_exception(ctx
, EXCP_DBp
);
5590 /* Treat as a noop */
5592 #ifdef TARGET_MIPS64
5593 case OPC_DCLZ
... OPC_DCLO
:
5594 gen_cl(ctx
, op1
, rd
, rs
);
5597 default: /* Invalid */
5598 MIPS_INVAL("special2");
5599 generate_exception(ctx
, EXCP_RI
);
5604 op1
= MASK_SPECIAL3(ctx
->opcode
);
5608 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
5611 op2
= MASK_BSHFL(ctx
->opcode
);
5614 GEN_LOAD_REG_TN(T1
, rt
);
5618 GEN_LOAD_REG_TN(T1
, rt
);
5622 GEN_LOAD_REG_TN(T1
, rt
);
5625 default: /* Invalid */
5626 MIPS_INVAL("bshfl");
5627 generate_exception(ctx
, EXCP_RI
);
5630 GEN_STORE_TN_REG(rd
, T0
);
5635 save_cpu_state(ctx
, 1);
5636 gen_op_rdhwr_cpunum();
5639 save_cpu_state(ctx
, 1);
5640 gen_op_rdhwr_synci_step();
5643 save_cpu_state(ctx
, 1);
5647 save_cpu_state(ctx
, 1);
5648 gen_op_rdhwr_ccres();
5651 #if defined (CONFIG_USER_ONLY)
5652 gen_op_tls_value ();
5655 default: /* Invalid */
5656 MIPS_INVAL("rdhwr");
5657 generate_exception(ctx
, EXCP_RI
);
5660 GEN_STORE_TN_REG(rt
, T0
);
5662 #ifdef TARGET_MIPS64
5663 case OPC_DEXTM
... OPC_DEXT
:
5664 case OPC_DINSM
... OPC_DINS
:
5665 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
5668 op2
= MASK_DBSHFL(ctx
->opcode
);
5671 GEN_LOAD_REG_TN(T1
, rt
);
5675 GEN_LOAD_REG_TN(T1
, rt
);
5678 default: /* Invalid */
5679 MIPS_INVAL("dbshfl");
5680 generate_exception(ctx
, EXCP_RI
);
5683 GEN_STORE_TN_REG(rd
, T0
);
5685 default: /* Invalid */
5686 MIPS_INVAL("special3");
5687 generate_exception(ctx
, EXCP_RI
);
5692 op1
= MASK_REGIMM(ctx
->opcode
);
5694 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
5695 case OPC_BLTZAL
... OPC_BGEZALL
:
5696 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
5698 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
5700 gen_trap(ctx
, op1
, rs
, -1, imm
);
5705 default: /* Invalid */
5706 MIPS_INVAL("regimm");
5707 generate_exception(ctx
, EXCP_RI
);
5712 save_cpu_state(ctx
, 1);
5713 gen_op_cp0_enabled();
5714 op1
= MASK_CP0(ctx
->opcode
);
5718 #ifdef TARGET_MIPS64
5722 gen_cp0(env
, ctx
, op1
, rt
, rd
);
5724 case OPC_C0_FIRST
... OPC_C0_LAST
:
5725 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
5728 op2
= MASK_MFMC0(ctx
->opcode
);
5732 /* Stop translation as we may have switched the execution mode */
5733 ctx
->bstate
= BS_STOP
;
5737 /* Stop translation as we may have switched the execution mode */
5738 ctx
->bstate
= BS_STOP
;
5740 default: /* Invalid */
5741 MIPS_INVAL("mfmc0");
5742 generate_exception(ctx
, EXCP_RI
);
5745 GEN_STORE_TN_REG(rt
, T0
);
5749 if ((env
->CP0_Config0
& (0x7 << CP0C0_AR
)) == (1 << CP0C0_AR
)) {
5750 /* Shadow registers not implemented. */
5751 GEN_LOAD_REG_TN(T0
, rt
);
5752 GEN_STORE_TN_REG(rd
, T0
);
5754 MIPS_INVAL("shadow register move");
5755 generate_exception(ctx
, EXCP_RI
);
5760 generate_exception(ctx
, EXCP_RI
);
5764 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
5765 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
5767 case OPC_J
... OPC_JAL
: /* Jump */
5768 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
5769 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
5771 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
5772 case OPC_BEQL
... OPC_BGTZL
:
5773 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
5775 case OPC_LB
... OPC_LWR
: /* Load and stores */
5776 case OPC_SB
... OPC_SW
:
5780 gen_ldst(ctx
, op
, rt
, rs
, imm
);
5783 /* FIXME: This works around self-modifying code, but only
5784 if the guest OS handles it properly, and if there's no
5785 such code executed in uncached space. */
5787 switch ((rt
>> 2) & 0x7) {
5789 GEN_LOAD_REG_TN(T0
, rs
);
5790 GEN_LOAD_IMM_TN(T1
, imm
);
5791 gen_op_flush_icache_range();
5796 /* Can be very inefficient. */
5797 gen_op_flush_icache_all();
5804 /* Treat as a noop */
5807 /* Floating point (COP1). */
5812 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5813 save_cpu_state(ctx
, 1);
5814 gen_op_cp1_enabled();
5815 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
5817 generate_exception_err(ctx
, EXCP_CpU
, 1);
5822 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5823 save_cpu_state(ctx
, 1);
5824 gen_op_cp1_enabled();
5825 op1
= MASK_CP1(ctx
->opcode
);
5831 #ifdef TARGET_MIPS64
5837 gen_cp1(ctx
, op1
, rt
, rd
);
5842 gen_compute_branch1(ctx
, MASK_BC1(ctx
->opcode
),
5843 (rt
>> 2) & 0x7, imm
<< 2);
5850 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
5855 generate_exception (ctx
, EXCP_RI
);
5859 generate_exception_err(ctx
, EXCP_CpU
, 1);
5869 /* COP2: Not implemented. */
5870 generate_exception_err(ctx
, EXCP_CpU
, 2);
5874 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5875 save_cpu_state(ctx
, 1);
5876 gen_op_cp1_enabled();
5877 op1
= MASK_CP3(ctx
->opcode
);
5885 gen_flt3_ldst(ctx
, op1
, sa
, rs
, rt
);
5903 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
5907 generate_exception (ctx
, EXCP_RI
);
5911 generate_exception_err(ctx
, EXCP_CpU
, 1);
5915 #ifdef TARGET_MIPS64
5916 /* MIPS64 opcodes */
5918 case OPC_LDL
... OPC_LDR
:
5919 case OPC_SDL
... OPC_SDR
:
5924 gen_ldst(ctx
, op
, rt
, rs
, imm
);
5926 case OPC_DADDI
... OPC_DADDIU
:
5927 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
5930 #ifdef MIPS_HAS_MIPS16
5932 /* MIPS16: Not implemented. */
5934 #ifdef MIPS_HAS_MDMX
5936 /* MDMX: Not implemented. */
5938 default: /* Invalid */
5939 MIPS_INVAL("major opcode");
5940 generate_exception(ctx
, EXCP_RI
);
5943 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
5944 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
5945 /* Branches completion */
5946 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
5947 ctx
->bstate
= BS_BRANCH
;
5948 save_cpu_state(ctx
, 0);
5951 /* unconditional branch */
5952 MIPS_DEBUG("unconditional branch");
5953 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5956 /* blikely taken case */
5957 MIPS_DEBUG("blikely branch taken");
5958 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5961 /* Conditional branch */
5962 MIPS_DEBUG("conditional branch");
5965 l1
= gen_new_label();
5967 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5969 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5973 /* unconditional branch to register */
5974 MIPS_DEBUG("branch to register");
5980 MIPS_DEBUG("unknown branch");
5987 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
5990 DisasContext ctx
, *ctxp
= &ctx
;
5991 target_ulong pc_start
;
5992 uint16_t *gen_opc_end
;
5995 if (search_pc
&& loglevel
)
5996 fprintf (logfile
, "search pc %d\n", search_pc
);
5999 gen_opc_ptr
= gen_opc_buf
;
6000 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6001 gen_opparam_ptr
= gen_opparam_buf
;
6006 ctx
.bstate
= BS_NONE
;
6007 /* Restore delay slot state from the tb context. */
6008 ctx
.hflags
= tb
->flags
;
6009 restore_cpu_state(env
, &ctx
);
6010 #if defined(CONFIG_USER_ONLY)
6013 ctx
.mem_idx
= !((ctx
.hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_UM
);
6016 if (loglevel
& CPU_LOG_TB_CPU
) {
6017 fprintf(logfile
, "------------------------------------------------\n");
6018 /* FIXME: This may print out stale hflags from env... */
6019 cpu_dump_state(env
, logfile
, fprintf
, 0);
6022 #ifdef MIPS_DEBUG_DISAS
6023 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6024 fprintf(logfile
, "\ntb %p super %d cond %04x\n",
6025 tb
, ctx
.mem_idx
, ctx
.hflags
);
6027 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6028 if (env
->nb_breakpoints
> 0) {
6029 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
6030 if (env
->breakpoints
[j
] == ctx
.pc
) {
6031 save_cpu_state(ctxp
, 1);
6032 ctx
.bstate
= BS_BRANCH
;
6034 goto done_generating
;
6040 j
= gen_opc_ptr
- gen_opc_buf
;
6044 gen_opc_instr_start
[lj
++] = 0;
6046 gen_opc_pc
[lj
] = ctx
.pc
;
6047 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
6048 gen_opc_instr_start
[lj
] = 1;
6050 ctx
.opcode
= ldl_code(ctx
.pc
);
6051 decode_opc(env
, &ctx
);
6054 if (env
->singlestep_enabled
)
6057 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
6060 #if defined (MIPS_SINGLE_STEP)
6064 if (env
->singlestep_enabled
) {
6065 save_cpu_state(ctxp
, ctx
.bstate
== BS_NONE
);
6068 switch (ctx
.bstate
) {
6070 gen_op_interrupt_restart();
6073 save_cpu_state(ctxp
, 0);
6074 gen_goto_tb(&ctx
, 0, ctx
.pc
);
6077 gen_op_interrupt_restart();
6087 *gen_opc_ptr
= INDEX_op_end
;
6089 j
= gen_opc_ptr
- gen_opc_buf
;
6092 gen_opc_instr_start
[lj
++] = 0;
6095 tb
->size
= ctx
.pc
- pc_start
;
6098 #if defined MIPS_DEBUG_DISAS
6099 if (loglevel
& CPU_LOG_TB_IN_ASM
)
6100 fprintf(logfile
, "\n");
6102 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6103 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6104 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
6105 fprintf(logfile
, "\n");
6107 if (loglevel
& CPU_LOG_TB_OP
) {
6108 fprintf(logfile
, "OP:\n");
6109 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6110 fprintf(logfile
, "\n");
6112 if (loglevel
& CPU_LOG_TB_CPU
) {
6113 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
6120 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6122 return gen_intermediate_code_internal(env
, tb
, 0);
6125 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6127 return gen_intermediate_code_internal(env
, tb
, 1);
6130 void fpu_dump_state(CPUState
*env
, FILE *f
,
6131 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6135 int is_fpu64
= !!(env
->CP0_Status
& (1 << CP0St_FR
));
6137 #define printfpr(fp) \
6140 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6141 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6142 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6145 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6146 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6147 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6148 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6149 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6154 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6155 env
->fcr0
, env
->fcr31
, is_fpu64
, env
->fp_status
, get_float_exception_flags(&env
->fp_status
));
6156 fpu_fprintf(f
, "FT0: "); printfpr(&env
->ft0
);
6157 fpu_fprintf(f
, "FT1: "); printfpr(&env
->ft1
);
6158 fpu_fprintf(f
, "FT2: "); printfpr(&env
->ft2
);
6159 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
6160 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
6161 printfpr(&env
->fpr
[i
]);
6167 void dump_fpu (CPUState
*env
)
6170 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
6171 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
6172 fpu_dump_state(env
, logfile
, fprintf
, 0);
6176 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6177 /* Debug help: The architecture requires 32bit code to maintain proper
6178 sign-extened values on 64bit machines. */
6180 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6182 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
6183 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6188 if (!SIGN_EXT_P(env
->PC
))
6189 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
);
6190 if (!SIGN_EXT_P(env
->HI
))
6191 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
);
6192 if (!SIGN_EXT_P(env
->LO
))
6193 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
);
6194 if (!SIGN_EXT_P(env
->btarget
))
6195 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
6197 for (i
= 0; i
< 32; i
++) {
6198 if (!SIGN_EXT_P(env
->gpr
[i
]))
6199 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[i
]);
6202 if (!SIGN_EXT_P(env
->CP0_EPC
))
6203 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
6204 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
6205 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
6209 void cpu_dump_state (CPUState
*env
, FILE *f
,
6210 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6216 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",
6217 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
6218 for (i
= 0; i
< 32; i
++) {
6220 cpu_fprintf(f
, "GPR%02d:", i
);
6221 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[i
]);
6223 cpu_fprintf(f
, "\n");
6226 c0_status
= env
->CP0_Status
;
6228 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
6229 c0_status
, env
->CP0_Cause
, env
->CP0_EPC
);
6230 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
6231 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
6232 if (c0_status
& (1 << CP0St_CU1
))
6233 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
6234 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6235 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
6239 CPUMIPSState
*cpu_mips_init (void)
6243 env
= qemu_mallocz(sizeof(CPUMIPSState
));
6251 void cpu_reset (CPUMIPSState
*env
)
6253 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
6258 #if !defined(CONFIG_USER_ONLY)
6259 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
6260 /* If the exception was raised from a delay slot,
6261 * come back to the jump. */
6262 env
->CP0_ErrorEPC
= env
->PC
- 4;
6263 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
6265 env
->CP0_ErrorEPC
= env
->PC
;
6268 env
->PC
= (int32_t)0xBFC00000;
6270 /* SMP not implemented */
6271 env
->CP0_EBase
= 0x80000000;
6272 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
6273 /* vectored interrupts not implemented, timer on int 7,
6274 no performance counters. */
6275 env
->CP0_IntCtl
= 0xe0000000;
6276 env
->CP0_WatchLo
= 0;
6277 env
->CP0_WatchHi
= 0;
6278 /* Count register increments in debug mode, EJTAG version 1 */
6279 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
6281 env
->exception_index
= EXCP_NONE
;
6282 #if defined(CONFIG_USER_ONLY)
6283 env
->hflags
|= MIPS_HFLAG_UM
;
6284 env
->user_mode_only
= 1;
6288 #include "translate_init.c"