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_S16 0x100
26 #define TCG_CT_CONST_U16 0x200
27 #define TCG_CT_CONST_S32 0x400
28 #define TCG_CT_CONST_U32 0x800
29 #define TCG_CT_CONST_ZERO 0x1000
30 #define TCG_CT_CONST_MONE 0x2000
32 static uint8_t *tb_ret_addr
;
34 #if TARGET_LONG_BITS == 32
46 #ifdef CONFIG_GETAUXVAL
48 static bool have_isa_2_06
;
49 #define HAVE_ISA_2_06 have_isa_2_06
50 #define HAVE_ISEL have_isa_2_06
52 #define HAVE_ISA_2_06 0
56 #ifdef CONFIG_USE_GUEST_BASE
57 #define TCG_GUEST_BASE_REG 30
59 #define TCG_GUEST_BASE_REG 0
63 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
99 static const int tcg_target_reg_alloc_order
[] = {
100 TCG_REG_R14
, /* call saved registers */
118 TCG_REG_R12
, /* call clobbered, non-arguments */
120 TCG_REG_R10
, /* call clobbered, arguments */
130 static const int tcg_target_call_iarg_regs
[] = {
141 static const int tcg_target_call_oarg_regs
[] = {
145 static const int tcg_target_callee_save_regs
[] = {
162 TCG_REG_R27
, /* currently used for the global env */
169 static inline bool in_range_b(tcg_target_long target
)
171 return target
== sextract64(target
, 0, 26);
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 assert(in_range_b(disp
));
181 return disp
& 0x3fffffc;
184 static void reloc_pc24(void *pc
, tcg_target_long target
)
186 *(uint32_t *)pc
= (*(uint32_t *)pc
& ~0x3fffffc)
187 | reloc_pc24_val(pc
, target
);
190 static uint16_t reloc_pc14_val(void *pc
, tcg_target_long target
)
192 tcg_target_long disp
;
194 disp
= target
- (tcg_target_long
)pc
;
195 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) | reloc_pc14_val(pc
, target
);
207 static inline void tcg_out_b_noaddr(TCGContext
*s
, int insn
)
209 unsigned retrans
= *(uint32_t *)s
->code_ptr
& 0x3fffffc;
210 tcg_out32(s
, insn
| retrans
);
213 static inline void tcg_out_bc_noaddr(TCGContext
*s
, int insn
)
215 unsigned retrans
= *(uint32_t *)s
->code_ptr
& 0xfffc;
216 tcg_out32(s
, insn
| retrans
);
219 static void patch_reloc(uint8_t *code_ptr
, int type
,
220 intptr_t value
, intptr_t addend
)
225 reloc_pc14(code_ptr
, value
);
228 reloc_pc24(code_ptr
, value
);
235 /* parse target specific constraints */
236 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
242 case 'A': case 'B': case 'C': case 'D':
243 ct
->ct
|= TCG_CT_REG
;
244 tcg_regset_set_reg(ct
->u
.regs
, 3 + ct_str
[0] - 'A');
247 ct
->ct
|= TCG_CT_REG
;
248 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
250 case 'L': /* qemu_ld constraint */
251 ct
->ct
|= TCG_CT_REG
;
252 tcg_regset_set32(ct
->u
.regs
, 0, 0xffffffff);
253 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R3
);
254 #ifdef CONFIG_SOFTMMU
255 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
256 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
259 case 'S': /* qemu_st 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 #ifdef CONFIG_SOFTMMU
264 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R4
);
265 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R5
);
266 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R6
);
270 ct
->ct
|= TCG_CT_CONST_S16
;
273 ct
->ct
|= TCG_CT_CONST_U16
;
276 ct
->ct
|= TCG_CT_CONST_MONE
;
279 ct
->ct
|= TCG_CT_CONST_S32
;
282 ct
->ct
|= TCG_CT_CONST_U32
;
285 ct
->ct
|= TCG_CT_CONST_ZERO
;
295 /* test if a constant matches the constraint */
296 static int tcg_target_const_match(tcg_target_long val
,
297 const TCGArgConstraint
*arg_ct
)
300 if (ct
& TCG_CT_CONST
) {
302 } else if ((ct
& TCG_CT_CONST_S16
) && val
== (int16_t)val
) {
304 } else if ((ct
& TCG_CT_CONST_U16
) && val
== (uint16_t)val
) {
306 } else if ((ct
& TCG_CT_CONST_S32
) && val
== (int32_t)val
) {
308 } else if ((ct
& TCG_CT_CONST_U32
) && val
== (uint32_t)val
) {
310 } else if ((ct
& TCG_CT_CONST_ZERO
) && val
== 0) {
312 } else if ((ct
& TCG_CT_CONST_MONE
) && val
== -1) {
318 #define OPCD(opc) ((opc)<<26)
319 #define XO19(opc) (OPCD(19)|((opc)<<1))
320 #define MD30(opc) (OPCD(30)|((opc)<<2))
321 #define MDS30(opc) (OPCD(30)|((opc)<<1))
322 #define XO31(opc) (OPCD(31)|((opc)<<1))
323 #define XO58(opc) (OPCD(58)|(opc))
324 #define XO62(opc) (OPCD(62)|(opc))
328 #define LBZ OPCD( 34)
329 #define LHZ OPCD( 40)
330 #define LHA OPCD( 42)
331 #define LWZ OPCD( 32)
332 #define STB OPCD( 38)
333 #define STH OPCD( 44)
334 #define STW OPCD( 36)
337 #define STDU XO62( 1)
338 #define STDX XO31(149)
341 #define LDX XO31( 21)
344 #define LWAX XO31(341)
346 #define ADDIC OPCD( 12)
347 #define ADDI OPCD( 14)
348 #define ADDIS OPCD( 15)
349 #define ORI OPCD( 24)
350 #define ORIS OPCD( 25)
351 #define XORI OPCD( 26)
352 #define XORIS OPCD( 27)
353 #define ANDI OPCD( 28)
354 #define ANDIS OPCD( 29)
355 #define MULLI OPCD( 7)
356 #define CMPLI OPCD( 10)
357 #define CMPI OPCD( 11)
358 #define SUBFIC OPCD( 8)
360 #define LWZU OPCD( 33)
361 #define STWU OPCD( 37)
363 #define RLWIMI OPCD( 20)
364 #define RLWINM OPCD( 21)
365 #define RLWNM OPCD( 23)
367 #define RLDICL MD30( 0)
368 #define RLDICR MD30( 1)
369 #define RLDIMI MD30( 3)
370 #define RLDCL MDS30( 8)
372 #define BCLR XO19( 16)
373 #define BCCTR XO19(528)
374 #define CRAND XO19(257)
375 #define CRANDC XO19(129)
376 #define CRNAND XO19(225)
377 #define CROR XO19(449)
378 #define CRNOR XO19( 33)
380 #define EXTSB XO31(954)
381 #define EXTSH XO31(922)
382 #define EXTSW XO31(986)
383 #define ADD XO31(266)
384 #define ADDE XO31(138)
385 #define ADDME XO31(234)
386 #define ADDZE XO31(202)
387 #define ADDC XO31( 10)
388 #define AND XO31( 28)
389 #define SUBF XO31( 40)
390 #define SUBFC XO31( 8)
391 #define SUBFE XO31(136)
392 #define SUBFME XO31(232)
393 #define SUBFZE XO31(200)
395 #define XOR XO31(316)
396 #define MULLW XO31(235)
397 #define MULHWU XO31( 11)
398 #define DIVW XO31(491)
399 #define DIVWU XO31(459)
401 #define CMPL XO31( 32)
402 #define LHBRX XO31(790)
403 #define LWBRX XO31(534)
404 #define LDBRX XO31(532)
405 #define STHBRX XO31(918)
406 #define STWBRX XO31(662)
407 #define STDBRX XO31(660)
408 #define MFSPR XO31(339)
409 #define MTSPR XO31(467)
410 #define SRAWI XO31(824)
411 #define NEG XO31(104)
412 #define MFCR XO31( 19)
413 #define MFOCRF (MFCR | (1u << 20))
414 #define NOR XO31(124)
415 #define CNTLZW XO31( 26)
416 #define CNTLZD XO31( 58)
417 #define ANDC XO31( 60)
418 #define ORC XO31(412)
419 #define EQV XO31(284)
420 #define NAND XO31(476)
421 #define ISEL XO31( 15)
423 #define MULLD XO31(233)
424 #define MULHD XO31( 73)
425 #define MULHDU XO31( 9)
426 #define DIVD XO31(489)
427 #define DIVDU XO31(457)
429 #define LBZX XO31( 87)
430 #define LHZX XO31(279)
431 #define LHAX XO31(343)
432 #define LWZX XO31( 23)
433 #define STBX XO31(215)
434 #define STHX XO31(407)
435 #define STWX XO31(151)
437 #define SPR(a, b) ((((a)<<5)|(b))<<11)
439 #define CTR SPR(9, 0)
441 #define SLW XO31( 24)
442 #define SRW XO31(536)
443 #define SRAW XO31(792)
445 #define SLD XO31( 27)
446 #define SRD XO31(539)
447 #define SRAD XO31(794)
448 #define SRADI XO31(413<<1)
451 #define TRAP (TW | TO(31))
453 #define RT(r) ((r)<<21)
454 #define RS(r) ((r)<<21)
455 #define RA(r) ((r)<<16)
456 #define RB(r) ((r)<<11)
457 #define TO(t) ((t)<<21)
458 #define SH(s) ((s)<<11)
459 #define MB(b) ((b)<<6)
460 #define ME(e) ((e)<<1)
461 #define BO(o) ((o)<<21)
462 #define MB64(b) ((b)<<5)
463 #define FXM(b) (1 << (19 - (b)))
467 #define TAB(t, a, b) (RT(t) | RA(a) | RB(b))
468 #define SAB(s, a, b) (RS(s) | RA(a) | RB(b))
469 #define TAI(s, a, i) (RT(s) | RA(a) | ((i) & 0xffff))
470 #define SAI(s, a, i) (RS(s) | RA(a) | ((i) & 0xffff))
472 #define BF(n) ((n)<<23)
473 #define BI(n, c) (((c)+((n)*4))<<16)
474 #define BT(n, c) (((c)+((n)*4))<<21)
475 #define BA(n, c) (((c)+((n)*4))<<16)
476 #define BB(n, c) (((c)+((n)*4))<<11)
477 #define BC_(n, c) (((c)+((n)*4))<<6)
479 #define BO_COND_TRUE BO(12)
480 #define BO_COND_FALSE BO( 4)
481 #define BO_ALWAYS BO(20)
490 static const uint32_t tcg_to_bc
[] = {
491 [TCG_COND_EQ
] = BC
| BI(7, CR_EQ
) | BO_COND_TRUE
,
492 [TCG_COND_NE
] = BC
| BI(7, CR_EQ
) | BO_COND_FALSE
,
493 [TCG_COND_LT
] = BC
| BI(7, CR_LT
) | BO_COND_TRUE
,
494 [TCG_COND_GE
] = BC
| BI(7, CR_LT
) | BO_COND_FALSE
,
495 [TCG_COND_LE
] = BC
| BI(7, CR_GT
) | BO_COND_FALSE
,
496 [TCG_COND_GT
] = BC
| BI(7, CR_GT
) | BO_COND_TRUE
,
497 [TCG_COND_LTU
] = BC
| BI(7, CR_LT
) | BO_COND_TRUE
,
498 [TCG_COND_GEU
] = BC
| BI(7, CR_LT
) | BO_COND_FALSE
,
499 [TCG_COND_LEU
] = BC
| BI(7, CR_GT
) | BO_COND_FALSE
,
500 [TCG_COND_GTU
] = BC
| BI(7, CR_GT
) | BO_COND_TRUE
,
503 /* The low bit here is set if the RA and RB fields must be inverted. */
504 static const uint32_t tcg_to_isel
[] = {
505 [TCG_COND_EQ
] = ISEL
| BC_(7, CR_EQ
),
506 [TCG_COND_NE
] = ISEL
| BC_(7, CR_EQ
) | 1,
507 [TCG_COND_LT
] = ISEL
| BC_(7, CR_LT
),
508 [TCG_COND_GE
] = ISEL
| BC_(7, CR_LT
) | 1,
509 [TCG_COND_LE
] = ISEL
| BC_(7, CR_GT
) | 1,
510 [TCG_COND_GT
] = ISEL
| BC_(7, CR_GT
),
511 [TCG_COND_LTU
] = ISEL
| BC_(7, CR_LT
),
512 [TCG_COND_GEU
] = ISEL
| BC_(7, CR_LT
) | 1,
513 [TCG_COND_LEU
] = ISEL
| BC_(7, CR_GT
) | 1,
514 [TCG_COND_GTU
] = ISEL
| BC_(7, CR_GT
),
517 static inline void tcg_out_mov(TCGContext
*s
, TCGType type
,
518 TCGReg ret
, TCGReg arg
)
521 tcg_out32(s
, OR
| SAB(arg
, ret
, arg
));
525 static inline void tcg_out_rld(TCGContext
*s
, int op
, TCGReg ra
, TCGReg rs
,
528 sh
= SH(sh
& 0x1f) | (((sh
>> 5) & 1) << 1);
529 mb
= MB64((mb
>> 5) | ((mb
<< 1) & 0x3f));
530 tcg_out32(s
, op
| RA(ra
) | RS(rs
) | sh
| mb
);
533 static inline void tcg_out_rlw(TCGContext
*s
, int op
, TCGReg ra
, TCGReg rs
,
534 int sh
, int mb
, int me
)
536 tcg_out32(s
, op
| RA(ra
) | RS(rs
) | SH(sh
) | MB(mb
) | ME(me
));
539 static inline void tcg_out_ext32u(TCGContext
*s
, TCGReg dst
, TCGReg src
)
541 tcg_out_rld(s
, RLDICL
, dst
, src
, 0, 32);
544 static inline void tcg_out_shli64(TCGContext
*s
, TCGReg dst
, TCGReg src
, int c
)
546 tcg_out_rld(s
, RLDICR
, dst
, src
, c
, 63 - c
);
549 static inline void tcg_out_shri64(TCGContext
*s
, TCGReg dst
, TCGReg src
, int c
)
551 tcg_out_rld(s
, RLDICL
, dst
, src
, 64 - c
, c
);
554 static void tcg_out_movi32(TCGContext
*s
, TCGReg ret
, int32_t arg
)
556 if (arg
== (int16_t) arg
) {
557 tcg_out32(s
, ADDI
| TAI(ret
, 0, arg
));
559 tcg_out32(s
, ADDIS
| TAI(ret
, 0, arg
>> 16));
561 tcg_out32(s
, ORI
| SAI(ret
, ret
, arg
));
566 static void tcg_out_movi(TCGContext
*s
, TCGType type
, TCGReg ret
,
569 if (type
== TCG_TYPE_I32
|| arg
== (int32_t)arg
) {
570 tcg_out_movi32(s
, ret
, arg
);
571 } else if (arg
== (uint32_t)arg
&& !(arg
& 0x8000)) {
572 tcg_out32(s
, ADDI
| TAI(ret
, 0, arg
));
573 tcg_out32(s
, ORIS
| SAI(ret
, ret
, arg
>> 16));
575 int32_t high
= arg
>> 32;
576 tcg_out_movi32(s
, ret
, high
);
578 tcg_out_shli64(s
, ret
, ret
, 32);
580 if (arg
& 0xffff0000) {
581 tcg_out32(s
, ORIS
| SAI(ret
, ret
, arg
>> 16));
584 tcg_out32(s
, ORI
| SAI(ret
, ret
, arg
));
589 static bool mask_operand(uint32_t c
, int *mb
, int *me
)
593 /* Accept a bit pattern like:
597 Keep track of the transitions. */
598 if (c
== 0 || c
== -1) {
604 if (test
& (test
- 1)) {
609 *mb
= test
? clz32(test
& -test
) + 1 : 0;
613 static bool mask64_operand(uint64_t c
, int *mb
, int *me
)
622 /* Accept 1..10..0. */
628 /* Accept 0..01..1. */
629 if (lsb
== 1 && (c
& (c
+ 1)) == 0) {
630 *mb
= clz64(c
+ 1) + 1;
637 static void tcg_out_andi32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
641 if ((c
& 0xffff) == c
) {
642 tcg_out32(s
, ANDI
| SAI(src
, dst
, c
));
644 } else if ((c
& 0xffff0000) == c
) {
645 tcg_out32(s
, ANDIS
| SAI(src
, dst
, c
>> 16));
647 } else if (mask_operand(c
, &mb
, &me
)) {
648 tcg_out_rlw(s
, RLWINM
, dst
, src
, 0, mb
, me
);
650 tcg_out_movi(s
, TCG_TYPE_I32
, TCG_REG_R0
, c
);
651 tcg_out32(s
, AND
| SAB(src
, dst
, TCG_REG_R0
));
655 static void tcg_out_andi64(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint64_t c
)
659 if ((c
& 0xffff) == c
) {
660 tcg_out32(s
, ANDI
| SAI(src
, dst
, c
));
662 } else if ((c
& 0xffff0000) == c
) {
663 tcg_out32(s
, ANDIS
| SAI(src
, dst
, c
>> 16));
665 } else if (mask64_operand(c
, &mb
, &me
)) {
667 tcg_out_rld(s
, RLDICR
, dst
, src
, 0, me
);
669 tcg_out_rld(s
, RLDICL
, dst
, src
, 0, mb
);
672 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R0
, c
);
673 tcg_out32(s
, AND
| SAB(src
, dst
, TCG_REG_R0
));
677 static void tcg_out_zori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
,
678 int op_lo
, int op_hi
)
681 tcg_out32(s
, op_hi
| SAI(src
, dst
, c
>> 16));
685 tcg_out32(s
, op_lo
| SAI(src
, dst
, c
));
690 static void tcg_out_ori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
692 tcg_out_zori32(s
, dst
, src
, c
, ORI
, ORIS
);
695 static void tcg_out_xori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
697 tcg_out_zori32(s
, dst
, src
, c
, XORI
, XORIS
);
700 static void tcg_out_b(TCGContext
*s
, int mask
, tcg_target_long target
)
702 tcg_target_long disp
;
704 disp
= target
- (tcg_target_long
)s
->code_ptr
;
705 if (in_range_b(disp
)) {
706 tcg_out32(s
, B
| (disp
& 0x3fffffc) | mask
);
708 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R0
, (tcg_target_long
)target
);
709 tcg_out32(s
, MTSPR
| RS(TCG_REG_R0
) | CTR
);
710 tcg_out32(s
, BCCTR
| BO_ALWAYS
| mask
);
714 static void tcg_out_call(TCGContext
*s
, tcg_target_long arg
, int const_arg
)
718 tcg_out_b(s
, LK
, arg
);
720 tcg_out32(s
, MTSPR
| RS(arg
) | LR
);
721 tcg_out32(s
, BCLR
| BO_ALWAYS
| LK
);
728 /* Look through the descriptor. If the branch is in range, and we
729 don't have to spend too much effort on building the toc. */
730 intptr_t tgt
= ((intptr_t *)arg
)[0];
731 intptr_t toc
= ((intptr_t *)arg
)[1];
732 intptr_t diff
= tgt
- (intptr_t)s
->code_ptr
;
734 if (in_range_b(diff
) && toc
== (uint32_t)toc
) {
735 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R2
, toc
);
736 tcg_out_b(s
, LK
, tgt
);
740 /* Fold the low bits of the constant into the addresses below. */
742 if (ofs
+ 8 < 0x8000) {
748 tcg_out_movi(s
, TCG_TYPE_I64
, reg
, arg
);
751 tcg_out32(s
, LD
| TAI(TCG_REG_R0
, reg
, ofs
));
752 tcg_out32(s
, MTSPR
| RA(TCG_REG_R0
) | CTR
);
753 tcg_out32(s
, LD
| TAI(TCG_REG_R2
, reg
, ofs
+ 8));
754 tcg_out32(s
, BCCTR
| BO_ALWAYS
| LK
);
758 static void tcg_out_mem_long(TCGContext
*s
, int opi
, int opx
, TCGReg rt
,
759 TCGReg base
, tcg_target_long offset
)
761 tcg_target_long orig
= offset
, l0
, l1
, extra
= 0, align
= 0;
762 TCGReg rs
= TCG_REG_R2
;
764 assert(rt
!= TCG_REG_R2
&& base
!= TCG_REG_R2
);
771 if (rt
!= TCG_REG_R0
) {
778 case STB
: case STH
: case STW
:
782 /* For unaligned, or very large offsets, use the indexed form. */
783 if (offset
& align
|| offset
!= (int32_t)offset
) {
784 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R2
, orig
);
785 tcg_out32(s
, opx
| TAB(rt
, base
, TCG_REG_R2
));
789 l0
= (int16_t)offset
;
790 offset
= (offset
- l0
) >> 16;
791 l1
= (int16_t)offset
;
793 if (l1
< 0 && orig
>= 0) {
795 l1
= (int16_t)(offset
- 0x4000);
798 tcg_out32(s
, ADDIS
| TAI(rs
, base
, l1
));
802 tcg_out32(s
, ADDIS
| TAI(rs
, base
, extra
));
805 if (opi
!= ADDI
|| base
!= rt
|| l0
!= 0) {
806 tcg_out32(s
, opi
| TAI(rt
, base
, l0
));
810 #if defined(CONFIG_SOFTMMU)
811 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
813 static const void * const qemu_ld_helpers
[4] = {
820 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
821 uintxx_t val, int mmu_idx) */
822 static const void * const qemu_st_helpers
[4] = {
829 /* Perform the TLB load and compare. Places the result of the comparison
830 in CR7, loads the addend of the TLB into R3, and returns the register
831 containing the guest address (zero-extended into R4). Clobbers R0 and R2. */
833 static TCGReg
tcg_out_tlb_read(TCGContext
*s
, int s_bits
, TCGReg addr_reg
,
834 int mem_index
, bool is_read
)
838 ? offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_read
)
839 : offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_write
));
840 int add_off
= offsetof(CPUArchState
, tlb_table
[mem_index
][0].addend
);
841 TCGReg base
= TCG_AREG0
;
843 /* Extract the page index, shifted into place for tlb index. */
844 if (TARGET_LONG_BITS
== 32) {
845 /* Zero-extend the address into a place helpful for further use. */
846 tcg_out_ext32u(s
, TCG_REG_R4
, addr_reg
);
847 addr_reg
= TCG_REG_R4
;
849 tcg_out_rld(s
, RLDICL
, TCG_REG_R3
, addr_reg
,
850 64 - TARGET_PAGE_BITS
, 64 - CPU_TLB_BITS
);
853 /* Compensate for very large offsets. */
854 if (add_off
>= 0x8000) {
855 /* Most target env are smaller than 32k; none are larger than 64k.
856 Simplify the logic here merely to offset by 0x7ff0, giving us a
857 range just shy of 64k. Check this assumption. */
858 QEMU_BUILD_BUG_ON(offsetof(CPUArchState
,
859 tlb_table
[NB_MMU_MODES
- 1][1])
861 tcg_out32(s
, ADDI
| TAI(TCG_REG_R2
, base
, 0x7ff0));
867 /* Extraction and shifting, part 2. */
868 if (TARGET_LONG_BITS
== 32) {
869 tcg_out_rlw(s
, RLWINM
, TCG_REG_R3
, addr_reg
,
870 32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
),
871 32 - (CPU_TLB_BITS
+ CPU_TLB_ENTRY_BITS
),
872 31 - CPU_TLB_ENTRY_BITS
);
874 tcg_out_shli64(s
, TCG_REG_R3
, TCG_REG_R3
, CPU_TLB_ENTRY_BITS
);
877 tcg_out32(s
, ADD
| TAB(TCG_REG_R3
, TCG_REG_R3
, base
));
879 /* Load the tlb comparator. */
880 tcg_out32(s
, LD_ADDR
| TAI(TCG_REG_R2
, TCG_REG_R3
, cmp_off
));
882 /* Load the TLB addend for use on the fast path. Do this asap
883 to minimize any load use delay. */
884 tcg_out32(s
, LD
| TAI(TCG_REG_R3
, TCG_REG_R3
, add_off
));
886 /* Clear the non-page, non-alignment bits from the address. */
887 if (TARGET_LONG_BITS
== 32) {
888 tcg_out_rlw(s
, RLWINM
, TCG_REG_R0
, addr_reg
, 0,
889 (32 - s_bits
) & 31, 31 - TARGET_PAGE_BITS
);
890 } else if (!s_bits
) {
891 tcg_out_rld(s
, RLDICR
, TCG_REG_R0
, addr_reg
, 0, 63 - TARGET_PAGE_BITS
);
893 tcg_out_rld(s
, RLDICL
, TCG_REG_R0
, addr_reg
,
894 64 - TARGET_PAGE_BITS
, TARGET_PAGE_BITS
- s_bits
);
895 tcg_out_rld(s
, RLDICL
, TCG_REG_R0
, TCG_REG_R0
, TARGET_PAGE_BITS
, 0);
898 tcg_out32(s
, CMP
| BF(7) | RA(TCG_REG_R0
) | RB(TCG_REG_R2
) | CMP_L
);
904 static const uint32_t qemu_ldx_opc
[8] = {
905 #ifdef TARGET_WORDS_BIGENDIAN
906 LBZX
, LHZX
, LWZX
, LDX
,
909 LBZX
, LHBRX
, LWBRX
, LDBRX
,
914 static const uint32_t qemu_stx_opc
[4] = {
915 #ifdef TARGET_WORDS_BIGENDIAN
916 STBX
, STHX
, STWX
, STDX
918 STBX
, STHBRX
, STWBRX
, STDBRX
,
922 static const uint32_t qemu_exts_opc
[4] = {
923 EXTSB
, EXTSH
, EXTSW
, 0
926 static void tcg_out_qemu_ld(TCGContext
*s
, const TCGArg
*args
, int opc
)
928 TCGReg addr_reg
, data_reg
, rbase
;
929 uint32_t insn
, s_bits
;
930 #ifdef CONFIG_SOFTMMU
933 void *label1_ptr
, *label2_ptr
;
940 #ifdef CONFIG_SOFTMMU
943 addr_reg
= tcg_out_tlb_read(s
, s_bits
, addr_reg
, mem_index
, true);
945 label1_ptr
= s
->code_ptr
;
946 tcg_out32(s
, BC
| BI(7, CR_EQ
) | BO_COND_TRUE
);
950 tcg_out_mov(s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
951 tcg_out_mov(s
, TCG_TYPE_I64
, ir
++, addr_reg
);
952 tcg_out_movi(s
, TCG_TYPE_I64
, ir
++, mem_index
);
954 tcg_out_call(s
, (tcg_target_long
) qemu_ld_helpers
[s_bits
], 1);
957 insn
= qemu_exts_opc
[s_bits
];
958 tcg_out32(s
, insn
| RA(data_reg
) | RS(TCG_REG_R3
));
959 } else if (data_reg
!= TCG_REG_R3
) {
960 tcg_out_mov(s
, TCG_TYPE_I64
, data_reg
, TCG_REG_R3
);
963 label2_ptr
= s
->code_ptr
;
966 /* label1: fast path */
967 reloc_pc14(label1_ptr
, (tcg_target_long
)s
->code_ptr
);
970 #else /* !CONFIG_SOFTMMU */
971 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
972 if (TARGET_LONG_BITS
== 32) {
973 tcg_out_ext32u(s
, TCG_REG_R2
, addr_reg
);
974 addr_reg
= TCG_REG_R2
;
978 insn
= qemu_ldx_opc
[opc
];
979 if (!HAVE_ISA_2_06
&& insn
== LDBRX
) {
980 tcg_out32(s
, ADDI
| TAI(TCG_REG_R0
, addr_reg
, 4));
981 tcg_out32(s
, LWBRX
| TAB(data_reg
, rbase
, addr_reg
));
982 tcg_out32(s
, LWBRX
| TAB(TCG_REG_R0
, rbase
, TCG_REG_R0
));
983 tcg_out_rld(s
, RLDIMI
, data_reg
, TCG_REG_R0
, 32, 0);
985 tcg_out32(s
, insn
| TAB(data_reg
, rbase
, addr_reg
));
987 insn
= qemu_ldx_opc
[s_bits
];
988 tcg_out32(s
, insn
| TAB(data_reg
, rbase
, addr_reg
));
989 insn
= qemu_exts_opc
[s_bits
];
990 tcg_out32(s
, insn
| RA(data_reg
) | RS(data_reg
));
993 #ifdef CONFIG_SOFTMMU
994 reloc_pc24(label2_ptr
, (tcg_target_long
)s
->code_ptr
);
998 static void tcg_out_qemu_st(TCGContext
*s
, const TCGArg
*args
, int opc
)
1000 TCGReg addr_reg
, rbase
, data_reg
;
1002 #ifdef CONFIG_SOFTMMU
1005 void *label1_ptr
, *label2_ptr
;
1011 #ifdef CONFIG_SOFTMMU
1014 addr_reg
= tcg_out_tlb_read(s
, opc
, addr_reg
, mem_index
, false);
1016 label1_ptr
= s
->code_ptr
;
1017 tcg_out32(s
, BC
| BI(7, CR_EQ
) | BO_COND_TRUE
);
1021 tcg_out_mov(s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
1022 tcg_out_mov(s
, TCG_TYPE_I64
, ir
++, addr_reg
);
1023 tcg_out_rld(s
, RLDICL
, ir
++, data_reg
, 0, 64 - (1 << (3 + opc
)));
1024 tcg_out_movi(s
, TCG_TYPE_I64
, ir
++, mem_index
);
1026 tcg_out_call(s
, (tcg_target_long
)qemu_st_helpers
[opc
], 1);
1028 label2_ptr
= s
->code_ptr
;
1031 /* label1: fast path */
1032 reloc_pc14(label1_ptr
, (tcg_target_long
) s
->code_ptr
);
1035 #else /* !CONFIG_SOFTMMU */
1036 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
1037 if (TARGET_LONG_BITS
== 32) {
1038 tcg_out_ext32u(s
, TCG_REG_R2
, addr_reg
);
1039 addr_reg
= TCG_REG_R2
;
1043 insn
= qemu_stx_opc
[opc
];
1044 if (!HAVE_ISA_2_06
&& insn
== STDBRX
) {
1045 tcg_out32(s
, STWBRX
| SAB(data_reg
, rbase
, addr_reg
));
1046 tcg_out32(s
, ADDI
| TAI(TCG_REG_R2
, addr_reg
, 4));
1047 tcg_out_shri64(s
, TCG_REG_R0
, data_reg
, 32);
1048 tcg_out32(s
, STWBRX
| SAB(TCG_REG_R0
, rbase
, TCG_REG_R2
));
1050 tcg_out32(s
, insn
| SAB(data_reg
, rbase
, addr_reg
));
1053 #ifdef CONFIG_SOFTMMU
1054 reloc_pc24(label2_ptr
, (tcg_target_long
)s
->code_ptr
);
1058 #define FRAME_SIZE ((int) \
1059 ((8 /* back chain */ \
1062 + 8 /* compiler doubleword */ \
1063 + 8 /* link editor doubleword */ \
1064 + 8 /* TOC save area */ \
1065 + TCG_STATIC_CALL_ARGS_SIZE \
1066 + CPU_TEMP_BUF_NLONGS * sizeof(long) \
1067 + ARRAY_SIZE(tcg_target_callee_save_regs) * 8 \
1070 #define REG_SAVE_BOT (FRAME_SIZE - ARRAY_SIZE(tcg_target_callee_save_regs) * 8)
1072 static void tcg_target_qemu_prologue(TCGContext
*s
)
1076 tcg_set_frame(s
, TCG_REG_CALL_STACK
,
1077 REG_SAVE_BOT
- CPU_TEMP_BUF_NLONGS
* sizeof(long),
1078 CPU_TEMP_BUF_NLONGS
* sizeof(long));
1081 /* First emit adhoc function descriptor */
1082 tcg_out64(s
, (uint64_t)s
->code_ptr
+ 24); /* entry point */
1083 s
->code_ptr
+= 16; /* skip TOC and environment pointer */
1087 tcg_out32(s
, MFSPR
| RT(TCG_REG_R0
) | LR
);
1088 tcg_out32(s
, STDU
| SAI(TCG_REG_R1
, TCG_REG_R1
, -FRAME_SIZE
));
1089 for (i
= 0; i
< ARRAY_SIZE(tcg_target_callee_save_regs
); ++i
) {
1090 tcg_out32(s
, STD
| SAI(tcg_target_callee_save_regs
[i
], 1,
1091 REG_SAVE_BOT
+ i
* 8));
1093 tcg_out32(s
, STD
| SAI(TCG_REG_R0
, TCG_REG_R1
, FRAME_SIZE
+ 16));
1095 #ifdef CONFIG_USE_GUEST_BASE
1097 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_GUEST_BASE_REG
, GUEST_BASE
);
1098 tcg_regset_set_reg(s
->reserved_regs
, TCG_GUEST_BASE_REG
);
1102 tcg_out_mov(s
, TCG_TYPE_PTR
, TCG_AREG0
, tcg_target_call_iarg_regs
[0]);
1103 tcg_out32(s
, MTSPR
| RS(tcg_target_call_iarg_regs
[1]) | CTR
);
1104 tcg_out32(s
, BCCTR
| BO_ALWAYS
);
1107 tb_ret_addr
= s
->code_ptr
;
1109 for (i
= 0; i
< ARRAY_SIZE(tcg_target_callee_save_regs
); ++i
) {
1110 tcg_out32(s
, LD
| TAI(tcg_target_callee_save_regs
[i
], TCG_REG_R1
,
1111 REG_SAVE_BOT
+ i
* 8));
1113 tcg_out32(s
, LD
| TAI(TCG_REG_R0
, TCG_REG_R1
, FRAME_SIZE
+ 16));
1114 tcg_out32(s
, MTSPR
| RS(TCG_REG_R0
) | LR
);
1115 tcg_out32(s
, ADDI
| TAI(TCG_REG_R1
, TCG_REG_R1
, FRAME_SIZE
));
1116 tcg_out32(s
, BCLR
| BO_ALWAYS
);
1119 static inline void tcg_out_ld(TCGContext
*s
, TCGType type
, TCGReg ret
,
1120 TCGReg arg1
, intptr_t arg2
)
1124 if (type
== TCG_TYPE_I32
) {
1125 opi
= LWZ
, opx
= LWZX
;
1127 opi
= LD
, opx
= LDX
;
1129 tcg_out_mem_long(s
, opi
, opx
, ret
, arg1
, arg2
);
1132 static inline void tcg_out_st(TCGContext
*s
, TCGType type
, TCGReg arg
,
1133 TCGReg arg1
, intptr_t arg2
)
1137 if (type
== TCG_TYPE_I32
) {
1138 opi
= STW
, opx
= STWX
;
1140 opi
= STD
, opx
= STDX
;
1142 tcg_out_mem_long(s
, opi
, opx
, arg
, arg1
, arg2
);
1145 static void tcg_out_cmp(TCGContext
*s
, int cond
, TCGArg arg1
, TCGArg arg2
,
1146 int const_arg2
, int cr
, TCGType type
)
1151 /* Simplify the comparisons below wrt CMPI. */
1152 if (type
== TCG_TYPE_I32
) {
1153 arg2
= (int32_t)arg2
;
1160 if ((int16_t) arg2
== arg2
) {
1164 } else if ((uint16_t) arg2
== arg2
) {
1179 if ((int16_t) arg2
== arg2
) {
1194 if ((uint16_t) arg2
== arg2
) {
1207 op
|= BF(cr
) | ((type
== TCG_TYPE_I64
) << 21);
1210 tcg_out32(s
, op
| RA(arg1
) | (arg2
& 0xffff));
1213 tcg_out_movi(s
, type
, TCG_REG_R0
, arg2
);
1216 tcg_out32(s
, op
| RA(arg1
) | RB(arg2
));
1220 static void tcg_out_setcond_eq0(TCGContext
*s
, TCGType type
,
1221 TCGReg dst
, TCGReg src
)
1223 tcg_out32(s
, (type
== TCG_TYPE_I64
? CNTLZD
: CNTLZW
) | RS(src
) | RA(dst
));
1224 tcg_out_shri64(s
, dst
, dst
, type
== TCG_TYPE_I64
? 6 : 5);
1227 static void tcg_out_setcond_ne0(TCGContext
*s
, TCGReg dst
, TCGReg src
)
1229 /* X != 0 implies X + -1 generates a carry. Extra addition
1230 trickery means: R = X-1 + ~X + C = X-1 + (-X+1) + C = C. */
1232 tcg_out32(s
, ADDIC
| TAI(dst
, src
, -1));
1233 tcg_out32(s
, SUBFE
| TAB(dst
, dst
, src
));
1235 tcg_out32(s
, ADDIC
| TAI(TCG_REG_R0
, src
, -1));
1236 tcg_out32(s
, SUBFE
| TAB(dst
, TCG_REG_R0
, src
));
1240 static TCGReg
tcg_gen_setcond_xor(TCGContext
*s
, TCGReg arg1
, TCGArg arg2
,
1244 if ((uint32_t)arg2
== arg2
) {
1245 tcg_out_xori32(s
, TCG_REG_R0
, arg1
, arg2
);
1247 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R0
, arg2
);
1248 tcg_out32(s
, XOR
| SAB(arg1
, TCG_REG_R0
, TCG_REG_R0
));
1251 tcg_out32(s
, XOR
| SAB(arg1
, TCG_REG_R0
, arg2
));
1256 static void tcg_out_setcond(TCGContext
*s
, TCGType type
, TCGCond cond
,
1257 TCGArg arg0
, TCGArg arg1
, TCGArg arg2
,
1262 /* Ignore high bits of a potential constant arg2. */
1263 if (type
== TCG_TYPE_I32
) {
1264 arg2
= (uint32_t)arg2
;
1267 /* Handle common and trivial cases before handling anything else. */
1271 tcg_out_setcond_eq0(s
, type
, arg0
, arg1
);
1274 if (type
== TCG_TYPE_I32
) {
1275 tcg_out_ext32u(s
, TCG_REG_R0
, arg1
);
1278 tcg_out_setcond_ne0(s
, arg0
, arg1
);
1281 tcg_out32(s
, NOR
| SAB(arg1
, arg0
, arg1
));
1285 /* Extract the sign bit. */
1286 tcg_out_rld(s
, RLDICL
, arg0
, arg1
,
1287 type
== TCG_TYPE_I64
? 1 : 33, 63);
1294 /* If we have ISEL, we can implement everything with 3 or 4 insns.
1295 All other cases below are also at least 3 insns, so speed up the
1296 code generator by not considering them and always using ISEL. */
1300 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1302 isel
= tcg_to_isel
[cond
];
1304 tcg_out_movi(s
, type
, arg0
, 1);
1306 /* arg0 = (bc ? 0 : 1) */
1307 tab
= TAB(arg0
, 0, arg0
);
1310 /* arg0 = (bc ? 1 : 0) */
1311 tcg_out_movi(s
, type
, TCG_REG_R0
, 0);
1312 tab
= TAB(arg0
, arg0
, TCG_REG_R0
);
1314 tcg_out32(s
, isel
| tab
);
1320 arg1
= tcg_gen_setcond_xor(s
, arg1
, arg2
, const_arg2
);
1321 tcg_out_setcond_eq0(s
, type
, arg0
, arg1
);
1325 arg1
= tcg_gen_setcond_xor(s
, arg1
, arg2
, const_arg2
);
1326 /* Discard the high bits only once, rather than both inputs. */
1327 if (type
== TCG_TYPE_I32
) {
1328 tcg_out_ext32u(s
, TCG_REG_R0
, arg1
);
1331 tcg_out_setcond_ne0(s
, arg0
, arg1
);
1349 crop
= CRNOR
| BT(7, CR_EQ
) | BA(7, CR_LT
) | BB(7, CR_LT
);
1355 crop
= CRNOR
| BT(7, CR_EQ
) | BA(7, CR_GT
) | BB(7, CR_GT
);
1357 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1361 tcg_out32(s
, MFOCRF
| RT(TCG_REG_R0
) | FXM(7));
1362 tcg_out_rlw(s
, RLWINM
, arg0
, TCG_REG_R0
, sh
, 31, 31);
1370 static void tcg_out_bc(TCGContext
*s
, int bc
, int label_index
)
1372 TCGLabel
*l
= &s
->labels
[label_index
];
1375 tcg_out32(s
, bc
| reloc_pc14_val(s
->code_ptr
, l
->u
.value
));
1377 tcg_out_reloc(s
, s
->code_ptr
, R_PPC_REL14
, label_index
, 0);
1378 tcg_out_bc_noaddr(s
, bc
);
1382 static void tcg_out_brcond(TCGContext
*s
, TCGCond cond
,
1383 TCGArg arg1
, TCGArg arg2
, int const_arg2
,
1384 int label_index
, TCGType type
)
1386 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1387 tcg_out_bc(s
, tcg_to_bc
[cond
], label_index
);
1390 static void tcg_out_movcond(TCGContext
*s
, TCGType type
, TCGCond cond
,
1391 TCGArg dest
, TCGArg c1
, TCGArg c2
, TCGArg v1
,
1392 TCGArg v2
, bool const_c2
)
1394 /* If for some reason both inputs are zero, don't produce bad code. */
1395 if (v1
== 0 && v2
== 0) {
1396 tcg_out_movi(s
, type
, dest
, 0);
1400 tcg_out_cmp(s
, cond
, c1
, c2
, const_c2
, 7, type
);
1403 int isel
= tcg_to_isel
[cond
];
1405 /* Swap the V operands if the operation indicates inversion. */
1412 /* V1 == 0 is handled by isel; V2 == 0 must be handled by hand. */
1414 tcg_out_movi(s
, type
, TCG_REG_R0
, 0);
1416 tcg_out32(s
, isel
| TAB(dest
, v1
, v2
));
1419 cond
= tcg_invert_cond(cond
);
1421 } else if (dest
!= v1
) {
1423 tcg_out_movi(s
, type
, dest
, 0);
1425 tcg_out_mov(s
, type
, dest
, v1
);
1428 /* Branch forward over one insn */
1429 tcg_out32(s
, tcg_to_bc
[cond
] | 8);
1431 tcg_out_movi(s
, type
, dest
, 0);
1433 tcg_out_mov(s
, type
, dest
, v2
);
1438 void ppc_tb_set_jmp_target(unsigned long jmp_addr
, unsigned long addr
)
1441 unsigned long patch_size
;
1443 s
.code_ptr
= (uint8_t *) jmp_addr
;
1444 tcg_out_b(&s
, 0, addr
);
1445 patch_size
= s
.code_ptr
- (uint8_t *) jmp_addr
;
1446 flush_icache_range(jmp_addr
, jmp_addr
+ patch_size
);
1449 static void tcg_out_op(TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
1450 const int *const_args
)
1456 case INDEX_op_exit_tb
:
1457 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R3
, args
[0]);
1458 tcg_out_b(s
, 0, (tcg_target_long
)tb_ret_addr
);
1460 case INDEX_op_goto_tb
:
1461 if (s
->tb_jmp_offset
) {
1462 /* Direct jump method. */
1463 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1466 /* Indirect jump method. */
1469 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1473 TCGLabel
*l
= &s
->labels
[args
[0]];
1476 tcg_out_b(s
, 0, l
->u
.value
);
1478 tcg_out_reloc(s
, s
->code_ptr
, R_PPC_REL24
, args
[0], 0);
1479 tcg_out_b_noaddr(s
, B
);
1484 tcg_out_call(s
, args
[0], const_args
[0]);
1486 case INDEX_op_movi_i32
:
1487 tcg_out_movi(s
, TCG_TYPE_I32
, args
[0], args
[1]);
1489 case INDEX_op_movi_i64
:
1490 tcg_out_movi(s
, TCG_TYPE_I64
, args
[0], args
[1]);
1492 case INDEX_op_ld8u_i32
:
1493 case INDEX_op_ld8u_i64
:
1494 tcg_out_mem_long(s
, LBZ
, LBZX
, args
[0], args
[1], args
[2]);
1496 case INDEX_op_ld8s_i32
:
1497 case INDEX_op_ld8s_i64
:
1498 tcg_out_mem_long(s
, LBZ
, LBZX
, args
[0], args
[1], args
[2]);
1499 tcg_out32(s
, EXTSB
| RS(args
[0]) | RA(args
[0]));
1501 case INDEX_op_ld16u_i32
:
1502 case INDEX_op_ld16u_i64
:
1503 tcg_out_mem_long(s
, LHZ
, LHZX
, args
[0], args
[1], args
[2]);
1505 case INDEX_op_ld16s_i32
:
1506 case INDEX_op_ld16s_i64
:
1507 tcg_out_mem_long(s
, LHA
, LHAX
, args
[0], args
[1], args
[2]);
1509 case INDEX_op_ld_i32
:
1510 case INDEX_op_ld32u_i64
:
1511 tcg_out_mem_long(s
, LWZ
, LWZX
, args
[0], args
[1], args
[2]);
1513 case INDEX_op_ld32s_i64
:
1514 tcg_out_mem_long(s
, LWA
, LWAX
, args
[0], args
[1], args
[2]);
1516 case INDEX_op_ld_i64
:
1517 tcg_out_mem_long(s
, LD
, LDX
, args
[0], args
[1], args
[2]);
1519 case INDEX_op_st8_i32
:
1520 case INDEX_op_st8_i64
:
1521 tcg_out_mem_long(s
, STB
, STBX
, args
[0], args
[1], args
[2]);
1523 case INDEX_op_st16_i32
:
1524 case INDEX_op_st16_i64
:
1525 tcg_out_mem_long(s
, STH
, STHX
, args
[0], args
[1], args
[2]);
1527 case INDEX_op_st_i32
:
1528 case INDEX_op_st32_i64
:
1529 tcg_out_mem_long(s
, STW
, STWX
, args
[0], args
[1], args
[2]);
1531 case INDEX_op_st_i64
:
1532 tcg_out_mem_long(s
, STD
, STDX
, args
[0], args
[1], args
[2]);
1535 case INDEX_op_add_i32
:
1536 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1537 if (const_args
[2]) {
1539 tcg_out_mem_long(s
, ADDI
, ADD
, a0
, a1
, (int32_t)a2
);
1541 tcg_out32(s
, ADD
| TAB(a0
, a1
, a2
));
1544 case INDEX_op_sub_i32
:
1545 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1546 if (const_args
[1]) {
1547 if (const_args
[2]) {
1548 tcg_out_movi(s
, TCG_TYPE_I32
, a0
, a1
- a2
);
1550 tcg_out32(s
, SUBFIC
| TAI(a0
, a2
, a1
));
1552 } else if (const_args
[2]) {
1556 tcg_out32(s
, SUBF
| TAB(a0
, a2
, a1
));
1560 case INDEX_op_and_i32
:
1561 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1562 if (const_args
[2]) {
1563 tcg_out_andi32(s
, a0
, a1
, a2
);
1565 tcg_out32(s
, AND
| SAB(a1
, a0
, a2
));
1568 case INDEX_op_and_i64
:
1569 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1570 if (const_args
[2]) {
1571 tcg_out_andi64(s
, a0
, a1
, a2
);
1573 tcg_out32(s
, AND
| SAB(a1
, a0
, a2
));
1576 case INDEX_op_or_i64
:
1577 case INDEX_op_or_i32
:
1578 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1579 if (const_args
[2]) {
1580 tcg_out_ori32(s
, a0
, a1
, a2
);
1582 tcg_out32(s
, OR
| SAB(a1
, a0
, a2
));
1585 case INDEX_op_xor_i64
:
1586 case INDEX_op_xor_i32
:
1587 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1588 if (const_args
[2]) {
1589 tcg_out_xori32(s
, a0
, a1
, a2
);
1591 tcg_out32(s
, XOR
| SAB(a1
, a0
, a2
));
1594 case INDEX_op_andc_i32
:
1595 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1596 if (const_args
[2]) {
1597 tcg_out_andi32(s
, a0
, a1
, ~a2
);
1599 tcg_out32(s
, ANDC
| SAB(a1
, a0
, a2
));
1602 case INDEX_op_andc_i64
:
1603 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1604 if (const_args
[2]) {
1605 tcg_out_andi64(s
, a0
, a1
, ~a2
);
1607 tcg_out32(s
, ANDC
| SAB(a1
, a0
, a2
));
1610 case INDEX_op_orc_i32
:
1611 if (const_args
[2]) {
1612 tcg_out_ori32(s
, args
[0], args
[1], ~args
[2]);
1616 case INDEX_op_orc_i64
:
1617 tcg_out32(s
, ORC
| SAB(args
[1], args
[0], args
[2]));
1619 case INDEX_op_eqv_i32
:
1620 if (const_args
[2]) {
1621 tcg_out_xori32(s
, args
[0], args
[1], ~args
[2]);
1625 case INDEX_op_eqv_i64
:
1626 tcg_out32(s
, EQV
| SAB(args
[1], args
[0], args
[2]));
1628 case INDEX_op_nand_i32
:
1629 case INDEX_op_nand_i64
:
1630 tcg_out32(s
, NAND
| SAB(args
[1], args
[0], args
[2]));
1632 case INDEX_op_nor_i32
:
1633 case INDEX_op_nor_i64
:
1634 tcg_out32(s
, NOR
| SAB(args
[1], args
[0], args
[2]));
1637 case INDEX_op_mul_i32
:
1638 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1639 if (const_args
[2]) {
1640 tcg_out32(s
, MULLI
| TAI(a0
, a1
, a2
));
1642 tcg_out32(s
, MULLW
| TAB(a0
, a1
, a2
));
1646 case INDEX_op_div_i32
:
1647 tcg_out32(s
, DIVW
| TAB(args
[0], args
[1], args
[2]));
1650 case INDEX_op_divu_i32
:
1651 tcg_out32(s
, DIVWU
| TAB(args
[0], args
[1], args
[2]));
1654 case INDEX_op_shl_i32
:
1655 if (const_args
[2]) {
1656 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], args
[2], 0, 31 - args
[2]);
1658 tcg_out32(s
, SLW
| SAB(args
[1], args
[0], args
[2]));
1661 case INDEX_op_shr_i32
:
1662 if (const_args
[2]) {
1663 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], 32 - args
[2], args
[2], 31);
1665 tcg_out32(s
, SRW
| SAB(args
[1], args
[0], args
[2]));
1668 case INDEX_op_sar_i32
:
1669 if (const_args
[2]) {
1670 tcg_out32(s
, SRAWI
| RS(args
[1]) | RA(args
[0]) | SH(args
[2]));
1672 tcg_out32(s
, SRAW
| SAB(args
[1], args
[0], args
[2]));
1675 case INDEX_op_rotl_i32
:
1676 if (const_args
[2]) {
1677 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], args
[2], 0, 31);
1679 tcg_out32(s
, RLWNM
| SAB(args
[1], args
[0], args
[2])
1683 case INDEX_op_rotr_i32
:
1684 if (const_args
[2]) {
1685 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], 32 - args
[2], 0, 31);
1687 tcg_out32(s
, SUBFIC
| TAI(TCG_REG_R0
, args
[2], 32));
1688 tcg_out32(s
, RLWNM
| SAB(args
[1], args
[0], TCG_REG_R0
)
1693 case INDEX_op_brcond_i32
:
1694 tcg_out_brcond(s
, args
[2], args
[0], args
[1], const_args
[1],
1695 args
[3], TCG_TYPE_I32
);
1698 case INDEX_op_brcond_i64
:
1699 tcg_out_brcond(s
, args
[2], args
[0], args
[1], const_args
[1],
1700 args
[3], TCG_TYPE_I64
);
1703 case INDEX_op_neg_i32
:
1704 case INDEX_op_neg_i64
:
1705 tcg_out32(s
, NEG
| RT(args
[0]) | RA(args
[1]));
1708 case INDEX_op_not_i32
:
1709 case INDEX_op_not_i64
:
1710 tcg_out32(s
, NOR
| SAB(args
[1], args
[0], args
[1]));
1713 case INDEX_op_add_i64
:
1714 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1715 if (const_args
[2]) {
1717 tcg_out_mem_long(s
, ADDI
, ADD
, a0
, a1
, a2
);
1719 tcg_out32(s
, ADD
| TAB(a0
, a1
, a2
));
1722 case INDEX_op_sub_i64
:
1723 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1724 if (const_args
[1]) {
1725 if (const_args
[2]) {
1726 tcg_out_movi(s
, TCG_TYPE_I64
, a0
, a1
- a2
);
1728 tcg_out32(s
, SUBFIC
| TAI(a0
, a2
, a1
));
1730 } else if (const_args
[2]) {
1734 tcg_out32(s
, SUBF
| TAB(a0
, a2
, a1
));
1738 case INDEX_op_shl_i64
:
1739 if (const_args
[2]) {
1740 tcg_out_shli64(s
, args
[0], args
[1], args
[2]);
1742 tcg_out32(s
, SLD
| SAB(args
[1], args
[0], args
[2]));
1745 case INDEX_op_shr_i64
:
1746 if (const_args
[2]) {
1747 tcg_out_shri64(s
, args
[0], args
[1], args
[2]);
1749 tcg_out32(s
, SRD
| SAB(args
[1], args
[0], args
[2]));
1752 case INDEX_op_sar_i64
:
1753 if (const_args
[2]) {
1754 int sh
= SH(args
[2] & 0x1f) | (((args
[2] >> 5) & 1) << 1);
1755 tcg_out32(s
, SRADI
| RA(args
[0]) | RS(args
[1]) | sh
);
1757 tcg_out32(s
, SRAD
| SAB(args
[1], args
[0], args
[2]));
1760 case INDEX_op_rotl_i64
:
1761 if (const_args
[2]) {
1762 tcg_out_rld(s
, RLDICL
, args
[0], args
[1], args
[2], 0);
1764 tcg_out32(s
, RLDCL
| SAB(args
[1], args
[0], args
[2]) | MB64(0));
1767 case INDEX_op_rotr_i64
:
1768 if (const_args
[2]) {
1769 tcg_out_rld(s
, RLDICL
, args
[0], args
[1], 64 - args
[2], 0);
1771 tcg_out32(s
, SUBFIC
| TAI(TCG_REG_R0
, args
[2], 64));
1772 tcg_out32(s
, RLDCL
| SAB(args
[1], args
[0], TCG_REG_R0
) | MB64(0));
1776 case INDEX_op_mul_i64
:
1777 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1778 if (const_args
[2]) {
1779 tcg_out32(s
, MULLI
| TAI(a0
, a1
, a2
));
1781 tcg_out32(s
, MULLD
| TAB(a0
, a1
, a2
));
1784 case INDEX_op_div_i64
:
1785 tcg_out32(s
, DIVD
| TAB(args
[0], args
[1], args
[2]));
1787 case INDEX_op_divu_i64
:
1788 tcg_out32(s
, DIVDU
| TAB(args
[0], args
[1], args
[2]));
1791 case INDEX_op_qemu_ld8u
:
1792 tcg_out_qemu_ld(s
, args
, 0);
1794 case INDEX_op_qemu_ld8s
:
1795 tcg_out_qemu_ld(s
, args
, 0 | 4);
1797 case INDEX_op_qemu_ld16u
:
1798 tcg_out_qemu_ld(s
, args
, 1);
1800 case INDEX_op_qemu_ld16s
:
1801 tcg_out_qemu_ld(s
, args
, 1 | 4);
1803 case INDEX_op_qemu_ld32
:
1804 case INDEX_op_qemu_ld32u
:
1805 tcg_out_qemu_ld(s
, args
, 2);
1807 case INDEX_op_qemu_ld32s
:
1808 tcg_out_qemu_ld(s
, args
, 2 | 4);
1810 case INDEX_op_qemu_ld64
:
1811 tcg_out_qemu_ld(s
, args
, 3);
1813 case INDEX_op_qemu_st8
:
1814 tcg_out_qemu_st(s
, args
, 0);
1816 case INDEX_op_qemu_st16
:
1817 tcg_out_qemu_st(s
, args
, 1);
1819 case INDEX_op_qemu_st32
:
1820 tcg_out_qemu_st(s
, args
, 2);
1822 case INDEX_op_qemu_st64
:
1823 tcg_out_qemu_st(s
, args
, 3);
1826 case INDEX_op_ext8s_i32
:
1827 case INDEX_op_ext8s_i64
:
1830 case INDEX_op_ext16s_i32
:
1831 case INDEX_op_ext16s_i64
:
1834 case INDEX_op_ext32s_i64
:
1838 tcg_out32(s
, c
| RS(args
[1]) | RA(args
[0]));
1841 case INDEX_op_setcond_i32
:
1842 tcg_out_setcond(s
, TCG_TYPE_I32
, args
[3], args
[0], args
[1], args
[2],
1845 case INDEX_op_setcond_i64
:
1846 tcg_out_setcond(s
, TCG_TYPE_I64
, args
[3], args
[0], args
[1], args
[2],
1850 case INDEX_op_bswap16_i32
:
1851 case INDEX_op_bswap16_i64
:
1852 a0
= args
[0], a1
= args
[1];
1855 /* a0 = (a1 r<< 24) & 0xff # 000c */
1856 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 24, 24, 31);
1857 /* a0 = (a0 & ~0xff00) | (a1 r<< 8) & 0xff00 # 00dc */
1858 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 8, 16, 23);
1860 /* r0 = (a1 r<< 8) & 0xff00 # 00d0 */
1861 tcg_out_rlw(s
, RLWINM
, TCG_REG_R0
, a1
, 8, 16, 23);
1862 /* a0 = (a1 r<< 24) & 0xff # 000c */
1863 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 24, 24, 31);
1864 /* a0 = a0 | r0 # 00dc */
1865 tcg_out32(s
, OR
| SAB(TCG_REG_R0
, a0
, a0
));
1869 case INDEX_op_bswap32_i32
:
1870 case INDEX_op_bswap32_i64
:
1871 /* Stolen from gcc's builtin_bswap32 */
1873 a0
= args
[0] == a1
? TCG_REG_R0
: args
[0];
1875 /* a1 = args[1] # abcd */
1876 /* a0 = rotate_left (a1, 8) # bcda */
1877 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 8, 0, 31);
1878 /* a0 = (a0 & ~0xff000000) | ((a1 r<< 24) & 0xff000000) # dcda */
1879 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 0, 7);
1880 /* a0 = (a0 & ~0x0000ff00) | ((a1 r<< 24) & 0x0000ff00) # dcba */
1881 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 16, 23);
1883 if (a0
== TCG_REG_R0
) {
1884 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1888 case INDEX_op_bswap64_i64
:
1889 a0
= args
[0], a1
= args
[1], a2
= TCG_REG_R0
;
1895 /* a1 = # abcd efgh */
1896 /* a0 = rl32(a1, 8) # 0000 fghe */
1897 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 8, 0, 31);
1898 /* a0 = dep(a0, rl32(a1, 24), 0xff000000) # 0000 hghe */
1899 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 0, 7);
1900 /* a0 = dep(a0, rl32(a1, 24), 0x0000ff00) # 0000 hgfe */
1901 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 16, 23);
1903 /* a0 = rl64(a0, 32) # hgfe 0000 */
1904 /* a2 = rl64(a1, 32) # efgh abcd */
1905 tcg_out_rld(s
, RLDICL
, a0
, a0
, 32, 0);
1906 tcg_out_rld(s
, RLDICL
, a2
, a1
, 32, 0);
1908 /* a0 = dep(a0, rl32(a2, 8), 0xffffffff) # hgfe bcda */
1909 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 8, 0, 31);
1910 /* a0 = dep(a0, rl32(a2, 24), 0xff000000) # hgfe dcda */
1911 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 24, 0, 7);
1912 /* a0 = dep(a0, rl32(a2, 24), 0x0000ff00) # hgfe dcba */
1913 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 24, 16, 23);
1916 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1920 case INDEX_op_deposit_i32
:
1921 if (const_args
[2]) {
1922 uint32_t mask
= ((2u << (args
[4] - 1)) - 1) << args
[3];
1923 tcg_out_andi32(s
, args
[0], args
[0], ~mask
);
1925 tcg_out_rlw(s
, RLWIMI
, args
[0], args
[2], args
[3],
1926 32 - args
[3] - args
[4], 31 - args
[3]);
1929 case INDEX_op_deposit_i64
:
1930 if (const_args
[2]) {
1931 uint64_t mask
= ((2ull << (args
[4] - 1)) - 1) << args
[3];
1932 tcg_out_andi64(s
, args
[0], args
[0], ~mask
);
1934 tcg_out_rld(s
, RLDIMI
, args
[0], args
[2], args
[3],
1935 64 - args
[3] - args
[4]);
1939 case INDEX_op_movcond_i32
:
1940 tcg_out_movcond(s
, TCG_TYPE_I32
, args
[5], args
[0], args
[1], args
[2],
1941 args
[3], args
[4], const_args
[2]);
1943 case INDEX_op_movcond_i64
:
1944 tcg_out_movcond(s
, TCG_TYPE_I64
, args
[5], args
[0], args
[1], args
[2],
1945 args
[3], args
[4], const_args
[2]);
1948 case INDEX_op_add2_i64
:
1949 /* Note that the CA bit is defined based on the word size of the
1950 environment. So in 64-bit mode it's always carry-out of bit 63.
1951 The fallback code using deposit works just as well for 32-bit. */
1952 a0
= args
[0], a1
= args
[1];
1953 if (a0
== args
[3] || (!const_args
[5] && a0
== args
[5])) {
1956 if (const_args
[4]) {
1957 tcg_out32(s
, ADDIC
| TAI(a0
, args
[2], args
[4]));
1959 tcg_out32(s
, ADDC
| TAB(a0
, args
[2], args
[4]));
1961 if (const_args
[5]) {
1962 tcg_out32(s
, (args
[5] ? ADDME
: ADDZE
) | RT(a1
) | RA(args
[3]));
1964 tcg_out32(s
, ADDE
| TAB(a1
, args
[3], args
[5]));
1966 if (a0
!= args
[0]) {
1967 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1971 case INDEX_op_sub2_i64
:
1972 a0
= args
[0], a1
= args
[1];
1973 if (a0
== args
[5] || (!const_args
[4] && a0
== args
[4])) {
1976 if (const_args
[2]) {
1977 tcg_out32(s
, SUBFIC
| TAI(a0
, args
[3], args
[2]));
1979 tcg_out32(s
, SUBFC
| TAB(a0
, args
[3], args
[2]));
1981 if (const_args
[4]) {
1982 tcg_out32(s
, (args
[4] ? SUBFME
: SUBFZE
) | RT(a1
) | RA(args
[5]));
1984 tcg_out32(s
, SUBFE
| TAB(a1
, args
[5], args
[4]));
1986 if (a0
!= args
[0]) {
1987 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1991 case INDEX_op_muluh_i64
:
1992 tcg_out32(s
, MULHDU
| TAB(args
[0], args
[1], args
[2]));
1994 case INDEX_op_mulsh_i64
:
1995 tcg_out32(s
, MULHD
| TAB(args
[0], args
[1], args
[2]));
2004 static const TCGTargetOpDef ppc_op_defs
[] = {
2005 { INDEX_op_exit_tb
, { } },
2006 { INDEX_op_goto_tb
, { } },
2007 { INDEX_op_call
, { "ri" } },
2008 { INDEX_op_br
, { } },
2010 { INDEX_op_mov_i32
, { "r", "r" } },
2011 { INDEX_op_mov_i64
, { "r", "r" } },
2012 { INDEX_op_movi_i32
, { "r" } },
2013 { INDEX_op_movi_i64
, { "r" } },
2015 { INDEX_op_ld8u_i32
, { "r", "r" } },
2016 { INDEX_op_ld8s_i32
, { "r", "r" } },
2017 { INDEX_op_ld16u_i32
, { "r", "r" } },
2018 { INDEX_op_ld16s_i32
, { "r", "r" } },
2019 { INDEX_op_ld_i32
, { "r", "r" } },
2020 { INDEX_op_ld_i64
, { "r", "r" } },
2021 { INDEX_op_st8_i32
, { "r", "r" } },
2022 { INDEX_op_st8_i64
, { "r", "r" } },
2023 { INDEX_op_st16_i32
, { "r", "r" } },
2024 { INDEX_op_st16_i64
, { "r", "r" } },
2025 { INDEX_op_st_i32
, { "r", "r" } },
2026 { INDEX_op_st_i64
, { "r", "r" } },
2027 { INDEX_op_st32_i64
, { "r", "r" } },
2029 { INDEX_op_ld8u_i64
, { "r", "r" } },
2030 { INDEX_op_ld8s_i64
, { "r", "r" } },
2031 { INDEX_op_ld16u_i64
, { "r", "r" } },
2032 { INDEX_op_ld16s_i64
, { "r", "r" } },
2033 { INDEX_op_ld32u_i64
, { "r", "r" } },
2034 { INDEX_op_ld32s_i64
, { "r", "r" } },
2036 { INDEX_op_add_i32
, { "r", "r", "ri" } },
2037 { INDEX_op_mul_i32
, { "r", "r", "rI" } },
2038 { INDEX_op_div_i32
, { "r", "r", "r" } },
2039 { INDEX_op_divu_i32
, { "r", "r", "r" } },
2040 { INDEX_op_sub_i32
, { "r", "rI", "ri" } },
2041 { INDEX_op_and_i32
, { "r", "r", "ri" } },
2042 { INDEX_op_or_i32
, { "r", "r", "ri" } },
2043 { INDEX_op_xor_i32
, { "r", "r", "ri" } },
2044 { INDEX_op_andc_i32
, { "r", "r", "ri" } },
2045 { INDEX_op_orc_i32
, { "r", "r", "ri" } },
2046 { INDEX_op_eqv_i32
, { "r", "r", "ri" } },
2047 { INDEX_op_nand_i32
, { "r", "r", "r" } },
2048 { INDEX_op_nor_i32
, { "r", "r", "r" } },
2050 { INDEX_op_shl_i32
, { "r", "r", "ri" } },
2051 { INDEX_op_shr_i32
, { "r", "r", "ri" } },
2052 { INDEX_op_sar_i32
, { "r", "r", "ri" } },
2053 { INDEX_op_rotl_i32
, { "r", "r", "ri" } },
2054 { INDEX_op_rotr_i32
, { "r", "r", "ri" } },
2056 { INDEX_op_brcond_i32
, { "r", "ri" } },
2057 { INDEX_op_brcond_i64
, { "r", "ri" } },
2059 { INDEX_op_neg_i32
, { "r", "r" } },
2060 { INDEX_op_not_i32
, { "r", "r" } },
2062 { INDEX_op_add_i64
, { "r", "r", "rT" } },
2063 { INDEX_op_sub_i64
, { "r", "rI", "rT" } },
2064 { INDEX_op_and_i64
, { "r", "r", "ri" } },
2065 { INDEX_op_or_i64
, { "r", "r", "rU" } },
2066 { INDEX_op_xor_i64
, { "r", "r", "rU" } },
2067 { INDEX_op_andc_i64
, { "r", "r", "ri" } },
2068 { INDEX_op_orc_i64
, { "r", "r", "r" } },
2069 { INDEX_op_eqv_i64
, { "r", "r", "r" } },
2070 { INDEX_op_nand_i64
, { "r", "r", "r" } },
2071 { INDEX_op_nor_i64
, { "r", "r", "r" } },
2073 { INDEX_op_shl_i64
, { "r", "r", "ri" } },
2074 { INDEX_op_shr_i64
, { "r", "r", "ri" } },
2075 { INDEX_op_sar_i64
, { "r", "r", "ri" } },
2076 { INDEX_op_rotl_i64
, { "r", "r", "ri" } },
2077 { INDEX_op_rotr_i64
, { "r", "r", "ri" } },
2079 { INDEX_op_mul_i64
, { "r", "r", "rI" } },
2080 { INDEX_op_div_i64
, { "r", "r", "r" } },
2081 { INDEX_op_divu_i64
, { "r", "r", "r" } },
2083 { INDEX_op_neg_i64
, { "r", "r" } },
2084 { INDEX_op_not_i64
, { "r", "r" } },
2086 { INDEX_op_qemu_ld8u
, { "r", "L" } },
2087 { INDEX_op_qemu_ld8s
, { "r", "L" } },
2088 { INDEX_op_qemu_ld16u
, { "r", "L" } },
2089 { INDEX_op_qemu_ld16s
, { "r", "L" } },
2090 { INDEX_op_qemu_ld32
, { "r", "L" } },
2091 { INDEX_op_qemu_ld32u
, { "r", "L" } },
2092 { INDEX_op_qemu_ld32s
, { "r", "L" } },
2093 { INDEX_op_qemu_ld64
, { "r", "L" } },
2095 { INDEX_op_qemu_st8
, { "S", "S" } },
2096 { INDEX_op_qemu_st16
, { "S", "S" } },
2097 { INDEX_op_qemu_st32
, { "S", "S" } },
2098 { INDEX_op_qemu_st64
, { "S", "S" } },
2100 { INDEX_op_ext8s_i32
, { "r", "r" } },
2101 { INDEX_op_ext16s_i32
, { "r", "r" } },
2102 { INDEX_op_ext8s_i64
, { "r", "r" } },
2103 { INDEX_op_ext16s_i64
, { "r", "r" } },
2104 { INDEX_op_ext32s_i64
, { "r", "r" } },
2106 { INDEX_op_setcond_i32
, { "r", "r", "ri" } },
2107 { INDEX_op_setcond_i64
, { "r", "r", "ri" } },
2108 { INDEX_op_movcond_i32
, { "r", "r", "ri", "rZ", "rZ" } },
2109 { INDEX_op_movcond_i64
, { "r", "r", "ri", "rZ", "rZ" } },
2111 { INDEX_op_bswap16_i32
, { "r", "r" } },
2112 { INDEX_op_bswap16_i64
, { "r", "r" } },
2113 { INDEX_op_bswap32_i32
, { "r", "r" } },
2114 { INDEX_op_bswap32_i64
, { "r", "r" } },
2115 { INDEX_op_bswap64_i64
, { "r", "r" } },
2117 { INDEX_op_deposit_i32
, { "r", "0", "rZ" } },
2118 { INDEX_op_deposit_i64
, { "r", "0", "rZ" } },
2120 { INDEX_op_add2_i64
, { "r", "r", "r", "r", "rI", "rZM" } },
2121 { INDEX_op_sub2_i64
, { "r", "r", "rI", "r", "rZM", "r" } },
2122 { INDEX_op_mulsh_i64
, { "r", "r", "r" } },
2123 { INDEX_op_muluh_i64
, { "r", "r", "r" } },
2128 static void tcg_target_init(TCGContext
*s
)
2130 #ifdef CONFIG_GETAUXVAL
2131 unsigned long hwcap
= getauxval(AT_HWCAP
);
2132 if (hwcap
& PPC_FEATURE_ARCH_2_06
) {
2133 have_isa_2_06
= true;
2137 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I32
], 0, 0xffffffff);
2138 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I64
], 0, 0xffffffff);
2139 tcg_regset_set32(tcg_target_call_clobber_regs
, 0,
2149 (1 << TCG_REG_R10
) |
2150 (1 << TCG_REG_R11
) |
2151 (1 << TCG_REG_R12
));
2153 tcg_regset_clear(s
->reserved_regs
);
2154 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R0
); /* tcg temp */
2155 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R1
); /* stack pointer */
2156 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R2
); /* mem temp */
2158 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R11
); /* ??? */
2160 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R13
); /* thread pointer */
2162 tcg_add_target_add_op_defs(ppc_op_defs
);
2167 DebugFrameFDEHeader fde
;
2168 uint8_t fde_def_cfa
[4];
2169 uint8_t fde_reg_ofs
[ARRAY_SIZE(tcg_target_callee_save_regs
) * 2 + 3];
2172 /* We're expecting a 2 byte uleb128 encoded value. */
2173 QEMU_BUILD_BUG_ON(FRAME_SIZE
>= (1 << 14));
2175 #define ELF_HOST_MACHINE EM_PPC64
2177 static DebugFrame debug_frame
= {
2178 .cie
.len
= sizeof(DebugFrameCIE
)-4, /* length after .len member */
2181 .cie
.code_align
= 1,
2182 .cie
.data_align
= 0x78, /* sleb128 -8 */
2183 .cie
.return_column
= 65,
2185 /* Total FDE size does not include the "len" member. */
2186 .fde
.len
= sizeof(DebugFrame
) - offsetof(DebugFrame
, fde
.cie_offset
),
2189 12, 1, /* DW_CFA_def_cfa r1, ... */
2190 (FRAME_SIZE
& 0x7f) | 0x80, /* ... uleb128 FRAME_SIZE */
2194 0x11, 65, 0x7e, /* DW_CFA_offset_extended_sf, lr, 16 */
2198 void tcg_register_jit(void *buf
, size_t buf_size
)
2200 uint8_t *p
= &debug_frame
.fde_reg_ofs
[3];
2203 for (i
= 0; i
< ARRAY_SIZE(tcg_target_callee_save_regs
); ++i
, p
+= 2) {
2204 p
[0] = 0x80 + tcg_target_callee_save_regs
[i
];
2205 p
[1] = (FRAME_SIZE
- (REG_SAVE_BOT
+ i
* 8)) / 8;
2208 debug_frame
.fde
.func_start
= (tcg_target_long
) buf
;
2209 debug_frame
.fde
.func_len
= buf_size
;
2211 tcg_register_jit_int(buf
, buf_size
, &debug_frame
, sizeof(debug_frame
));