2 * PPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "dyngen-exec.h"
25 //#define DO_SINGLE_STEP
26 //#define DO_STEP_FLUSH
30 #define DEF(s, n, copy_size) INDEX_op_ ## s,
36 static uint16_t *gen_opc_ptr;
37 static uint32_t *gen_opparam_ptr;
41 #define GEN8(func, NAME) \
42 static GenOpFunc *NAME ## _table [8] = { \
43 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
44 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
46 static inline void func(int n) \
48 NAME ## _table[n](); \
51 #define GEN16(func, NAME) \
52 static GenOpFunc *NAME ## _table [16] = { \
53 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
54 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
55 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
56 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
58 static inline void func(int n) \
60 NAME ## _table[n](); \
63 #define GEN32(func, NAME) \
64 static GenOpFunc *NAME ## _table [32] = { \
65 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
66 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
67 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
68 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
69 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
70 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
71 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
72 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
74 static inline void func(int n) \
76 NAME ## _table[n](); \
79 /* Condition register moves */
80 GEN8(gen_op_load_crf_T0, gen_op_load_crf_T0_crf);
81 GEN8(gen_op_load_crf_T1, gen_op_load_crf_T1_crf);
82 GEN8(gen_op_store_T0_crf, gen_op_store_T0_crf_crf);
83 GEN8(gen_op_store_T1_crf, gen_op_store_T1_crf_crf);
85 /* Floating point condition and status register moves */
86 GEN8(gen_op_load_fpscr_T0, gen_op_load_fpscr_T0_fpscr);
87 GEN8(gen_op_store_T0_fpscr, gen_op_store_T0_fpscr_fpscr);
88 GEN8(gen_op_clear_fpscr, gen_op_clear_fpscr_fpscr);
89 static GenOpFunc1 *gen_op_store_T0_fpscri_fpscr_table[8] = {
90 &gen_op_store_T0_fpscri_fpscr0,
91 &gen_op_store_T0_fpscri_fpscr1,
92 &gen_op_store_T0_fpscri_fpscr2,
93 &gen_op_store_T0_fpscri_fpscr3,
94 &gen_op_store_T0_fpscri_fpscr4,
95 &gen_op_store_T0_fpscri_fpscr5,
96 &gen_op_store_T0_fpscri_fpscr6,
97 &gen_op_store_T0_fpscri_fpscr7,
99 static inline void gen_op_store_T0_fpscri(int n, uint8_t param)
101 (*gen_op_store_T0_fpscri_fpscr_table[n])(param);
104 /* Segment register moves */
105 GEN16(gen_op_load_sr, gen_op_load_sr);
106 GEN16(gen_op_store_sr, gen_op_store_sr);
108 /* General purpose registers moves */
109 GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
110 GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
111 GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
113 GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
114 GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
115 GEN32(gen_op_store_T2_gpr, gen_op_store_T2_gpr_gpr);
117 /* floating point registers moves */
118 GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fpr);
119 GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fpr);
120 GEN32(gen_op_load_fpr_FT2, gen_op_load_fpr_FT2_fpr);
121 GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fpr);
122 GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fpr);
123 GEN32(gen_op_store_FT2_fpr, gen_op_store_FT2_fpr_fpr);
125 static uint8_t spr_access[1024 / 2];
127 /* internal defines */
128 typedef struct DisasContext {
129 struct TranslationBlock *tb;
133 /* Time base offset */
135 /* Decrementer offset */
136 uint32_t decr_offset;
138 #if !defined(CONFIG_USER_ONLY)
141 /* Routine used to access memory */
145 typedef struct opc_handler_t {
148 /* instruction type */
151 void (*handler)(DisasContext *ctx);
154 #define RET_EXCP(excp, error) \
156 gen_op_queue_exception_err(excp, error); \
157 ctx->exception = excp; \
161 #define RET_INVAL() \
162 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL)
164 #define RET_PRIVOPC() \
165 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_OPC)
167 #define RET_PRIVREG() \
168 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG)
170 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
171 static void gen_##name (DisasContext *ctx); \
172 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
173 static void gen_##name (DisasContext *ctx)
175 typedef struct opcode_t {
176 unsigned char opc1, opc2, opc3;
177 opc_handler_t handler;
180 /* XXX: move that elsewhere */
181 extern FILE *logfile;
184 /*** Instruction decoding ***/
185 #define EXTRACT_HELPER(name, shift, nb) \
186 static inline uint32_t name (uint32_t opcode) \
188 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
191 #define EXTRACT_SHELPER(name, shift, nb) \
192 static inline int32_t name (uint32_t opcode) \
194 return s_ext16((opcode >> (shift)) & ((1 << (nb)) - 1)); \
198 EXTRACT_HELPER(opc1, 26, 6);
200 EXTRACT_HELPER(opc2, 1, 5);
202 EXTRACT_HELPER(opc3, 6, 5);
203 /* Update Cr0 flags */
204 EXTRACT_HELPER(Rc, 0, 1);
206 EXTRACT_HELPER(rD, 21, 5);
208 EXTRACT_HELPER(rS, 21, 5);
210 EXTRACT_HELPER(rA, 16, 5);
212 EXTRACT_HELPER(rB, 11, 5);
214 EXTRACT_HELPER(rC, 6, 5);
216 EXTRACT_HELPER(crfD, 23, 3);
217 EXTRACT_HELPER(crfS, 18, 3);
218 EXTRACT_HELPER(crbD, 21, 5);
219 EXTRACT_HELPER(crbA, 16, 5);
220 EXTRACT_HELPER(crbB, 11, 5);
222 EXTRACT_HELPER(SPR, 11, 10);
223 /*** Get constants ***/
224 EXTRACT_HELPER(IMM, 12, 8);
225 /* 16 bits signed immediate value */
226 EXTRACT_SHELPER(SIMM, 0, 16);
227 /* 16 bits unsigned immediate value */
228 EXTRACT_HELPER(UIMM, 0, 16);
230 EXTRACT_HELPER(NB, 11, 5);
232 EXTRACT_HELPER(SH, 11, 5);
234 EXTRACT_HELPER(MB, 6, 5);
236 EXTRACT_HELPER(ME, 1, 5);
238 EXTRACT_HELPER(TO, 21, 5);
240 EXTRACT_HELPER(CRM, 12, 8);
241 EXTRACT_HELPER(FM, 17, 8);
242 EXTRACT_HELPER(SR, 16, 4);
243 EXTRACT_HELPER(FPIMM, 20, 4);
245 /*** Jump target decoding ***/
247 EXTRACT_SHELPER(d, 0, 16);
248 /* Immediate address */
249 static inline uint32_t LI (uint32_t opcode)
251 return (opcode >> 0) & 0x03FFFFFC;
254 static inline uint32_t BD (uint32_t opcode)
256 return (opcode >> 0) & 0xFFFC;
259 EXTRACT_HELPER(BO, 21, 5);
260 EXTRACT_HELPER(BI, 16, 5);
261 /* Absolute/relative address */
262 EXTRACT_HELPER(AA, 1, 1);
264 EXTRACT_HELPER(LK, 0, 1);
266 /* Create a mask between <start> and <end> bits */
267 static inline uint32_t MASK (uint32_t start, uint32_t end)
271 ret = (((uint32_t)(-1)) >> (start)) ^ (((uint32_t)(-1) >> (end)) >> 1);
278 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
279 __attribute__ ((section(".opcodes"), unused)) \
280 static opcode_t opc_##name = { \
287 .handler = &gen_##name, \
291 #define GEN_OPCODE_MARK(name) \
292 __attribute__ ((section(".opcodes"), unused)) \
293 static opcode_t opc_##name = { \
298 .inval = 0x00000000, \
304 /* Start opcode list */
305 GEN_OPCODE_MARK(start);
307 /* Invalid instruction */
308 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
313 /* Special opcode to stop emulation */
314 GEN_HANDLER(stop, 0x06, 0x00, 0xFF, 0x03FFFFC1, PPC_COMMON)
316 gen_op_queue_exception(EXCP_HLT);
317 ctx->exception = EXCP_HLT;
320 /* Special opcode to call open-firmware */
321 GEN_HANDLER(of_enter, 0x06, 0x01, 0xFF, 0x03FFFFC1, PPC_COMMON)
323 gen_op_queue_exception(EXCP_OFCALL);
324 ctx->exception = EXCP_OFCALL;
327 /* Special opcode to call RTAS */
328 GEN_HANDLER(rtas_enter, 0x06, 0x02, 0xFF, 0x03FFFFC1, PPC_COMMON)
330 printf("RTAS entry point !\n");
331 gen_op_queue_exception(EXCP_RTASCALL);
332 ctx->exception = EXCP_RTASCALL;
335 static opc_handler_t invalid_handler = {
338 .handler = gen_invalid,
341 /*** Integer arithmetic ***/
342 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval) \
343 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
345 gen_op_load_gpr_T0(rA(ctx->opcode)); \
346 gen_op_load_gpr_T1(rB(ctx->opcode)); \
348 if (Rc(ctx->opcode) != 0) \
350 gen_op_store_T0_gpr(rD(ctx->opcode)); \
353 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval) \
354 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
356 gen_op_load_gpr_T0(rA(ctx->opcode)); \
357 gen_op_load_gpr_T1(rB(ctx->opcode)); \
359 if (Rc(ctx->opcode) != 0) \
360 gen_op_set_Rc0_ov(); \
361 gen_op_store_T0_gpr(rD(ctx->opcode)); \
364 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
365 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
367 gen_op_load_gpr_T0(rA(ctx->opcode)); \
369 if (Rc(ctx->opcode) != 0) \
371 gen_op_store_T0_gpr(rD(ctx->opcode)); \
373 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3) \
374 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
376 gen_op_load_gpr_T0(rA(ctx->opcode)); \
378 if (Rc(ctx->opcode) != 0) \
379 gen_op_set_Rc0_ov(); \
380 gen_op_store_T0_gpr(rD(ctx->opcode)); \
383 /* Two operands arithmetic functions */
384 #define GEN_INT_ARITH2(name, opc1, opc2, opc3) \
385 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000) \
386 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000)
388 /* Two operands arithmetic functions with no overflow allowed */
389 #define GEN_INT_ARITHN(name, opc1, opc2, opc3) \
390 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400)
392 /* One operand arithmetic functions */
393 #define GEN_INT_ARITH1(name, opc1, opc2, opc3) \
394 __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
395 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10)
397 /* add add. addo addo. */
398 GEN_INT_ARITH2 (add, 0x1F, 0x0A, 0x08);
399 /* addc addc. addco addco. */
400 GEN_INT_ARITH2 (addc, 0x1F, 0x0A, 0x00);
401 /* adde adde. addeo addeo. */
402 GEN_INT_ARITH2 (adde, 0x1F, 0x0A, 0x04);
403 /* addme addme. addmeo addmeo. */
404 GEN_INT_ARITH1 (addme, 0x1F, 0x0A, 0x07);
405 /* addze addze. addzeo addzeo. */
406 GEN_INT_ARITH1 (addze, 0x1F, 0x0A, 0x06);
407 /* divw divw. divwo divwo. */
408 GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F);
409 /* divwu divwu. divwuo divwuo. */
410 GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E);
412 GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02);
414 GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00);
415 /* mullw mullw. mullwo mullwo. */
416 GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07);
417 /* neg neg. nego nego. */
418 GEN_INT_ARITH1 (neg, 0x1F, 0x08, 0x03);
419 /* subf subf. subfo subfo. */
420 GEN_INT_ARITH2 (subf, 0x1F, 0x08, 0x01);
421 /* subfc subfc. subfco subfco. */
422 GEN_INT_ARITH2 (subfc, 0x1F, 0x08, 0x00);
423 /* subfe subfe. subfeo subfeo. */
424 GEN_INT_ARITH2 (subfe, 0x1F, 0x08, 0x04);
425 /* subfme subfme. subfmeo subfmeo. */
426 GEN_INT_ARITH1 (subfme, 0x1F, 0x08, 0x07);
427 /* subfze subfze. subfzeo subfzeo. */
428 GEN_INT_ARITH1 (subfze, 0x1F, 0x08, 0x06);
430 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
432 int32_t simm = SIMM(ctx->opcode);
434 if (rA(ctx->opcode) == 0) {
437 gen_op_load_gpr_T0(rA(ctx->opcode));
440 gen_op_store_T0_gpr(rD(ctx->opcode));
443 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
445 gen_op_load_gpr_T0(rA(ctx->opcode));
446 gen_op_addic(SIMM(ctx->opcode));
447 gen_op_store_T0_gpr(rD(ctx->opcode));
450 GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
452 gen_op_load_gpr_T0(rA(ctx->opcode));
453 gen_op_addic(SIMM(ctx->opcode));
455 gen_op_store_T0_gpr(rD(ctx->opcode));
458 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
460 int32_t simm = SIMM(ctx->opcode);
462 if (rA(ctx->opcode) == 0) {
463 gen_op_set_T0(simm << 16);
465 gen_op_load_gpr_T0(rA(ctx->opcode));
466 gen_op_addi(simm << 16);
468 gen_op_store_T0_gpr(rD(ctx->opcode));
471 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
473 gen_op_load_gpr_T0(rA(ctx->opcode));
474 gen_op_mulli(SIMM(ctx->opcode));
475 gen_op_store_T0_gpr(rD(ctx->opcode));
478 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
480 gen_op_load_gpr_T0(rA(ctx->opcode));
481 gen_op_subfic(SIMM(ctx->opcode));
482 gen_op_store_T0_gpr(rD(ctx->opcode));
485 /*** Integer comparison ***/
486 #define GEN_CMP(name, opc) \
487 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, PPC_INTEGER) \
489 gen_op_load_gpr_T0(rA(ctx->opcode)); \
490 gen_op_load_gpr_T1(rB(ctx->opcode)); \
492 gen_op_store_T0_crf(crfD(ctx->opcode)); \
498 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
500 gen_op_load_gpr_T0(rA(ctx->opcode));
501 gen_op_cmpi(SIMM(ctx->opcode));
502 gen_op_store_T0_crf(crfD(ctx->opcode));
507 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
509 gen_op_load_gpr_T0(rA(ctx->opcode));
510 gen_op_cmpli(UIMM(ctx->opcode));
511 gen_op_store_T0_crf(crfD(ctx->opcode));
514 /*** Integer logical ***/
515 #define __GEN_LOGICAL2(name, opc2, opc3) \
516 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \
518 gen_op_load_gpr_T0(rS(ctx->opcode)); \
519 gen_op_load_gpr_T1(rB(ctx->opcode)); \
521 if (Rc(ctx->opcode) != 0) \
523 gen_op_store_T0_gpr(rA(ctx->opcode)); \
525 #define GEN_LOGICAL2(name, opc) \
526 __GEN_LOGICAL2(name, 0x1C, opc)
528 #define GEN_LOGICAL1(name, opc) \
529 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \
531 gen_op_load_gpr_T0(rS(ctx->opcode)); \
533 if (Rc(ctx->opcode) != 0) \
535 gen_op_store_T0_gpr(rA(ctx->opcode)); \
539 GEN_LOGICAL2(and, 0x00);
541 GEN_LOGICAL2(andc, 0x01);
543 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
545 gen_op_load_gpr_T0(rS(ctx->opcode));
546 gen_op_andi_(UIMM(ctx->opcode));
548 gen_op_store_T0_gpr(rA(ctx->opcode));
551 GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
553 gen_op_load_gpr_T0(rS(ctx->opcode));
554 gen_op_andi_(UIMM(ctx->opcode) << 16);
556 gen_op_store_T0_gpr(rA(ctx->opcode));
560 GEN_LOGICAL1(cntlzw, 0x00);
562 GEN_LOGICAL2(eqv, 0x08);
564 GEN_LOGICAL1(extsb, 0x1D);
566 GEN_LOGICAL1(extsh, 0x1C);
568 GEN_LOGICAL2(nand, 0x0E);
570 GEN_LOGICAL2(nor, 0x03);
573 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
575 gen_op_load_gpr_T0(rS(ctx->opcode));
576 /* Optimisation for mr case */
577 if (rS(ctx->opcode) != rB(ctx->opcode)) {
578 gen_op_load_gpr_T1(rB(ctx->opcode));
581 if (Rc(ctx->opcode) != 0)
583 gen_op_store_T0_gpr(rA(ctx->opcode));
587 GEN_LOGICAL2(orc, 0x0C);
589 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
591 gen_op_load_gpr_T0(rS(ctx->opcode));
592 /* Optimisation for "set to zero" case */
593 if (rS(ctx->opcode) != rB(ctx->opcode)) {
594 gen_op_load_gpr_T1(rB(ctx->opcode));
599 if (Rc(ctx->opcode) != 0)
601 gen_op_store_T0_gpr(rA(ctx->opcode));
604 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
606 uint32_t uimm = UIMM(ctx->opcode);
608 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
612 gen_op_load_gpr_T0(rS(ctx->opcode));
615 gen_op_store_T0_gpr(rA(ctx->opcode));
618 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
620 uint32_t uimm = UIMM(ctx->opcode);
622 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
626 gen_op_load_gpr_T0(rS(ctx->opcode));
628 gen_op_ori(uimm << 16);
629 gen_op_store_T0_gpr(rA(ctx->opcode));
632 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
634 uint32_t uimm = UIMM(ctx->opcode);
636 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
640 gen_op_load_gpr_T0(rS(ctx->opcode));
642 gen_op_xori(UIMM(ctx->opcode));
643 gen_op_store_T0_gpr(rA(ctx->opcode));
647 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
649 uint32_t uimm = UIMM(ctx->opcode);
651 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
655 gen_op_load_gpr_T0(rS(ctx->opcode));
657 gen_op_xori(UIMM(ctx->opcode) << 16);
658 gen_op_store_T0_gpr(rA(ctx->opcode));
661 /*** Integer rotate ***/
662 /* rlwimi & rlwimi. */
663 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
667 mb = MB(ctx->opcode);
668 me = ME(ctx->opcode);
669 gen_op_load_gpr_T0(rS(ctx->opcode));
670 gen_op_load_gpr_T1(rA(ctx->opcode));
671 gen_op_rlwimi(SH(ctx->opcode), MASK(mb, me), ~MASK(mb, me));
672 if (Rc(ctx->opcode) != 0)
674 gen_op_store_T0_gpr(rA(ctx->opcode));
676 /* rlwinm & rlwinm. */
677 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
681 sh = SH(ctx->opcode);
682 mb = MB(ctx->opcode);
683 me = ME(ctx->opcode);
684 gen_op_load_gpr_T0(rS(ctx->opcode));
689 } else if (me == (31 - sh)) {
692 } else if (sh == 0) {
693 gen_op_andi_(MASK(0, me));
696 } else if (me == 31) {
697 if (sh == (32 - mb)) {
700 } else if (sh == 0) {
701 gen_op_andi_(MASK(mb, 31));
705 gen_op_rlwinm(sh, MASK(mb, me));
707 if (Rc(ctx->opcode) != 0)
709 gen_op_store_T0_gpr(rA(ctx->opcode));
712 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
716 mb = MB(ctx->opcode);
717 me = ME(ctx->opcode);
718 gen_op_load_gpr_T0(rS(ctx->opcode));
719 gen_op_load_gpr_T1(rB(ctx->opcode));
720 if (mb == 0 && me == 31) {
724 gen_op_rlwnm(MASK(mb, me));
726 if (Rc(ctx->opcode) != 0)
728 gen_op_store_T0_gpr(rA(ctx->opcode));
731 /*** Integer shift ***/
733 __GEN_LOGICAL2(slw, 0x18, 0x00);
735 __GEN_LOGICAL2(sraw, 0x18, 0x18);
737 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
739 gen_op_load_gpr_T0(rS(ctx->opcode));
740 gen_op_srawi(SH(ctx->opcode), MASK(32 - SH(ctx->opcode), 31));
741 if (Rc(ctx->opcode) != 0)
743 gen_op_store_T0_gpr(rA(ctx->opcode));
746 __GEN_LOGICAL2(srw, 0x18, 0x10);
748 /*** Floating-Point arithmetic ***/
749 #define _GEN_FLOAT_ACB(name, op1, op2) \
750 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, PPC_FLOAT) \
752 gen_op_reset_scrfx(); \
753 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
754 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
755 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
757 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
758 if (Rc(ctx->opcode)) \
762 #define GEN_FLOAT_ACB(name, op2) \
763 _GEN_FLOAT_ACB(name, 0x3F, op2); \
764 _GEN_FLOAT_ACB(name##s, 0x3B, op2);
766 #define _GEN_FLOAT_AB(name, op1, op2, inval) \
767 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
769 gen_op_reset_scrfx(); \
770 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
771 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
773 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
774 if (Rc(ctx->opcode)) \
777 #define GEN_FLOAT_AB(name, op2, inval) \
778 _GEN_FLOAT_AB(name, 0x3F, op2, inval); \
779 _GEN_FLOAT_AB(name##s, 0x3B, op2, inval);
781 #define _GEN_FLOAT_AC(name, op1, op2, inval) \
782 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
784 gen_op_reset_scrfx(); \
785 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
786 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
788 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
789 if (Rc(ctx->opcode)) \
792 #define GEN_FLOAT_AC(name, op2, inval) \
793 _GEN_FLOAT_AC(name, 0x3F, op2, inval); \
794 _GEN_FLOAT_AC(name##s, 0x3B, op2, inval);
796 #define GEN_FLOAT_B(name, op2, op3) \
797 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, PPC_FLOAT) \
799 gen_op_reset_scrfx(); \
800 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
802 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
803 if (Rc(ctx->opcode)) \
807 #define GEN_FLOAT_BS(name, op2) \
808 GEN_HANDLER(f##name, 0x3F, op2, 0xFF, 0x001F07C0, PPC_FLOAT) \
810 gen_op_reset_scrfx(); \
811 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
813 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
814 if (Rc(ctx->opcode)) \
819 GEN_FLOAT_AB(add, 0x15, 0x000007C0);
821 GEN_FLOAT_AB(div, 0x12, 0x000007C0);
823 GEN_FLOAT_AC(mul, 0x19, 0x0000F800);
826 GEN_FLOAT_BS(res, 0x18);
829 GEN_FLOAT_BS(rsqrte, 0x1A);
832 _GEN_FLOAT_ACB(sel, 0x3F, 0x17);
834 GEN_FLOAT_AB(sub, 0x14, 0x000007C0);
837 GEN_FLOAT_BS(sqrt, 0x16);
839 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_OPT)
841 gen_op_reset_scrfx();
842 gen_op_load_fpr_FT0(rB(ctx->opcode));
844 gen_op_store_FT0_fpr(rD(ctx->opcode));
849 /*** Floating-Point multiply-and-add ***/
851 GEN_FLOAT_ACB(madd, 0x1D);
853 GEN_FLOAT_ACB(msub, 0x1C);
855 GEN_FLOAT_ACB(nmadd, 0x1F);
857 GEN_FLOAT_ACB(nmsub, 0x1E);
859 /*** Floating-Point round & convert ***/
861 GEN_FLOAT_B(ctiw, 0x0E, 0x00);
863 GEN_FLOAT_B(ctiwz, 0x0F, 0x00);
865 GEN_FLOAT_B(rsp, 0x0C, 0x00);
867 /*** Floating-Point compare ***/
869 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
871 gen_op_reset_scrfx();
872 gen_op_load_fpr_FT0(rA(ctx->opcode));
873 gen_op_load_fpr_FT1(rB(ctx->opcode));
875 gen_op_store_T0_crf(crfD(ctx->opcode));
879 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
881 gen_op_reset_scrfx();
882 gen_op_load_fpr_FT0(rA(ctx->opcode));
883 gen_op_load_fpr_FT1(rB(ctx->opcode));
885 gen_op_store_T0_crf(crfD(ctx->opcode));
888 /*** Floating-point move ***/
890 GEN_FLOAT_B(abs, 0x08, 0x08);
893 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
895 gen_op_reset_scrfx();
896 gen_op_load_fpr_FT0(rB(ctx->opcode));
897 gen_op_store_FT0_fpr(rD(ctx->opcode));
903 GEN_FLOAT_B(nabs, 0x08, 0x04);
905 GEN_FLOAT_B(neg, 0x08, 0x01);
907 /*** Floating-Point status & ctrl register ***/
909 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
911 gen_op_load_fpscr_T0(crfS(ctx->opcode));
912 gen_op_store_T0_crf(crfD(ctx->opcode));
913 gen_op_clear_fpscr(crfS(ctx->opcode));
917 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
920 gen_op_store_FT0_fpr(rD(ctx->opcode));
926 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
930 crb = crbD(ctx->opcode) >> 2;
931 gen_op_load_fpscr_T0(crb);
932 gen_op_andi_(~(1 << (crbD(ctx->opcode) & 0x03)));
933 gen_op_store_T0_fpscr(crb);
939 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
943 crb = crbD(ctx->opcode) >> 2;
944 gen_op_load_fpscr_T0(crb);
945 gen_op_ori(1 << (crbD(ctx->opcode) & 0x03));
946 gen_op_store_T0_fpscr(crb);
952 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
954 gen_op_load_fpr_FT0(rB(ctx->opcode));
955 gen_op_store_fpscr(FM(ctx->opcode));
961 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
963 gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
968 /*** Integer load ***/
969 #if defined(CONFIG_USER_ONLY)
970 #define op_ldst(name) gen_op_##name##_raw()
971 #define OP_LD_TABLE(width)
972 #define OP_ST_TABLE(width)
974 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
975 #define OP_LD_TABLE(width) \
976 static GenOpFunc *gen_op_l##width[] = { \
977 &gen_op_l##width##_user, \
978 &gen_op_l##width##_kernel, \
980 #define OP_ST_TABLE(width) \
981 static GenOpFunc *gen_op_st##width[] = { \
982 &gen_op_st##width##_user, \
983 &gen_op_st##width##_kernel, \
987 #define GEN_LD(width, opc) \
988 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
990 uint32_t simm = SIMM(ctx->opcode); \
991 if (rA(ctx->opcode) == 0) { \
992 gen_op_set_T0(simm); \
994 gen_op_load_gpr_T0(rA(ctx->opcode)); \
999 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1002 #define GEN_LDU(width, opc) \
1003 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1005 uint32_t simm = SIMM(ctx->opcode); \
1006 if (rA(ctx->opcode) == 0 || \
1007 rA(ctx->opcode) == rD(ctx->opcode)) { \
1010 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1012 gen_op_addi(simm); \
1013 op_ldst(l##width); \
1014 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1015 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1018 #define GEN_LDUX(width, opc) \
1019 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1021 if (rA(ctx->opcode) == 0 || \
1022 rA(ctx->opcode) == rD(ctx->opcode)) { \
1025 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1026 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1028 op_ldst(l##width); \
1029 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1030 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1033 #define GEN_LDX(width, opc2, opc3) \
1034 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1036 if (rA(ctx->opcode) == 0) { \
1037 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1039 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1040 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1043 op_ldst(l##width); \
1044 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1047 #define GEN_LDS(width, op) \
1048 OP_LD_TABLE(width); \
1049 GEN_LD(width, op | 0x20); \
1050 GEN_LDU(width, op | 0x21); \
1051 GEN_LDUX(width, op | 0x01); \
1052 GEN_LDX(width, 0x17, op | 0x00)
1054 /* lbz lbzu lbzux lbzx */
1056 /* lha lhau lhaux lhax */
1058 /* lhz lhzu lhzux lhzx */
1060 /* lwz lwzu lwzux lwzx */
1063 /*** Integer store ***/
1064 #define GEN_ST(width, opc) \
1065 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1067 uint32_t simm = SIMM(ctx->opcode); \
1068 if (rA(ctx->opcode) == 0) { \
1069 gen_op_set_T0(simm); \
1071 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1073 gen_op_addi(simm); \
1075 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1076 op_ldst(st##width); \
1079 #define GEN_STU(width, opc) \
1080 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1082 uint32_t simm = SIMM(ctx->opcode); \
1083 if (rA(ctx->opcode) == 0) { \
1086 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1088 gen_op_addi(simm); \
1089 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1090 op_ldst(st##width); \
1091 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1094 #define GEN_STUX(width, opc) \
1095 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1097 if (rA(ctx->opcode) == 0) { \
1100 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1101 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1103 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1104 op_ldst(st##width); \
1105 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1108 #define GEN_STX(width, opc2, opc3) \
1109 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1111 if (rA(ctx->opcode) == 0) { \
1112 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1114 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1115 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1118 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1119 op_ldst(st##width); \
1122 #define GEN_STS(width, op) \
1123 OP_ST_TABLE(width); \
1124 GEN_ST(width, op | 0x20); \
1125 GEN_STU(width, op | 0x21); \
1126 GEN_STUX(width, op | 0x01); \
1127 GEN_STX(width, 0x17, op | 0x00)
1129 /* stb stbu stbux stbx */
1131 /* sth sthu sthux sthx */
1133 /* stw stwu stwux stwx */
1136 /*** Integer load and store with byte reverse ***/
1139 GEN_LDX(hbr, 0x16, 0x18);
1142 GEN_LDX(wbr, 0x16, 0x10);
1145 GEN_STX(hbr, 0x16, 0x1C);
1148 GEN_STX(wbr, 0x16, 0x14);
1150 /*** Integer load and store multiple ***/
1151 #if defined(CONFIG_USER_ONLY)
1152 #define op_ldstm(name, reg) gen_op_##name##_raw(reg)
1154 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
1155 static GenOpFunc1 *gen_op_lmw[] = {
1159 static GenOpFunc1 *gen_op_stmw[] = {
1161 &gen_op_stmw_kernel,
1166 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1168 int simm = SIMM(ctx->opcode);
1170 if (rA(ctx->opcode) == 0) {
1171 gen_op_set_T0(simm);
1173 gen_op_load_gpr_T0(rA(ctx->opcode));
1177 op_ldstm(lmw, rD(ctx->opcode));
1181 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1183 int simm = SIMM(ctx->opcode);
1185 if (rA(ctx->opcode) == 0) {
1186 gen_op_set_T0(simm);
1188 gen_op_load_gpr_T0(rA(ctx->opcode));
1192 op_ldstm(stmw, rS(ctx->opcode));
1195 /*** Integer load and store strings ***/
1196 #if defined(CONFIG_USER_ONLY)
1197 #define op_ldsts(name, start) gen_op_##name##_raw(start)
1198 #define op_ldstsx(name, rd, ra, rb) gen_op_##name##_raw(rd, ra, rb)
1200 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
1201 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
1202 static GenOpFunc1 *gen_op_lswi[] = {
1204 &gen_op_lswi_kernel,
1206 static GenOpFunc3 *gen_op_lswx[] = {
1208 &gen_op_lswx_kernel,
1210 static GenOpFunc1 *gen_op_stsw[] = {
1212 &gen_op_stsw_kernel,
1217 /* PPC32 specification says we must generate an exception if
1218 * rA is in the range of registers to be loaded.
1219 * In an other hand, IBM says this is valid, but rA won't be loaded.
1220 * For now, I'll follow the spec...
1222 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER)
1224 int nb = NB(ctx->opcode);
1225 int start = rD(ctx->opcode);
1226 int ra = rA(ctx->opcode);
1232 if (((start + nr) > 32 && start <= ra && (start + nr - 32) > ra) ||
1233 ((start + nr) <= 32 && start <= ra && (start + nr) > ra)) {
1234 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
1239 gen_op_load_gpr_T0(ra);
1242 op_ldsts(lswi, start);
1246 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER)
1248 int ra = rA(ctx->opcode);
1249 int rb = rB(ctx->opcode);
1252 gen_op_load_gpr_T0(rb);
1255 gen_op_load_gpr_T0(ra);
1256 gen_op_load_gpr_T1(rb);
1259 gen_op_load_xer_bc();
1260 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
1264 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
1266 if (rA(ctx->opcode) == 0) {
1269 gen_op_load_gpr_T0(rA(ctx->opcode));
1271 gen_op_set_T1(NB(ctx->opcode));
1272 op_ldsts(stsw, rS(ctx->opcode));
1276 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER)
1278 int ra = rA(ctx->opcode);
1281 gen_op_load_gpr_T0(rB(ctx->opcode));
1282 ra = rB(ctx->opcode);
1284 gen_op_load_gpr_T0(ra);
1285 gen_op_load_gpr_T1(rB(ctx->opcode));
1288 gen_op_load_xer_bc();
1289 op_ldsts(stsw, rS(ctx->opcode));
1292 /*** Memory synchronisation ***/
1294 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FF0801, PPC_MEM)
1299 GEN_HANDLER(isync, 0x13, 0x16, 0xFF, 0x03FF0801, PPC_MEM)
1304 #if defined(CONFIG_USER_ONLY)
1305 #define op_lwarx() gen_op_lwarx_raw()
1306 #define op_stwcx() gen_op_stwcx_raw()
1308 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
1309 static GenOpFunc *gen_op_lwarx[] = {
1311 &gen_op_lwarx_kernel,
1313 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
1314 static GenOpFunc *gen_op_stwcx[] = {
1316 &gen_op_stwcx_kernel,
1320 GEN_HANDLER(lwarx, 0x1F, 0x14, 0xFF, 0x00000001, PPC_RES)
1322 if (rA(ctx->opcode) == 0) {
1323 gen_op_load_gpr_T0(rB(ctx->opcode));
1325 gen_op_load_gpr_T0(rA(ctx->opcode));
1326 gen_op_load_gpr_T1(rB(ctx->opcode));
1330 gen_op_store_T1_gpr(rD(ctx->opcode));
1334 GEN_HANDLER(stwcx_, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
1336 if (rA(ctx->opcode) == 0) {
1337 gen_op_load_gpr_T0(rB(ctx->opcode));
1339 gen_op_load_gpr_T0(rA(ctx->opcode));
1340 gen_op_load_gpr_T1(rB(ctx->opcode));
1343 gen_op_load_gpr_T1(rS(ctx->opcode));
1348 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_MEM)
1352 /*** Floating-point load ***/
1353 #define GEN_LDF(width, opc) \
1354 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1356 uint32_t simm = SIMM(ctx->opcode); \
1357 if (rA(ctx->opcode) == 0) { \
1358 gen_op_set_T0(simm); \
1360 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1362 gen_op_addi(simm); \
1364 op_ldst(l##width); \
1365 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1368 #define GEN_LDUF(width, opc) \
1369 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1371 uint32_t simm = SIMM(ctx->opcode); \
1372 if (rA(ctx->opcode) == 0 || \
1373 rA(ctx->opcode) == rD(ctx->opcode)) { \
1376 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1378 gen_op_addi(simm); \
1379 op_ldst(l##width); \
1380 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1381 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1384 #define GEN_LDUXF(width, opc) \
1385 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1387 if (rA(ctx->opcode) == 0 || \
1388 rA(ctx->opcode) == rD(ctx->opcode)) { \
1391 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1392 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1394 op_ldst(l##width); \
1395 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1396 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1399 #define GEN_LDXF(width, opc2, opc3) \
1400 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1402 if (rA(ctx->opcode) == 0) { \
1403 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1405 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1406 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1409 op_ldst(l##width); \
1410 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1413 #define GEN_LDFS(width, op) \
1414 OP_LD_TABLE(width); \
1415 GEN_LDF(width, op | 0x20); \
1416 GEN_LDUF(width, op | 0x21); \
1417 GEN_LDUXF(width, op | 0x01); \
1418 GEN_LDXF(width, 0x17, op | 0x00)
1420 /* lfd lfdu lfdux lfdx */
1422 /* lfs lfsu lfsux lfsx */
1425 /*** Floating-point store ***/
1426 #define GEN_STF(width, opc) \
1427 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1429 uint32_t simm = SIMM(ctx->opcode); \
1430 if (rA(ctx->opcode) == 0) { \
1431 gen_op_set_T0(simm); \
1433 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1435 gen_op_addi(simm); \
1437 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1438 op_ldst(st##width); \
1441 #define GEN_STUF(width, opc) \
1442 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1444 uint32_t simm = SIMM(ctx->opcode); \
1445 if (rA(ctx->opcode) == 0) { \
1448 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1450 gen_op_addi(simm); \
1451 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1452 op_ldst(st##width); \
1453 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1456 #define GEN_STUXF(width, opc) \
1457 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1459 if (rA(ctx->opcode) == 0) { \
1462 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1463 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1465 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1466 op_ldst(st##width); \
1467 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1470 #define GEN_STXF(width, opc2, opc3) \
1471 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1473 if (rA(ctx->opcode) == 0) { \
1474 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1476 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1477 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1480 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1481 op_ldst(st##width); \
1484 #define GEN_STFS(width, op) \
1485 OP_ST_TABLE(width); \
1486 GEN_STF(width, op | 0x20); \
1487 GEN_STUF(width, op | 0x21); \
1488 GEN_STUXF(width, op | 0x01); \
1489 GEN_STXF(width, 0x17, op | 0x00)
1491 /* stfd stfdu stfdux stfdx */
1493 /* stfs stfsu stfsux stfsx */
1498 GEN_HANDLER(stfiwx, 0x1F, 0x17, 0x1E, 0x00000001, PPC_FLOAT)
1506 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1508 uint32_t li = s_ext24(LI(ctx->opcode)), target;
1510 gen_op_update_tb(ctx->tb_offset);
1511 gen_op_update_decr(ctx->decr_offset);
1512 gen_op_process_exceptions((uint32_t)ctx->nip - 4);
1513 if (AA(ctx->opcode) == 0)
1514 target = (uint32_t)ctx->nip + li - 4;
1517 if (LK(ctx->opcode)) {
1518 gen_op_setlr((uint32_t)ctx->nip);
1520 gen_op_b((long)ctx->tb, target);
1521 ctx->exception = EXCP_BRANCH;
1528 static inline void gen_bcond(DisasContext *ctx, int type)
1530 uint32_t target = 0;
1531 uint32_t bo = BO(ctx->opcode);
1532 uint32_t bi = BI(ctx->opcode);
1536 gen_op_update_tb(ctx->tb_offset);
1537 gen_op_update_decr(ctx->decr_offset);
1538 gen_op_process_exceptions((uint32_t)ctx->nip - 4);
1540 if ((bo & 0x4) == 0)
1544 li = s_ext16(BD(ctx->opcode));
1545 if (AA(ctx->opcode) == 0) {
1546 target = (uint32_t)ctx->nip + li - 4;
1552 gen_op_movl_T1_ctr();
1556 gen_op_movl_T1_lr();
1559 if (LK(ctx->opcode)) {
1560 gen_op_setlr((uint32_t)ctx->nip);
1563 /* No CR condition */
1574 if (type == BCOND_IM) {
1575 gen_op_b((long)ctx->tb, target);
1582 mask = 1 << (3 - (bi & 0x03));
1583 gen_op_load_crf_T0(bi >> 2);
1587 gen_op_test_ctr_true(mask);
1590 gen_op_test_ctrz_true(mask);
1595 gen_op_test_true(mask);
1601 gen_op_test_ctr_false(mask);
1604 gen_op_test_ctrz_false(mask);
1609 gen_op_test_false(mask);
1614 if (type == BCOND_IM) {
1615 gen_op_btest((long)ctx->tb, target, (uint32_t)ctx->nip);
1617 gen_op_btest_T1((uint32_t)ctx->nip);
1620 ctx->exception = EXCP_BRANCH;
1623 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1625 gen_bcond(ctx, BCOND_IM);
1628 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
1630 gen_bcond(ctx, BCOND_CTR);
1633 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
1635 gen_bcond(ctx, BCOND_LR);
1638 /*** Condition register logical ***/
1639 #define GEN_CRLOGIC(op, opc) \
1640 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
1642 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
1643 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
1644 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
1645 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
1647 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
1648 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
1649 3 - (crbD(ctx->opcode) & 0x03)); \
1650 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
1654 GEN_CRLOGIC(and, 0x08)
1656 GEN_CRLOGIC(andc, 0x04)
1658 GEN_CRLOGIC(eqv, 0x09)
1660 GEN_CRLOGIC(nand, 0x07)
1662 GEN_CRLOGIC(nor, 0x01)
1664 GEN_CRLOGIC(or, 0x0E)
1666 GEN_CRLOGIC(orc, 0x0D)
1668 GEN_CRLOGIC(xor, 0x06)
1670 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
1672 gen_op_load_crf_T0(crfS(ctx->opcode));
1673 gen_op_store_T0_crf(crfD(ctx->opcode));
1676 /*** System linkage ***/
1677 /* rfi (supervisor only) */
1678 GEN_HANDLER(rfi, 0x13, 0x12, 0xFF, 0x03FF8001, PPC_FLOW)
1680 #if defined(CONFIG_USER_ONLY)
1683 /* Restore CPU state */
1684 if (!ctx->supervisor) {
1688 ctx->exception = EXCP_RFI;
1693 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFFFFD, PPC_FLOW)
1695 #if defined(CONFIG_USER_ONLY)
1696 gen_op_queue_exception(EXCP_SYSCALL_USER);
1698 gen_op_queue_exception(EXCP_SYSCALL);
1700 ctx->exception = EXCP_SYSCALL;
1705 GEN_HANDLER(tw, 0x1F, 0x04, 0xFF, 0x00000001, PPC_FLOW)
1707 gen_op_load_gpr_T0(rA(ctx->opcode));
1708 gen_op_load_gpr_T1(rB(ctx->opcode));
1709 gen_op_tw(TO(ctx->opcode));
1713 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1715 gen_op_load_gpr_T0(rA(ctx->opcode));
1717 printf("%s: param=0x%04x T0=0x%04x\n", __func__,
1718 SIMM(ctx->opcode), TO(ctx->opcode));
1720 gen_op_twi(SIMM(ctx->opcode), TO(ctx->opcode));
1723 /*** Processor control ***/
1724 static inline int check_spr_access (int spr, int rw, int supervisor)
1726 uint32_t rights = spr_access[spr >> 1] >> (4 * (spr & 1));
1729 if (spr != LR && spr != CTR) {
1731 fprintf(logfile, "%s reg=%d s=%d rw=%d r=0x%02x 0x%02x\n", __func__,
1732 SPR_ENCODE(spr), supervisor, rw, rights,
1733 (rights >> ((2 * supervisor) + rw)) & 1);
1735 printf("%s reg=%d s=%d rw=%d r=0x%02x 0x%02x\n", __func__,
1736 SPR_ENCODE(spr), supervisor, rw, rights,
1737 (rights >> ((2 * supervisor) + rw)) & 1);
1743 rights = rights >> (2 * supervisor);
1744 rights = rights >> rw;
1750 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
1752 gen_op_load_xer_cr();
1753 gen_op_store_T0_crf(crfD(ctx->opcode));
1754 gen_op_clear_xer_cr();
1758 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x001FF801, PPC_MISC)
1761 gen_op_store_T0_gpr(rD(ctx->opcode));
1765 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
1767 #if defined(CONFIG_USER_ONLY)
1770 if (!ctx->supervisor) {
1774 gen_op_store_T0_gpr(rD(ctx->opcode));
1779 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
1781 uint32_t sprn = SPR(ctx->opcode);
1783 #if defined(CONFIG_USER_ONLY)
1784 switch (check_spr_access(sprn, 0, 0))
1786 switch (check_spr_access(sprn, 0, ctx->supervisor))
1790 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_SPR);
1809 gen_op_load_ibat(0, 0);
1812 gen_op_load_ibat(0, 1);
1815 gen_op_load_ibat(0, 2);
1818 gen_op_load_ibat(0, 3);
1821 gen_op_load_ibat(0, 4);
1824 gen_op_load_ibat(0, 5);
1827 gen_op_load_ibat(0, 6);
1830 gen_op_load_ibat(0, 7);
1833 gen_op_load_ibat(1, 0);
1836 gen_op_load_ibat(1, 1);
1839 gen_op_load_ibat(1, 2);
1842 gen_op_load_ibat(1, 3);
1845 gen_op_load_ibat(1, 4);
1848 gen_op_load_ibat(1, 5);
1851 gen_op_load_ibat(1, 6);
1854 gen_op_load_ibat(1, 7);
1857 gen_op_load_dbat(0, 0);
1860 gen_op_load_dbat(0, 1);
1863 gen_op_load_dbat(0, 2);
1866 gen_op_load_dbat(0, 3);
1869 gen_op_load_dbat(0, 4);
1872 gen_op_load_dbat(0, 5);
1875 gen_op_load_dbat(0, 6);
1878 gen_op_load_dbat(0, 7);
1881 gen_op_load_dbat(1, 0);
1884 gen_op_load_dbat(1, 1);
1887 gen_op_load_dbat(1, 2);
1890 gen_op_load_dbat(1, 3);
1893 gen_op_load_dbat(1, 4);
1896 gen_op_load_dbat(1, 5);
1899 gen_op_load_dbat(1, 6);
1902 gen_op_load_dbat(1, 7);
1908 gen_op_update_tb(ctx->tb_offset);
1910 /* TBL is still in T0 */
1913 gen_op_update_tb(ctx->tb_offset);
1918 gen_op_update_decr(ctx->decr_offset);
1919 ctx->decr_offset = 0;
1920 /* decr is still in T0 */
1923 gen_op_load_spr(sprn);
1926 gen_op_store_T0_gpr(rD(ctx->opcode));
1930 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MISC)
1932 uint32_t sprn = SPR(ctx->opcode);
1934 /* We need to update the time base before reading it */
1937 gen_op_update_tb(ctx->tb_offset);
1938 /* TBL is still in T0 */
1941 gen_op_update_tb(ctx->tb_offset);
1949 gen_op_store_T0_gpr(rD(ctx->opcode));
1953 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00100801, PPC_MISC)
1955 gen_op_load_gpr_T0(rS(ctx->opcode));
1956 gen_op_store_cr(CRM(ctx->opcode));
1960 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
1962 #if defined(CONFIG_USER_ONLY)
1965 if (!ctx->supervisor) {
1968 gen_op_load_gpr_T0(rS(ctx->opcode));
1970 /* Must stop the translation as machine state (may have) changed */
1971 ctx->exception = EXCP_MTMSR;
1976 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
1978 uint32_t sprn = SPR(ctx->opcode);
1982 fprintf(logfile, "MTSPR %d src=%d (%d)\n", SPR_ENCODE(sprn),
1983 rS(ctx->opcode), sprn);
1986 #if defined(CONFIG_USER_ONLY)
1987 switch (check_spr_access(sprn, 1, 0))
1989 switch (check_spr_access(sprn, 1, ctx->supervisor))
1993 RET_EXCP(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_SPR);
2001 gen_op_load_gpr_T0(rS(ctx->opcode));
2007 gen_op_andi_(~0x03);
2014 gen_op_store_ibat(0, 0);
2018 gen_op_store_ibat(0, 1);
2022 gen_op_store_ibat(0, 2);
2026 gen_op_store_ibat(0, 3);
2030 gen_op_store_ibat(0, 4);
2034 gen_op_store_ibat(0, 5);
2038 gen_op_store_ibat(0, 6);
2042 gen_op_store_ibat(0, 7);
2046 gen_op_store_ibat(1, 0);
2050 gen_op_store_ibat(1, 1);
2054 gen_op_store_ibat(1, 2);
2058 gen_op_store_ibat(1, 3);
2062 gen_op_store_ibat(1, 4);
2066 gen_op_store_ibat(1, 5);
2070 gen_op_store_ibat(1, 6);
2074 gen_op_store_ibat(1, 7);
2078 gen_op_store_dbat(0, 0);
2082 gen_op_store_dbat(0, 1);
2086 gen_op_store_dbat(0, 2);
2090 gen_op_store_dbat(0, 3);
2094 gen_op_store_dbat(0, 4);
2098 gen_op_store_dbat(0, 5);
2102 gen_op_store_dbat(0, 6);
2106 gen_op_store_dbat(0, 7);
2110 gen_op_store_dbat(1, 0);
2114 gen_op_store_dbat(1, 1);
2118 gen_op_store_dbat(1, 2);
2122 gen_op_store_dbat(1, 3);
2126 gen_op_store_dbat(1, 4);
2130 gen_op_store_dbat(1, 5);
2134 gen_op_store_dbat(1, 6);
2138 gen_op_store_dbat(1, 7);
2142 gen_op_store_sdr1();
2154 gen_op_store_decr();
2155 ctx->decr_offset = 0;
2158 gen_op_store_spr(sprn);
2163 /*** Cache management ***/
2164 /* For now, all those will be implemented as nop:
2165 * this is valid, regarding the PowerPC specs...
2166 * We just have to flush tb while invalidating instruction cache lines...
2169 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03E00001, PPC_CACHE)
2173 /* dcbi (Supervisor only) */
2174 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
2176 #if !defined(CONFIG_USER_ONLY)
2177 if (!ctx->supervisor)
2185 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
2190 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x03E00001, PPC_CACHE)
2195 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE)
2200 #if defined(CONFIG_USER_ONLY)
2201 #define op_dcbz() gen_op_dcbz_raw()
2203 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
2204 static GenOpFunc *gen_op_dcbz[] = {
2206 &gen_op_dcbz_kernel,
2210 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
2212 if (rA(ctx->opcode) == 0) {
2213 gen_op_load_gpr_T0(rB(ctx->opcode));
2215 gen_op_load_gpr_T0(rA(ctx->opcode));
2216 gen_op_load_gpr_T1(rB(ctx->opcode));
2223 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE)
2225 if (rA(ctx->opcode) == 0) {
2226 gen_op_load_gpr_T0(rB(ctx->opcode));
2228 gen_op_load_gpr_T0(rA(ctx->opcode));
2229 gen_op_load_gpr_T1(rB(ctx->opcode));
2237 GEN_HANDLER(dcba, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE_OPT)
2241 /*** Segment register manipulation ***/
2242 /* Supervisor only: */
2244 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
2246 #if defined(CONFIG_USER_ONLY)
2249 if (!ctx->supervisor) {
2252 gen_op_load_sr(SR(ctx->opcode));
2253 gen_op_store_T0_gpr(rD(ctx->opcode));
2258 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
2260 #if defined(CONFIG_USER_ONLY)
2263 if (!ctx->supervisor) {
2266 gen_op_load_gpr_T1(rB(ctx->opcode));
2268 gen_op_store_T0_gpr(rD(ctx->opcode));
2273 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x02, 0x0010F801, PPC_SEGMENT)
2275 #if defined(CONFIG_USER_ONLY)
2278 if (!ctx->supervisor) {
2281 gen_op_load_gpr_T0(rS(ctx->opcode));
2282 gen_op_store_sr(SR(ctx->opcode));
2288 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
2290 #if defined(CONFIG_USER_ONLY)
2293 if (!ctx->supervisor) {
2296 gen_op_load_gpr_T0(rS(ctx->opcode));
2297 gen_op_load_gpr_T1(rB(ctx->opcode));
2298 gen_op_store_srin();
2303 /*** Lookaside buffer management ***/
2304 /* Optional & supervisor only: */
2306 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_OPT)
2308 #if defined(CONFIG_USER_ONLY)
2311 if (!ctx->supervisor) {
2319 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM)
2321 #if defined(CONFIG_USER_ONLY)
2324 if (!ctx->supervisor) {
2327 gen_op_load_gpr_T0(rB(ctx->opcode));
2333 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFFC01, PPC_MEM)
2335 #if defined(CONFIG_USER_ONLY)
2338 if (!ctx->supervisor) {
2341 /* This has no effect: it should ensure that all previous
2342 * tlbie have completed
2347 /*** External control ***/
2350 #if defined(CONFIG_USER_ONLY)
2351 #define op_eciwx() gen_op_eciwx_raw()
2352 #define op_ecowx() gen_op_ecowx_raw()
2354 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
2355 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
2356 static GenOpFunc *gen_op_eciwx[] = {
2358 &gen_op_eciwx_kernel,
2360 static GenOpFunc *gen_op_ecowx[] = {
2362 &gen_op_ecowx_kernel,
2366 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
2368 /* Should check EAR[E] & alignment ! */
2369 if (rA(ctx->opcode) == 0) {
2370 gen_op_load_gpr_T0(rB(ctx->opcode));
2372 gen_op_load_gpr_T0(rA(ctx->opcode));
2373 gen_op_load_gpr_T1(rB(ctx->opcode));
2377 gen_op_store_T0_gpr(rD(ctx->opcode));
2381 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
2383 /* Should check EAR[E] & alignment ! */
2384 if (rA(ctx->opcode) == 0) {
2385 gen_op_load_gpr_T0(rB(ctx->opcode));
2387 gen_op_load_gpr_T0(rA(ctx->opcode));
2388 gen_op_load_gpr_T1(rB(ctx->opcode));
2391 gen_op_load_gpr_T2(rS(ctx->opcode));
2395 /* End opcode list */
2396 GEN_OPCODE_MARK(end);
2398 /*****************************************************************************/
2402 int fflush (FILE *stream);
2404 /* Main ppc opcodes table:
2405 * at init, all opcodes are invalids
2407 static opc_handler_t *ppc_opcodes[0x40];
2411 PPC_DIRECT = 0, /* Opcode routine */
2412 PPC_INDIRECT = 1, /* Indirect opcode table */
2415 static inline int is_indirect_opcode (void *handler)
2417 return ((unsigned long)handler & 0x03) == PPC_INDIRECT;
2420 static inline opc_handler_t **ind_table(void *handler)
2422 return (opc_handler_t **)((unsigned long)handler & ~3);
2425 /* Instruction table creation */
2426 /* Opcodes tables creation */
2427 static void fill_new_table (opc_handler_t **table, int len)
2431 for (i = 0; i < len; i++)
2432 table[i] = &invalid_handler;
2435 static int create_new_table (opc_handler_t **table, unsigned char idx)
2437 opc_handler_t **tmp;
2439 tmp = malloc(0x20 * sizeof(opc_handler_t));
2442 fill_new_table(tmp, 0x20);
2443 table[idx] = (opc_handler_t *)((unsigned long)tmp | PPC_INDIRECT);
2448 static int insert_in_table (opc_handler_t **table, unsigned char idx,
2449 opc_handler_t *handler)
2451 if (table[idx] != &invalid_handler)
2453 table[idx] = handler;
2458 static int register_direct_insn (opc_handler_t **ppc_opcodes,
2459 unsigned char idx, opc_handler_t *handler)
2461 if (insert_in_table(ppc_opcodes, idx, handler) < 0) {
2462 printf("*** ERROR: opcode %02x already assigned in main "
2463 "opcode table\n", idx);
2470 static int register_ind_in_table (opc_handler_t **table,
2471 unsigned char idx1, unsigned char idx2,
2472 opc_handler_t *handler)
2474 if (table[idx1] == &invalid_handler) {
2475 if (create_new_table(table, idx1) < 0) {
2476 printf("*** ERROR: unable to create indirect table "
2477 "idx=%02x\n", idx1);
2481 if (!is_indirect_opcode(table[idx1])) {
2482 printf("*** ERROR: idx %02x already assigned to a direct "
2487 if (handler != NULL &&
2488 insert_in_table(ind_table(table[idx1]), idx2, handler) < 0) {
2489 printf("*** ERROR: opcode %02x already assigned in "
2490 "opcode table %02x\n", idx2, idx1);
2497 static int register_ind_insn (opc_handler_t **ppc_opcodes,
2498 unsigned char idx1, unsigned char idx2,
2499 opc_handler_t *handler)
2503 ret = register_ind_in_table(ppc_opcodes, idx1, idx2, handler);
2508 static int register_dblind_insn (opc_handler_t **ppc_opcodes,
2509 unsigned char idx1, unsigned char idx2,
2510 unsigned char idx3, opc_handler_t *handler)
2512 if (register_ind_in_table(ppc_opcodes, idx1, idx2, NULL) < 0) {
2513 printf("*** ERROR: unable to join indirect table idx "
2514 "[%02x-%02x]\n", idx1, idx2);
2517 if (register_ind_in_table(ind_table(ppc_opcodes[idx1]), idx2, idx3,
2519 printf("*** ERROR: unable to insert opcode "
2520 "[%02x-%02x-%02x]\n", idx1, idx2, idx3);
2527 static int register_insn (opc_handler_t **ppc_opcodes, opcode_t *insn)
2529 if (insn->opc2 != 0xFF) {
2530 if (insn->opc3 != 0xFF) {
2531 if (register_dblind_insn(ppc_opcodes, insn->opc1, insn->opc2,
2532 insn->opc3, &insn->handler) < 0)
2535 if (register_ind_insn(ppc_opcodes, insn->opc1,
2536 insn->opc2, &insn->handler) < 0)
2540 if (register_direct_insn(ppc_opcodes, insn->opc1, &insn->handler) < 0)
2547 static int test_opcode_table (opc_handler_t **table, int len)
2551 for (i = 0, count = 0; i < len; i++) {
2552 /* Consistency fixup */
2553 if (table[i] == NULL)
2554 table[i] = &invalid_handler;
2555 if (table[i] != &invalid_handler) {
2556 if (is_indirect_opcode(table[i])) {
2557 tmp = test_opcode_table(ind_table(table[i]), 0x20);
2560 table[i] = &invalid_handler;
2573 static void fix_opcode_tables (opc_handler_t **ppc_opcodes)
2575 if (test_opcode_table(ppc_opcodes, 0x40) == 0)
2576 printf("*** WARNING: no opcode defined !\n");
2579 #define SPR_RIGHTS(rw, priv) (1 << ((2 * (priv)) + (rw)))
2580 #define SPR_UR SPR_RIGHTS(0, 0)
2581 #define SPR_UW SPR_RIGHTS(1, 0)
2582 #define SPR_SR SPR_RIGHTS(0, 1)
2583 #define SPR_SW SPR_RIGHTS(1, 1)
2585 #define spr_set_rights(spr, rights) \
2587 spr_access[(spr) >> 1] |= ((rights) << (4 * ((spr) & 1))); \
2590 static void init_spr_rights (uint32_t pvr)
2593 spr_set_rights(XER, SPR_UR | SPR_UW | SPR_SR | SPR_SW);
2595 spr_set_rights(LR, SPR_UR | SPR_UW | SPR_SR | SPR_SW);
2597 spr_set_rights(CTR, SPR_UR | SPR_UW | SPR_SR | SPR_SW);
2599 spr_set_rights(V_TBL, SPR_UR | SPR_SR);
2601 spr_set_rights(V_TBU, SPR_UR | SPR_SR);
2602 /* DSISR (SPR 18) */
2603 spr_set_rights(DSISR, SPR_SR | SPR_SW);
2605 spr_set_rights(DAR, SPR_SR | SPR_SW);
2607 spr_set_rights(DECR, SPR_SR | SPR_SW);
2609 spr_set_rights(SDR1, SPR_SR | SPR_SW);
2611 spr_set_rights(SRR0, SPR_SR | SPR_SW);
2613 spr_set_rights(SRR1, SPR_SR | SPR_SW);
2614 /* SPRG0 (SPR 272) */
2615 spr_set_rights(SPRG0, SPR_SR | SPR_SW);
2616 /* SPRG1 (SPR 273) */
2617 spr_set_rights(SPRG1, SPR_SR | SPR_SW);
2618 /* SPRG2 (SPR 274) */
2619 spr_set_rights(SPRG2, SPR_SR | SPR_SW);
2620 /* SPRG3 (SPR 275) */
2621 spr_set_rights(SPRG3, SPR_SR | SPR_SW);
2623 spr_set_rights(ASR, SPR_SR | SPR_SW);
2625 spr_set_rights(EAR, SPR_SR | SPR_SW);
2627 spr_set_rights(O_TBL, SPR_SW);
2629 spr_set_rights(O_TBU, SPR_SW);
2631 spr_set_rights(PVR, SPR_SR);
2632 /* IBAT0U (SPR 528) */
2633 spr_set_rights(IBAT0U, SPR_SR | SPR_SW);
2634 /* IBAT0L (SPR 529) */
2635 spr_set_rights(IBAT0L, SPR_SR | SPR_SW);
2636 /* IBAT1U (SPR 530) */
2637 spr_set_rights(IBAT1U, SPR_SR | SPR_SW);
2638 /* IBAT1L (SPR 531) */
2639 spr_set_rights(IBAT1L, SPR_SR | SPR_SW);
2640 /* IBAT2U (SPR 532) */
2641 spr_set_rights(IBAT2U, SPR_SR | SPR_SW);
2642 /* IBAT2L (SPR 533) */
2643 spr_set_rights(IBAT2L, SPR_SR | SPR_SW);
2644 /* IBAT3U (SPR 534) */
2645 spr_set_rights(IBAT3U, SPR_SR | SPR_SW);
2646 /* IBAT3L (SPR 535) */
2647 spr_set_rights(IBAT3L, SPR_SR | SPR_SW);
2648 /* DBAT0U (SPR 536) */
2649 spr_set_rights(DBAT0U, SPR_SR | SPR_SW);
2650 /* DBAT0L (SPR 537) */
2651 spr_set_rights(DBAT0L, SPR_SR | SPR_SW);
2652 /* DBAT1U (SPR 538) */
2653 spr_set_rights(DBAT1U, SPR_SR | SPR_SW);
2654 /* DBAT1L (SPR 539) */
2655 spr_set_rights(DBAT1L, SPR_SR | SPR_SW);
2656 /* DBAT2U (SPR 540) */
2657 spr_set_rights(DBAT2U, SPR_SR | SPR_SW);
2658 /* DBAT2L (SPR 541) */
2659 spr_set_rights(DBAT2L, SPR_SR | SPR_SW);
2660 /* DBAT3U (SPR 542) */
2661 spr_set_rights(DBAT3U, SPR_SR | SPR_SW);
2662 /* DBAT3L (SPR 543) */
2663 spr_set_rights(DBAT3L, SPR_SR | SPR_SW);
2664 /* DABR (SPR 1013) */
2665 spr_set_rights(DABR, SPR_SR | SPR_SW);
2666 /* FPECR (SPR 1022) */
2667 spr_set_rights(FPECR, SPR_SR | SPR_SW);
2668 /* PIR (SPR 1023) */
2669 spr_set_rights(PIR, SPR_SR | SPR_SW);
2670 /* Special registers for MPC740/745/750/755 (aka G3) & IBM 750 */
2671 if ((pvr & 0xFFFF0000) == 0x00080000 ||
2672 (pvr & 0xFFFF0000) == 0x70000000) {
2674 spr_set_rights(SPR_ENCODE(1008), SPR_SR | SPR_SW);
2676 spr_set_rights(SPR_ENCODE(1009), SPR_SR | SPR_SW);
2678 spr_set_rights(SPR_ENCODE(1010), SPR_SR | SPR_SW);
2680 spr_set_rights(SPR_ENCODE(1019), SPR_SR | SPR_SW);
2682 spr_set_rights(SPR_ENCODE(1017), SPR_SR | SPR_SW);
2684 spr_set_rights(SPR_ENCODE(952), SPR_SR | SPR_SW);
2686 spr_set_rights(SPR_ENCODE(956), SPR_SR | SPR_SW);
2688 spr_set_rights(SPR_ENCODE(953), SPR_SR | SPR_SW);
2690 spr_set_rights(SPR_ENCODE(954), SPR_SR | SPR_SW);
2692 spr_set_rights(SPR_ENCODE(957), SPR_SR | SPR_SW);
2694 spr_set_rights(SPR_ENCODE(958), SPR_SR | SPR_SW);
2696 spr_set_rights(SPR_ENCODE(955), SPR_SR | SPR_SW);
2698 spr_set_rights(SPR_ENCODE(1020), SPR_SR | SPR_SW);
2700 spr_set_rights(SPR_ENCODE(1021), SPR_SR | SPR_SW);
2702 spr_set_rights(SPR_ENCODE(1022), SPR_SR | SPR_SW);
2704 spr_set_rights(SPR_ENCODE(936), SPR_UR | SPR_UW);
2706 spr_set_rights(SPR_ENCODE(940), SPR_UR | SPR_UW);
2708 spr_set_rights(SPR_ENCODE(937), SPR_UR | SPR_UW);
2710 spr_set_rights(SPR_ENCODE(938), SPR_UR | SPR_UW);
2712 spr_set_rights(SPR_ENCODE(941), SPR_UR | SPR_UW);
2714 spr_set_rights(SPR_ENCODE(942), SPR_UR | SPR_UW);
2716 spr_set_rights(SPR_ENCODE(939), SPR_UR | SPR_UW);
2718 /* MPC755 has special registers */
2719 if (pvr == 0x00083100) {
2721 spr_set_rights(SPRG4, SPR_SR | SPR_SW);
2723 spr_set_rights(SPRG5, SPR_SR | SPR_SW);
2725 spr_set_rights(SPRG6, SPR_SR | SPR_SW);
2727 spr_set_rights(SPRG7, SPR_SR | SPR_SW);
2729 spr_set_rights(IBAT4U, SPR_SR | SPR_SW);
2731 spr_set_rights(IBAT4L, SPR_SR | SPR_SW);
2733 spr_set_rights(IBAT5U, SPR_SR | SPR_SW);
2735 spr_set_rights(IBAT5L, SPR_SR | SPR_SW);
2737 spr_set_rights(IBAT6U, SPR_SR | SPR_SW);
2739 spr_set_rights(IBAT6L, SPR_SR | SPR_SW);
2741 spr_set_rights(IBAT7U, SPR_SR | SPR_SW);
2743 spr_set_rights(IBAT7L, SPR_SR | SPR_SW);
2745 spr_set_rights(DBAT4U, SPR_SR | SPR_SW);
2747 spr_set_rights(DBAT4L, SPR_SR | SPR_SW);
2749 spr_set_rights(DBAT5U, SPR_SR | SPR_SW);
2751 spr_set_rights(DBAT5L, SPR_SR | SPR_SW);
2753 spr_set_rights(DBAT6U, SPR_SR | SPR_SW);
2755 spr_set_rights(DBAT6L, SPR_SR | SPR_SW);
2757 spr_set_rights(DBAT7U, SPR_SR | SPR_SW);
2759 spr_set_rights(DBAT7L, SPR_SR | SPR_SW);
2761 spr_set_rights(SPR_ENCODE(976), SPR_SR | SPR_SW);
2763 spr_set_rights(SPR_ENCODE(977), SPR_SR | SPR_SW);
2765 spr_set_rights(SPR_ENCODE(978), SPR_SR | SPR_SW);
2767 spr_set_rights(SPR_ENCODE(979), SPR_SR | SPR_SW);
2769 spr_set_rights(SPR_ENCODE(980), SPR_SR | SPR_SW);
2771 spr_set_rights(SPR_ENCODE(981), SPR_SR | SPR_SW);
2773 spr_set_rights(SPR_ENCODE(982), SPR_SR | SPR_SW);
2775 spr_set_rights(SPR_ENCODE(1011), SPR_SR | SPR_SW);
2777 spr_set_rights(SPR_ENCODE(1016), SPR_SR | SPR_SW);
2781 /*****************************************************************************/
2782 /* PPC "main stream" common instructions (no optional ones) */
2784 typedef struct ppc_proc_t {
2789 typedef struct ppc_def_t {
2791 unsigned long pvr_mask;
2795 static ppc_proc_t ppc_proc_common = {
2796 .flags = PPC_COMMON,
2800 static ppc_proc_t ppc_proc_G3 = {
2805 static ppc_def_t ppc_defs[] =
2807 /* MPC740/745/750/755 (G3) */
2810 .pvr_mask = 0xFFFF0000,
2811 .proc = &ppc_proc_G3,
2813 /* IBM 750FX (G3 embedded) */
2816 .pvr_mask = 0xFFFF0000,
2817 .proc = &ppc_proc_G3,
2819 /* Fallback (generic PPC) */
2822 .pvr_mask = 0x00000000,
2823 .proc = &ppc_proc_common,
2827 static int create_ppc_proc (opc_handler_t **ppc_opcodes, unsigned long pvr)
2832 fill_new_table(ppc_opcodes, 0x40);
2833 for (i = 0; ; i++) {
2834 if ((ppc_defs[i].pvr & ppc_defs[i].pvr_mask) ==
2835 (pvr & ppc_defs[i].pvr_mask)) {
2836 flags = ppc_defs[i].proc->flags;
2841 for (opc = &opc_start + 1; opc != &opc_end; opc++) {
2842 if ((opc->handler.type & flags) != 0)
2843 if (register_insn(ppc_opcodes, opc) < 0) {
2844 printf("*** ERROR initializing PPC instruction "
2845 "0x%02x 0x%02x 0x%02x\n", opc->opc1, opc->opc2,
2850 fix_opcode_tables(ppc_opcodes);
2856 /*****************************************************************************/
2857 /* Misc PPC helpers */
2860 void cpu_ppc_dump_state(CPUPPCState *env, FILE *f, int flags)
2864 fprintf(f, "nip=0x%08x LR=0x%08x CTR=0x%08x XER=0x%08x "
2865 "MSR=0x%08x\n", env->nip, env->lr, env->ctr,
2866 _load_xer(), _load_msr());
2867 for (i = 0; i < 32; i++) {
2869 fprintf(f, "GPR%02d:", i);
2870 fprintf(f, " %08x", env->gpr[i]);
2874 fprintf(f, "CR: 0x");
2875 for (i = 0; i < 8; i++)
2876 fprintf(f, "%01x", env->crf[i]);
2878 for (i = 0; i < 8; i++) {
2880 if (env->crf[i] & 0x08)
2882 else if (env->crf[i] & 0x04)
2884 else if (env->crf[i] & 0x02)
2886 fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
2889 fprintf(f, "TB: 0x%08x %08x\n", env->tb[1], env->tb[0]);
2890 for (i = 0; i < 16; i++) {
2892 fprintf(f, "FPR%02d:", i);
2893 fprintf(f, " %016llx", *((uint64_t *)&env->fpr[i]));
2897 fprintf(f, "SRR0 0x%08x SRR1 0x%08x\n",
2898 env->spr[SRR0], env->spr[SRR1]);
2899 fprintf(f, "reservation 0x%08x\n", env->reserve);
2903 #if !defined(CONFIG_USER_ONLY) && defined (USE_OPENFIRMWARE)
2904 int setup_machine (CPUPPCState *env, uint32_t mid);
2907 CPUPPCState *cpu_ppc_init(void)
2913 env = malloc(sizeof(CPUPPCState));
2916 memset(env, 0, sizeof(CPUPPCState));
2917 #if !defined(CONFIG_USER_ONLY) && defined (USE_OPEN_FIRMWARE)
2918 setup_machine(env, 0);
2920 // env->spr[PVR] = 0; /* Basic PPC */
2921 env->spr[PVR] = 0x00080100; /* G3 CPU */
2922 // env->spr[PVR] = 0x00083100; /* MPC755 (G3 embedded) */
2923 // env->spr[PVR] = 0x00070100; /* IBM 750FX */
2925 env->decr = 0xFFFFFFFF;
2926 if (create_ppc_proc(ppc_opcodes, env->spr[PVR]) < 0)
2928 init_spr_rights(env->spr[PVR]);
2930 #if defined (DO_SINGLE_STEP)
2931 /* Single step trace mode */
2934 #if defined(CONFIG_USER_ONLY)
2941 void cpu_ppc_close(CPUPPCState *env)
2943 /* Should also remove all opcode tables... */
2947 /*****************************************************************************/
2948 void raise_exception_err (int exception_index, int error_code);
2949 int print_insn_powerpc (FILE *out, unsigned long insn, unsigned memaddr,
2952 int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
2956 opc_handler_t **table, *handler;
2958 uint16_t *gen_opc_end;
2962 gen_opc_ptr = gen_opc_buf;
2963 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
2964 gen_opparam_ptr = gen_opparam_buf;
2965 ctx.nip = (uint32_t *)pc_start;
2967 ctx.decr_offset = 0;
2969 ctx.exception = EXCP_NONE;
2970 #if defined(CONFIG_USER_ONLY)
2973 ctx.supervisor = 1 - msr_pr;
2974 ctx.mem_idx = (1 - msr_pr);
2976 #if defined (DO_SINGLE_STEP)
2977 /* Single step trace mode */
2980 /* Set env in case of segfault during code fetch */
2981 while (ctx.exception == EXCP_NONE && gen_opc_ptr < gen_opc_end) {
2984 fprintf(logfile, "Search PC...\n");
2985 j = gen_opc_ptr - gen_opc_buf;
2989 gen_opc_instr_start[lj++] = 0;
2990 gen_opc_pc[lj] = (uint32_t)ctx.nip;
2991 gen_opc_instr_start[lj] = 1;
2994 #if defined DEBUG_DISAS
2996 fprintf(logfile, "----------------\n");
2997 fprintf(logfile, "nip=%p super=%d ir=%d\n",
2998 ctx.nip, 1 - msr_pr, msr_ir);
3001 ctx.opcode = ldl_code(ctx.nip);
3002 #if defined DEBUG_DISAS
3004 fprintf(logfile, "translate opcode %08x (%02x %02x %02x)\n",
3005 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
3011 /* Check decrementer exception */
3012 if (++ctx.decr_offset == env->decr + 1)
3013 ctx.exception = EXCP_DECR;
3014 table = ppc_opcodes;
3015 handler = table[opc1(ctx.opcode)];
3016 if (is_indirect_opcode(handler)) {
3017 table = ind_table(handler);
3018 handler = table[opc2(ctx.opcode)];
3019 if (is_indirect_opcode(handler)) {
3020 table = ind_table(handler);
3021 handler = table[opc3(ctx.opcode)];
3024 /* Is opcode *REALLY* valid ? */
3025 if ((ctx.opcode & handler->inval) != 0) {
3027 if (handler->handler == &gen_invalid) {
3028 fprintf(logfile, "invalid/unsupported opcode: "
3029 "%02x -%02x - %02x (%08x) %p\n",
3030 opc1(ctx.opcode), opc2(ctx.opcode),
3031 opc3(ctx.opcode), ctx.opcode, ctx.nip - 1);
3033 fprintf(logfile, "invalid bits: %08x for opcode: "
3034 "%02x -%02x - %02x (0x%08x) (%p)\n",
3035 ctx.opcode & handler->inval, opc1(ctx.opcode),
3036 opc2(ctx.opcode), opc3(ctx.opcode),
3037 ctx.opcode, ctx.nip - 1);
3040 if (handler->handler == &gen_invalid) {
3041 printf("invalid/unsupported opcode: "
3042 "%02x -%02x - %02x (%08x) %p\n",
3043 opc1(ctx.opcode), opc2(ctx.opcode),
3044 opc3(ctx.opcode), ctx.opcode, ctx.nip - 1);
3046 printf("invalid bits: %08x for opcode: "
3047 "%02x -%02x - %02x (0x%08x) (%p)\n",
3048 ctx.opcode & handler->inval, opc1(ctx.opcode),
3049 opc2(ctx.opcode), opc3(ctx.opcode),
3050 ctx.opcode, ctx.nip - 1);
3053 (*gen_invalid)(&ctx);
3055 (*(handler->handler))(&ctx);
3057 /* Check trace mode exceptions */
3058 if ((msr_be && ctx.exception == EXCP_BRANCH) ||
3059 /* Check in single step trace mode
3060 * we need to stop except if:
3061 * - rfi, trap or syscall
3062 * - first instruction of an exception handler
3064 (msr_se && ((uint32_t)ctx.nip < 0x100 ||
3065 (uint32_t)ctx.nip > 0xF00 ||
3066 ((uint32_t)ctx.nip & 0xFC) != 0x04) &&
3067 ctx.exception != EXCP_SYSCALL && ctx.exception != EXCP_RFI &&
3068 ctx.exception != EXCP_TRAP)) {
3069 #if !defined(CONFIG_USER_ONLY)
3070 gen_op_queue_exception(EXCP_TRACE);
3072 if (ctx.exception == EXCP_NONE) {
3073 ctx.exception = EXCP_TRACE;
3076 /* if too long translation, stop generation too */
3077 if (gen_opc_ptr >= gen_opc_end ||
3078 ((uint32_t)ctx.nip - pc_start) >= (TARGET_PAGE_SIZE - 32)) {
3079 if (ctx.exception == EXCP_NONE) {
3080 gen_op_b((long)ctx.tb, (uint32_t)ctx.nip);
3081 ctx.exception = EXCP_BRANCH;
3085 /* In case of branch, this has already been done *BEFORE* the branch */
3086 if (ctx.exception != EXCP_BRANCH && ctx.exception != EXCP_RFI) {
3087 gen_op_update_tb(ctx.tb_offset);
3088 gen_op_update_decr(ctx.decr_offset);
3089 gen_op_process_exceptions((uint32_t)ctx.nip);
3092 /* TO BE FIXED: T0 hasn't got a proper value, which makes tb_add_jump
3093 * do bad business and then qemu crashes !
3097 /* Generate the return instruction */
3099 *gen_opc_ptr = INDEX_op_end;
3101 j = gen_opc_ptr - gen_opc_buf;
3104 gen_opc_instr_start[lj++] = 0;
3112 tb->size = (uint32_t)ctx.nip - pc_start;
3116 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
3117 cpu_ppc_dump_state(env, logfile, 0);
3118 fprintf(logfile, "IN: %s\n", lookup_symbol((void *)pc_start));
3119 disas(logfile, (void *)pc_start, (uint32_t)ctx.nip - pc_start, 0, 0);
3120 fprintf(logfile, "\n");
3122 fprintf(logfile, "OP:\n");
3123 dump_ops(gen_opc_buf, gen_opparam_buf);
3124 fprintf(logfile, "\n");
3131 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
3133 return gen_intermediate_code_internal(env, tb, 0);
3136 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
3138 return gen_intermediate_code_internal(env, tb, 1);