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
25 static uint8_t *tb_ret_addr;
28 #define LINKAGE_AREA_SIZE 24
30 #elif defined _CALL_AIX
31 #define LINKAGE_AREA_SIZE 52
34 #define LINKAGE_AREA_SIZE 8
41 #if TARGET_PHYS_ADDR_BITS <= 32
42 #define ADDEND_OFFSET 0
44 #define ADDEND_OFFSET 4
52 #ifdef CONFIG_USE_GUEST_BASE
53 #define TCG_GUEST_BASE_REG 30
55 #define TCG_GUEST_BASE_REG 0
59 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
95 static const int tcg_target_reg_alloc_order[] = {
134 static const int tcg_target_call_iarg_regs[] = {
145 static const int tcg_target_call_oarg_regs[2] = {
150 static const int tcg_target_callee_save_regs[] = {
171 /* TCG_REG_R27, */ /* currently used for the global env, so no
179 static uint32_t reloc_pc24_val (void *pc, tcg_target_long target)
181 tcg_target_long disp;
183 disp = target - (tcg_target_long) pc;
184 if ((disp << 6) >> 6 != disp)
187 return disp & 0x3fffffc;
190 static void reloc_pc24 (void *pc, tcg_target_long target)
192 *(uint32_t *) pc = (*(uint32_t *) pc & ~0x3fffffc)
193 | reloc_pc24_val (pc, target);
196 static uint16_t reloc_pc14_val (void *pc, tcg_target_long target)
198 tcg_target_long disp;
200 disp = target - (tcg_target_long) pc;
201 if (disp != (int16_t) disp)
204 return disp & 0xfffc;
207 static void reloc_pc14 (void *pc, tcg_target_long target)
209 *(uint32_t *) pc = (*(uint32_t *) pc & ~0xfffc)
210 | reloc_pc14_val (pc, target);
213 static void patch_reloc(uint8_t *code_ptr, int type,
214 tcg_target_long value, tcg_target_long addend)
219 reloc_pc14 (code_ptr, value);
222 reloc_pc24 (code_ptr, value);
229 /* maximum number of register used for input function arguments */
230 static int tcg_target_get_call_iarg_regs_count(int flags)
232 return ARRAY_SIZE (tcg_target_call_iarg_regs);
235 /* parse target specific constraints */
236 static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
242 case 'A': case 'B': case 'C': case 'D':
243 ct->ct |= TCG_CT_REG;
244 tcg_regset_set_reg(ct->u.regs, 3 + ct_str[0] - 'A');
247 ct->ct |= TCG_CT_REG;
248 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
250 #ifdef CONFIG_SOFTMMU
251 case 'L': /* qemu_ld constraint */
252 ct->ct |= TCG_CT_REG;
253 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
254 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
255 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
257 case 'K': /* qemu_st[8..32] constraint */
258 ct->ct |= TCG_CT_REG;
259 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
260 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
261 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
262 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R5);
263 #if TARGET_LONG_BITS == 64
264 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R6);
267 case 'M': /* qemu_st64 constraint */
268 ct->ct |= TCG_CT_REG;
269 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
270 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
271 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R4);
272 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R5);
273 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R6);
274 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R7);
279 ct->ct |= TCG_CT_REG;
280 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
283 ct->ct |= TCG_CT_REG;
284 tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
285 tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
296 /* test if a constant matches the constraint */
297 static int tcg_target_const_match(tcg_target_long val,
298 const TCGArgConstraint *arg_ct)
303 if (ct & TCG_CT_CONST)
308 #define OPCD(opc) ((opc)<<26)
309 #define XO31(opc) (OPCD(31)|((opc)<<1))
310 #define XO19(opc) (OPCD(19)|((opc)<<1))
322 #define ADDIC OPCD(12)
323 #define ADDI OPCD(14)
324 #define ADDIS OPCD(15)
326 #define ORIS OPCD(25)
327 #define XORI OPCD(26)
328 #define XORIS OPCD(27)
329 #define ANDI OPCD(28)
330 #define ANDIS OPCD(29)
331 #define MULLI OPCD( 7)
332 #define CMPLI OPCD(10)
333 #define CMPI OPCD(11)
334 #define SUBFIC OPCD( 8)
336 #define LWZU OPCD(33)
337 #define STWU OPCD(37)
339 #define RLWINM OPCD(21)
340 #define RLWNM OPCD(23)
342 #define BCLR XO19( 16)
343 #define BCCTR XO19(528)
344 #define CRAND XO19(257)
345 #define CRANDC XO19(129)
346 #define CRNAND XO19(225)
347 #define CROR XO19(449)
348 #define CRNOR XO19( 33)
350 #define EXTSB XO31(954)
351 #define EXTSH XO31(922)
352 #define ADD XO31(266)
353 #define ADDE XO31(138)
354 #define ADDC XO31( 10)
355 #define AND XO31( 28)
356 #define SUBF XO31( 40)
357 #define SUBFC XO31( 8)
358 #define SUBFE XO31(136)
360 #define XOR XO31(316)
361 #define MULLW XO31(235)
362 #define MULHWU XO31( 11)
363 #define DIVW XO31(491)
364 #define DIVWU XO31(459)
366 #define CMPL XO31( 32)
367 #define LHBRX XO31(790)
368 #define LWBRX XO31(534)
369 #define STHBRX XO31(918)
370 #define STWBRX XO31(662)
371 #define MFSPR XO31(339)
372 #define MTSPR XO31(467)
373 #define SRAWI XO31(824)
374 #define NEG XO31(104)
375 #define MFCR XO31( 19)
376 #define CNTLZW XO31( 26)
377 #define NOR XO31(124)
378 #define ANDC XO31( 60)
379 #define ORC XO31(412)
381 #define LBZX XO31( 87)
382 #define LHZX XO31(279)
383 #define LHAX XO31(343)
384 #define LWZX XO31( 23)
385 #define STBX XO31(215)
386 #define STHX XO31(407)
387 #define STWX XO31(151)
389 #define SPR(a,b) ((((a)<<5)|(b))<<11)
391 #define CTR SPR(9, 0)
393 #define SLW XO31( 24)
394 #define SRW XO31(536)
395 #define SRAW XO31(792)
398 #define TRAP (TW | TO (31))
400 #define RT(r) ((r)<<21)
401 #define RS(r) ((r)<<21)
402 #define RA(r) ((r)<<16)
403 #define RB(r) ((r)<<11)
404 #define TO(t) ((t)<<21)
405 #define SH(s) ((s)<<11)
406 #define MB(b) ((b)<<6)
407 #define ME(e) ((e)<<1)
408 #define BO(o) ((o)<<21)
412 #define TAB(t,a,b) (RT(t) | RA(a) | RB(b))
413 #define SAB(s,a,b) (RS(s) | RA(a) | RB(b))
415 #define BF(n) ((n)<<23)
416 #define BI(n, c) (((c)+((n)*4))<<16)
417 #define BT(n, c) (((c)+((n)*4))<<21)
418 #define BA(n, c) (((c)+((n)*4))<<16)
419 #define BB(n, c) (((c)+((n)*4))<<11)
421 #define BO_COND_TRUE BO (12)
422 #define BO_COND_FALSE BO (4)
423 #define BO_ALWAYS BO (20)
432 static const uint32_t tcg_to_bc[10] = {
433 [TCG_COND_EQ] = BC | BI (7, CR_EQ) | BO_COND_TRUE,
434 [TCG_COND_NE] = BC | BI (7, CR_EQ) | BO_COND_FALSE,
435 [TCG_COND_LT] = BC | BI (7, CR_LT) | BO_COND_TRUE,
436 [TCG_COND_GE] = BC | BI (7, CR_LT) | BO_COND_FALSE,
437 [TCG_COND_LE] = BC | BI (7, CR_GT) | BO_COND_FALSE,
438 [TCG_COND_GT] = BC | BI (7, CR_GT) | BO_COND_TRUE,
439 [TCG_COND_LTU] = BC | BI (7, CR_LT) | BO_COND_TRUE,
440 [TCG_COND_GEU] = BC | BI (7, CR_LT) | BO_COND_FALSE,
441 [TCG_COND_LEU] = BC | BI (7, CR_GT) | BO_COND_FALSE,
442 [TCG_COND_GTU] = BC | BI (7, CR_GT) | BO_COND_TRUE,
445 static void tcg_out_mov(TCGContext *s, int ret, int arg)
447 tcg_out32 (s, OR | SAB (arg, ret, arg));
450 static void tcg_out_movi(TCGContext *s, TCGType type,
451 int ret, tcg_target_long arg)
453 if (arg == (int16_t) arg)
454 tcg_out32 (s, ADDI | RT (ret) | RA (0) | (arg & 0xffff));
456 tcg_out32 (s, ADDIS | RT (ret) | RA (0) | ((arg >> 16) & 0xffff));
458 tcg_out32 (s, ORI | RS (ret) | RA (ret) | (arg & 0xffff));
462 static void tcg_out_ldst (TCGContext *s, int ret, int addr,
463 int offset, int op1, int op2)
465 if (offset == (int16_t) offset)
466 tcg_out32 (s, op1 | RT (ret) | RA (addr) | (offset & 0xffff));
468 tcg_out_movi (s, TCG_TYPE_I32, 0, offset);
469 tcg_out32 (s, op2 | RT (ret) | RA (addr) | RB (0));
473 static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target)
475 tcg_target_long disp;
477 disp = target - (tcg_target_long) s->code_ptr;
478 if ((disp << 6) >> 6 == disp)
479 tcg_out32 (s, B | (disp & 0x3fffffc) | mask);
481 tcg_out_movi (s, TCG_TYPE_I32, 0, (tcg_target_long) target);
482 tcg_out32 (s, MTSPR | RS (0) | CTR);
483 tcg_out32 (s, BCCTR | BO_ALWAYS | mask);
487 static void tcg_out_call (TCGContext *s, tcg_target_long arg, int const_arg)
494 tcg_out_movi (s, TCG_TYPE_I32, reg, arg);
498 tcg_out32 (s, LWZ | RT (0) | RA (reg));
499 tcg_out32 (s, MTSPR | RA (0) | CTR);
500 tcg_out32 (s, LWZ | RT (2) | RA (reg) | 4);
501 tcg_out32 (s, BCCTR | BO_ALWAYS | LK);
504 tcg_out_b (s, LK, arg);
507 tcg_out32 (s, MTSPR | RS (arg) | LR);
508 tcg_out32 (s, BCLR | BO_ALWAYS | LK);
513 #if defined(CONFIG_SOFTMMU)
515 #include "../../softmmu_defs.h"
517 static void *qemu_ld_helpers[4] = {
524 static void *qemu_st_helpers[4] = {
532 static void tcg_out_qemu_ld (TCGContext *s, const TCGArg *args, int opc)
534 int addr_reg, data_reg, data_reg2, r0, r1, rbase, mem_index, s_bits, bswap;
535 #ifdef CONFIG_SOFTMMU
537 void *label1_ptr, *label2_ptr;
539 #if TARGET_LONG_BITS == 64
549 #if TARGET_LONG_BITS == 64
555 #ifdef CONFIG_SOFTMMU
561 tcg_out32 (s, (RLWINM
564 | SH (32 - (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS))
565 | MB (32 - (CPU_TLB_BITS + CPU_TLB_ENTRY_BITS))
566 | ME (31 - CPU_TLB_ENTRY_BITS)
569 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (TCG_AREG0));
573 | offsetof (CPUState, tlb_table[mem_index][0].addr_read)
576 tcg_out32 (s, (RLWINM
580 | MB ((32 - s_bits) & 31)
581 | ME (31 - TARGET_PAGE_BITS)
585 tcg_out32 (s, CMP | BF (7) | RA (r2) | RB (r1));
586 #if TARGET_LONG_BITS == 64
587 tcg_out32 (s, LWZ | RT (r1) | RA (r0) | 4);
588 tcg_out32 (s, CMP | BF (6) | RA (addr_reg2) | RB (r1));
589 tcg_out32 (s, CRAND | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
592 label1_ptr = s->code_ptr;
594 tcg_out32 (s, BC | BI (7, CR_EQ) | BO_COND_TRUE);
598 #if TARGET_LONG_BITS == 32
599 tcg_out_mov (s, 3, addr_reg);
600 tcg_out_movi (s, TCG_TYPE_I32, 4, mem_index);
602 tcg_out_mov (s, 3, addr_reg2);
603 tcg_out_mov (s, 4, addr_reg);
604 tcg_out_movi (s, TCG_TYPE_I32, 5, mem_index);
607 tcg_out_call (s, (tcg_target_long) qemu_ld_helpers[s_bits], 1);
610 tcg_out32 (s, EXTSB | RA (data_reg) | RS (3));
613 tcg_out32 (s, EXTSH | RA (data_reg) | RS (3));
619 tcg_out_mov (s, data_reg, 3);
623 if (data_reg2 == 4) {
624 tcg_out_mov (s, 0, 4);
625 tcg_out_mov (s, 4, 3);
626 tcg_out_mov (s, 3, 0);
629 tcg_out_mov (s, data_reg2, 3);
630 tcg_out_mov (s, 3, 4);
634 if (data_reg != 4) tcg_out_mov (s, data_reg, 4);
635 if (data_reg2 != 3) tcg_out_mov (s, data_reg2, 3);
639 label2_ptr = s->code_ptr;
642 /* label1: fast path */
644 reloc_pc14 (label1_ptr, (tcg_target_long) s->code_ptr);
647 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
651 | (ADDEND_OFFSET + offsetof (CPUTLBEntry, addend)
652 - offsetof (CPUTLBEntry, addr_read))
654 /* r0 = env->tlb_table[mem_index][index].addend */
655 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (addr_reg));
656 /* r0 = env->tlb_table[mem_index][index].addend + addr */
658 #else /* !CONFIG_SOFTMMU */
661 rbase = GUEST_BASE ? TCG_GUEST_BASE_REG : 0;
664 #ifdef TARGET_WORDS_BIGENDIAN
673 tcg_out32 (s, LBZX | TAB (data_reg, rbase, r0));
676 tcg_out32 (s, LBZX | TAB (data_reg, rbase, r0));
677 tcg_out32 (s, EXTSB | RA (data_reg) | RS (data_reg));
681 tcg_out32 (s, LHBRX | TAB (data_reg, rbase, r0));
683 tcg_out32 (s, LHZX | TAB (data_reg, rbase, r0));
687 tcg_out32 (s, LHBRX | TAB (data_reg, rbase, r0));
688 tcg_out32 (s, EXTSH | RA (data_reg) | RS (data_reg));
690 else tcg_out32 (s, LHAX | TAB (data_reg, rbase, r0));
694 tcg_out32 (s, LWBRX | TAB (data_reg, rbase, r0));
696 tcg_out32 (s, LWZX | TAB (data_reg, rbase, r0));
700 tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);
701 tcg_out32 (s, LWBRX | TAB (data_reg, rbase, r0));
702 tcg_out32 (s, LWBRX | TAB (data_reg2, rbase, r1));
705 #ifdef CONFIG_USE_GUEST_BASE
706 tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);
707 tcg_out32 (s, LWZX | TAB (data_reg2, rbase, r0));
708 tcg_out32 (s, LWZX | TAB (data_reg, rbase, r1));
710 if (r0 == data_reg2) {
711 tcg_out32 (s, LWZ | RT (0) | RA (r0));
712 tcg_out32 (s, LWZ | RT (data_reg) | RA (r0) | 4);
713 tcg_out_mov (s, data_reg2, 0);
716 tcg_out32 (s, LWZ | RT (data_reg2) | RA (r0));
717 tcg_out32 (s, LWZ | RT (data_reg) | RA (r0) | 4);
724 #ifdef CONFIG_SOFTMMU
725 reloc_pc24 (label2_ptr, (tcg_target_long) s->code_ptr);
729 static void tcg_out_qemu_st (TCGContext *s, const TCGArg *args, int opc)
731 int addr_reg, r0, r1, data_reg, data_reg2, mem_index, bswap, rbase;
732 #ifdef CONFIG_SOFTMMU
734 void *label1_ptr, *label2_ptr;
736 #if TARGET_LONG_BITS == 64
746 #if TARGET_LONG_BITS == 64
751 #ifdef CONFIG_SOFTMMU
757 tcg_out32 (s, (RLWINM
760 | SH (32 - (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS))
761 | MB (32 - (CPU_TLB_ENTRY_BITS + CPU_TLB_BITS))
762 | ME (31 - CPU_TLB_ENTRY_BITS)
765 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (TCG_AREG0));
769 | offsetof (CPUState, tlb_table[mem_index][0].addr_write)
772 tcg_out32 (s, (RLWINM
776 | MB ((32 - opc) & 31)
777 | ME (31 - TARGET_PAGE_BITS)
781 tcg_out32 (s, CMP | (7 << 23) | RA (r2) | RB (r1));
782 #if TARGET_LONG_BITS == 64
783 tcg_out32 (s, LWZ | RT (r1) | RA (r0) | 4);
784 tcg_out32 (s, CMP | BF (6) | RA (addr_reg2) | RB (r1));
785 tcg_out32 (s, CRAND | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
788 label1_ptr = s->code_ptr;
790 tcg_out32 (s, BC | BI (7, CR_EQ) | BO_COND_TRUE);
794 #if TARGET_LONG_BITS == 32
795 tcg_out_mov (s, 3, addr_reg);
798 tcg_out_mov (s, 3, addr_reg2);
799 tcg_out_mov (s, 4, addr_reg);
800 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
809 tcg_out32 (s, (RLWINM
817 tcg_out32 (s, (RLWINM
825 tcg_out_mov (s, ir, data_reg);
828 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
831 tcg_out_mov (s, ir++, data_reg2);
832 tcg_out_mov (s, ir, data_reg);
837 tcg_out_movi (s, TCG_TYPE_I32, ir, mem_index);
838 tcg_out_call (s, (tcg_target_long) qemu_st_helpers[opc], 1);
839 label2_ptr = s->code_ptr;
842 /* label1: fast path */
844 reloc_pc14 (label1_ptr, (tcg_target_long) s->code_ptr);
850 | (ADDEND_OFFSET + offsetof (CPUTLBEntry, addend)
851 - offsetof (CPUTLBEntry, addr_write))
853 /* r0 = env->tlb_table[mem_index][index].addend */
854 tcg_out32 (s, ADD | RT (r0) | RA (r0) | RB (addr_reg));
855 /* r0 = env->tlb_table[mem_index][index].addend + addr */
857 #else /* !CONFIG_SOFTMMU */
860 rbase = GUEST_BASE ? TCG_GUEST_BASE_REG : 0;
863 #ifdef TARGET_WORDS_BIGENDIAN
870 tcg_out32 (s, STBX | SAB (data_reg, rbase, r0));
874 tcg_out32 (s, STHBRX | SAB (data_reg, rbase, r0));
876 tcg_out32 (s, STHX | SAB (data_reg, rbase, r0));
880 tcg_out32 (s, STWBRX | SAB (data_reg, rbase, r0));
882 tcg_out32 (s, STWX | SAB (data_reg, rbase, r0));
886 tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);
887 tcg_out32 (s, STWBRX | SAB (data_reg, rbase, r0));
888 tcg_out32 (s, STWBRX | SAB (data_reg2, rbase, r1));
891 #ifdef CONFIG_USE_GUEST_BASE
892 tcg_out32 (s, STWX | SAB (data_reg2, rbase, r0));
893 tcg_out32 (s, ADDI | RT (r1) | RA (r0) | 4);
894 tcg_out32 (s, STWX | SAB (data_reg, rbase, r1));
896 tcg_out32 (s, STW | RS (data_reg2) | RA (r0));
897 tcg_out32 (s, STW | RS (data_reg) | RA (r0) | 4);
903 #ifdef CONFIG_SOFTMMU
904 reloc_pc24 (label2_ptr, (tcg_target_long) s->code_ptr);
908 void tcg_target_qemu_prologue (TCGContext *s)
914 + TCG_STATIC_CALL_ARGS_SIZE
915 + ARRAY_SIZE (tcg_target_callee_save_regs) * 4
917 frame_size = (frame_size + 15) & ~15;
923 /* First emit adhoc function descriptor */
924 addr = (uint32_t) s->code_ptr + 12;
925 tcg_out32 (s, addr); /* entry point */
926 s->code_ptr += 8; /* skip TOC and environment pointer */
929 tcg_out32 (s, MFSPR | RT (0) | LR);
930 tcg_out32 (s, STWU | RS (1) | RA (1) | (-frame_size & 0xffff));
931 for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)
933 | RS (tcg_target_callee_save_regs[i])
935 | (i * 4 + LINKAGE_AREA_SIZE + TCG_STATIC_CALL_ARGS_SIZE)
938 tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + LR_OFFSET));
940 #ifdef CONFIG_USE_GUEST_BASE
941 tcg_out_movi (s, TCG_TYPE_I32, TCG_GUEST_BASE_REG, GUEST_BASE);
944 tcg_out32 (s, MTSPR | RS (3) | CTR);
945 tcg_out32 (s, BCCTR | BO_ALWAYS);
946 tb_ret_addr = s->code_ptr;
948 for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)
950 | RT (tcg_target_callee_save_regs[i])
952 | (i * 4 + LINKAGE_AREA_SIZE + TCG_STATIC_CALL_ARGS_SIZE)
955 tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + LR_OFFSET));
956 tcg_out32 (s, MTSPR | RS (0) | LR);
957 tcg_out32 (s, ADDI | RT (1) | RA (1) | frame_size);
958 tcg_out32 (s, BCLR | BO_ALWAYS);
961 static void tcg_out_ld (TCGContext *s, TCGType type, int ret, int arg1,
962 tcg_target_long arg2)
964 tcg_out_ldst (s, ret, arg1, arg2, LWZ, LWZX);
967 static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
968 tcg_target_long arg2)
970 tcg_out_ldst (s, arg, arg1, arg2, STW, STWX);
973 static void ppc_addi (TCGContext *s, int rt, int ra, tcg_target_long si)
978 if (si == (int16_t) si)
979 tcg_out32 (s, ADDI | RT (rt) | RA (ra) | (si & 0xffff));
981 uint16_t h = ((si >> 16) & 0xffff) + ((uint16_t) si >> 15);
982 tcg_out32 (s, ADDIS | RT (rt) | RA (ra) | h);
983 tcg_out32 (s, ADDI | RT (rt) | RA (rt) | (si & 0xffff));
987 static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
989 ppc_addi (s, reg, reg, val);
992 static void tcg_out_cmp (TCGContext *s, int cond, TCGArg arg1, TCGArg arg2,
993 int const_arg2, int cr)
1002 if ((int16_t) arg2 == arg2) {
1007 else if ((uint16_t) arg2 == arg2) {
1022 if ((int16_t) arg2 == arg2) {
1037 if ((uint16_t) arg2 == arg2) {
1053 tcg_out32 (s, op | RA (arg1) | (arg2 & 0xffff));
1056 tcg_out_movi (s, TCG_TYPE_I32, 0, arg2);
1057 tcg_out32 (s, op | RA (arg1) | RB (0));
1060 tcg_out32 (s, op | RA (arg1) | RB (arg2));
1065 static void tcg_out_bc (TCGContext *s, int bc, int label_index)
1067 TCGLabel *l = &s->labels[label_index];
1070 tcg_out32 (s, bc | reloc_pc14_val (s->code_ptr, l->u.value));
1072 uint16_t val = *(uint16_t *) &s->code_ptr[2];
1074 /* Thanks to Andrzej Zaborowski */
1075 tcg_out32 (s, bc | (val & 0xfffc));
1076 tcg_out_reloc (s, s->code_ptr - 4, R_PPC_REL14, label_index, 0);
1080 static void tcg_out_cr7eq_from_cond (TCGContext *s, const TCGArg *args,
1081 const int *const_args)
1083 TCGCond cond = args[4];
1085 struct { int bit1; int bit2; int cond2; } bits[] = {
1086 [TCG_COND_LT ] = { CR_LT, CR_LT, TCG_COND_LT },
1087 [TCG_COND_LE ] = { CR_LT, CR_GT, TCG_COND_LT },
1088 [TCG_COND_GT ] = { CR_GT, CR_GT, TCG_COND_GT },
1089 [TCG_COND_GE ] = { CR_GT, CR_LT, TCG_COND_GT },
1090 [TCG_COND_LTU] = { CR_LT, CR_LT, TCG_COND_LTU },
1091 [TCG_COND_LEU] = { CR_LT, CR_GT, TCG_COND_LTU },
1092 [TCG_COND_GTU] = { CR_GT, CR_GT, TCG_COND_GTU },
1093 [TCG_COND_GEU] = { CR_GT, CR_LT, TCG_COND_GTU },
1094 }, *b = &bits[cond];
1099 op = (cond == TCG_COND_EQ) ? CRAND : CRNAND;
1100 tcg_out_cmp (s, cond, args[0], args[2], const_args[2], 6);
1101 tcg_out_cmp (s, cond, args[1], args[3], const_args[3], 7);
1102 tcg_out32 (s, op | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, CR_EQ));
1112 op = (b->bit1 != b->bit2) ? CRANDC : CRAND;
1113 tcg_out_cmp (s, b->cond2, args[1], args[3], const_args[3], 5);
1114 tcg_out_cmp (s, TCG_COND_EQ, args[1], args[3], const_args[3], 6);
1115 tcg_out_cmp (s, cond, args[0], args[2], const_args[2], 7);
1116 tcg_out32 (s, op | BT (7, CR_EQ) | BA (6, CR_EQ) | BB (7, b->bit2));
1117 tcg_out32 (s, CROR | BT (7, CR_EQ) | BA (5, b->bit1) | BB (7, CR_EQ));
1124 static void tcg_out_setcond (TCGContext *s, TCGCond cond, TCGArg arg0,
1125 TCGArg arg1, TCGArg arg2, int const_arg2)
1137 if ((uint16_t) arg2 == arg2) {
1138 tcg_out32 (s, XORI | RS (arg1) | RA (0) | arg2);
1141 tcg_out_movi (s, TCG_TYPE_I32, 0, arg2);
1142 tcg_out32 (s, XOR | SAB (arg1, 0, 0));
1148 tcg_out32 (s, XOR | SAB (arg1, 0, arg2));
1150 tcg_out32 (s, CNTLZW | RS (arg) | RA (0));
1151 tcg_out32 (s, (RLWINM
1168 if ((uint16_t) arg2 == arg2) {
1169 tcg_out32 (s, XORI | RS (arg1) | RA (0) | arg2);
1172 tcg_out_movi (s, TCG_TYPE_I32, 0, arg2);
1173 tcg_out32 (s, XOR | SAB (arg1, 0, 0));
1179 tcg_out32 (s, XOR | SAB (arg1, 0, arg2));
1182 if (arg == arg1 && arg1 == arg0) {
1183 tcg_out32 (s, ADDIC | RT (0) | RA (arg) | 0xffff);
1184 tcg_out32 (s, SUBFE | TAB (arg0, 0, arg));
1187 tcg_out32 (s, ADDIC | RT (arg0) | RA (arg) | 0xffff);
1188 tcg_out32 (s, SUBFE | TAB (arg0, arg0, arg));
1207 crop = CRNOR | BT (7, CR_EQ) | BA (7, CR_LT) | BB (7, CR_LT);
1213 crop = CRNOR | BT (7, CR_EQ) | BA (7, CR_GT) | BB (7, CR_GT);
1215 tcg_out_cmp (s, cond, arg1, arg2, const_arg2, 7);
1216 if (crop) tcg_out32 (s, crop);
1217 tcg_out32 (s, MFCR | RT (0));
1218 tcg_out32 (s, (RLWINM
1233 static void tcg_out_setcond2 (TCGContext *s, const TCGArg *args,
1234 const int *const_args)
1236 tcg_out_cr7eq_from_cond (s, args + 1, const_args + 1);
1237 tcg_out32 (s, MFCR | RT (0));
1238 tcg_out32 (s, (RLWINM
1248 static void tcg_out_brcond (TCGContext *s, TCGCond cond,
1249 TCGArg arg1, TCGArg arg2, int const_arg2,
1252 tcg_out_cmp (s, cond, arg1, arg2, const_arg2, 7);
1253 tcg_out_bc (s, tcg_to_bc[cond], label_index);
1256 /* XXX: we implement it at the target level to avoid having to
1257 handle cross basic blocks temporaries */
1258 static void tcg_out_brcond2 (TCGContext *s, const TCGArg *args,
1259 const int *const_args)
1261 tcg_out_cr7eq_from_cond (s, args, const_args);
1262 tcg_out_bc (s, (BC | BI (7, CR_EQ) | BO_COND_TRUE), args[5]);
1265 void ppc_tb_set_jmp_target (unsigned long jmp_addr, unsigned long addr)
1268 long disp = addr - jmp_addr;
1269 unsigned long patch_size;
1271 ptr = (uint32_t *)jmp_addr;
1273 if ((disp << 6) >> 6 != disp) {
1274 ptr[0] = 0x3c000000 | (addr >> 16); /* lis 0,addr@ha */
1275 ptr[1] = 0x60000000 | (addr & 0xffff); /* la 0,addr@l(0) */
1276 ptr[2] = 0x7c0903a6; /* mtctr 0 */
1277 ptr[3] = 0x4e800420; /* brctr */
1280 /* patch the branch destination */
1282 *ptr = 0x48000000 | (disp & 0x03fffffc); /* b disp */
1285 ptr[0] = 0x60000000; /* nop */
1286 ptr[1] = 0x60000000;
1287 ptr[2] = 0x60000000;
1288 ptr[3] = 0x60000000;
1293 flush_icache_range(jmp_addr, jmp_addr + patch_size);
1296 static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
1297 const int *const_args)
1300 case INDEX_op_exit_tb:
1301 tcg_out_movi (s, TCG_TYPE_I32, TCG_REG_R3, args[0]);
1302 tcg_out_b (s, 0, (tcg_target_long) tb_ret_addr);
1304 case INDEX_op_goto_tb:
1305 if (s->tb_jmp_offset) {
1306 /* direct jump method */
1308 s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
1314 s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
1318 TCGLabel *l = &s->labels[args[0]];
1321 tcg_out_b (s, 0, l->u.value);
1324 uint32_t val = *(uint32_t *) s->code_ptr;
1326 /* Thanks to Andrzej Zaborowski */
1327 tcg_out32 (s, B | (val & 0x3fffffc));
1328 tcg_out_reloc (s, s->code_ptr - 4, R_PPC_REL24, args[0], 0);
1333 tcg_out_call (s, args[0], const_args[0]);
1336 if (const_args[0]) {
1337 tcg_out_b (s, 0, args[0]);
1340 tcg_out32 (s, MTSPR | RS (args[0]) | CTR);
1341 tcg_out32 (s, BCCTR | BO_ALWAYS);
1344 case INDEX_op_movi_i32:
1345 tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]);
1347 case INDEX_op_ld8u_i32:
1348 tcg_out_ldst (s, args[0], args[1], args[2], LBZ, LBZX);
1350 case INDEX_op_ld8s_i32:
1351 tcg_out_ldst (s, args[0], args[1], args[2], LBZ, LBZX);
1352 tcg_out32 (s, EXTSB | RS (args[0]) | RA (args[0]));
1354 case INDEX_op_ld16u_i32:
1355 tcg_out_ldst (s, args[0], args[1], args[2], LHZ, LHZX);
1357 case INDEX_op_ld16s_i32:
1358 tcg_out_ldst (s, args[0], args[1], args[2], LHA, LHAX);
1360 case INDEX_op_ld_i32:
1361 tcg_out_ldst (s, args[0], args[1], args[2], LWZ, LWZX);
1363 case INDEX_op_st8_i32:
1364 tcg_out_ldst (s, args[0], args[1], args[2], STB, STBX);
1366 case INDEX_op_st16_i32:
1367 tcg_out_ldst (s, args[0], args[1], args[2], STH, STHX);
1369 case INDEX_op_st_i32:
1370 tcg_out_ldst (s, args[0], args[1], args[2], STW, STWX);
1373 case INDEX_op_add_i32:
1375 ppc_addi (s, args[0], args[1], args[2]);
1377 tcg_out32 (s, ADD | TAB (args[0], args[1], args[2]));
1379 case INDEX_op_sub_i32:
1381 ppc_addi (s, args[0], args[1], -args[2]);
1383 tcg_out32 (s, SUBF | TAB (args[0], args[2], args[1]));
1386 case INDEX_op_and_i32:
1387 if (const_args[2]) {
1393 tcg_out_movi (s, TCG_TYPE_I32, args[0], 0);
1403 if ((t & (t - 1)) == 0) {
1406 if ((c & 0x80000001) == 0x80000001) {
1421 tcg_out32 (s, (RLWINM
1431 #endif /* !__PPU__ */
1433 if ((c & 0xffff) == c)
1434 tcg_out32 (s, ANDI | RS (args[1]) | RA (args[0]) | c);
1435 else if ((c & 0xffff0000) == c)
1436 tcg_out32 (s, ANDIS | RS (args[1]) | RA (args[0])
1437 | ((c >> 16) & 0xffff));
1439 tcg_out_movi (s, TCG_TYPE_I32, 0, c);
1440 tcg_out32 (s, AND | SAB (args[1], args[0], 0));
1445 tcg_out32 (s, AND | SAB (args[1], args[0], args[2]));
1447 case INDEX_op_or_i32:
1448 if (const_args[2]) {
1449 if (args[2] & 0xffff) {
1450 tcg_out32 (s, ORI | RS (args[1]) | RA (args[0])
1451 | (args[2] & 0xffff));
1453 tcg_out32 (s, ORIS | RS (args[0]) | RA (args[0])
1454 | ((args[2] >> 16) & 0xffff));
1457 tcg_out32 (s, ORIS | RS (args[1]) | RA (args[0])
1458 | ((args[2] >> 16) & 0xffff));
1462 tcg_out32 (s, OR | SAB (args[1], args[0], args[2]));
1464 case INDEX_op_xor_i32:
1465 if (const_args[2]) {
1466 if ((args[2] & 0xffff) == args[2])
1467 tcg_out32 (s, XORI | RS (args[1]) | RA (args[0])
1468 | (args[2] & 0xffff));
1469 else if ((args[2] & 0xffff0000) == args[2])
1470 tcg_out32 (s, XORIS | RS (args[1]) | RA (args[0])
1471 | ((args[2] >> 16) & 0xffff));
1473 tcg_out_movi (s, TCG_TYPE_I32, 0, args[2]);
1474 tcg_out32 (s, XOR | SAB (args[1], args[0], 0));
1478 tcg_out32 (s, XOR | SAB (args[1], args[0], args[2]));
1480 case INDEX_op_andc_i32:
1481 tcg_out32 (s, ANDC | SAB (args[1], args[0], args[2]));
1483 case INDEX_op_orc_i32:
1484 tcg_out32 (s, ORC | SAB (args[1], args[0], args[2]));
1487 case INDEX_op_mul_i32:
1488 if (const_args[2]) {
1489 if (args[2] == (int16_t) args[2])
1490 tcg_out32 (s, MULLI | RT (args[0]) | RA (args[1])
1491 | (args[2] & 0xffff));
1493 tcg_out_movi (s, TCG_TYPE_I32, 0, args[2]);
1494 tcg_out32 (s, MULLW | TAB (args[0], args[1], 0));
1498 tcg_out32 (s, MULLW | TAB (args[0], args[1], args[2]));
1501 case INDEX_op_div_i32:
1502 tcg_out32 (s, DIVW | TAB (args[0], args[1], args[2]));
1505 case INDEX_op_divu_i32:
1506 tcg_out32 (s, DIVWU | TAB (args[0], args[1], args[2]));
1509 case INDEX_op_rem_i32:
1510 tcg_out32 (s, DIVW | TAB (0, args[1], args[2]));
1511 tcg_out32 (s, MULLW | TAB (0, 0, args[2]));
1512 tcg_out32 (s, SUBF | TAB (args[0], 0, args[1]));
1515 case INDEX_op_remu_i32:
1516 tcg_out32 (s, DIVWU | TAB (0, args[1], args[2]));
1517 tcg_out32 (s, MULLW | TAB (0, 0, args[2]));
1518 tcg_out32 (s, SUBF | TAB (args[0], 0, args[1]));
1521 case INDEX_op_mulu2_i32:
1522 if (args[0] == args[2] || args[0] == args[3]) {
1523 tcg_out32 (s, MULLW | TAB (0, args[2], args[3]));
1524 tcg_out32 (s, MULHWU | TAB (args[1], args[2], args[3]));
1525 tcg_out_mov (s, args[0], 0);
1528 tcg_out32 (s, MULLW | TAB (args[0], args[2], args[3]));
1529 tcg_out32 (s, MULHWU | TAB (args[1], args[2], args[3]));
1533 case INDEX_op_shl_i32:
1534 if (const_args[2]) {
1535 tcg_out32 (s, (RLWINM
1545 tcg_out32 (s, SLW | SAB (args[1], args[0], args[2]));
1547 case INDEX_op_shr_i32:
1548 if (const_args[2]) {
1549 tcg_out32 (s, (RLWINM
1559 tcg_out32 (s, SRW | SAB (args[1], args[0], args[2]));
1561 case INDEX_op_sar_i32:
1563 tcg_out32 (s, SRAWI | RS (args[1]) | RA (args[0]) | SH (args[2]));
1565 tcg_out32 (s, SRAW | SAB (args[1], args[0], args[2]));
1567 case INDEX_op_rotl_i32:
1574 | (const_args[2] ? RLWINM | SH (args[2])
1575 : RLWNM | RB (args[2]))
1580 case INDEX_op_rotr_i32:
1581 if (const_args[2]) {
1583 tcg_out_mov (s, args[0], args[1]);
1586 tcg_out32 (s, RLWINM
1596 tcg_out32 (s, SUBFIC | RT (0) | RA (args[2]) | 32);
1607 case INDEX_op_add2_i32:
1608 if (args[0] == args[3] || args[0] == args[5]) {
1609 tcg_out32 (s, ADDC | TAB (0, args[2], args[4]));
1610 tcg_out32 (s, ADDE | TAB (args[1], args[3], args[5]));
1611 tcg_out_mov (s, args[0], 0);
1614 tcg_out32 (s, ADDC | TAB (args[0], args[2], args[4]));
1615 tcg_out32 (s, ADDE | TAB (args[1], args[3], args[5]));
1618 case INDEX_op_sub2_i32:
1619 if (args[0] == args[3] || args[0] == args[5]) {
1620 tcg_out32 (s, SUBFC | TAB (0, args[4], args[2]));
1621 tcg_out32 (s, SUBFE | TAB (args[1], args[5], args[3]));
1622 tcg_out_mov (s, args[0], 0);
1625 tcg_out32 (s, SUBFC | TAB (args[0], args[4], args[2]));
1626 tcg_out32 (s, SUBFE | TAB (args[1], args[5], args[3]));
1630 case INDEX_op_brcond_i32:
1635 args[3] = r1 is const
1636 args[4] = label_index
1638 tcg_out_brcond (s, args[2], args[0], args[1], const_args[1], args[3]);
1640 case INDEX_op_brcond2_i32:
1641 tcg_out_brcond2(s, args, const_args);
1644 case INDEX_op_neg_i32:
1645 tcg_out32 (s, NEG | RT (args[0]) | RA (args[1]));
1648 case INDEX_op_not_i32:
1649 tcg_out32 (s, NOR | SAB (args[1], args[0], args[1]));
1652 case INDEX_op_qemu_ld8u:
1653 tcg_out_qemu_ld(s, args, 0);
1655 case INDEX_op_qemu_ld8s:
1656 tcg_out_qemu_ld(s, args, 0 | 4);
1658 case INDEX_op_qemu_ld16u:
1659 tcg_out_qemu_ld(s, args, 1);
1661 case INDEX_op_qemu_ld16s:
1662 tcg_out_qemu_ld(s, args, 1 | 4);
1664 case INDEX_op_qemu_ld32:
1665 tcg_out_qemu_ld(s, args, 2);
1667 case INDEX_op_qemu_ld64:
1668 tcg_out_qemu_ld(s, args, 3);
1670 case INDEX_op_qemu_st8:
1671 tcg_out_qemu_st(s, args, 0);
1673 case INDEX_op_qemu_st16:
1674 tcg_out_qemu_st(s, args, 1);
1676 case INDEX_op_qemu_st32:
1677 tcg_out_qemu_st(s, args, 2);
1679 case INDEX_op_qemu_st64:
1680 tcg_out_qemu_st(s, args, 3);
1683 case INDEX_op_ext8s_i32:
1684 tcg_out32 (s, EXTSB | RS (args[1]) | RA (args[0]));
1686 case INDEX_op_ext8u_i32:
1687 tcg_out32 (s, RLWINM
1695 case INDEX_op_ext16s_i32:
1696 tcg_out32 (s, EXTSH | RS (args[1]) | RA (args[0]));
1698 case INDEX_op_ext16u_i32:
1699 tcg_out32 (s, RLWINM
1708 case INDEX_op_setcond_i32:
1709 tcg_out_setcond (s, args[3], args[0], args[1], args[2], const_args[2]);
1711 case INDEX_op_setcond2_i32:
1712 tcg_out_setcond2 (s, args, const_args);
1716 tcg_dump_ops (s, stderr);
1721 static const TCGTargetOpDef ppc_op_defs[] = {
1722 { INDEX_op_exit_tb, { } },
1723 { INDEX_op_goto_tb, { } },
1724 { INDEX_op_call, { "ri" } },
1725 { INDEX_op_jmp, { "ri" } },
1726 { INDEX_op_br, { } },
1728 { INDEX_op_mov_i32, { "r", "r" } },
1729 { INDEX_op_movi_i32, { "r" } },
1730 { INDEX_op_ld8u_i32, { "r", "r" } },
1731 { INDEX_op_ld8s_i32, { "r", "r" } },
1732 { INDEX_op_ld16u_i32, { "r", "r" } },
1733 { INDEX_op_ld16s_i32, { "r", "r" } },
1734 { INDEX_op_ld_i32, { "r", "r" } },
1735 { INDEX_op_st8_i32, { "r", "r" } },
1736 { INDEX_op_st16_i32, { "r", "r" } },
1737 { INDEX_op_st_i32, { "r", "r" } },
1739 { INDEX_op_add_i32, { "r", "r", "ri" } },
1740 { INDEX_op_mul_i32, { "r", "r", "ri" } },
1741 { INDEX_op_div_i32, { "r", "r", "r" } },
1742 { INDEX_op_divu_i32, { "r", "r", "r" } },
1743 { INDEX_op_rem_i32, { "r", "r", "r" } },
1744 { INDEX_op_remu_i32, { "r", "r", "r" } },
1745 { INDEX_op_mulu2_i32, { "r", "r", "r", "r" } },
1746 { INDEX_op_sub_i32, { "r", "r", "ri" } },
1747 { INDEX_op_and_i32, { "r", "r", "ri" } },
1748 { INDEX_op_or_i32, { "r", "r", "ri" } },
1749 { INDEX_op_xor_i32, { "r", "r", "ri" } },
1751 { INDEX_op_shl_i32, { "r", "r", "ri" } },
1752 { INDEX_op_shr_i32, { "r", "r", "ri" } },
1753 { INDEX_op_sar_i32, { "r", "r", "ri" } },
1755 { INDEX_op_rotl_i32, { "r", "r", "ri" } },
1756 { INDEX_op_rotr_i32, { "r", "r", "ri" } },
1758 { INDEX_op_brcond_i32, { "r", "ri" } },
1760 { INDEX_op_add2_i32, { "r", "r", "r", "r", "r", "r" } },
1761 { INDEX_op_sub2_i32, { "r", "r", "r", "r", "r", "r" } },
1762 { INDEX_op_brcond2_i32, { "r", "r", "r", "r" } },
1764 { INDEX_op_neg_i32, { "r", "r" } },
1765 { INDEX_op_not_i32, { "r", "r" } },
1767 { INDEX_op_andc_i32, { "r", "r", "r" } },
1768 { INDEX_op_orc_i32, { "r", "r", "r" } },
1770 { INDEX_op_setcond_i32, { "r", "r", "ri" } },
1771 { INDEX_op_setcond2_i32, { "r", "r", "r", "ri", "ri" } },
1773 #if TARGET_LONG_BITS == 32
1774 { INDEX_op_qemu_ld8u, { "r", "L" } },
1775 { INDEX_op_qemu_ld8s, { "r", "L" } },
1776 { INDEX_op_qemu_ld16u, { "r", "L" } },
1777 { INDEX_op_qemu_ld16s, { "r", "L" } },
1778 { INDEX_op_qemu_ld32, { "r", "L" } },
1779 { INDEX_op_qemu_ld64, { "r", "r", "L" } },
1781 { INDEX_op_qemu_st8, { "K", "K" } },
1782 { INDEX_op_qemu_st16, { "K", "K" } },
1783 { INDEX_op_qemu_st32, { "K", "K" } },
1784 { INDEX_op_qemu_st64, { "M", "M", "M" } },
1786 { INDEX_op_qemu_ld8u, { "r", "L", "L" } },
1787 { INDEX_op_qemu_ld8s, { "r", "L", "L" } },
1788 { INDEX_op_qemu_ld16u, { "r", "L", "L" } },
1789 { INDEX_op_qemu_ld16s, { "r", "L", "L" } },
1790 { INDEX_op_qemu_ld32, { "r", "L", "L" } },
1791 { INDEX_op_qemu_ld64, { "r", "L", "L", "L" } },
1793 { INDEX_op_qemu_st8, { "K", "K", "K" } },
1794 { INDEX_op_qemu_st16, { "K", "K", "K" } },
1795 { INDEX_op_qemu_st32, { "K", "K", "K" } },
1796 { INDEX_op_qemu_st64, { "M", "M", "M", "M" } },
1799 { INDEX_op_ext8s_i32, { "r", "r" } },
1800 { INDEX_op_ext8u_i32, { "r", "r" } },
1801 { INDEX_op_ext16s_i32, { "r", "r" } },
1802 { INDEX_op_ext16u_i32, { "r", "r" } },
1807 void tcg_target_init(TCGContext *s)
1809 tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
1810 tcg_regset_set32(tcg_target_call_clobber_regs, 0,
1822 (1 << TCG_REG_R10) |
1823 (1 << TCG_REG_R11) |
1827 tcg_regset_clear(s->reserved_regs);
1828 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0);
1829 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R1);
1830 #ifndef _CALL_DARWIN
1831 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R2);
1834 tcg_regset_set_reg(s->reserved_regs, TCG_REG_R13);
1836 #ifdef CONFIG_USE_GUEST_BASE
1837 tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
1840 tcg_add_target_add_op_defs(ppc_op_defs);