2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 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
30 //#define DO_SINGLE_STEP
31 //#define PPC_DEBUG_DISAS
32 //#define DO_PPC_STATISTICS
34 #ifdef USE_DIRECT_JUMP
37 #define TBPARAM(x) (long)(x)
41 #define DEF(s, n, copy_size) INDEX_op_ ## s,
47 static uint16_t *gen_opc_ptr;
48 static uint32_t *gen_opparam_ptr;
52 #define GEN8(func, NAME) \
53 static GenOpFunc *NAME ## _table [8] = { \
54 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
55 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
57 static inline void func(int n) \
59 NAME ## _table[n](); \
62 #define GEN16(func, NAME) \
63 static GenOpFunc *NAME ## _table [16] = { \
64 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
65 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
66 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
67 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
69 static inline void func(int n) \
71 NAME ## _table[n](); \
74 #define GEN32(func, NAME) \
75 static GenOpFunc *NAME ## _table [32] = { \
76 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
77 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
78 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
79 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
80 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
81 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
82 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
83 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
85 static inline void func(int n) \
87 NAME ## _table[n](); \
90 /* Condition register moves */
91 GEN8(gen_op_load_crf_T0, gen_op_load_crf_T0_crf);
92 GEN8(gen_op_load_crf_T1, gen_op_load_crf_T1_crf);
93 GEN8(gen_op_store_T0_crf, gen_op_store_T0_crf_crf);
94 GEN8(gen_op_store_T1_crf, gen_op_store_T1_crf_crf);
96 /* Floating point condition and status register moves */
97 GEN8(gen_op_load_fpscr_T0, gen_op_load_fpscr_T0_fpscr);
98 GEN8(gen_op_store_T0_fpscr, gen_op_store_T0_fpscr_fpscr);
99 GEN8(gen_op_clear_fpscr, gen_op_clear_fpscr_fpscr);
100 static inline void gen_op_store_T0_fpscri(int n, uint8_t param)
102 gen_op_set_T0(param);
103 gen_op_store_T0_fpscr(n);
106 /* General purpose registers moves */
107 GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
108 GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
109 GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
111 GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
112 GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
114 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);
124 GEN32(gen_op_store_FT2_fpr, gen_op_store_FT2_fpr_fpr);
127 /* internal defines */
128 typedef struct DisasContext {
129 struct TranslationBlock *tb;
133 /* Routine used to access memory */
135 /* Translation flags */
136 #if !defined(CONFIG_USER_ONLY)
140 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
141 int singlestep_enabled;
144 struct opc_handler_t {
147 /* instruction type */
150 void (*handler)(DisasContext *ctx);
151 #if defined(DO_PPC_STATISTICS)
152 const unsigned char *oname;
157 static inline void gen_set_Rc0 (DisasContext *ctx)
163 #define RET_EXCP(ctx, excp, error) \
165 if ((ctx)->exception == EXCP_NONE) { \
166 gen_op_update_nip((ctx)->nip); \
168 gen_op_raise_exception_err((excp), (error)); \
169 ctx->exception = (excp); \
172 #define RET_INVAL(ctx) \
173 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL)
175 #define RET_PRIVOPC(ctx) \
176 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_OPC)
178 #define RET_PRIVREG(ctx) \
179 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG)
181 /* Stop translation */
182 static inline void RET_STOP (DisasContext *ctx)
184 gen_op_update_nip((ctx)->nip);
185 ctx->exception = EXCP_MTMSR;
188 /* No need to update nip here, as execution flow will change */
189 static inline void RET_CHG_FLOW (DisasContext *ctx)
191 ctx->exception = EXCP_MTMSR;
194 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
195 static void gen_##name (DisasContext *ctx); \
196 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
197 static void gen_##name (DisasContext *ctx)
199 typedef struct opcode_t {
200 unsigned char opc1, opc2, opc3;
201 #if HOST_LONG_BITS == 64 /* Explicitely align to 64 bits */
202 unsigned char pad[5];
204 unsigned char pad[1];
206 opc_handler_t handler;
207 const unsigned char *oname;
210 /*** Instruction decoding ***/
211 #define EXTRACT_HELPER(name, shift, nb) \
212 static inline target_ulong name (uint32_t opcode) \
214 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
217 #define EXTRACT_SHELPER(name, shift, nb) \
218 static inline target_long name (uint32_t opcode) \
220 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
224 EXTRACT_HELPER(opc1, 26, 6);
226 EXTRACT_HELPER(opc2, 1, 5);
228 EXTRACT_HELPER(opc3, 6, 5);
229 /* Update Cr0 flags */
230 EXTRACT_HELPER(Rc, 0, 1);
232 EXTRACT_HELPER(rD, 21, 5);
234 EXTRACT_HELPER(rS, 21, 5);
236 EXTRACT_HELPER(rA, 16, 5);
238 EXTRACT_HELPER(rB, 11, 5);
240 EXTRACT_HELPER(rC, 6, 5);
242 EXTRACT_HELPER(crfD, 23, 3);
243 EXTRACT_HELPER(crfS, 18, 3);
244 EXTRACT_HELPER(crbD, 21, 5);
245 EXTRACT_HELPER(crbA, 16, 5);
246 EXTRACT_HELPER(crbB, 11, 5);
248 EXTRACT_HELPER(_SPR, 11, 10);
249 static inline uint32_t SPR (uint32_t opcode)
251 uint32_t sprn = _SPR(opcode);
253 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
255 /*** Get constants ***/
256 EXTRACT_HELPER(IMM, 12, 8);
257 /* 16 bits signed immediate value */
258 EXTRACT_SHELPER(SIMM, 0, 16);
259 /* 16 bits unsigned immediate value */
260 EXTRACT_HELPER(UIMM, 0, 16);
262 EXTRACT_HELPER(NB, 11, 5);
264 EXTRACT_HELPER(SH, 11, 5);
266 EXTRACT_HELPER(MB, 6, 5);
268 EXTRACT_HELPER(ME, 1, 5);
270 EXTRACT_HELPER(TO, 21, 5);
272 EXTRACT_HELPER(CRM, 12, 8);
273 EXTRACT_HELPER(FM, 17, 8);
274 EXTRACT_HELPER(SR, 16, 4);
275 EXTRACT_HELPER(FPIMM, 20, 4);
277 /*** Jump target decoding ***/
279 EXTRACT_SHELPER(d, 0, 16);
280 /* Immediate address */
281 static inline target_ulong LI (uint32_t opcode)
283 return (opcode >> 0) & 0x03FFFFFC;
286 static inline uint32_t BD (uint32_t opcode)
288 return (opcode >> 0) & 0xFFFC;
291 EXTRACT_HELPER(BO, 21, 5);
292 EXTRACT_HELPER(BI, 16, 5);
293 /* Absolute/relative address */
294 EXTRACT_HELPER(AA, 1, 1);
296 EXTRACT_HELPER(LK, 0, 1);
298 /* Create a mask between <start> and <end> bits */
299 static inline target_ulong MASK (uint32_t start, uint32_t end)
303 #if defined(TARGET_PPC64)
304 if (likely(start == 0)) {
305 ret = (uint64_t)(-1ULL) << (63 - end);
306 } else if (likely(end == 63)) {
307 ret = (uint64_t)(-1ULL) >> start;
310 if (likely(start == 0)) {
311 ret = (uint32_t)(-1ULL) << (31 - end);
312 } else if (likely(end == 31)) {
313 ret = (uint32_t)(-1ULL) >> start;
317 ret = (((target_ulong)(-1ULL)) >> (start)) ^
318 (((target_ulong)(-1ULL) >> (end)) >> 1);
319 if (unlikely(start > end))
326 #if HOST_LONG_BITS == 64
331 #if defined(__APPLE__)
332 #define OPCODES_SECTION \
333 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
335 #define OPCODES_SECTION \
336 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
339 #if defined(DO_PPC_STATISTICS)
340 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
341 OPCODES_SECTION opcode_t opc_##name = { \
349 .handler = &gen_##name, \
350 .oname = stringify(name), \
352 .oname = stringify(name), \
355 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
356 OPCODES_SECTION opcode_t opc_##name = { \
364 .handler = &gen_##name, \
366 .oname = stringify(name), \
370 #define GEN_OPCODE_MARK(name) \
371 OPCODES_SECTION opcode_t opc_##name = { \
377 .inval = 0x00000000, \
381 .oname = stringify(name), \
384 /* Start opcode list */
385 GEN_OPCODE_MARK(start);
387 /* Invalid instruction */
388 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
393 static opc_handler_t invalid_handler = {
396 .handler = gen_invalid,
399 /*** Integer arithmetic ***/
400 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval) \
401 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
403 gen_op_load_gpr_T0(rA(ctx->opcode)); \
404 gen_op_load_gpr_T1(rB(ctx->opcode)); \
406 gen_op_store_T0_gpr(rD(ctx->opcode)); \
407 if (unlikely(Rc(ctx->opcode) != 0)) \
411 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval) \
412 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
414 gen_op_load_gpr_T0(rA(ctx->opcode)); \
415 gen_op_load_gpr_T1(rB(ctx->opcode)); \
417 gen_op_store_T0_gpr(rD(ctx->opcode)); \
418 if (unlikely(Rc(ctx->opcode) != 0)) \
422 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
423 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
425 gen_op_load_gpr_T0(rA(ctx->opcode)); \
427 gen_op_store_T0_gpr(rD(ctx->opcode)); \
428 if (unlikely(Rc(ctx->opcode) != 0)) \
431 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3) \
432 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
434 gen_op_load_gpr_T0(rA(ctx->opcode)); \
436 gen_op_store_T0_gpr(rD(ctx->opcode)); \
437 if (unlikely(Rc(ctx->opcode) != 0)) \
441 /* Two operands arithmetic functions */
442 #define GEN_INT_ARITH2(name, opc1, opc2, opc3) \
443 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000) \
444 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000)
446 /* Two operands arithmetic functions with no overflow allowed */
447 #define GEN_INT_ARITHN(name, opc1, opc2, opc3) \
448 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400)
450 /* One operand arithmetic functions */
451 #define GEN_INT_ARITH1(name, opc1, opc2, opc3) \
452 __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
453 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10)
455 /* add add. addo addo. */
456 GEN_INT_ARITH2 (add, 0x1F, 0x0A, 0x08);
457 /* addc addc. addco addco. */
458 GEN_INT_ARITH2 (addc, 0x1F, 0x0A, 0x00);
459 /* adde adde. addeo addeo. */
460 GEN_INT_ARITH2 (adde, 0x1F, 0x0A, 0x04);
461 /* addme addme. addmeo addmeo. */
462 GEN_INT_ARITH1 (addme, 0x1F, 0x0A, 0x07);
463 /* addze addze. addzeo addzeo. */
464 GEN_INT_ARITH1 (addze, 0x1F, 0x0A, 0x06);
465 /* divw divw. divwo divwo. */
466 GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F);
467 /* divwu divwu. divwuo divwuo. */
468 GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E);
470 GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02);
472 GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00);
473 /* mullw mullw. mullwo mullwo. */
474 GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07);
475 /* neg neg. nego nego. */
476 GEN_INT_ARITH1 (neg, 0x1F, 0x08, 0x03);
477 /* subf subf. subfo subfo. */
478 GEN_INT_ARITH2 (subf, 0x1F, 0x08, 0x01);
479 /* subfc subfc. subfco subfco. */
480 GEN_INT_ARITH2 (subfc, 0x1F, 0x08, 0x00);
481 /* subfe subfe. subfeo subfeo. */
482 GEN_INT_ARITH2 (subfe, 0x1F, 0x08, 0x04);
483 /* subfme subfme. subfmeo subfmeo. */
484 GEN_INT_ARITH1 (subfme, 0x1F, 0x08, 0x07);
485 /* subfze subfze. subfzeo subfzeo. */
486 GEN_INT_ARITH1 (subfze, 0x1F, 0x08, 0x06);
488 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
490 target_long simm = SIMM(ctx->opcode);
492 if (rA(ctx->opcode) == 0) {
496 gen_op_load_gpr_T0(rA(ctx->opcode));
497 if (likely(simm != 0))
500 gen_op_store_T0_gpr(rD(ctx->opcode));
503 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
505 target_long simm = SIMM(ctx->opcode);
507 gen_op_load_gpr_T0(rA(ctx->opcode));
508 if (likely(simm != 0))
509 gen_op_addic(SIMM(ctx->opcode));
510 gen_op_store_T0_gpr(rD(ctx->opcode));
513 GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
515 target_long simm = SIMM(ctx->opcode);
517 gen_op_load_gpr_T0(rA(ctx->opcode));
518 if (likely(simm != 0))
519 gen_op_addic(SIMM(ctx->opcode));
520 gen_op_store_T0_gpr(rD(ctx->opcode));
524 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
526 target_long simm = SIMM(ctx->opcode);
528 if (rA(ctx->opcode) == 0) {
530 gen_op_set_T0(simm << 16);
532 gen_op_load_gpr_T0(rA(ctx->opcode));
533 if (likely(simm != 0))
534 gen_op_addi(simm << 16);
536 gen_op_store_T0_gpr(rD(ctx->opcode));
539 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
541 gen_op_load_gpr_T0(rA(ctx->opcode));
542 gen_op_mulli(SIMM(ctx->opcode));
543 gen_op_store_T0_gpr(rD(ctx->opcode));
546 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
548 gen_op_load_gpr_T0(rA(ctx->opcode));
549 gen_op_subfic(SIMM(ctx->opcode));
550 gen_op_store_T0_gpr(rD(ctx->opcode));
553 /*** Integer comparison ***/
554 #define GEN_CMP(name, opc) \
555 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, PPC_INTEGER) \
557 gen_op_load_gpr_T0(rA(ctx->opcode)); \
558 gen_op_load_gpr_T1(rB(ctx->opcode)); \
560 gen_op_store_T0_crf(crfD(ctx->opcode)); \
566 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
568 gen_op_load_gpr_T0(rA(ctx->opcode));
569 gen_op_cmpi(SIMM(ctx->opcode));
570 gen_op_store_T0_crf(crfD(ctx->opcode));
575 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
577 gen_op_load_gpr_T0(rA(ctx->opcode));
578 gen_op_cmpli(UIMM(ctx->opcode));
579 gen_op_store_T0_crf(crfD(ctx->opcode));
582 /*** Integer logical ***/
583 #define __GEN_LOGICAL2(name, opc2, opc3) \
584 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \
586 gen_op_load_gpr_T0(rS(ctx->opcode)); \
587 gen_op_load_gpr_T1(rB(ctx->opcode)); \
589 gen_op_store_T0_gpr(rA(ctx->opcode)); \
590 if (unlikely(Rc(ctx->opcode) != 0)) \
593 #define GEN_LOGICAL2(name, opc) \
594 __GEN_LOGICAL2(name, 0x1C, opc)
596 #define GEN_LOGICAL1(name, opc) \
597 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \
599 gen_op_load_gpr_T0(rS(ctx->opcode)); \
601 gen_op_store_T0_gpr(rA(ctx->opcode)); \
602 if (unlikely(Rc(ctx->opcode) != 0)) \
607 GEN_LOGICAL2(and, 0x00);
609 GEN_LOGICAL2(andc, 0x01);
611 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
613 gen_op_load_gpr_T0(rS(ctx->opcode));
614 gen_op_andi_T0(UIMM(ctx->opcode));
615 gen_op_store_T0_gpr(rA(ctx->opcode));
619 GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
621 gen_op_load_gpr_T0(rS(ctx->opcode));
622 gen_op_andi_T0(UIMM(ctx->opcode) << 16);
623 gen_op_store_T0_gpr(rA(ctx->opcode));
628 GEN_LOGICAL1(cntlzw, 0x00);
630 GEN_LOGICAL2(eqv, 0x08);
632 GEN_LOGICAL1(extsb, 0x1D);
634 GEN_LOGICAL1(extsh, 0x1C);
636 GEN_LOGICAL2(nand, 0x0E);
638 GEN_LOGICAL2(nor, 0x03);
641 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
645 rs = rS(ctx->opcode);
646 ra = rA(ctx->opcode);
647 rb = rB(ctx->opcode);
648 /* Optimisation for mr. ri case */
649 if (rs != ra || rs != rb) {
650 gen_op_load_gpr_T0(rs);
652 gen_op_load_gpr_T1(rb);
655 gen_op_store_T0_gpr(ra);
656 if (unlikely(Rc(ctx->opcode) != 0))
658 } else if (unlikely(Rc(ctx->opcode) != 0)) {
659 gen_op_load_gpr_T0(rs);
665 GEN_LOGICAL2(orc, 0x0C);
667 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
669 gen_op_load_gpr_T0(rS(ctx->opcode));
670 /* Optimisation for "set to zero" case */
671 if (rS(ctx->opcode) != rB(ctx->opcode)) {
672 gen_op_load_gpr_T1(rB(ctx->opcode));
677 gen_op_store_T0_gpr(rA(ctx->opcode));
678 if (unlikely(Rc(ctx->opcode) != 0))
682 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
684 target_ulong uimm = UIMM(ctx->opcode);
686 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
688 /* XXX: should handle special NOPs for POWER series */
691 gen_op_load_gpr_T0(rS(ctx->opcode));
692 if (likely(uimm != 0))
694 gen_op_store_T0_gpr(rA(ctx->opcode));
697 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
699 target_ulong uimm = UIMM(ctx->opcode);
701 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
705 gen_op_load_gpr_T0(rS(ctx->opcode));
706 if (likely(uimm != 0))
707 gen_op_ori(uimm << 16);
708 gen_op_store_T0_gpr(rA(ctx->opcode));
711 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
713 target_ulong uimm = UIMM(ctx->opcode);
715 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
719 gen_op_load_gpr_T0(rS(ctx->opcode));
720 if (likely(uimm != 0))
722 gen_op_store_T0_gpr(rA(ctx->opcode));
726 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
728 target_ulong uimm = UIMM(ctx->opcode);
730 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
734 gen_op_load_gpr_T0(rS(ctx->opcode));
735 if (likely(uimm != 0))
736 gen_op_xori(uimm << 16);
737 gen_op_store_T0_gpr(rA(ctx->opcode));
740 /*** Integer rotate ***/
741 /* rlwimi & rlwimi. */
742 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
748 mb = MB(ctx->opcode);
749 me = ME(ctx->opcode);
750 sh = SH(ctx->opcode);
752 if (likely(sh == 0)) {
753 if (likely(mb == 0 && me == 31)) {
754 gen_op_load_gpr_T0(rS(ctx->opcode));
756 } else if (likely(mb == 31 && me == 0)) {
757 gen_op_load_gpr_T0(rA(ctx->opcode));
760 gen_op_load_gpr_T0(rS(ctx->opcode));
761 gen_op_load_gpr_T1(rA(ctx->opcode));
764 gen_op_load_gpr_T0(rS(ctx->opcode));
765 gen_op_load_gpr_T1(rA(ctx->opcode));
766 gen_op_rotli32_T0(SH(ctx->opcode));
768 #if defined(TARGET_PPC64)
773 gen_op_andi_T0(mask);
774 gen_op_andi_T1(~mask);
777 gen_op_store_T0_gpr(rA(ctx->opcode));
778 if (unlikely(Rc(ctx->opcode) != 0))
781 /* rlwinm & rlwinm. */
782 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
786 sh = SH(ctx->opcode);
787 mb = MB(ctx->opcode);
788 me = ME(ctx->opcode);
789 gen_op_load_gpr_T0(rS(ctx->opcode));
790 if (likely(sh == 0)) {
793 if (likely(mb == 0)) {
794 if (likely(me == 31)) {
795 gen_op_rotli32_T0(sh);
797 } else if (likely(me == (31 - sh))) {
801 } else if (likely(me == 31)) {
802 if (likely(sh == (32 - mb))) {
807 gen_op_rotli32_T0(sh);
809 #if defined(TARGET_PPC64)
813 gen_op_andi_T0(MASK(mb, me));
815 gen_op_store_T0_gpr(rA(ctx->opcode));
816 if (unlikely(Rc(ctx->opcode) != 0))
820 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
824 mb = MB(ctx->opcode);
825 me = ME(ctx->opcode);
826 gen_op_load_gpr_T0(rS(ctx->opcode));
827 gen_op_load_gpr_T1(rB(ctx->opcode));
828 gen_op_rotl32_T0_T1();
829 if (unlikely(mb != 0 || me != 31)) {
830 #if defined(TARGET_PPC64)
834 gen_op_andi_T0(MASK(mb, me));
836 gen_op_store_T0_gpr(rA(ctx->opcode));
837 if (unlikely(Rc(ctx->opcode) != 0))
841 /*** Integer shift ***/
843 __GEN_LOGICAL2(slw, 0x18, 0x00);
845 __GEN_LOGICAL2(sraw, 0x18, 0x18);
847 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
849 gen_op_load_gpr_T0(rS(ctx->opcode));
850 if (SH(ctx->opcode) != 0)
851 gen_op_srawi(SH(ctx->opcode), MASK(32 - SH(ctx->opcode), 31));
852 gen_op_store_T0_gpr(rA(ctx->opcode));
853 if (unlikely(Rc(ctx->opcode) != 0))
857 __GEN_LOGICAL2(srw, 0x18, 0x10);
859 /*** Floating-Point arithmetic ***/
860 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat) \
861 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, PPC_FLOAT) \
863 if (unlikely(!ctx->fpu_enabled)) { \
864 RET_EXCP(ctx, EXCP_NO_FP, 0); \
867 gen_op_reset_scrfx(); \
868 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
869 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
870 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
875 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
876 if (unlikely(Rc(ctx->opcode) != 0)) \
880 #define GEN_FLOAT_ACB(name, op2) \
881 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0); \
882 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1);
884 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
885 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
887 if (unlikely(!ctx->fpu_enabled)) { \
888 RET_EXCP(ctx, EXCP_NO_FP, 0); \
891 gen_op_reset_scrfx(); \
892 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
893 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
898 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
899 if (unlikely(Rc(ctx->opcode) != 0)) \
902 #define GEN_FLOAT_AB(name, op2, inval) \
903 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
904 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
906 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
907 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
909 if (unlikely(!ctx->fpu_enabled)) { \
910 RET_EXCP(ctx, EXCP_NO_FP, 0); \
913 gen_op_reset_scrfx(); \
914 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
915 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
920 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
921 if (unlikely(Rc(ctx->opcode) != 0)) \
924 #define GEN_FLOAT_AC(name, op2, inval) \
925 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
926 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
928 #define GEN_FLOAT_B(name, op2, op3) \
929 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, PPC_FLOAT) \
931 if (unlikely(!ctx->fpu_enabled)) { \
932 RET_EXCP(ctx, EXCP_NO_FP, 0); \
935 gen_op_reset_scrfx(); \
936 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
938 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
939 if (unlikely(Rc(ctx->opcode) != 0)) \
943 #define GEN_FLOAT_BS(name, op1, op2) \
944 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, PPC_FLOAT) \
946 if (unlikely(!ctx->fpu_enabled)) { \
947 RET_EXCP(ctx, EXCP_NO_FP, 0); \
950 gen_op_reset_scrfx(); \
951 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
953 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
954 if (unlikely(Rc(ctx->opcode) != 0)) \
959 GEN_FLOAT_AB(add, 0x15, 0x000007C0);
961 GEN_FLOAT_AB(div, 0x12, 0x000007C0);
963 GEN_FLOAT_AC(mul, 0x19, 0x0000F800);
965 /* fres */ /* XXX: not in 601 */
966 GEN_FLOAT_BS(res, 0x3B, 0x18);
968 /* frsqrte */ /* XXX: not in 601 */
969 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A);
971 /* fsel */ /* XXX: not in 601 */
972 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0);
974 GEN_FLOAT_AB(sub, 0x14, 0x000007C0);
977 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_OPT)
979 if (unlikely(!ctx->fpu_enabled)) {
980 RET_EXCP(ctx, EXCP_NO_FP, 0);
983 gen_op_reset_scrfx();
984 gen_op_load_fpr_FT0(rB(ctx->opcode));
986 gen_op_store_FT0_fpr(rD(ctx->opcode));
987 if (unlikely(Rc(ctx->opcode) != 0))
991 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_OPT)
993 if (unlikely(!ctx->fpu_enabled)) {
994 RET_EXCP(ctx, EXCP_NO_FP, 0);
997 gen_op_reset_scrfx();
998 gen_op_load_fpr_FT0(rB(ctx->opcode));
1001 gen_op_store_FT0_fpr(rD(ctx->opcode));
1002 if (unlikely(Rc(ctx->opcode) != 0))
1006 /*** Floating-Point multiply-and-add ***/
1007 /* fmadd - fmadds */
1008 GEN_FLOAT_ACB(madd, 0x1D);
1009 /* fmsub - fmsubs */
1010 GEN_FLOAT_ACB(msub, 0x1C);
1011 /* fnmadd - fnmadds */
1012 GEN_FLOAT_ACB(nmadd, 0x1F);
1013 /* fnmsub - fnmsubs */
1014 GEN_FLOAT_ACB(nmsub, 0x1E);
1016 /*** Floating-Point round & convert ***/
1018 GEN_FLOAT_B(ctiw, 0x0E, 0x00);
1020 GEN_FLOAT_B(ctiwz, 0x0F, 0x00);
1022 GEN_FLOAT_B(rsp, 0x0C, 0x00);
1024 /*** Floating-Point compare ***/
1026 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
1028 if (unlikely(!ctx->fpu_enabled)) {
1029 RET_EXCP(ctx, EXCP_NO_FP, 0);
1032 gen_op_reset_scrfx();
1033 gen_op_load_fpr_FT0(rA(ctx->opcode));
1034 gen_op_load_fpr_FT1(rB(ctx->opcode));
1036 gen_op_store_T0_crf(crfD(ctx->opcode));
1040 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
1042 if (unlikely(!ctx->fpu_enabled)) {
1043 RET_EXCP(ctx, EXCP_NO_FP, 0);
1046 gen_op_reset_scrfx();
1047 gen_op_load_fpr_FT0(rA(ctx->opcode));
1048 gen_op_load_fpr_FT1(rB(ctx->opcode));
1050 gen_op_store_T0_crf(crfD(ctx->opcode));
1053 /*** Floating-point move ***/
1055 GEN_FLOAT_B(abs, 0x08, 0x08);
1058 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
1060 if (unlikely(!ctx->fpu_enabled)) {
1061 RET_EXCP(ctx, EXCP_NO_FP, 0);
1064 gen_op_reset_scrfx();
1065 gen_op_load_fpr_FT0(rB(ctx->opcode));
1066 gen_op_store_FT0_fpr(rD(ctx->opcode));
1067 if (unlikely(Rc(ctx->opcode) != 0))
1072 GEN_FLOAT_B(nabs, 0x08, 0x04);
1074 GEN_FLOAT_B(neg, 0x08, 0x01);
1076 /*** Floating-Point status & ctrl register ***/
1078 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
1080 if (unlikely(!ctx->fpu_enabled)) {
1081 RET_EXCP(ctx, EXCP_NO_FP, 0);
1084 gen_op_load_fpscr_T0(crfS(ctx->opcode));
1085 gen_op_store_T0_crf(crfD(ctx->opcode));
1086 gen_op_clear_fpscr(crfS(ctx->opcode));
1090 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
1092 if (unlikely(!ctx->fpu_enabled)) {
1093 RET_EXCP(ctx, EXCP_NO_FP, 0);
1096 gen_op_load_fpscr();
1097 gen_op_store_FT0_fpr(rD(ctx->opcode));
1098 if (unlikely(Rc(ctx->opcode) != 0))
1103 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
1107 if (unlikely(!ctx->fpu_enabled)) {
1108 RET_EXCP(ctx, EXCP_NO_FP, 0);
1111 crb = crbD(ctx->opcode) >> 2;
1112 gen_op_load_fpscr_T0(crb);
1113 gen_op_andi_T0(~(1 << (crbD(ctx->opcode) & 0x03)));
1114 gen_op_store_T0_fpscr(crb);
1115 if (unlikely(Rc(ctx->opcode) != 0))
1120 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
1124 if (unlikely(!ctx->fpu_enabled)) {
1125 RET_EXCP(ctx, EXCP_NO_FP, 0);
1128 crb = crbD(ctx->opcode) >> 2;
1129 gen_op_load_fpscr_T0(crb);
1130 gen_op_ori(1 << (crbD(ctx->opcode) & 0x03));
1131 gen_op_store_T0_fpscr(crb);
1132 if (unlikely(Rc(ctx->opcode) != 0))
1137 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
1139 if (unlikely(!ctx->fpu_enabled)) {
1140 RET_EXCP(ctx, EXCP_NO_FP, 0);
1143 gen_op_load_fpr_FT0(rB(ctx->opcode));
1144 gen_op_store_fpscr(FM(ctx->opcode));
1145 if (unlikely(Rc(ctx->opcode) != 0))
1150 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
1152 if (unlikely(!ctx->fpu_enabled)) {
1153 RET_EXCP(ctx, EXCP_NO_FP, 0);
1156 gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
1157 if (unlikely(Rc(ctx->opcode) != 0))
1161 /*** Addressing modes ***/
1162 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
1163 static inline void gen_addr_imm_index (DisasContext *ctx)
1165 target_long simm = SIMM(ctx->opcode);
1167 if (rA(ctx->opcode) == 0) {
1168 gen_op_set_T0(simm);
1170 gen_op_load_gpr_T0(rA(ctx->opcode));
1171 if (likely(simm != 0))
1176 static inline void gen_addr_reg_index (DisasContext *ctx)
1178 if (rA(ctx->opcode) == 0) {
1179 gen_op_load_gpr_T0(rB(ctx->opcode));
1181 gen_op_load_gpr_T0(rA(ctx->opcode));
1182 gen_op_load_gpr_T1(rB(ctx->opcode));
1187 static inline void gen_addr_register (DisasContext *ctx)
1189 if (rA(ctx->opcode) == 0) {
1192 gen_op_load_gpr_T0(rA(ctx->opcode));
1196 /*** Integer load ***/
1197 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
1198 #if defined(CONFIG_USER_ONLY)
1199 #define OP_LD_TABLE(width) \
1200 static GenOpFunc *gen_op_l##width[] = { \
1201 &gen_op_l##width##_raw, \
1202 &gen_op_l##width##_le_raw, \
1204 #define OP_ST_TABLE(width) \
1205 static GenOpFunc *gen_op_st##width[] = { \
1206 &gen_op_st##width##_raw, \
1207 &gen_op_st##width##_le_raw, \
1209 /* Byte access routine are endian safe */
1210 #define gen_op_stb_le_raw gen_op_stb_raw
1211 #define gen_op_lbz_le_raw gen_op_lbz_raw
1213 #define OP_LD_TABLE(width) \
1214 static GenOpFunc *gen_op_l##width[] = { \
1215 &gen_op_l##width##_user, \
1216 &gen_op_l##width##_le_user, \
1217 &gen_op_l##width##_kernel, \
1218 &gen_op_l##width##_le_kernel, \
1220 #define OP_ST_TABLE(width) \
1221 static GenOpFunc *gen_op_st##width[] = { \
1222 &gen_op_st##width##_user, \
1223 &gen_op_st##width##_le_user, \
1224 &gen_op_st##width##_kernel, \
1225 &gen_op_st##width##_le_kernel, \
1227 /* Byte access routine are endian safe */
1228 #define gen_op_stb_le_user gen_op_stb_user
1229 #define gen_op_lbz_le_user gen_op_lbz_user
1230 #define gen_op_stb_le_kernel gen_op_stb_kernel
1231 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
1234 #define GEN_LD(width, opc) \
1235 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1237 gen_addr_imm_index(ctx); \
1238 op_ldst(l##width); \
1239 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1242 #define GEN_LDU(width, opc) \
1243 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1245 if (unlikely(rA(ctx->opcode) == 0 || \
1246 rA(ctx->opcode) == rD(ctx->opcode))) { \
1250 gen_addr_imm_index(ctx); \
1251 op_ldst(l##width); \
1252 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1253 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1256 #define GEN_LDUX(width, opc) \
1257 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1259 if (unlikely(rA(ctx->opcode) == 0 || \
1260 rA(ctx->opcode) == rD(ctx->opcode))) { \
1264 gen_addr_reg_index(ctx); \
1265 op_ldst(l##width); \
1266 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1267 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1270 #define GEN_LDX(width, opc2, opc3) \
1271 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1273 gen_addr_reg_index(ctx); \
1274 op_ldst(l##width); \
1275 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1278 #define GEN_LDS(width, op) \
1279 OP_LD_TABLE(width); \
1280 GEN_LD(width, op | 0x20); \
1281 GEN_LDU(width, op | 0x21); \
1282 GEN_LDUX(width, op | 0x01); \
1283 GEN_LDX(width, 0x17, op | 0x00)
1285 /* lbz lbzu lbzux lbzx */
1287 /* lha lhau lhaux lhax */
1289 /* lhz lhzu lhzux lhzx */
1291 /* lwz lwzu lwzux lwzx */
1294 /*** Integer store ***/
1295 #define GEN_ST(width, opc) \
1296 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1298 gen_addr_imm_index(ctx); \
1299 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1300 op_ldst(st##width); \
1303 #define GEN_STU(width, opc) \
1304 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1306 if (unlikely(rA(ctx->opcode) == 0)) { \
1310 gen_addr_imm_index(ctx); \
1311 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1312 op_ldst(st##width); \
1313 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1316 #define GEN_STUX(width, opc) \
1317 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1319 if (unlikely(rA(ctx->opcode) == 0)) { \
1323 gen_addr_reg_index(ctx); \
1324 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1325 op_ldst(st##width); \
1326 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1329 #define GEN_STX(width, opc2, opc3) \
1330 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1332 gen_addr_reg_index(ctx); \
1333 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1334 op_ldst(st##width); \
1337 #define GEN_STS(width, op) \
1338 OP_ST_TABLE(width); \
1339 GEN_ST(width, op | 0x20); \
1340 GEN_STU(width, op | 0x21); \
1341 GEN_STUX(width, op | 0x01); \
1342 GEN_STX(width, 0x17, op | 0x00)
1344 /* stb stbu stbux stbx */
1346 /* sth sthu sthux sthx */
1348 /* stw stwu stwux stwx */
1351 /*** Integer load and store with byte reverse ***/
1354 GEN_LDX(hbr, 0x16, 0x18);
1357 GEN_LDX(wbr, 0x16, 0x10);
1360 GEN_STX(hbr, 0x16, 0x1C);
1363 GEN_STX(wbr, 0x16, 0x14);
1365 /*** Integer load and store multiple ***/
1366 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
1367 #if defined(CONFIG_USER_ONLY)
1368 static GenOpFunc1 *gen_op_lmw[] = {
1372 static GenOpFunc1 *gen_op_stmw[] = {
1374 &gen_op_stmw_le_raw,
1377 static GenOpFunc1 *gen_op_lmw[] = {
1379 &gen_op_lmw_le_user,
1381 &gen_op_lmw_le_kernel,
1383 static GenOpFunc1 *gen_op_stmw[] = {
1385 &gen_op_stmw_le_user,
1386 &gen_op_stmw_kernel,
1387 &gen_op_stmw_le_kernel,
1392 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1394 /* NIP cannot be restored if the memory exception comes from an helper */
1395 gen_op_update_nip(ctx->nip - 4);
1396 gen_addr_imm_index(ctx);
1397 op_ldstm(lmw, rD(ctx->opcode));
1401 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1403 /* NIP cannot be restored if the memory exception comes from an helper */
1404 gen_op_update_nip(ctx->nip - 4);
1405 gen_addr_imm_index(ctx);
1406 op_ldstm(stmw, rS(ctx->opcode));
1409 /*** Integer load and store strings ***/
1410 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
1411 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
1412 #if defined(CONFIG_USER_ONLY)
1413 static GenOpFunc1 *gen_op_lswi[] = {
1415 &gen_op_lswi_le_raw,
1417 static GenOpFunc3 *gen_op_lswx[] = {
1419 &gen_op_lswx_le_raw,
1421 static GenOpFunc1 *gen_op_stsw[] = {
1423 &gen_op_stsw_le_raw,
1426 static GenOpFunc1 *gen_op_lswi[] = {
1428 &gen_op_lswi_le_user,
1429 &gen_op_lswi_kernel,
1430 &gen_op_lswi_le_kernel,
1432 static GenOpFunc3 *gen_op_lswx[] = {
1434 &gen_op_lswx_le_user,
1435 &gen_op_lswx_kernel,
1436 &gen_op_lswx_le_kernel,
1438 static GenOpFunc1 *gen_op_stsw[] = {
1440 &gen_op_stsw_le_user,
1441 &gen_op_stsw_kernel,
1442 &gen_op_stsw_le_kernel,
1447 /* PowerPC32 specification says we must generate an exception if
1448 * rA is in the range of registers to be loaded.
1449 * In an other hand, IBM says this is valid, but rA won't be loaded.
1450 * For now, I'll follow the spec...
1452 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER)
1454 int nb = NB(ctx->opcode);
1455 int start = rD(ctx->opcode);
1456 int ra = rA(ctx->opcode);
1462 if (unlikely(((start + nr) > 32 &&
1463 start <= ra && (start + nr - 32) > ra) ||
1464 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
1465 RET_EXCP(ctx, EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
1468 /* NIP cannot be restored if the memory exception comes from an helper */
1469 gen_op_update_nip(ctx->nip - 4);
1470 gen_addr_register(ctx);
1472 op_ldsts(lswi, start);
1476 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER)
1478 int ra = rA(ctx->opcode);
1479 int rb = rB(ctx->opcode);
1481 /* NIP cannot be restored if the memory exception comes from an helper */
1482 gen_op_update_nip(ctx->nip - 4);
1483 gen_addr_reg_index(ctx);
1487 gen_op_load_xer_bc();
1488 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
1492 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
1494 int nb = NB(ctx->opcode);
1496 /* NIP cannot be restored if the memory exception comes from an helper */
1497 gen_op_update_nip(ctx->nip - 4);
1498 gen_addr_register(ctx);
1502 op_ldsts(stsw, rS(ctx->opcode));
1506 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER)
1508 /* NIP cannot be restored if the memory exception comes from an helper */
1509 gen_op_update_nip(ctx->nip - 4);
1510 gen_addr_reg_index(ctx);
1511 gen_op_load_xer_bc();
1512 op_ldsts(stsw, rS(ctx->opcode));
1515 /*** Memory synchronisation ***/
1517 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FF0801, PPC_MEM_EIEIO)
1522 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FF0801, PPC_MEM)
1526 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
1527 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
1528 #if defined(CONFIG_USER_ONLY)
1529 static GenOpFunc *gen_op_lwarx[] = {
1531 &gen_op_lwarx_le_raw,
1533 static GenOpFunc *gen_op_stwcx[] = {
1535 &gen_op_stwcx_le_raw,
1538 static GenOpFunc *gen_op_lwarx[] = {
1540 &gen_op_lwarx_le_user,
1541 &gen_op_lwarx_kernel,
1542 &gen_op_lwarx_le_kernel,
1544 static GenOpFunc *gen_op_stwcx[] = {
1546 &gen_op_stwcx_le_user,
1547 &gen_op_stwcx_kernel,
1548 &gen_op_stwcx_le_kernel,
1553 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
1555 gen_addr_reg_index(ctx);
1557 gen_op_store_T1_gpr(rD(ctx->opcode));
1561 GEN_HANDLER(stwcx_, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
1563 gen_addr_reg_index(ctx);
1564 gen_op_load_gpr_T1(rS(ctx->opcode));
1569 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_MEM_SYNC)
1573 /*** Floating-point load ***/
1574 #define GEN_LDF(width, opc) \
1575 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1577 if (unlikely(!ctx->fpu_enabled)) { \
1578 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1581 gen_addr_imm_index(ctx); \
1582 op_ldst(l##width); \
1583 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1586 #define GEN_LDUF(width, opc) \
1587 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1589 if (unlikely(!ctx->fpu_enabled)) { \
1590 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1593 if (unlikely(rA(ctx->opcode) == 0)) { \
1597 gen_addr_imm_index(ctx); \
1598 op_ldst(l##width); \
1599 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1600 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1603 #define GEN_LDUXF(width, opc) \
1604 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_FLOAT) \
1606 if (unlikely(!ctx->fpu_enabled)) { \
1607 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1610 if (unlikely(rA(ctx->opcode) == 0)) { \
1614 gen_addr_reg_index(ctx); \
1615 op_ldst(l##width); \
1616 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1617 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1620 #define GEN_LDXF(width, opc2, opc3) \
1621 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_FLOAT) \
1623 if (unlikely(!ctx->fpu_enabled)) { \
1624 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1627 gen_addr_reg_index(ctx); \
1628 op_ldst(l##width); \
1629 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1632 #define GEN_LDFS(width, op) \
1633 OP_LD_TABLE(width); \
1634 GEN_LDF(width, op | 0x20); \
1635 GEN_LDUF(width, op | 0x21); \
1636 GEN_LDUXF(width, op | 0x01); \
1637 GEN_LDXF(width, 0x17, op | 0x00)
1639 /* lfd lfdu lfdux lfdx */
1641 /* lfs lfsu lfsux lfsx */
1644 /*** Floating-point store ***/
1645 #define GEN_STF(width, opc) \
1646 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1648 if (unlikely(!ctx->fpu_enabled)) { \
1649 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1652 gen_addr_imm_index(ctx); \
1653 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
1654 op_ldst(st##width); \
1657 #define GEN_STUF(width, opc) \
1658 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1660 if (unlikely(!ctx->fpu_enabled)) { \
1661 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1664 if (unlikely(rA(ctx->opcode) == 0)) { \
1668 gen_addr_imm_index(ctx); \
1669 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
1670 op_ldst(st##width); \
1671 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1674 #define GEN_STUXF(width, opc) \
1675 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_FLOAT) \
1677 if (unlikely(!ctx->fpu_enabled)) { \
1678 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1681 if (unlikely(rA(ctx->opcode) == 0)) { \
1685 gen_addr_reg_index(ctx); \
1686 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
1687 op_ldst(st##width); \
1688 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1691 #define GEN_STXF(width, opc2, opc3) \
1692 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_FLOAT) \
1694 if (unlikely(!ctx->fpu_enabled)) { \
1695 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1698 gen_addr_reg_index(ctx); \
1699 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
1700 op_ldst(st##width); \
1703 #define GEN_STFS(width, op) \
1704 OP_ST_TABLE(width); \
1705 GEN_STF(width, op | 0x20); \
1706 GEN_STUF(width, op | 0x21); \
1707 GEN_STUXF(width, op | 0x01); \
1708 GEN_STXF(width, 0x17, op | 0x00)
1710 /* stfd stfdu stfdux stfdx */
1712 /* stfs stfsu stfsux stfsx */
1717 GEN_HANDLER(stfiwx, 0x1F, 0x17, 0x1E, 0x00000001, PPC_FLOAT)
1719 if (unlikely(!ctx->fpu_enabled)) {
1720 RET_EXCP(ctx, EXCP_NO_FP, 0);
1723 gen_addr_reg_index(ctx);
1724 /* XXX: TODO: memcpy low order 32 bits of FRP(rs) into memory */
1730 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1732 TranslationBlock *tb;
1734 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1736 gen_op_goto_tb0(TBPARAM(tb));
1738 gen_op_goto_tb1(TBPARAM(tb));
1739 gen_op_set_T1(dest);
1741 gen_op_set_T0((long)tb + n);
1742 if (ctx->singlestep_enabled)
1746 gen_op_set_T1(dest);
1749 if (ctx->singlestep_enabled)
1756 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1758 target_ulong li, target;
1760 /* sign extend LI */
1761 #if defined(TARGET_PPC64)
1762 li = ((target_long)LI(ctx->opcode) << 38) >> 38;
1764 li = ((target_long)LI(ctx->opcode) << 6) >> 6;
1766 if (likely(AA(ctx->opcode) == 0))
1767 target = ctx->nip + li - 4;
1770 if (LK(ctx->opcode)) {
1771 gen_op_setlr(ctx->nip);
1773 gen_goto_tb(ctx, 0, target);
1774 ctx->exception = EXCP_BRANCH;
1781 static inline void gen_bcond(DisasContext *ctx, int type)
1783 target_ulong target = 0;
1785 uint32_t bo = BO(ctx->opcode);
1786 uint32_t bi = BI(ctx->opcode);
1789 if ((bo & 0x4) == 0)
1793 li = (target_long)((int16_t)(BD(ctx->opcode)));
1794 if (likely(AA(ctx->opcode) == 0)) {
1795 target = ctx->nip + li - 4;
1801 gen_op_movl_T1_ctr();
1805 gen_op_movl_T1_lr();
1808 if (LK(ctx->opcode)) {
1809 gen_op_setlr(ctx->nip);
1812 /* No CR condition */
1823 if (type == BCOND_IM) {
1824 gen_goto_tb(ctx, 0, target);
1832 mask = 1 << (3 - (bi & 0x03));
1833 gen_op_load_crf_T0(bi >> 2);
1837 gen_op_test_ctr_true(mask);
1840 gen_op_test_ctrz_true(mask);
1845 gen_op_test_true(mask);
1851 gen_op_test_ctr_false(mask);
1854 gen_op_test_ctrz_false(mask);
1859 gen_op_test_false(mask);
1864 if (type == BCOND_IM) {
1865 int l1 = gen_new_label();
1867 gen_goto_tb(ctx, 0, target);
1869 gen_goto_tb(ctx, 1, ctx->nip);
1871 gen_op_btest_T1(ctx->nip);
1875 if (ctx->singlestep_enabled)
1878 ctx->exception = EXCP_BRANCH;
1881 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1883 gen_bcond(ctx, BCOND_IM);
1886 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
1888 gen_bcond(ctx, BCOND_CTR);
1891 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
1893 gen_bcond(ctx, BCOND_LR);
1896 /*** Condition register logical ***/
1897 #define GEN_CRLOGIC(op, opc) \
1898 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
1900 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
1901 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
1902 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
1903 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
1905 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
1906 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
1907 3 - (crbD(ctx->opcode) & 0x03)); \
1908 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
1912 GEN_CRLOGIC(and, 0x08);
1914 GEN_CRLOGIC(andc, 0x04);
1916 GEN_CRLOGIC(eqv, 0x09);
1918 GEN_CRLOGIC(nand, 0x07);
1920 GEN_CRLOGIC(nor, 0x01);
1922 GEN_CRLOGIC(or, 0x0E);
1924 GEN_CRLOGIC(orc, 0x0D);
1926 GEN_CRLOGIC(xor, 0x06);
1928 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
1930 gen_op_load_crf_T0(crfS(ctx->opcode));
1931 gen_op_store_T0_crf(crfD(ctx->opcode));
1934 /*** System linkage ***/
1935 /* rfi (supervisor only) */
1936 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
1938 #if defined(CONFIG_USER_ONLY)
1941 /* Restore CPU state */
1942 if (unlikely(!ctx->supervisor)) {
1952 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFFFFD, PPC_FLOW)
1954 #if defined(CONFIG_USER_ONLY)
1955 RET_EXCP(ctx, EXCP_SYSCALL_USER, 0);
1957 RET_EXCP(ctx, EXCP_SYSCALL, 0);
1963 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
1965 gen_op_load_gpr_T0(rA(ctx->opcode));
1966 gen_op_load_gpr_T1(rB(ctx->opcode));
1967 /* Update the nip since this might generate a trap exception */
1968 gen_op_update_nip(ctx->nip);
1969 gen_op_tw(TO(ctx->opcode));
1973 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1975 gen_op_load_gpr_T0(rA(ctx->opcode));
1976 gen_op_set_T1(SIMM(ctx->opcode));
1977 gen_op_tw(TO(ctx->opcode));
1980 /*** Processor control ***/
1982 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
1984 gen_op_load_xer_cr();
1985 gen_op_store_T0_crf(crfD(ctx->opcode));
1986 gen_op_clear_xer_cr();
1990 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
1992 #if 0 // XXX: to be tested
1995 if (likely(ctx->opcode & 0x00100000)) {
1996 crm = CRM(ctx->opcode);
1997 if (likely((crm ^ (crm - 1)) == 0)) {
1999 gen_op_load_cro(7 - crn);
2006 gen_op_store_T0_gpr(rD(ctx->opcode));
2010 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
2012 #if defined(CONFIG_USER_ONLY)
2015 if (unlikely(!ctx->supervisor)) {
2020 gen_op_store_T0_gpr(rD(ctx->opcode));
2025 #define SPR_NOACCESS ((void *)(-1))
2027 static void spr_noaccess (void *opaque, int sprn)
2029 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
2030 printf("ERROR: try to access SPR %d !\n", sprn);
2032 #define SPR_NOACCESS (&spr_noaccess)
2036 static inline void gen_op_mfspr (DisasContext *ctx)
2038 void (*read_cb)(void *opaque, int sprn);
2039 uint32_t sprn = SPR(ctx->opcode);
2041 #if !defined(CONFIG_USER_ONLY)
2042 if (ctx->supervisor)
2043 read_cb = ctx->spr_cb[sprn].oea_read;
2046 read_cb = ctx->spr_cb[sprn].uea_read;
2047 if (likely(read_cb != NULL)) {
2048 if (likely(read_cb != SPR_NOACCESS)) {
2049 (*read_cb)(ctx, sprn);
2050 gen_op_store_T0_gpr(rD(ctx->opcode));
2052 /* Privilege exception */
2054 fprintf(logfile, "Trying to read priviledged spr %d %03x\n",
2057 printf("Trying to read priviledged spr %d %03x\n", sprn, sprn);
2063 fprintf(logfile, "Trying to read invalid spr %d %03x\n",
2066 printf("Trying to read invalid spr %d %03x\n", sprn, sprn);
2067 RET_EXCP(ctx, EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_SPR);
2071 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
2077 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_TB)
2083 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
2087 gen_op_load_gpr_T0(rS(ctx->opcode));
2088 crm = CRM(ctx->opcode);
2089 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
2091 gen_op_srli_T0(crn * 4);
2092 gen_op_andi_T0(0xF);
2093 gen_op_store_cro(7 - crn);
2095 gen_op_store_cr(crm);
2100 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
2102 #if defined(CONFIG_USER_ONLY)
2105 if (unlikely(!ctx->supervisor)) {
2109 gen_op_update_nip((ctx)->nip);
2110 gen_op_load_gpr_T0(rS(ctx->opcode));
2112 /* Must stop the translation as machine state (may have) changed */
2118 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
2120 void (*write_cb)(void *opaque, int sprn);
2121 uint32_t sprn = SPR(ctx->opcode);
2123 #if !defined(CONFIG_USER_ONLY)
2124 if (ctx->supervisor)
2125 write_cb = ctx->spr_cb[sprn].oea_write;
2128 write_cb = ctx->spr_cb[sprn].uea_write;
2129 if (likely(write_cb != NULL)) {
2130 if (likely(write_cb != SPR_NOACCESS)) {
2131 gen_op_load_gpr_T0(rS(ctx->opcode));
2132 (*write_cb)(ctx, sprn);
2134 /* Privilege exception */
2136 fprintf(logfile, "Trying to write priviledged spr %d %03x\n",
2139 printf("Trying to write priviledged spr %d %03x\n", sprn, sprn);
2145 fprintf(logfile, "Trying to write invalid spr %d %03x\n",
2148 printf("Trying to write invalid spr %d %03x\n", sprn, sprn);
2149 RET_EXCP(ctx, EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_SPR);
2153 /*** Cache management ***/
2154 /* For now, all those will be implemented as nop:
2155 * this is valid, regarding the PowerPC specs...
2156 * We just have to flush tb while invalidating instruction cache lines...
2159 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03E00001, PPC_CACHE)
2161 gen_addr_reg_index(ctx);
2165 /* dcbi (Supervisor only) */
2166 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
2168 #if defined(CONFIG_USER_ONLY)
2171 if (unlikely(!ctx->supervisor)) {
2175 gen_addr_reg_index(ctx);
2176 /* XXX: specification says this should be treated as a store by the MMU */
2183 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
2185 /* XXX: specification say this is treated as a load by the MMU */
2186 gen_addr_reg_index(ctx);
2191 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x03E00001, PPC_CACHE)
2193 /* XXX: specification say this is treated as a load by the MMU
2194 * but does not generate any exception
2199 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE)
2201 /* XXX: specification say this is treated as a load by the MMU
2202 * but does not generate any exception
2207 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
2208 #if defined(CONFIG_USER_ONLY)
2209 static GenOpFunc *gen_op_dcbz[] = {
2214 static GenOpFunc *gen_op_dcbz[] = {
2217 &gen_op_dcbz_kernel,
2218 &gen_op_dcbz_kernel,
2222 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
2224 gen_addr_reg_index(ctx);
2226 gen_op_check_reservation();
2230 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE)
2232 /* NIP cannot be restored if the memory exception comes from an helper */
2233 gen_op_update_nip(ctx->nip - 4);
2234 gen_addr_reg_index(ctx);
2241 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_OPT)
2245 /*** Segment register manipulation ***/
2246 /* Supervisor only: */
2248 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
2250 #if defined(CONFIG_USER_ONLY)
2253 if (unlikely(!ctx->supervisor)) {
2257 gen_op_set_T1(SR(ctx->opcode));
2259 gen_op_store_T0_gpr(rD(ctx->opcode));
2264 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
2266 #if defined(CONFIG_USER_ONLY)
2269 if (unlikely(!ctx->supervisor)) {
2273 gen_op_load_gpr_T1(rB(ctx->opcode));
2276 gen_op_store_T0_gpr(rD(ctx->opcode));
2281 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
2283 #if defined(CONFIG_USER_ONLY)
2286 if (unlikely(!ctx->supervisor)) {
2290 gen_op_load_gpr_T0(rS(ctx->opcode));
2291 gen_op_set_T1(SR(ctx->opcode));
2298 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
2300 #if defined(CONFIG_USER_ONLY)
2303 if (unlikely(!ctx->supervisor)) {
2307 gen_op_load_gpr_T0(rS(ctx->opcode));
2308 gen_op_load_gpr_T1(rB(ctx->opcode));
2315 /*** Lookaside buffer management ***/
2316 /* Optional & supervisor only: */
2318 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
2320 #if defined(CONFIG_USER_ONLY)
2323 if (unlikely(!ctx->supervisor)) {
2325 fprintf(logfile, "%s: ! supervisor\n", __func__);
2335 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
2337 #if defined(CONFIG_USER_ONLY)
2340 if (unlikely(!ctx->supervisor)) {
2344 gen_op_load_gpr_T0(rB(ctx->opcode));
2351 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
2353 #if defined(CONFIG_USER_ONLY)
2356 if (unlikely(!ctx->supervisor)) {
2360 /* This has no effect: it should ensure that all previous
2361 * tlbie have completed
2367 /*** External control ***/
2369 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
2370 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
2371 #if defined(CONFIG_USER_ONLY)
2372 static GenOpFunc *gen_op_eciwx[] = {
2374 &gen_op_eciwx_le_raw,
2376 static GenOpFunc *gen_op_ecowx[] = {
2378 &gen_op_ecowx_le_raw,
2381 static GenOpFunc *gen_op_eciwx[] = {
2383 &gen_op_eciwx_le_user,
2384 &gen_op_eciwx_kernel,
2385 &gen_op_eciwx_le_kernel,
2387 static GenOpFunc *gen_op_ecowx[] = {
2389 &gen_op_ecowx_le_user,
2390 &gen_op_ecowx_kernel,
2391 &gen_op_ecowx_le_kernel,
2396 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
2398 /* Should check EAR[E] & alignment ! */
2399 gen_addr_reg_index(ctx);
2401 gen_op_store_T0_gpr(rD(ctx->opcode));
2405 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
2407 /* Should check EAR[E] & alignment ! */
2408 gen_addr_reg_index(ctx);
2409 gen_op_load_gpr_T1(rS(ctx->opcode));
2413 /* PowerPC 601 specific instructions */
2415 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
2417 gen_op_load_gpr_T0(rA(ctx->opcode));
2419 gen_op_store_T0_gpr(rD(ctx->opcode));
2420 if (unlikely(Rc(ctx->opcode) != 0))
2425 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
2427 gen_op_load_gpr_T0(rA(ctx->opcode));
2428 gen_op_POWER_abso();
2429 gen_op_store_T0_gpr(rD(ctx->opcode));
2430 if (unlikely(Rc(ctx->opcode) != 0))
2435 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR) /* 601 ? */
2437 gen_op_load_gpr_T0(rA(ctx->opcode));
2438 gen_op_POWER_clcs();
2439 gen_op_store_T0_gpr(rD(ctx->opcode));
2443 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
2445 gen_op_load_gpr_T0(rA(ctx->opcode));
2446 gen_op_load_gpr_T1(rB(ctx->opcode));
2448 gen_op_store_T0_gpr(rD(ctx->opcode));
2449 if (unlikely(Rc(ctx->opcode) != 0))
2454 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
2456 gen_op_load_gpr_T0(rA(ctx->opcode));
2457 gen_op_load_gpr_T1(rB(ctx->opcode));
2458 gen_op_POWER_divo();
2459 gen_op_store_T0_gpr(rD(ctx->opcode));
2460 if (unlikely(Rc(ctx->opcode) != 0))
2465 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
2467 gen_op_load_gpr_T0(rA(ctx->opcode));
2468 gen_op_load_gpr_T1(rB(ctx->opcode));
2469 gen_op_POWER_divs();
2470 gen_op_store_T0_gpr(rD(ctx->opcode));
2471 if (unlikely(Rc(ctx->opcode) != 0))
2475 /* divso - divso. */
2476 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
2478 gen_op_load_gpr_T0(rA(ctx->opcode));
2479 gen_op_load_gpr_T1(rB(ctx->opcode));
2480 gen_op_POWER_divso();
2481 gen_op_store_T0_gpr(rD(ctx->opcode));
2482 if (unlikely(Rc(ctx->opcode) != 0))
2487 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
2489 gen_op_load_gpr_T0(rA(ctx->opcode));
2490 gen_op_load_gpr_T1(rB(ctx->opcode));
2492 gen_op_store_T0_gpr(rD(ctx->opcode));
2493 if (unlikely(Rc(ctx->opcode) != 0))
2498 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
2500 gen_op_load_gpr_T0(rA(ctx->opcode));
2501 gen_op_load_gpr_T1(rB(ctx->opcode));
2502 gen_op_POWER_dozo();
2503 gen_op_store_T0_gpr(rD(ctx->opcode));
2504 if (unlikely(Rc(ctx->opcode) != 0))
2509 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
2511 gen_op_load_gpr_T0(rA(ctx->opcode));
2512 gen_op_set_T1(SIMM(ctx->opcode));
2514 gen_op_store_T0_gpr(rD(ctx->opcode));
2517 /* As lscbx load from memory byte after byte, it's always endian safe */
2518 #define op_POWER_lscbx(start, ra, rb) \
2519 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
2520 #if defined(CONFIG_USER_ONLY)
2521 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
2522 &gen_op_POWER_lscbx_raw,
2523 &gen_op_POWER_lscbx_raw,
2526 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
2527 &gen_op_POWER_lscbx_user,
2528 &gen_op_POWER_lscbx_user,
2529 &gen_op_POWER_lscbx_kernel,
2530 &gen_op_POWER_lscbx_kernel,
2534 /* lscbx - lscbx. */
2535 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
2537 int ra = rA(ctx->opcode);
2538 int rb = rB(ctx->opcode);
2540 gen_addr_reg_index(ctx);
2544 /* NIP cannot be restored if the memory exception comes from an helper */
2545 gen_op_update_nip(ctx->nip - 4);
2546 gen_op_load_xer_bc();
2547 gen_op_load_xer_cmp();
2548 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
2549 gen_op_store_xer_bc();
2550 if (unlikely(Rc(ctx->opcode) != 0))
2554 /* maskg - maskg. */
2555 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
2557 gen_op_load_gpr_T0(rS(ctx->opcode));
2558 gen_op_load_gpr_T1(rB(ctx->opcode));
2559 gen_op_POWER_maskg();
2560 gen_op_store_T0_gpr(rA(ctx->opcode));
2561 if (unlikely(Rc(ctx->opcode) != 0))
2565 /* maskir - maskir. */
2566 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
2568 gen_op_load_gpr_T0(rA(ctx->opcode));
2569 gen_op_load_gpr_T1(rS(ctx->opcode));
2570 gen_op_load_gpr_T2(rB(ctx->opcode));
2571 gen_op_POWER_maskir();
2572 gen_op_store_T0_gpr(rA(ctx->opcode));
2573 if (unlikely(Rc(ctx->opcode) != 0))
2578 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
2580 gen_op_load_gpr_T0(rA(ctx->opcode));
2581 gen_op_load_gpr_T1(rB(ctx->opcode));
2583 gen_op_store_T0_gpr(rD(ctx->opcode));
2584 if (unlikely(Rc(ctx->opcode) != 0))
2589 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
2591 gen_op_load_gpr_T0(rA(ctx->opcode));
2592 gen_op_load_gpr_T1(rB(ctx->opcode));
2593 gen_op_POWER_mulo();
2594 gen_op_store_T0_gpr(rD(ctx->opcode));
2595 if (unlikely(Rc(ctx->opcode) != 0))
2600 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
2602 gen_op_load_gpr_T0(rA(ctx->opcode));
2603 gen_op_POWER_nabs();
2604 gen_op_store_T0_gpr(rD(ctx->opcode));
2605 if (unlikely(Rc(ctx->opcode) != 0))
2609 /* nabso - nabso. */
2610 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
2612 gen_op_load_gpr_T0(rA(ctx->opcode));
2613 gen_op_POWER_nabso();
2614 gen_op_store_T0_gpr(rD(ctx->opcode));
2615 if (unlikely(Rc(ctx->opcode) != 0))
2620 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
2624 mb = MB(ctx->opcode);
2625 me = ME(ctx->opcode);
2626 gen_op_load_gpr_T0(rS(ctx->opcode));
2627 gen_op_load_gpr_T1(rA(ctx->opcode));
2628 gen_op_load_gpr_T2(rB(ctx->opcode));
2629 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
2630 gen_op_store_T0_gpr(rA(ctx->opcode));
2631 if (unlikely(Rc(ctx->opcode) != 0))
2636 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
2638 gen_op_load_gpr_T0(rS(ctx->opcode));
2639 gen_op_load_gpr_T1(rA(ctx->opcode));
2640 gen_op_load_gpr_T2(rB(ctx->opcode));
2641 gen_op_POWER_rrib();
2642 gen_op_store_T0_gpr(rA(ctx->opcode));
2643 if (unlikely(Rc(ctx->opcode) != 0))
2648 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
2650 gen_op_load_gpr_T0(rS(ctx->opcode));
2651 gen_op_load_gpr_T1(rB(ctx->opcode));
2653 gen_op_store_T0_gpr(rA(ctx->opcode));
2654 if (unlikely(Rc(ctx->opcode) != 0))
2659 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
2661 gen_op_load_gpr_T0(rS(ctx->opcode));
2662 gen_op_load_gpr_T1(rB(ctx->opcode));
2663 gen_op_POWER_sleq();
2664 gen_op_store_T0_gpr(rA(ctx->opcode));
2665 if (unlikely(Rc(ctx->opcode) != 0))
2670 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
2672 gen_op_load_gpr_T0(rS(ctx->opcode));
2673 gen_op_set_T1(SH(ctx->opcode));
2675 gen_op_store_T0_gpr(rA(ctx->opcode));
2676 if (unlikely(Rc(ctx->opcode) != 0))
2680 /* slliq - slliq. */
2681 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
2683 gen_op_load_gpr_T0(rS(ctx->opcode));
2684 gen_op_set_T1(SH(ctx->opcode));
2685 gen_op_POWER_sleq();
2686 gen_op_store_T0_gpr(rA(ctx->opcode));
2687 if (unlikely(Rc(ctx->opcode) != 0))
2692 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
2694 gen_op_load_gpr_T0(rS(ctx->opcode));
2695 gen_op_load_gpr_T1(rB(ctx->opcode));
2696 gen_op_POWER_sllq();
2697 gen_op_store_T0_gpr(rA(ctx->opcode));
2698 if (unlikely(Rc(ctx->opcode) != 0))
2703 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
2705 gen_op_load_gpr_T0(rS(ctx->opcode));
2706 gen_op_load_gpr_T1(rB(ctx->opcode));
2708 gen_op_store_T0_gpr(rA(ctx->opcode));
2709 if (unlikely(Rc(ctx->opcode) != 0))
2714 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
2716 gen_op_load_gpr_T0(rS(ctx->opcode));
2717 gen_op_set_T1(SH(ctx->opcode));
2718 gen_op_POWER_sraq();
2719 gen_op_store_T0_gpr(rA(ctx->opcode));
2720 if (unlikely(Rc(ctx->opcode) != 0))
2725 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
2727 gen_op_load_gpr_T0(rS(ctx->opcode));
2728 gen_op_load_gpr_T1(rB(ctx->opcode));
2729 gen_op_POWER_sraq();
2730 gen_op_store_T0_gpr(rA(ctx->opcode));
2731 if (unlikely(Rc(ctx->opcode) != 0))
2736 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
2738 gen_op_load_gpr_T0(rS(ctx->opcode));
2739 gen_op_load_gpr_T1(rB(ctx->opcode));
2741 gen_op_store_T0_gpr(rA(ctx->opcode));
2742 if (unlikely(Rc(ctx->opcode) != 0))
2747 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
2749 gen_op_load_gpr_T0(rS(ctx->opcode));
2750 gen_op_load_gpr_T1(rB(ctx->opcode));
2751 gen_op_POWER_srea();
2752 gen_op_store_T0_gpr(rA(ctx->opcode));
2753 if (unlikely(Rc(ctx->opcode) != 0))
2758 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
2760 gen_op_load_gpr_T0(rS(ctx->opcode));
2761 gen_op_load_gpr_T1(rB(ctx->opcode));
2762 gen_op_POWER_sreq();
2763 gen_op_store_T0_gpr(rA(ctx->opcode));
2764 if (unlikely(Rc(ctx->opcode) != 0))
2769 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
2771 gen_op_load_gpr_T0(rS(ctx->opcode));
2772 gen_op_set_T1(SH(ctx->opcode));
2774 gen_op_store_T0_gpr(rA(ctx->opcode));
2775 if (unlikely(Rc(ctx->opcode) != 0))
2780 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
2782 gen_op_load_gpr_T0(rS(ctx->opcode));
2783 gen_op_load_gpr_T1(rB(ctx->opcode));
2784 gen_op_set_T1(SH(ctx->opcode));
2785 gen_op_POWER_srlq();
2786 gen_op_store_T0_gpr(rA(ctx->opcode));
2787 if (unlikely(Rc(ctx->opcode) != 0))
2792 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
2794 gen_op_load_gpr_T0(rS(ctx->opcode));
2795 gen_op_load_gpr_T1(rB(ctx->opcode));
2796 gen_op_POWER_srlq();
2797 gen_op_store_T0_gpr(rA(ctx->opcode));
2798 if (unlikely(Rc(ctx->opcode) != 0))
2803 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
2805 gen_op_load_gpr_T0(rS(ctx->opcode));
2806 gen_op_load_gpr_T1(rB(ctx->opcode));
2808 gen_op_store_T0_gpr(rA(ctx->opcode));
2809 if (unlikely(Rc(ctx->opcode) != 0))
2813 /* PowerPC 602 specific instructions */
2815 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
2822 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
2829 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
2831 #if defined(CONFIG_USER_ONLY)
2834 if (unlikely(!ctx->supervisor)) {
2838 gen_op_load_gpr_T0(rA(ctx->opcode));
2840 gen_op_store_T0_gpr(rD(ctx->opcode));
2844 /* 602 - 603 - G2 TLB management */
2846 GEN_HANDLER(tlbld, 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
2848 #if defined(CONFIG_USER_ONLY)
2851 if (unlikely(!ctx->supervisor)) {
2855 gen_op_load_gpr_T0(rB(ctx->opcode));
2862 GEN_HANDLER(tlbli, 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
2864 #if defined(CONFIG_USER_ONLY)
2867 if (unlikely(!ctx->supervisor)) {
2871 gen_op_load_gpr_T0(rB(ctx->opcode));
2877 /* POWER instructions not in PowerPC 601 */
2879 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
2881 /* Cache line flush: implemented as no-op */
2885 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
2887 /* Cache line invalidate: priviledged and treated as no-op */
2888 #if defined(CONFIG_USER_ONLY)
2891 if (unlikely(!ctx->supervisor)) {
2899 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
2901 /* Data cache line store: treated as no-op */
2904 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
2906 #if defined(CONFIG_USER_ONLY)
2909 if (unlikely(!ctx->supervisor)) {
2913 int ra = rA(ctx->opcode);
2914 int rd = rD(ctx->opcode);
2916 gen_addr_reg_index(ctx);
2917 gen_op_POWER_mfsri();
2918 gen_op_store_T0_gpr(rd);
2919 if (ra != 0 && ra != rd)
2920 gen_op_store_T1_gpr(ra);
2924 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
2926 #if defined(CONFIG_USER_ONLY)
2929 if (unlikely(!ctx->supervisor)) {
2933 gen_addr_reg_index(ctx);
2935 gen_op_store_T0_gpr(rD(ctx->opcode));
2939 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
2941 #if defined(CONFIG_USER_ONLY)
2944 if (unlikely(!ctx->supervisor)) {
2948 gen_op_POWER_rfsvc();
2953 /* svc is not implemented for now */
2955 /* POWER2 specific instructions */
2956 /* Quad manipulation (load/store two floats at a time) */
2957 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
2958 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
2959 #if defined(CONFIG_USER_ONLY)
2960 static GenOpFunc *gen_op_POWER2_lfq[] = {
2961 &gen_op_POWER2_lfq_le_raw,
2962 &gen_op_POWER2_lfq_raw,
2964 static GenOpFunc *gen_op_POWER2_stfq[] = {
2965 &gen_op_POWER2_stfq_le_raw,
2966 &gen_op_POWER2_stfq_raw,
2969 static GenOpFunc *gen_op_POWER2_lfq[] = {
2970 &gen_op_POWER2_lfq_le_user,
2971 &gen_op_POWER2_lfq_user,
2972 &gen_op_POWER2_lfq_le_kernel,
2973 &gen_op_POWER2_lfq_kernel,
2975 static GenOpFunc *gen_op_POWER2_stfq[] = {
2976 &gen_op_POWER2_stfq_le_user,
2977 &gen_op_POWER2_stfq_user,
2978 &gen_op_POWER2_stfq_le_kernel,
2979 &gen_op_POWER2_stfq_kernel,
2984 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
2986 /* NIP cannot be restored if the memory exception comes from an helper */
2987 gen_op_update_nip(ctx->nip - 4);
2988 gen_addr_imm_index(ctx);
2990 gen_op_store_FT0_fpr(rD(ctx->opcode));
2991 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
2995 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
2997 int ra = rA(ctx->opcode);
2999 /* NIP cannot be restored if the memory exception comes from an helper */
3000 gen_op_update_nip(ctx->nip - 4);
3001 gen_addr_imm_index(ctx);
3003 gen_op_store_FT0_fpr(rD(ctx->opcode));
3004 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
3006 gen_op_store_T0_gpr(ra);
3010 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
3012 int ra = rA(ctx->opcode);
3014 /* NIP cannot be restored if the memory exception comes from an helper */
3015 gen_op_update_nip(ctx->nip - 4);
3016 gen_addr_reg_index(ctx);
3018 gen_op_store_FT0_fpr(rD(ctx->opcode));
3019 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
3021 gen_op_store_T0_gpr(ra);
3025 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
3027 /* NIP cannot be restored if the memory exception comes from an helper */
3028 gen_op_update_nip(ctx->nip - 4);
3029 gen_addr_reg_index(ctx);
3031 gen_op_store_FT0_fpr(rD(ctx->opcode));
3032 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
3036 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
3038 /* NIP cannot be restored if the memory exception comes from an helper */
3039 gen_op_update_nip(ctx->nip - 4);
3040 gen_addr_imm_index(ctx);
3041 gen_op_load_fpr_FT0(rS(ctx->opcode));
3042 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
3047 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
3049 int ra = rA(ctx->opcode);
3051 /* NIP cannot be restored if the memory exception comes from an helper */
3052 gen_op_update_nip(ctx->nip - 4);
3053 gen_addr_imm_index(ctx);
3054 gen_op_load_fpr_FT0(rS(ctx->opcode));
3055 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
3058 gen_op_store_T0_gpr(ra);
3062 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
3064 int ra = rA(ctx->opcode);
3066 /* NIP cannot be restored if the memory exception comes from an helper */
3067 gen_op_update_nip(ctx->nip - 4);
3068 gen_addr_reg_index(ctx);
3069 gen_op_load_fpr_FT0(rS(ctx->opcode));
3070 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
3073 gen_op_store_T0_gpr(ra);
3077 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
3079 /* NIP cannot be restored if the memory exception comes from an helper */
3080 gen_op_update_nip(ctx->nip - 4);
3081 gen_addr_reg_index(ctx);
3082 gen_op_load_fpr_FT0(rS(ctx->opcode));
3083 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
3087 /* BookE specific instructions */
3088 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_BOOKE)
3094 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE)
3096 #if defined(CONFIG_USER_ONLY)
3099 if (unlikely(!ctx->supervisor)) {
3103 gen_addr_reg_index(ctx);
3104 /* Use the same micro-ops as for tlbie */
3110 /* All 405 MAC instructions are translated here */
3111 static inline void gen_405_mulladd_insn (DisasContext *ctx, int opc2, int opc3,
3112 int ra, int rb, int rt, int Rc)
3114 gen_op_load_gpr_T0(ra);
3115 gen_op_load_gpr_T1(rb);
3116 switch (opc3 & 0x0D) {
3118 /* macchw - macchw. - macchwo - macchwo. */
3119 /* macchws - macchws. - macchwso - macchwso. */
3120 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
3121 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
3122 /* mulchw - mulchw. */
3123 gen_op_405_mulchw();
3126 /* macchwu - macchwu. - macchwuo - macchwuo. */
3127 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
3128 /* mulchwu - mulchwu. */
3129 gen_op_405_mulchwu();
3132 /* machhw - machhw. - machhwo - machhwo. */
3133 /* machhws - machhws. - machhwso - machhwso. */
3134 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
3135 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
3136 /* mulhhw - mulhhw. */
3137 gen_op_405_mulhhw();
3140 /* machhwu - machhwu. - machhwuo - machhwuo. */
3141 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
3142 /* mulhhwu - mulhhwu. */
3143 gen_op_405_mulhhwu();
3146 /* maclhw - maclhw. - maclhwo - maclhwo. */
3147 /* maclhws - maclhws. - maclhwso - maclhwso. */
3148 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
3149 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
3150 /* mullhw - mullhw. */
3151 gen_op_405_mullhw();
3154 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
3155 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
3156 /* mullhwu - mullhwu. */
3157 gen_op_405_mullhwu();
3161 /* nmultiply-and-accumulate (0x0E) */
3165 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
3166 gen_op_load_gpr_T2(rt);
3167 gen_op_move_T1_T0();
3168 gen_op_405_add_T0_T2();
3171 /* Check overflow */
3173 gen_op_405_check_ov();
3175 gen_op_405_check_ovu();
3180 gen_op_405_check_sat();
3182 gen_op_405_check_satu();
3184 gen_op_store_T0_gpr(rt);
3185 if (unlikely(Rc) != 0) {
3191 #define GEN_MAC_HANDLER(name, opc2, opc3) \
3192 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
3194 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
3195 rD(ctx->opcode), Rc(ctx->opcode)); \
3198 /* macchw - macchw. */
3199 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
3200 /* macchwo - macchwo. */
3201 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
3202 /* macchws - macchws. */
3203 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
3204 /* macchwso - macchwso. */
3205 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
3206 /* macchwsu - macchwsu. */
3207 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
3208 /* macchwsuo - macchwsuo. */
3209 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
3210 /* macchwu - macchwu. */
3211 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
3212 /* macchwuo - macchwuo. */
3213 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
3214 /* machhw - machhw. */
3215 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
3216 /* machhwo - machhwo. */
3217 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
3218 /* machhws - machhws. */
3219 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
3220 /* machhwso - machhwso. */
3221 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
3222 /* machhwsu - machhwsu. */
3223 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
3224 /* machhwsuo - machhwsuo. */
3225 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
3226 /* machhwu - machhwu. */
3227 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
3228 /* machhwuo - machhwuo. */
3229 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
3230 /* maclhw - maclhw. */
3231 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
3232 /* maclhwo - maclhwo. */
3233 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
3234 /* maclhws - maclhws. */
3235 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
3236 /* maclhwso - maclhwso. */
3237 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
3238 /* maclhwu - maclhwu. */
3239 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
3240 /* maclhwuo - maclhwuo. */
3241 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
3242 /* maclhwsu - maclhwsu. */
3243 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
3244 /* maclhwsuo - maclhwsuo. */
3245 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
3246 /* nmacchw - nmacchw. */
3247 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
3248 /* nmacchwo - nmacchwo. */
3249 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
3250 /* nmacchws - nmacchws. */
3251 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
3252 /* nmacchwso - nmacchwso. */
3253 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
3254 /* nmachhw - nmachhw. */
3255 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
3256 /* nmachhwo - nmachhwo. */
3257 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
3258 /* nmachhws - nmachhws. */
3259 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
3260 /* nmachhwso - nmachhwso. */
3261 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
3262 /* nmaclhw - nmaclhw. */
3263 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
3264 /* nmaclhwo - nmaclhwo. */
3265 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
3266 /* nmaclhws - nmaclhws. */
3267 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
3268 /* nmaclhwso - nmaclhwso. */
3269 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
3271 /* mulchw - mulchw. */
3272 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
3273 /* mulchwu - mulchwu. */
3274 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
3275 /* mulhhw - mulhhw. */
3276 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
3277 /* mulhhwu - mulhhwu. */
3278 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
3279 /* mullhw - mullhw. */
3280 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
3281 /* mullhwu - mullhwu. */
3282 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
3285 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_EMB_COMMON)
3287 #if defined(CONFIG_USER_ONLY)
3290 uint32_t dcrn = SPR(ctx->opcode);
3292 if (unlikely(!ctx->supervisor)) {
3296 gen_op_4xx_load_dcr(dcrn);
3297 gen_op_store_T0_gpr(rD(ctx->opcode));
3302 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_EMB_COMMON)
3304 #if defined(CONFIG_USER_ONLY)
3307 uint32_t dcrn = SPR(ctx->opcode);
3309 if (unlikely(!ctx->supervisor)) {
3313 gen_op_load_gpr_T0(rS(ctx->opcode));
3314 gen_op_4xx_store_dcr(dcrn);
3319 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
3321 #if defined(CONFIG_USER_ONLY)
3324 if (unlikely(!ctx->supervisor)) {
3328 /* interpreted as no-op */
3333 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
3335 #if defined(CONFIG_USER_ONLY)
3338 if (unlikely(!ctx->supervisor)) {
3342 gen_addr_reg_index(ctx);
3344 gen_op_store_T0_gpr(rD(ctx->opcode));
3349 GEN_HANDLER(icbt_40x, 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_SPEC)
3351 /* interpreted as no-op */
3352 /* XXX: specification say this is treated as a load by the MMU
3353 * but does not generate any exception
3358 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
3360 #if defined(CONFIG_USER_ONLY)
3363 if (unlikely(!ctx->supervisor)) {
3367 /* interpreted as no-op */
3372 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
3374 #if defined(CONFIG_USER_ONLY)
3377 if (unlikely(!ctx->supervisor)) {
3381 /* interpreted as no-op */
3385 /* rfci (supervisor only) */
3386 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_EMB_COMMON)
3388 #if defined(CONFIG_USER_ONLY)
3391 if (unlikely(!ctx->supervisor)) {
3395 /* Restore CPU state */
3402 GEN_HANDLER(tlbre, 0x1F, 0x12, 0x1D, 0x00000001, PPC_EMB_COMMON)
3404 #if defined(CONFIG_USER_ONLY)
3407 if (unlikely(!ctx->supervisor)) {
3411 switch (rB(ctx->opcode)) {
3413 gen_op_load_gpr_T0(rA(ctx->opcode));
3414 gen_op_4xx_tlbre_hi();
3415 gen_op_store_T0_gpr(rD(ctx->opcode));
3418 gen_op_load_gpr_T0(rA(ctx->opcode));
3419 gen_op_4xx_tlbre_lo();
3420 gen_op_store_T0_gpr(rD(ctx->opcode));
3429 /* tlbsx - tlbsx. */ /* Named tlbs in BookE */
3430 GEN_HANDLER(tlbsx, 0x1F, 0x12, 0x1C, 0x00000000, PPC_EMB_COMMON)
3432 #if defined(CONFIG_USER_ONLY)
3435 if (unlikely(!ctx->supervisor)) {
3439 gen_addr_reg_index(ctx);
3440 if (Rc(ctx->opcode))
3441 gen_op_4xx_tlbsx_();
3444 gen_op_store_T0_gpr(rD(ctx->opcode));
3449 GEN_HANDLER(tlbwe, 0x1F, 0x12, 0x1E, 0x00000001, PPC_EMB_COMMON)
3451 #if defined(CONFIG_USER_ONLY)
3454 if (unlikely(!ctx->supervisor)) {
3458 switch (rB(ctx->opcode)) {
3460 gen_op_load_gpr_T0(rA(ctx->opcode));
3461 gen_op_load_gpr_T1(rS(ctx->opcode));
3462 gen_op_4xx_tlbwe_hi();
3465 gen_op_load_gpr_T0(rA(ctx->opcode));
3466 gen_op_load_gpr_T1(rS(ctx->opcode));
3467 gen_op_4xx_tlbwe_lo();
3477 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_EMB_COMMON)
3479 #if defined(CONFIG_USER_ONLY)
3482 if (unlikely(!ctx->supervisor)) {
3486 gen_op_load_gpr_T0(rD(ctx->opcode));
3488 RET_EXCP(ctx, EXCP_MTMSR, 0);
3493 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_EMB_COMMON)
3495 #if defined(CONFIG_USER_ONLY)
3498 if (unlikely(!ctx->supervisor)) {
3502 gen_op_set_T0(ctx->opcode & 0x00010000);
3504 RET_EXCP(ctx, EXCP_MTMSR, 0);
3508 /* PPC 440 specific instructions */
3510 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
3512 gen_op_load_gpr_T0(rS(ctx->opcode));
3513 gen_op_load_gpr_T1(rB(ctx->opcode));
3515 gen_op_store_T0_gpr(rA(ctx->opcode));
3516 gen_op_store_xer_bc();
3517 if (Rc(ctx->opcode)) {
3518 gen_op_440_dlmzb_update_Rc();
3519 gen_op_store_T0_crf(0);
3523 /* mbar replaces eieio on 440 */
3524 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
3526 /* interpreted as no-op */
3529 /* msync replaces sync on 440 */
3530 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_BOOKE)
3532 /* interpreted as no-op */
3536 GEN_HANDLER(icbt_440, 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
3538 /* interpreted as no-op */
3539 /* XXX: specification say this is treated as a load by the MMU
3540 * but does not generate any exception
3544 /* End opcode list */
3545 GEN_OPCODE_MARK(end);
3547 #include "translate_init.c"
3549 /*****************************************************************************/
3550 /* Misc PowerPC helpers */
3551 static inline uint32_t load_xer (CPUState *env)
3553 return (xer_so << XER_SO) |
3554 (xer_ov << XER_OV) |
3555 (xer_ca << XER_CA) |
3556 (xer_bc << XER_BC) |
3557 (xer_cmp << XER_CMP);
3560 void cpu_dump_state(CPUState *env, FILE *f,
3561 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
3564 #if defined(TARGET_PPC64) || 1
3576 cpu_fprintf(f, "NIP " REGX " LR " REGX " CTR " REGX "\n",
3577 env->nip, env->lr, env->ctr);
3578 cpu_fprintf(f, "MSR " REGX FILL " XER %08x TB %08x %08x "
3579 #if !defined(CONFIG_USER_ONLY)
3583 do_load_msr(env), load_xer(env), cpu_ppc_load_tbu(env),
3584 cpu_ppc_load_tbl(env)
3585 #if !defined(CONFIG_USER_ONLY)
3586 , cpu_ppc_load_decr(env)
3589 for (i = 0; i < 32; i++) {
3590 if ((i & (RGPL - 1)) == 0)
3591 cpu_fprintf(f, "GPR%02d", i);
3592 cpu_fprintf(f, " " REGX, env->gpr[i]);
3593 if ((i & (RGPL - 1)) == (RGPL - 1))
3594 cpu_fprintf(f, "\n");
3596 cpu_fprintf(f, "CR ");
3597 for (i = 0; i < 8; i++)
3598 cpu_fprintf(f, "%01x", env->crf[i]);
3599 cpu_fprintf(f, " [");
3600 for (i = 0; i < 8; i++) {
3602 if (env->crf[i] & 0x08)
3604 else if (env->crf[i] & 0x04)
3606 else if (env->crf[i] & 0x02)
3608 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
3610 cpu_fprintf(f, " ] " FILL "RES " REGX "\n", env->reserve);
3611 for (i = 0; i < 32; i++) {
3612 if ((i & (RFPL - 1)) == 0)
3613 cpu_fprintf(f, "FPR%02d", i);
3614 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3615 if ((i & (RFPL - 1)) == (RFPL - 1))
3616 cpu_fprintf(f, "\n");
3618 cpu_fprintf(f, "SRR0 " REGX " SRR1 " REGX " " FILL FILL FILL
3620 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
3628 void cpu_dump_statistics (CPUState *env, FILE*f,
3629 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
3632 #if defined(DO_PPC_STATISTICS)
3633 opc_handler_t **t1, **t2, **t3, *handler;
3637 for (op1 = 0; op1 < 64; op1++) {
3639 if (is_indirect_opcode(handler)) {
3640 t2 = ind_table(handler);
3641 for (op2 = 0; op2 < 32; op2++) {
3643 if (is_indirect_opcode(handler)) {
3644 t3 = ind_table(handler);
3645 for (op3 = 0; op3 < 32; op3++) {
3647 if (handler->count == 0)
3649 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
3651 op1, op2, op3, op1, (op3 << 5) | op2,
3653 handler->count, handler->count);
3656 if (handler->count == 0)
3658 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
3660 op1, op2, op1, op2, handler->oname,
3661 handler->count, handler->count);
3665 if (handler->count == 0)
3667 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
3668 op1, op1, handler->oname,
3669 handler->count, handler->count);
3675 /*****************************************************************************/
3676 int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3679 DisasContext ctx, *ctxp = &ctx;
3680 opc_handler_t **table, *handler;
3681 target_ulong pc_start;
3682 uint16_t *gen_opc_end;
3686 gen_opc_ptr = gen_opc_buf;
3687 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
3688 gen_opparam_ptr = gen_opparam_buf;
3692 ctx.exception = EXCP_NONE;
3693 ctx.spr_cb = env->spr_cb;
3694 #if defined(CONFIG_USER_ONLY)
3695 ctx.mem_idx = msr_le;
3697 ctx.supervisor = 1 - msr_pr;
3698 ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le;
3700 ctx.fpu_enabled = msr_fp;
3701 ctx.singlestep_enabled = env->singlestep_enabled;
3702 #if defined (DO_SINGLE_STEP) && 0
3703 /* Single step trace mode */
3706 /* Set env in case of segfault during code fetch */
3707 while (ctx.exception == EXCP_NONE && gen_opc_ptr < gen_opc_end) {
3708 if (unlikely(env->nb_breakpoints > 0)) {
3709 for (j = 0; j < env->nb_breakpoints; j++) {
3710 if (env->breakpoints[j] == ctx.nip) {
3711 gen_op_update_nip(ctx.nip);
3717 if (unlikely(search_pc)) {
3718 j = gen_opc_ptr - gen_opc_buf;
3722 gen_opc_instr_start[lj++] = 0;
3723 gen_opc_pc[lj] = ctx.nip;
3724 gen_opc_instr_start[lj] = 1;
3727 #if defined PPC_DEBUG_DISAS
3728 if (loglevel & CPU_LOG_TB_IN_ASM) {
3729 fprintf(logfile, "----------------\n");
3730 fprintf(logfile, "nip=%08x super=%d ir=%d\n",
3731 ctx.nip, 1 - msr_pr, msr_ir);
3734 ctx.opcode = ldl_code(ctx.nip);
3736 ctx.opcode = ((ctx.opcode & 0xFF000000) >> 24) |
3737 ((ctx.opcode & 0x00FF0000) >> 8) |
3738 ((ctx.opcode & 0x0000FF00) << 8) |
3739 ((ctx.opcode & 0x000000FF) << 24);
3741 #if defined PPC_DEBUG_DISAS
3742 if (loglevel & CPU_LOG_TB_IN_ASM) {
3743 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
3744 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
3745 opc3(ctx.opcode), msr_le ? "little" : "big");
3749 table = env->opcodes;
3750 handler = table[opc1(ctx.opcode)];
3751 if (is_indirect_opcode(handler)) {
3752 table = ind_table(handler);
3753 handler = table[opc2(ctx.opcode)];
3754 if (is_indirect_opcode(handler)) {
3755 table = ind_table(handler);
3756 handler = table[opc3(ctx.opcode)];
3759 /* Is opcode *REALLY* valid ? */
3760 if (unlikely(handler->handler == &gen_invalid)) {
3762 fprintf(logfile, "invalid/unsupported opcode: "
3763 "%02x - %02x - %02x (%08x) 0x%08x %d\n",
3764 opc1(ctx.opcode), opc2(ctx.opcode),
3765 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
3767 printf("invalid/unsupported opcode: "
3768 "%02x - %02x - %02x (%08x) 0x%08x %d\n",
3769 opc1(ctx.opcode), opc2(ctx.opcode),
3770 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
3773 if (unlikely((ctx.opcode & handler->inval) != 0)) {
3775 fprintf(logfile, "invalid bits: %08x for opcode: "
3776 "%02x -%02x - %02x (0x%08x) (0x%08x)\n",
3777 ctx.opcode & handler->inval, opc1(ctx.opcode),
3778 opc2(ctx.opcode), opc3(ctx.opcode),
3779 ctx.opcode, ctx.nip - 4);
3781 printf("invalid bits: %08x for opcode: "
3782 "%02x -%02x - %02x (0x%08x) (0x%08x)\n",
3783 ctx.opcode & handler->inval, opc1(ctx.opcode),
3784 opc2(ctx.opcode), opc3(ctx.opcode),
3785 ctx.opcode, ctx.nip - 4);
3791 (*(handler->handler))(&ctx);
3792 #if defined(DO_PPC_STATISTICS)
3795 /* Check trace mode exceptions */
3796 if (unlikely((msr_be && ctx.exception == EXCP_BRANCH) ||
3797 /* Check in single step trace mode
3798 * we need to stop except if:
3799 * - rfi, trap or syscall
3800 * - first instruction of an exception handler
3802 (msr_se && (ctx.nip < 0x100 ||
3804 (ctx.nip & 0xFC) != 0x04) &&
3805 ctx.exception != EXCP_SYSCALL &&
3806 ctx.exception != EXCP_SYSCALL_USER &&
3807 ctx.exception != EXCP_TRAP))) {
3808 RET_EXCP(ctxp, EXCP_TRACE, 0);
3810 /* if we reach a page boundary or are single stepping, stop
3813 if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
3814 (env->singlestep_enabled))) {
3817 #if defined (DO_SINGLE_STEP)
3821 if (ctx.exception == EXCP_NONE) {
3822 gen_goto_tb(&ctx, 0, ctx.nip);
3823 } else if (ctx.exception != EXCP_BRANCH) {
3825 /* Generate the return instruction */
3828 *gen_opc_ptr = INDEX_op_end;
3829 if (unlikely(search_pc)) {
3830 j = gen_opc_ptr - gen_opc_buf;
3833 gen_opc_instr_start[lj++] = 0;
3836 tb->size = ctx.nip - pc_start;
3839 if (loglevel & CPU_LOG_TB_CPU) {
3840 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
3841 cpu_dump_state(env, logfile, fprintf, 0);
3843 if (loglevel & CPU_LOG_TB_IN_ASM) {
3846 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
3847 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
3848 fprintf(logfile, "\n");
3850 if (loglevel & CPU_LOG_TB_OP) {
3851 fprintf(logfile, "OP:\n");
3852 dump_ops(gen_opc_buf, gen_opparam_buf);
3853 fprintf(logfile, "\n");
3859 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
3861 return gen_intermediate_code_internal(env, tb, 0);
3864 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
3866 return gen_intermediate_code_internal(env, tb, 1);