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
44 #ifdef CONFIG_USE_GUEST_BASE
45 #define TCG_GUEST_BASE_REG 30
47 #define TCG_GUEST_BASE_REG 0
51 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
87 static const int tcg_target_reg_alloc_order
[] = {
126 static const int tcg_target_call_iarg_regs
[] = {
137 static const int tcg_target_call_oarg_regs
[2] = {
142 static const int tcg_target_callee_save_regs
[] = {
163 /* TCG_REG_R27, */ /* currently used for the global env, so no
171 static uint32_t reloc_pc24_val (void *pc
, tcg_target_long target
)
173 tcg_target_long disp
;
175 disp
= target
- (tcg_target_long
) pc
;
176 if ((disp
<< 6) >> 6 != disp
)
179 return disp
& 0x3fffffc;
182 static void reloc_pc24 (void *pc
, tcg_target_long target
)
184 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0x3fffffc)
185 | reloc_pc24_val (pc
, target
);
188 static uint16_t reloc_pc14_val (void *pc
, tcg_target_long target
)
190 tcg_target_long disp
;
192 disp
= target
- (tcg_target_long
) pc
;
193 if (disp
!= (int16_t) disp
)
196 return disp
& 0xfffc;
199 static void reloc_pc14 (void *pc
, tcg_target_long target
)
201 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0xfffc)
202 | reloc_pc14_val (pc
, target
);
205 static void patch_reloc(uint8_t *code_ptr
, int type
,
206 tcg_target_long value
, tcg_target_long addend
)
211 reloc_pc14 (code_ptr
, value
);
214 reloc_pc24 (code_ptr
, value
);
221 /* maximum number of register used for input function arguments */
222 static int tcg_target_get_call_iarg_regs_count(int flags
)
224 return ARRAY_SIZE (tcg_target_call_iarg_regs
);
227 /* parse target specific constraints */
228 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
234 case 'A': case 'B': case 'C': case 'D':
235 ct
->ct
|= TCG_CT_REG
;
236 tcg_regset_set_reg(ct
->u
.regs
, 3 + ct_str
[0] - 'A');
239 ct
->ct
|= TCG_CT_REG
;
240 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
242 #ifdef CONFIG_SOFTMMU
243 case 'L': /* qemu_ld constraint */
244 ct
->ct
|= TCG_CT_REG
;
245 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
246 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
247 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
249 case 'K': /* qemu_st[8..32] constraint */
250 ct
->ct
|= TCG_CT_REG
;
251 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
252 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
253 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
254 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
255 #if TARGET_LONG_BITS == 64
256 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R6
);
259 case 'M': /* qemu_st64 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 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R7
);
271 ct
->ct
|= TCG_CT_REG
;
272 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
275 ct
->ct
|= TCG_CT_REG
;
276 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
277 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
288 /* test if a constant matches the constraint */
289 static int tcg_target_const_match(tcg_target_long val
,
290 const TCGArgConstraint
*arg_ct
)
295 if (ct
& TCG_CT_CONST
)
300 #define OPCD(opc) ((opc)<<26)
301 #define XO31(opc) (OPCD(31)|((opc)<<1))
302 #define XO19(opc) (OPCD(19)|((opc)<<1))
314 #define ADDIC OPCD(12)
315 #define ADDI OPCD(14)
316 #define ADDIS OPCD(15)
318 #define ORIS OPCD(25)
319 #define XORI OPCD(26)
320 #define XORIS OPCD(27)
321 #define ANDI OPCD(28)
322 #define ANDIS OPCD(29)
323 #define MULLI OPCD( 7)
324 #define CMPLI OPCD(10)
325 #define CMPI OPCD(11)
326 #define SUBFIC OPCD( 8)
328 #define LWZU OPCD(33)
329 #define STWU OPCD(37)
331 #define RLWIMI OPCD(20)
332 #define RLWINM OPCD(21)
333 #define RLWNM OPCD(23)
335 #define BCLR XO19( 16)
336 #define BCCTR XO19(528)
337 #define CRAND XO19(257)
338 #define CRANDC XO19(129)
339 #define CRNAND XO19(225)
340 #define CROR XO19(449)
341 #define CRNOR XO19( 33)
343 #define EXTSB XO31(954)
344 #define EXTSH XO31(922)
345 #define ADD XO31(266)
346 #define ADDE XO31(138)
347 #define ADDC XO31( 10)
348 #define AND XO31( 28)
349 #define SUBF XO31( 40)
350 #define SUBFC XO31( 8)
351 #define SUBFE XO31(136)
353 #define XOR XO31(316)
354 #define MULLW XO31(235)
355 #define MULHWU XO31( 11)
356 #define DIVW XO31(491)
357 #define DIVWU XO31(459)
359 #define CMPL XO31( 32)
360 #define LHBRX XO31(790)
361 #define LWBRX XO31(534)
362 #define STHBRX XO31(918)
363 #define STWBRX XO31(662)
364 #define MFSPR XO31(339)
365 #define MTSPR XO31(467)
366 #define SRAWI XO31(824)
367 #define NEG XO31(104)
368 #define MFCR XO31( 19)
369 #define CNTLZW XO31( 26)
370 #define NOR XO31(124)
371 #define ANDC XO31( 60)
372 #define ORC XO31(412)
373 #define EQV XO31(284)
374 #define NAND XO31(476)
376 #define LBZX XO31( 87)
377 #define LHZX XO31(279)
378 #define LHAX XO31(343)
379 #define LWZX XO31( 23)
380 #define STBX XO31(215)
381 #define STHX XO31(407)
382 #define STWX XO31(151)
384 #define SPR(a,b) ((((a)<<5)|(b))<<11)
386 #define CTR SPR(9, 0)
388 #define SLW XO31( 24)
389 #define SRW XO31(536)
390 #define SRAW XO31(792)
393 #define TRAP (TW | TO (31))
395 #define RT(r) ((r)<<21)
396 #define RS(r) ((r)<<21)
397 #define RA(r) ((r)<<16)
398 #define RB(r) ((r)<<11)
399 #define TO(t) ((t)<<21)
400 #define SH(s) ((s)<<11)
401 #define MB(b) ((b)<<6)
402 #define ME(e) ((e)<<1)
403 #define BO(o) ((o)<<21)
407 #define TAB(t,a,b) (RT(t) | RA(a) | RB(b))
408 #define SAB(s,a,b) (RS(s) | RA(a) | RB(b))
410 #define BF(n) ((n)<<23)
411 #define BI(n, c) (((c)+((n)*4))<<16)
412 #define BT(n, c) (((c)+((n)*4))<<21)
413 #define BA(n, c) (((c)+((n)*4))<<16)
414 #define BB(n, c) (((c)+((n)*4))<<11)
416 #define BO_COND_TRUE BO (12)
417 #define BO_COND_FALSE BO (4)
418 #define BO_ALWAYS BO (20)
427 static const uint32_t tcg_to_bc
[10] = {
428 [TCG_COND_EQ
] = BC
| BI (7, CR_EQ
) | BO_COND_TRUE
,
429 [TCG_COND_NE
] = BC
| BI (7, CR_EQ
) | BO_COND_FALSE
,
430 [TCG_COND_LT
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
431 [TCG_COND_GE
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
432 [TCG_COND_LE
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
433 [TCG_COND_GT
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
434 [TCG_COND_LTU
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
435 [TCG_COND_GEU
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
436 [TCG_COND_LEU
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
437 [TCG_COND_GTU
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
440 static void tcg_out_mov(TCGContext
*s
, TCGType type
, int ret
, int arg
)
442 tcg_out32 (s
, OR
| SAB (arg
, ret
, arg
));
445 static void tcg_out_movi(TCGContext
*s
, TCGType type
,
446 int ret
, tcg_target_long arg
)
448 if (arg
== (int16_t) arg
)
449 tcg_out32 (s
, ADDI
| RT (ret
) | RA (0) | (arg
& 0xffff));
451 tcg_out32 (s
, ADDIS
| RT (ret
) | RA (0) | ((arg
>> 16) & 0xffff));
453 tcg_out32 (s
, ORI
| RS (ret
) | RA (ret
) | (arg
& 0xffff));
457 static void tcg_out_ldst (TCGContext
*s
, int ret
, int addr
,
458 int offset
, int op1
, int op2
)
460 if (offset
== (int16_t) offset
)
461 tcg_out32 (s
, op1
| RT (ret
) | RA (addr
) | (offset
& 0xffff));
463 tcg_out_movi (s
, TCG_TYPE_I32
, 0, offset
);
464 tcg_out32 (s
, op2
| RT (ret
) | RA (addr
) | RB (0));
468 static void tcg_out_b (TCGContext
*s
, int mask
, tcg_target_long target
)
470 tcg_target_long disp
;
472 disp
= target
- (tcg_target_long
) s
->code_ptr
;
473 if ((disp
<< 6) >> 6 == disp
)
474 tcg_out32 (s
, B
| (disp
& 0x3fffffc) | mask
);
476 tcg_out_movi (s
, TCG_TYPE_I32
, 0, (tcg_target_long
) target
);
477 tcg_out32 (s
, MTSPR
| RS (0) | CTR
);
478 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| mask
);
482 static void tcg_out_call (TCGContext
*s
, tcg_target_long arg
, int const_arg
)
489 tcg_out_movi (s
, TCG_TYPE_I32
, reg
, arg
);
493 tcg_out32 (s
, LWZ
| RT (0) | RA (reg
));
494 tcg_out32 (s
, MTSPR
| RA (0) | CTR
);
495 tcg_out32 (s
, LWZ
| RT (2) | RA (reg
) | 4);
496 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| LK
);
499 tcg_out_b (s
, LK
, arg
);
502 tcg_out32 (s
, MTSPR
| RS (arg
) | LR
);
503 tcg_out32 (s
, BCLR
| BO_ALWAYS
| LK
);
508 #if defined(CONFIG_SOFTMMU)
510 #include "../../softmmu_defs.h"
512 static void *qemu_ld_helpers
[4] = {
519 static void *qemu_st_helpers
[4] = {
527 static void tcg_out_qemu_ld (TCGContext
*s
, const TCGArg
*args
, int opc
)
529 int addr_reg
, data_reg
, data_reg2
, r0
, r1
, rbase
, mem_index
, s_bits
, bswap
;
530 #ifdef CONFIG_SOFTMMU
532 void *label1_ptr
, *label2_ptr
;
534 #if TARGET_LONG_BITS == 64
544 #if TARGET_LONG_BITS == 64
550 #ifdef CONFIG_SOFTMMU
556 tcg_out32 (s
, (RLWINM
559 | SH (32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
))
560 | MB (32 - (CPU_TLB_BITS
+ CPU_TLB_ENTRY_BITS
))
561 | ME (31 - CPU_TLB_ENTRY_BITS
)
564 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (TCG_AREG0
));
568 | offsetof (CPUState
, tlb_table
[mem_index
][0].addr_read
)
571 tcg_out32 (s
, (RLWINM
575 | MB ((32 - s_bits
) & 31)
576 | ME (31 - TARGET_PAGE_BITS
)
580 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
));
581 #if TARGET_LONG_BITS == 64
582 tcg_out32 (s
, LWZ
| RT (r1
) | RA (r0
) | 4);
583 tcg_out32 (s
, CMP
| BF (6) | RA (addr_reg2
) | RB (r1
));
584 tcg_out32 (s
, CRAND
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
587 label1_ptr
= s
->code_ptr
;
589 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
593 #if TARGET_LONG_BITS == 32
594 tcg_out_mov (s
, TCG_TYPE_I32
, 3, addr_reg
);
595 tcg_out_movi (s
, TCG_TYPE_I32
, 4, mem_index
);
597 tcg_out_mov (s
, TCG_TYPE_I32
, 3, addr_reg2
);
598 tcg_out_mov (s
, TCG_TYPE_I32
, 4, addr_reg
);
599 tcg_out_movi (s
, TCG_TYPE_I32
, 5, mem_index
);
602 tcg_out_call (s
, (tcg_target_long
) qemu_ld_helpers
[s_bits
], 1);
605 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (3));
608 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (3));
614 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg
, 3);
618 if (data_reg2
== 4) {
619 tcg_out_mov (s
, TCG_TYPE_I32
, 0, 4);
620 tcg_out_mov (s
, TCG_TYPE_I32
, 4, 3);
621 tcg_out_mov (s
, TCG_TYPE_I32
, 3, 0);
624 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 3);
625 tcg_out_mov (s
, TCG_TYPE_I32
, 3, 4);
629 if (data_reg
!= 4) tcg_out_mov (s
, TCG_TYPE_I32
, data_reg
, 4);
630 if (data_reg2
!= 3) tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 3);
634 label2_ptr
= s
->code_ptr
;
637 /* label1: fast path */
639 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
642 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
646 | (offsetof (CPUTLBEntry
, addend
)
647 - offsetof (CPUTLBEntry
, addr_read
))
649 /* r0 = env->tlb_table[mem_index][index].addend */
650 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (addr_reg
));
651 /* r0 = env->tlb_table[mem_index][index].addend + addr */
653 #else /* !CONFIG_SOFTMMU */
656 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
659 #ifdef TARGET_WORDS_BIGENDIAN
668 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
671 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
672 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (data_reg
));
676 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
678 tcg_out32 (s
, LHZX
| TAB (data_reg
, rbase
, r0
));
682 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
683 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (data_reg
));
685 else tcg_out32 (s
, LHAX
| TAB (data_reg
, rbase
, r0
));
689 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
691 tcg_out32 (s
, LWZX
| TAB (data_reg
, rbase
, r0
));
695 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
696 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
697 tcg_out32 (s
, LWBRX
| TAB (data_reg2
, rbase
, r1
));
700 #ifdef CONFIG_USE_GUEST_BASE
701 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
702 tcg_out32 (s
, LWZX
| TAB (data_reg2
, rbase
, r0
));
703 tcg_out32 (s
, LWZX
| TAB (data_reg
, rbase
, r1
));
705 if (r0
== data_reg2
) {
706 tcg_out32 (s
, LWZ
| RT (0) | RA (r0
));
707 tcg_out32 (s
, LWZ
| RT (data_reg
) | RA (r0
) | 4);
708 tcg_out_mov (s
, TCG_TYPE_I32
, data_reg2
, 0);
711 tcg_out32 (s
, LWZ
| RT (data_reg2
) | RA (r0
));
712 tcg_out32 (s
, LWZ
| RT (data_reg
) | RA (r0
) | 4);
719 #ifdef CONFIG_SOFTMMU
720 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
724 static void tcg_out_qemu_st (TCGContext
*s
, const TCGArg
*args
, int opc
)
726 int addr_reg
, r0
, r1
, data_reg
, data_reg2
, mem_index
, bswap
, rbase
;
727 #ifdef CONFIG_SOFTMMU
729 void *label1_ptr
, *label2_ptr
;
731 #if TARGET_LONG_BITS == 64
741 #if TARGET_LONG_BITS == 64
746 #ifdef CONFIG_SOFTMMU
752 tcg_out32 (s
, (RLWINM
755 | SH (32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
))
756 | MB (32 - (CPU_TLB_ENTRY_BITS
+ CPU_TLB_BITS
))
757 | ME (31 - CPU_TLB_ENTRY_BITS
)
760 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (TCG_AREG0
));
764 | offsetof (CPUState
, tlb_table
[mem_index
][0].addr_write
)
767 tcg_out32 (s
, (RLWINM
771 | MB ((32 - opc
) & 31)
772 | ME (31 - TARGET_PAGE_BITS
)
776 tcg_out32 (s
, CMP
| (7 << 23) | RA (r2
) | RB (r1
));
777 #if TARGET_LONG_BITS == 64
778 tcg_out32 (s
, LWZ
| RT (r1
) | RA (r0
) | 4);
779 tcg_out32 (s
, CMP
| BF (6) | RA (addr_reg2
) | RB (r1
));
780 tcg_out32 (s
, CRAND
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
783 label1_ptr
= s
->code_ptr
;
785 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
789 #if TARGET_LONG_BITS == 32
790 tcg_out_mov (s
, TCG_TYPE_I32
, 3, addr_reg
);
793 tcg_out_mov (s
, TCG_TYPE_I32
, 3, addr_reg2
);
794 tcg_out_mov (s
, TCG_TYPE_I32
, 4, addr_reg
);
795 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
804 tcg_out32 (s
, (RLWINM
812 tcg_out32 (s
, (RLWINM
820 tcg_out_mov (s
, TCG_TYPE_I32
, ir
, data_reg
);
823 #ifdef TCG_TARGET_CALL_ALIGN_ARGS
826 tcg_out_mov (s
, TCG_TYPE_I32
, ir
++, data_reg2
);
827 tcg_out_mov (s
, TCG_TYPE_I32
, ir
, data_reg
);
832 tcg_out_movi (s
, TCG_TYPE_I32
, ir
, mem_index
);
833 tcg_out_call (s
, (tcg_target_long
) qemu_st_helpers
[opc
], 1);
834 label2_ptr
= s
->code_ptr
;
837 /* label1: fast path */
839 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
845 | (offsetof (CPUTLBEntry
, addend
)
846 - offsetof (CPUTLBEntry
, addr_write
))
848 /* r0 = env->tlb_table[mem_index][index].addend */
849 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (addr_reg
));
850 /* r0 = env->tlb_table[mem_index][index].addend + addr */
852 #else /* !CONFIG_SOFTMMU */
855 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
858 #ifdef TARGET_WORDS_BIGENDIAN
865 tcg_out32 (s
, STBX
| SAB (data_reg
, rbase
, r0
));
869 tcg_out32 (s
, STHBRX
| SAB (data_reg
, rbase
, r0
));
871 tcg_out32 (s
, STHX
| SAB (data_reg
, rbase
, r0
));
875 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
877 tcg_out32 (s
, STWX
| SAB (data_reg
, rbase
, r0
));
881 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
882 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
883 tcg_out32 (s
, STWBRX
| SAB (data_reg2
, rbase
, r1
));
886 #ifdef CONFIG_USE_GUEST_BASE
887 tcg_out32 (s
, STWX
| SAB (data_reg2
, rbase
, r0
));
888 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
889 tcg_out32 (s
, STWX
| SAB (data_reg
, rbase
, r1
));
891 tcg_out32 (s
, STW
| RS (data_reg2
) | RA (r0
));
892 tcg_out32 (s
, STW
| RS (data_reg
) | RA (r0
) | 4);
898 #ifdef CONFIG_SOFTMMU
899 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
903 static void tcg_target_qemu_prologue (TCGContext
*s
)
909 + TCG_STATIC_CALL_ARGS_SIZE
910 + ARRAY_SIZE (tcg_target_callee_save_regs
) * 4
912 frame_size
= (frame_size
+ 15) & ~15;
918 /* First emit adhoc function descriptor */
919 addr
= (uint32_t) s
->code_ptr
+ 12;
920 tcg_out32 (s
, addr
); /* entry point */
921 s
->code_ptr
+= 8; /* skip TOC and environment pointer */
924 tcg_out32 (s
, MFSPR
| RT (0) | LR
);
925 tcg_out32 (s
, STWU
| RS (1) | RA (1) | (-frame_size
& 0xffff));
926 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
928 | RS (tcg_target_callee_save_regs
[i
])
930 | (i
* 4 + LINKAGE_AREA_SIZE
+ TCG_STATIC_CALL_ARGS_SIZE
)
933 tcg_out32 (s
, STW
| RS (0) | RA (1) | (frame_size
+ LR_OFFSET
));
935 #ifdef CONFIG_USE_GUEST_BASE
937 tcg_out_movi (s
, TCG_TYPE_I32
, TCG_GUEST_BASE_REG
, GUEST_BASE
);
938 tcg_regset_set_reg(s
->reserved_regs
, TCG_GUEST_BASE_REG
);
942 tcg_out32 (s
, MTSPR
| RS (3) | CTR
);
943 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
944 tb_ret_addr
= s
->code_ptr
;
946 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
948 | RT (tcg_target_callee_save_regs
[i
])
950 | (i
* 4 + LINKAGE_AREA_SIZE
+ TCG_STATIC_CALL_ARGS_SIZE
)
953 tcg_out32 (s
, LWZ
| RT (0) | RA (1) | (frame_size
+ LR_OFFSET
));
954 tcg_out32 (s
, MTSPR
| RS (0) | LR
);
955 tcg_out32 (s
, ADDI
| RT (1) | RA (1) | frame_size
);
956 tcg_out32 (s
, BCLR
| BO_ALWAYS
);
959 static void tcg_out_ld (TCGContext
*s
, TCGType type
, int ret
, int arg1
,
960 tcg_target_long arg2
)
962 tcg_out_ldst (s
, ret
, arg1
, arg2
, LWZ
, LWZX
);
965 static void tcg_out_st (TCGContext
*s
, TCGType type
, int arg
, int arg1
,
966 tcg_target_long arg2
)
968 tcg_out_ldst (s
, arg
, arg1
, arg2
, STW
, STWX
);
971 static void ppc_addi (TCGContext
*s
, int rt
, int ra
, tcg_target_long si
)
976 if (si
== (int16_t) si
)
977 tcg_out32 (s
, ADDI
| RT (rt
) | RA (ra
) | (si
& 0xffff));
979 uint16_t h
= ((si
>> 16) & 0xffff) + ((uint16_t) si
>> 15);
980 tcg_out32 (s
, ADDIS
| RT (rt
) | RA (ra
) | h
);
981 tcg_out32 (s
, ADDI
| RT (rt
) | RA (rt
) | (si
& 0xffff));
985 static void tcg_out_addi(TCGContext
*s
, int reg
, tcg_target_long val
)
987 ppc_addi (s
, reg
, reg
, val
);
990 static void tcg_out_cmp (TCGContext
*s
, int cond
, TCGArg arg1
, TCGArg arg2
,
991 int const_arg2
, int cr
)
1000 if ((int16_t) arg2
== arg2
) {
1005 else if ((uint16_t) arg2
== arg2
) {
1020 if ((int16_t) arg2
== arg2
) {
1035 if ((uint16_t) arg2
== arg2
) {
1051 tcg_out32 (s
, op
| RA (arg1
) | (arg2
& 0xffff));
1054 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1055 tcg_out32 (s
, op
| RA (arg1
) | RB (0));
1058 tcg_out32 (s
, op
| RA (arg1
) | RB (arg2
));
1063 static void tcg_out_bc (TCGContext
*s
, int bc
, int label_index
)
1065 TCGLabel
*l
= &s
->labels
[label_index
];
1068 tcg_out32 (s
, bc
| reloc_pc14_val (s
->code_ptr
, l
->u
.value
));
1070 uint16_t val
= *(uint16_t *) &s
->code_ptr
[2];
1072 /* Thanks to Andrzej Zaborowski */
1073 tcg_out32 (s
, bc
| (val
& 0xfffc));
1074 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL14
, label_index
, 0);
1078 static void tcg_out_cr7eq_from_cond (TCGContext
*s
, const TCGArg
*args
,
1079 const int *const_args
)
1081 TCGCond cond
= args
[4];
1083 struct { int bit1
; int bit2
; int cond2
; } bits
[] = {
1084 [TCG_COND_LT
] = { CR_LT
, CR_LT
, TCG_COND_LT
},
1085 [TCG_COND_LE
] = { CR_LT
, CR_GT
, TCG_COND_LT
},
1086 [TCG_COND_GT
] = { CR_GT
, CR_GT
, TCG_COND_GT
},
1087 [TCG_COND_GE
] = { CR_GT
, CR_LT
, TCG_COND_GT
},
1088 [TCG_COND_LTU
] = { CR_LT
, CR_LT
, TCG_COND_LTU
},
1089 [TCG_COND_LEU
] = { CR_LT
, CR_GT
, TCG_COND_LTU
},
1090 [TCG_COND_GTU
] = { CR_GT
, CR_GT
, TCG_COND_GTU
},
1091 [TCG_COND_GEU
] = { CR_GT
, CR_LT
, TCG_COND_GTU
},
1092 }, *b
= &bits
[cond
];
1097 op
= (cond
== TCG_COND_EQ
) ? CRAND
: CRNAND
;
1098 tcg_out_cmp (s
, cond
, args
[0], args
[2], const_args
[2], 6);
1099 tcg_out_cmp (s
, cond
, args
[1], args
[3], const_args
[3], 7);
1100 tcg_out32 (s
, op
| BT (7, CR_EQ
) | BA (6, CR_EQ
) | BB (7, CR_EQ
));
1110 op
= (b
->bit1
!= b
->bit2
) ? CRANDC
: CRAND
;
1111 tcg_out_cmp (s
, b
->cond2
, args
[1], args
[3], const_args
[3], 5);
1112 tcg_out_cmp (s
, tcg_unsigned_cond (cond
), args
[0], args
[2],
1114 tcg_out32 (s
, op
| BT (7, CR_EQ
) | BA (5, CR_EQ
) | BB (7, b
->bit2
));
1115 tcg_out32 (s
, CROR
| BT (7, CR_EQ
) | BA (5, b
->bit1
) | BB (7, CR_EQ
));
1122 static void tcg_out_setcond (TCGContext
*s
, TCGCond cond
, TCGArg arg0
,
1123 TCGArg arg1
, TCGArg arg2
, int const_arg2
)
1135 if ((uint16_t) arg2
== arg2
) {
1136 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1139 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1140 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1146 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1148 tcg_out32 (s
, CNTLZW
| RS (arg
) | RA (0));
1149 tcg_out32 (s
, (RLWINM
1166 if ((uint16_t) arg2
== arg2
) {
1167 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1170 tcg_out_movi (s
, TCG_TYPE_I32
, 0, arg2
);
1171 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1177 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1180 if (arg
== arg1
&& arg1
== arg0
) {
1181 tcg_out32 (s
, ADDIC
| RT (0) | RA (arg
) | 0xffff);
1182 tcg_out32 (s
, SUBFE
| TAB (arg0
, 0, arg
));
1185 tcg_out32 (s
, ADDIC
| RT (arg0
) | RA (arg
) | 0xffff);
1186 tcg_out32 (s
, SUBFE
| TAB (arg0
, arg0
, arg
));
1205 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_LT
) | BB (7, CR_LT
);
1211 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_GT
) | BB (7, CR_GT
);
1213 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7);
1214 if (crop
) tcg_out32 (s
, crop
);
1215 tcg_out32 (s
, MFCR
| RT (0));
1216 tcg_out32 (s
, (RLWINM
1231 static void tcg_out_setcond2 (TCGContext
*s
, const TCGArg
*args
,
1232 const int *const_args
)
1234 tcg_out_cr7eq_from_cond (s
, args
+ 1, const_args
+ 1);
1235 tcg_out32 (s
, MFCR
| RT (0));
1236 tcg_out32 (s
, (RLWINM
1246 static void tcg_out_brcond (TCGContext
*s
, TCGCond cond
,
1247 TCGArg arg1
, TCGArg arg2
, int const_arg2
,
1250 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7);
1251 tcg_out_bc (s
, tcg_to_bc
[cond
], label_index
);
1254 /* XXX: we implement it at the target level to avoid having to
1255 handle cross basic blocks temporaries */
1256 static void tcg_out_brcond2 (TCGContext
*s
, const TCGArg
*args
,
1257 const int *const_args
)
1259 tcg_out_cr7eq_from_cond (s
, args
, const_args
);
1260 tcg_out_bc (s
, (BC
| BI (7, CR_EQ
) | BO_COND_TRUE
), args
[5]);
1263 void ppc_tb_set_jmp_target (unsigned long jmp_addr
, unsigned long addr
)
1266 long disp
= addr
- jmp_addr
;
1267 unsigned long patch_size
;
1269 ptr
= (uint32_t *)jmp_addr
;
1271 if ((disp
<< 6) >> 6 != disp
) {
1272 ptr
[0] = 0x3c000000 | (addr
>> 16); /* lis 0,addr@ha */
1273 ptr
[1] = 0x60000000 | (addr
& 0xffff); /* la 0,addr@l(0) */
1274 ptr
[2] = 0x7c0903a6; /* mtctr 0 */
1275 ptr
[3] = 0x4e800420; /* brctr */
1278 /* patch the branch destination */
1280 *ptr
= 0x48000000 | (disp
& 0x03fffffc); /* b disp */
1283 ptr
[0] = 0x60000000; /* nop */
1284 ptr
[1] = 0x60000000;
1285 ptr
[2] = 0x60000000;
1286 ptr
[3] = 0x60000000;
1291 flush_icache_range(jmp_addr
, jmp_addr
+ patch_size
);
1294 static void tcg_out_op(TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
1295 const int *const_args
)
1298 case INDEX_op_exit_tb
:
1299 tcg_out_movi (s
, TCG_TYPE_I32
, TCG_REG_R3
, args
[0]);
1300 tcg_out_b (s
, 0, (tcg_target_long
) tb_ret_addr
);
1302 case INDEX_op_goto_tb
:
1303 if (s
->tb_jmp_offset
) {
1304 /* direct jump method */
1306 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1312 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1316 TCGLabel
*l
= &s
->labels
[args
[0]];
1319 tcg_out_b (s
, 0, l
->u
.value
);
1322 uint32_t val
= *(uint32_t *) s
->code_ptr
;
1324 /* Thanks to Andrzej Zaborowski */
1325 tcg_out32 (s
, B
| (val
& 0x3fffffc));
1326 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL24
, args
[0], 0);
1331 tcg_out_call (s
, args
[0], const_args
[0]);
1334 if (const_args
[0]) {
1335 tcg_out_b (s
, 0, args
[0]);
1338 tcg_out32 (s
, MTSPR
| RS (args
[0]) | CTR
);
1339 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
1342 case INDEX_op_movi_i32
:
1343 tcg_out_movi(s
, TCG_TYPE_I32
, args
[0], args
[1]);
1345 case INDEX_op_ld8u_i32
:
1346 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1348 case INDEX_op_ld8s_i32
:
1349 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1350 tcg_out32 (s
, EXTSB
| RS (args
[0]) | RA (args
[0]));
1352 case INDEX_op_ld16u_i32
:
1353 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHZ
, LHZX
);
1355 case INDEX_op_ld16s_i32
:
1356 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHA
, LHAX
);
1358 case INDEX_op_ld_i32
:
1359 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LWZ
, LWZX
);
1361 case INDEX_op_st8_i32
:
1362 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STB
, STBX
);
1364 case INDEX_op_st16_i32
:
1365 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STH
, STHX
);
1367 case INDEX_op_st_i32
:
1368 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STW
, STWX
);
1371 case INDEX_op_add_i32
:
1373 ppc_addi (s
, args
[0], args
[1], args
[2]);
1375 tcg_out32 (s
, ADD
| TAB (args
[0], args
[1], args
[2]));
1377 case INDEX_op_sub_i32
:
1379 ppc_addi (s
, args
[0], args
[1], -args
[2]);
1381 tcg_out32 (s
, SUBF
| TAB (args
[0], args
[2], args
[1]));
1384 case INDEX_op_and_i32
:
1385 if (const_args
[2]) {
1391 tcg_out_movi (s
, TCG_TYPE_I32
, args
[0], 0);
1401 if ((t
& (t
- 1)) == 0) {
1404 if ((c
& 0x80000001) == 0x80000001) {
1419 tcg_out32 (s
, (RLWINM
1429 #endif /* !__PPU__ */
1431 if ((c
& 0xffff) == c
)
1432 tcg_out32 (s
, ANDI
| RS (args
[1]) | RA (args
[0]) | c
);
1433 else if ((c
& 0xffff0000) == c
)
1434 tcg_out32 (s
, ANDIS
| RS (args
[1]) | RA (args
[0])
1435 | ((c
>> 16) & 0xffff));
1437 tcg_out_movi (s
, TCG_TYPE_I32
, 0, c
);
1438 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], 0));
1443 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], args
[2]));
1445 case INDEX_op_or_i32
:
1446 if (const_args
[2]) {
1447 if (args
[2] & 0xffff) {
1448 tcg_out32 (s
, ORI
| RS (args
[1]) | RA (args
[0])
1449 | (args
[2] & 0xffff));
1451 tcg_out32 (s
, ORIS
| RS (args
[0]) | RA (args
[0])
1452 | ((args
[2] >> 16) & 0xffff));
1455 tcg_out32 (s
, ORIS
| RS (args
[1]) | RA (args
[0])
1456 | ((args
[2] >> 16) & 0xffff));
1460 tcg_out32 (s
, OR
| SAB (args
[1], args
[0], args
[2]));
1462 case INDEX_op_xor_i32
:
1463 if (const_args
[2]) {
1464 if ((args
[2] & 0xffff) == args
[2])
1465 tcg_out32 (s
, XORI
| RS (args
[1]) | RA (args
[0])
1466 | (args
[2] & 0xffff));
1467 else if ((args
[2] & 0xffff0000) == args
[2])
1468 tcg_out32 (s
, XORIS
| RS (args
[1]) | RA (args
[0])
1469 | ((args
[2] >> 16) & 0xffff));
1471 tcg_out_movi (s
, TCG_TYPE_I32
, 0, args
[2]);
1472 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], 0));
1476 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], args
[2]));
1478 case INDEX_op_andc_i32
:
1479 tcg_out32 (s
, ANDC
| SAB (args
[1], args
[0], args
[2]));
1481 case INDEX_op_orc_i32
:
1482 tcg_out32 (s
, ORC
| SAB (args
[1], args
[0], args
[2]));
1484 case INDEX_op_eqv_i32
:
1485 tcg_out32 (s
, EQV
| SAB (args
[1], args
[0], args
[2]));
1487 case INDEX_op_nand_i32
:
1488 tcg_out32 (s
, NAND
| SAB (args
[1], args
[0], args
[2]));
1490 case INDEX_op_nor_i32
:
1491 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[2]));
1494 case INDEX_op_mul_i32
:
1495 if (const_args
[2]) {
1496 if (args
[2] == (int16_t) args
[2])
1497 tcg_out32 (s
, MULLI
| RT (args
[0]) | RA (args
[1])
1498 | (args
[2] & 0xffff));
1500 tcg_out_movi (s
, TCG_TYPE_I32
, 0, args
[2]);
1501 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], 0));
1505 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], args
[2]));
1508 case INDEX_op_div_i32
:
1509 tcg_out32 (s
, DIVW
| TAB (args
[0], args
[1], args
[2]));
1512 case INDEX_op_divu_i32
:
1513 tcg_out32 (s
, DIVWU
| TAB (args
[0], args
[1], args
[2]));
1516 case INDEX_op_rem_i32
:
1517 tcg_out32 (s
, DIVW
| TAB (0, args
[1], args
[2]));
1518 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1519 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1522 case INDEX_op_remu_i32
:
1523 tcg_out32 (s
, DIVWU
| TAB (0, args
[1], args
[2]));
1524 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1525 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1528 case INDEX_op_mulu2_i32
:
1529 if (args
[0] == args
[2] || args
[0] == args
[3]) {
1530 tcg_out32 (s
, MULLW
| TAB (0, args
[2], args
[3]));
1531 tcg_out32 (s
, MULHWU
| TAB (args
[1], args
[2], args
[3]));
1532 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1535 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[2], args
[3]));
1536 tcg_out32 (s
, MULHWU
| TAB (args
[1], args
[2], args
[3]));
1540 case INDEX_op_shl_i32
:
1541 if (const_args
[2]) {
1542 tcg_out32 (s
, (RLWINM
1552 tcg_out32 (s
, SLW
| SAB (args
[1], args
[0], args
[2]));
1554 case INDEX_op_shr_i32
:
1555 if (const_args
[2]) {
1556 tcg_out32 (s
, (RLWINM
1566 tcg_out32 (s
, SRW
| SAB (args
[1], args
[0], args
[2]));
1568 case INDEX_op_sar_i32
:
1570 tcg_out32 (s
, SRAWI
| RS (args
[1]) | RA (args
[0]) | SH (args
[2]));
1572 tcg_out32 (s
, SRAW
| SAB (args
[1], args
[0], args
[2]));
1574 case INDEX_op_rotl_i32
:
1581 | (const_args
[2] ? RLWINM
| SH (args
[2])
1582 : RLWNM
| RB (args
[2]))
1587 case INDEX_op_rotr_i32
:
1588 if (const_args
[2]) {
1590 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], args
[1]);
1593 tcg_out32 (s
, RLWINM
1603 tcg_out32 (s
, SUBFIC
| RT (0) | RA (args
[2]) | 32);
1614 case INDEX_op_add2_i32
:
1615 if (args
[0] == args
[3] || args
[0] == args
[5]) {
1616 tcg_out32 (s
, ADDC
| TAB (0, args
[2], args
[4]));
1617 tcg_out32 (s
, ADDE
| TAB (args
[1], args
[3], args
[5]));
1618 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1621 tcg_out32 (s
, ADDC
| TAB (args
[0], args
[2], args
[4]));
1622 tcg_out32 (s
, ADDE
| TAB (args
[1], args
[3], args
[5]));
1625 case INDEX_op_sub2_i32
:
1626 if (args
[0] == args
[3] || args
[0] == args
[5]) {
1627 tcg_out32 (s
, SUBFC
| TAB (0, args
[4], args
[2]));
1628 tcg_out32 (s
, SUBFE
| TAB (args
[1], args
[5], args
[3]));
1629 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], 0);
1632 tcg_out32 (s
, SUBFC
| TAB (args
[0], args
[4], args
[2]));
1633 tcg_out32 (s
, SUBFE
| TAB (args
[1], args
[5], args
[3]));
1637 case INDEX_op_brcond_i32
:
1642 args[3] = r1 is const
1643 args[4] = label_index
1645 tcg_out_brcond (s
, args
[2], args
[0], args
[1], const_args
[1], args
[3]);
1647 case INDEX_op_brcond2_i32
:
1648 tcg_out_brcond2(s
, args
, const_args
);
1651 case INDEX_op_neg_i32
:
1652 tcg_out32 (s
, NEG
| RT (args
[0]) | RA (args
[1]));
1655 case INDEX_op_not_i32
:
1656 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[1]));
1659 case INDEX_op_qemu_ld8u
:
1660 tcg_out_qemu_ld(s
, args
, 0);
1662 case INDEX_op_qemu_ld8s
:
1663 tcg_out_qemu_ld(s
, args
, 0 | 4);
1665 case INDEX_op_qemu_ld16u
:
1666 tcg_out_qemu_ld(s
, args
, 1);
1668 case INDEX_op_qemu_ld16s
:
1669 tcg_out_qemu_ld(s
, args
, 1 | 4);
1671 case INDEX_op_qemu_ld32
:
1672 tcg_out_qemu_ld(s
, args
, 2);
1674 case INDEX_op_qemu_ld64
:
1675 tcg_out_qemu_ld(s
, args
, 3);
1677 case INDEX_op_qemu_st8
:
1678 tcg_out_qemu_st(s
, args
, 0);
1680 case INDEX_op_qemu_st16
:
1681 tcg_out_qemu_st(s
, args
, 1);
1683 case INDEX_op_qemu_st32
:
1684 tcg_out_qemu_st(s
, args
, 2);
1686 case INDEX_op_qemu_st64
:
1687 tcg_out_qemu_st(s
, args
, 3);
1690 case INDEX_op_ext8s_i32
:
1691 tcg_out32 (s
, EXTSB
| RS (args
[1]) | RA (args
[0]));
1693 case INDEX_op_ext8u_i32
:
1694 tcg_out32 (s
, RLWINM
1702 case INDEX_op_ext16s_i32
:
1703 tcg_out32 (s
, EXTSH
| RS (args
[1]) | RA (args
[0]));
1705 case INDEX_op_ext16u_i32
:
1706 tcg_out32 (s
, RLWINM
1715 case INDEX_op_setcond_i32
:
1716 tcg_out_setcond (s
, args
[3], args
[0], args
[1], args
[2], const_args
[2]);
1718 case INDEX_op_setcond2_i32
:
1719 tcg_out_setcond2 (s
, args
, const_args
);
1722 case INDEX_op_bswap16_i32
:
1723 /* Stolen from gcc's builtin_bswap16 */
1727 /* r0 = (a1 << 8) & 0xff00 # 00d0 */
1728 tcg_out32 (s
, RLWINM
1736 /* a0 = rotate_left (a1, 24) & 0xff # 000c */
1737 tcg_out32 (s
, RLWINM
1745 /* a0 = a0 | r0 # 00dc */
1746 tcg_out32 (s
, OR
| SAB (0, args
[0], args
[0]));
1749 case INDEX_op_bswap32_i32
:
1750 /* Stolen from gcc's builtin_bswap32 */
1754 /* a1 = args[1] # abcd */
1756 if (a0
== args
[1]) {
1760 /* a0 = rotate_left (a1, 8) # bcda */
1761 tcg_out32 (s
, RLWINM
1769 /* a0 = (a0 & ~0xff000000) | ((a1 << 24) & 0xff000000) # dcda */
1770 tcg_out32 (s
, RLWIMI
1778 /* a0 = (a0 & ~0x0000ff00) | ((a1 << 24) & 0x0000ff00) # dcba */
1779 tcg_out32 (s
, RLWIMI
1788 tcg_out_mov (s
, TCG_TYPE_I32
, args
[0], a0
);
1794 tcg_dump_ops (s
, stderr
);
1799 static const TCGTargetOpDef ppc_op_defs
[] = {
1800 { INDEX_op_exit_tb
, { } },
1801 { INDEX_op_goto_tb
, { } },
1802 { INDEX_op_call
, { "ri" } },
1803 { INDEX_op_jmp
, { "ri" } },
1804 { INDEX_op_br
, { } },
1806 { INDEX_op_mov_i32
, { "r", "r" } },
1807 { INDEX_op_movi_i32
, { "r" } },
1808 { INDEX_op_ld8u_i32
, { "r", "r" } },
1809 { INDEX_op_ld8s_i32
, { "r", "r" } },
1810 { INDEX_op_ld16u_i32
, { "r", "r" } },
1811 { INDEX_op_ld16s_i32
, { "r", "r" } },
1812 { INDEX_op_ld_i32
, { "r", "r" } },
1813 { INDEX_op_st8_i32
, { "r", "r" } },
1814 { INDEX_op_st16_i32
, { "r", "r" } },
1815 { INDEX_op_st_i32
, { "r", "r" } },
1817 { INDEX_op_add_i32
, { "r", "r", "ri" } },
1818 { INDEX_op_mul_i32
, { "r", "r", "ri" } },
1819 { INDEX_op_div_i32
, { "r", "r", "r" } },
1820 { INDEX_op_divu_i32
, { "r", "r", "r" } },
1821 { INDEX_op_rem_i32
, { "r", "r", "r" } },
1822 { INDEX_op_remu_i32
, { "r", "r", "r" } },
1823 { INDEX_op_mulu2_i32
, { "r", "r", "r", "r" } },
1824 { INDEX_op_sub_i32
, { "r", "r", "ri" } },
1825 { INDEX_op_and_i32
, { "r", "r", "ri" } },
1826 { INDEX_op_or_i32
, { "r", "r", "ri" } },
1827 { INDEX_op_xor_i32
, { "r", "r", "ri" } },
1829 { INDEX_op_shl_i32
, { "r", "r", "ri" } },
1830 { INDEX_op_shr_i32
, { "r", "r", "ri" } },
1831 { INDEX_op_sar_i32
, { "r", "r", "ri" } },
1833 { INDEX_op_rotl_i32
, { "r", "r", "ri" } },
1834 { INDEX_op_rotr_i32
, { "r", "r", "ri" } },
1836 { INDEX_op_brcond_i32
, { "r", "ri" } },
1838 { INDEX_op_add2_i32
, { "r", "r", "r", "r", "r", "r" } },
1839 { INDEX_op_sub2_i32
, { "r", "r", "r", "r", "r", "r" } },
1840 { INDEX_op_brcond2_i32
, { "r", "r", "r", "r" } },
1842 { INDEX_op_neg_i32
, { "r", "r" } },
1843 { INDEX_op_not_i32
, { "r", "r" } },
1845 { INDEX_op_andc_i32
, { "r", "r", "r" } },
1846 { INDEX_op_orc_i32
, { "r", "r", "r" } },
1847 { INDEX_op_eqv_i32
, { "r", "r", "r" } },
1848 { INDEX_op_nand_i32
, { "r", "r", "r" } },
1849 { INDEX_op_nor_i32
, { "r", "r", "r" } },
1851 { INDEX_op_setcond_i32
, { "r", "r", "ri" } },
1852 { INDEX_op_setcond2_i32
, { "r", "r", "r", "ri", "ri" } },
1854 { INDEX_op_bswap16_i32
, { "r", "r" } },
1855 { INDEX_op_bswap32_i32
, { "r", "r" } },
1857 #if TARGET_LONG_BITS == 32
1858 { INDEX_op_qemu_ld8u
, { "r", "L" } },
1859 { INDEX_op_qemu_ld8s
, { "r", "L" } },
1860 { INDEX_op_qemu_ld16u
, { "r", "L" } },
1861 { INDEX_op_qemu_ld16s
, { "r", "L" } },
1862 { INDEX_op_qemu_ld32
, { "r", "L" } },
1863 { INDEX_op_qemu_ld64
, { "r", "r", "L" } },
1865 { INDEX_op_qemu_st8
, { "K", "K" } },
1866 { INDEX_op_qemu_st16
, { "K", "K" } },
1867 { INDEX_op_qemu_st32
, { "K", "K" } },
1868 { INDEX_op_qemu_st64
, { "M", "M", "M" } },
1870 { INDEX_op_qemu_ld8u
, { "r", "L", "L" } },
1871 { INDEX_op_qemu_ld8s
, { "r", "L", "L" } },
1872 { INDEX_op_qemu_ld16u
, { "r", "L", "L" } },
1873 { INDEX_op_qemu_ld16s
, { "r", "L", "L" } },
1874 { INDEX_op_qemu_ld32
, { "r", "L", "L" } },
1875 { INDEX_op_qemu_ld64
, { "r", "L", "L", "L" } },
1877 { INDEX_op_qemu_st8
, { "K", "K", "K" } },
1878 { INDEX_op_qemu_st16
, { "K", "K", "K" } },
1879 { INDEX_op_qemu_st32
, { "K", "K", "K" } },
1880 { INDEX_op_qemu_st64
, { "M", "M", "M", "M" } },
1883 { INDEX_op_ext8s_i32
, { "r", "r" } },
1884 { INDEX_op_ext8u_i32
, { "r", "r" } },
1885 { INDEX_op_ext16s_i32
, { "r", "r" } },
1886 { INDEX_op_ext16u_i32
, { "r", "r" } },
1891 static void tcg_target_init(TCGContext
*s
)
1893 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I32
], 0, 0xffffffff);
1894 tcg_regset_set32(tcg_target_call_clobber_regs
, 0,
1906 (1 << TCG_REG_R10
) |
1907 (1 << TCG_REG_R11
) |
1911 tcg_regset_clear(s
->reserved_regs
);
1912 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R0
);
1913 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R1
);
1914 #ifndef _CALL_DARWIN
1915 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R2
);
1918 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R13
);
1921 tcg_add_target_add_op_defs(ppc_op_defs
);