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
30 //#define DO_SINGLE_STEP
31 //#define PPC_DEBUG_DISAS
34 #define DEF(s, n, copy_size) INDEX_op_ ## s,
40 static uint16_t *gen_opc_ptr
;
41 static uint32_t *gen_opparam_ptr
;
45 #define GEN8(func, NAME) \
46 static GenOpFunc *NAME ## _table [8] = { \
47 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
48 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
50 static inline void func(int n) \
52 NAME ## _table[n](); \
55 #define GEN16(func, NAME) \
56 static GenOpFunc *NAME ## _table [16] = { \
57 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
58 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
59 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
60 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
62 static inline void func(int n) \
64 NAME ## _table[n](); \
67 #define GEN32(func, NAME) \
68 static GenOpFunc *NAME ## _table [32] = { \
69 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
70 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
71 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
72 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
73 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
74 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
75 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
76 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
78 static inline void func(int n) \
80 NAME ## _table[n](); \
83 /* Condition register moves */
84 GEN8(gen_op_load_crf_T0
, gen_op_load_crf_T0_crf
);
85 GEN8(gen_op_load_crf_T1
, gen_op_load_crf_T1_crf
);
86 GEN8(gen_op_store_T0_crf
, gen_op_store_T0_crf_crf
);
87 GEN8(gen_op_store_T1_crf
, gen_op_store_T1_crf_crf
);
89 /* Floating point condition and status register moves */
90 GEN8(gen_op_load_fpscr_T0
, gen_op_load_fpscr_T0_fpscr
);
91 GEN8(gen_op_store_T0_fpscr
, gen_op_store_T0_fpscr_fpscr
);
92 GEN8(gen_op_clear_fpscr
, gen_op_clear_fpscr_fpscr
);
93 static GenOpFunc1
*gen_op_store_T0_fpscri_fpscr_table
[8] = {
94 &gen_op_store_T0_fpscri_fpscr0
,
95 &gen_op_store_T0_fpscri_fpscr1
,
96 &gen_op_store_T0_fpscri_fpscr2
,
97 &gen_op_store_T0_fpscri_fpscr3
,
98 &gen_op_store_T0_fpscri_fpscr4
,
99 &gen_op_store_T0_fpscri_fpscr5
,
100 &gen_op_store_T0_fpscri_fpscr6
,
101 &gen_op_store_T0_fpscri_fpscr7
,
103 static inline void gen_op_store_T0_fpscri(int n
, uint8_t param
)
105 (*gen_op_store_T0_fpscri_fpscr_table
[n
])(param
);
108 /* Segment register moves */
109 GEN16(gen_op_load_sr
, gen_op_load_sr
);
110 GEN16(gen_op_store_sr
, gen_op_store_sr
);
112 /* General purpose registers moves */
113 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
114 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
115 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
117 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
118 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
119 GEN32(gen_op_store_T2_gpr
, gen_op_store_T2_gpr_gpr
);
121 /* floating point registers moves */
122 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fpr
);
123 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fpr
);
124 GEN32(gen_op_load_fpr_FT2
, gen_op_load_fpr_FT2_fpr
);
125 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fpr
);
126 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fpr
);
127 GEN32(gen_op_store_FT2_fpr
, gen_op_store_FT2_fpr_fpr
);
129 static uint8_t spr_access
[1024 / 2];
131 /* internal defines */
132 typedef struct DisasContext
{
133 struct TranslationBlock
*tb
;
137 /* Routine used to access memory */
139 /* Translation flags */
140 #if !defined(CONFIG_USER_ONLY)
146 typedef struct opc_handler_t
{
149 /* instruction type */
152 void (*handler
)(DisasContext
*ctx
);
155 #define RET_EXCP(ctx, excp, error) \
157 if ((ctx)->exception == EXCP_NONE) { \
158 gen_op_update_nip((ctx)->nip); \
160 gen_op_raise_exception_err((excp), (error)); \
161 ctx->exception = (excp); \
164 #define RET_INVAL(ctx) \
165 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL)
167 #define RET_PRIVOPC(ctx) \
168 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_OPC)
170 #define RET_PRIVREG(ctx) \
171 RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG)
173 #define RET_MTMSR(ctx) \
174 RET_EXCP((ctx), EXCP_MTMSR, 0)
176 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
177 static void gen_##name (DisasContext *ctx); \
178 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
179 static void gen_##name (DisasContext *ctx)
181 typedef struct opcode_t
{
182 unsigned char opc1
, opc2
, opc3
;
183 #if HOST_LONG_BITS == 64 /* Explicitely align to 64 bits */
184 unsigned char pad
[5];
186 unsigned char pad
[1];
188 opc_handler_t handler
;
191 /*** Instruction decoding ***/
192 #define EXTRACT_HELPER(name, shift, nb) \
193 static inline uint32_t name (uint32_t opcode) \
195 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
198 #define EXTRACT_SHELPER(name, shift, nb) \
199 static inline int32_t name (uint32_t opcode) \
201 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
205 EXTRACT_HELPER(opc1
, 26, 6);
207 EXTRACT_HELPER(opc2
, 1, 5);
209 EXTRACT_HELPER(opc3
, 6, 5);
210 /* Update Cr0 flags */
211 EXTRACT_HELPER(Rc
, 0, 1);
213 EXTRACT_HELPER(rD
, 21, 5);
215 EXTRACT_HELPER(rS
, 21, 5);
217 EXTRACT_HELPER(rA
, 16, 5);
219 EXTRACT_HELPER(rB
, 11, 5);
221 EXTRACT_HELPER(rC
, 6, 5);
223 EXTRACT_HELPER(crfD
, 23, 3);
224 EXTRACT_HELPER(crfS
, 18, 3);
225 EXTRACT_HELPER(crbD
, 21, 5);
226 EXTRACT_HELPER(crbA
, 16, 5);
227 EXTRACT_HELPER(crbB
, 11, 5);
229 EXTRACT_HELPER(SPR
, 11, 10);
230 /*** Get constants ***/
231 EXTRACT_HELPER(IMM
, 12, 8);
232 /* 16 bits signed immediate value */
233 EXTRACT_SHELPER(SIMM
, 0, 16);
234 /* 16 bits unsigned immediate value */
235 EXTRACT_HELPER(UIMM
, 0, 16);
237 EXTRACT_HELPER(NB
, 11, 5);
239 EXTRACT_HELPER(SH
, 11, 5);
241 EXTRACT_HELPER(MB
, 6, 5);
243 EXTRACT_HELPER(ME
, 1, 5);
245 EXTRACT_HELPER(TO
, 21, 5);
247 EXTRACT_HELPER(CRM
, 12, 8);
248 EXTRACT_HELPER(FM
, 17, 8);
249 EXTRACT_HELPER(SR
, 16, 4);
250 EXTRACT_HELPER(FPIMM
, 20, 4);
252 /*** Jump target decoding ***/
254 EXTRACT_SHELPER(d
, 0, 16);
255 /* Immediate address */
256 static inline uint32_t LI (uint32_t opcode
)
258 return (opcode
>> 0) & 0x03FFFFFC;
261 static inline uint32_t BD (uint32_t opcode
)
263 return (opcode
>> 0) & 0xFFFC;
266 EXTRACT_HELPER(BO
, 21, 5);
267 EXTRACT_HELPER(BI
, 16, 5);
268 /* Absolute/relative address */
269 EXTRACT_HELPER(AA
, 1, 1);
271 EXTRACT_HELPER(LK
, 0, 1);
273 /* Create a mask between <start> and <end> bits */
274 static inline uint32_t MASK (uint32_t start
, uint32_t end
)
278 ret
= (((uint32_t)(-1)) >> (start
)) ^ (((uint32_t)(-1) >> (end
)) >> 1);
285 #if defined(__APPLE__)
286 #define OPCODES_SECTION \
287 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (8) ))
289 #define OPCODES_SECTION \
290 __attribute__ ((section(".opcodes"), unused, aligned (8) ))
293 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
294 OPCODES_SECTION opcode_t opc_##name = { \
302 .handler = &gen_##name, \
306 #define GEN_OPCODE_MARK(name) \
307 OPCODES_SECTION opcode_t opc_##name = { \
313 .inval = 0x00000000, \
319 /* Start opcode list */
320 GEN_OPCODE_MARK(start
);
322 /* Invalid instruction */
323 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
328 static opc_handler_t invalid_handler
= {
331 .handler
= gen_invalid
,
334 /*** Integer arithmetic ***/
335 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval) \
336 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
338 gen_op_load_gpr_T0(rA(ctx->opcode)); \
339 gen_op_load_gpr_T1(rB(ctx->opcode)); \
341 if (Rc(ctx->opcode) != 0) \
343 gen_op_store_T0_gpr(rD(ctx->opcode)); \
346 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval) \
347 GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
349 gen_op_load_gpr_T0(rA(ctx->opcode)); \
350 gen_op_load_gpr_T1(rB(ctx->opcode)); \
352 if (Rc(ctx->opcode) != 0) \
354 gen_op_store_T0_gpr(rD(ctx->opcode)); \
357 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
358 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
360 gen_op_load_gpr_T0(rA(ctx->opcode)); \
362 if (Rc(ctx->opcode) != 0) \
364 gen_op_store_T0_gpr(rD(ctx->opcode)); \
366 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3) \
367 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
369 gen_op_load_gpr_T0(rA(ctx->opcode)); \
371 if (Rc(ctx->opcode) != 0) \
373 gen_op_store_T0_gpr(rD(ctx->opcode)); \
376 /* Two operands arithmetic functions */
377 #define GEN_INT_ARITH2(name, opc1, opc2, opc3) \
378 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000) \
379 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000)
381 /* Two operands arithmetic functions with no overflow allowed */
382 #define GEN_INT_ARITHN(name, opc1, opc2, opc3) \
383 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400)
385 /* One operand arithmetic functions */
386 #define GEN_INT_ARITH1(name, opc1, opc2, opc3) \
387 __GEN_INT_ARITH1(name, opc1, opc2, opc3) \
388 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10)
390 /* add add. addo addo. */
391 GEN_INT_ARITH2 (add
, 0x1F, 0x0A, 0x08);
392 /* addc addc. addco addco. */
393 GEN_INT_ARITH2 (addc
, 0x1F, 0x0A, 0x00);
394 /* adde adde. addeo addeo. */
395 GEN_INT_ARITH2 (adde
, 0x1F, 0x0A, 0x04);
396 /* addme addme. addmeo addmeo. */
397 GEN_INT_ARITH1 (addme
, 0x1F, 0x0A, 0x07);
398 /* addze addze. addzeo addzeo. */
399 GEN_INT_ARITH1 (addze
, 0x1F, 0x0A, 0x06);
400 /* divw divw. divwo divwo. */
401 GEN_INT_ARITH2 (divw
, 0x1F, 0x0B, 0x0F);
402 /* divwu divwu. divwuo divwuo. */
403 GEN_INT_ARITH2 (divwu
, 0x1F, 0x0B, 0x0E);
405 GEN_INT_ARITHN (mulhw
, 0x1F, 0x0B, 0x02);
407 GEN_INT_ARITHN (mulhwu
, 0x1F, 0x0B, 0x00);
408 /* mullw mullw. mullwo mullwo. */
409 GEN_INT_ARITH2 (mullw
, 0x1F, 0x0B, 0x07);
410 /* neg neg. nego nego. */
411 GEN_INT_ARITH1 (neg
, 0x1F, 0x08, 0x03);
412 /* subf subf. subfo subfo. */
413 GEN_INT_ARITH2 (subf
, 0x1F, 0x08, 0x01);
414 /* subfc subfc. subfco subfco. */
415 GEN_INT_ARITH2 (subfc
, 0x1F, 0x08, 0x00);
416 /* subfe subfe. subfeo subfeo. */
417 GEN_INT_ARITH2 (subfe
, 0x1F, 0x08, 0x04);
418 /* subfme subfme. subfmeo subfmeo. */
419 GEN_INT_ARITH1 (subfme
, 0x1F, 0x08, 0x07);
420 /* subfze subfze. subfzeo subfzeo. */
421 GEN_INT_ARITH1 (subfze
, 0x1F, 0x08, 0x06);
423 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
425 int32_t simm
= SIMM(ctx
->opcode
);
427 if (rA(ctx
->opcode
) == 0) {
430 gen_op_load_gpr_T0(rA(ctx
->opcode
));
433 gen_op_store_T0_gpr(rD(ctx
->opcode
));
436 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
438 gen_op_load_gpr_T0(rA(ctx
->opcode
));
439 gen_op_addic(SIMM(ctx
->opcode
));
440 gen_op_store_T0_gpr(rD(ctx
->opcode
));
443 GEN_HANDLER(addic_
, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
445 gen_op_load_gpr_T0(rA(ctx
->opcode
));
446 gen_op_addic(SIMM(ctx
->opcode
));
448 gen_op_store_T0_gpr(rD(ctx
->opcode
));
451 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
453 int32_t simm
= SIMM(ctx
->opcode
);
455 if (rA(ctx
->opcode
) == 0) {
456 gen_op_set_T0(simm
<< 16);
458 gen_op_load_gpr_T0(rA(ctx
->opcode
));
459 gen_op_addi(simm
<< 16);
461 gen_op_store_T0_gpr(rD(ctx
->opcode
));
464 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
466 gen_op_load_gpr_T0(rA(ctx
->opcode
));
467 gen_op_mulli(SIMM(ctx
->opcode
));
468 gen_op_store_T0_gpr(rD(ctx
->opcode
));
471 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
473 gen_op_load_gpr_T0(rA(ctx
->opcode
));
474 gen_op_subfic(SIMM(ctx
->opcode
));
475 gen_op_store_T0_gpr(rD(ctx
->opcode
));
478 /*** Integer comparison ***/
479 #define GEN_CMP(name, opc) \
480 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, PPC_INTEGER) \
482 gen_op_load_gpr_T0(rA(ctx->opcode)); \
483 gen_op_load_gpr_T1(rB(ctx->opcode)); \
485 gen_op_store_T0_crf(crfD(ctx->opcode)); \
491 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
493 gen_op_load_gpr_T0(rA(ctx
->opcode
));
494 gen_op_cmpi(SIMM(ctx
->opcode
));
495 gen_op_store_T0_crf(crfD(ctx
->opcode
));
500 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
502 gen_op_load_gpr_T0(rA(ctx
->opcode
));
503 gen_op_cmpli(UIMM(ctx
->opcode
));
504 gen_op_store_T0_crf(crfD(ctx
->opcode
));
507 /*** Integer logical ***/
508 #define __GEN_LOGICAL2(name, opc2, opc3) \
509 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \
511 gen_op_load_gpr_T0(rS(ctx->opcode)); \
512 gen_op_load_gpr_T1(rB(ctx->opcode)); \
514 if (Rc(ctx->opcode) != 0) \
516 gen_op_store_T0_gpr(rA(ctx->opcode)); \
518 #define GEN_LOGICAL2(name, opc) \
519 __GEN_LOGICAL2(name, 0x1C, opc)
521 #define GEN_LOGICAL1(name, opc) \
522 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \
524 gen_op_load_gpr_T0(rS(ctx->opcode)); \
526 if (Rc(ctx->opcode) != 0) \
528 gen_op_store_T0_gpr(rA(ctx->opcode)); \
532 GEN_LOGICAL2(and, 0x00);
534 GEN_LOGICAL2(andc
, 0x01);
536 GEN_HANDLER(andi_
, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
538 gen_op_load_gpr_T0(rS(ctx
->opcode
));
539 gen_op_andi_(UIMM(ctx
->opcode
));
541 gen_op_store_T0_gpr(rA(ctx
->opcode
));
544 GEN_HANDLER(andis_
, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
546 gen_op_load_gpr_T0(rS(ctx
->opcode
));
547 gen_op_andi_(UIMM(ctx
->opcode
) << 16);
549 gen_op_store_T0_gpr(rA(ctx
->opcode
));
553 GEN_LOGICAL1(cntlzw
, 0x00);
555 GEN_LOGICAL2(eqv
, 0x08);
557 GEN_LOGICAL1(extsb
, 0x1D);
559 GEN_LOGICAL1(extsh
, 0x1C);
561 GEN_LOGICAL2(nand
, 0x0E);
563 GEN_LOGICAL2(nor
, 0x03);
566 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
568 gen_op_load_gpr_T0(rS(ctx
->opcode
));
569 /* Optimisation for mr case */
570 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
571 gen_op_load_gpr_T1(rB(ctx
->opcode
));
574 if (Rc(ctx
->opcode
) != 0)
576 gen_op_store_T0_gpr(rA(ctx
->opcode
));
580 GEN_LOGICAL2(orc
, 0x0C);
582 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
584 gen_op_load_gpr_T0(rS(ctx
->opcode
));
585 /* Optimisation for "set to zero" case */
586 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
587 gen_op_load_gpr_T1(rB(ctx
->opcode
));
592 if (Rc(ctx
->opcode
) != 0)
594 gen_op_store_T0_gpr(rA(ctx
->opcode
));
597 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
599 uint32_t uimm
= UIMM(ctx
->opcode
);
601 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
605 gen_op_load_gpr_T0(rS(ctx
->opcode
));
608 gen_op_store_T0_gpr(rA(ctx
->opcode
));
611 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
613 uint32_t uimm
= UIMM(ctx
->opcode
);
615 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
619 gen_op_load_gpr_T0(rS(ctx
->opcode
));
621 gen_op_ori(uimm
<< 16);
622 gen_op_store_T0_gpr(rA(ctx
->opcode
));
625 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
627 uint32_t uimm
= UIMM(ctx
->opcode
);
629 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
633 gen_op_load_gpr_T0(rS(ctx
->opcode
));
636 gen_op_store_T0_gpr(rA(ctx
->opcode
));
640 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
642 uint32_t uimm
= UIMM(ctx
->opcode
);
644 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
648 gen_op_load_gpr_T0(rS(ctx
->opcode
));
650 gen_op_xori(uimm
<< 16);
651 gen_op_store_T0_gpr(rA(ctx
->opcode
));
654 /*** Integer rotate ***/
655 /* rlwimi & rlwimi. */
656 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
660 mb
= MB(ctx
->opcode
);
661 me
= ME(ctx
->opcode
);
662 gen_op_load_gpr_T0(rS(ctx
->opcode
));
663 gen_op_load_gpr_T1(rA(ctx
->opcode
));
664 gen_op_rlwimi(SH(ctx
->opcode
), MASK(mb
, me
), ~MASK(mb
, me
));
665 if (Rc(ctx
->opcode
) != 0)
667 gen_op_store_T0_gpr(rA(ctx
->opcode
));
669 /* rlwinm & rlwinm. */
670 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
674 sh
= SH(ctx
->opcode
);
675 mb
= MB(ctx
->opcode
);
676 me
= ME(ctx
->opcode
);
677 gen_op_load_gpr_T0(rS(ctx
->opcode
));
680 gen_op_andi_(MASK(mb
, me
));
689 } else if (me
== (31 - sh
)) {
694 } else if (me
== 31) {
696 if (sh
== (32 - mb
)) {
702 gen_op_rlwinm(sh
, MASK(mb
, me
));
704 if (Rc(ctx
->opcode
) != 0)
706 gen_op_store_T0_gpr(rA(ctx
->opcode
));
709 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
713 mb
= MB(ctx
->opcode
);
714 me
= ME(ctx
->opcode
);
715 gen_op_load_gpr_T0(rS(ctx
->opcode
));
716 gen_op_load_gpr_T1(rB(ctx
->opcode
));
717 if (mb
== 0 && me
== 31) {
721 gen_op_rlwnm(MASK(mb
, me
));
723 if (Rc(ctx
->opcode
) != 0)
725 gen_op_store_T0_gpr(rA(ctx
->opcode
));
728 /*** Integer shift ***/
730 __GEN_LOGICAL2(slw
, 0x18, 0x00);
732 __GEN_LOGICAL2(sraw
, 0x18, 0x18);
734 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
736 gen_op_load_gpr_T0(rS(ctx
->opcode
));
737 if (SH(ctx
->opcode
) != 0)
738 gen_op_srawi(SH(ctx
->opcode
), MASK(32 - SH(ctx
->opcode
), 31));
739 if (Rc(ctx
->opcode
) != 0)
741 gen_op_store_T0_gpr(rA(ctx
->opcode
));
744 __GEN_LOGICAL2(srw
, 0x18, 0x10);
746 /*** Floating-Point arithmetic ***/
747 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat) \
748 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, PPC_FLOAT) \
750 if (!ctx->fpu_enabled) { \
751 RET_EXCP(ctx, EXCP_NO_FP, 0); \
754 gen_op_reset_scrfx(); \
755 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
756 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
757 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
762 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
763 if (Rc(ctx->opcode)) \
767 #define GEN_FLOAT_ACB(name, op2) \
768 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0); \
769 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1);
771 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
772 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
774 if (!ctx->fpu_enabled) { \
775 RET_EXCP(ctx, EXCP_NO_FP, 0); \
778 gen_op_reset_scrfx(); \
779 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
780 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
785 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
786 if (Rc(ctx->opcode)) \
789 #define GEN_FLOAT_AB(name, op2, inval) \
790 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
791 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
793 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
794 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
796 if (!ctx->fpu_enabled) { \
797 RET_EXCP(ctx, EXCP_NO_FP, 0); \
800 gen_op_reset_scrfx(); \
801 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
802 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
807 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
808 if (Rc(ctx->opcode)) \
811 #define GEN_FLOAT_AC(name, op2, inval) \
812 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
813 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
815 #define GEN_FLOAT_B(name, op2, op3) \
816 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, PPC_FLOAT) \
818 if (!ctx->fpu_enabled) { \
819 RET_EXCP(ctx, EXCP_NO_FP, 0); \
822 gen_op_reset_scrfx(); \
823 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
825 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
826 if (Rc(ctx->opcode)) \
830 #define GEN_FLOAT_BS(name, op1, op2) \
831 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, PPC_FLOAT) \
833 if (!ctx->fpu_enabled) { \
834 RET_EXCP(ctx, EXCP_NO_FP, 0); \
837 gen_op_reset_scrfx(); \
838 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
840 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
841 if (Rc(ctx->opcode)) \
846 GEN_FLOAT_AB(add
, 0x15, 0x000007C0);
848 GEN_FLOAT_AB(div
, 0x12, 0x000007C0);
850 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800);
853 GEN_FLOAT_BS(res
, 0x3B, 0x18);
856 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A);
859 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0);
861 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0);
864 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_OPT
)
866 if (!ctx
->fpu_enabled
) {
867 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
870 gen_op_reset_scrfx();
871 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
873 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
878 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_OPT
)
880 if (!ctx
->fpu_enabled
) {
881 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
884 gen_op_reset_scrfx();
885 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
888 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
893 /*** Floating-Point multiply-and-add ***/
895 GEN_FLOAT_ACB(madd
, 0x1D);
897 GEN_FLOAT_ACB(msub
, 0x1C);
898 /* fnmadd - fnmadds */
899 GEN_FLOAT_ACB(nmadd
, 0x1F);
900 /* fnmsub - fnmsubs */
901 GEN_FLOAT_ACB(nmsub
, 0x1E);
903 /*** Floating-Point round & convert ***/
905 GEN_FLOAT_B(ctiw
, 0x0E, 0x00);
907 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00);
909 GEN_FLOAT_B(rsp
, 0x0C, 0x00);
911 /*** Floating-Point compare ***/
913 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
915 if (!ctx
->fpu_enabled
) {
916 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
919 gen_op_reset_scrfx();
920 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
921 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
923 gen_op_store_T0_crf(crfD(ctx
->opcode
));
927 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
929 if (!ctx
->fpu_enabled
) {
930 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
933 gen_op_reset_scrfx();
934 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
935 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
937 gen_op_store_T0_crf(crfD(ctx
->opcode
));
940 /*** Floating-point move ***/
942 GEN_FLOAT_B(abs
, 0x08, 0x08);
945 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
947 if (!ctx
->fpu_enabled
) {
948 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
951 gen_op_reset_scrfx();
952 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
953 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
959 GEN_FLOAT_B(nabs
, 0x08, 0x04);
961 GEN_FLOAT_B(neg
, 0x08, 0x01);
963 /*** Floating-Point status & ctrl register ***/
965 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
967 if (!ctx
->fpu_enabled
) {
968 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
971 gen_op_load_fpscr_T0(crfS(ctx
->opcode
));
972 gen_op_store_T0_crf(crfD(ctx
->opcode
));
973 gen_op_clear_fpscr(crfS(ctx
->opcode
));
977 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
979 if (!ctx
->fpu_enabled
) {
980 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
984 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
990 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
994 if (!ctx
->fpu_enabled
) {
995 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
998 crb
= crbD(ctx
->opcode
) >> 2;
999 gen_op_load_fpscr_T0(crb
);
1000 gen_op_andi_(~(1 << (crbD(ctx
->opcode
) & 0x03)));
1001 gen_op_store_T0_fpscr(crb
);
1002 if (Rc(ctx
->opcode
))
1007 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
1011 if (!ctx
->fpu_enabled
) {
1012 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
1015 crb
= crbD(ctx
->opcode
) >> 2;
1016 gen_op_load_fpscr_T0(crb
);
1017 gen_op_ori(1 << (crbD(ctx
->opcode
) & 0x03));
1018 gen_op_store_T0_fpscr(crb
);
1019 if (Rc(ctx
->opcode
))
1024 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
1026 if (!ctx
->fpu_enabled
) {
1027 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
1030 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1031 gen_op_store_fpscr(FM(ctx
->opcode
));
1032 if (Rc(ctx
->opcode
))
1037 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
1039 if (!ctx
->fpu_enabled
) {
1040 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
1043 gen_op_store_T0_fpscri(crbD(ctx
->opcode
) >> 2, FPIMM(ctx
->opcode
));
1044 if (Rc(ctx
->opcode
))
1048 /*** Integer load ***/
1049 #if defined(CONFIG_USER_ONLY)
1050 #define op_ldst(name) gen_op_##name##_raw()
1051 #define OP_LD_TABLE(width)
1052 #define OP_ST_TABLE(width)
1054 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
1055 #define OP_LD_TABLE(width) \
1056 static GenOpFunc *gen_op_l##width[] = { \
1057 &gen_op_l##width##_user, \
1058 &gen_op_l##width##_kernel, \
1060 #define OP_ST_TABLE(width) \
1061 static GenOpFunc *gen_op_st##width[] = { \
1062 &gen_op_st##width##_user, \
1063 &gen_op_st##width##_kernel, \
1067 #define GEN_LD(width, opc) \
1068 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1070 uint32_t simm = SIMM(ctx->opcode); \
1071 if (rA(ctx->opcode) == 0) { \
1072 gen_op_set_T0(simm); \
1074 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1076 gen_op_addi(simm); \
1078 op_ldst(l##width); \
1079 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1082 #define GEN_LDU(width, opc) \
1083 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1085 uint32_t simm = SIMM(ctx->opcode); \
1086 if (rA(ctx->opcode) == 0 || \
1087 rA(ctx->opcode) == rD(ctx->opcode)) { \
1091 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1093 gen_op_addi(simm); \
1094 op_ldst(l##width); \
1095 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1096 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1099 #define GEN_LDUX(width, opc) \
1100 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1102 if (rA(ctx->opcode) == 0 || \
1103 rA(ctx->opcode) == rD(ctx->opcode)) { \
1107 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1108 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1110 op_ldst(l##width); \
1111 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1112 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1115 #define GEN_LDX(width, opc2, opc3) \
1116 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1118 if (rA(ctx->opcode) == 0) { \
1119 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1121 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1122 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1125 op_ldst(l##width); \
1126 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1129 #define GEN_LDS(width, op) \
1130 OP_LD_TABLE(width); \
1131 GEN_LD(width, op | 0x20); \
1132 GEN_LDU(width, op | 0x21); \
1133 GEN_LDUX(width, op | 0x01); \
1134 GEN_LDX(width, 0x17, op | 0x00)
1136 /* lbz lbzu lbzux lbzx */
1138 /* lha lhau lhaux lhax */
1140 /* lhz lhzu lhzux lhzx */
1142 /* lwz lwzu lwzux lwzx */
1145 /*** Integer store ***/
1146 #define GEN_ST(width, opc) \
1147 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1149 uint32_t simm = SIMM(ctx->opcode); \
1150 if (rA(ctx->opcode) == 0) { \
1151 gen_op_set_T0(simm); \
1153 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1155 gen_op_addi(simm); \
1157 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1158 op_ldst(st##width); \
1161 #define GEN_STU(width, opc) \
1162 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1164 uint32_t simm = SIMM(ctx->opcode); \
1165 if (rA(ctx->opcode) == 0) { \
1169 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1171 gen_op_addi(simm); \
1172 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1173 op_ldst(st##width); \
1174 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1177 #define GEN_STUX(width, opc) \
1178 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1180 if (rA(ctx->opcode) == 0) { \
1184 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1185 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1187 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1188 op_ldst(st##width); \
1189 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1192 #define GEN_STX(width, opc2, opc3) \
1193 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \
1195 if (rA(ctx->opcode) == 0) { \
1196 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1198 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1199 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1202 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1203 op_ldst(st##width); \
1206 #define GEN_STS(width, op) \
1207 OP_ST_TABLE(width); \
1208 GEN_ST(width, op | 0x20); \
1209 GEN_STU(width, op | 0x21); \
1210 GEN_STUX(width, op | 0x01); \
1211 GEN_STX(width, 0x17, op | 0x00)
1213 /* stb stbu stbux stbx */
1215 /* sth sthu sthux sthx */
1217 /* stw stwu stwux stwx */
1220 /*** Integer load and store with byte reverse ***/
1223 GEN_LDX(hbr
, 0x16, 0x18);
1226 GEN_LDX(wbr
, 0x16, 0x10);
1229 GEN_STX(hbr
, 0x16, 0x1C);
1232 GEN_STX(wbr
, 0x16, 0x14);
1234 /*** Integer load and store multiple ***/
1235 #if defined(CONFIG_USER_ONLY)
1236 #define op_ldstm(name, reg) gen_op_##name##_raw(reg)
1238 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
1239 static GenOpFunc1
*gen_op_lmw
[] = {
1243 static GenOpFunc1
*gen_op_stmw
[] = {
1245 &gen_op_stmw_kernel
,
1250 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1252 int simm
= SIMM(ctx
->opcode
);
1254 if (rA(ctx
->opcode
) == 0) {
1255 gen_op_set_T0(simm
);
1257 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1261 op_ldstm(lmw
, rD(ctx
->opcode
));
1265 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1267 int simm
= SIMM(ctx
->opcode
);
1269 if (rA(ctx
->opcode
) == 0) {
1270 gen_op_set_T0(simm
);
1272 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1276 op_ldstm(stmw
, rS(ctx
->opcode
));
1279 /*** Integer load and store strings ***/
1280 #if defined(CONFIG_USER_ONLY)
1281 #define op_ldsts(name, start) gen_op_##name##_raw(start)
1282 #define op_ldstsx(name, rd, ra, rb) gen_op_##name##_raw(rd, ra, rb)
1284 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
1285 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
1286 static GenOpFunc1
*gen_op_lswi
[] = {
1288 &gen_op_lswi_kernel
,
1290 static GenOpFunc3
*gen_op_lswx
[] = {
1292 &gen_op_lswx_kernel
,
1294 static GenOpFunc1
*gen_op_stsw
[] = {
1296 &gen_op_stsw_kernel
,
1301 /* PPC32 specification says we must generate an exception if
1302 * rA is in the range of registers to be loaded.
1303 * In an other hand, IBM says this is valid, but rA won't be loaded.
1304 * For now, I'll follow the spec...
1306 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER
)
1308 int nb
= NB(ctx
->opcode
);
1309 int start
= rD(ctx
->opcode
);
1310 int ra
= rA(ctx
->opcode
);
1316 if (((start
+ nr
) > 32 && start
<= ra
&& (start
+ nr
- 32) > ra
) ||
1317 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
)) {
1318 RET_EXCP(ctx
, EXCP_PROGRAM
, EXCP_INVAL
| EXCP_INVAL_LSWX
);
1324 gen_op_load_gpr_T0(ra
);
1327 op_ldsts(lswi
, start
);
1331 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER
)
1333 int ra
= rA(ctx
->opcode
);
1334 int rb
= rB(ctx
->opcode
);
1337 gen_op_load_gpr_T0(rb
);
1340 gen_op_load_gpr_T0(ra
);
1341 gen_op_load_gpr_T1(rb
);
1344 gen_op_load_xer_bc();
1345 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
1349 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER
)
1351 int nb
= NB(ctx
->opcode
);
1353 if (rA(ctx
->opcode
) == 0) {
1356 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1361 op_ldsts(stsw
, rS(ctx
->opcode
));
1365 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER
)
1367 int ra
= rA(ctx
->opcode
);
1370 gen_op_load_gpr_T0(rB(ctx
->opcode
));
1371 ra
= rB(ctx
->opcode
);
1373 gen_op_load_gpr_T0(ra
);
1374 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1377 gen_op_load_xer_bc();
1378 op_ldsts(stsw
, rS(ctx
->opcode
));
1381 /*** Memory synchronisation ***/
1383 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FF0801, PPC_MEM
)
1388 GEN_HANDLER(isync
, 0x13, 0x16, 0xFF, 0x03FF0801, PPC_MEM
)
1393 #if defined(CONFIG_USER_ONLY)
1394 #define op_lwarx() gen_op_lwarx_raw()
1395 #define op_stwcx() gen_op_stwcx_raw()
1397 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
1398 static GenOpFunc
*gen_op_lwarx
[] = {
1400 &gen_op_lwarx_kernel
,
1402 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
1403 static GenOpFunc
*gen_op_stwcx
[] = {
1405 &gen_op_stwcx_kernel
,
1409 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0xFF, 0x00000001, PPC_RES
)
1411 if (rA(ctx
->opcode
) == 0) {
1412 gen_op_load_gpr_T0(rB(ctx
->opcode
));
1414 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1415 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1419 gen_op_store_T1_gpr(rD(ctx
->opcode
));
1423 GEN_HANDLER(stwcx_
, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
1425 if (rA(ctx
->opcode
) == 0) {
1426 gen_op_load_gpr_T0(rB(ctx
->opcode
));
1428 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1429 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1432 gen_op_load_gpr_T1(rS(ctx
->opcode
));
1437 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_MEM
)
1441 /*** Floating-point load ***/
1442 #define GEN_LDF(width, opc) \
1443 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1445 uint32_t simm = SIMM(ctx->opcode); \
1446 if (!ctx->fpu_enabled) { \
1447 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1450 if (rA(ctx->opcode) == 0) { \
1451 gen_op_set_T0(simm); \
1453 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1455 gen_op_addi(simm); \
1457 op_ldst(l##width); \
1458 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1461 #define GEN_LDUF(width, opc) \
1462 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1464 uint32_t simm = SIMM(ctx->opcode); \
1465 if (!ctx->fpu_enabled) { \
1466 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1469 if (rA(ctx->opcode) == 0 || \
1470 rA(ctx->opcode) == rD(ctx->opcode)) { \
1474 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1476 gen_op_addi(simm); \
1477 op_ldst(l##width); \
1478 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1479 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1482 #define GEN_LDUXF(width, opc) \
1483 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_FLOAT) \
1485 if (!ctx->fpu_enabled) { \
1486 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1489 if (rA(ctx->opcode) == 0 || \
1490 rA(ctx->opcode) == rD(ctx->opcode)) { \
1494 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1495 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1497 op_ldst(l##width); \
1498 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1499 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1502 #define GEN_LDXF(width, opc2, opc3) \
1503 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_FLOAT) \
1505 if (!ctx->fpu_enabled) { \
1506 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1509 if (rA(ctx->opcode) == 0) { \
1510 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1512 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1513 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1516 op_ldst(l##width); \
1517 gen_op_store_FT1_fpr(rD(ctx->opcode)); \
1520 #define GEN_LDFS(width, op) \
1521 OP_LD_TABLE(width); \
1522 GEN_LDF(width, op | 0x20); \
1523 GEN_LDUF(width, op | 0x21); \
1524 GEN_LDUXF(width, op | 0x01); \
1525 GEN_LDXF(width, 0x17, op | 0x00)
1527 /* lfd lfdu lfdux lfdx */
1529 /* lfs lfsu lfsux lfsx */
1532 /*** Floating-point store ***/
1533 #define GEN_STF(width, opc) \
1534 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1536 uint32_t simm = SIMM(ctx->opcode); \
1537 if (!ctx->fpu_enabled) { \
1538 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1541 if (rA(ctx->opcode) == 0) { \
1542 gen_op_set_T0(simm); \
1544 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1546 gen_op_addi(simm); \
1548 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1549 op_ldst(st##width); \
1552 #define GEN_STUF(width, opc) \
1553 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_FLOAT) \
1555 uint32_t simm = SIMM(ctx->opcode); \
1556 if (!ctx->fpu_enabled) { \
1557 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1560 if (rA(ctx->opcode) == 0) { \
1564 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1566 gen_op_addi(simm); \
1567 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1568 op_ldst(st##width); \
1569 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1572 #define GEN_STUXF(width, opc) \
1573 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_FLOAT) \
1575 if (!ctx->fpu_enabled) { \
1576 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1579 if (rA(ctx->opcode) == 0) { \
1583 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1584 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1586 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1587 op_ldst(st##width); \
1588 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1591 #define GEN_STXF(width, opc2, opc3) \
1592 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_FLOAT) \
1594 if (!ctx->fpu_enabled) { \
1595 RET_EXCP(ctx, EXCP_NO_FP, 0); \
1598 if (rA(ctx->opcode) == 0) { \
1599 gen_op_load_gpr_T0(rB(ctx->opcode)); \
1601 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1602 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1605 gen_op_load_fpr_FT1(rS(ctx->opcode)); \
1606 op_ldst(st##width); \
1609 #define GEN_STFS(width, op) \
1610 OP_ST_TABLE(width); \
1611 GEN_STF(width, op | 0x20); \
1612 GEN_STUF(width, op | 0x21); \
1613 GEN_STUXF(width, op | 0x01); \
1614 GEN_STXF(width, 0x17, op | 0x00)
1616 /* stfd stfdu stfdux stfdx */
1618 /* stfs stfsu stfsux stfsx */
1623 GEN_HANDLER(stfiwx
, 0x1F, 0x17, 0x1E, 0x00000001, PPC_FLOAT
)
1625 if (!ctx
->fpu_enabled
) {
1626 RET_EXCP(ctx
, EXCP_NO_FP
, 0);
1635 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
1637 uint32_t li
, target
;
1639 /* sign extend LI */
1640 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
1642 if (AA(ctx
->opcode
) == 0)
1643 target
= ctx
->nip
+ li
- 4;
1646 if (LK(ctx
->opcode
)) {
1647 gen_op_setlr(ctx
->nip
);
1649 gen_op_b((long)ctx
->tb
, target
);
1650 ctx
->exception
= EXCP_BRANCH
;
1657 static inline void gen_bcond(DisasContext
*ctx
, int type
)
1659 uint32_t target
= 0;
1660 uint32_t bo
= BO(ctx
->opcode
);
1661 uint32_t bi
= BI(ctx
->opcode
);
1665 if ((bo
& 0x4) == 0)
1669 li
= (int32_t)((int16_t)(BD(ctx
->opcode
)));
1670 if (AA(ctx
->opcode
) == 0) {
1671 target
= ctx
->nip
+ li
- 4;
1677 gen_op_movl_T1_ctr();
1681 gen_op_movl_T1_lr();
1684 if (LK(ctx
->opcode
)) {
1685 gen_op_setlr(ctx
->nip
);
1688 /* No CR condition */
1699 if (type
== BCOND_IM
) {
1700 gen_op_b((long)ctx
->tb
, target
);
1707 mask
= 1 << (3 - (bi
& 0x03));
1708 gen_op_load_crf_T0(bi
>> 2);
1712 gen_op_test_ctr_true(mask
);
1715 gen_op_test_ctrz_true(mask
);
1720 gen_op_test_true(mask
);
1726 gen_op_test_ctr_false(mask
);
1729 gen_op_test_ctrz_false(mask
);
1734 gen_op_test_false(mask
);
1739 if (type
== BCOND_IM
) {
1740 gen_op_btest((long)ctx
->tb
, target
, ctx
->nip
);
1742 gen_op_btest_T1(ctx
->nip
);
1745 ctx
->exception
= EXCP_BRANCH
;
1748 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
1750 gen_bcond(ctx
, BCOND_IM
);
1753 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
1755 gen_bcond(ctx
, BCOND_CTR
);
1758 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
1760 gen_bcond(ctx
, BCOND_LR
);
1763 /*** Condition register logical ***/
1764 #define GEN_CRLOGIC(op, opc) \
1765 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
1767 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
1768 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
1769 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
1770 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
1772 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
1773 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
1774 3 - (crbD(ctx->opcode) & 0x03)); \
1775 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
1779 GEN_CRLOGIC(and, 0x08)
1781 GEN_CRLOGIC(andc
, 0x04)
1783 GEN_CRLOGIC(eqv
, 0x09)
1785 GEN_CRLOGIC(nand
, 0x07)
1787 GEN_CRLOGIC(nor
, 0x01)
1789 GEN_CRLOGIC(or, 0x0E)
1791 GEN_CRLOGIC(orc
, 0x0D)
1793 GEN_CRLOGIC(xor, 0x06)
1795 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
1797 gen_op_load_crf_T0(crfS(ctx
->opcode
));
1798 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1801 /*** System linkage ***/
1802 /* rfi (supervisor only) */
1803 GEN_HANDLER(rfi
, 0x13, 0x12, 0xFF, 0x03FF8001, PPC_FLOW
)
1805 #if defined(CONFIG_USER_ONLY)
1808 /* Restore CPU state */
1809 if (!ctx
->supervisor
) {
1814 RET_EXCP(ctx
, EXCP_RFI
, 0);
1819 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFFFFD, PPC_FLOW
)
1821 #if defined(CONFIG_USER_ONLY)
1822 RET_EXCP(ctx
, EXCP_SYSCALL_USER
, 0);
1824 RET_EXCP(ctx
, EXCP_SYSCALL
, 0);
1830 GEN_HANDLER(tw
, 0x1F, 0x04, 0xFF, 0x00000001, PPC_FLOW
)
1832 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1833 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1834 gen_op_tw(TO(ctx
->opcode
));
1838 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
1840 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1842 printf("%s: param=0x%04x T0=0x%04x\n", __func__
,
1843 SIMM(ctx
->opcode
), TO(ctx
->opcode
));
1845 gen_op_twi(SIMM(ctx
->opcode
), TO(ctx
->opcode
));
1848 /*** Processor control ***/
1849 static inline int check_spr_access (int spr
, int rw
, int supervisor
)
1851 uint32_t rights
= spr_access
[spr
>> 1] >> (4 * (spr
& 1));
1854 if (spr
!= LR
&& spr
!= CTR
) {
1856 fprintf(logfile
, "%s reg=%d s=%d rw=%d r=0x%02x 0x%02x\n", __func__
,
1857 SPR_ENCODE(spr
), supervisor
, rw
, rights
,
1858 (rights
>> ((2 * supervisor
) + rw
)) & 1);
1860 printf("%s reg=%d s=%d rw=%d r=0x%02x 0x%02x\n", __func__
,
1861 SPR_ENCODE(spr
), supervisor
, rw
, rights
,
1862 (rights
>> ((2 * supervisor
) + rw
)) & 1);
1868 rights
= rights
>> (2 * supervisor
);
1869 rights
= rights
>> rw
;
1875 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
1877 gen_op_load_xer_cr();
1878 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1879 gen_op_clear_xer_cr();
1883 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x001FF801, PPC_MISC
)
1886 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1890 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
1892 #if defined(CONFIG_USER_ONLY)
1895 if (!ctx
->supervisor
) {
1900 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1905 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
1907 uint32_t sprn
= SPR(ctx
->opcode
);
1909 #if defined(CONFIG_USER_ONLY)
1910 switch (check_spr_access(sprn
, 0, 0))
1912 switch (check_spr_access(sprn
, 0, ctx
->supervisor
))
1916 RET_EXCP(ctx
, EXCP_PROGRAM
, EXCP_INVAL
| EXCP_INVAL_SPR
);
1935 gen_op_load_ibat(0, 0);
1938 gen_op_load_ibat(0, 1);
1941 gen_op_load_ibat(0, 2);
1944 gen_op_load_ibat(0, 3);
1947 gen_op_load_ibat(0, 4);
1950 gen_op_load_ibat(0, 5);
1953 gen_op_load_ibat(0, 6);
1956 gen_op_load_ibat(0, 7);
1959 gen_op_load_ibat(1, 0);
1962 gen_op_load_ibat(1, 1);
1965 gen_op_load_ibat(1, 2);
1968 gen_op_load_ibat(1, 3);
1971 gen_op_load_ibat(1, 4);
1974 gen_op_load_ibat(1, 5);
1977 gen_op_load_ibat(1, 6);
1980 gen_op_load_ibat(1, 7);
1983 gen_op_load_dbat(0, 0);
1986 gen_op_load_dbat(0, 1);
1989 gen_op_load_dbat(0, 2);
1992 gen_op_load_dbat(0, 3);
1995 gen_op_load_dbat(0, 4);
1998 gen_op_load_dbat(0, 5);
2001 gen_op_load_dbat(0, 6);
2004 gen_op_load_dbat(0, 7);
2007 gen_op_load_dbat(1, 0);
2010 gen_op_load_dbat(1, 1);
2013 gen_op_load_dbat(1, 2);
2016 gen_op_load_dbat(1, 3);
2019 gen_op_load_dbat(1, 4);
2022 gen_op_load_dbat(1, 5);
2025 gen_op_load_dbat(1, 6);
2028 gen_op_load_dbat(1, 7);
2043 gen_op_load_spr(sprn
);
2046 gen_op_store_T0_gpr(rD(ctx
->opcode
));
2050 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MISC
)
2052 uint32_t sprn
= SPR(ctx
->opcode
);
2054 /* We need to update the time base before reading it */
2066 gen_op_store_T0_gpr(rD(ctx
->opcode
));
2070 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00100801, PPC_MISC
)
2072 gen_op_load_gpr_T0(rS(ctx
->opcode
));
2073 gen_op_store_cr(CRM(ctx
->opcode
));
2077 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
2079 #if defined(CONFIG_USER_ONLY)
2082 if (!ctx
->supervisor
) {
2086 gen_op_load_gpr_T0(rS(ctx
->opcode
));
2088 /* Must stop the translation as machine state (may have) changed */
2094 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
2096 uint32_t sprn
= SPR(ctx
->opcode
);
2100 fprintf(logfile
, "MTSPR %d src=%d (%d)\n", SPR_ENCODE(sprn
),
2101 rS(ctx
->opcode
), sprn
);
2104 #if defined(CONFIG_USER_ONLY)
2105 switch (check_spr_access(sprn
, 1, 0))
2107 switch (check_spr_access(sprn
, 1, ctx
->supervisor
))
2111 RET_EXCP(ctx
, EXCP_PROGRAM
, EXCP_INVAL
| EXCP_INVAL_SPR
);
2119 gen_op_load_gpr_T0(rS(ctx
->opcode
));
2131 gen_op_store_ibat(0, 0);
2135 gen_op_store_ibat(0, 1);
2139 gen_op_store_ibat(0, 2);
2143 gen_op_store_ibat(0, 3);
2147 gen_op_store_ibat(0, 4);
2151 gen_op_store_ibat(0, 5);
2155 gen_op_store_ibat(0, 6);
2159 gen_op_store_ibat(0, 7);
2163 gen_op_store_ibat(1, 0);
2167 gen_op_store_ibat(1, 1);
2171 gen_op_store_ibat(1, 2);
2175 gen_op_store_ibat(1, 3);
2179 gen_op_store_ibat(1, 4);
2183 gen_op_store_ibat(1, 5);
2187 gen_op_store_ibat(1, 6);
2191 gen_op_store_ibat(1, 7);
2195 gen_op_store_dbat(0, 0);
2199 gen_op_store_dbat(0, 1);
2203 gen_op_store_dbat(0, 2);
2207 gen_op_store_dbat(0, 3);
2211 gen_op_store_dbat(0, 4);
2215 gen_op_store_dbat(0, 5);
2219 gen_op_store_dbat(0, 6);
2223 gen_op_store_dbat(0, 7);
2227 gen_op_store_dbat(1, 0);
2231 gen_op_store_dbat(1, 1);
2235 gen_op_store_dbat(1, 2);
2239 gen_op_store_dbat(1, 3);
2243 gen_op_store_dbat(1, 4);
2247 gen_op_store_dbat(1, 5);
2251 gen_op_store_dbat(1, 6);
2255 gen_op_store_dbat(1, 7);
2259 gen_op_store_sdr1();
2269 gen_op_store_decr();
2272 gen_op_store_spr(sprn
);
2277 /*** Cache management ***/
2278 /* For now, all those will be implemented as nop:
2279 * this is valid, regarding the PowerPC specs...
2280 * We just have to flush tb while invalidating instruction cache lines...
2283 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03E00001, PPC_CACHE
)
2285 if (rA(ctx
->opcode
) == 0) {
2286 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2288 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2289 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2295 /* dcbi (Supervisor only) */
2296 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
2298 #if defined(CONFIG_USER_ONLY)
2301 if (!ctx
->supervisor
) {
2305 if (rA(ctx
->opcode
) == 0) {
2306 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2308 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2309 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2318 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
2320 if (rA(ctx
->opcode
) == 0) {
2321 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2323 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2324 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2331 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x03E00001, PPC_CACHE
)
2336 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE
)
2341 #if defined(CONFIG_USER_ONLY)
2342 #define op_dcbz() gen_op_dcbz_raw()
2344 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
2345 static GenOpFunc
*gen_op_dcbz
[] = {
2347 &gen_op_dcbz_kernel
,
2351 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE
)
2353 if (rA(ctx
->opcode
) == 0) {
2354 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2356 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2357 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2361 gen_op_check_reservation();
2365 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE
)
2367 if (rA(ctx
->opcode
) == 0) {
2368 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2370 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2371 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2379 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_OPT
)
2383 /*** Segment register manipulation ***/
2384 /* Supervisor only: */
2386 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
2388 #if defined(CONFIG_USER_ONLY)
2391 if (!ctx
->supervisor
) {
2395 gen_op_load_sr(SR(ctx
->opcode
));
2396 gen_op_store_T0_gpr(rD(ctx
->opcode
));
2401 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
2403 #if defined(CONFIG_USER_ONLY)
2406 if (!ctx
->supervisor
) {
2410 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2412 gen_op_store_T0_gpr(rD(ctx
->opcode
));
2417 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
2419 #if defined(CONFIG_USER_ONLY)
2422 if (!ctx
->supervisor
) {
2426 gen_op_load_gpr_T0(rS(ctx
->opcode
));
2427 gen_op_store_sr(SR(ctx
->opcode
));
2432 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
2434 #if defined(CONFIG_USER_ONLY)
2437 if (!ctx
->supervisor
) {
2441 gen_op_load_gpr_T0(rS(ctx
->opcode
));
2442 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2443 gen_op_store_srin();
2447 /*** Lookaside buffer management ***/
2448 /* Optional & supervisor only: */
2450 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_OPT
)
2452 #if defined(CONFIG_USER_ONLY)
2455 if (!ctx
->supervisor
) {
2457 fprintf(logfile
, "%s: ! supervisor\n", __func__
);
2467 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM
)
2469 #if defined(CONFIG_USER_ONLY)
2472 if (!ctx
->supervisor
) {
2476 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2483 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM
)
2485 #if defined(CONFIG_USER_ONLY)
2488 if (!ctx
->supervisor
) {
2492 /* This has no effect: it should ensure that all previous
2493 * tlbie have completed
2499 /*** External control ***/
2502 #if defined(CONFIG_USER_ONLY)
2503 #define op_eciwx() gen_op_eciwx_raw()
2504 #define op_ecowx() gen_op_ecowx_raw()
2506 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
2507 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
2508 static GenOpFunc
*gen_op_eciwx
[] = {
2510 &gen_op_eciwx_kernel
,
2512 static GenOpFunc
*gen_op_ecowx
[] = {
2514 &gen_op_ecowx_kernel
,
2518 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
2520 /* Should check EAR[E] & alignment ! */
2521 if (rA(ctx
->opcode
) == 0) {
2522 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2524 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2525 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2529 gen_op_store_T0_gpr(rD(ctx
->opcode
));
2533 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
2535 /* Should check EAR[E] & alignment ! */
2536 if (rA(ctx
->opcode
) == 0) {
2537 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2539 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2540 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2543 gen_op_load_gpr_T2(rS(ctx
->opcode
));
2547 /* End opcode list */
2548 GEN_OPCODE_MARK(end
);
2550 /*****************************************************************************/
2554 int fflush (FILE *stream
);
2556 /* Main ppc opcodes table:
2557 * at init, all opcodes are invalids
2559 static opc_handler_t
*ppc_opcodes
[0x40];
2563 PPC_DIRECT
= 0, /* Opcode routine */
2564 PPC_INDIRECT
= 1, /* Indirect opcode table */
2567 static inline int is_indirect_opcode (void *handler
)
2569 return ((unsigned long)handler
& 0x03) == PPC_INDIRECT
;
2572 static inline opc_handler_t
**ind_table(void *handler
)
2574 return (opc_handler_t
**)((unsigned long)handler
& ~3);
2577 /* Instruction table creation */
2578 /* Opcodes tables creation */
2579 static void fill_new_table (opc_handler_t
**table
, int len
)
2583 for (i
= 0; i
< len
; i
++)
2584 table
[i
] = &invalid_handler
;
2587 static int create_new_table (opc_handler_t
**table
, unsigned char idx
)
2589 opc_handler_t
**tmp
;
2591 tmp
= malloc(0x20 * sizeof(opc_handler_t
));
2594 fill_new_table(tmp
, 0x20);
2595 table
[idx
] = (opc_handler_t
*)((unsigned long)tmp
| PPC_INDIRECT
);
2600 static int insert_in_table (opc_handler_t
**table
, unsigned char idx
,
2601 opc_handler_t
*handler
)
2603 if (table
[idx
] != &invalid_handler
)
2605 table
[idx
] = handler
;
2610 static int register_direct_insn (opc_handler_t
**ppc_opcodes
,
2611 unsigned char idx
, opc_handler_t
*handler
)
2613 if (insert_in_table(ppc_opcodes
, idx
, handler
) < 0) {
2614 printf("*** ERROR: opcode %02x already assigned in main "
2615 "opcode table\n", idx
);
2622 static int register_ind_in_table (opc_handler_t
**table
,
2623 unsigned char idx1
, unsigned char idx2
,
2624 opc_handler_t
*handler
)
2626 if (table
[idx1
] == &invalid_handler
) {
2627 if (create_new_table(table
, idx1
) < 0) {
2628 printf("*** ERROR: unable to create indirect table "
2629 "idx=%02x\n", idx1
);
2633 if (!is_indirect_opcode(table
[idx1
])) {
2634 printf("*** ERROR: idx %02x already assigned to a direct "
2639 if (handler
!= NULL
&&
2640 insert_in_table(ind_table(table
[idx1
]), idx2
, handler
) < 0) {
2641 printf("*** ERROR: opcode %02x already assigned in "
2642 "opcode table %02x\n", idx2
, idx1
);
2649 static int register_ind_insn (opc_handler_t
**ppc_opcodes
,
2650 unsigned char idx1
, unsigned char idx2
,
2651 opc_handler_t
*handler
)
2655 ret
= register_ind_in_table(ppc_opcodes
, idx1
, idx2
, handler
);
2660 static int register_dblind_insn (opc_handler_t
**ppc_opcodes
,
2661 unsigned char idx1
, unsigned char idx2
,
2662 unsigned char idx3
, opc_handler_t
*handler
)
2664 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
2665 printf("*** ERROR: unable to join indirect table idx "
2666 "[%02x-%02x]\n", idx1
, idx2
);
2669 if (register_ind_in_table(ind_table(ppc_opcodes
[idx1
]), idx2
, idx3
,
2671 printf("*** ERROR: unable to insert opcode "
2672 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
2679 static int register_insn (opc_handler_t
**ppc_opcodes
, opcode_t
*insn
)
2681 if (insn
->opc2
!= 0xFF) {
2682 if (insn
->opc3
!= 0xFF) {
2683 if (register_dblind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
2684 insn
->opc3
, &insn
->handler
) < 0)
2687 if (register_ind_insn(ppc_opcodes
, insn
->opc1
,
2688 insn
->opc2
, &insn
->handler
) < 0)
2692 if (register_direct_insn(ppc_opcodes
, insn
->opc1
, &insn
->handler
) < 0)
2699 static int test_opcode_table (opc_handler_t
**table
, int len
)
2703 for (i
= 0, count
= 0; i
< len
; i
++) {
2704 /* Consistency fixup */
2705 if (table
[i
] == NULL
)
2706 table
[i
] = &invalid_handler
;
2707 if (table
[i
] != &invalid_handler
) {
2708 if (is_indirect_opcode(table
[i
])) {
2709 tmp
= test_opcode_table(ind_table(table
[i
]), 0x20);
2712 table
[i
] = &invalid_handler
;
2725 static void fix_opcode_tables (opc_handler_t
**ppc_opcodes
)
2727 if (test_opcode_table(ppc_opcodes
, 0x40) == 0)
2728 printf("*** WARNING: no opcode defined !\n");
2731 #define SPR_RIGHTS(rw, priv) (1 << ((2 * (priv)) + (rw)))
2732 #define SPR_UR SPR_RIGHTS(0, 0)
2733 #define SPR_UW SPR_RIGHTS(1, 0)
2734 #define SPR_SR SPR_RIGHTS(0, 1)
2735 #define SPR_SW SPR_RIGHTS(1, 1)
2737 #define spr_set_rights(spr, rights) \
2739 spr_access[(spr) >> 1] |= ((rights) << (4 * ((spr) & 1))); \
2742 static void init_spr_rights (uint32_t pvr
)
2745 spr_set_rights(XER
, SPR_UR
| SPR_UW
| SPR_SR
| SPR_SW
);
2747 spr_set_rights(LR
, SPR_UR
| SPR_UW
| SPR_SR
| SPR_SW
);
2749 spr_set_rights(CTR
, SPR_UR
| SPR_UW
| SPR_SR
| SPR_SW
);
2751 spr_set_rights(V_TBL
, SPR_UR
| SPR_SR
);
2753 spr_set_rights(V_TBU
, SPR_UR
| SPR_SR
);
2754 /* DSISR (SPR 18) */
2755 spr_set_rights(DSISR
, SPR_SR
| SPR_SW
);
2757 spr_set_rights(DAR
, SPR_SR
| SPR_SW
);
2759 spr_set_rights(DECR
, SPR_SR
| SPR_SW
);
2761 spr_set_rights(SDR1
, SPR_SR
| SPR_SW
);
2763 spr_set_rights(SRR0
, SPR_SR
| SPR_SW
);
2765 spr_set_rights(SRR1
, SPR_SR
| SPR_SW
);
2766 /* SPRG0 (SPR 272) */
2767 spr_set_rights(SPRG0
, SPR_SR
| SPR_SW
);
2768 /* SPRG1 (SPR 273) */
2769 spr_set_rights(SPRG1
, SPR_SR
| SPR_SW
);
2770 /* SPRG2 (SPR 274) */
2771 spr_set_rights(SPRG2
, SPR_SR
| SPR_SW
);
2772 /* SPRG3 (SPR 275) */
2773 spr_set_rights(SPRG3
, SPR_SR
| SPR_SW
);
2775 spr_set_rights(ASR
, SPR_SR
| SPR_SW
);
2777 spr_set_rights(EAR
, SPR_SR
| SPR_SW
);
2779 spr_set_rights(O_TBL
, SPR_SW
);
2781 spr_set_rights(O_TBU
, SPR_SW
);
2783 spr_set_rights(PVR
, SPR_SR
);
2784 /* IBAT0U (SPR 528) */
2785 spr_set_rights(IBAT0U
, SPR_SR
| SPR_SW
);
2786 /* IBAT0L (SPR 529) */
2787 spr_set_rights(IBAT0L
, SPR_SR
| SPR_SW
);
2788 /* IBAT1U (SPR 530) */
2789 spr_set_rights(IBAT1U
, SPR_SR
| SPR_SW
);
2790 /* IBAT1L (SPR 531) */
2791 spr_set_rights(IBAT1L
, SPR_SR
| SPR_SW
);
2792 /* IBAT2U (SPR 532) */
2793 spr_set_rights(IBAT2U
, SPR_SR
| SPR_SW
);
2794 /* IBAT2L (SPR 533) */
2795 spr_set_rights(IBAT2L
, SPR_SR
| SPR_SW
);
2796 /* IBAT3U (SPR 534) */
2797 spr_set_rights(IBAT3U
, SPR_SR
| SPR_SW
);
2798 /* IBAT3L (SPR 535) */
2799 spr_set_rights(IBAT3L
, SPR_SR
| SPR_SW
);
2800 /* DBAT0U (SPR 536) */
2801 spr_set_rights(DBAT0U
, SPR_SR
| SPR_SW
);
2802 /* DBAT0L (SPR 537) */
2803 spr_set_rights(DBAT0L
, SPR_SR
| SPR_SW
);
2804 /* DBAT1U (SPR 538) */
2805 spr_set_rights(DBAT1U
, SPR_SR
| SPR_SW
);
2806 /* DBAT1L (SPR 539) */
2807 spr_set_rights(DBAT1L
, SPR_SR
| SPR_SW
);
2808 /* DBAT2U (SPR 540) */
2809 spr_set_rights(DBAT2U
, SPR_SR
| SPR_SW
);
2810 /* DBAT2L (SPR 541) */
2811 spr_set_rights(DBAT2L
, SPR_SR
| SPR_SW
);
2812 /* DBAT3U (SPR 542) */
2813 spr_set_rights(DBAT3U
, SPR_SR
| SPR_SW
);
2814 /* DBAT3L (SPR 543) */
2815 spr_set_rights(DBAT3L
, SPR_SR
| SPR_SW
);
2816 /* FPECR (SPR 1022) */
2817 spr_set_rights(FPECR
, SPR_SR
| SPR_SW
);
2818 /* Special registers for PPC 604 */
2819 if ((pvr
& 0xFFFF0000) == 0x00040000) {
2821 spr_set_rights(IABR
, SPR_SR
| SPR_SW
);
2822 /* DABR (SPR 1013) */
2823 spr_set_rights(DABR
, SPR_SR
| SPR_SW
);
2825 spr_set_rights(HID0
, SPR_SR
| SPR_SW
);
2827 spr_set_rights(PIR
, SPR_SR
| SPR_SW
);
2829 spr_set_rights(PMC1
, SPR_SR
| SPR_SW
);
2831 spr_set_rights(PMC2
, SPR_SR
| SPR_SW
);
2833 spr_set_rights(MMCR0
, SPR_SR
| SPR_SW
);
2835 spr_set_rights(SIA
, SPR_SR
| SPR_SW
);
2837 spr_set_rights(SDA
, SPR_SR
| SPR_SW
);
2839 /* Special registers for MPC740/745/750/755 (aka G3) & IBM 750 */
2840 if ((pvr
& 0xFFFF0000) == 0x00080000 ||
2841 (pvr
& 0xFFFF0000) == 0x70000000) {
2843 spr_set_rights(HID0
, SPR_SR
| SPR_SW
);
2845 spr_set_rights(HID1
, SPR_SR
| SPR_SW
);
2847 spr_set_rights(IABR
, SPR_SR
| SPR_SW
);
2849 spr_set_rights(ICTC
, SPR_SR
| SPR_SW
);
2851 spr_set_rights(L2CR
, SPR_SR
| SPR_SW
);
2853 spr_set_rights(MMCR0
, SPR_SR
| SPR_SW
);
2855 spr_set_rights(MMCR1
, SPR_SR
| SPR_SW
);
2857 spr_set_rights(PMC1
, SPR_SR
| SPR_SW
);
2859 spr_set_rights(PMC2
, SPR_SR
| SPR_SW
);
2861 spr_set_rights(PMC3
, SPR_SR
| SPR_SW
);
2863 spr_set_rights(PMC4
, SPR_SR
| SPR_SW
);
2865 spr_set_rights(SIA
, SPR_SR
| SPR_SW
);
2867 spr_set_rights(SDA
, SPR_SR
| SPR_SW
);
2869 spr_set_rights(THRM1
, SPR_SR
| SPR_SW
);
2871 spr_set_rights(THRM2
, SPR_SR
| SPR_SW
);
2873 spr_set_rights(THRM3
, SPR_SR
| SPR_SW
);
2875 spr_set_rights(UMMCR0
, SPR_UR
| SPR_UW
);
2877 spr_set_rights(UMMCR1
, SPR_UR
| SPR_UW
);
2879 spr_set_rights(UPMC1
, SPR_UR
| SPR_UW
);
2881 spr_set_rights(UPMC2
, SPR_UR
| SPR_UW
);
2883 spr_set_rights(UPMC3
, SPR_UR
| SPR_UW
);
2885 spr_set_rights(UPMC4
, SPR_UR
| SPR_UW
);
2887 spr_set_rights(USIA
, SPR_UR
| SPR_UW
);
2889 /* MPC755 has special registers */
2890 if (pvr
== 0x00083100) {
2892 spr_set_rights(SPRG4
, SPR_SR
| SPR_SW
);
2894 spr_set_rights(SPRG5
, SPR_SR
| SPR_SW
);
2896 spr_set_rights(SPRG6
, SPR_SR
| SPR_SW
);
2898 spr_set_rights(SPRG7
, SPR_SR
| SPR_SW
);
2900 spr_set_rights(IBAT4U
, SPR_SR
| SPR_SW
);
2902 spr_set_rights(IBAT4L
, SPR_SR
| SPR_SW
);
2904 spr_set_rights(IBAT5U
, SPR_SR
| SPR_SW
);
2906 spr_set_rights(IBAT5L
, SPR_SR
| SPR_SW
);
2908 spr_set_rights(IBAT6U
, SPR_SR
| SPR_SW
);
2910 spr_set_rights(IBAT6L
, SPR_SR
| SPR_SW
);
2912 spr_set_rights(IBAT7U
, SPR_SR
| SPR_SW
);
2914 spr_set_rights(IBAT7L
, SPR_SR
| SPR_SW
);
2916 spr_set_rights(DBAT4U
, SPR_SR
| SPR_SW
);
2918 spr_set_rights(DBAT4L
, SPR_SR
| SPR_SW
);
2920 spr_set_rights(DBAT5U
, SPR_SR
| SPR_SW
);
2922 spr_set_rights(DBAT5L
, SPR_SR
| SPR_SW
);
2924 spr_set_rights(DBAT6U
, SPR_SR
| SPR_SW
);
2926 spr_set_rights(DBAT6L
, SPR_SR
| SPR_SW
);
2928 spr_set_rights(DBAT7U
, SPR_SR
| SPR_SW
);
2930 spr_set_rights(DBAT7L
, SPR_SR
| SPR_SW
);
2932 spr_set_rights(DMISS
, SPR_SR
| SPR_SW
);
2934 spr_set_rights(DCMP
, SPR_SR
| SPR_SW
);
2936 spr_set_rights(DHASH1
, SPR_SR
| SPR_SW
);
2938 spr_set_rights(DHASH2
, SPR_SR
| SPR_SW
);
2940 spr_set_rights(IMISS
, SPR_SR
| SPR_SW
);
2942 spr_set_rights(ICMP
, SPR_SR
| SPR_SW
);
2944 spr_set_rights(RPA
, SPR_SR
| SPR_SW
);
2946 spr_set_rights(HID2
, SPR_SR
| SPR_SW
);
2948 spr_set_rights(L2PM
, SPR_SR
| SPR_SW
);
2952 /*****************************************************************************/
2953 /* PPC "main stream" common instructions (no optional ones) */
2955 typedef struct ppc_proc_t
{
2960 typedef struct ppc_def_t
{
2962 unsigned long pvr_mask
;
2966 static ppc_proc_t ppc_proc_common
= {
2967 .flags
= PPC_COMMON
,
2971 static ppc_proc_t ppc_proc_G3
= {
2976 static ppc_def_t ppc_defs
[] =
2978 /* MPC740/745/750/755 (G3) */
2981 .pvr_mask
= 0xFFFF0000,
2982 .proc
= &ppc_proc_G3
,
2984 /* IBM 750FX (G3 embedded) */
2987 .pvr_mask
= 0xFFFF0000,
2988 .proc
= &ppc_proc_G3
,
2990 /* Fallback (generic PPC) */
2993 .pvr_mask
= 0x00000000,
2994 .proc
= &ppc_proc_common
,
2998 static int create_ppc_proc (opc_handler_t
**ppc_opcodes
, unsigned long pvr
)
3000 opcode_t
*opc
, *start
, *end
;
3003 fill_new_table(ppc_opcodes
, 0x40);
3004 for (i
= 0; ; i
++) {
3005 if ((ppc_defs
[i
].pvr
& ppc_defs
[i
].pvr_mask
) ==
3006 (pvr
& ppc_defs
[i
].pvr_mask
)) {
3007 flags
= ppc_defs
[i
].proc
->flags
;
3012 if (&opc_start
< &opc_end
) {
3019 for (opc
= start
+ 1; opc
!= end
; opc
++) {
3020 if ((opc
->handler
.type
& flags
) != 0)
3021 if (register_insn(ppc_opcodes
, opc
) < 0) {
3022 printf("*** ERROR initializing PPC instruction "
3023 "0x%02x 0x%02x 0x%02x\n", opc
->opc1
, opc
->opc2
,
3028 fix_opcode_tables(ppc_opcodes
);
3034 /*****************************************************************************/
3035 /* Misc PPC helpers */
3037 void cpu_dump_state(CPUState
*env
, FILE *f
,
3038 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
3043 cpu_fprintf(f
, "nip=0x%08x LR=0x%08x CTR=0x%08x XER=0x%08x "
3044 "MSR=0x%08x\n", env
->nip
, env
->lr
, env
->ctr
,
3045 _load_xer(env
), _load_msr(env
));
3046 for (i
= 0; i
< 32; i
++) {
3048 cpu_fprintf(f
, "GPR%02d:", i
);
3049 cpu_fprintf(f
, " %08x", env
->gpr
[i
]);
3051 cpu_fprintf(f
, "\n");
3053 cpu_fprintf(f
, "CR: 0x");
3054 for (i
= 0; i
< 8; i
++)
3055 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
3056 cpu_fprintf(f
, " [");
3057 for (i
= 0; i
< 8; i
++) {
3059 if (env
->crf
[i
] & 0x08)
3061 else if (env
->crf
[i
] & 0x04)
3063 else if (env
->crf
[i
] & 0x02)
3065 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
3067 cpu_fprintf(f
, " ] ");
3068 cpu_fprintf(f
, "TB: 0x%08x %08x\n", cpu_ppc_load_tbu(env
),
3069 cpu_ppc_load_tbl(env
));
3070 for (i
= 0; i
< 16; i
++) {
3072 cpu_fprintf(f
, "FPR%02d:", i
);
3073 cpu_fprintf(f
, " %016llx", *((uint64_t *)&env
->fpr
[i
]));
3075 cpu_fprintf(f
, "\n");
3077 cpu_fprintf(f
, "SRR0 0x%08x SRR1 0x%08x DECR=0x%08x\n",
3078 env
->spr
[SRR0
], env
->spr
[SRR1
], cpu_ppc_load_decr(env
));
3079 cpu_fprintf(f
, "reservation 0x%08x\n", env
->reserve
);
3082 CPUPPCState
*cpu_ppc_init(void)
3088 env
= qemu_mallocz(sizeof(CPUPPCState
));
3091 // env->spr[PVR] = 0; /* Basic PPC */
3092 env
->spr
[PVR
] = 0x00080100; /* G3 CPU */
3093 // env->spr[PVR] = 0x00083100; /* MPC755 (G3 embedded) */
3094 // env->spr[PVR] = 0x00070100; /* IBM 750FX */
3096 #if defined (DO_SINGLE_STEP)
3097 /* Single step trace mode */
3100 msr_fp
= 1; /* Allow floating point exceptions */
3101 msr_me
= 1; /* Allow machine check exceptions */
3102 #if defined(CONFIG_USER_ONLY)
3104 cpu_ppc_register(env
, 0x00080000);
3106 env
->nip
= 0xFFFFFFFC;
3108 cpu_single_env
= env
;
3112 int cpu_ppc_register (CPUPPCState
*env
, uint32_t pvr
)
3114 env
->spr
[PVR
] = pvr
;
3115 if (create_ppc_proc(ppc_opcodes
, env
->spr
[PVR
]) < 0)
3117 init_spr_rights(env
->spr
[PVR
]);
3122 void cpu_ppc_close(CPUPPCState
*env
)
3124 /* Should also remove all opcode tables... */
3128 /*****************************************************************************/
3129 int gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
3132 DisasContext ctx
, *ctxp
= &ctx
;
3133 opc_handler_t
**table
, *handler
;
3134 target_ulong pc_start
;
3135 uint16_t *gen_opc_end
;
3139 gen_opc_ptr
= gen_opc_buf
;
3140 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3141 gen_opparam_ptr
= gen_opparam_buf
;
3144 ctx
.exception
= EXCP_NONE
;
3145 #if defined(CONFIG_USER_ONLY)
3148 ctx
.supervisor
= 1 - msr_pr
;
3149 ctx
.mem_idx
= 1 - msr_pr
;
3151 ctx
.fpu_enabled
= msr_fp
;
3152 #if defined (DO_SINGLE_STEP)
3153 /* Single step trace mode */
3156 /* Set env in case of segfault during code fetch */
3157 while (ctx
.exception
== EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
3159 j
= gen_opc_ptr
- gen_opc_buf
;
3163 gen_opc_instr_start
[lj
++] = 0;
3164 gen_opc_pc
[lj
] = ctx
.nip
;
3165 gen_opc_instr_start
[lj
] = 1;
3168 #if defined PPC_DEBUG_DISAS
3169 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3170 fprintf(logfile
, "----------------\n");
3171 fprintf(logfile
, "nip=%08x super=%d ir=%d\n",
3172 ctx
.nip
, 1 - msr_pr
, msr_ir
);
3175 ctx
.opcode
= ldl_code(ctx
.nip
);
3176 #if defined PPC_DEBUG_DISAS
3177 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3178 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x)\n",
3179 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
3184 table
= ppc_opcodes
;
3185 handler
= table
[opc1(ctx
.opcode
)];
3186 if (is_indirect_opcode(handler
)) {
3187 table
= ind_table(handler
);
3188 handler
= table
[opc2(ctx
.opcode
)];
3189 if (is_indirect_opcode(handler
)) {
3190 table
= ind_table(handler
);
3191 handler
= table
[opc3(ctx
.opcode
)];
3194 /* Is opcode *REALLY* valid ? */
3195 if (handler
->handler
== &gen_invalid
) {
3197 fprintf(logfile
, "invalid/unsupported opcode: "
3198 "%02x - %02x - %02x (%08x) 0x%08x %d\n",
3199 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
3200 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, msr_ir
);
3202 printf("invalid/unsupported opcode: "
3203 "%02x - %02x - %02x (%08x) 0x%08x %d\n",
3204 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
3205 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, msr_ir
);
3208 if ((ctx
.opcode
& handler
->inval
) != 0) {
3210 fprintf(logfile
, "invalid bits: %08x for opcode: "
3211 "%02x -%02x - %02x (0x%08x) (0x%08x)\n",
3212 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
3213 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
3214 ctx
.opcode
, ctx
.nip
- 4);
3216 printf("invalid bits: %08x for opcode: "
3217 "%02x -%02x - %02x (0x%08x) (0x%08x)\n",
3218 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
3219 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
3220 ctx
.opcode
, ctx
.nip
- 4);
3226 (*(handler
->handler
))(&ctx
);
3227 /* Check trace mode exceptions */
3228 if ((msr_be
&& ctx
.exception
== EXCP_BRANCH
) ||
3229 /* Check in single step trace mode
3230 * we need to stop except if:
3231 * - rfi, trap or syscall
3232 * - first instruction of an exception handler
3234 (msr_se
&& (ctx
.nip
< 0x100 ||
3236 (ctx
.nip
& 0xFC) != 0x04) &&
3237 ctx
.exception
!= EXCP_SYSCALL
&& ctx
.exception
!= EXCP_RFI
&&
3238 ctx
.exception
!= EXCP_TRAP
)) {
3239 RET_EXCP(ctxp
, EXCP_TRACE
, 0);
3241 /* if we reach a page boundary, stop generation */
3242 if ((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) {
3243 RET_EXCP(ctxp
, EXCP_BRANCH
, 0);
3246 if (ctx
.exception
== EXCP_NONE
) {
3247 gen_op_b((unsigned long)ctx
.tb
, ctx
.nip
);
3248 } else if (ctx
.exception
!= EXCP_BRANCH
) {
3252 /* TO BE FIXED: T0 hasn't got a proper value, which makes tb_add_jump
3253 * do bad business and then qemu crashes !
3257 /* Generate the return instruction */
3259 *gen_opc_ptr
= INDEX_op_end
;
3261 j
= gen_opc_ptr
- gen_opc_buf
;
3264 gen_opc_instr_start
[lj
++] = 0;
3272 tb
->size
= ctx
.nip
- pc_start
;
3275 if (loglevel
& CPU_LOG_TB_CPU
) {
3276 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
3277 cpu_dump_state(env
, logfile
, fprintf
, 0);
3279 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3280 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
3281 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, 0);
3282 fprintf(logfile
, "\n");
3284 if (loglevel
& CPU_LOG_TB_OP
) {
3285 fprintf(logfile
, "OP:\n");
3286 dump_ops(gen_opc_buf
, gen_opparam_buf
);
3287 fprintf(logfile
, "\n");
3293 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3295 return gen_intermediate_code_internal(env
, tb
, 0);
3298 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3300 return gen_intermediate_code_internal(env
, tb
, 1);