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 #define TCG_CT_CONST_U32 0x100
27 static uint8_t *tb_ret_addr
;
31 #if TARGET_LONG_BITS == 32
43 #ifdef CONFIG_USE_GUEST_BASE
44 #define TCG_GUEST_BASE_REG 30
46 #define TCG_GUEST_BASE_REG 0
50 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
86 static const int tcg_target_reg_alloc_order
[] = {
122 static const int tcg_target_call_iarg_regs
[] = {
133 static const int tcg_target_call_oarg_regs
[] = {
137 static const int tcg_target_callee_save_regs
[] = {
154 TCG_REG_R27
, /* currently used for the global env */
161 static uint32_t reloc_pc24_val (void *pc
, tcg_target_long target
)
163 tcg_target_long disp
;
165 disp
= target
- (tcg_target_long
) pc
;
166 if ((disp
<< 38) >> 38 != disp
)
169 return disp
& 0x3fffffc;
172 static void reloc_pc24 (void *pc
, tcg_target_long target
)
174 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0x3fffffc)
175 | reloc_pc24_val (pc
, target
);
178 static uint16_t reloc_pc14_val (void *pc
, tcg_target_long target
)
180 tcg_target_long disp
;
182 disp
= target
- (tcg_target_long
) pc
;
183 if (disp
!= (int16_t) disp
)
186 return disp
& 0xfffc;
189 static void reloc_pc14 (void *pc
, tcg_target_long target
)
191 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0xfffc)
192 | reloc_pc14_val (pc
, target
);
195 static void patch_reloc (uint8_t *code_ptr
, int type
,
196 tcg_target_long value
, tcg_target_long addend
)
201 reloc_pc14 (code_ptr
, value
);
204 reloc_pc24 (code_ptr
, value
);
211 /* maximum number of register used for input function arguments */
212 static int tcg_target_get_call_iarg_regs_count (int flags
)
214 return ARRAY_SIZE (tcg_target_call_iarg_regs
);
217 /* parse target specific constraints */
218 static int target_parse_constraint (TCGArgConstraint
*ct
, const char **pct_str
)
224 case 'A': case 'B': case 'C': case 'D':
225 ct
->ct
|= TCG_CT_REG
;
226 tcg_regset_set_reg (ct
->u
.regs
, 3 + ct_str
[0] - 'A');
229 ct
->ct
|= TCG_CT_REG
;
230 tcg_regset_set32 (ct
->u
.regs
, 0, 0xffffffff);
232 case 'L': /* qemu_ld constraint */
233 ct
->ct
|= TCG_CT_REG
;
234 tcg_regset_set32 (ct
->u
.regs
, 0, 0xffffffff);
235 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R3
);
236 #ifdef CONFIG_SOFTMMU
237 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R4
);
238 #ifdef CONFIG_TCG_PASS_AREG0
239 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R5
);
243 case 'S': /* qemu_st 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 #ifdef CONFIG_SOFTMMU
248 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R4
);
249 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R5
);
250 #ifdef CONFIG_TCG_PASS_AREG0
251 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R6
);
256 ct
->ct
|= TCG_CT_CONST_U32
;
266 /* test if a constant matches the constraint */
267 static int tcg_target_const_match (tcg_target_long val
,
268 const TCGArgConstraint
*arg_ct
)
273 if (ct
& TCG_CT_CONST
)
275 else if ((ct
& TCG_CT_CONST_U32
) && (val
== (uint32_t) val
))
280 #define OPCD(opc) ((opc)<<26)
281 #define XO19(opc) (OPCD(19)|((opc)<<1))
282 #define XO30(opc) (OPCD(30)|((opc)<<2))
283 #define XO31(opc) (OPCD(31)|((opc)<<1))
284 #define XO58(opc) (OPCD(58)|(opc))
285 #define XO62(opc) (OPCD(62)|(opc))
289 #define LBZ OPCD( 34)
290 #define LHZ OPCD( 40)
291 #define LHA OPCD( 42)
292 #define LWZ OPCD( 32)
293 #define STB OPCD( 38)
294 #define STH OPCD( 44)
295 #define STW OPCD( 36)
298 #define STDU XO62( 1)
299 #define STDX XO31(149)
302 #define LDX XO31( 21)
305 #define LWAX XO31(341)
307 #define ADDIC OPCD( 12)
308 #define ADDI OPCD( 14)
309 #define ADDIS OPCD( 15)
310 #define ORI OPCD( 24)
311 #define ORIS OPCD( 25)
312 #define XORI OPCD( 26)
313 #define XORIS OPCD( 27)
314 #define ANDI OPCD( 28)
315 #define ANDIS OPCD( 29)
316 #define MULLI OPCD( 7)
317 #define CMPLI OPCD( 10)
318 #define CMPI OPCD( 11)
320 #define LWZU OPCD( 33)
321 #define STWU OPCD( 37)
323 #define RLWINM OPCD( 21)
325 #define RLDICL XO30( 0)
326 #define RLDICR XO30( 1)
327 #define RLDIMI XO30( 3)
329 #define BCLR XO19( 16)
330 #define BCCTR XO19(528)
331 #define CRAND XO19(257)
332 #define CRANDC XO19(129)
333 #define CRNAND XO19(225)
334 #define CROR XO19(449)
335 #define CRNOR XO19( 33)
337 #define EXTSB XO31(954)
338 #define EXTSH XO31(922)
339 #define EXTSW XO31(986)
340 #define ADD XO31(266)
341 #define ADDE XO31(138)
342 #define ADDC XO31( 10)
343 #define AND XO31( 28)
344 #define SUBF XO31( 40)
345 #define SUBFC XO31( 8)
346 #define SUBFE XO31(136)
348 #define XOR XO31(316)
349 #define MULLW XO31(235)
350 #define MULHWU XO31( 11)
351 #define DIVW XO31(491)
352 #define DIVWU XO31(459)
354 #define CMPL XO31( 32)
355 #define LHBRX XO31(790)
356 #define LWBRX XO31(534)
357 #define STHBRX XO31(918)
358 #define STWBRX XO31(662)
359 #define MFSPR XO31(339)
360 #define MTSPR XO31(467)
361 #define SRAWI XO31(824)
362 #define NEG XO31(104)
363 #define MFCR XO31( 19)
364 #define NOR XO31(124)
365 #define CNTLZW XO31( 26)
366 #define CNTLZD XO31( 58)
368 #define MULLD XO31(233)
369 #define MULHD XO31( 73)
370 #define MULHDU XO31( 9)
371 #define DIVD XO31(489)
372 #define DIVDU XO31(457)
374 #define LBZX XO31( 87)
375 #define LHZX XO31(279)
376 #define LHAX XO31(343)
377 #define LWZX XO31( 23)
378 #define STBX XO31(215)
379 #define STHX XO31(407)
380 #define STWX XO31(151)
382 #define SPR(a,b) ((((a)<<5)|(b))<<11)
384 #define CTR SPR(9, 0)
386 #define SLW XO31( 24)
387 #define SRW XO31(536)
388 #define SRAW XO31(792)
390 #define SLD XO31( 27)
391 #define SRD XO31(539)
392 #define SRAD XO31(794)
393 #define SRADI XO31(413<<1)
396 #define TRAP (TW | TO (31))
398 #define RT(r) ((r)<<21)
399 #define RS(r) ((r)<<21)
400 #define RA(r) ((r)<<16)
401 #define RB(r) ((r)<<11)
402 #define TO(t) ((t)<<21)
403 #define SH(s) ((s)<<11)
404 #define MB(b) ((b)<<6)
405 #define ME(e) ((e)<<1)
406 #define BO(o) ((o)<<21)
407 #define MB64(b) ((b)<<5)
411 #define TAB(t,a,b) (RT(t) | RA(a) | RB(b))
412 #define SAB(s,a,b) (RS(s) | RA(a) | RB(b))
414 #define BF(n) ((n)<<23)
415 #define BI(n, c) (((c)+((n)*4))<<16)
416 #define BT(n, c) (((c)+((n)*4))<<21)
417 #define BA(n, c) (((c)+((n)*4))<<16)
418 #define BB(n, c) (((c)+((n)*4))<<11)
420 #define BO_COND_TRUE BO (12)
421 #define BO_COND_FALSE BO ( 4)
422 #define BO_ALWAYS BO (20)
431 static const uint32_t tcg_to_bc
[10] = {
432 [TCG_COND_EQ
] = BC
| BI (7, CR_EQ
) | BO_COND_TRUE
,
433 [TCG_COND_NE
] = BC
| BI (7, CR_EQ
) | BO_COND_FALSE
,
434 [TCG_COND_LT
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
435 [TCG_COND_GE
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
436 [TCG_COND_LE
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
437 [TCG_COND_GT
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
438 [TCG_COND_LTU
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
439 [TCG_COND_GEU
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
440 [TCG_COND_LEU
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
441 [TCG_COND_GTU
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
444 static void tcg_out_mov (TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg
)
446 tcg_out32 (s
, OR
| SAB (arg
, ret
, arg
));
449 static void tcg_out_rld (TCGContext
*s
, int op
, int ra
, int rs
, int sh
, int mb
)
451 sh
= SH (sh
& 0x1f) | (((sh
>> 5) & 1) << 1);
452 mb
= MB64 ((mb
>> 5) | ((mb
<< 1) & 0x3f));
453 tcg_out32 (s
, op
| RA (ra
) | RS (rs
) | sh
| mb
);
456 static void tcg_out_movi32 (TCGContext
*s
, int ret
, int32_t arg
)
458 if (arg
== (int16_t) arg
)
459 tcg_out32 (s
, ADDI
| RT (ret
) | RA (0) | (arg
& 0xffff));
461 tcg_out32 (s
, ADDIS
| RT (ret
) | RA (0) | ((arg
>> 16) & 0xffff));
463 tcg_out32 (s
, ORI
| RS (ret
) | RA (ret
) | (arg
& 0xffff));
467 static void tcg_out_movi (TCGContext
*s
, TCGType type
,
468 TCGReg ret
, tcg_target_long arg
)
471 arg
= type
== TCG_TYPE_I32
? arg
& 0xffffffff : arg
;
474 tcg_out_movi32 (s
, ret
, arg32
);
477 if ((uint64_t) arg
>> 32) {
478 uint16_t h16
= arg
>> 16;
481 tcg_out_movi32 (s
, ret
, arg
>> 32);
482 tcg_out_rld (s
, RLDICR
, ret
, ret
, 32, 31);
483 if (h16
) tcg_out32 (s
, ORIS
| RS (ret
) | RA (ret
) | h16
);
484 if (l16
) tcg_out32 (s
, ORI
| RS (ret
) | RA (ret
) | l16
);
487 tcg_out_movi32 (s
, ret
, arg32
);
489 tcg_out_rld (s
, RLDICL
, ret
, ret
, 0, 32);
494 static void tcg_out_b (TCGContext
*s
, int mask
, tcg_target_long target
)
496 tcg_target_long disp
;
498 disp
= target
- (tcg_target_long
) s
->code_ptr
;
499 if ((disp
<< 38) >> 38 == disp
)
500 tcg_out32 (s
, B
| (disp
& 0x3fffffc) | mask
);
502 tcg_out_movi (s
, TCG_TYPE_I64
, 0, (tcg_target_long
) target
);
503 tcg_out32 (s
, MTSPR
| RS (0) | CTR
);
504 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| mask
);
508 static void tcg_out_call (TCGContext
*s
, tcg_target_long arg
, int const_arg
)
512 tcg_out_b (s
, LK
, arg
);
515 tcg_out32 (s
, MTSPR
| RS (arg
) | LR
);
516 tcg_out32 (s
, BCLR
| BO_ALWAYS
| LK
);
523 tcg_out_movi (s
, TCG_TYPE_I64
, reg
, arg
);
527 tcg_out32 (s
, LD
| RT (0) | RA (reg
));
528 tcg_out32 (s
, MTSPR
| RA (0) | CTR
);
529 tcg_out32 (s
, LD
| RT (11) | RA (reg
) | 16);
530 tcg_out32 (s
, LD
| RT (2) | RA (reg
) | 8);
531 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| LK
);
535 static void tcg_out_ldst (TCGContext
*s
, int ret
, int addr
,
536 int offset
, int op1
, int op2
)
538 if (offset
== (int16_t) offset
)
539 tcg_out32 (s
, op1
| RT (ret
) | RA (addr
) | (offset
& 0xffff));
541 tcg_out_movi (s
, TCG_TYPE_I64
, 0, offset
);
542 tcg_out32 (s
, op2
| RT (ret
) | RA (addr
) | RB (0));
546 static void tcg_out_ldsta (TCGContext
*s
, int ret
, int addr
,
547 int offset
, int op1
, int op2
)
549 if (offset
== (int16_t) (offset
& ~3))
550 tcg_out32 (s
, op1
| RT (ret
) | RA (addr
) | (offset
& 0xffff));
552 tcg_out_movi (s
, TCG_TYPE_I64
, 0, offset
);
553 tcg_out32 (s
, op2
| RT (ret
) | RA (addr
) | RB (0));
557 #if defined (CONFIG_SOFTMMU)
559 #include "../../softmmu_defs.h"
561 #ifdef CONFIG_TCG_PASS_AREG0
562 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
564 static const void * const qemu_ld_helpers
[4] = {
571 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
572 uintxx_t val, int mmu_idx) */
573 static const void * const qemu_st_helpers
[4] = {
580 /* legacy helper signature: __ld_mmu(target_ulong addr, int
582 static void *qemu_ld_helpers
[4] = {
589 /* legacy helper signature: __st_mmu(target_ulong addr, uintxx_t val,
591 static void *qemu_st_helpers
[4] = {
599 static void tcg_out_tlb_read (TCGContext
*s
, int r0
, int r1
, int r2
,
600 int addr_reg
, int s_bits
, int offset
)
602 #if TARGET_LONG_BITS == 32
603 tcg_out_rld (s
, RLDICL
, addr_reg
, addr_reg
, 0, 32);
605 tcg_out32 (s
, (RLWINM
608 | SH (32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
))
609 | MB (32 - (CPU_TLB_BITS
+ CPU_TLB_ENTRY_BITS
))
610 | ME (31 - CPU_TLB_ENTRY_BITS
)
613 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (TCG_AREG0
));
614 tcg_out32 (s
, (LWZU
| RT (r1
) | RA (r0
) | offset
));
615 tcg_out32 (s
, (RLWINM
619 | MB ((32 - s_bits
) & 31)
620 | ME (31 - TARGET_PAGE_BITS
)
624 tcg_out_rld (s
, RLDICL
, r0
, addr_reg
,
625 64 - TARGET_PAGE_BITS
,
627 tcg_out_rld (s
, RLDICR
, r0
, r0
,
629 63 - CPU_TLB_ENTRY_BITS
);
631 tcg_out32 (s
, ADD
| TAB (r0
, r0
, TCG_AREG0
));
632 tcg_out32 (s
, LD_ADDR
| RT (r1
) | RA (r0
) | offset
);
635 tcg_out_rld (s
, RLDICR
, r2
, addr_reg
, 0, 63 - TARGET_PAGE_BITS
);
638 tcg_out_rld (s
, RLDICL
, r2
, addr_reg
,
639 64 - TARGET_PAGE_BITS
,
640 TARGET_PAGE_BITS
- s_bits
);
641 tcg_out_rld (s
, RLDICL
, r2
, r2
, TARGET_PAGE_BITS
, 0);
647 static void tcg_out_qemu_ld (TCGContext
*s
, const TCGArg
*args
, int opc
)
649 int addr_reg
, data_reg
, r0
, r1
, rbase
, bswap
;
650 #ifdef CONFIG_SOFTMMU
651 int r2
, mem_index
, s_bits
, ir
;
652 void *label1_ptr
, *label2_ptr
;
658 #ifdef CONFIG_SOFTMMU
667 tcg_out_tlb_read (s
, r0
, r1
, r2
, addr_reg
, s_bits
,
668 offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_read
));
670 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
) | CMP_L
);
672 label1_ptr
= s
->code_ptr
;
674 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
679 #ifdef CONFIG_TCG_PASS_AREG0
680 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
682 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, addr_reg
);
683 tcg_out_movi (s
, TCG_TYPE_I64
, ir
++, mem_index
);
685 tcg_out_call (s
, (tcg_target_long
) qemu_ld_helpers
[s_bits
], 1);
689 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (3));
692 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (3));
695 tcg_out32 (s
, EXTSW
| RA (data_reg
) | RS (3));
702 tcg_out_mov (s
, TCG_TYPE_I64
, data_reg
, 3);
705 label2_ptr
= s
->code_ptr
;
708 /* label1: fast path */
710 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
713 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
717 | (offsetof (CPUTLBEntry
, addend
)
718 - offsetof (CPUTLBEntry
, addr_read
))
720 /* r0 = env->tlb_table[mem_index][index].addend */
721 tcg_out32 (s
, ADD
| RT (r0
) | RA (r0
) | RB (addr_reg
));
722 /* r0 = env->tlb_table[mem_index][index].addend + addr */
724 #else /* !CONFIG_SOFTMMU */
725 #if TARGET_LONG_BITS == 32
726 tcg_out_rld (s
, RLDICL
, addr_reg
, addr_reg
, 0, 32);
730 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
733 #ifdef TARGET_WORDS_BIGENDIAN
741 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
744 tcg_out32 (s
, LBZX
| TAB (data_reg
, rbase
, r0
));
745 tcg_out32 (s
, EXTSB
| RA (data_reg
) | RS (data_reg
));
749 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
751 tcg_out32 (s
, LHZX
| TAB (data_reg
, rbase
, r0
));
755 tcg_out32 (s
, LHBRX
| TAB (data_reg
, rbase
, r0
));
756 tcg_out32 (s
, EXTSH
| RA (data_reg
) | RS (data_reg
));
758 else tcg_out32 (s
, LHAX
| TAB (data_reg
, rbase
, r0
));
762 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
764 tcg_out32 (s
, LWZX
| TAB (data_reg
, rbase
, r0
));
768 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
769 tcg_out32 (s
, EXTSW
| RA (data_reg
) | RS (data_reg
));
771 else tcg_out32 (s
, LWAX
| TAB (data_reg
, rbase
, r0
));
774 #ifdef CONFIG_USE_GUEST_BASE
776 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
777 tcg_out32 (s
, LWBRX
| TAB (data_reg
, rbase
, r0
));
778 tcg_out32 (s
, LWBRX
| TAB ( r1
, rbase
, r1
));
779 tcg_out_rld (s
, RLDIMI
, data_reg
, r1
, 32, 0);
781 else tcg_out32 (s
, LDX
| TAB (data_reg
, rbase
, r0
));
784 tcg_out_movi32 (s
, 0, 4);
785 tcg_out32 (s
, LWBRX
| RT (data_reg
) | RB (r0
));
786 tcg_out32 (s
, LWBRX
| RT ( r1
) | RA (r0
));
787 tcg_out_rld (s
, RLDIMI
, data_reg
, r1
, 32, 0);
789 else tcg_out32 (s
, LD
| RT (data_reg
) | RA (r0
));
794 #ifdef CONFIG_SOFTMMU
795 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
799 static void tcg_out_qemu_st (TCGContext
*s
, const TCGArg
*args
, int opc
)
801 int addr_reg
, r0
, r1
, rbase
, data_reg
, bswap
;
802 #ifdef CONFIG_SOFTMMU
803 int r2
, mem_index
, ir
;
804 void *label1_ptr
, *label2_ptr
;
810 #ifdef CONFIG_SOFTMMU
818 tcg_out_tlb_read (s
, r0
, r1
, r2
, addr_reg
, opc
,
819 offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_write
));
821 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
) | CMP_L
);
823 label1_ptr
= s
->code_ptr
;
825 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
830 #ifdef CONFIG_TCG_PASS_AREG0
831 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
833 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, addr_reg
);
834 tcg_out_rld (s
, RLDICL
, ir
++, data_reg
, 0, 64 - (1 << (3 + opc
)));
835 tcg_out_movi (s
, TCG_TYPE_I64
, ir
++, mem_index
);
837 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 | (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 */
858 #if TARGET_LONG_BITS == 32
859 tcg_out_rld (s
, RLDICL
, addr_reg
, addr_reg
, 0, 32);
863 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
866 #ifdef TARGET_WORDS_BIGENDIAN
873 tcg_out32 (s
, STBX
| SAB (data_reg
, rbase
, r0
));
877 tcg_out32 (s
, STHBRX
| SAB (data_reg
, rbase
, r0
));
879 tcg_out32 (s
, STHX
| SAB (data_reg
, rbase
, r0
));
883 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
885 tcg_out32 (s
, STWX
| SAB (data_reg
, rbase
, r0
));
889 tcg_out32 (s
, STWBRX
| SAB (data_reg
, rbase
, r0
));
890 tcg_out32 (s
, ADDI
| RT (r1
) | RA (r0
) | 4);
891 tcg_out_rld (s
, RLDICL
, 0, data_reg
, 32, 0);
892 tcg_out32 (s
, STWBRX
| SAB (0, rbase
, r1
));
894 else tcg_out32 (s
, STDX
| SAB (data_reg
, rbase
, r0
));
898 #ifdef CONFIG_SOFTMMU
899 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
903 static void tcg_target_qemu_prologue (TCGContext
*s
)
914 + 8 /* compiler doubleword */
915 + 8 /* link editor doubleword */
916 + 8 /* TOC save area */
917 + TCG_STATIC_CALL_ARGS_SIZE
918 + ARRAY_SIZE (tcg_target_callee_save_regs
) * 8
919 + CPU_TEMP_BUF_NLONGS
* sizeof(long)
921 frame_size
= (frame_size
+ 15) & ~15;
923 tcg_set_frame (s
, TCG_REG_CALL_STACK
, frame_size
924 - CPU_TEMP_BUF_NLONGS
* sizeof (long),
925 CPU_TEMP_BUF_NLONGS
* sizeof (long));
928 /* First emit adhoc function descriptor */
929 addr
= (uint64_t) s
->code_ptr
+ 24;
930 tcg_out32 (s
, addr
>> 32); tcg_out32 (s
, addr
); /* entry point */
931 s
->code_ptr
+= 16; /* skip TOC and environment pointer */
935 tcg_out32 (s
, MFSPR
| RT (0) | LR
);
936 tcg_out32 (s
, STDU
| RS (1) | RA (1) | (-frame_size
& 0xffff));
937 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
939 | RS (tcg_target_callee_save_regs
[i
])
941 | (i
* 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE
)
944 tcg_out32 (s
, STD
| RS (0) | RA (1) | (frame_size
+ 16));
946 #ifdef CONFIG_USE_GUEST_BASE
948 tcg_out_movi (s
, TCG_TYPE_I64
, TCG_GUEST_BASE_REG
, GUEST_BASE
);
949 tcg_regset_set_reg (s
->reserved_regs
, TCG_GUEST_BASE_REG
);
953 tcg_out_mov (s
, TCG_TYPE_PTR
, TCG_AREG0
, tcg_target_call_iarg_regs
[0]);
954 tcg_out32 (s
, MTSPR
| RS (tcg_target_call_iarg_regs
[1]) | CTR
);
955 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
958 tb_ret_addr
= s
->code_ptr
;
960 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
962 | RT (tcg_target_callee_save_regs
[i
])
964 | (i
* 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE
)
967 tcg_out32 (s
, LD
| RT (0) | RA (1) | (frame_size
+ 16));
968 tcg_out32 (s
, MTSPR
| RS (0) | LR
);
969 tcg_out32 (s
, ADDI
| RT (1) | RA (1) | frame_size
);
970 tcg_out32 (s
, BCLR
| BO_ALWAYS
);
973 static void tcg_out_ld (TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg1
,
974 tcg_target_long arg2
)
976 if (type
== TCG_TYPE_I32
)
977 tcg_out_ldst (s
, ret
, arg1
, arg2
, LWZ
, LWZX
);
979 tcg_out_ldsta (s
, ret
, arg1
, arg2
, LD
, LDX
);
982 static void tcg_out_st (TCGContext
*s
, TCGType type
, TCGReg arg
, TCGReg arg1
,
983 tcg_target_long arg2
)
985 if (type
== TCG_TYPE_I32
)
986 tcg_out_ldst (s
, arg
, arg1
, arg2
, STW
, STWX
);
988 tcg_out_ldsta (s
, arg
, arg1
, arg2
, STD
, STDX
);
991 static void ppc_addi32 (TCGContext
*s
, int rt
, int ra
, tcg_target_long si
)
996 if (si
== (int16_t) si
)
997 tcg_out32 (s
, ADDI
| RT (rt
) | RA (ra
) | (si
& 0xffff));
999 uint16_t h
= ((si
>> 16) & 0xffff) + ((uint16_t) si
>> 15);
1000 tcg_out32 (s
, ADDIS
| RT (rt
) | RA (ra
) | h
);
1001 tcg_out32 (s
, ADDI
| RT (rt
) | RA (rt
) | (si
& 0xffff));
1005 static void ppc_addi64 (TCGContext
*s
, int rt
, int ra
, tcg_target_long si
)
1007 /* XXX: suboptimal */
1008 if (si
== (int16_t) si
1009 || ((((uint64_t) si
>> 31) == 0) && (si
& 0x8000) == 0))
1010 ppc_addi32 (s
, rt
, ra
, si
);
1012 tcg_out_movi (s
, TCG_TYPE_I64
, 0, si
);
1013 tcg_out32 (s
, ADD
| RT (rt
) | RA (ra
));
1017 static void tcg_out_cmp (TCGContext
*s
, int cond
, TCGArg arg1
, TCGArg arg2
,
1018 int const_arg2
, int cr
, int arch64
)
1027 if ((int16_t) arg2
== arg2
) {
1032 else if ((uint16_t) arg2
== arg2
) {
1047 if ((int16_t) arg2
== arg2
) {
1062 if ((uint16_t) arg2
== arg2
) {
1075 op
|= BF (cr
) | (arch64
<< 21);
1078 tcg_out32 (s
, op
| RA (arg1
) | (arg2
& 0xffff));
1081 tcg_out_movi (s
, TCG_TYPE_I64
, 0, arg2
);
1082 tcg_out32 (s
, op
| RA (arg1
) | RB (0));
1085 tcg_out32 (s
, op
| RA (arg1
) | RB (arg2
));
1090 static void tcg_out_setcond (TCGContext
*s
, TCGType type
, TCGCond cond
,
1091 TCGArg arg0
, TCGArg arg1
, TCGArg arg2
,
1104 if ((uint16_t) arg2
== arg2
) {
1105 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1108 tcg_out_movi (s
, type
, 0, arg2
);
1109 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1115 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1118 if (type
== TCG_TYPE_I64
) {
1119 tcg_out32 (s
, CNTLZD
| RS (arg
) | RA (0));
1120 tcg_out_rld (s
, RLDICL
, arg0
, 0, 58, 6);
1123 tcg_out32 (s
, CNTLZW
| RS (arg
) | RA (0));
1124 tcg_out32 (s
, (RLWINM
1142 if ((uint16_t) arg2
== arg2
) {
1143 tcg_out32 (s
, XORI
| RS (arg1
) | RA (0) | arg2
);
1146 tcg_out_movi (s
, type
, 0, arg2
);
1147 tcg_out32 (s
, XOR
| SAB (arg1
, 0, 0));
1153 tcg_out32 (s
, XOR
| SAB (arg1
, 0, arg2
));
1156 if (arg
== arg1
&& arg1
== arg0
) {
1157 tcg_out32 (s
, ADDIC
| RT (0) | RA (arg
) | 0xffff);
1158 tcg_out32 (s
, SUBFE
| TAB (arg0
, 0, arg
));
1161 tcg_out32 (s
, ADDIC
| RT (arg0
) | RA (arg
) | 0xffff);
1162 tcg_out32 (s
, SUBFE
| TAB (arg0
, arg0
, arg
));
1181 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_LT
) | BB (7, CR_LT
);
1187 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_GT
) | BB (7, CR_GT
);
1189 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7, type
== TCG_TYPE_I64
);
1190 if (crop
) tcg_out32 (s
, crop
);
1191 tcg_out32 (s
, MFCR
| RT (0));
1192 tcg_out32 (s
, (RLWINM
1207 static void tcg_out_bc (TCGContext
*s
, int bc
, int label_index
)
1209 TCGLabel
*l
= &s
->labels
[label_index
];
1212 tcg_out32 (s
, bc
| reloc_pc14_val (s
->code_ptr
, l
->u
.value
));
1214 uint16_t val
= *(uint16_t *) &s
->code_ptr
[2];
1216 /* Thanks to Andrzej Zaborowski */
1217 tcg_out32 (s
, bc
| (val
& 0xfffc));
1218 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL14
, label_index
, 0);
1222 static void tcg_out_brcond (TCGContext
*s
, TCGCond cond
,
1223 TCGArg arg1
, TCGArg arg2
, int const_arg2
,
1224 int label_index
, int arch64
)
1226 tcg_out_cmp (s
, cond
, arg1
, arg2
, const_arg2
, 7, arch64
);
1227 tcg_out_bc (s
, tcg_to_bc
[cond
], label_index
);
1230 void ppc_tb_set_jmp_target (unsigned long jmp_addr
, unsigned long addr
)
1233 unsigned long patch_size
;
1235 s
.code_ptr
= (uint8_t *) jmp_addr
;
1236 tcg_out_b (&s
, 0, addr
);
1237 patch_size
= s
.code_ptr
- (uint8_t *) jmp_addr
;
1238 flush_icache_range (jmp_addr
, jmp_addr
+ patch_size
);
1241 static void tcg_out_op (TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
1242 const int *const_args
)
1247 case INDEX_op_exit_tb
:
1248 tcg_out_movi (s
, TCG_TYPE_I64
, TCG_REG_R3
, args
[0]);
1249 tcg_out_b (s
, 0, (tcg_target_long
) tb_ret_addr
);
1251 case INDEX_op_goto_tb
:
1252 if (s
->tb_jmp_offset
) {
1253 /* direct jump method */
1255 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1261 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1265 TCGLabel
*l
= &s
->labels
[args
[0]];
1268 tcg_out_b (s
, 0, l
->u
.value
);
1271 uint32_t val
= *(uint32_t *) s
->code_ptr
;
1273 /* Thanks to Andrzej Zaborowski */
1274 tcg_out32 (s
, B
| (val
& 0x3fffffc));
1275 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL24
, args
[0], 0);
1280 tcg_out_call (s
, args
[0], const_args
[0]);
1283 if (const_args
[0]) {
1284 tcg_out_b (s
, 0, args
[0]);
1287 tcg_out32 (s
, MTSPR
| RS (args
[0]) | CTR
);
1288 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
1291 case INDEX_op_movi_i32
:
1292 tcg_out_movi (s
, TCG_TYPE_I32
, args
[0], args
[1]);
1294 case INDEX_op_movi_i64
:
1295 tcg_out_movi (s
, TCG_TYPE_I64
, args
[0], args
[1]);
1297 case INDEX_op_ld8u_i32
:
1298 case INDEX_op_ld8u_i64
:
1299 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1301 case INDEX_op_ld8s_i32
:
1302 case INDEX_op_ld8s_i64
:
1303 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1304 tcg_out32 (s
, EXTSB
| RS (args
[0]) | RA (args
[0]));
1306 case INDEX_op_ld16u_i32
:
1307 case INDEX_op_ld16u_i64
:
1308 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHZ
, LHZX
);
1310 case INDEX_op_ld16s_i32
:
1311 case INDEX_op_ld16s_i64
:
1312 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHA
, LHAX
);
1314 case INDEX_op_ld_i32
:
1315 case INDEX_op_ld32u_i64
:
1316 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LWZ
, LWZX
);
1318 case INDEX_op_ld32s_i64
:
1319 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], LWA
, LWAX
);
1321 case INDEX_op_ld_i64
:
1322 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], LD
, LDX
);
1324 case INDEX_op_st8_i32
:
1325 case INDEX_op_st8_i64
:
1326 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STB
, STBX
);
1328 case INDEX_op_st16_i32
:
1329 case INDEX_op_st16_i64
:
1330 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STH
, STHX
);
1332 case INDEX_op_st_i32
:
1333 case INDEX_op_st32_i64
:
1334 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STW
, STWX
);
1336 case INDEX_op_st_i64
:
1337 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], STD
, STDX
);
1340 case INDEX_op_add_i32
:
1342 ppc_addi32 (s
, args
[0], args
[1], args
[2]);
1344 tcg_out32 (s
, ADD
| TAB (args
[0], args
[1], args
[2]));
1346 case INDEX_op_sub_i32
:
1348 ppc_addi32 (s
, args
[0], args
[1], -args
[2]);
1350 tcg_out32 (s
, SUBF
| TAB (args
[0], args
[2], args
[1]));
1353 case INDEX_op_and_i64
:
1354 case INDEX_op_and_i32
:
1355 if (const_args
[2]) {
1356 if ((args
[2] & 0xffff) == args
[2])
1357 tcg_out32 (s
, ANDI
| RS (args
[1]) | RA (args
[0]) | args
[2]);
1358 else if ((args
[2] & 0xffff0000) == args
[2])
1359 tcg_out32 (s
, ANDIS
| RS (args
[1]) | RA (args
[0])
1360 | ((args
[2] >> 16) & 0xffff));
1362 tcg_out_movi (s
, (opc
== INDEX_op_and_i32
1366 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], 0));
1370 tcg_out32 (s
, AND
| SAB (args
[1], args
[0], args
[2]));
1372 case INDEX_op_or_i64
:
1373 case INDEX_op_or_i32
:
1374 if (const_args
[2]) {
1375 if (args
[2] & 0xffff) {
1376 tcg_out32 (s
, ORI
| RS (args
[1]) | RA (args
[0])
1377 | (args
[2] & 0xffff));
1379 tcg_out32 (s
, ORIS
| RS (args
[0]) | RA (args
[0])
1380 | ((args
[2] >> 16) & 0xffff));
1383 tcg_out32 (s
, ORIS
| RS (args
[1]) | RA (args
[0])
1384 | ((args
[2] >> 16) & 0xffff));
1388 tcg_out32 (s
, OR
| SAB (args
[1], args
[0], args
[2]));
1390 case INDEX_op_xor_i64
:
1391 case INDEX_op_xor_i32
:
1392 if (const_args
[2]) {
1393 if ((args
[2] & 0xffff) == args
[2])
1394 tcg_out32 (s
, XORI
| RS (args
[1]) | RA (args
[0])
1395 | (args
[2] & 0xffff));
1396 else if ((args
[2] & 0xffff0000) == args
[2])
1397 tcg_out32 (s
, XORIS
| RS (args
[1]) | RA (args
[0])
1398 | ((args
[2] >> 16) & 0xffff));
1400 tcg_out_movi (s
, (opc
== INDEX_op_and_i32
1404 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], 0));
1408 tcg_out32 (s
, XOR
| SAB (args
[1], args
[0], args
[2]));
1411 case INDEX_op_mul_i32
:
1412 if (const_args
[2]) {
1413 if (args
[2] == (int16_t) args
[2])
1414 tcg_out32 (s
, MULLI
| RT (args
[0]) | RA (args
[1])
1415 | (args
[2] & 0xffff));
1417 tcg_out_movi (s
, TCG_TYPE_I32
, 0, args
[2]);
1418 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], 0));
1422 tcg_out32 (s
, MULLW
| TAB (args
[0], args
[1], args
[2]));
1425 case INDEX_op_div_i32
:
1426 tcg_out32 (s
, DIVW
| TAB (args
[0], args
[1], args
[2]));
1429 case INDEX_op_divu_i32
:
1430 tcg_out32 (s
, DIVWU
| TAB (args
[0], args
[1], args
[2]));
1433 case INDEX_op_rem_i32
:
1434 tcg_out32 (s
, DIVW
| TAB (0, args
[1], args
[2]));
1435 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1436 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1439 case INDEX_op_remu_i32
:
1440 tcg_out32 (s
, DIVWU
| TAB (0, args
[1], args
[2]));
1441 tcg_out32 (s
, MULLW
| TAB (0, 0, args
[2]));
1442 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1445 case INDEX_op_shl_i32
:
1446 if (const_args
[2]) {
1447 tcg_out32 (s
, (RLWINM
1457 tcg_out32 (s
, SLW
| SAB (args
[1], args
[0], args
[2]));
1459 case INDEX_op_shr_i32
:
1460 if (const_args
[2]) {
1461 tcg_out32 (s
, (RLWINM
1471 tcg_out32 (s
, SRW
| SAB (args
[1], args
[0], args
[2]));
1473 case INDEX_op_sar_i32
:
1475 tcg_out32 (s
, SRAWI
| RS (args
[1]) | RA (args
[0]) | SH (args
[2]));
1477 tcg_out32 (s
, SRAW
| SAB (args
[1], args
[0], args
[2]));
1480 case INDEX_op_brcond_i32
:
1481 tcg_out_brcond (s
, args
[2], args
[0], args
[1], const_args
[1], args
[3], 0);
1484 case INDEX_op_brcond_i64
:
1485 tcg_out_brcond (s
, args
[2], args
[0], args
[1], const_args
[1], args
[3], 1);
1488 case INDEX_op_neg_i32
:
1489 case INDEX_op_neg_i64
:
1490 tcg_out32 (s
, NEG
| RT (args
[0]) | RA (args
[1]));
1493 case INDEX_op_not_i32
:
1494 case INDEX_op_not_i64
:
1495 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[1]));
1498 case INDEX_op_add_i64
:
1500 ppc_addi64 (s
, args
[0], args
[1], args
[2]);
1502 tcg_out32 (s
, ADD
| TAB (args
[0], args
[1], args
[2]));
1504 case INDEX_op_sub_i64
:
1506 ppc_addi64 (s
, args
[0], args
[1], -args
[2]);
1508 tcg_out32 (s
, SUBF
| TAB (args
[0], args
[2], args
[1]));
1511 case INDEX_op_shl_i64
:
1513 tcg_out_rld (s
, RLDICR
, args
[0], args
[1], args
[2], 63 - args
[2]);
1515 tcg_out32 (s
, SLD
| SAB (args
[1], args
[0], args
[2]));
1517 case INDEX_op_shr_i64
:
1519 tcg_out_rld (s
, RLDICL
, args
[0], args
[1], 64 - args
[2], args
[2]);
1521 tcg_out32 (s
, SRD
| SAB (args
[1], args
[0], args
[2]));
1523 case INDEX_op_sar_i64
:
1524 if (const_args
[2]) {
1525 int sh
= SH (args
[2] & 0x1f) | (((args
[2] >> 5) & 1) << 1);
1526 tcg_out32 (s
, SRADI
| RA (args
[0]) | RS (args
[1]) | sh
);
1529 tcg_out32 (s
, SRAD
| SAB (args
[1], args
[0], args
[2]));
1532 case INDEX_op_mul_i64
:
1533 tcg_out32 (s
, MULLD
| TAB (args
[0], args
[1], args
[2]));
1535 case INDEX_op_div_i64
:
1536 tcg_out32 (s
, DIVD
| TAB (args
[0], args
[1], args
[2]));
1538 case INDEX_op_divu_i64
:
1539 tcg_out32 (s
, DIVDU
| TAB (args
[0], args
[1], args
[2]));
1541 case INDEX_op_rem_i64
:
1542 tcg_out32 (s
, DIVD
| TAB (0, args
[1], args
[2]));
1543 tcg_out32 (s
, MULLD
| TAB (0, 0, args
[2]));
1544 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1546 case INDEX_op_remu_i64
:
1547 tcg_out32 (s
, DIVDU
| TAB (0, args
[1], args
[2]));
1548 tcg_out32 (s
, MULLD
| TAB (0, 0, args
[2]));
1549 tcg_out32 (s
, SUBF
| TAB (args
[0], 0, args
[1]));
1552 case INDEX_op_qemu_ld8u
:
1553 tcg_out_qemu_ld (s
, args
, 0);
1555 case INDEX_op_qemu_ld8s
:
1556 tcg_out_qemu_ld (s
, args
, 0 | 4);
1558 case INDEX_op_qemu_ld16u
:
1559 tcg_out_qemu_ld (s
, args
, 1);
1561 case INDEX_op_qemu_ld16s
:
1562 tcg_out_qemu_ld (s
, args
, 1 | 4);
1564 case INDEX_op_qemu_ld32
:
1565 case INDEX_op_qemu_ld32u
:
1566 tcg_out_qemu_ld (s
, args
, 2);
1568 case INDEX_op_qemu_ld32s
:
1569 tcg_out_qemu_ld (s
, args
, 2 | 4);
1571 case INDEX_op_qemu_ld64
:
1572 tcg_out_qemu_ld (s
, args
, 3);
1574 case INDEX_op_qemu_st8
:
1575 tcg_out_qemu_st (s
, args
, 0);
1577 case INDEX_op_qemu_st16
:
1578 tcg_out_qemu_st (s
, args
, 1);
1580 case INDEX_op_qemu_st32
:
1581 tcg_out_qemu_st (s
, args
, 2);
1583 case INDEX_op_qemu_st64
:
1584 tcg_out_qemu_st (s
, args
, 3);
1587 case INDEX_op_ext8s_i32
:
1588 case INDEX_op_ext8s_i64
:
1591 case INDEX_op_ext16s_i32
:
1592 case INDEX_op_ext16s_i64
:
1595 case INDEX_op_ext32s_i64
:
1599 tcg_out32 (s
, c
| RS (args
[1]) | RA (args
[0]));
1602 case INDEX_op_ext32u_i64
:
1603 tcg_out_rld (s
, RLDICL
, args
[0], args
[1], 0, 32);
1606 case INDEX_op_setcond_i32
:
1607 tcg_out_setcond (s
, TCG_TYPE_I32
, args
[3], args
[0], args
[1], args
[2],
1610 case INDEX_op_setcond_i64
:
1611 tcg_out_setcond (s
, TCG_TYPE_I64
, args
[3], args
[0], args
[1], args
[2],
1621 static const TCGTargetOpDef ppc_op_defs
[] = {
1622 { INDEX_op_exit_tb
, { } },
1623 { INDEX_op_goto_tb
, { } },
1624 { INDEX_op_call
, { "ri" } },
1625 { INDEX_op_jmp
, { "ri" } },
1626 { INDEX_op_br
, { } },
1628 { INDEX_op_mov_i32
, { "r", "r" } },
1629 { INDEX_op_mov_i64
, { "r", "r" } },
1630 { INDEX_op_movi_i32
, { "r" } },
1631 { INDEX_op_movi_i64
, { "r" } },
1633 { INDEX_op_ld8u_i32
, { "r", "r" } },
1634 { INDEX_op_ld8s_i32
, { "r", "r" } },
1635 { INDEX_op_ld16u_i32
, { "r", "r" } },
1636 { INDEX_op_ld16s_i32
, { "r", "r" } },
1637 { INDEX_op_ld_i32
, { "r", "r" } },
1638 { INDEX_op_ld_i64
, { "r", "r" } },
1639 { INDEX_op_st8_i32
, { "r", "r" } },
1640 { INDEX_op_st8_i64
, { "r", "r" } },
1641 { INDEX_op_st16_i32
, { "r", "r" } },
1642 { INDEX_op_st16_i64
, { "r", "r" } },
1643 { INDEX_op_st_i32
, { "r", "r" } },
1644 { INDEX_op_st_i64
, { "r", "r" } },
1645 { INDEX_op_st32_i64
, { "r", "r" } },
1647 { INDEX_op_ld8u_i64
, { "r", "r" } },
1648 { INDEX_op_ld8s_i64
, { "r", "r" } },
1649 { INDEX_op_ld16u_i64
, { "r", "r" } },
1650 { INDEX_op_ld16s_i64
, { "r", "r" } },
1651 { INDEX_op_ld32u_i64
, { "r", "r" } },
1652 { INDEX_op_ld32s_i64
, { "r", "r" } },
1654 { INDEX_op_add_i32
, { "r", "r", "ri" } },
1655 { INDEX_op_mul_i32
, { "r", "r", "ri" } },
1656 { INDEX_op_div_i32
, { "r", "r", "r" } },
1657 { INDEX_op_divu_i32
, { "r", "r", "r" } },
1658 { INDEX_op_rem_i32
, { "r", "r", "r" } },
1659 { INDEX_op_remu_i32
, { "r", "r", "r" } },
1660 { INDEX_op_sub_i32
, { "r", "r", "ri" } },
1661 { INDEX_op_and_i32
, { "r", "r", "ri" } },
1662 { INDEX_op_or_i32
, { "r", "r", "ri" } },
1663 { INDEX_op_xor_i32
, { "r", "r", "ri" } },
1665 { INDEX_op_shl_i32
, { "r", "r", "ri" } },
1666 { INDEX_op_shr_i32
, { "r", "r", "ri" } },
1667 { INDEX_op_sar_i32
, { "r", "r", "ri" } },
1669 { INDEX_op_brcond_i32
, { "r", "ri" } },
1670 { INDEX_op_brcond_i64
, { "r", "ri" } },
1672 { INDEX_op_neg_i32
, { "r", "r" } },
1673 { INDEX_op_not_i32
, { "r", "r" } },
1675 { INDEX_op_add_i64
, { "r", "r", "ri" } },
1676 { INDEX_op_sub_i64
, { "r", "r", "ri" } },
1677 { INDEX_op_and_i64
, { "r", "r", "rZ" } },
1678 { INDEX_op_or_i64
, { "r", "r", "rZ" } },
1679 { INDEX_op_xor_i64
, { "r", "r", "rZ" } },
1681 { INDEX_op_shl_i64
, { "r", "r", "ri" } },
1682 { INDEX_op_shr_i64
, { "r", "r", "ri" } },
1683 { INDEX_op_sar_i64
, { "r", "r", "ri" } },
1685 { INDEX_op_mul_i64
, { "r", "r", "r" } },
1686 { INDEX_op_div_i64
, { "r", "r", "r" } },
1687 { INDEX_op_divu_i64
, { "r", "r", "r" } },
1688 { INDEX_op_rem_i64
, { "r", "r", "r" } },
1689 { INDEX_op_remu_i64
, { "r", "r", "r" } },
1691 { INDEX_op_neg_i64
, { "r", "r" } },
1692 { INDEX_op_not_i64
, { "r", "r" } },
1694 { INDEX_op_qemu_ld8u
, { "r", "L" } },
1695 { INDEX_op_qemu_ld8s
, { "r", "L" } },
1696 { INDEX_op_qemu_ld16u
, { "r", "L" } },
1697 { INDEX_op_qemu_ld16s
, { "r", "L" } },
1698 { INDEX_op_qemu_ld32
, { "r", "L" } },
1699 { INDEX_op_qemu_ld32u
, { "r", "L" } },
1700 { INDEX_op_qemu_ld32s
, { "r", "L" } },
1701 { INDEX_op_qemu_ld64
, { "r", "L" } },
1703 { INDEX_op_qemu_st8
, { "S", "S" } },
1704 { INDEX_op_qemu_st16
, { "S", "S" } },
1705 { INDEX_op_qemu_st32
, { "S", "S" } },
1706 { INDEX_op_qemu_st64
, { "S", "S" } },
1708 { INDEX_op_ext8s_i32
, { "r", "r" } },
1709 { INDEX_op_ext16s_i32
, { "r", "r" } },
1710 { INDEX_op_ext8s_i64
, { "r", "r" } },
1711 { INDEX_op_ext16s_i64
, { "r", "r" } },
1712 { INDEX_op_ext32s_i64
, { "r", "r" } },
1713 { INDEX_op_ext32u_i64
, { "r", "r" } },
1715 { INDEX_op_setcond_i32
, { "r", "r", "ri" } },
1716 { INDEX_op_setcond_i64
, { "r", "r", "ri" } },
1721 static void tcg_target_init (TCGContext
*s
)
1723 tcg_regset_set32 (tcg_target_available_regs
[TCG_TYPE_I32
], 0, 0xffffffff);
1724 tcg_regset_set32 (tcg_target_available_regs
[TCG_TYPE_I64
], 0, 0xffffffff);
1725 tcg_regset_set32 (tcg_target_call_clobber_regs
, 0,
1737 (1 << TCG_REG_R10
) |
1738 (1 << TCG_REG_R11
) |
1742 tcg_regset_clear (s
->reserved_regs
);
1743 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R0
);
1744 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R1
);
1746 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R2
);
1748 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R13
);
1750 tcg_add_target_add_op_defs (ppc_op_defs
);