]>
git.proxmox.com Git - qemu.git/blob - target-mips/translate.c
06581f2cc6317ce63a5a48d10ba2a4b768590d5c
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_MFHCI
= (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_MTHCI
= (0x07 << 21) | OPC_CP1
,
341 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
342 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
343 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
344 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
345 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
346 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
347 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
351 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
352 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
353 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
354 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
357 #define MASK_CP1_BCOND(op) MASK_CP1(op) | (op & (0x3 << 16))
358 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
360 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
363 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
364 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
365 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
366 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
367 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
368 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
369 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
370 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
371 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
374 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
377 OPC_LWXC1
= 0x00 | OPC_CP3
,
378 OPC_LDXC1
= 0x01 | OPC_CP3
,
379 OPC_LUXC1
= 0x05 | OPC_CP3
,
380 OPC_SWXC1
= 0x08 | OPC_CP3
,
381 OPC_SDXC1
= 0x09 | OPC_CP3
,
382 OPC_SUXC1
= 0x0D | OPC_CP3
,
383 OPC_PREFX
= 0x0F | OPC_CP3
,
384 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
385 OPC_MADD_S
= 0x20 | OPC_CP3
,
386 OPC_MADD_D
= 0x21 | OPC_CP3
,
387 OPC_MADD_PS
= 0x26 | OPC_CP3
,
388 OPC_MSUB_S
= 0x28 | OPC_CP3
,
389 OPC_MSUB_D
= 0x29 | OPC_CP3
,
390 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
391 OPC_NMADD_S
= 0x30 | OPC_CP3
,
392 OPC_NMADD_D
= 0x32 | OPC_CP3
,
393 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
394 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
395 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
396 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
400 const unsigned char *regnames
[] =
401 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
402 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
403 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
404 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
406 /* Warning: no function for r0 register (hard wired to zero) */
407 #define GEN32(func, NAME) \
408 static GenOpFunc *NAME ## _table [32] = { \
409 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
410 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
411 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
412 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
413 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
414 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
415 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
416 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
418 static inline void func(int n) \
420 NAME ## _table[n](); \
423 /* General purpose registers moves */
424 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
425 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
426 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
428 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
429 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
431 static const char *fregnames
[] =
432 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
433 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
434 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
435 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
437 # define SFGEN32(func, NAME) \
438 static GenOpFunc *NAME ## _table [32] = { \
439 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
440 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
441 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
442 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
443 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
444 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
445 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
446 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
448 static inline void func(int n) \
450 NAME ## _table[n](); \
453 # define DFGEN32(func, NAME) \
454 static GenOpFunc *NAME ## _table [32] = { \
455 NAME ## 0, 0, NAME ## 2, 0, \
456 NAME ## 4, 0, NAME ## 6, 0, \
457 NAME ## 8, 0, NAME ## 10, 0, \
458 NAME ## 12, 0, NAME ## 14, 0, \
459 NAME ## 16, 0, NAME ## 18, 0, \
460 NAME ## 20, 0, NAME ## 22, 0, \
461 NAME ## 24, 0, NAME ## 26, 0, \
462 NAME ## 28, 0, NAME ## 30, 0, \
464 static inline void func(int n) \
466 NAME ## _table[n](); \
469 SFGEN32(gen_op_load_fpr_WT0
, gen_op_load_fpr_WT0_fpr
);
470 SFGEN32(gen_op_store_fpr_WT0
, gen_op_store_fpr_WT0_fpr
);
472 SFGEN32(gen_op_load_fpr_WT1
, gen_op_load_fpr_WT1_fpr
);
473 SFGEN32(gen_op_store_fpr_WT1
, gen_op_store_fpr_WT1_fpr
);
475 SFGEN32(gen_op_load_fpr_WT2
, gen_op_load_fpr_WT2_fpr
);
476 SFGEN32(gen_op_store_fpr_WT2
, gen_op_store_fpr_WT2_fpr
);
478 DFGEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fpr
);
479 DFGEN32(gen_op_store_fpr_DT0
, gen_op_store_fpr_DT0_fpr
);
481 DFGEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fpr
);
482 DFGEN32(gen_op_store_fpr_DT1
, gen_op_store_fpr_DT1_fpr
);
484 DFGEN32(gen_op_load_fpr_DT2
, gen_op_load_fpr_DT2_fpr
);
485 DFGEN32(gen_op_store_fpr_DT2
, gen_op_store_fpr_DT2_fpr
);
487 #define FOP_CONDS(fmt) \
488 static GenOpFunc * cond_ ## fmt ## _table[16] = { \
489 gen_op_cmp_ ## fmt ## _f, \
490 gen_op_cmp_ ## fmt ## _un, \
491 gen_op_cmp_ ## fmt ## _eq, \
492 gen_op_cmp_ ## fmt ## _ueq, \
493 gen_op_cmp_ ## fmt ## _olt, \
494 gen_op_cmp_ ## fmt ## _ult, \
495 gen_op_cmp_ ## fmt ## _ole, \
496 gen_op_cmp_ ## fmt ## _ule, \
497 gen_op_cmp_ ## fmt ## _sf, \
498 gen_op_cmp_ ## fmt ## _ngle, \
499 gen_op_cmp_ ## fmt ## _seq, \
500 gen_op_cmp_ ## fmt ## _ngl, \
501 gen_op_cmp_ ## fmt ## _lt, \
502 gen_op_cmp_ ## fmt ## _nge, \
503 gen_op_cmp_ ## fmt ## _le, \
504 gen_op_cmp_ ## fmt ## _ngt, \
506 static inline void gen_cmp_ ## fmt(int n) \
508 cond_ ## fmt ## _table[n](); \
514 typedef struct DisasContext
{
515 struct TranslationBlock
*tb
;
516 target_ulong pc
, saved_pc
;
518 /* Routine used to access memory */
520 uint32_t hflags
, saved_hflags
;
523 target_ulong btarget
;
527 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
528 * exception condition
530 BS_STOP
= 1, /* We want to stop translation for any reason */
531 BS_BRANCH
= 2, /* We reached a branch condition */
532 BS_EXCP
= 3, /* We reached an exception condition */
535 #if defined MIPS_DEBUG_DISAS
536 #define MIPS_DEBUG(fmt, args...) \
538 if (loglevel & CPU_LOG_TB_IN_ASM) { \
539 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
540 ctx->pc, ctx->opcode , ##args); \
544 #define MIPS_DEBUG(fmt, args...) do { } while(0)
547 #define MIPS_INVAL(op) \
549 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
550 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
553 #define GEN_LOAD_REG_TN(Tn, Rn) \
556 glue(gen_op_reset_, Tn)(); \
558 glue(gen_op_load_gpr_, Tn)(Rn); \
562 #define GEN_LOAD_IMM_TN(Tn, Imm) \
565 glue(gen_op_reset_, Tn)(); \
567 glue(gen_op_set_, Tn)(Imm); \
571 #define GEN_STORE_TN_REG(Rn, Tn) \
574 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
578 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
580 glue(gen_op_load_fpr_, FTn)(Fn); \
583 #define GEN_STORE_FTN_FREG(Fn, FTn) \
585 glue(gen_op_store_fpr_, FTn)(Fn); \
588 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
590 #if defined MIPS_DEBUG_DISAS
591 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
592 fprintf(logfile
, "hflags %08x saved %08x\n",
593 ctx
->hflags
, ctx
->saved_hflags
);
596 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
597 gen_op_save_pc(ctx
->pc
);
598 ctx
->saved_pc
= ctx
->pc
;
600 if (ctx
->hflags
!= ctx
->saved_hflags
) {
601 gen_op_save_state(ctx
->hflags
);
602 ctx
->saved_hflags
= ctx
->hflags
;
603 if (ctx
->hflags
& MIPS_HFLAG_BR
) {
604 gen_op_save_breg_target();
605 } else if (ctx
->hflags
& MIPS_HFLAG_B
) {
606 gen_op_save_btarget(ctx
->btarget
);
607 } else if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
609 gen_op_save_btarget(ctx
->btarget
);
614 static inline void generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
616 #if defined MIPS_DEBUG_DISAS
617 if (loglevel
& CPU_LOG_TB_IN_ASM
)
618 fprintf(logfile
, "%s: raise exception %d\n", __func__
, excp
);
620 save_cpu_state(ctx
, 1);
622 gen_op_raise_exception(excp
);
624 gen_op_raise_exception_err(excp
, err
);
625 ctx
->bstate
= BS_EXCP
;
628 static inline void generate_exception (DisasContext
*ctx
, int excp
)
630 generate_exception_err (ctx
, excp
, 0);
633 #if defined(CONFIG_USER_ONLY)
634 #define op_ldst(name) gen_op_##name##_raw()
635 #define OP_LD_TABLE(width)
636 #define OP_ST_TABLE(width)
638 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
639 #define OP_LD_TABLE(width) \
640 static GenOpFunc *gen_op_l##width[] = { \
641 &gen_op_l##width##_user, \
642 &gen_op_l##width##_kernel, \
644 #define OP_ST_TABLE(width) \
645 static GenOpFunc *gen_op_s##width[] = { \
646 &gen_op_s##width##_user, \
647 &gen_op_s##width##_kernel, \
682 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
683 int base
, int16_t offset
)
685 const char *opn
= "unk";
688 GEN_LOAD_IMM_TN(T0
, offset
);
689 } else if (offset
== 0) {
690 gen_op_load_gpr_T0(base
);
692 gen_op_load_gpr_T0(base
);
693 gen_op_set_T1(offset
);
696 /* Don't do NOP if destination is zero: we must perform the actual
703 GEN_STORE_TN_REG(rt
, T0
);
708 GEN_STORE_TN_REG(rt
, T0
);
712 GEN_LOAD_REG_TN(T1
, rt
);
717 save_cpu_state(ctx
, 1);
718 GEN_LOAD_REG_TN(T1
, rt
);
724 GEN_STORE_TN_REG(rt
, T0
);
728 GEN_LOAD_REG_TN(T1
, rt
);
734 GEN_STORE_TN_REG(rt
, T0
);
738 GEN_LOAD_REG_TN(T1
, rt
);
745 GEN_STORE_TN_REG(rt
, T0
);
750 GEN_STORE_TN_REG(rt
, T0
);
754 GEN_LOAD_REG_TN(T1
, rt
);
760 GEN_STORE_TN_REG(rt
, T0
);
764 GEN_LOAD_REG_TN(T1
, rt
);
770 GEN_STORE_TN_REG(rt
, T0
);
775 GEN_STORE_TN_REG(rt
, T0
);
779 GEN_LOAD_REG_TN(T1
, rt
);
785 GEN_STORE_TN_REG(rt
, T0
);
789 GEN_LOAD_REG_TN(T1
, rt
);
791 GEN_STORE_TN_REG(rt
, T0
);
795 GEN_LOAD_REG_TN(T1
, rt
);
800 GEN_LOAD_REG_TN(T1
, rt
);
802 GEN_STORE_TN_REG(rt
, T0
);
806 GEN_LOAD_REG_TN(T1
, rt
);
812 GEN_STORE_TN_REG(rt
, T0
);
816 save_cpu_state(ctx
, 1);
817 GEN_LOAD_REG_TN(T1
, rt
);
819 GEN_STORE_TN_REG(rt
, T0
);
823 MIPS_INVAL("load/store");
824 generate_exception(ctx
, EXCP_RI
);
827 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
831 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
832 int base
, int16_t offset
)
834 const char *opn
= "unk";
837 GEN_LOAD_IMM_TN(T0
, offset
);
838 } else if (offset
== 0) {
839 gen_op_load_gpr_T0(base
);
841 gen_op_load_gpr_T0(base
);
842 gen_op_set_T1(offset
);
845 /* Don't do NOP if destination is zero: we must perform the actual
851 GEN_STORE_FTN_FREG(ft
, WT0
);
855 GEN_LOAD_FREG_FTN(WT0
, ft
);
861 GEN_STORE_FTN_FREG(ft
, DT0
);
865 GEN_LOAD_FREG_FTN(DT0
, ft
);
870 MIPS_INVAL("float load/store");
871 generate_exception(ctx
, EXCP_RI
);
874 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
877 /* Arithmetic with immediate operand */
878 static void gen_arith_imm (DisasContext
*ctx
, uint32_t opc
, int rt
,
882 const char *opn
= "unk";
884 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
885 /* if no destination, treat it as a NOP
886 * For addi, we must generate the overflow exception when needed.
891 uimm
= (uint16_t)imm
;
901 uimm
= (int32_t)imm
; /* Sign extend to 32 bits */
906 GEN_LOAD_REG_TN(T0
, rs
);
907 GEN_LOAD_IMM_TN(T1
, uimm
);
910 GEN_LOAD_IMM_TN(T0
, uimm
<< 16);
924 GEN_LOAD_REG_TN(T0
, rs
);
925 GEN_LOAD_IMM_TN(T1
, uimm
);
930 save_cpu_state(ctx
, 1);
940 save_cpu_state(ctx
, 1);
981 switch ((ctx
->opcode
>> 21) & 0x1f) {
991 MIPS_INVAL("invalid srl flag");
992 generate_exception(ctx
, EXCP_RI
);
1006 switch ((ctx
->opcode
>> 21) & 0x1f) {
1016 MIPS_INVAL("invalid dsrl flag");
1017 generate_exception(ctx
, EXCP_RI
);
1030 switch ((ctx
->opcode
>> 21) & 0x1f) {
1040 MIPS_INVAL("invalid dsrl32 flag");
1041 generate_exception(ctx
, EXCP_RI
);
1047 MIPS_INVAL("imm arith");
1048 generate_exception(ctx
, EXCP_RI
);
1051 GEN_STORE_TN_REG(rt
, T0
);
1052 MIPS_DEBUG("%s %s, %s, %x", opn
, regnames
[rt
], regnames
[rs
], uimm
);
1056 static void gen_arith (DisasContext
*ctx
, uint32_t opc
,
1057 int rd
, int rs
, int rt
)
1059 const char *opn
= "unk";
1061 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1062 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1063 /* if no destination, treat it as a NOP
1064 * For add & sub, we must generate the overflow exception when needed.
1069 GEN_LOAD_REG_TN(T0
, rs
);
1070 GEN_LOAD_REG_TN(T1
, rt
);
1073 save_cpu_state(ctx
, 1);
1082 save_cpu_state(ctx
, 1);
1090 #ifdef TARGET_MIPS64
1092 save_cpu_state(ctx
, 1);
1101 save_cpu_state(ctx
, 1);
1155 switch ((ctx
->opcode
>> 6) & 0x1f) {
1165 MIPS_INVAL("invalid srlv flag");
1166 generate_exception(ctx
, EXCP_RI
);
1170 #ifdef TARGET_MIPS64
1180 switch ((ctx
->opcode
>> 6) & 0x1f) {
1190 MIPS_INVAL("invalid dsrlv flag");
1191 generate_exception(ctx
, EXCP_RI
);
1197 MIPS_INVAL("arith");
1198 generate_exception(ctx
, EXCP_RI
);
1201 GEN_STORE_TN_REG(rd
, T0
);
1203 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1206 /* Arithmetic on HI/LO registers */
1207 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1209 const char *opn
= "unk";
1211 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1212 /* Treat as a NOP */
1219 GEN_STORE_TN_REG(reg
, T0
);
1224 GEN_STORE_TN_REG(reg
, T0
);
1228 GEN_LOAD_REG_TN(T0
, reg
);
1233 GEN_LOAD_REG_TN(T0
, reg
);
1239 generate_exception(ctx
, EXCP_RI
);
1242 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1245 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1248 const char *opn
= "unk";
1250 GEN_LOAD_REG_TN(T0
, rs
);
1251 GEN_LOAD_REG_TN(T1
, rt
);
1269 #ifdef TARGET_MIPS64
1304 MIPS_INVAL("mul/div");
1305 generate_exception(ctx
, EXCP_RI
);
1308 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
1311 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
1314 const char *opn
= "unk";
1316 /* Treat as a NOP */
1320 GEN_LOAD_REG_TN(T0
, rs
);
1330 #ifdef TARGET_MIPS64
1342 generate_exception(ctx
, EXCP_RI
);
1345 gen_op_store_T0_gpr(rd
);
1346 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
1350 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
1351 int rs
, int rt
, int16_t imm
)
1356 /* Load needed operands */
1364 /* Compare two registers */
1366 GEN_LOAD_REG_TN(T0
, rs
);
1367 GEN_LOAD_REG_TN(T1
, rt
);
1377 /* Compare register to immediate */
1378 if (rs
!= 0 || imm
!= 0) {
1379 GEN_LOAD_REG_TN(T0
, rs
);
1380 GEN_LOAD_IMM_TN(T1
, (int32_t)imm
);
1387 case OPC_TEQ
: /* rs == rs */
1388 case OPC_TEQI
: /* r0 == 0 */
1389 case OPC_TGE
: /* rs >= rs */
1390 case OPC_TGEI
: /* r0 >= 0 */
1391 case OPC_TGEU
: /* rs >= rs unsigned */
1392 case OPC_TGEIU
: /* r0 >= 0 unsigned */
1396 case OPC_TLT
: /* rs < rs */
1397 case OPC_TLTI
: /* r0 < 0 */
1398 case OPC_TLTU
: /* rs < rs unsigned */
1399 case OPC_TLTIU
: /* r0 < 0 unsigned */
1400 case OPC_TNE
: /* rs != rs */
1401 case OPC_TNEI
: /* r0 != 0 */
1402 /* Never trap: treat as NOP */
1406 generate_exception(ctx
, EXCP_RI
);
1437 generate_exception(ctx
, EXCP_RI
);
1441 save_cpu_state(ctx
, 1);
1443 ctx
->bstate
= BS_STOP
;
1446 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
1448 TranslationBlock
*tb
;
1450 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
1452 gen_op_goto_tb0(TBPARAM(tb
));
1454 gen_op_goto_tb1(TBPARAM(tb
));
1455 gen_op_save_pc(dest
);
1456 gen_op_set_T0((long)tb
+ n
);
1458 gen_op_save_pc(dest
);
1464 /* Branches (before delay slot) */
1465 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
1466 int rs
, int rt
, int32_t offset
)
1468 target_ulong btarget
= -1;
1472 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
1473 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
1475 "undefined branch in delay slot at PC " TARGET_FMT_lx
"\n",
1478 MIPS_INVAL("branch/jump in bdelay slot");
1479 generate_exception(ctx
, EXCP_RI
);
1483 /* Load needed operands */
1489 /* Compare two registers */
1491 GEN_LOAD_REG_TN(T0
, rs
);
1492 GEN_LOAD_REG_TN(T1
, rt
);
1495 btarget
= ctx
->pc
+ 4 + offset
;
1509 /* Compare to zero */
1511 gen_op_load_gpr_T0(rs
);
1514 btarget
= ctx
->pc
+ 4 + offset
;
1518 /* Jump to immediate */
1519 btarget
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | offset
;
1523 /* Jump to register */
1524 if (offset
!= 0 && offset
!= 16) {
1525 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1526 others are reserved. */
1527 generate_exception(ctx
, EXCP_RI
);
1530 GEN_LOAD_REG_TN(T2
, rs
);
1533 MIPS_INVAL("branch/jump");
1534 generate_exception(ctx
, EXCP_RI
);
1538 /* No condition to be computed */
1540 case OPC_BEQ
: /* rx == rx */
1541 case OPC_BEQL
: /* rx == rx likely */
1542 case OPC_BGEZ
: /* 0 >= 0 */
1543 case OPC_BGEZL
: /* 0 >= 0 likely */
1544 case OPC_BLEZ
: /* 0 <= 0 */
1545 case OPC_BLEZL
: /* 0 <= 0 likely */
1547 ctx
->hflags
|= MIPS_HFLAG_B
;
1548 MIPS_DEBUG("balways");
1550 case OPC_BGEZAL
: /* 0 >= 0 */
1551 case OPC_BGEZALL
: /* 0 >= 0 likely */
1552 /* Always take and link */
1554 ctx
->hflags
|= MIPS_HFLAG_B
;
1555 MIPS_DEBUG("balways and link");
1557 case OPC_BNE
: /* rx != rx */
1558 case OPC_BGTZ
: /* 0 > 0 */
1559 case OPC_BLTZ
: /* 0 < 0 */
1560 /* Treated as NOP */
1561 MIPS_DEBUG("bnever (NOP)");
1563 case OPC_BLTZAL
: /* 0 < 0 */
1564 gen_op_set_T0(ctx
->pc
+ 8);
1565 gen_op_store_T0_gpr(31);
1566 MIPS_DEBUG("bnever and link");
1568 case OPC_BLTZALL
: /* 0 < 0 likely */
1569 gen_op_set_T0(ctx
->pc
+ 8);
1570 gen_op_store_T0_gpr(31);
1571 /* Skip the instruction in the delay slot */
1572 MIPS_DEBUG("bnever, link and skip");
1575 case OPC_BNEL
: /* rx != rx likely */
1576 case OPC_BGTZL
: /* 0 > 0 likely */
1577 case OPC_BLTZL
: /* 0 < 0 likely */
1578 /* Skip the instruction in the delay slot */
1579 MIPS_DEBUG("bnever and skip");
1583 ctx
->hflags
|= MIPS_HFLAG_B
;
1584 MIPS_DEBUG("j %08x", btarget
);
1588 ctx
->hflags
|= MIPS_HFLAG_B
;
1589 MIPS_DEBUG("jal %08x", btarget
);
1592 ctx
->hflags
|= MIPS_HFLAG_BR
;
1593 MIPS_DEBUG("jr %s", regnames
[rs
]);
1597 ctx
->hflags
|= MIPS_HFLAG_BR
;
1598 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
1601 MIPS_INVAL("branch/jump");
1602 generate_exception(ctx
, EXCP_RI
);
1609 MIPS_DEBUG("beq %s, %s, %08x",
1610 regnames
[rs
], regnames
[rt
], btarget
);
1614 MIPS_DEBUG("beql %s, %s, %08x",
1615 regnames
[rs
], regnames
[rt
], btarget
);
1619 MIPS_DEBUG("bne %s, %s, %08x",
1620 regnames
[rs
], regnames
[rt
], btarget
);
1624 MIPS_DEBUG("bnel %s, %s, %08x",
1625 regnames
[rs
], regnames
[rt
], btarget
);
1629 MIPS_DEBUG("bgez %s, %08x", regnames
[rs
], btarget
);
1633 MIPS_DEBUG("bgezl %s, %08x", regnames
[rs
], btarget
);
1637 MIPS_DEBUG("bgezal %s, %08x", regnames
[rs
], btarget
);
1643 MIPS_DEBUG("bgezall %s, %08x", regnames
[rs
], btarget
);
1647 MIPS_DEBUG("bgtz %s, %08x", regnames
[rs
], btarget
);
1651 MIPS_DEBUG("bgtzl %s, %08x", regnames
[rs
], btarget
);
1655 MIPS_DEBUG("blez %s, %08x", regnames
[rs
], btarget
);
1659 MIPS_DEBUG("blezl %s, %08x", regnames
[rs
], btarget
);
1663 MIPS_DEBUG("bltz %s, %08x", regnames
[rs
], btarget
);
1667 MIPS_DEBUG("bltzl %s, %08x", regnames
[rs
], btarget
);
1672 MIPS_DEBUG("bltzal %s, %08x", regnames
[rs
], btarget
);
1674 ctx
->hflags
|= MIPS_HFLAG_BC
;
1679 MIPS_DEBUG("bltzall %s, %08x", regnames
[rs
], btarget
);
1681 ctx
->hflags
|= MIPS_HFLAG_BL
;
1684 MIPS_INVAL("conditional branch/jump");
1685 generate_exception(ctx
, EXCP_RI
);
1690 MIPS_DEBUG("enter ds: link %d cond %02x target %08x",
1691 blink
, ctx
->hflags
, btarget
);
1692 ctx
->btarget
= btarget
;
1694 gen_op_set_T0(ctx
->pc
+ 8);
1695 gen_op_store_T0_gpr(blink
);
1699 /* special3 bitfield operations */
1700 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
1701 int rs
, int lsb
, int msb
)
1703 GEN_LOAD_REG_TN(T1
, rs
);
1708 gen_op_ext(lsb
, msb
+ 1);
1713 gen_op_ext(lsb
, msb
+ 1 + 32);
1718 gen_op_ext(lsb
+ 32, msb
+ 1);
1721 gen_op_ext(lsb
, msb
+ 1);
1726 GEN_LOAD_REG_TN(T0
, rt
);
1727 gen_op_ins(lsb
, msb
- lsb
+ 1);
1732 GEN_LOAD_REG_TN(T0
, rt
);
1733 gen_op_ins(lsb
, msb
- lsb
+ 1 + 32);
1738 GEN_LOAD_REG_TN(T0
, rt
);
1739 gen_op_ins(lsb
+ 32, msb
- lsb
+ 1);
1744 GEN_LOAD_REG_TN(T0
, rt
);
1745 gen_op_ins(lsb
, msb
- lsb
+ 1);
1749 MIPS_INVAL("bitops");
1750 generate_exception(ctx
, EXCP_RI
);
1753 GEN_STORE_TN_REG(rt
, T0
);
1756 /* CP0 (MMU and control) */
1757 static void gen_mfc0 (DisasContext
*ctx
, int reg
, int sel
)
1759 const char *rn
= "invalid";
1765 gen_op_mfc0_index();
1769 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1773 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1777 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1787 gen_op_mfc0_random();
1791 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1795 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1799 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1803 // gen_op_mfc0_YQMask(); /* MT ASE */
1807 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1811 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1812 rn
= "VPEScheFBack";
1815 // gen_op_mfc0_vpeopt(); /* MT ASE */
1825 gen_op_mfc0_entrylo0();
1829 // gen_op_mfc0_tcstatus(); /* MT ASE */
1833 // gen_op_mfc0_tcbind(); /* MT ASE */
1837 // gen_op_mfc0_tcrestart(); /* MT ASE */
1841 // gen_op_mfc0_tchalt(); /* MT ASE */
1845 // gen_op_mfc0_tccontext(); /* MT ASE */
1849 // gen_op_mfc0_tcschedule(); /* MT ASE */
1853 // gen_op_mfc0_tcschefback(); /* MT ASE */
1863 gen_op_mfc0_entrylo1();
1873 gen_op_mfc0_context();
1877 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1878 rn
= "ContextConfig";
1887 gen_op_mfc0_pagemask();
1891 gen_op_mfc0_pagegrain();
1901 gen_op_mfc0_wired();
1905 // gen_op_mfc0_srsconf0(); /* shadow registers */
1909 // gen_op_mfc0_srsconf1(); /* shadow registers */
1913 // gen_op_mfc0_srsconf2(); /* shadow registers */
1917 // gen_op_mfc0_srsconf3(); /* shadow registers */
1921 // gen_op_mfc0_srsconf4(); /* shadow registers */
1931 gen_op_mfc0_hwrena();
1941 gen_op_mfc0_badvaddr();
1951 gen_op_mfc0_count();
1954 /* 6,7 are implementation dependent */
1962 gen_op_mfc0_entryhi();
1972 gen_op_mfc0_compare();
1975 /* 6,7 are implementation dependent */
1983 gen_op_mfc0_status();
1987 gen_op_mfc0_intctl();
1991 gen_op_mfc0_srsctl();
1995 // gen_op_mfc0_srsmap(); /* shadow registers */
2005 gen_op_mfc0_cause();
2029 gen_op_mfc0_ebase();
2039 gen_op_mfc0_config0();
2043 gen_op_mfc0_config1();
2047 gen_op_mfc0_config2();
2051 gen_op_mfc0_config3();
2054 /* 4,5 are reserved */
2055 /* 6,7 are implementation dependent */
2057 gen_op_mfc0_config6();
2061 gen_op_mfc0_config7();
2071 gen_op_mfc0_lladdr();
2081 gen_op_mfc0_watchlo0();
2085 // gen_op_mfc0_watchlo1();
2089 // gen_op_mfc0_watchlo2();
2093 // gen_op_mfc0_watchlo3();
2097 // gen_op_mfc0_watchlo4();
2101 // gen_op_mfc0_watchlo5();
2105 // gen_op_mfc0_watchlo6();
2109 // gen_op_mfc0_watchlo7();
2119 gen_op_mfc0_watchhi0();
2123 // gen_op_mfc0_watchhi1();
2127 // gen_op_mfc0_watchhi2();
2131 // gen_op_mfc0_watchhi3();
2135 // gen_op_mfc0_watchhi4();
2139 // gen_op_mfc0_watchhi5();
2143 // gen_op_mfc0_watchhi6();
2147 // gen_op_mfc0_watchhi7();
2157 /* 64 bit MMU only */
2158 gen_op_mfc0_xcontext();
2166 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2169 gen_op_mfc0_framemask();
2178 rn
= "'Diagnostic"; /* implementation dependent */
2183 gen_op_mfc0_debug(); /* EJTAG support */
2187 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2188 rn
= "TraceControl";
2191 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2192 rn
= "TraceControl2";
2195 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2196 rn
= "UserTraceData";
2199 // gen_op_mfc0_debug(); /* PDtrace support */
2209 gen_op_mfc0_depc(); /* EJTAG support */
2219 gen_op_mfc0_performance0();
2220 rn
= "Performance0";
2223 // gen_op_mfc0_performance1();
2224 rn
= "Performance1";
2227 // gen_op_mfc0_performance2();
2228 rn
= "Performance2";
2231 // gen_op_mfc0_performance3();
2232 rn
= "Performance3";
2235 // gen_op_mfc0_performance4();
2236 rn
= "Performance4";
2239 // gen_op_mfc0_performance5();
2240 rn
= "Performance5";
2243 // gen_op_mfc0_performance6();
2244 rn
= "Performance6";
2247 // gen_op_mfc0_performance7();
2248 rn
= "Performance7";
2273 gen_op_mfc0_taglo();
2280 gen_op_mfc0_datalo();
2293 gen_op_mfc0_taghi();
2300 gen_op_mfc0_datahi();
2310 gen_op_mfc0_errorepc();
2320 gen_op_mfc0_desave(); /* EJTAG support */
2330 #if defined MIPS_DEBUG_DISAS
2331 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2332 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2339 #if defined MIPS_DEBUG_DISAS
2340 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2341 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
2345 generate_exception(ctx
, EXCP_RI
);
2348 static void gen_mtc0 (DisasContext
*ctx
, int reg
, int sel
)
2350 const char *rn
= "invalid";
2356 gen_op_mtc0_index();
2360 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2364 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2368 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2382 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2386 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2390 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2394 // gen_op_mtc0_YQMask(); /* MT ASE */
2398 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2402 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2403 rn
= "VPEScheFBack";
2406 // gen_op_mtc0_vpeopt(); /* MT ASE */
2416 gen_op_mtc0_entrylo0();
2420 // gen_op_mtc0_tcstatus(); /* MT ASE */
2424 // gen_op_mtc0_tcbind(); /* MT ASE */
2428 // gen_op_mtc0_tcrestart(); /* MT ASE */
2432 // gen_op_mtc0_tchalt(); /* MT ASE */
2436 // gen_op_mtc0_tccontext(); /* MT ASE */
2440 // gen_op_mtc0_tcschedule(); /* MT ASE */
2444 // gen_op_mtc0_tcschefback(); /* MT ASE */
2454 gen_op_mtc0_entrylo1();
2464 gen_op_mtc0_context();
2468 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2469 rn
= "ContextConfig";
2478 gen_op_mtc0_pagemask();
2482 gen_op_mtc0_pagegrain();
2492 gen_op_mtc0_wired();
2496 // gen_op_mtc0_srsconf0(); /* shadow registers */
2500 // gen_op_mtc0_srsconf1(); /* shadow registers */
2504 // gen_op_mtc0_srsconf2(); /* shadow registers */
2508 // gen_op_mtc0_srsconf3(); /* shadow registers */
2512 // gen_op_mtc0_srsconf4(); /* shadow registers */
2522 gen_op_mtc0_hwrena();
2536 gen_op_mtc0_count();
2539 /* 6,7 are implementation dependent */
2543 /* Stop translation as we may have switched the execution mode */
2544 ctx
->bstate
= BS_STOP
;
2549 gen_op_mtc0_entryhi();
2559 gen_op_mtc0_compare();
2562 /* 6,7 are implementation dependent */
2566 /* Stop translation as we may have switched the execution mode */
2567 ctx
->bstate
= BS_STOP
;
2572 gen_op_mtc0_status();
2576 gen_op_mtc0_intctl();
2580 gen_op_mtc0_srsctl();
2584 // gen_op_mtc0_srsmap(); /* shadow registers */
2590 /* Stop translation as we may have switched the execution mode */
2591 ctx
->bstate
= BS_STOP
;
2596 gen_op_mtc0_cause();
2602 /* Stop translation as we may have switched the execution mode */
2603 ctx
->bstate
= BS_STOP
;
2622 gen_op_mtc0_ebase();
2632 gen_op_mtc0_config0();
2634 /* Stop translation as we may have switched the execution mode */
2635 ctx
->bstate
= BS_STOP
;
2638 /* ignored, read only */
2642 gen_op_mtc0_config2();
2644 /* Stop translation as we may have switched the execution mode */
2645 ctx
->bstate
= BS_STOP
;
2648 /* ignored, read only */
2651 /* 4,5 are reserved */
2652 /* 6,7 are implementation dependent */
2662 rn
= "Invalid config selector";
2679 gen_op_mtc0_watchlo0();
2683 // gen_op_mtc0_watchlo1();
2687 // gen_op_mtc0_watchlo2();
2691 // gen_op_mtc0_watchlo3();
2695 // gen_op_mtc0_watchlo4();
2699 // gen_op_mtc0_watchlo5();
2703 // gen_op_mtc0_watchlo6();
2707 // gen_op_mtc0_watchlo7();
2717 gen_op_mtc0_watchhi0();
2721 // gen_op_mtc0_watchhi1();
2725 // gen_op_mtc0_watchhi2();
2729 // gen_op_mtc0_watchhi3();
2733 // gen_op_mtc0_watchhi4();
2737 // gen_op_mtc0_watchhi5();
2741 // gen_op_mtc0_watchhi6();
2745 // gen_op_mtc0_watchhi7();
2755 /* 64 bit MMU only */
2756 /* Nothing writable in lower 32 bits */
2764 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2767 gen_op_mtc0_framemask();
2776 rn
= "Diagnostic"; /* implementation dependent */
2781 gen_op_mtc0_debug(); /* EJTAG support */
2785 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2786 rn
= "TraceControl";
2789 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2790 rn
= "TraceControl2";
2793 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2794 rn
= "UserTraceData";
2797 // gen_op_mtc0_debug(); /* PDtrace support */
2803 /* Stop translation as we may have switched the execution mode */
2804 ctx
->bstate
= BS_STOP
;
2809 gen_op_mtc0_depc(); /* EJTAG support */
2819 gen_op_mtc0_performance0();
2820 rn
= "Performance0";
2823 // gen_op_mtc0_performance1();
2824 rn
= "Performance1";
2827 // gen_op_mtc0_performance2();
2828 rn
= "Performance2";
2831 // gen_op_mtc0_performance3();
2832 rn
= "Performance3";
2835 // gen_op_mtc0_performance4();
2836 rn
= "Performance4";
2839 // gen_op_mtc0_performance5();
2840 rn
= "Performance5";
2843 // gen_op_mtc0_performance6();
2844 rn
= "Performance6";
2847 // gen_op_mtc0_performance7();
2848 rn
= "Performance7";
2874 gen_op_mtc0_taglo();
2881 gen_op_mtc0_datalo();
2894 gen_op_mtc0_taghi();
2901 gen_op_mtc0_datahi();
2912 gen_op_mtc0_errorepc();
2922 gen_op_mtc0_desave(); /* EJTAG support */
2928 /* Stop translation as we may have switched the execution mode */
2929 ctx
->bstate
= BS_STOP
;
2934 #if defined MIPS_DEBUG_DISAS
2935 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2936 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2943 #if defined MIPS_DEBUG_DISAS
2944 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2945 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
2949 generate_exception(ctx
, EXCP_RI
);
2952 #ifdef TARGET_MIPS64
2953 static void gen_dmfc0 (DisasContext
*ctx
, int reg
, int sel
)
2955 const char *rn
= "invalid";
2961 gen_op_mfc0_index();
2965 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
2969 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
2973 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
2983 gen_op_mfc0_random();
2987 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
2991 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
2995 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
2999 // gen_op_dmfc0_YQMask(); /* MT ASE */
3003 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3007 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3008 rn
= "VPEScheFBack";
3011 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3021 gen_op_dmfc0_entrylo0();
3025 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3029 // gen_op_dmfc0_tcbind(); /* MT ASE */
3033 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3037 // gen_op_dmfc0_tchalt(); /* MT ASE */
3041 // gen_op_dmfc0_tccontext(); /* MT ASE */
3045 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3049 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3059 gen_op_dmfc0_entrylo1();
3069 gen_op_dmfc0_context();
3073 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3074 rn
= "ContextConfig";
3083 gen_op_mfc0_pagemask();
3087 gen_op_mfc0_pagegrain();
3097 gen_op_mfc0_wired();
3101 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3105 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3109 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3113 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3117 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3127 gen_op_mfc0_hwrena();
3137 gen_op_dmfc0_badvaddr();
3147 gen_op_mfc0_count();
3150 /* 6,7 are implementation dependent */
3158 gen_op_dmfc0_entryhi();
3168 gen_op_mfc0_compare();
3171 /* 6,7 are implementation dependent */
3179 gen_op_mfc0_status();
3183 gen_op_mfc0_intctl();
3187 gen_op_mfc0_srsctl();
3191 gen_op_mfc0_srsmap(); /* shadow registers */
3201 gen_op_mfc0_cause();
3225 gen_op_mfc0_ebase();
3235 gen_op_mfc0_config0();
3239 gen_op_mfc0_config1();
3243 gen_op_mfc0_config2();
3247 gen_op_mfc0_config3();
3250 /* 6,7 are implementation dependent */
3258 gen_op_dmfc0_lladdr();
3268 gen_op_dmfc0_watchlo0();
3272 // gen_op_dmfc0_watchlo1();
3276 // gen_op_dmfc0_watchlo2();
3280 // gen_op_dmfc0_watchlo3();
3284 // gen_op_dmfc0_watchlo4();
3288 // gen_op_dmfc0_watchlo5();
3292 // gen_op_dmfc0_watchlo6();
3296 // gen_op_dmfc0_watchlo7();
3306 gen_op_mfc0_watchhi0();
3310 // gen_op_mfc0_watchhi1();
3314 // gen_op_mfc0_watchhi2();
3318 // gen_op_mfc0_watchhi3();
3322 // gen_op_mfc0_watchhi4();
3326 // gen_op_mfc0_watchhi5();
3330 // gen_op_mfc0_watchhi6();
3334 // gen_op_mfc0_watchhi7();
3344 /* 64 bit MMU only */
3345 gen_op_dmfc0_xcontext();
3353 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3356 gen_op_mfc0_framemask();
3365 rn
= "'Diagnostic"; /* implementation dependent */
3370 gen_op_mfc0_debug(); /* EJTAG support */
3374 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3375 rn
= "TraceControl";
3378 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3379 rn
= "TraceControl2";
3382 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3383 rn
= "UserTraceData";
3386 // gen_op_dmfc0_debug(); /* PDtrace support */
3396 gen_op_dmfc0_depc(); /* EJTAG support */
3406 gen_op_mfc0_performance0();
3407 rn
= "Performance0";
3410 // gen_op_dmfc0_performance1();
3411 rn
= "Performance1";
3414 // gen_op_dmfc0_performance2();
3415 rn
= "Performance2";
3418 // gen_op_dmfc0_performance3();
3419 rn
= "Performance3";
3422 // gen_op_dmfc0_performance4();
3423 rn
= "Performance4";
3426 // gen_op_dmfc0_performance5();
3427 rn
= "Performance5";
3430 // gen_op_dmfc0_performance6();
3431 rn
= "Performance6";
3434 // gen_op_dmfc0_performance7();
3435 rn
= "Performance7";
3460 gen_op_mfc0_taglo();
3467 gen_op_mfc0_datalo();
3480 gen_op_mfc0_taghi();
3487 gen_op_mfc0_datahi();
3497 gen_op_dmfc0_errorepc();
3507 gen_op_mfc0_desave(); /* EJTAG support */
3517 #if defined MIPS_DEBUG_DISAS
3518 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3519 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3526 #if defined MIPS_DEBUG_DISAS
3527 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3528 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
3532 generate_exception(ctx
, EXCP_RI
);
3535 static void gen_dmtc0 (DisasContext
*ctx
, int reg
, int sel
)
3537 const char *rn
= "invalid";
3543 gen_op_mtc0_index();
3547 // gen_op_dmtc0_mvpcontrol(); /* MT ASE */
3551 // gen_op_dmtc0_mvpconf0(); /* MT ASE */
3555 // gen_op_dmtc0_mvpconf1(); /* MT ASE */
3569 // gen_op_dmtc0_vpecontrol(); /* MT ASE */
3573 // gen_op_dmtc0_vpeconf0(); /* MT ASE */
3577 // gen_op_dmtc0_vpeconf1(); /* MT ASE */
3581 // gen_op_dmtc0_YQMask(); /* MT ASE */
3585 // gen_op_dmtc0_vpeschedule(); /* MT ASE */
3589 // gen_op_dmtc0_vpeschefback(); /* MT ASE */
3590 rn
= "VPEScheFBack";
3593 // gen_op_dmtc0_vpeopt(); /* MT ASE */
3603 gen_op_dmtc0_entrylo0();
3607 // gen_op_dmtc0_tcstatus(); /* MT ASE */
3611 // gen_op_dmtc0_tcbind(); /* MT ASE */
3615 // gen_op_dmtc0_tcrestart(); /* MT ASE */
3619 // gen_op_dmtc0_tchalt(); /* MT ASE */
3623 // gen_op_dmtc0_tccontext(); /* MT ASE */
3627 // gen_op_dmtc0_tcschedule(); /* MT ASE */
3631 // gen_op_dmtc0_tcschefback(); /* MT ASE */
3641 gen_op_dmtc0_entrylo1();
3651 gen_op_dmtc0_context();
3655 // gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
3656 rn
= "ContextConfig";
3665 gen_op_mtc0_pagemask();
3669 gen_op_mtc0_pagegrain();
3679 gen_op_mtc0_wired();
3683 // gen_op_dmtc0_srsconf0(); /* shadow registers */
3687 // gen_op_dmtc0_srsconf1(); /* shadow registers */
3691 // gen_op_dmtc0_srsconf2(); /* shadow registers */
3695 // gen_op_dmtc0_srsconf3(); /* shadow registers */
3699 // gen_op_dmtc0_srsconf4(); /* shadow registers */
3709 gen_op_mtc0_hwrena();
3723 gen_op_mtc0_count();
3726 /* 6,7 are implementation dependent */
3730 /* Stop translation as we may have switched the execution mode */
3731 ctx
->bstate
= BS_STOP
;
3736 gen_op_mtc0_entryhi();
3746 gen_op_mtc0_compare();
3749 /* 6,7 are implementation dependent */
3753 /* Stop translation as we may have switched the execution mode */
3754 ctx
->bstate
= BS_STOP
;
3759 gen_op_mtc0_status();
3763 gen_op_mtc0_intctl();
3767 gen_op_mtc0_srsctl();
3771 gen_op_mtc0_srsmap(); /* shadow registers */
3777 /* Stop translation as we may have switched the execution mode */
3778 ctx
->bstate
= BS_STOP
;
3783 gen_op_mtc0_cause();
3789 /* Stop translation as we may have switched the execution mode */
3790 ctx
->bstate
= BS_STOP
;
3809 gen_op_mtc0_ebase();
3819 gen_op_mtc0_config0();
3821 /* Stop translation as we may have switched the execution mode */
3822 ctx
->bstate
= BS_STOP
;
3829 gen_op_mtc0_config2();
3831 /* Stop translation as we may have switched the execution mode */
3832 ctx
->bstate
= BS_STOP
;
3838 /* 6,7 are implementation dependent */
3840 rn
= "Invalid config selector";
3857 gen_op_dmtc0_watchlo0();
3861 // gen_op_dmtc0_watchlo1();
3865 // gen_op_dmtc0_watchlo2();
3869 // gen_op_dmtc0_watchlo3();
3873 // gen_op_dmtc0_watchlo4();
3877 // gen_op_dmtc0_watchlo5();
3881 // gen_op_dmtc0_watchlo6();
3885 // gen_op_dmtc0_watchlo7();
3895 gen_op_mtc0_watchhi0();
3899 // gen_op_dmtc0_watchhi1();
3903 // gen_op_dmtc0_watchhi2();
3907 // gen_op_dmtc0_watchhi3();
3911 // gen_op_dmtc0_watchhi4();
3915 // gen_op_dmtc0_watchhi5();
3919 // gen_op_dmtc0_watchhi6();
3923 // gen_op_dmtc0_watchhi7();
3933 /* 64 bit MMU only */
3934 gen_op_dmtc0_xcontext();
3942 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3945 gen_op_mtc0_framemask();
3954 rn
= "Diagnostic"; /* implementation dependent */
3959 gen_op_mtc0_debug(); /* EJTAG support */
3963 // gen_op_dmtc0_tracecontrol(); /* PDtrace support */
3964 rn
= "TraceControl";
3967 // gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
3968 rn
= "TraceControl2";
3971 // gen_op_dmtc0_usertracedata(); /* PDtrace support */
3972 rn
= "UserTraceData";
3975 // gen_op_dmtc0_debug(); /* PDtrace support */
3981 /* Stop translation as we may have switched the execution mode */
3982 ctx
->bstate
= BS_STOP
;
3987 gen_op_dmtc0_depc(); /* EJTAG support */
3997 gen_op_mtc0_performance0();
3998 rn
= "Performance0";
4001 // gen_op_dmtc0_performance1();
4002 rn
= "Performance1";
4005 // gen_op_dmtc0_performance2();
4006 rn
= "Performance2";
4009 // gen_op_dmtc0_performance3();
4010 rn
= "Performance3";
4013 // gen_op_dmtc0_performance4();
4014 rn
= "Performance4";
4017 // gen_op_dmtc0_performance5();
4018 rn
= "Performance5";
4021 // gen_op_dmtc0_performance6();
4022 rn
= "Performance6";
4025 // gen_op_dmtc0_performance7();
4026 rn
= "Performance7";
4052 gen_op_mtc0_taglo();
4059 gen_op_mtc0_datalo();
4072 gen_op_mtc0_taghi();
4079 gen_op_mtc0_datahi();
4090 gen_op_dmtc0_errorepc();
4100 gen_op_mtc0_desave(); /* EJTAG support */
4106 /* Stop translation as we may have switched the execution mode */
4107 ctx
->bstate
= BS_STOP
;
4112 #if defined MIPS_DEBUG_DISAS
4113 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4114 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4121 #if defined MIPS_DEBUG_DISAS
4122 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4123 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
4127 generate_exception(ctx
, EXCP_RI
);
4129 #endif /* TARGET_MIPS64 */
4131 static void gen_cp0 (DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
4133 const char *opn
= "unk";
4141 gen_mfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4142 gen_op_store_T0_gpr(rt
);
4146 GEN_LOAD_REG_TN(T0
, rt
);
4147 gen_mtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4150 #ifdef TARGET_MIPS64
4156 gen_dmfc0(ctx
, rd
, ctx
->opcode
& 0x7);
4157 gen_op_store_T0_gpr(rt
);
4161 GEN_LOAD_REG_TN(T0
, rt
);
4162 gen_dmtc0(ctx
, rd
, ctx
->opcode
& 0x7);
4166 #if defined(MIPS_USES_R4K_TLB)
4186 save_cpu_state(ctx
, 0);
4188 ctx
->bstate
= BS_EXCP
;
4192 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4193 generate_exception(ctx
, EXCP_RI
);
4195 save_cpu_state(ctx
, 0);
4197 ctx
->bstate
= BS_EXCP
;
4202 /* If we get an exception, we want to restart at next instruction */
4204 save_cpu_state(ctx
, 1);
4207 ctx
->bstate
= BS_EXCP
;
4210 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4211 fprintf(logfile
, "Invalid CP0 opcode: %08x %03x %03x %03x\n",
4212 ctx
->opcode
, ctx
->opcode
>> 26, ctx
->opcode
& 0x3F,
4213 ((ctx
->opcode
>> 16) & 0x1F));
4215 generate_exception(ctx
, EXCP_RI
);
4218 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
4221 /* CP1 Branches (before delay slot) */
4222 static void gen_compute_branch1 (DisasContext
*ctx
, uint32_t op
,
4225 target_ulong btarget
;
4227 btarget
= ctx
->pc
+ 4 + offset
;
4232 MIPS_DEBUG("bc1f " TARGET_FMT_lx
, btarget
);
4236 MIPS_DEBUG("bc1fl " TARGET_FMT_lx
, btarget
);
4240 MIPS_DEBUG("bc1t " TARGET_FMT_lx
, btarget
);
4242 ctx
->hflags
|= MIPS_HFLAG_BC
;
4246 MIPS_DEBUG("bc1tl " TARGET_FMT_lx
, btarget
);
4248 ctx
->hflags
|= MIPS_HFLAG_BL
;
4251 MIPS_INVAL("cp1 branch/jump");
4252 generate_exception (ctx
, EXCP_RI
);
4257 MIPS_DEBUG("enter ds: cond %02x target " TARGET_FMT_lx
,
4258 ctx
->hflags
, btarget
);
4259 ctx
->btarget
= btarget
;
4264 /* Coprocessor 1 (FPU) */
4265 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
4267 const char *opn
= "unk";
4271 GEN_LOAD_FREG_FTN(WT0
, fs
);
4273 GEN_STORE_TN_REG(rt
, T0
);
4277 GEN_LOAD_REG_TN(T0
, rt
);
4279 GEN_STORE_FTN_FREG(fs
, WT0
);
4283 if (fs
!= 0 && fs
!= 31) {
4284 MIPS_INVAL("cfc1 freg");
4285 generate_exception (ctx
, EXCP_RI
);
4288 GEN_LOAD_IMM_TN(T1
, fs
);
4290 GEN_STORE_TN_REG(rt
, T0
);
4294 if (fs
!= 0 && fs
!= 31) {
4295 MIPS_INVAL("ctc1 freg");
4296 generate_exception (ctx
, EXCP_RI
);
4299 GEN_LOAD_IMM_TN(T1
, fs
);
4300 GEN_LOAD_REG_TN(T0
, rt
);
4306 /* Not implemented, fallthrough. */
4308 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4309 fprintf(logfile
, "Invalid CP1 opcode: %08x %03x %03x %03x\n",
4310 ctx
->opcode
, ctx
->opcode
>> 26, ctx
->opcode
& 0x3F,
4311 ((ctx
->opcode
>> 16) & 0x1F));
4313 generate_exception (ctx
, EXCP_RI
);
4316 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
4319 /* verify if floating point register is valid; an operation is not defined
4320 * if bit 0 of any register specification is set and the FR bit in the
4321 * Status register equals zero, since the register numbers specify an
4322 * even-odd pair of adjacent coprocessor general registers. When the FR bit
4323 * in the Status register equals one, both even and odd register numbers
4324 * are valid. This limitation exists only for 64 bit wide (d,l) registers.
4326 * Multiple 64 bit wide registers can be checked by calling
4327 * CHECK_FR(ctx, freg1 | freg2 | ... | fregN);
4329 #define CHECK_FR(ctx, freg) do { \
4330 if (!((ctx)->CP0_Status & (1<<CP0St_FR)) && ((freg) & 1)) { \
4331 generate_exception (ctx, EXCP_RI); \
4336 #define FOP(func, fmt) (((fmt) << 21) | (func))
4338 static void gen_farith (DisasContext
*ctx
, uint32_t op1
, int ft
, int fs
, int fd
)
4340 const char *opn
= "unk";
4341 const char *condnames
[] = {
4360 uint32_t func
= ctx
->opcode
& 0x3f;
4362 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
4364 CHECK_FR(ctx
, fs
| ft
| fd
);
4365 GEN_LOAD_FREG_FTN(DT0
, fs
);
4366 GEN_LOAD_FREG_FTN(DT1
, ft
);
4367 gen_op_float_add_d();
4368 GEN_STORE_FTN_FREG(fd
, DT2
);
4373 CHECK_FR(ctx
, fs
| ft
| fd
);
4374 GEN_LOAD_FREG_FTN(DT0
, fs
);
4375 GEN_LOAD_FREG_FTN(DT1
, ft
);
4376 gen_op_float_sub_d();
4377 GEN_STORE_FTN_FREG(fd
, DT2
);
4382 CHECK_FR(ctx
, fs
| ft
| fd
);
4383 GEN_LOAD_FREG_FTN(DT0
, fs
);
4384 GEN_LOAD_FREG_FTN(DT1
, ft
);
4385 gen_op_float_mul_d();
4386 GEN_STORE_FTN_FREG(fd
, DT2
);
4391 CHECK_FR(ctx
, fs
| ft
| fd
);
4392 GEN_LOAD_FREG_FTN(DT0
, fs
);
4393 GEN_LOAD_FREG_FTN(DT1
, ft
);
4394 gen_op_float_div_d();
4395 GEN_STORE_FTN_FREG(fd
, DT2
);
4400 CHECK_FR(ctx
, fs
| fd
);
4401 GEN_LOAD_FREG_FTN(DT0
, fs
);
4402 gen_op_float_sqrt_d();
4403 GEN_STORE_FTN_FREG(fd
, DT2
);
4407 CHECK_FR(ctx
, fs
| fd
);
4408 GEN_LOAD_FREG_FTN(DT0
, fs
);
4409 gen_op_float_abs_d();
4410 GEN_STORE_FTN_FREG(fd
, DT2
);
4414 CHECK_FR(ctx
, fs
| fd
);
4415 GEN_LOAD_FREG_FTN(DT0
, fs
);
4416 gen_op_float_mov_d();
4417 GEN_STORE_FTN_FREG(fd
, DT2
);
4421 CHECK_FR(ctx
, fs
| fd
);
4422 GEN_LOAD_FREG_FTN(DT0
, fs
);
4423 gen_op_float_chs_d();
4424 GEN_STORE_FTN_FREG(fd
, DT2
);
4433 GEN_LOAD_FREG_FTN(DT0
, fs
);
4434 gen_op_float_roundw_d();
4435 GEN_STORE_FTN_FREG(fd
, WT2
);
4440 GEN_LOAD_FREG_FTN(DT0
, fs
);
4441 gen_op_float_truncw_d();
4442 GEN_STORE_FTN_FREG(fd
, WT2
);
4447 GEN_LOAD_FREG_FTN(DT0
, fs
);
4448 gen_op_float_ceilw_d();
4449 GEN_STORE_FTN_FREG(fd
, WT2
);
4454 GEN_LOAD_FREG_FTN(DT0
, fs
);
4455 gen_op_float_floorw_d();
4456 GEN_STORE_FTN_FREG(fd
, WT2
);
4461 GEN_LOAD_FREG_FTN(WT0
, fs
);
4462 gen_op_float_cvtd_s();
4463 GEN_STORE_FTN_FREG(fd
, DT2
);
4468 GEN_LOAD_FREG_FTN(WT0
, fs
);
4469 gen_op_float_cvtd_w();
4470 GEN_STORE_FTN_FREG(fd
, DT2
);
4489 CHECK_FR(ctx
, fs
| ft
);
4490 GEN_LOAD_FREG_FTN(DT0
, fs
);
4491 GEN_LOAD_FREG_FTN(DT1
, ft
);
4493 opn
= condnames
[func
-48];
4496 GEN_LOAD_FREG_FTN(WT0
, fs
);
4497 GEN_LOAD_FREG_FTN(WT1
, ft
);
4498 gen_op_float_add_s();
4499 GEN_STORE_FTN_FREG(fd
, WT2
);
4504 GEN_LOAD_FREG_FTN(WT0
, fs
);
4505 GEN_LOAD_FREG_FTN(WT1
, ft
);
4506 gen_op_float_sub_s();
4507 GEN_STORE_FTN_FREG(fd
, WT2
);
4512 GEN_LOAD_FREG_FTN(WT0
, fs
);
4513 GEN_LOAD_FREG_FTN(WT1
, ft
);
4514 gen_op_float_mul_s();
4515 GEN_STORE_FTN_FREG(fd
, WT2
);
4520 GEN_LOAD_FREG_FTN(WT0
, fs
);
4521 GEN_LOAD_FREG_FTN(WT1
, ft
);
4522 gen_op_float_div_s();
4523 GEN_STORE_FTN_FREG(fd
, WT2
);
4528 GEN_LOAD_FREG_FTN(WT0
, fs
);
4529 gen_op_float_sqrt_s();
4530 GEN_STORE_FTN_FREG(fd
, WT2
);
4534 GEN_LOAD_FREG_FTN(WT0
, fs
);
4535 gen_op_float_abs_s();
4536 GEN_STORE_FTN_FREG(fd
, WT2
);
4540 GEN_LOAD_FREG_FTN(WT0
, fs
);
4541 gen_op_float_mov_s();
4542 GEN_STORE_FTN_FREG(fd
, WT2
);
4546 GEN_LOAD_FREG_FTN(WT0
, fs
);
4547 gen_op_float_chs_s();
4548 GEN_STORE_FTN_FREG(fd
, WT2
);
4552 GEN_LOAD_FREG_FTN(WT0
, fs
);
4553 gen_op_float_roundw_s();
4554 GEN_STORE_FTN_FREG(fd
, WT2
);
4558 GEN_LOAD_FREG_FTN(WT0
, fs
);
4559 gen_op_float_truncw_s();
4560 GEN_STORE_FTN_FREG(fd
, WT2
);
4565 GEN_LOAD_FREG_FTN(DT0
, fs
);
4566 gen_op_float_cvts_d();
4567 GEN_STORE_FTN_FREG(fd
, WT2
);
4571 GEN_LOAD_FREG_FTN(WT0
, fs
);
4572 gen_op_float_cvts_w();
4573 GEN_STORE_FTN_FREG(fd
, WT2
);
4577 GEN_LOAD_FREG_FTN(WT0
, fs
);
4578 gen_op_float_cvtw_s();
4579 GEN_STORE_FTN_FREG(fd
, WT2
);
4584 GEN_LOAD_FREG_FTN(DT0
, fs
);
4585 gen_op_float_cvtw_d();
4586 GEN_STORE_FTN_FREG(fd
, WT2
);
4605 GEN_LOAD_FREG_FTN(WT0
, fs
);
4606 GEN_LOAD_FREG_FTN(WT1
, ft
);
4608 opn
= condnames
[func
-48];
4611 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4612 fprintf(logfile
, "Invalid FP arith function: %08x %03x %03x %03x\n",
4613 ctx
->opcode
, ctx
->opcode
>> 26, ctx
->opcode
& 0x3F,
4614 ((ctx
->opcode
>> 16) & 0x1F));
4616 generate_exception (ctx
, EXCP_RI
);
4620 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
4622 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
4625 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
4630 ccbit
= 1 << (24 + cc
);
4634 gen_op_movf(ccbit
, rd
, rs
);
4636 gen_op_movt(ccbit
, rd
, rs
);
4639 /* ISA extensions (ASEs) */
4640 /* MIPS16 extension to MIPS32 */
4641 /* SmartMIPS extension to MIPS32 */
4643 #ifdef TARGET_MIPS64
4644 /* Coprocessor 3 (FPU) */
4646 /* MDMX extension to MIPS64 */
4647 /* MIPS-3D extension to MIPS64 */
4651 static void gen_blikely(DisasContext
*ctx
)
4654 l1
= gen_new_label();
4656 gen_op_save_state(ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
4657 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
4661 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
4665 uint32_t op
, op1
, op2
;
4668 /* make sure instructions are on a word boundary */
4669 if (ctx
->pc
& 0x3) {
4670 env
->CP0_BadVAddr
= ctx
->pc
;
4671 generate_exception(ctx
, EXCP_AdEL
);
4675 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
4676 /* Handle blikely not taken case */
4677 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
4680 op
= MASK_OP_MAJOR(ctx
->opcode
);
4681 rs
= (ctx
->opcode
>> 21) & 0x1f;
4682 rt
= (ctx
->opcode
>> 16) & 0x1f;
4683 rd
= (ctx
->opcode
>> 11) & 0x1f;
4684 sa
= (ctx
->opcode
>> 6) & 0x1f;
4685 imm
= (int16_t)ctx
->opcode
;
4688 op1
= MASK_SPECIAL(ctx
->opcode
);
4690 case OPC_SLL
: /* Arithmetic with immediate */
4691 case OPC_SRL
... OPC_SRA
:
4692 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
4694 case OPC_SLLV
: /* Arithmetic */
4695 case OPC_SRLV
... OPC_SRAV
:
4696 case OPC_MOVZ
... OPC_MOVN
:
4697 case OPC_ADD
... OPC_NOR
:
4698 case OPC_SLT
... OPC_SLTU
:
4699 gen_arith(ctx
, op1
, rd
, rs
, rt
);
4701 case OPC_MULT
... OPC_DIVU
:
4702 gen_muldiv(ctx
, op1
, rs
, rt
);
4704 case OPC_JR
... OPC_JALR
:
4705 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
4707 case OPC_TGE
... OPC_TEQ
: /* Traps */
4709 gen_trap(ctx
, op1
, rs
, rt
, -1);
4711 case OPC_MFHI
: /* Move from HI/LO */
4713 gen_HILO(ctx
, op1
, rd
);
4716 case OPC_MTLO
: /* Move to HI/LO */
4717 gen_HILO(ctx
, op1
, rs
);
4719 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
4720 #ifdef MIPS_STRICT_STANDARD
4721 MIPS_INVAL("PMON / selsl");
4722 generate_exception(ctx
, EXCP_RI
);
4728 generate_exception(ctx
, EXCP_SYSCALL
);
4731 generate_exception(ctx
, EXCP_BREAK
);
4734 #ifdef MIPS_STRICT_STANDARD
4736 generate_exception(ctx
, EXCP_RI
);
4738 /* Implemented as RI exception for now. */
4739 MIPS_INVAL("spim (unofficial)");
4740 generate_exception(ctx
, EXCP_RI
);
4744 /* Treat as a noop. */
4748 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
4749 save_cpu_state(ctx
, 1);
4750 gen_op_cp1_enabled();
4751 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
4752 (ctx
->opcode
>> 16) & 1);
4754 generate_exception_err(ctx
, EXCP_CpU
, 1);
4758 #ifdef TARGET_MIPS64
4759 /* MIPS64 specific opcodes */
4761 case OPC_DSRL
... OPC_DSRA
:
4763 case OPC_DSRL32
... OPC_DSRA32
:
4764 gen_arith_imm(ctx
, op1
, rd
, rt
, sa
);
4767 case OPC_DSRLV
... OPC_DSRAV
:
4768 case OPC_DADD
... OPC_DSUBU
:
4769 gen_arith(ctx
, op1
, rd
, rs
, rt
);
4771 case OPC_DMULT
... OPC_DDIVU
:
4772 gen_muldiv(ctx
, op1
, rs
, rt
);
4775 default: /* Invalid */
4776 MIPS_INVAL("special");
4777 generate_exception(ctx
, EXCP_RI
);
4782 op1
= MASK_SPECIAL2(ctx
->opcode
);
4784 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
4785 case OPC_MSUB
... OPC_MSUBU
:
4786 gen_muldiv(ctx
, op1
, rs
, rt
);
4789 gen_arith(ctx
, op1
, rd
, rs
, rt
);
4791 case OPC_CLZ
... OPC_CLO
:
4792 gen_cl(ctx
, op1
, rd
, rs
);
4795 /* XXX: not clear which exception should be raised
4796 * when in debug mode...
4798 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
4799 generate_exception(ctx
, EXCP_DBp
);
4801 generate_exception(ctx
, EXCP_DBp
);
4803 /* Treat as a noop */
4805 #ifdef TARGET_MIPS64
4806 case OPC_DCLZ
... OPC_DCLO
:
4807 gen_cl(ctx
, op1
, rd
, rs
);
4810 default: /* Invalid */
4811 MIPS_INVAL("special2");
4812 generate_exception(ctx
, EXCP_RI
);
4817 op1
= MASK_SPECIAL3(ctx
->opcode
);
4821 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
4824 op2
= MASK_BSHFL(ctx
->opcode
);
4827 GEN_LOAD_REG_TN(T1
, rt
);
4831 GEN_LOAD_REG_TN(T1
, rt
);
4835 GEN_LOAD_REG_TN(T1
, rt
);
4838 default: /* Invalid */
4839 MIPS_INVAL("bshfl");
4840 generate_exception(ctx
, EXCP_RI
);
4843 GEN_STORE_TN_REG(rd
, T0
);
4848 save_cpu_state(ctx
, 1);
4849 gen_op_rdhwr_cpunum();
4852 save_cpu_state(ctx
, 1);
4853 gen_op_rdhwr_synci_step();
4856 save_cpu_state(ctx
, 1);
4860 save_cpu_state(ctx
, 1);
4861 gen_op_rdhwr_ccres();
4864 #if defined (CONFIG_USER_ONLY)
4865 gen_op_tls_value ();
4868 default: /* Invalid */
4869 MIPS_INVAL("rdhwr");
4870 generate_exception(ctx
, EXCP_RI
);
4873 GEN_STORE_TN_REG(rt
, T0
);
4875 #ifdef TARGET_MIPS64
4876 case OPC_DEXTM
... OPC_DEXT
:
4877 case OPC_DINSM
... OPC_DINS
:
4878 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
4881 op2
= MASK_DBSHFL(ctx
->opcode
);
4884 GEN_LOAD_REG_TN(T1
, rt
);
4888 GEN_LOAD_REG_TN(T1
, rt
);
4891 default: /* Invalid */
4892 MIPS_INVAL("dbshfl");
4893 generate_exception(ctx
, EXCP_RI
);
4896 GEN_STORE_TN_REG(rd
, T0
);
4898 default: /* Invalid */
4899 MIPS_INVAL("special3");
4900 generate_exception(ctx
, EXCP_RI
);
4905 op1
= MASK_REGIMM(ctx
->opcode
);
4907 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
4908 case OPC_BLTZAL
... OPC_BGEZALL
:
4909 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
4911 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
4913 gen_trap(ctx
, op1
, rs
, -1, imm
);
4918 default: /* Invalid */
4919 MIPS_INVAL("REGIMM");
4920 generate_exception(ctx
, EXCP_RI
);
4925 save_cpu_state(ctx
, 1);
4926 gen_op_cp0_enabled();
4927 op1
= MASK_CP0(ctx
->opcode
);
4931 #ifdef TARGET_MIPS64
4935 gen_cp0(ctx
, op1
, rt
, rd
);
4937 case OPC_C0_FIRST
... OPC_C0_LAST
:
4938 gen_cp0(ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
4941 op2
= MASK_MFMC0(ctx
->opcode
);
4945 /* Stop translation as we may have switched the execution mode */
4946 ctx
->bstate
= BS_STOP
;
4950 /* Stop translation as we may have switched the execution mode */
4951 ctx
->bstate
= BS_STOP
;
4953 default: /* Invalid */
4954 MIPS_INVAL("MFMC0");
4955 generate_exception(ctx
, EXCP_RI
);
4958 GEN_STORE_TN_REG(rt
, T0
);
4962 if ((env
->CP0_Config0
& (0x7 << CP0C0_AR
)) == (1 << CP0C0_AR
)) {
4963 /* Shadow registers not implemented. */
4964 GEN_LOAD_REG_TN(T0
, rt
);
4965 GEN_STORE_TN_REG(rd
, T0
);
4967 generate_exception(ctx
, EXCP_RI
);
4970 generate_exception(ctx
, EXCP_RI
);
4974 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
4975 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
4977 case OPC_J
... OPC_JAL
: /* Jump */
4978 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
4979 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
4981 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
4982 case OPC_BEQL
... OPC_BGTZL
:
4983 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
4985 case OPC_LB
... OPC_LWR
: /* Load and stores */
4986 case OPC_SB
... OPC_SW
:
4990 gen_ldst(ctx
, op
, rt
, rs
, imm
);
4993 /* Treat as a noop */
4996 /* Treat as a noop */
4999 /* Floating point. */
5004 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5005 save_cpu_state(ctx
, 1);
5006 gen_op_cp1_enabled();
5007 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
5009 generate_exception_err(ctx
, EXCP_CpU
, 1);
5014 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5015 save_cpu_state(ctx
, 1);
5016 gen_op_cp1_enabled();
5017 op1
= MASK_CP1(ctx
->opcode
);
5023 #ifdef TARGET_MIPS64
5027 gen_cp1(ctx
, op1
, rt
, rd
);
5030 gen_compute_branch1(ctx
, MASK_CP1_BCOND(ctx
->opcode
), imm
<< 2);
5036 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
);
5039 generate_exception (ctx
, EXCP_RI
);
5043 generate_exception_err(ctx
, EXCP_CpU
, 1);
5053 /* COP2: Not implemented. */
5054 generate_exception_err(ctx
, EXCP_CpU
, 2);
5058 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
5059 save_cpu_state(ctx
, 1);
5060 gen_op_cp1_enabled();
5061 op1
= MASK_CP3(ctx
->opcode
);
5066 /* Not implemented */
5068 generate_exception (ctx
, EXCP_RI
);
5072 generate_exception_err(ctx
, EXCP_CpU
, 1);
5076 #ifdef TARGET_MIPS64
5077 /* MIPS64 opcodes */
5079 case OPC_LDL
... OPC_LDR
:
5080 case OPC_SDL
... OPC_SDR
:
5085 gen_ldst(ctx
, op
, rt
, rs
, imm
);
5087 case OPC_DADDI
... OPC_DADDIU
:
5088 gen_arith_imm(ctx
, op
, rt
, rs
, imm
);
5091 #ifdef MIPS_HAS_MIPS16
5093 /* MIPS16: Not implemented. */
5095 #ifdef MIPS_HAS_MDMX
5097 /* MDMX: Not implemented. */
5099 default: /* Invalid */
5101 generate_exception(ctx
, EXCP_RI
);
5104 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
5105 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
5106 /* Branches completion */
5107 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
5108 ctx
->bstate
= BS_BRANCH
;
5109 save_cpu_state(ctx
, 0);
5110 switch (hflags
& MIPS_HFLAG_BMASK
) {
5112 /* unconditional branch */
5113 MIPS_DEBUG("unconditional branch");
5114 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5117 /* blikely taken case */
5118 MIPS_DEBUG("blikely branch taken");
5119 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5122 /* Conditional branch */
5123 MIPS_DEBUG("conditional branch");
5126 l1
= gen_new_label();
5128 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
5130 gen_goto_tb(ctx
, 0, ctx
->btarget
);
5134 /* unconditional branch to register */
5135 MIPS_DEBUG("branch to register");
5139 MIPS_DEBUG("unknown branch");
5146 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
5149 DisasContext ctx
, *ctxp
= &ctx
;
5150 target_ulong pc_start
;
5151 uint16_t *gen_opc_end
;
5154 if (search_pc
&& loglevel
)
5155 fprintf (logfile
, "search pc %d\n", search_pc
);
5158 gen_opc_ptr
= gen_opc_buf
;
5159 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
5160 gen_opparam_ptr
= gen_opparam_buf
;
5165 ctx
.bstate
= BS_NONE
;
5166 /* Restore delay slot state from the tb context. */
5167 ctx
.hflags
= tb
->flags
;
5168 ctx
.saved_hflags
= ctx
.hflags
;
5169 if (ctx
.hflags
& MIPS_HFLAG_BR
) {
5170 gen_op_restore_breg_target();
5171 } else if (ctx
.hflags
& MIPS_HFLAG_B
) {
5172 ctx
.btarget
= env
->btarget
;
5173 } else if (ctx
.hflags
& MIPS_HFLAG_BMASK
) {
5174 /* If we are in the delay slot of a conditional branch,
5175 * restore the branch condition from env->bcond to T2
5177 ctx
.btarget
= env
->btarget
;
5178 gen_op_restore_bcond();
5180 #if defined(CONFIG_USER_ONLY)
5183 ctx
.mem_idx
= !((ctx
.hflags
& MIPS_HFLAG_MODE
) == MIPS_HFLAG_UM
);
5185 ctx
.CP0_Status
= env
->CP0_Status
;
5187 if (loglevel
& CPU_LOG_TB_CPU
) {
5188 fprintf(logfile
, "------------------------------------------------\n");
5189 /* FIXME: This may print out stale hflags from env... */
5190 cpu_dump_state(env
, logfile
, fprintf
, 0);
5193 #if defined MIPS_DEBUG_DISAS
5194 if (loglevel
& CPU_LOG_TB_IN_ASM
)
5195 fprintf(logfile
, "\ntb %p super %d cond %04x\n",
5196 tb
, ctx
.mem_idx
, ctx
.hflags
);
5198 while (ctx
.bstate
== BS_NONE
&& gen_opc_ptr
< gen_opc_end
) {
5199 if (env
->nb_breakpoints
> 0) {
5200 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
5201 if (env
->breakpoints
[j
] == ctx
.pc
) {
5202 save_cpu_state(ctxp
, 1);
5203 ctx
.bstate
= BS_BRANCH
;
5205 goto done_generating
;
5211 j
= gen_opc_ptr
- gen_opc_buf
;
5215 gen_opc_instr_start
[lj
++] = 0;
5217 gen_opc_pc
[lj
] = ctx
.pc
;
5218 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
5219 gen_opc_instr_start
[lj
] = 1;
5221 ctx
.opcode
= ldl_code(ctx
.pc
);
5222 decode_opc(env
, &ctx
);
5225 if (env
->singlestep_enabled
)
5228 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
5231 #if defined (MIPS_SINGLE_STEP)
5235 if (env
->singlestep_enabled
) {
5236 save_cpu_state(ctxp
, ctx
.bstate
== BS_NONE
);
5239 switch (ctx
.bstate
) {
5241 gen_op_interrupt_restart();
5243 /* Generate the return instruction. */
5247 gen_op_interrupt_restart();
5250 save_cpu_state(ctxp
, 0);
5251 gen_goto_tb(&ctx
, 0, ctx
.pc
);
5256 /* Generate the return instruction. */
5262 *gen_opc_ptr
= INDEX_op_end
;
5264 j
= gen_opc_ptr
- gen_opc_buf
;
5267 gen_opc_instr_start
[lj
++] = 0;
5270 tb
->size
= ctx
.pc
- pc_start
;
5273 #if defined MIPS_DEBUG_DISAS
5274 if (loglevel
& CPU_LOG_TB_IN_ASM
)
5275 fprintf(logfile
, "\n");
5277 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5278 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
5279 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
5280 fprintf(logfile
, "\n");
5282 if (loglevel
& CPU_LOG_TB_OP
) {
5283 fprintf(logfile
, "OP:\n");
5284 dump_ops(gen_opc_buf
, gen_opparam_buf
);
5285 fprintf(logfile
, "\n");
5287 if (loglevel
& CPU_LOG_TB_CPU
) {
5288 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
5295 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
5297 return gen_intermediate_code_internal(env
, tb
, 0);
5300 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
5302 return gen_intermediate_code_internal(env
, tb
, 1);
5305 void fpu_dump_state(CPUState
*env
, FILE *f
,
5306 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
5311 # define printfpr(fp) do { \
5312 fpu_fprintf(f, "w:%08x d:%08lx%08lx fd:%g fs:%g\n", \
5313 (fp)->w[FP_ENDIAN_IDX], (fp)->w[0], (fp)->w[1], (fp)->fd, (fp)->fs[FP_ENDIAN_IDX]); \
5316 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d\n",
5317 env
->fcr0
, env
->fcr31
,
5318 (env
->CP0_Status
& (1 << CP0St_FR
)) != 0);
5319 fpu_fprintf(f
, "FT0: "); printfpr(&env
->ft0
);
5320 fpu_fprintf(f
, "FT1: "); printfpr(&env
->ft1
);
5321 fpu_fprintf(f
, "FT2: "); printfpr(&env
->ft2
);
5322 for(i
= 0; i
< 32; i
+= 2) {
5323 fpu_fprintf(f
, "%s: ", fregnames
[i
]);
5324 printfpr(FPR(env
, i
));
5330 void dump_fpu (CPUState
*env
)
5333 fprintf(logfile
, "pc=0x" TARGET_FMT_lx
" HI=0x" TARGET_FMT_lx
" LO=0x" TARGET_FMT_lx
" ds %04x " TARGET_FMT_lx
" %d\n",
5334 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
5335 fpu_dump_state(env
, logfile
, fprintf
, 0);
5339 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5340 /* Debug help: The architecture requires 32bit code to maintain proper
5341 sign-extened values on 64bit machines. */
5343 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
5345 void cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
5346 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
5351 if (!SIGN_EXT_P(env
->PC
))
5352 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->PC
);
5353 if (!SIGN_EXT_P(env
->HI
))
5354 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->HI
);
5355 if (!SIGN_EXT_P(env
->LO
))
5356 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->LO
);
5357 if (!SIGN_EXT_P(env
->btarget
))
5358 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
5360 for (i
= 0; i
< 32; i
++) {
5361 if (!SIGN_EXT_P(env
->gpr
[i
]))
5362 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->gpr
[i
]);
5365 if (!SIGN_EXT_P(env
->CP0_EPC
))
5366 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
5367 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
5368 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
5372 void cpu_dump_state (CPUState
*env
, FILE *f
,
5373 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
5379 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",
5380 env
->PC
, env
->HI
, env
->LO
, env
->hflags
, env
->btarget
, env
->bcond
);
5381 for (i
= 0; i
< 32; i
++) {
5383 cpu_fprintf(f
, "GPR%02d:", i
);
5384 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->gpr
[i
]);
5386 cpu_fprintf(f
, "\n");
5389 c0_status
= env
->CP0_Status
;
5391 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
5392 c0_status
, env
->CP0_Cause
, env
->CP0_EPC
);
5393 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
5394 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
5395 if (c0_status
& (1 << CP0St_CU1
))
5396 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
5397 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5398 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
5402 CPUMIPSState
*cpu_mips_init (void)
5406 env
= qemu_mallocz(sizeof(CPUMIPSState
));
5414 void cpu_reset (CPUMIPSState
*env
)
5416 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
5421 #if !defined(CONFIG_USER_ONLY)
5422 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
5423 /* If the exception was raised from a delay slot,
5424 * come back to the jump. */
5425 env
->CP0_ErrorEPC
= env
->PC
- 4;
5426 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
5428 env
->CP0_ErrorEPC
= env
->PC
;
5431 env
->PC
= (int32_t)0xBFC00000;
5433 /* SMP not implemented */
5434 env
->CP0_EBase
= 0x80000000;
5435 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
5436 /* vectored interrupts not implemented, timer on int 7,
5437 no performance counters. */
5438 env
->CP0_IntCtl
= 0xe0000000;
5439 env
->CP0_WatchLo
= 0;
5440 env
->CP0_WatchHi
= 0;
5441 /* Count register increments in debug mode, EJTAG version 1 */
5442 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
5444 env
->exception_index
= EXCP_NONE
;
5445 #if defined(CONFIG_USER_ONLY)
5446 env
->hflags
|= MIPS_HFLAG_UM
;
5447 env
->user_mode_only
= 1;
5451 #include "translate_init.c"