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
;
27 #if defined _CALL_DARWIN || defined __APPLE__
28 #define TCG_TARGET_CALL_DARWIN
31 #ifdef TCG_TARGET_CALL_DARWIN
32 #define LINKAGE_AREA_SIZE 24
34 #elif defined _CALL_AIX
35 #define LINKAGE_AREA_SIZE 52
38 #define LINKAGE_AREA_SIZE 8
48 #ifdef CONFIG_USE_GUEST_BASE
49 #define TCG_GUEST_BASE_REG 30
51 #define TCG_GUEST_BASE_REG 0
55 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
91 static const int tcg_target_reg_alloc_order
[] = {
106 #ifdef TCG_TARGET_CALL_DARWIN
117 #ifndef TCG_TARGET_CALL_DARWIN
130 static const int tcg_target_call_iarg_regs
[] = {
141 static const int tcg_target_call_oarg_regs
[2] = {
146 static const int tcg_target_callee_save_regs
[] = {
147 #ifdef TCG_TARGET_CALL_DARWIN
167 TCG_REG_R27
, /* currently used for the global env */
174 static uint32_t reloc_pc24_val (void *pc
, tcg_target_long target
)
176 tcg_target_long disp
;
178 disp
= target
- (tcg_target_long
) pc
;
179 if ((disp
<< 6) >> 6 != disp
)
182 return disp
& 0x3fffffc;
185 static void reloc_pc24 (void *pc
, tcg_target_long target
)
187 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0x3fffffc)
188 | reloc_pc24_val (pc
, target
);
191 static uint16_t reloc_pc14_val (void *pc
, tcg_target_long target
)
193 tcg_target_long disp
;
195 disp
= target
- (tcg_target_long
) pc
;
196 if (disp
!= (int16_t) disp
)
199 return disp
& 0xfffc;
202 static void reloc_pc14 (void *pc
, tcg_target_long target
)
204 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0xfffc)
205 | reloc_pc14_val (pc
, target
);
208 static void patch_reloc(uint8_t *code_ptr
, int type
,
209 tcg_target_long value
, tcg_target_long addend
)
214 reloc_pc14 (code_ptr
, value
);
217 reloc_pc24 (code_ptr
, value
);
224 /* maximum number of register used for input function arguments */
225 static int tcg_target_get_call_iarg_regs_count(int flags
)
227 return ARRAY_SIZE (tcg_target_call_iarg_regs
);
230 /* parse target specific constraints */
231 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
237 case 'A': case 'B': case 'C': case 'D':
238 ct
->ct
|= TCG_CT_REG
;
239 tcg_regset_set_reg(ct
->u
.regs
, 3 + ct_str
[0] - 'A');
242 ct
->ct
|= TCG_CT_REG
;
243 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
245 #ifdef CONFIG_SOFTMMU
246 case 'L': /* qemu_ld constraint */
247 ct
->ct
|= TCG_CT_REG
;
248 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
249 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
250 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
251 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
252 #if TARGET_LONG_BITS == 64
253 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R6
);
254 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
255 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R7
);
259 case 'K': /* qemu_st[8..32] constraint */
260 ct
->ct
|= TCG_CT_REG
;
261 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
262 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
263 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
264 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
265 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R6
);
266 #if TARGET_LONG_BITS == 64
267 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R7
);
268 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
269 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R8
);
273 case 'M': /* qemu_st64 constraint */
274 ct
->ct
|= TCG_CT_REG
;
275 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
276 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
277 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
278 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
279 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R6
);
280 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R7
);
281 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R8
);
282 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
283 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R9
);
289 ct
->ct
|= TCG_CT_REG
;
290 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
293 ct
->ct
|= TCG_CT_REG
;
294 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
295 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
306 /* test if a constant matches the constraint */
307 static int tcg_target_const_match(tcg_target_long val
,
308 const TCGArgConstraint
*arg_ct
)
313 if (ct
& TCG_CT_CONST
)
318 #define OPCD(opc) ((opc)<<26)
319 #define XO31(opc) (OPCD(31)|((opc)<<1))
320 #define XO19(opc) (OPCD(19)|((opc)<<1))
332 #define ADDIC OPCD(12)
333 #define ADDI OPCD(14)
334 #define ADDIS OPCD(15)
336 #define ORIS OPCD(25)
337 #define XORI OPCD(26)
338 #define XORIS OPCD(27)
339 #define ANDI OPCD(28)
340 #define ANDIS OPCD(29)
341 #define MULLI OPCD( 7)
342 #define CMPLI OPCD(10)
343 #define CMPI OPCD(11)
344 #define SUBFIC OPCD( 8)
346 #define LWZU OPCD(33)
347 #define STWU OPCD(37)
349 #define RLWIMI OPCD(20)
350 #define RLWINM OPCD(21)
351 #define RLWNM OPCD(23)
353 #define BCLR XO19( 16)
354 #define BCCTR XO19(528)
355 #define CRAND XO19(257)
356 #define CRANDC XO19(129)
357 #define CRNAND XO19(225)
358 #define CROR XO19(449)
359 #define CRNOR XO19( 33)
361 #define EXTSB XO31(954)
362 #define EXTSH XO31(922)
363 #define ADD XO31(266)
364 #define ADDE XO31(138)
365 #define ADDC XO31( 10)
366 #define AND XO31( 28)
367 #define SUBF XO31( 40)
368 #define SUBFC XO31( 8)
369 #define SUBFE XO31(136)
371 #define XOR XO31(316)
372 #define MULLW XO31(235)
373 #define MULHWU XO31( 11)
374 #define DIVW XO31(491)
375 #define DIVWU XO31(459)
377 #define CMPL XO31( 32)
378 #define LHBRX XO31(790)
379 #define LWBRX XO31(534)
380 #define STHBRX XO31(918)
381 #define STWBRX XO31(662)
382 #define MFSPR XO31(339)
383 #define MTSPR XO31(467)
384 #define SRAWI XO31(824)
385 #define NEG XO31(104)
386 #define MFCR XO31( 19)
387 #define CNTLZW XO31( 26)
388 #define NOR XO31(124)
389 #define ANDC XO31( 60)
390 #define ORC XO31(412)
391 #define EQV XO31(284)
392 #define NAND XO31(476)
394 #define LBZX XO31( 87)
395 #define LHZX XO31(279)
396 #define LHAX XO31(343)
397 #define LWZX XO31( 23)
398 #define STBX XO31(215)
399 #define STHX XO31(407)
400 #define STWX XO31(151)
402 #define SPR(a,b) ((((a)<<5)|(b))<<11)
404 #define CTR SPR(9, 0)
406 #define SLW XO31( 24)
407 #define SRW XO31(536)
408 #define SRAW XO31(792)
411 #define TRAP (TW | TO (31))
413 #define RT(r) ((r)<<21)
414 #define RS(r) ((r)<<21)
415 #define RA(r) ((r)<<16)
416 #define RB(r) ((r)<<11)
417 #define TO(t) ((t)<<21)
418 #define SH(s) ((s)<<11)
419 #define MB(b) ((b)<<6)
420 #define ME(e) ((e)<<1)
421 #define BO(o) ((o)<<21)
425 #define TAB(t,a,b) (RT(t) | RA(a) | RB(b))
426 #define SAB(s,a,b) (RS(s) | RA(a) | RB(b))
428 #define BF(n) ((n)<<23)
429 #define BI(n, c) (((c)+((n)*4))<<16)
430 #define BT(n, c) (((c)+((n)*4))<<21)
431 #define BA(n, c) (((c)+((n)*4))<<16)
432 #define BB(n, c) (((c)+((n)*4))<<11)
434 #define BO_COND_TRUE BO (12)
435 #define BO_COND_FALSE BO (4)
436 #define BO_ALWAYS BO (20)
445 static const uint32_t tcg_to_bc
[10] = {
446 [TCG_COND_EQ
] = BC
| BI (7, CR_EQ
) | BO_COND_TRUE
,
447 [TCG_COND_NE
] = BC
| BI (7, CR_EQ
) | BO_COND_FALSE
,
448 [TCG_COND_LT
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
449 [TCG_COND_GE
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
450 [TCG_COND_LE
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
451 [TCG_COND_GT
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
452 [TCG_COND_LTU
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
453 [TCG_COND_GEU
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
454 [TCG_COND_LEU
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
455 [TCG_COND_GTU
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
458 static void tcg_out_mov(TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg
)
460 tcg_out32 (s
, OR
| SAB (arg
, ret
, arg
));
463 static void tcg_out_movi(TCGContext
*s
, TCGType type
,
464 TCGReg ret
, tcg_target_long arg
)
466 if (arg
== (int16_t) arg
)
467 tcg_out32 (s
, ADDI
| RT (ret
) | RA (0) | (arg
& 0xffff));
469 tcg_out32 (s
, ADDIS
| RT (ret
) | RA (0) | ((arg
>> 16) & 0xffff));
471 tcg_out32 (s
, ORI
| RS (ret
) | RA (ret
) | (arg
& 0xffff));
475 static void tcg_out_ldst (TCGContext
*s
, int ret
, int addr
,
476 int offset
, int op1
, int op2
)
478 if (offset
== (int16_t) offset
)
479 tcg_out32 (s
, op1
| RT (ret
) | RA (addr
) | (offset
& 0xffff));
481 tcg_out_movi (s
, TCG_TYPE_I32
, 0, offset
);
482 tcg_out32 (s
, op2
| RT (ret
) | RA (addr
) | RB (0));
486 static void tcg_out_b (TCGContext
*s
, int mask
, tcg_target_long target
)
488 tcg_target_long disp
;
490 disp
= target
- (tcg_target_long
) s
->code_ptr
;
491 if ((disp
<< 6) >> 6 == disp
)
492 tcg_out32 (s
, B
| (disp
& 0x3fffffc) | mask
);
494 tcg_out_movi (s
, TCG_TYPE_I32
, 0, (tcg_target_long
) target
);
495 tcg_out32 (s
, MTSPR
| RS (0) | CTR
);
496 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| mask
);
500 static void tcg_out_call (TCGContext
*s
, tcg_target_long arg
, int const_arg
)
507 tcg_out_movi (s
, TCG_TYPE_I32
, reg
, arg
);
511 tcg_out32 (s
, LWZ
| RT (0) | RA (reg
));
512 tcg_out32 (s
, MTSPR
| RA (0) | CTR
);
513 tcg_out32 (s
, LWZ
| RT (2) | RA (reg
) | 4);
514 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| LK
);
517 tcg_out_b (s
, LK
, arg
);
520 tcg_out32 (s
, MTSPR
| RS (arg
) | LR
);
521 tcg_out32 (s
, BCLR
| BO_ALWAYS
| LK
);
526 #if defined(CONFIG_SOFTMMU)
528 #include "../../softmmu_defs.h"
530 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
532 static const void * const qemu_ld_helpers
[4] = {
539 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
540 uintxx_t val, int mmu_idx) */
541 static const void * const qemu_st_helpers
[4] = {
549 static void tcg_out_qemu_ld (TCGContext
*s
, const TCGArg
*args
, int opc
)
551 int addr_reg
, data_reg
, data_reg2
, r0
, r1
, rbase
, bswap
;
552 #ifdef CONFIG_SOFTMMU
553 int mem_index
, s_bits
, r2
, ir
;
554 void *label1_ptr
, *label2_ptr
;
555 #if TARGET_LONG_BITS == 64
567 #ifdef CONFIG_SOFTMMU
568 #if TARGET_LONG_BITS == 64
578 tcg_out32 (s
, (RLWINM
581 | SH (32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
))
582 | MB (32 - (CPU_TLB_BITS
+ CPU_TLB_ENTRY_BITS
))
583 | ME (31 - CPU_TLB_ENTRY_BITS
)
586 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (TCG_AREG0
));
590 | offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_read
)
593 tcg_out32 (s
, (RLWINM
597 | MB ((32 - s_bits
) & 31)
598 | ME (31 - TARGET_PAGE_BITS
)
602 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
));
603 #if TARGET_LONG_BITS == 64
604 tcg_out32 (s
, LWZ
| RT (r1
) | RA (r0
) | 4);
605 tcg_out32 (s
, CMP
| BF (6) | RA (addr_reg2
) | RB (r1
));
606 tcg_out32 (s
, CRAND
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
609 label1_ptr
= s
->code_ptr
;
611 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
616 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, TCG_AREG0
);
617 #if TARGET_LONG_BITS == 32
618 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg
);
620 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
623 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg2
);
624 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg
);
626 tcg_out_movi (s
, TCG_TYPE_I32
, ir
, mem_index
);
628 tcg_out_call (s
, (tcg_target_long
) qemu_ld_helpers
[s_bits
], 1);
631 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (3));
634 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (3));
640 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg
, 3);
644 if (data_reg2
== 4) {
645 tcg_out_mov (s
, TCG_TYPE_I32
, 0, 4);
646 tcg_out_mov (s
, TCG_TYPE_I32
, 4, 3);
647 tcg_out_mov (s
, TCG_TYPE_I32
, 3, 0);
650 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 3);
651 tcg_out_mov (s
, TCG_TYPE_I32
, 3, 4);
655 if (data_reg
!= 4) tcg_out_mov (s
, TCG_TYPE_I32
, data_reg
, 4);
656 if (data_reg2
!= 3) tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 3);
660 label2_ptr
= s
->code_ptr
;
663 /* label1: fast path */
665 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
668 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
672 | (offsetof (CPUTLBEntry
, addend
)
673 - offsetof (CPUTLBEntry
, addr_read
))
675 /* r0 = env->tlb_table[mem_index][index].addend */
676 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (addr_reg
));
677 /* r0 = env->tlb_table[mem_index][index].addend + addr */
679 #else /* !CONFIG_SOFTMMU */
682 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
685 #ifdef TARGET_WORDS_BIGENDIAN
694 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
697 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
698 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (data_reg
));
702 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
704 tcg_out32 (s
, LHZX
| TAB (data_reg
, rbase
, r0
));
708 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
709 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (data_reg
));
711 else tcg_out32 (s
, LHAX
| TAB (data_reg
, rbase
, r0
));
715 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
717 tcg_out32 (s
, LWZX
| TAB (data_reg
, rbase
, r0
));
721 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
722 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
723 tcg_out32 (s
, LWBRX
| TAB (data_reg2
, rbase
, r1
));
726 #ifdef CONFIG_USE_GUEST_BASE
727 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
728 tcg_out32 (s
, LWZX
| TAB (data_reg2
, rbase
, r0
));
729 tcg_out32 (s
, LWZX
| TAB (data_reg
, rbase
, r1
));
731 if (r0
== data_reg2
) {
732 tcg_out32 (s
, LWZ
| RT (0) | RA (r0
));
733 tcg_out32 (s
, LWZ
| RT (data_reg
) | RA (r0
) | 4);
734 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 0);
737 tcg_out32 (s
, LWZ
| RT (data_reg2
) | RA (r0
));
738 tcg_out32 (s
, LWZ
| RT (data_reg
) | RA (r0
) | 4);
745 #ifdef CONFIG_SOFTMMU
746 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
750 static void tcg_out_qemu_st (TCGContext
*s
, const TCGArg
*args
, int opc
)
752 int addr_reg
, r0
, r1
, data_reg
, data_reg2
, bswap
, rbase
;
753 #ifdef CONFIG_SOFTMMU
754 int mem_index
, r2
, ir
;
755 void *label1_ptr
, *label2_ptr
;
756 #if TARGET_LONG_BITS == 64
768 #ifdef CONFIG_SOFTMMU
769 #if TARGET_LONG_BITS == 64
778 tcg_out32 (s
, (RLWINM
781 | SH (32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
))
782 | MB (32 - (CPU_TLB_ENTRY_BITS
+ CPU_TLB_BITS
))
783 | ME (31 - CPU_TLB_ENTRY_BITS
)
786 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (TCG_AREG0
));
790 | offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_write
)
793 tcg_out32 (s
, (RLWINM
797 | MB ((32 - opc
) & 31)
798 | ME (31 - TARGET_PAGE_BITS
)
802 tcg_out32 (s
, CMP
| (7 << 23) | RA (r2
) | RB (r1
));
803 #if TARGET_LONG_BITS == 64
804 tcg_out32 (s
, LWZ
| RT (r1
) | RA (r0
) | 4);
805 tcg_out32 (s
, CMP
| BF (6) | RA (addr_reg2
) | RB (r1
));
806 tcg_out32 (s
, CRAND
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
809 label1_ptr
= s
->code_ptr
;
811 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
816 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, TCG_AREG0
);
817 #if TARGET_LONG_BITS == 32
818 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg
);
820 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
823 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg2
);
824 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, addr_reg
);
829 tcg_out32 (s
, (RLWINM
837 tcg_out32 (s
, (RLWINM
845 tcg_out_mov (s
, TCG_TYPE_I32
, ir
, data_reg
);
848 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
851 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, data_reg2
);
852 tcg_out_mov (s
, TCG_TYPE_I32
, ir
, data_reg
);
857 tcg_out_movi (s
, TCG_TYPE_I32
, ir
, mem_index
);
858 tcg_out_call (s
, (tcg_target_long
) qemu_st_helpers
[opc
], 1);
859 label2_ptr
= s
->code_ptr
;
862 /* label1: fast path */
864 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
870 | (offsetof (CPUTLBEntry
, addend
)
871 - offsetof (CPUTLBEntry
, addr_write
))
873 /* r0 = env->tlb_table[mem_index][index].addend */
874 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (addr_reg
));
875 /* r0 = env->tlb_table[mem_index][index].addend + addr */
877 #else /* !CONFIG_SOFTMMU */
880 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
883 #ifdef TARGET_WORDS_BIGENDIAN
890 tcg_out32 (s
, STBX
| SAB (data_reg
, rbase
, r0
));
894 tcg_out32 (s
, STHBRX
| SAB (data_reg
, rbase
, r0
));
896 tcg_out32 (s
, STHX
| SAB (data_reg
, rbase
, r0
));
900 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
902 tcg_out32 (s
, STWX
| SAB (data_reg
, rbase
, r0
));
906 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
907 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
908 tcg_out32 (s
, STWBRX
| SAB (data_reg2
, rbase
, r1
));
911 #ifdef CONFIG_USE_GUEST_BASE
912 tcg_out32 (s
, STWX
| SAB (data_reg2
, rbase
, r0
));
913 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
914 tcg_out32 (s
, STWX
| SAB (data_reg
, rbase
, r1
));
916 tcg_out32 (s
, STW
| RS (data_reg2
) | RA (r0
));
917 tcg_out32 (s
, STW
| RS (data_reg
) | RA (r0
) | 4);
923 #ifdef CONFIG_SOFTMMU
924 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
928 static void tcg_target_qemu_prologue (TCGContext
*s
)
934 + TCG_STATIC_CALL_ARGS_SIZE
935 + ARRAY_SIZE (tcg_target_callee_save_regs
) * 4
936 + CPU_TEMP_BUF_NLONGS
* sizeof(long)
938 frame_size
= (frame_size
+ 15) & ~15;
940 tcg_set_frame(s
, TCG_REG_CALL_STACK
, frame_size
941 - CPU_TEMP_BUF_NLONGS
* sizeof(long),
942 CPU_TEMP_BUF_NLONGS
* sizeof(long));
948 /* First emit adhoc function descriptor */
949 addr
= (uint32_t) s
->code_ptr
+ 12;
950 tcg_out32 (s
, addr
); /* entry point */
951 s
->code_ptr
+= 8; /* skip TOC and environment pointer */
954 tcg_out32 (s
, MFSPR
| RT (0) | LR
);
955 tcg_out32 (s
, STWU
| RS (1) | RA (1) | (-frame_size
& 0xffff));
956 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
958 | RS (tcg_target_callee_save_regs
[i
])
960 | (i
* 4 + LINKAGE_AREA_SIZE
+ TCG_STATIC_CALL_ARGS_SIZE
)
963 tcg_out32 (s
, STW
| RS (0) | RA (1) | (frame_size
+ LR_OFFSET
));
965 #ifdef CONFIG_USE_GUEST_BASE
967 tcg_out_movi (s
, TCG_TYPE_I32
, TCG_GUEST_BASE_REG
, GUEST_BASE
);
968 tcg_regset_set_reg(s
->reserved_regs
, TCG_GUEST_BASE_REG
);
972 tcg_out_mov (s
, TCG_TYPE_PTR
, TCG_AREG0
, tcg_target_call_iarg_regs
[0]);
973 tcg_out32 (s
, MTSPR
| RS (tcg_target_call_iarg_regs
[1]) | CTR
);
974 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
975 tb_ret_addr
= s
->code_ptr
;
977 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
979 | RT (tcg_target_callee_save_regs
[i
])
981 | (i
* 4 + LINKAGE_AREA_SIZE
+ TCG_STATIC_CALL_ARGS_SIZE
)
984 tcg_out32 (s
, LWZ
| RT (0) | RA (1) | (frame_size
+ LR_OFFSET
));
985 tcg_out32 (s
, MTSPR
| RS (0) | LR
);
986 tcg_out32 (s
, ADDI
| RT (1) | RA (1) | frame_size
);
987 tcg_out32 (s
, BCLR
| BO_ALWAYS
);
990 static void tcg_out_ld (TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg1
,
991 tcg_target_long arg2
)
993 tcg_out_ldst (s
, ret
, arg1
, arg2
, LWZ
, LWZX
);
996 static void tcg_out_st (TCGContext
*s
, TCGType type
, TCGReg arg
, TCGReg arg1
,
997 tcg_target_long arg2
)
999 tcg_out_ldst (s
, arg
, arg1
, arg2
, STW
, STWX
);
1002 static void ppc_addi (TCGContext
*s
, int rt
, int ra
, tcg_target_long si
)
1004 if (!si
&& rt
== ra
)
1007 if (si
== (int16_t) si
)
1008 tcg_out32 (s
, ADDI
| RT (rt
) | RA (ra
) | (si
& 0xffff));
1010 uint16_t h
= ((si
>> 16) & 0xffff) + ((uint16_t) si
>> 15);
1011 tcg_out32 (s
, ADDIS
| RT (rt
) | RA (ra
) | h
);
1012 tcg_out32 (s
, ADDI
| RT (rt
) | RA (rt
) | (si
& 0xffff));
1016 static void tcg_out_cmp (TCGContext
*s
, int cond
, TCGArg arg1
, TCGArg arg2
,
1017 int const_arg2
, int cr
)
1026 if ((int16_t) arg2
== arg2
) {
1031 else if ((uint16_t) arg2
== arg2
) {
1046 if ((int16_t) arg2
== arg2
) {
1061 if ((uint16_t) arg2
== arg2
) {
1077 tcg_out32 (s
, op
| RA (arg1
) | (arg2
& 0xffff));
1080 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1081 tcg_out32 (s
, op
| RA (arg1
) | RB (0));
1084 tcg_out32 (s
, op
| RA (arg1
) | RB (arg2
));
1089 static void tcg_out_bc (TCGContext
*s
, int bc
, int label_index
)
1091 TCGLabel
*l
= &s
->labels
[label_index
];
1094 tcg_out32 (s
, bc
| reloc_pc14_val (s
->code_ptr
, l
->u
.value
));
1096 uint16_t val
= *(uint16_t *) &s
->code_ptr
[2];
1098 /* Thanks to Andrzej Zaborowski */
1099 tcg_out32 (s
, bc
| (val
& 0xfffc));
1100 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL14
, label_index
, 0);
1104 static void tcg_out_cr7eq_from_cond (TCGContext
*s
, const TCGArg
*args
,
1105 const int *const_args
)
1107 TCGCond cond
= args
[4];
1109 struct { int bit1
; int bit2
; int cond2
; } bits
[] = {
1110 [TCG_COND_LT
] = { CR_LT
, CR_LT
, TCG_COND_LT
},
1111 [TCG_COND_LE
] = { CR_LT
, CR_GT
, TCG_COND_LT
},
1112 [TCG_COND_GT
] = { CR_GT
, CR_GT
, TCG_COND_GT
},
1113 [TCG_COND_GE
] = { CR_GT
, CR_LT
, TCG_COND_GT
},
1114 [TCG_COND_LTU
] = { CR_LT
, CR_LT
, TCG_COND_LTU
},
1115 [TCG_COND_LEU
] = { CR_LT
, CR_GT
, TCG_COND_LTU
},
1116 [TCG_COND_GTU
] = { CR_GT
, CR_GT
, TCG_COND_GTU
},
1117 [TCG_COND_GEU
] = { CR_GT
, CR_LT
, TCG_COND_GTU
},
1118 }, *b
= &bits
[cond
];
1123 op
= (cond
== TCG_COND_EQ
) ? CRAND
: CRNAND
;
1124 tcg_out_cmp (s
, cond
, args
[0], args
[2], const_args
[2], 6);
1125 tcg_out_cmp (s
, cond
, args
[1], args
[3], const_args
[3], 7);
1126 tcg_out32 (s
, op
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
1136 op
= (b
->bit1
!= b
->bit2
) ? CRANDC
: CRAND
;
1137 tcg_out_cmp (s
, b
->cond2
, args
[1], args
[3], const_args
[3], 5);
1138 tcg_out_cmp (s
, tcg_unsigned_cond (cond
), args
[0], args
[2],
1140 tcg_out32 (s
, op
| BT (7, CR_EQ
) | BA (5, CR_EQ
) | BB (7, b
->bit2
));
1141 tcg_out32 (s
, CROR
| BT (7, CR_EQ
) | BA (5, b
->bit1
) | BB (7, CR_EQ
));
1148 static void tcg_out_setcond (TCGContext
*s
, TCGCond cond
, TCGArg arg0
,
1149 TCGArg arg1
, TCGArg arg2
, int const_arg2
)
1161 if ((uint16_t) arg2
== arg2
) {
1162 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1165 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1166 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1172 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1174 tcg_out32 (s
, CNTLZW
| RS (arg
) | RA (0));
1175 tcg_out32 (s
, (RLWINM
1192 if ((uint16_t) arg2
== arg2
) {
1193 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1196 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1197 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1203 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1206 if (arg
== arg1
&& arg1
== arg0
) {
1207 tcg_out32 (s
, ADDIC
| RT (0) | RA (arg
) | 0xffff);
1208 tcg_out32 (s
, SUBFE
| TAB (arg0
, 0, arg
));
1211 tcg_out32 (s
, ADDIC
| RT (arg0
) | RA (arg
) | 0xffff);
1212 tcg_out32 (s
, SUBFE
| TAB (arg0
, arg0
, arg
));
1231 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_LT
) | BB (7, CR_LT
);
1237 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_GT
) | BB (7, CR_GT
);
1239 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7);
1240 if (crop
) tcg_out32 (s
, crop
);
1241 tcg_out32 (s
, MFCR
| RT (0));
1242 tcg_out32 (s
, (RLWINM
1257 static void tcg_out_setcond2 (TCGContext
*s
, const TCGArg
*args
,
1258 const int *const_args
)
1260 tcg_out_cr7eq_from_cond (s
, args
+ 1, const_args
+ 1);
1261 tcg_out32 (s
, MFCR
| RT (0));
1262 tcg_out32 (s
, (RLWINM
1272 static void tcg_out_brcond (TCGContext
*s
, TCGCond cond
,
1273 TCGArg arg1
, TCGArg arg2
, int const_arg2
,
1276 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7);
1277 tcg_out_bc (s
, tcg_to_bc
[cond
], label_index
);
1280 /* XXX: we implement it at the target level to avoid having to
1281 handle cross basic blocks temporaries */
1282 static void tcg_out_brcond2 (TCGContext
*s
, const TCGArg
*args
,
1283 const int *const_args
)
1285 tcg_out_cr7eq_from_cond (s
, args
, const_args
);
1286 tcg_out_bc (s
, (BC
| BI (7, CR_EQ
) | BO_COND_TRUE
), args
[5]);
1289 void ppc_tb_set_jmp_target (unsigned long jmp_addr
, unsigned long addr
)
1292 long disp
= addr
- jmp_addr
;
1293 unsigned long patch_size
;
1295 ptr
= (uint32_t *)jmp_addr
;
1297 if ((disp
<< 6) >> 6 != disp
) {
1298 ptr
[0] = 0x3c000000 | (addr
>> 16); /* lis 0,addr@ha */
1299 ptr
[1] = 0x60000000 | (addr
& 0xffff); /* la 0,addr@l(0) */
1300 ptr
[2] = 0x7c0903a6; /* mtctr 0 */
1301 ptr
[3] = 0x4e800420; /* brctr */
1304 /* patch the branch destination */
1306 *ptr
= 0x48000000 | (disp
& 0x03fffffc); /* b disp */
1309 ptr
[0] = 0x60000000; /* nop */
1310 ptr
[1] = 0x60000000;
1311 ptr
[2] = 0x60000000;
1312 ptr
[3] = 0x60000000;
1317 flush_icache_range(jmp_addr
, jmp_addr
+ patch_size
);
1320 static void tcg_out_op(TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
1321 const int *const_args
)
1324 case INDEX_op_exit_tb
:
1325 tcg_out_movi (s
, TCG_TYPE_I32
, TCG_REG_R3
, args
[0]);
1326 tcg_out_b (s
, 0, (tcg_target_long
) tb_ret_addr
);
1328 case INDEX_op_goto_tb
:
1329 if (s
->tb_jmp_offset
) {
1330 /* direct jump method */
1332 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1338 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1342 TCGLabel
*l
= &s
->labels
[args
[0]];
1345 tcg_out_b (s
, 0, l
->u
.value
);
1348 uint32_t val
= *(uint32_t *) s
->code_ptr
;
1350 /* Thanks to Andrzej Zaborowski */
1351 tcg_out32 (s
, B
| (val
& 0x3fffffc));
1352 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL24
, args
[0], 0);
1357 tcg_out_call (s
, args
[0], const_args
[0]);
1360 if (const_args
[0]) {
1361 tcg_out_b (s
, 0, args
[0]);
1364 tcg_out32 (s
, MTSPR
| RS (args
[0]) | CTR
);
1365 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
1368 case INDEX_op_movi_i32
:
1369 tcg_out_movi(s
, TCG_TYPE_I32
, args
[0], args
[1]);
1371 case INDEX_op_ld8u_i32
:
1372 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1374 case INDEX_op_ld8s_i32
:
1375 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1376 tcg_out32 (s
, EXTSB
| RS (args
[0]) | RA (args
[0]));
1378 case INDEX_op_ld16u_i32
:
1379 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHZ
, LHZX
);
1381 case INDEX_op_ld16s_i32
:
1382 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHA
, LHAX
);
1384 case INDEX_op_ld_i32
:
1385 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LWZ
, LWZX
);
1387 case INDEX_op_st8_i32
:
1388 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STB
, STBX
);
1390 case INDEX_op_st16_i32
:
1391 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STH
, STHX
);
1393 case INDEX_op_st_i32
:
1394 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STW
, STWX
);
1397 case INDEX_op_add_i32
:
1399 ppc_addi (s
, args
[0], args
[1], args
[2]);
1401 tcg_out32 (s
, ADD
| TAB (args
[0], args
[1], args
[2]));
1403 case INDEX_op_sub_i32
:
1405 ppc_addi (s
, args
[0], args
[1], -args
[2]);
1407 tcg_out32 (s
, SUBF
| TAB (args
[0], args
[2], args
[1]));
1410 case INDEX_op_and_i32
:
1411 if (const_args
[2]) {
1417 tcg_out_movi (s
, TCG_TYPE_I32
, args
[0], 0);
1427 if ((t
& (t
- 1)) == 0) {
1430 if ((c
& 0x80000001) == 0x80000001) {
1445 tcg_out32 (s
, (RLWINM
1455 #endif /* !__PPU__ */
1457 if ((c
& 0xffff) == c
)
1458 tcg_out32 (s
, ANDI
| RS (args
[1]) | RA (args
[0]) | c
);
1459 else if ((c
& 0xffff0000) == c
)
1460 tcg_out32 (s
, ANDIS
| RS (args
[1]) | RA (args
[0])
1461 | ((c
>> 16) & 0xffff));
1463 tcg_out_movi (s
, TCG_TYPE_I32
, 0, c
);
1464 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], 0));
1469 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], args
[2]));
1471 case INDEX_op_or_i32
:
1472 if (const_args
[2]) {
1473 if (args
[2] & 0xffff) {
1474 tcg_out32 (s
, ORI
| RS (args
[1]) | RA (args
[0])
1475 | (args
[2] & 0xffff));
1477 tcg_out32 (s
, ORIS
| RS (args
[0]) | RA (args
[0])
1478 | ((args
[2] >> 16) & 0xffff));
1481 tcg_out32 (s
, ORIS
| RS (args
[1]) | RA (args
[0])
1482 | ((args
[2] >> 16) & 0xffff));
1486 tcg_out32 (s
, OR
| SAB (args
[1], args
[0], args
[2]));
1488 case INDEX_op_xor_i32
:
1489 if (const_args
[2]) {
1490 if ((args
[2] & 0xffff) == args
[2])
1491 tcg_out32 (s
, XORI
| RS (args
[1]) | RA (args
[0])
1492 | (args
[2] & 0xffff));
1493 else if ((args
[2] & 0xffff0000) == args
[2])
1494 tcg_out32 (s
, XORIS
| RS (args
[1]) | RA (args
[0])
1495 | ((args
[2] >> 16) & 0xffff));
1497 tcg_out_movi (s
, TCG_TYPE_I32
, 0, args
[2]);
1498 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], 0));
1502 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], args
[2]));
1504 case INDEX_op_andc_i32
:
1505 tcg_out32 (s
, ANDC
| SAB (args
[1], args
[0], args
[2]));
1507 case INDEX_op_orc_i32
:
1508 tcg_out32 (s
, ORC
| SAB (args
[1], args
[0], args
[2]));
1510 case INDEX_op_eqv_i32
:
1511 tcg_out32 (s
, EQV
| SAB (args
[1], args
[0], args
[2]));
1513 case INDEX_op_nand_i32
:
1514 tcg_out32 (s
, NAND
| SAB (args
[1], args
[0], args
[2]));
1516 case INDEX_op_nor_i32
:
1517 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[2]));
1520 case INDEX_op_mul_i32
:
1521 if (const_args
[2]) {
1522 if (args
[2] == (int16_t) args
[2])
1523 tcg_out32 (s
, MULLI
| RT (args
[0]) | RA (args
[1])
1524 | (args
[2] & 0xffff));
1526 tcg_out_movi (s
, TCG_TYPE_I32
, 0, args
[2]);
1527 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], 0));
1531 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], args
[2]));
1534 case INDEX_op_div_i32
:
1535 tcg_out32 (s
, DIVW
| TAB (args
[0], args
[1], args
[2]));
1538 case INDEX_op_divu_i32
:
1539 tcg_out32 (s
, DIVWU
| TAB (args
[0], args
[1], args
[2]));
1542 case INDEX_op_rem_i32
:
1543 tcg_out32 (s
, DIVW
| TAB (0, args
[1], args
[2]));
1544 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1545 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1548 case INDEX_op_remu_i32
:
1549 tcg_out32 (s
, DIVWU
| TAB (0, args
[1], args
[2]));
1550 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1551 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1554 case INDEX_op_mulu2_i32
:
1555 if (args
[0] == args
[2] || args
[0] == args
[3]) {
1556 tcg_out32 (s
, MULLW
| TAB (0, args
[2], args
[3]));
1557 tcg_out32 (s
, MULHWU
| TAB (args
[1], args
[2], args
[3]));
1558 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1561 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[2], args
[3]));
1562 tcg_out32 (s
, MULHWU
| TAB (args
[1], args
[2], args
[3]));
1566 case INDEX_op_shl_i32
:
1567 if (const_args
[2]) {
1568 tcg_out32 (s
, (RLWINM
1578 tcg_out32 (s
, SLW
| SAB (args
[1], args
[0], args
[2]));
1580 case INDEX_op_shr_i32
:
1581 if (const_args
[2]) {
1582 tcg_out32 (s
, (RLWINM
1592 tcg_out32 (s
, SRW
| SAB (args
[1], args
[0], args
[2]));
1594 case INDEX_op_sar_i32
:
1596 tcg_out32 (s
, SRAWI
| RS (args
[1]) | RA (args
[0]) | SH (args
[2]));
1598 tcg_out32 (s
, SRAW
| SAB (args
[1], args
[0], args
[2]));
1600 case INDEX_op_rotl_i32
:
1607 | (const_args
[2] ? RLWINM
| SH (args
[2])
1608 : RLWNM
| RB (args
[2]))
1613 case INDEX_op_rotr_i32
:
1614 if (const_args
[2]) {
1616 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], args
[1]);
1619 tcg_out32 (s
, RLWINM
1629 tcg_out32 (s
, SUBFIC
| RT (0) | RA (args
[2]) | 32);
1640 case INDEX_op_add2_i32
:
1641 if (args
[0] == args
[3] || args
[0] == args
[5]) {
1642 tcg_out32 (s
, ADDC
| TAB (0, args
[2], args
[4]));
1643 tcg_out32 (s
, ADDE
| TAB (args
[1], args
[3], args
[5]));
1644 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1647 tcg_out32 (s
, ADDC
| TAB (args
[0], args
[2], args
[4]));
1648 tcg_out32 (s
, ADDE
| TAB (args
[1], args
[3], args
[5]));
1651 case INDEX_op_sub2_i32
:
1652 if (args
[0] == args
[3] || args
[0] == args
[5]) {
1653 tcg_out32 (s
, SUBFC
| TAB (0, args
[4], args
[2]));
1654 tcg_out32 (s
, SUBFE
| TAB (args
[1], args
[5], args
[3]));
1655 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1658 tcg_out32 (s
, SUBFC
| TAB (args
[0], args
[4], args
[2]));
1659 tcg_out32 (s
, SUBFE
| TAB (args
[1], args
[5], args
[3]));
1663 case INDEX_op_brcond_i32
:
1668 args[3] = r1 is const
1669 args[4] = label_index
1671 tcg_out_brcond (s
, args
[2], args
[0], args
[1], const_args
[1], args
[3]);
1673 case INDEX_op_brcond2_i32
:
1674 tcg_out_brcond2(s
, args
, const_args
);
1677 case INDEX_op_neg_i32
:
1678 tcg_out32 (s
, NEG
| RT (args
[0]) | RA (args
[1]));
1681 case INDEX_op_not_i32
:
1682 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[1]));
1685 case INDEX_op_qemu_ld8u
:
1686 tcg_out_qemu_ld(s
, args
, 0);
1688 case INDEX_op_qemu_ld8s
:
1689 tcg_out_qemu_ld(s
, args
, 0 | 4);
1691 case INDEX_op_qemu_ld16u
:
1692 tcg_out_qemu_ld(s
, args
, 1);
1694 case INDEX_op_qemu_ld16s
:
1695 tcg_out_qemu_ld(s
, args
, 1 | 4);
1697 case INDEX_op_qemu_ld32
:
1698 tcg_out_qemu_ld(s
, args
, 2);
1700 case INDEX_op_qemu_ld64
:
1701 tcg_out_qemu_ld(s
, args
, 3);
1703 case INDEX_op_qemu_st8
:
1704 tcg_out_qemu_st(s
, args
, 0);
1706 case INDEX_op_qemu_st16
:
1707 tcg_out_qemu_st(s
, args
, 1);
1709 case INDEX_op_qemu_st32
:
1710 tcg_out_qemu_st(s
, args
, 2);
1712 case INDEX_op_qemu_st64
:
1713 tcg_out_qemu_st(s
, args
, 3);
1716 case INDEX_op_ext8s_i32
:
1717 tcg_out32 (s
, EXTSB
| RS (args
[1]) | RA (args
[0]));
1719 case INDEX_op_ext8u_i32
:
1720 tcg_out32 (s
, RLWINM
1728 case INDEX_op_ext16s_i32
:
1729 tcg_out32 (s
, EXTSH
| RS (args
[1]) | RA (args
[0]));
1731 case INDEX_op_ext16u_i32
:
1732 tcg_out32 (s
, RLWINM
1741 case INDEX_op_setcond_i32
:
1742 tcg_out_setcond (s
, args
[3], args
[0], args
[1], args
[2], const_args
[2]);
1744 case INDEX_op_setcond2_i32
:
1745 tcg_out_setcond2 (s
, args
, const_args
);
1748 case INDEX_op_bswap16_i32
:
1749 /* Stolen from gcc's builtin_bswap16 */
1753 /* r0 = (a1 << 8) & 0xff00 # 00d0 */
1754 tcg_out32 (s
, RLWINM
1762 /* a0 = rotate_left (a1, 24) & 0xff # 000c */
1763 tcg_out32 (s
, RLWINM
1771 /* a0 = a0 | r0 # 00dc */
1772 tcg_out32 (s
, OR
| SAB (0, args
[0], args
[0]));
1775 case INDEX_op_bswap32_i32
:
1776 /* Stolen from gcc's builtin_bswap32 */
1780 /* a1 = args[1] # abcd */
1782 if (a0
== args
[1]) {
1786 /* a0 = rotate_left (a1, 8) # bcda */
1787 tcg_out32 (s
, RLWINM
1795 /* a0 = (a0 & ~0xff000000) | ((a1 << 24) & 0xff000000) # dcda */
1796 tcg_out32 (s
, RLWIMI
1804 /* a0 = (a0 & ~0x0000ff00) | ((a1 << 24) & 0x0000ff00) # dcba */
1805 tcg_out32 (s
, RLWIMI
1814 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], a0
);
1819 case INDEX_op_deposit_i32
:
1820 tcg_out32 (s
, RLWIMI
1824 | MB (32 - args
[3] - args
[4])
1835 static const TCGTargetOpDef ppc_op_defs
[] = {
1836 { INDEX_op_exit_tb
, { } },
1837 { INDEX_op_goto_tb
, { } },
1838 { INDEX_op_call
, { "ri" } },
1839 { INDEX_op_jmp
, { "ri" } },
1840 { INDEX_op_br
, { } },
1842 { INDEX_op_mov_i32
, { "r", "r" } },
1843 { INDEX_op_movi_i32
, { "r" } },
1844 { INDEX_op_ld8u_i32
, { "r", "r" } },
1845 { INDEX_op_ld8s_i32
, { "r", "r" } },
1846 { INDEX_op_ld16u_i32
, { "r", "r" } },
1847 { INDEX_op_ld16s_i32
, { "r", "r" } },
1848 { INDEX_op_ld_i32
, { "r", "r" } },
1849 { INDEX_op_st8_i32
, { "r", "r" } },
1850 { INDEX_op_st16_i32
, { "r", "r" } },
1851 { INDEX_op_st_i32
, { "r", "r" } },
1853 { INDEX_op_add_i32
, { "r", "r", "ri" } },
1854 { INDEX_op_mul_i32
, { "r", "r", "ri" } },
1855 { INDEX_op_div_i32
, { "r", "r", "r" } },
1856 { INDEX_op_divu_i32
, { "r", "r", "r" } },
1857 { INDEX_op_rem_i32
, { "r", "r", "r" } },
1858 { INDEX_op_remu_i32
, { "r", "r", "r" } },
1859 { INDEX_op_mulu2_i32
, { "r", "r", "r", "r" } },
1860 { INDEX_op_sub_i32
, { "r", "r", "ri" } },
1861 { INDEX_op_and_i32
, { "r", "r", "ri" } },
1862 { INDEX_op_or_i32
, { "r", "r", "ri" } },
1863 { INDEX_op_xor_i32
, { "r", "r", "ri" } },
1865 { INDEX_op_shl_i32
, { "r", "r", "ri" } },
1866 { INDEX_op_shr_i32
, { "r", "r", "ri" } },
1867 { INDEX_op_sar_i32
, { "r", "r", "ri" } },
1869 { INDEX_op_rotl_i32
, { "r", "r", "ri" } },
1870 { INDEX_op_rotr_i32
, { "r", "r", "ri" } },
1872 { INDEX_op_brcond_i32
, { "r", "ri" } },
1874 { INDEX_op_add2_i32
, { "r", "r", "r", "r", "r", "r" } },
1875 { INDEX_op_sub2_i32
, { "r", "r", "r", "r", "r", "r" } },
1876 { INDEX_op_brcond2_i32
, { "r", "r", "r", "r" } },
1878 { INDEX_op_neg_i32
, { "r", "r" } },
1879 { INDEX_op_not_i32
, { "r", "r" } },
1881 { INDEX_op_andc_i32
, { "r", "r", "r" } },
1882 { INDEX_op_orc_i32
, { "r", "r", "r" } },
1883 { INDEX_op_eqv_i32
, { "r", "r", "r" } },
1884 { INDEX_op_nand_i32
, { "r", "r", "r" } },
1885 { INDEX_op_nor_i32
, { "r", "r", "r" } },
1887 { INDEX_op_setcond_i32
, { "r", "r", "ri" } },
1888 { INDEX_op_setcond2_i32
, { "r", "r", "r", "ri", "ri" } },
1890 { INDEX_op_bswap16_i32
, { "r", "r" } },
1891 { INDEX_op_bswap32_i32
, { "r", "r" } },
1893 #if TARGET_LONG_BITS == 32
1894 { INDEX_op_qemu_ld8u
, { "r", "L" } },
1895 { INDEX_op_qemu_ld8s
, { "r", "L" } },
1896 { INDEX_op_qemu_ld16u
, { "r", "L" } },
1897 { INDEX_op_qemu_ld16s
, { "r", "L" } },
1898 { INDEX_op_qemu_ld32
, { "r", "L" } },
1899 { INDEX_op_qemu_ld64
, { "r", "r", "L" } },
1901 { INDEX_op_qemu_st8
, { "K", "K" } },
1902 { INDEX_op_qemu_st16
, { "K", "K" } },
1903 { INDEX_op_qemu_st32
, { "K", "K" } },
1904 { INDEX_op_qemu_st64
, { "M", "M", "M" } },
1906 { INDEX_op_qemu_ld8u
, { "r", "L", "L" } },
1907 { INDEX_op_qemu_ld8s
, { "r", "L", "L" } },
1908 { INDEX_op_qemu_ld16u
, { "r", "L", "L" } },
1909 { INDEX_op_qemu_ld16s
, { "r", "L", "L" } },
1910 { INDEX_op_qemu_ld32
, { "r", "L", "L" } },
1911 { INDEX_op_qemu_ld64
, { "r", "L", "L", "L" } },
1913 { INDEX_op_qemu_st8
, { "K", "K", "K" } },
1914 { INDEX_op_qemu_st16
, { "K", "K", "K" } },
1915 { INDEX_op_qemu_st32
, { "K", "K", "K" } },
1916 { INDEX_op_qemu_st64
, { "M", "M", "M", "M" } },
1919 { INDEX_op_ext8s_i32
, { "r", "r" } },
1920 { INDEX_op_ext8u_i32
, { "r", "r" } },
1921 { INDEX_op_ext16s_i32
, { "r", "r" } },
1922 { INDEX_op_ext16u_i32
, { "r", "r" } },
1924 { INDEX_op_deposit_i32
, { "r", "0", "r" } },
1929 static void tcg_target_init(TCGContext
*s
)
1931 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I32
], 0, 0xffffffff);
1932 tcg_regset_set32(tcg_target_call_clobber_regs
, 0,
1934 #ifdef TCG_TARGET_CALL_DARWIN
1944 (1 << TCG_REG_R10
) |
1945 (1 << TCG_REG_R11
) |
1949 tcg_regset_clear(s
->reserved_regs
);
1950 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R0
);
1951 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R1
);
1952 #ifndef TCG_TARGET_CALL_DARWIN
1953 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R2
);
1956 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R13
);
1959 tcg_add_target_add_op_defs(ppc_op_defs
);