On ppc32 make tb_set_jmp_target1 behave like it does on a ppc64
[qemu-kvm/fedora.git] / tcg / ppc / tcg-target.c
blob218e4bc703d29e3f3c9e364af4fcf1e8aef6b136
1 /*
2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 static uint8_t *tb_ret_addr;
27 #define FAST_PATH
28 #if TARGET_PHYS_ADDR_BITS <= 32
29 #define ADDEND_OFFSET 0
30 #else
31 #define ADDEND_OFFSET 4
32 #endif
34 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
35 "r0",
36 "r1",
37 "rp",
38 "r3",
39 "r4",
40 "r5",
41 "r6",
42 "r7",
43 "r8",
44 "r9",
45 "r10",
46 "r11",
47 "r12",
48 "r13",
49 "r14",
50 "r15",
51 "r16",
52 "r17",
53 "r18",
54 "r19",
55 "r20",
56 "r21",
57 "r22",
58 "r23",
59 "r24",
60 "r25",
61 "r26",
62 "r27",
63 "r28",
64 "r29",
65 "r30",
66 "r31"
69 static const int tcg_target_reg_alloc_order[] = {
70 TCG_REG_R14,
71 TCG_REG_R15,
72 TCG_REG_R16,
73 TCG_REG_R17,
74 TCG_REG_R18,
75 TCG_REG_R19,
76 TCG_REG_R20,
77 TCG_REG_R21,
78 TCG_REG_R22,
79 TCG_REG_R23,
80 TCG_REG_R28,
81 TCG_REG_R29,
82 TCG_REG_R30,
83 TCG_REG_R31,
84 TCG_REG_R3,
85 TCG_REG_R4,
86 TCG_REG_R5,
87 TCG_REG_R6,
88 TCG_REG_R7,
89 TCG_REG_R8,
90 TCG_REG_R9,
91 TCG_REG_R10,
92 TCG_REG_R11,
93 TCG_REG_R12,
94 TCG_REG_R13,
95 TCG_REG_R0,
96 TCG_REG_R1,
97 TCG_REG_R2,
98 TCG_REG_R24,
99 TCG_REG_R25,
100 TCG_REG_R26,
101 TCG_REG_R27
104 static const int tcg_target_call_iarg_regs[] = {
105 TCG_REG_R3,
106 TCG_REG_R4,
107 TCG_REG_R5,
108 TCG_REG_R6,
109 TCG_REG_R7,
110 TCG_REG_R8,
111 TCG_REG_R9,
112 TCG_REG_R10
115 static const int tcg_target_call_oarg_regs[2] = {
116 TCG_REG_R3,
117 TCG_REG_R4
120 static const int tcg_target_callee_save_regs[] = {
121 TCG_REG_R14,
122 TCG_REG_R15,
123 TCG_REG_R16,
124 TCG_REG_R17,
125 TCG_REG_R18,
126 TCG_REG_R19,
127 TCG_REG_R20,
128 TCG_REG_R21,
129 TCG_REG_R22,
130 TCG_REG_R23,
131 TCG_REG_R28,
132 TCG_REG_R29,
133 TCG_REG_R30,
134 TCG_REG_R31
137 static uint32_t reloc_pc24_val (void *pc, tcg_target_long target)
139 tcg_target_long disp;
141 disp = target - (tcg_target_long) pc;
142 if ((disp << 6) >> 6 != disp)
143 tcg_abort ();
145 return disp & 0x3fffffc;
148 static void reloc_pc24 (void *pc, tcg_target_long target)
150 *(uint32_t *) pc = (*(uint32_t *) pc & ~0x3fffffc)
151 | reloc_pc24_val (pc, target);
154 static uint16_t reloc_pc14_val (void *pc, tcg_target_long target)
156 tcg_target_long disp;
158 disp = target - (tcg_target_long) pc;
159 if (disp != (int16_t) disp)
160 tcg_abort ();
162 return disp & 0xfffc;
165 static void reloc_pc14 (void *pc, tcg_target_long target)
167 *(uint32_t *) pc = (*(uint32_t *) pc & ~0xfffc)
168 | reloc_pc14_val (pc, target);
171 static void patch_reloc(uint8_t *code_ptr, int type,
172 tcg_target_long value, tcg_target_long addend)
174 value += addend;
175 switch (type) {
176 case R_PPC_REL14:
177 reloc_pc14 (code_ptr, value);
178 break;
179 case R_PPC_REL24:
180 reloc_pc24 (code_ptr, value);
181 break;
182 default:
183 tcg_abort();
187 /* maximum number of register used for input function arguments */
188 static int tcg_target_get_call_iarg_regs_count(int flags)
190 return sizeof (tcg_target_call_iarg_regs) / sizeof (tcg_target_call_iarg_regs[0]);
193 /* parse target specific constraints */
194 static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
196 const char *ct_str;
198 ct_str = *pct_str;
199 switch (ct_str[0]) {
200 case 'A': case 'B': case 'C': case 'D':
201 ct->ct |= TCG_CT_REG;
202 tcg_regset_set_reg(ct->u.regs, 3 + ct_str[0] - 'A');
203 break;
204 case 'r':
205 ct->ct |= TCG_CT_REG;
206 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
207 break;
208 case 'L': /* qemu_ld constraint */
209 ct->ct |= TCG_CT_REG;
210 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
211 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
212 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
213 break;
214 case 'K': /* qemu_st[8..32] constraint */
215 ct->ct |= TCG_CT_REG;
216 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
217 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
218 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
219 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R5);
220 #if TARGET_LONG_BITS == 64
221 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R6);
222 #endif
223 break;
224 case 'M': /* qemu_st64 constraint */
225 ct->ct |= TCG_CT_REG;
226 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
227 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
228 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
229 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R5);
230 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R6);
231 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R7);
232 break;
233 default:
234 return -1;
236 ct_str++;
237 *pct_str = ct_str;
238 return 0;
241 /* test if a constant matches the constraint */
242 static int tcg_target_const_match(tcg_target_long val,
243 const TCGArgConstraint *arg_ct)
245 int ct;
247 ct = arg_ct->ct;
248 if (ct & TCG_CT_CONST)
249 return 1;
250 return 0;
253 #define OPCD(opc) ((opc)<<26)
254 #define XO31(opc) (OPCD(31)|((opc)<<1))
255 #define XO19(opc) (OPCD(19)|((opc)<<1))
257 #define B OPCD(18)
258 #define BC OPCD(16)
259 #define LBZ OPCD(34)
260 #define LHZ OPCD(40)
261 #define LHA OPCD(42)
262 #define LWZ OPCD(32)
263 #define STB OPCD(38)
264 #define STH OPCD(44)
265 #define STW OPCD(36)
267 #define ADDI OPCD(14)
268 #define ADDIS OPCD(15)
269 #define ORI OPCD(24)
270 #define ORIS OPCD(25)
271 #define XORI OPCD(26)
272 #define XORIS OPCD(27)
273 #define ANDI OPCD(28)
274 #define ANDIS OPCD(29)
275 #define MULLI OPCD( 7)
276 #define CMPLI OPCD(10)
277 #define CMPI OPCD(11)
279 #define LWZU OPCD(33)
280 #define STWU OPCD(37)
282 #define RLWINM OPCD(21)
284 #define BCLR XO19( 16)
285 #define BCCTR XO19(528)
286 #define CRAND XO19(257)
287 #define CRANDC XO19(129)
288 #define CRNAND XO19(225)
289 #define CROR XO19(449)
291 #define EXTSB XO31(954)
292 #define EXTSH XO31(922)
293 #define ADD XO31(266)
294 #define ADDE XO31(138)
295 #define ADDC XO31( 10)
296 #define AND XO31( 28)
297 #define SUBF XO31( 40)
298 #define SUBFC XO31( 8)
299 #define SUBFE XO31(136)
300 #define OR XO31(444)
301 #define XOR XO31(316)
302 #define MULLW XO31(235)
303 #define MULHWU XO31( 11)
304 #define DIVW XO31(491)
305 #define DIVWU XO31(459)
306 #define CMP XO31( 0)
307 #define CMPL XO31( 32)
308 #define LHBRX XO31(790)
309 #define LWBRX XO31(534)
310 #define STHBRX XO31(918)
311 #define STWBRX XO31(662)
312 #define MFSPR XO31(339)
313 #define MTSPR XO31(467)
314 #define SRAWI XO31(824)
315 #define NEG XO31(104)
317 #define LBZX XO31( 87)
318 #define LHZX XO31(276)
319 #define LHAX XO31(343)
320 #define LWZX XO31( 23)
321 #define STBX XO31(215)
322 #define STHX XO31(407)
323 #define STWX XO31(151)
325 #define SPR(a,b) ((((a)<<5)|(b))<<11)
326 #define LR SPR(8, 0)
327 #define CTR SPR(9, 0)
329 #define SLW XO31( 24)
330 #define SRW XO31(536)
331 #define SRAW XO31(792)
333 #define LMW OPCD(46)
334 #define STMW OPCD(47)
336 #define TW XO31(4)
337 #define TRAP (TW | TO (31))
339 #define RT(r) ((r)<<21)
340 #define RS(r) ((r)<<21)
341 #define RA(r) ((r)<<16)
342 #define RB(r) ((r)<<11)
343 #define TO(t) ((t)<<21)
344 #define SH(s) ((s)<<11)
345 #define MB(b) ((b)<<6)
346 #define ME(e) ((e)<<1)
347 #define BO(o) ((o)<<21)
349 #define LK 1
351 #define TAB(t,a,b) (RT(t) | RA(a) | RB(b))
352 #define SAB(s,a,b) (RS(s) | RA(a) | RB(b))
354 #define BF(n) ((n)<<23)
355 #define BI(n, c) (((c)+((n)*4))<<16)
356 #define BT(n, c) (((c)+((n)*4))<<21)
357 #define BA(n, c) (((c)+((n)*4))<<16)
358 #define BB(n, c) (((c)+((n)*4))<<11)
360 #define BO_COND_TRUE BO (12)
361 #define BO_COND_FALSE BO (4)
362 #define BO_ALWAYS BO (20)
364 enum {
365 CR_LT,
366 CR_GT,
367 CR_EQ,
368 CR_SO
371 static const uint32_t tcg_to_bc[10] = {
372 [TCG_COND_EQ] = BC | BI (7, CR_EQ) | BO_COND_TRUE,
373 [TCG_COND_NE] = BC | BI (7, CR_EQ) | BO_COND_FALSE,
374 [TCG_COND_LT] = BC | BI (7, CR_LT) | BO_COND_TRUE,
375 [TCG_COND_GE] = BC | BI (7, CR_LT) | BO_COND_FALSE,
376 [TCG_COND_LE] = BC | BI (7, CR_GT) | BO_COND_FALSE,
377 [TCG_COND_GT] = BC | BI (7, CR_GT) | BO_COND_TRUE,
378 [TCG_COND_LTU] = BC | BI (7, CR_LT) | BO_COND_TRUE,
379 [TCG_COND_GEU] = BC | BI (7, CR_LT) | BO_COND_FALSE,
380 [TCG_COND_LEU] = BC | BI (7, CR_GT) | BO_COND_FALSE,
381 [TCG_COND_GTU] = BC | BI (7, CR_GT) | BO_COND_TRUE,
384 static void tcg_out_mov(TCGContext *s, int ret, int arg)
386 tcg_out32 (s, OR | SAB (arg, ret, arg));
389 static void tcg_out_movi(TCGContext *s, TCGType type,
390 int ret, tcg_target_long arg)
392 if (arg == (int16_t) arg)
393 tcg_out32 (s, ADDI | RT (ret) | RA (0) | (arg & 0xffff));
394 else {
395 tcg_out32 (s, ADDIS | RT (ret) | RA (0) | ((arg >> 16) & 0xffff));
396 if (arg & 0xffff)
397 tcg_out32 (s, ORI | RS (ret) | RA (ret) | (arg & 0xffff));
401 static void tcg_out_ldst (TCGContext *s, int ret, int addr,
402 int offset, int op1, int op2)
404 if (offset == (int16_t) offset)
405 tcg_out32 (s, op1 | RT (ret) | RA (addr) | (offset & 0xffff));
406 else {
407 tcg_out_movi (s, TCG_TYPE_I32, 0, offset);
408 tcg_out32 (s, op2 | RT (ret) | RA (addr) | RB (0));
412 static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target)
414 tcg_target_long disp;
416 disp = target - (tcg_target_long) s->code_ptr;
417 if ((disp << 6) >> 6 == disp)
418 tcg_out32 (s, B | (disp & 0x3fffffc) | mask);
419 else {
420 tcg_out_movi (s, TCG_TYPE_I32, 0, (tcg_target_long) target);
421 tcg_out32 (s, MTSPR | RS (0) | CTR);
422 tcg_out32 (s, BCCTR | BO_ALWAYS | mask);
426 #if defined(CONFIG_SOFTMMU)
427 extern void __ldb_mmu(void);
428 extern void __ldw_mmu(void);
429 extern void __ldl_mmu(void);
430 extern void __ldq_mmu(void);
432 extern void __stb_mmu(void);
433 extern void __stw_mmu(void);
434 extern void __stl_mmu(void);
435 extern void __stq_mmu(void);
437 static void *qemu_ld_helpers[4] = {
438 __ldb_mmu,
439 __ldw_mmu,
440 __ldl_mmu,
441 __ldq_mmu,
444 static void *qemu_st_helpers[4] = {
445 __stb_mmu,
446 __stw_mmu,
447 __stl_mmu,
448 __stq_mmu,
450 #endif
452 static void tcg_out_qemu_ld (TCGContext *s, const TCGArg *args, int opc)
454 int addr_reg, data_reg, data_reg2, r0, mem_index, s_bits, bswap;
455 #ifdef CONFIG_SOFTMMU
456 int r1, r2;
457 void *label1_ptr, *label2_ptr;
458 #endif
459 #if TARGET_LONG_BITS == 64
460 int addr_reg2;
461 #endif
463 data_reg = *args++;
464 if (opc == 3)
465 data_reg2 = *args++;
466 else
467 data_reg2 = 0;
468 addr_reg = *args++;
469 #if TARGET_LONG_BITS == 64
470 addr_reg2 = *args++;
471 #endif
472 mem_index = *args;
473 s_bits = opc & 3;
475 #ifdef CONFIG_SOFTMMU
476 r0 = 3;
477 r1 = 4;
478 r2 = 0;
480 tcg_out32 (s, (RLWINM
481 | RA (r0)
482 | RS (addr_reg)
483 | SH (32 - (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS))
484 | MB (32 - (CPU_TLB_BITS + CPU_TLB_ENTRY_BITS))
485 | ME (31 - CPU_TLB_ENTRY_BITS)
488 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (TCG_AREG0));
489 tcg_out32 (s, (LWZU
490 | RT (r1)
491 | RA (r0)
492 | offsetof (CPUState, tlb_table[mem_index][0].addr_read)
495 tcg_out32 (s, (RLWINM
496 | RA (r2)
497 | RS (addr_reg)
498 | SH (0)
499 | MB ((32 - s_bits) & 31)
500 | ME (31 - TARGET_PAGE_BITS)
504 tcg_out32 (s, CMP | BF (7) | RA (r2) | RB (r1));
505 #if TARGET_LONG_BITS == 64
506 tcg_out32 (s, LWZ | RT (r1) | RA (r0) | 4);
507 tcg_out32 (s, CMP | BF (6) | RA (addr_reg2) | RB (r1));
508 tcg_out32 (s, CRAND | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
509 #endif
511 label1_ptr = s->code_ptr;
512 #ifdef FAST_PATH
513 tcg_out32 (s, BC | BI (7, CR_EQ) | BO_COND_TRUE);
514 #endif
516 /* slow path */
517 #if TARGET_LONG_BITS == 32
518 tcg_out_mov (s, 3, addr_reg);
519 tcg_out_movi (s, TCG_TYPE_I32, 4, mem_index);
520 #else
521 tcg_out_mov (s, 3, addr_reg2);
522 tcg_out_mov (s, 4, addr_reg);
523 tcg_out_movi (s, TCG_TYPE_I32, 5, mem_index);
524 #endif
526 tcg_out_b (s, LK, (tcg_target_long) qemu_ld_helpers[s_bits]);
527 switch (opc) {
528 case 0|4:
529 tcg_out32 (s, EXTSB | RA (data_reg) | RS (3));
530 break;
531 case 1|4:
532 tcg_out32 (s, EXTSH | RA (data_reg) | RS (3));
533 break;
534 case 0:
535 case 1:
536 case 2:
537 if (data_reg != 3)
538 tcg_out_mov (s, data_reg, 3);
539 break;
540 case 3:
541 if (data_reg == 3) {
542 if (data_reg2 == 4) {
543 tcg_out_mov (s, 0, 4);
544 tcg_out_mov (s, 4, 3);
545 tcg_out_mov (s, 3, 0);
547 else {
548 tcg_out_mov (s, data_reg2, 3);
549 tcg_out_mov (s, 3, 4);
552 else {
553 if (data_reg != 4) tcg_out_mov (s, data_reg, 4);
554 if (data_reg2 != 3) tcg_out_mov (s, data_reg2, 3);
556 break;
558 label2_ptr = s->code_ptr;
559 tcg_out32 (s, B);
561 /* label1: fast path */
562 #ifdef FAST_PATH
563 reloc_pc14 (label1_ptr, (tcg_target_long) s->code_ptr);
564 #endif
566 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
567 tcg_out32 (s, (LWZ
568 | RT (r0)
569 | RA (r0)
570 | (ADDEND_OFFSET + offsetof (CPUTLBEntry, addend)
571 - offsetof (CPUTLBEntry, addr_read))
573 /* r0 = env->tlb_table[mem_index][index].addend */
574 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (addr_reg));
575 /* r0 = env->tlb_table[mem_index][index].addend + addr */
577 #else /* !CONFIG_SOFTMMU */
578 r0 = addr_reg;
579 #endif
581 #ifdef TARGET_WORDS_BIGENDIAN
582 bswap = 0;
583 #else
584 bswap = 1;
585 #endif
586 switch (opc) {
587 default:
588 case 0:
589 tcg_out32 (s, LBZ | RT (data_reg) | RA (r0));
590 break;
591 case 0|4:
592 tcg_out32 (s, LBZ | RT (data_reg) | RA (r0));
593 tcg_out32 (s, EXTSB | RA (data_reg) | RS (data_reg));
594 break;
595 case 1:
596 if (bswap) tcg_out32 (s, LHBRX | RT (data_reg) | RB (r0));
597 else tcg_out32 (s, LHZ | RT (data_reg) | RA (r0));
598 break;
599 case 1|4:
600 if (bswap) {
601 tcg_out32 (s, LHBRX | RT (data_reg) | RB (r0));
602 tcg_out32 (s, EXTSH | RA (data_reg) | RS (data_reg));
604 else tcg_out32 (s, LHA | RT (data_reg) | RA (r0));
605 break;
606 case 2:
607 if (bswap) tcg_out32 (s, LWBRX | RT (data_reg) | RB (r0));
608 else tcg_out32 (s, LWZ | RT (data_reg)| RA (r0));
609 break;
610 case 3:
611 if (bswap) {
612 if (r0 == data_reg) {
613 tcg_out32 (s, LWBRX | RT (0) | RB (r0));
614 tcg_out32 (s, ADDI | RT (r0) | RA (r0) | 4);
615 tcg_out32 (s, LWBRX | RT (data_reg2) | RB (r0));
616 tcg_out_mov (s, data_reg, 0);
618 else {
619 tcg_out32 (s, LWBRX | RT (data_reg) | RB (r0));
620 tcg_out32 (s, ADDI | RT (r0) | RA (r0) | 4);
621 tcg_out32 (s, LWBRX | RT (data_reg2) | RB (r0));
624 else {
625 if (r0 == data_reg2) {
626 tcg_out32 (s, LWZ | RT (0) | RA (r0));
627 tcg_out32 (s, LWZ | RT (data_reg) | RA (r0) | 4);
628 tcg_out_mov (s, data_reg2, 0);
630 else {
631 tcg_out32 (s, LWZ | RT (data_reg2) | RA (r0));
632 tcg_out32 (s, LWZ | RT (data_reg) | RA (r0) | 4);
635 break;
638 #ifdef CONFIG_SOFTMMU
639 reloc_pc24 (label2_ptr, (tcg_target_long) s->code_ptr);
640 #endif
643 static void tcg_out_qemu_st (TCGContext *s, const TCGArg *args, int opc)
645 int addr_reg, r0, r1, data_reg, data_reg2, mem_index, bswap;
646 #ifdef CONFIG_SOFTMMU
647 int r2, ir;
648 void *label1_ptr, *label2_ptr;
649 #endif
650 #if TARGET_LONG_BITS == 64
651 int addr_reg2;
652 #endif
654 data_reg = *args++;
655 if (opc == 3)
656 data_reg2 = *args++;
657 else
658 data_reg2 = 0;
659 addr_reg = *args++;
660 #if TARGET_LONG_BITS == 64
661 addr_reg2 = *args++;
662 #endif
663 mem_index = *args;
665 #ifdef CONFIG_SOFTMMU
666 r0 = 3;
667 r1 = 4;
668 r2 = 0;
670 tcg_out32 (s, (RLWINM
671 | RA (r0)
672 | RS (addr_reg)
673 | SH (32 - (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS))
674 | MB (32 - (CPU_TLB_ENTRY_BITS + CPU_TLB_BITS))
675 | ME (31 - CPU_TLB_ENTRY_BITS)
678 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (TCG_AREG0));
679 tcg_out32 (s, (LWZU
680 | RT (r1)
681 | RA (r0)
682 | offsetof (CPUState, tlb_table[mem_index][0].addr_write)
685 tcg_out32 (s, (RLWINM
686 | RA (r2)
687 | RS (addr_reg)
688 | SH (0)
689 | MB ((32 - opc) & 31)
690 | ME (31 - TARGET_PAGE_BITS)
694 tcg_out32 (s, CMP | (7 << 23) | RA (r2) | RB (r1));
695 #if TARGET_LONG_BITS == 64
696 tcg_out32 (s, LWZ | RT (r1) | RA (r0) | 4);
697 tcg_out32 (s, CMP | BF (6) | RA (addr_reg2) | RB (r1));
698 tcg_out32 (s, CRAND | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
699 #endif
701 label1_ptr = s->code_ptr;
702 #ifdef FAST_PATH
703 tcg_out32 (s, BC | BI (7, CR_EQ) | BO_COND_TRUE);
704 #endif
706 /* slow path */
707 #if TARGET_LONG_BITS == 32
708 tcg_out_mov (s, 3, addr_reg);
709 ir = 4;
710 #else
711 tcg_out_mov (s, 3, addr_reg2);
712 tcg_out_mov (s, 4, addr_reg);
713 ir = 5;
714 #endif
716 switch (opc) {
717 case 0:
718 tcg_out32 (s, (RLWINM
719 | RA (ir)
720 | RS (data_reg)
721 | SH (0)
722 | MB (24)
723 | ME (31)));
724 break;
725 case 1:
726 tcg_out32 (s, (RLWINM
727 | RA (ir)
728 | RS (data_reg)
729 | SH (0)
730 | MB (16)
731 | ME (31)));
732 break;
733 case 2:
734 tcg_out_mov (s, ir, data_reg);
735 break;
736 case 3:
737 tcg_out_mov (s, 5, data_reg2);
738 tcg_out_mov (s, 6, data_reg);
739 ir = 6;
740 break;
742 ir++;
744 tcg_out_movi (s, TCG_TYPE_I32, ir, mem_index);
745 tcg_out_b (s, LK, (tcg_target_long) qemu_st_helpers[opc]);
746 label2_ptr = s->code_ptr;
747 tcg_out32 (s, B);
749 /* label1: fast path */
750 #ifdef FAST_PATH
751 reloc_pc14 (label1_ptr, (tcg_target_long) s->code_ptr);
752 #endif
754 tcg_out32 (s, (LWZ
755 | RT (r0)
756 | RA (r0)
757 | (ADDEND_OFFSET + offsetof (CPUTLBEntry, addend)
758 - offsetof (CPUTLBEntry, addr_write))
760 /* r0 = env->tlb_table[mem_index][index].addend */
761 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (addr_reg));
762 /* r0 = env->tlb_table[mem_index][index].addend + addr */
764 #else /* !CONFIG_SOFTMMU */
765 r1 = 4;
766 r0 = addr_reg;
767 #endif
769 #ifdef TARGET_WORDS_BIGENDIAN
770 bswap = 0;
771 #else
772 bswap = 1;
773 #endif
774 switch (opc) {
775 case 0:
776 tcg_out32 (s, STB | RS (data_reg) | RA (r0));
777 break;
778 case 1:
779 if (bswap) tcg_out32 (s, STHBRX | RS (data_reg) | RA (0) | RB (r0));
780 else tcg_out32 (s, STH | RS (data_reg) | RA (r0));
781 break;
782 case 2:
783 if (bswap) tcg_out32 (s, STWBRX | RS (data_reg) | RA (0) | RB (r0));
784 else tcg_out32 (s, STW | RS (data_reg) | RA (r0));
785 break;
786 case 3:
787 if (bswap) {
788 tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);
789 tcg_out32 (s, STWBRX | RS (data_reg) | RA (0) | RB (r0));
790 tcg_out32 (s, STWBRX | RS (data_reg2) | RA (0) | RB (r1));
792 else {
793 tcg_out32 (s, STW | RS (data_reg2) | RA (r0));
794 tcg_out32 (s, STW | RS (data_reg) | RA (r0) | 4);
796 break;
799 #ifdef CONFIG_SOFTMMU
800 reloc_pc24 (label2_ptr, (tcg_target_long) s->code_ptr);
801 #endif
804 void tcg_target_qemu_prologue (TCGContext *s)
806 int i, frame_size;
808 frame_size = 0
809 + 4 /* back chain */
810 + 4 /* LR */
811 + TCG_STATIC_CALL_ARGS_SIZE
812 + ARRAY_SIZE (tcg_target_callee_save_regs) * 4
814 frame_size = (frame_size + 15) & ~15;
816 tcg_out32 (s, MFSPR | RT (0) | LR);
817 tcg_out32 (s, STWU | RS (1) | RA (1) | (-frame_size & 0xffff));
818 for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)
819 tcg_out32 (s, (STW
820 | RS (tcg_target_callee_save_regs[i])
821 | RA (1)
822 | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
825 tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + 4));
827 tcg_out32 (s, MTSPR | RS (3) | CTR);
828 tcg_out32 (s, BCCTR | BO_ALWAYS);
829 tb_ret_addr = s->code_ptr;
831 for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)
832 tcg_out32 (s, (LWZ
833 | RT (tcg_target_callee_save_regs[i])
834 | RA (1)
835 | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
838 tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + 4));
839 tcg_out32 (s, MTSPR | RS (0) | LR);
840 tcg_out32 (s, ADDI | RT (1) | RA (1) | frame_size);
841 tcg_out32 (s, BCLR | BO_ALWAYS);
844 static void tcg_out_ld (TCGContext *s, TCGType type, int ret, int arg1,
845 tcg_target_long arg2)
847 tcg_out_ldst (s, ret, arg1, arg2, LWZ, LWZX);
850 static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
851 tcg_target_long arg2)
853 tcg_out_ldst (s, arg, arg1, arg2, STW, STWX);
856 static void ppc_addi (TCGContext *s, int rt, int ra, tcg_target_long si)
858 if (!si && rt == ra)
859 return;
861 if (si == (int16_t) si)
862 tcg_out32 (s, ADDI | RT (rt) | RA (ra) | (si & 0xffff));
863 else {
864 uint16_t h = ((si >> 16) & 0xffff) + ((uint16_t) si >> 15);
865 tcg_out32 (s, ADDIS | RT (rt) | RA (ra) | h);
866 tcg_out32 (s, ADDI | RT (rt) | RA (rt) | (si & 0xffff));
870 static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
872 ppc_addi (s, reg, reg, val);
875 static void tcg_out_cmp (TCGContext *s, int cond, TCGArg arg1, TCGArg arg2,
876 int const_arg2, int cr)
878 int imm;
879 uint32_t op;
881 switch (cond) {
882 case TCG_COND_EQ:
883 case TCG_COND_NE:
884 if (const_arg2) {
885 if ((int16_t) arg2 == arg2) {
886 op = CMPI;
887 imm = 1;
888 break;
890 else if ((uint16_t) arg2 == arg2) {
891 op = CMPLI;
892 imm = 1;
893 break;
896 op = CMPL;
897 imm = 0;
898 break;
900 case TCG_COND_LT:
901 case TCG_COND_GE:
902 case TCG_COND_LE:
903 case TCG_COND_GT:
904 if (const_arg2) {
905 if ((int16_t) arg2 == arg2) {
906 op = CMPI;
907 imm = 1;
908 break;
911 op = CMP;
912 imm = 0;
913 break;
915 case TCG_COND_LTU:
916 case TCG_COND_GEU:
917 case TCG_COND_LEU:
918 case TCG_COND_GTU:
919 if (const_arg2) {
920 if ((uint16_t) arg2 == arg2) {
921 op = CMPLI;
922 imm = 1;
923 break;
926 op = CMPL;
927 imm = 0;
928 break;
930 default:
931 tcg_abort ();
933 op |= BF (cr);
935 if (imm)
936 tcg_out32 (s, op | RA (arg1) | (arg2 & 0xffff));
937 else {
938 if (const_arg2) {
939 tcg_out_movi (s, TCG_TYPE_I32, 0, arg2);
940 tcg_out32 (s, op | RA (arg1) | RB (0));
942 else
943 tcg_out32 (s, op | RA (arg1) | RB (arg2));
948 static void tcg_out_bc (TCGContext *s, int bc, int label_index)
950 TCGLabel *l = &s->labels[label_index];
952 if (l->has_value)
953 tcg_out32 (s, bc | reloc_pc14_val (s->code_ptr, l->u.value));
954 else {
955 uint16_t val = *(uint16_t *) &s->code_ptr[2];
957 /* Thanks to Andrzej Zaborowski */
958 tcg_out32 (s, bc | (val & 0xfffc));
959 tcg_out_reloc (s, s->code_ptr - 4, R_PPC_REL14, label_index, 0);
963 static void tcg_out_brcond (TCGContext *s, int cond,
964 TCGArg arg1, TCGArg arg2, int const_arg2,
965 int label_index)
967 tcg_out_cmp (s, cond, arg1, arg2, const_arg2, 7);
968 tcg_out_bc (s, tcg_to_bc[cond], label_index);
971 /* XXX: we implement it at the target level to avoid having to
972 handle cross basic blocks temporaries */
973 static void tcg_out_brcond2 (TCGContext *s, const TCGArg *args,
974 const int *const_args)
976 int cond = args[4], label_index = args[5], op;
977 struct { int bit1; int bit2; int cond2; } bits[] = {
978 [TCG_COND_LT ] = { CR_LT, CR_LT, TCG_COND_LT },
979 [TCG_COND_LE ] = { CR_LT, CR_GT, TCG_COND_LT },
980 [TCG_COND_GT ] = { CR_GT, CR_GT, TCG_COND_GT },
981 [TCG_COND_GE ] = { CR_GT, CR_LT, TCG_COND_GT },
982 [TCG_COND_LTU] = { CR_LT, CR_LT, TCG_COND_LTU },
983 [TCG_COND_LEU] = { CR_LT, CR_GT, TCG_COND_LTU },
984 [TCG_COND_GTU] = { CR_GT, CR_GT, TCG_COND_GTU },
985 [TCG_COND_GEU] = { CR_GT, CR_LT, TCG_COND_GTU },
986 }, *b = &bits[cond];
988 switch (cond) {
989 case TCG_COND_EQ:
990 case TCG_COND_NE:
991 op = (cond == TCG_COND_EQ) ? CRAND : CRNAND;
992 tcg_out_cmp (s, cond, args[0], args[2], const_args[2], 6);
993 tcg_out_cmp (s, cond, args[1], args[3], const_args[3], 7);
994 tcg_out32 (s, op | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
995 break;
996 case TCG_COND_LT:
997 case TCG_COND_LE:
998 case TCG_COND_GT:
999 case TCG_COND_GE:
1000 case TCG_COND_LTU:
1001 case TCG_COND_LEU:
1002 case TCG_COND_GTU:
1003 case TCG_COND_GEU:
1004 op = (b->bit1 != b->bit2) ? CRANDC : CRAND;
1005 tcg_out_cmp (s, b->cond2, args[1], args[3], const_args[3], 5);
1006 tcg_out_cmp (s, TCG_COND_EQ, args[1], args[3], const_args[3], 6);
1007 tcg_out_cmp (s, cond, args[0], args[2], const_args[2], 7);
1008 tcg_out32 (s, op | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, b->bit2));
1009 tcg_out32 (s, CROR | BT (7, CR_EQ) | BA (5, b->bit1) | BB (7, CR_EQ));
1010 break;
1011 default:
1012 tcg_abort();
1015 tcg_out_bc (s, (BC | BI (7, CR_EQ) | BO_COND_TRUE), label_index);
1018 void ppc_tb_set_jmp_target (unsigned long jmp_addr, unsigned long addr)
1020 uint32_t *ptr;
1021 long disp = addr - jmp_addr;
1022 unsigned long patch_size;
1024 ptr = (uint32_t *)jmp_addr;
1026 if ((disp << 6) >> 6 != disp) {
1027 ptr[0] = 0x3c000000 | (addr >> 16); /* lis 0,addr@ha */
1028 ptr[1] = 0x60000000 | (addr & 0xffff); /* la 0,addr@l(0) */
1029 ptr[2] = 0x7c0903a6; /* mtctr 0 */
1030 ptr[3] = 0x4e800420; /* brctr */
1031 patch_size = 16;
1032 } else {
1033 /* patch the branch destination */
1034 if (disp != 16) {
1035 *ptr = 0x48000000 | (disp & 0x03fffffc); /* b disp */
1036 patch_size = 4;
1037 } else {
1038 ptr[0] = 0x60000000; /* nop */
1039 ptr[1] = 0x60000000;
1040 ptr[2] = 0x60000000;
1041 ptr[3] = 0x60000000;
1042 patch_size = 16;
1045 /* flush icache */
1046 flush_icache_range(jmp_addr, jmp_addr + patch_size);
1049 static void tcg_out_op(TCGContext *s, int opc, const TCGArg *args,
1050 const int *const_args)
1052 switch (opc) {
1053 case INDEX_op_exit_tb:
1054 tcg_out_movi (s, TCG_TYPE_I32, TCG_REG_R3, args[0]);
1055 tcg_out_b (s, 0, (tcg_target_long) tb_ret_addr);
1056 break;
1057 case INDEX_op_goto_tb:
1058 if (s->tb_jmp_offset) {
1059 /* direct jump method */
1061 s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
1062 s->code_ptr += 16;
1064 else {
1065 tcg_abort ();
1067 s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
1068 break;
1069 case INDEX_op_br:
1071 TCGLabel *l = &s->labels[args[0]];
1073 if (l->has_value) {
1074 tcg_out_b (s, 0, l->u.value);
1076 else {
1077 uint32_t val = *(uint32_t *) s->code_ptr;
1079 /* Thanks to Andrzej Zaborowski */
1080 tcg_out32 (s, B | (val & 0x3fffffc));
1081 tcg_out_reloc (s, s->code_ptr - 4, R_PPC_REL24, args[0], 0);
1084 break;
1085 case INDEX_op_call:
1086 if (const_args[0]) {
1087 tcg_out_b (s, LK, args[0]);
1089 else {
1090 tcg_out32 (s, MTSPR | RS (args[0]) | LR);
1091 tcg_out32 (s, BCLR | BO_ALWAYS | LK);
1093 break;
1094 case INDEX_op_jmp:
1095 if (const_args[0]) {
1096 tcg_out_b (s, 0, args[0]);
1098 else {
1099 tcg_out32 (s, MTSPR | RS (args[0]) | CTR);
1100 tcg_out32 (s, BCCTR | BO_ALWAYS);
1102 break;
1103 case INDEX_op_movi_i32:
1104 tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]);
1105 break;
1106 case INDEX_op_ld8u_i32:
1107 tcg_out_ldst (s, args[0], args[1], args[2], LBZ, LBZX);
1108 break;
1109 case INDEX_op_ld8s_i32:
1110 tcg_out_ldst (s, args[0], args[1], args[2], LBZ, LBZX);
1111 tcg_out32 (s, EXTSB | RS (args[0]) | RA (args[0]));
1112 break;
1113 case INDEX_op_ld16u_i32:
1114 tcg_out_ldst (s, args[0], args[1], args[2], LHZ, LHZX);
1115 break;
1116 case INDEX_op_ld16s_i32:
1117 tcg_out_ldst (s, args[0], args[1], args[2], LHA, LHAX);
1118 break;
1119 case INDEX_op_ld_i32:
1120 tcg_out_ldst (s, args[0], args[1], args[2], LWZ, LWZX);
1121 break;
1122 case INDEX_op_st8_i32:
1123 tcg_out_ldst (s, args[0], args[1], args[2], STB, STBX);
1124 break;
1125 case INDEX_op_st16_i32:
1126 tcg_out_ldst (s, args[0], args[1], args[2], STH, STHX);
1127 break;
1128 case INDEX_op_st_i32:
1129 tcg_out_ldst (s, args[0], args[1], args[2], STW, STWX);
1130 break;
1132 case INDEX_op_add_i32:
1133 if (const_args[2])
1134 ppc_addi (s, args[0], args[1], args[2]);
1135 else
1136 tcg_out32 (s, ADD | TAB (args[0], args[1], args[2]));
1137 break;
1138 case INDEX_op_sub_i32:
1139 if (const_args[2])
1140 ppc_addi (s, args[0], args[1], -args[2]);
1141 else
1142 tcg_out32 (s, SUBF | TAB (args[0], args[2], args[1]));
1143 break;
1145 case INDEX_op_and_i32:
1146 if (const_args[2]) {
1147 if ((args[2] & 0xffff) == args[2])
1148 tcg_out32 (s, ANDI | RS (args[1]) | RA (args[0]) | args[2]);
1149 else if ((args[2] & 0xffff0000) == args[2])
1150 tcg_out32 (s, ANDIS | RS (args[1]) | RA (args[0])
1151 | ((args[2] >> 16) & 0xffff));
1152 else {
1153 tcg_out_movi (s, TCG_TYPE_I32, 0, args[2]);
1154 tcg_out32 (s, AND | SAB (args[1], args[0], 0));
1157 else
1158 tcg_out32 (s, AND | SAB (args[1], args[0], args[2]));
1159 break;
1160 case INDEX_op_or_i32:
1161 if (const_args[2]) {
1162 if (args[2] & 0xffff) {
1163 tcg_out32 (s, ORI | RS (args[1]) | RA (args[0])
1164 | (args[2] & 0xffff));
1165 if (args[2] >> 16)
1166 tcg_out32 (s, ORIS | RS (args[0]) | RA (args[0])
1167 | ((args[2] >> 16) & 0xffff));
1169 else {
1170 tcg_out32 (s, ORIS | RS (args[1]) | RA (args[0])
1171 | ((args[2] >> 16) & 0xffff));
1174 else
1175 tcg_out32 (s, OR | SAB (args[1], args[0], args[2]));
1176 break;
1177 case INDEX_op_xor_i32:
1178 if (const_args[2]) {
1179 if ((args[2] & 0xffff) == args[2])
1180 tcg_out32 (s, XORI | RS (args[1]) | RA (args[0])
1181 | (args[2] & 0xffff));
1182 else if ((args[2] & 0xffff0000) == args[2])
1183 tcg_out32 (s, XORIS | RS (args[1]) | RA (args[0])
1184 | ((args[2] >> 16) & 0xffff));
1185 else {
1186 tcg_out_movi (s, TCG_TYPE_I32, 0, args[2]);
1187 tcg_out32 (s, XOR | SAB (args[1], args[0], 0));
1190 else
1191 tcg_out32 (s, XOR | SAB (args[1], args[0], args[2]));
1192 break;
1194 case INDEX_op_mul_i32:
1195 if (const_args[2]) {
1196 if (args[2] == (int16_t) args[2])
1197 tcg_out32 (s, MULLI | RT (args[0]) | RA (args[1])
1198 | (args[2] & 0xffff));
1199 else {
1200 tcg_out_movi (s, TCG_TYPE_I32, 0, args[2]);
1201 tcg_out32 (s, MULLW | TAB (args[0], args[1], 0));
1204 else
1205 tcg_out32 (s, MULLW | TAB (args[0], args[1], args[2]));
1206 break;
1208 case INDEX_op_div_i32:
1209 tcg_out32 (s, DIVW | TAB (args[0], args[1], args[2]));
1210 break;
1212 case INDEX_op_divu_i32:
1213 tcg_out32 (s, DIVWU | TAB (args[0], args[1], args[2]));
1214 break;
1216 case INDEX_op_rem_i32:
1217 tcg_out32 (s, DIVW | TAB (0, args[1], args[2]));
1218 tcg_out32 (s, MULLW | TAB (0, 0, args[2]));
1219 tcg_out32 (s, SUBF | TAB (args[0], 0, args[1]));
1220 break;
1222 case INDEX_op_remu_i32:
1223 tcg_out32 (s, DIVWU | TAB (0, args[1], args[2]));
1224 tcg_out32 (s, MULLW | TAB (0, 0, args[2]));
1225 tcg_out32 (s, SUBF | TAB (args[0], 0, args[1]));
1226 break;
1228 case INDEX_op_mulu2_i32:
1229 if (args[0] == args[2] || args[0] == args[3]) {
1230 tcg_out32 (s, MULLW | TAB (0, args[2], args[3]));
1231 tcg_out32 (s, MULHWU | TAB (args[1], args[2], args[3]));
1232 tcg_out_mov (s, args[0], 0);
1234 else {
1235 tcg_out32 (s, MULLW | TAB (args[0], args[2], args[3]));
1236 tcg_out32 (s, MULHWU | TAB (args[1], args[2], args[3]));
1238 break;
1240 case INDEX_op_shl_i32:
1241 if (const_args[2]) {
1242 tcg_out32 (s, (RLWINM
1243 | RA (args[0])
1244 | RS (args[1])
1245 | SH (args[2])
1246 | MB (0)
1247 | ME (31 - args[2])
1251 else
1252 tcg_out32 (s, SLW | SAB (args[1], args[0], args[2]));
1253 break;
1254 case INDEX_op_shr_i32:
1255 if (const_args[2]) {
1256 tcg_out32 (s, (RLWINM
1257 | RA (args[0])
1258 | RS (args[1])
1259 | SH (32 - args[2])
1260 | MB (args[2])
1261 | ME (31)
1265 else
1266 tcg_out32 (s, SRW | SAB (args[1], args[0], args[2]));
1267 break;
1268 case INDEX_op_sar_i32:
1269 if (const_args[2])
1270 tcg_out32 (s, SRAWI | RS (args[1]) | RA (args[0]) | SH (args[2]));
1271 else
1272 tcg_out32 (s, SRAW | SAB (args[1], args[0], args[2]));
1273 break;
1275 case INDEX_op_add2_i32:
1276 if (args[0] == args[3] || args[0] == args[5]) {
1277 tcg_out32 (s, ADDC | TAB (0, args[2], args[4]));
1278 tcg_out32 (s, ADDE | TAB (args[1], args[3], args[5]));
1279 tcg_out_mov (s, args[0], 0);
1281 else {
1282 tcg_out32 (s, ADDC | TAB (args[0], args[2], args[4]));
1283 tcg_out32 (s, ADDE | TAB (args[1], args[3], args[5]));
1285 break;
1286 case INDEX_op_sub2_i32:
1287 if (args[0] == args[3] || args[0] == args[5]) {
1288 tcg_out32 (s, SUBFC | TAB (0, args[4], args[2]));
1289 tcg_out32 (s, SUBFE | TAB (args[1], args[5], args[3]));
1290 tcg_out_mov (s, args[0], 0);
1292 else {
1293 tcg_out32 (s, SUBFC | TAB (args[0], args[4], args[2]));
1294 tcg_out32 (s, SUBFE | TAB (args[1], args[5], args[3]));
1296 break;
1298 case INDEX_op_brcond_i32:
1300 args[0] = r0
1301 args[1] = r1
1302 args[2] = cond
1303 args[3] = r1 is const
1304 args[4] = label_index
1306 tcg_out_brcond (s, args[2], args[0], args[1], const_args[1], args[3]);
1307 break;
1308 case INDEX_op_brcond2_i32:
1309 tcg_out_brcond2(s, args, const_args);
1310 break;
1312 case INDEX_op_neg_i32:
1313 tcg_out32 (s, NEG | RT (args[0]) | RA (args[1]));
1314 break;
1316 case INDEX_op_qemu_ld8u:
1317 tcg_out_qemu_ld(s, args, 0);
1318 break;
1319 case INDEX_op_qemu_ld8s:
1320 tcg_out_qemu_ld(s, args, 0 | 4);
1321 break;
1322 case INDEX_op_qemu_ld16u:
1323 tcg_out_qemu_ld(s, args, 1);
1324 break;
1325 case INDEX_op_qemu_ld16s:
1326 tcg_out_qemu_ld(s, args, 1 | 4);
1327 break;
1328 case INDEX_op_qemu_ld32u:
1329 tcg_out_qemu_ld(s, args, 2);
1330 break;
1331 case INDEX_op_qemu_ld64:
1332 tcg_out_qemu_ld(s, args, 3);
1333 break;
1334 case INDEX_op_qemu_st8:
1335 tcg_out_qemu_st(s, args, 0);
1336 break;
1337 case INDEX_op_qemu_st16:
1338 tcg_out_qemu_st(s, args, 1);
1339 break;
1340 case INDEX_op_qemu_st32:
1341 tcg_out_qemu_st(s, args, 2);
1342 break;
1343 case INDEX_op_qemu_st64:
1344 tcg_out_qemu_st(s, args, 3);
1345 break;
1347 case INDEX_op_ext8s_i32:
1348 tcg_out32 (s, EXTSB | RS (args[1]) | RA (args[0]));
1349 break;
1350 case INDEX_op_ext16s_i32:
1351 tcg_out32 (s, EXTSH | RS (args[1]) | RA (args[0]));
1352 break;
1354 default:
1355 tcg_dump_ops (s, stderr);
1356 tcg_abort ();
1360 static const TCGTargetOpDef ppc_op_defs[] = {
1361 { INDEX_op_exit_tb, { } },
1362 { INDEX_op_goto_tb, { } },
1363 { INDEX_op_call, { "ri" } },
1364 { INDEX_op_jmp, { "ri" } },
1365 { INDEX_op_br, { } },
1367 { INDEX_op_mov_i32, { "r", "r" } },
1368 { INDEX_op_movi_i32, { "r" } },
1369 { INDEX_op_ld8u_i32, { "r", "r" } },
1370 { INDEX_op_ld8s_i32, { "r", "r" } },
1371 { INDEX_op_ld16u_i32, { "r", "r" } },
1372 { INDEX_op_ld16s_i32, { "r", "r" } },
1373 { INDEX_op_ld_i32, { "r", "r" } },
1374 { INDEX_op_st8_i32, { "r", "r" } },
1375 { INDEX_op_st16_i32, { "r", "r" } },
1376 { INDEX_op_st_i32, { "r", "r" } },
1378 { INDEX_op_add_i32, { "r", "r", "ri" } },
1379 { INDEX_op_mul_i32, { "r", "r", "ri" } },
1380 { INDEX_op_div_i32, { "r", "r", "r" } },
1381 { INDEX_op_divu_i32, { "r", "r", "r" } },
1382 { INDEX_op_rem_i32, { "r", "r", "r" } },
1383 { INDEX_op_remu_i32, { "r", "r", "r" } },
1384 { INDEX_op_mulu2_i32, { "r", "r", "r", "r" } },
1385 { INDEX_op_sub_i32, { "r", "r", "ri" } },
1386 { INDEX_op_and_i32, { "r", "r", "ri" } },
1387 { INDEX_op_or_i32, { "r", "r", "ri" } },
1388 { INDEX_op_xor_i32, { "r", "r", "ri" } },
1390 { INDEX_op_shl_i32, { "r", "r", "ri" } },
1391 { INDEX_op_shr_i32, { "r", "r", "ri" } },
1392 { INDEX_op_sar_i32, { "r", "r", "ri" } },
1394 { INDEX_op_brcond_i32, { "r", "ri" } },
1396 { INDEX_op_add2_i32, { "r", "r", "r", "r", "r", "r" } },
1397 { INDEX_op_sub2_i32, { "r", "r", "r", "r", "r", "r" } },
1398 { INDEX_op_brcond2_i32, { "r", "r", "r", "r" } },
1400 { INDEX_op_neg_i32, { "r", "r" } },
1402 #if TARGET_LONG_BITS == 32
1403 { INDEX_op_qemu_ld8u, { "r", "L" } },
1404 { INDEX_op_qemu_ld8s, { "r", "L" } },
1405 { INDEX_op_qemu_ld16u, { "r", "L" } },
1406 { INDEX_op_qemu_ld16s, { "r", "L" } },
1407 { INDEX_op_qemu_ld32u, { "r", "L" } },
1408 { INDEX_op_qemu_ld32s, { "r", "L" } },
1409 { INDEX_op_qemu_ld64, { "r", "r", "L" } },
1411 { INDEX_op_qemu_st8, { "K", "K" } },
1412 { INDEX_op_qemu_st16, { "K", "K" } },
1413 { INDEX_op_qemu_st32, { "K", "K" } },
1414 { INDEX_op_qemu_st64, { "M", "M", "M" } },
1415 #else
1416 { INDEX_op_qemu_ld8u, { "r", "L", "L" } },
1417 { INDEX_op_qemu_ld8s, { "r", "L", "L" } },
1418 { INDEX_op_qemu_ld16u, { "r", "L", "L" } },
1419 { INDEX_op_qemu_ld16s, { "r", "L", "L" } },
1420 { INDEX_op_qemu_ld32u, { "r", "L", "L" } },
1421 { INDEX_op_qemu_ld32s, { "r", "L", "L" } },
1422 { INDEX_op_qemu_ld64, { "r", "L", "L", "L" } },
1424 { INDEX_op_qemu_st8, { "K", "K", "K" } },
1425 { INDEX_op_qemu_st16, { "K", "K", "K" } },
1426 { INDEX_op_qemu_st32, { "K", "K", "K" } },
1427 { INDEX_op_qemu_st64, { "M", "M", "M", "M" } },
1428 #endif
1430 { INDEX_op_ext8s_i32, { "r", "r" } },
1431 { INDEX_op_ext16s_i32, { "r", "r" } },
1433 { -1 },
1436 void tcg_target_init(TCGContext *s)
1438 tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
1439 tcg_regset_set32(tcg_target_call_clobber_regs, 0,
1440 (1 << TCG_REG_R0) |
1441 (1 << TCG_REG_R3) |
1442 (1 << TCG_REG_R4) |
1443 (1 << TCG_REG_R5) |
1444 (1 << TCG_REG_R6) |
1445 (1 << TCG_REG_R7) |
1446 (1 << TCG_REG_R8) |
1447 (1 << TCG_REG_R9) |
1448 (1 << TCG_REG_R10) |
1449 (1 << TCG_REG_R11) |
1450 (1 << TCG_REG_R12)
1453 tcg_regset_clear(s->reserved_regs);
1454 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0);
1455 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R1);
1456 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R2);
1458 tcg_add_target_add_op_defs(ppc_op_defs);