2 * Tiny Code Interpreter for QEMU
4 * Copyright (c) 2009, 2011 Stefan Weil
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /* Defining NDEBUG disables assertions (which makes the code faster). */
23 #if !defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
27 #include "qemu-common.h"
28 #include "exec/exec-all.h" /* MAX_OPC_PARAM_IARGS */
31 /* Marker for missing code. */
34 fprintf(stderr, "TODO %s:%u: %s()\n", \
35 __FILE__, __LINE__, __func__); \
39 #if MAX_OPC_PARAM_IARGS != 5
40 # error Fix needed, number of supported input arguments changed!
42 #if TCG_TARGET_REG_BITS == 32
43 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
44 tcg_target_ulong
, tcg_target_ulong
,
45 tcg_target_ulong
, tcg_target_ulong
,
46 tcg_target_ulong
, tcg_target_ulong
,
47 tcg_target_ulong
, tcg_target_ulong
);
49 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
50 tcg_target_ulong
, tcg_target_ulong
,
54 /* Targets which don't use GETPC also don't need tci_tb_ptr
55 which makes them a little faster. */
60 static tcg_target_ulong tci_reg
[TCG_TARGET_NB_REGS
];
62 static tcg_target_ulong
tci_read_reg(TCGReg index
)
64 assert(index
< ARRAY_SIZE(tci_reg
));
65 return tci_reg
[index
];
68 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
69 static int8_t tci_read_reg8s(TCGReg index
)
71 return (int8_t)tci_read_reg(index
);
75 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
76 static int16_t tci_read_reg16s(TCGReg index
)
78 return (int16_t)tci_read_reg(index
);
82 #if TCG_TARGET_REG_BITS == 64
83 static int32_t tci_read_reg32s(TCGReg index
)
85 return (int32_t)tci_read_reg(index
);
89 static uint8_t tci_read_reg8(TCGReg index
)
91 return (uint8_t)tci_read_reg(index
);
94 static uint16_t tci_read_reg16(TCGReg index
)
96 return (uint16_t)tci_read_reg(index
);
99 static uint32_t tci_read_reg32(TCGReg index
)
101 return (uint32_t)tci_read_reg(index
);
104 #if TCG_TARGET_REG_BITS == 64
105 static uint64_t tci_read_reg64(TCGReg index
)
107 return tci_read_reg(index
);
111 static void tci_write_reg(TCGReg index
, tcg_target_ulong value
)
113 assert(index
< ARRAY_SIZE(tci_reg
));
114 assert(index
!= TCG_AREG0
);
115 assert(index
!= TCG_REG_CALL_STACK
);
116 tci_reg
[index
] = value
;
119 static void tci_write_reg8s(TCGReg index
, int8_t value
)
121 tci_write_reg(index
, value
);
124 static void tci_write_reg16s(TCGReg index
, int16_t value
)
126 tci_write_reg(index
, value
);
129 #if TCG_TARGET_REG_BITS == 64
130 static void tci_write_reg32s(TCGReg index
, int32_t value
)
132 tci_write_reg(index
, value
);
136 static void tci_write_reg8(TCGReg index
, uint8_t value
)
138 tci_write_reg(index
, value
);
141 static void tci_write_reg16(TCGReg index
, uint16_t value
)
143 tci_write_reg(index
, value
);
146 static void tci_write_reg32(TCGReg index
, uint32_t value
)
148 tci_write_reg(index
, value
);
151 #if TCG_TARGET_REG_BITS == 32
152 static void tci_write_reg64(uint32_t high_index
, uint32_t low_index
,
155 tci_write_reg(low_index
, value
);
156 tci_write_reg(high_index
, value
>> 32);
158 #elif TCG_TARGET_REG_BITS == 64
159 static void tci_write_reg64(TCGReg index
, uint64_t value
)
161 tci_write_reg(index
, value
);
165 #if TCG_TARGET_REG_BITS == 32
166 /* Create a 64 bit value from two 32 bit values. */
167 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
169 return ((uint64_t)high
<< 32) + low
;
173 /* Read constant (native size) from bytecode. */
174 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
176 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
177 *tb_ptr
+= sizeof(value
);
181 /* Read unsigned constant (32 bit) from bytecode. */
182 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
184 uint32_t value
= *(uint32_t *)(*tb_ptr
);
185 *tb_ptr
+= sizeof(value
);
189 /* Read signed constant (32 bit) from bytecode. */
190 static int32_t tci_read_s32(uint8_t **tb_ptr
)
192 int32_t value
= *(int32_t *)(*tb_ptr
);
193 *tb_ptr
+= sizeof(value
);
197 #if TCG_TARGET_REG_BITS == 64
198 /* Read constant (64 bit) from bytecode. */
199 static uint64_t tci_read_i64(uint8_t **tb_ptr
)
201 uint64_t value
= *(uint64_t *)(*tb_ptr
);
202 *tb_ptr
+= sizeof(value
);
207 /* Read indexed register (native size) from bytecode. */
208 static tcg_target_ulong
tci_read_r(uint8_t **tb_ptr
)
210 tcg_target_ulong value
= tci_read_reg(**tb_ptr
);
215 /* Read indexed register (8 bit) from bytecode. */
216 static uint8_t tci_read_r8(uint8_t **tb_ptr
)
218 uint8_t value
= tci_read_reg8(**tb_ptr
);
223 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
224 /* Read indexed register (8 bit signed) from bytecode. */
225 static int8_t tci_read_r8s(uint8_t **tb_ptr
)
227 int8_t value
= tci_read_reg8s(**tb_ptr
);
233 /* Read indexed register (16 bit) from bytecode. */
234 static uint16_t tci_read_r16(uint8_t **tb_ptr
)
236 uint16_t value
= tci_read_reg16(**tb_ptr
);
241 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
242 /* Read indexed register (16 bit signed) from bytecode. */
243 static int16_t tci_read_r16s(uint8_t **tb_ptr
)
245 int16_t value
= tci_read_reg16s(**tb_ptr
);
251 /* Read indexed register (32 bit) from bytecode. */
252 static uint32_t tci_read_r32(uint8_t **tb_ptr
)
254 uint32_t value
= tci_read_reg32(**tb_ptr
);
259 #if TCG_TARGET_REG_BITS == 32
260 /* Read two indexed registers (2 * 32 bit) from bytecode. */
261 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
263 uint32_t low
= tci_read_r32(tb_ptr
);
264 return tci_uint64(tci_read_r32(tb_ptr
), low
);
266 #elif TCG_TARGET_REG_BITS == 64
267 /* Read indexed register (32 bit signed) from bytecode. */
268 static int32_t tci_read_r32s(uint8_t **tb_ptr
)
270 int32_t value
= tci_read_reg32s(**tb_ptr
);
275 /* Read indexed register (64 bit) from bytecode. */
276 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
278 uint64_t value
= tci_read_reg64(**tb_ptr
);
284 /* Read indexed register(s) with target address from bytecode. */
285 static target_ulong
tci_read_ulong(uint8_t **tb_ptr
)
287 target_ulong taddr
= tci_read_r(tb_ptr
);
288 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
289 taddr
+= (uint64_t)tci_read_r(tb_ptr
) << 32;
294 /* Read indexed register or constant (native size) from bytecode. */
295 static tcg_target_ulong
tci_read_ri(uint8_t **tb_ptr
)
297 tcg_target_ulong value
;
300 if (r
== TCG_CONST
) {
301 value
= tci_read_i(tb_ptr
);
303 value
= tci_read_reg(r
);
308 /* Read indexed register or constant (32 bit) from bytecode. */
309 static uint32_t tci_read_ri32(uint8_t **tb_ptr
)
314 if (r
== TCG_CONST
) {
315 value
= tci_read_i32(tb_ptr
);
317 value
= tci_read_reg32(r
);
322 #if TCG_TARGET_REG_BITS == 32
323 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
324 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
326 uint32_t low
= tci_read_ri32(tb_ptr
);
327 return tci_uint64(tci_read_ri32(tb_ptr
), low
);
329 #elif TCG_TARGET_REG_BITS == 64
330 /* Read indexed register or constant (64 bit) from bytecode. */
331 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
336 if (r
== TCG_CONST
) {
337 value
= tci_read_i64(tb_ptr
);
339 value
= tci_read_reg64(r
);
345 static tcg_target_ulong
tci_read_label(uint8_t **tb_ptr
)
347 tcg_target_ulong label
= tci_read_i(tb_ptr
);
352 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
394 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
436 /* Interpret pseudo code in tb. */
437 uintptr_t tcg_qemu_tb_exec(CPUArchState
*env
, uint8_t *tb_ptr
)
439 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
440 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
441 uintptr_t next_tb
= 0;
443 tci_reg
[TCG_AREG0
] = (tcg_target_ulong
)env
;
444 tci_reg
[TCG_REG_CALL_STACK
] = sp_value
;
448 TCGOpcode opc
= tb_ptr
[0];
450 uint8_t op_size
= tb_ptr
[1];
451 uint8_t *old_code_ptr
= tb_ptr
;
456 tcg_target_ulong label
;
459 #ifndef CONFIG_SOFTMMU
460 tcg_target_ulong host_addr
;
466 #if TCG_TARGET_REG_BITS == 32
471 tci_tb_ptr
= (uintptr_t)tb_ptr
;
474 /* Skip opcode and size entry. */
485 case INDEX_op_discard
:
488 case INDEX_op_set_label
:
492 t0
= tci_read_ri(&tb_ptr
);
493 #if TCG_TARGET_REG_BITS == 32
494 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
495 tci_read_reg(TCG_REG_R1
),
496 tci_read_reg(TCG_REG_R2
),
497 tci_read_reg(TCG_REG_R3
),
498 tci_read_reg(TCG_REG_R5
),
499 tci_read_reg(TCG_REG_R6
),
500 tci_read_reg(TCG_REG_R7
),
501 tci_read_reg(TCG_REG_R8
),
502 tci_read_reg(TCG_REG_R9
),
503 tci_read_reg(TCG_REG_R10
));
504 tci_write_reg(TCG_REG_R0
, tmp64
);
505 tci_write_reg(TCG_REG_R1
, tmp64
>> 32);
507 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
508 tci_read_reg(TCG_REG_R1
),
509 tci_read_reg(TCG_REG_R2
),
510 tci_read_reg(TCG_REG_R3
),
511 tci_read_reg(TCG_REG_R5
));
512 tci_write_reg(TCG_REG_R0
, tmp64
);
516 label
= tci_read_label(&tb_ptr
);
517 assert(tb_ptr
== old_code_ptr
+ op_size
);
518 tb_ptr
= (uint8_t *)label
;
520 case INDEX_op_setcond_i32
:
522 t1
= tci_read_r32(&tb_ptr
);
523 t2
= tci_read_ri32(&tb_ptr
);
524 condition
= *tb_ptr
++;
525 tci_write_reg32(t0
, tci_compare32(t1
, t2
, condition
));
527 #if TCG_TARGET_REG_BITS == 32
528 case INDEX_op_setcond2_i32
:
530 tmp64
= tci_read_r64(&tb_ptr
);
531 v64
= tci_read_ri64(&tb_ptr
);
532 condition
= *tb_ptr
++;
533 tci_write_reg32(t0
, tci_compare64(tmp64
, v64
, condition
));
535 #elif TCG_TARGET_REG_BITS == 64
536 case INDEX_op_setcond_i64
:
538 t1
= tci_read_r64(&tb_ptr
);
539 t2
= tci_read_ri64(&tb_ptr
);
540 condition
= *tb_ptr
++;
541 tci_write_reg64(t0
, tci_compare64(t1
, t2
, condition
));
544 case INDEX_op_mov_i32
:
546 t1
= tci_read_r32(&tb_ptr
);
547 tci_write_reg32(t0
, t1
);
549 case INDEX_op_movi_i32
:
551 t1
= tci_read_i32(&tb_ptr
);
552 tci_write_reg32(t0
, t1
);
555 /* Load/store operations (32 bit). */
557 case INDEX_op_ld8u_i32
:
559 t1
= tci_read_r(&tb_ptr
);
560 t2
= tci_read_s32(&tb_ptr
);
561 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
563 case INDEX_op_ld8s_i32
:
564 case INDEX_op_ld16u_i32
:
567 case INDEX_op_ld16s_i32
:
570 case INDEX_op_ld_i32
:
572 t1
= tci_read_r(&tb_ptr
);
573 t2
= tci_read_s32(&tb_ptr
);
574 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
576 case INDEX_op_st8_i32
:
577 t0
= tci_read_r8(&tb_ptr
);
578 t1
= tci_read_r(&tb_ptr
);
579 t2
= tci_read_s32(&tb_ptr
);
580 *(uint8_t *)(t1
+ t2
) = t0
;
582 case INDEX_op_st16_i32
:
583 t0
= tci_read_r16(&tb_ptr
);
584 t1
= tci_read_r(&tb_ptr
);
585 t2
= tci_read_s32(&tb_ptr
);
586 *(uint16_t *)(t1
+ t2
) = t0
;
588 case INDEX_op_st_i32
:
589 t0
= tci_read_r32(&tb_ptr
);
590 t1
= tci_read_r(&tb_ptr
);
591 t2
= tci_read_s32(&tb_ptr
);
592 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
593 *(uint32_t *)(t1
+ t2
) = t0
;
596 /* Arithmetic operations (32 bit). */
598 case INDEX_op_add_i32
:
600 t1
= tci_read_ri32(&tb_ptr
);
601 t2
= tci_read_ri32(&tb_ptr
);
602 tci_write_reg32(t0
, t1
+ t2
);
604 case INDEX_op_sub_i32
:
606 t1
= tci_read_ri32(&tb_ptr
);
607 t2
= tci_read_ri32(&tb_ptr
);
608 tci_write_reg32(t0
, t1
- t2
);
610 case INDEX_op_mul_i32
:
612 t1
= tci_read_ri32(&tb_ptr
);
613 t2
= tci_read_ri32(&tb_ptr
);
614 tci_write_reg32(t0
, t1
* t2
);
616 #if TCG_TARGET_HAS_div_i32
617 case INDEX_op_div_i32
:
619 t1
= tci_read_ri32(&tb_ptr
);
620 t2
= tci_read_ri32(&tb_ptr
);
621 tci_write_reg32(t0
, (int32_t)t1
/ (int32_t)t2
);
623 case INDEX_op_divu_i32
:
625 t1
= tci_read_ri32(&tb_ptr
);
626 t2
= tci_read_ri32(&tb_ptr
);
627 tci_write_reg32(t0
, t1
/ t2
);
629 case INDEX_op_rem_i32
:
631 t1
= tci_read_ri32(&tb_ptr
);
632 t2
= tci_read_ri32(&tb_ptr
);
633 tci_write_reg32(t0
, (int32_t)t1
% (int32_t)t2
);
635 case INDEX_op_remu_i32
:
637 t1
= tci_read_ri32(&tb_ptr
);
638 t2
= tci_read_ri32(&tb_ptr
);
639 tci_write_reg32(t0
, t1
% t2
);
641 #elif TCG_TARGET_HAS_div2_i32
642 case INDEX_op_div2_i32
:
643 case INDEX_op_divu2_i32
:
647 case INDEX_op_and_i32
:
649 t1
= tci_read_ri32(&tb_ptr
);
650 t2
= tci_read_ri32(&tb_ptr
);
651 tci_write_reg32(t0
, t1
& t2
);
653 case INDEX_op_or_i32
:
655 t1
= tci_read_ri32(&tb_ptr
);
656 t2
= tci_read_ri32(&tb_ptr
);
657 tci_write_reg32(t0
, t1
| t2
);
659 case INDEX_op_xor_i32
:
661 t1
= tci_read_ri32(&tb_ptr
);
662 t2
= tci_read_ri32(&tb_ptr
);
663 tci_write_reg32(t0
, t1
^ t2
);
666 /* Shift/rotate operations (32 bit). */
668 case INDEX_op_shl_i32
:
670 t1
= tci_read_ri32(&tb_ptr
);
671 t2
= tci_read_ri32(&tb_ptr
);
672 tci_write_reg32(t0
, t1
<< (t2
& 31));
674 case INDEX_op_shr_i32
:
676 t1
= tci_read_ri32(&tb_ptr
);
677 t2
= tci_read_ri32(&tb_ptr
);
678 tci_write_reg32(t0
, t1
>> (t2
& 31));
680 case INDEX_op_sar_i32
:
682 t1
= tci_read_ri32(&tb_ptr
);
683 t2
= tci_read_ri32(&tb_ptr
);
684 tci_write_reg32(t0
, ((int32_t)t1
>> (t2
& 31)));
686 #if TCG_TARGET_HAS_rot_i32
687 case INDEX_op_rotl_i32
:
689 t1
= tci_read_ri32(&tb_ptr
);
690 t2
= tci_read_ri32(&tb_ptr
);
691 tci_write_reg32(t0
, rol32(t1
, t2
& 31));
693 case INDEX_op_rotr_i32
:
695 t1
= tci_read_ri32(&tb_ptr
);
696 t2
= tci_read_ri32(&tb_ptr
);
697 tci_write_reg32(t0
, ror32(t1
, t2
& 31));
700 #if TCG_TARGET_HAS_deposit_i32
701 case INDEX_op_deposit_i32
:
703 t1
= tci_read_r32(&tb_ptr
);
704 t2
= tci_read_r32(&tb_ptr
);
707 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
708 tci_write_reg32(t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
711 case INDEX_op_brcond_i32
:
712 t0
= tci_read_r32(&tb_ptr
);
713 t1
= tci_read_ri32(&tb_ptr
);
714 condition
= *tb_ptr
++;
715 label
= tci_read_label(&tb_ptr
);
716 if (tci_compare32(t0
, t1
, condition
)) {
717 assert(tb_ptr
== old_code_ptr
+ op_size
);
718 tb_ptr
= (uint8_t *)label
;
722 #if TCG_TARGET_REG_BITS == 32
723 case INDEX_op_add2_i32
:
726 tmp64
= tci_read_r64(&tb_ptr
);
727 tmp64
+= tci_read_r64(&tb_ptr
);
728 tci_write_reg64(t1
, t0
, tmp64
);
730 case INDEX_op_sub2_i32
:
733 tmp64
= tci_read_r64(&tb_ptr
);
734 tmp64
-= tci_read_r64(&tb_ptr
);
735 tci_write_reg64(t1
, t0
, tmp64
);
737 case INDEX_op_brcond2_i32
:
738 tmp64
= tci_read_r64(&tb_ptr
);
739 v64
= tci_read_ri64(&tb_ptr
);
740 condition
= *tb_ptr
++;
741 label
= tci_read_label(&tb_ptr
);
742 if (tci_compare64(tmp64
, v64
, condition
)) {
743 assert(tb_ptr
== old_code_ptr
+ op_size
);
744 tb_ptr
= (uint8_t *)label
;
748 case INDEX_op_mulu2_i32
:
751 t2
= tci_read_r32(&tb_ptr
);
752 tmp64
= tci_read_r32(&tb_ptr
);
753 tci_write_reg64(t1
, t0
, t2
* tmp64
);
755 #endif /* TCG_TARGET_REG_BITS == 32 */
756 #if TCG_TARGET_HAS_ext8s_i32
757 case INDEX_op_ext8s_i32
:
759 t1
= tci_read_r8s(&tb_ptr
);
760 tci_write_reg32(t0
, t1
);
763 #if TCG_TARGET_HAS_ext16s_i32
764 case INDEX_op_ext16s_i32
:
766 t1
= tci_read_r16s(&tb_ptr
);
767 tci_write_reg32(t0
, t1
);
770 #if TCG_TARGET_HAS_ext8u_i32
771 case INDEX_op_ext8u_i32
:
773 t1
= tci_read_r8(&tb_ptr
);
774 tci_write_reg32(t0
, t1
);
777 #if TCG_TARGET_HAS_ext16u_i32
778 case INDEX_op_ext16u_i32
:
780 t1
= tci_read_r16(&tb_ptr
);
781 tci_write_reg32(t0
, t1
);
784 #if TCG_TARGET_HAS_bswap16_i32
785 case INDEX_op_bswap16_i32
:
787 t1
= tci_read_r16(&tb_ptr
);
788 tci_write_reg32(t0
, bswap16(t1
));
791 #if TCG_TARGET_HAS_bswap32_i32
792 case INDEX_op_bswap32_i32
:
794 t1
= tci_read_r32(&tb_ptr
);
795 tci_write_reg32(t0
, bswap32(t1
));
798 #if TCG_TARGET_HAS_not_i32
799 case INDEX_op_not_i32
:
801 t1
= tci_read_r32(&tb_ptr
);
802 tci_write_reg32(t0
, ~t1
);
805 #if TCG_TARGET_HAS_neg_i32
806 case INDEX_op_neg_i32
:
808 t1
= tci_read_r32(&tb_ptr
);
809 tci_write_reg32(t0
, -t1
);
812 #if TCG_TARGET_REG_BITS == 64
813 case INDEX_op_mov_i64
:
815 t1
= tci_read_r64(&tb_ptr
);
816 tci_write_reg64(t0
, t1
);
818 case INDEX_op_movi_i64
:
820 t1
= tci_read_i64(&tb_ptr
);
821 tci_write_reg64(t0
, t1
);
824 /* Load/store operations (64 bit). */
826 case INDEX_op_ld8u_i64
:
828 t1
= tci_read_r(&tb_ptr
);
829 t2
= tci_read_s32(&tb_ptr
);
830 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
832 case INDEX_op_ld8s_i64
:
833 case INDEX_op_ld16u_i64
:
834 case INDEX_op_ld16s_i64
:
837 case INDEX_op_ld32u_i64
:
839 t1
= tci_read_r(&tb_ptr
);
840 t2
= tci_read_s32(&tb_ptr
);
841 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
843 case INDEX_op_ld32s_i64
:
845 t1
= tci_read_r(&tb_ptr
);
846 t2
= tci_read_s32(&tb_ptr
);
847 tci_write_reg32s(t0
, *(int32_t *)(t1
+ t2
));
849 case INDEX_op_ld_i64
:
851 t1
= tci_read_r(&tb_ptr
);
852 t2
= tci_read_s32(&tb_ptr
);
853 tci_write_reg64(t0
, *(uint64_t *)(t1
+ t2
));
855 case INDEX_op_st8_i64
:
856 t0
= tci_read_r8(&tb_ptr
);
857 t1
= tci_read_r(&tb_ptr
);
858 t2
= tci_read_s32(&tb_ptr
);
859 *(uint8_t *)(t1
+ t2
) = t0
;
861 case INDEX_op_st16_i64
:
862 t0
= tci_read_r16(&tb_ptr
);
863 t1
= tci_read_r(&tb_ptr
);
864 t2
= tci_read_s32(&tb_ptr
);
865 *(uint16_t *)(t1
+ t2
) = t0
;
867 case INDEX_op_st32_i64
:
868 t0
= tci_read_r32(&tb_ptr
);
869 t1
= tci_read_r(&tb_ptr
);
870 t2
= tci_read_s32(&tb_ptr
);
871 *(uint32_t *)(t1
+ t2
) = t0
;
873 case INDEX_op_st_i64
:
874 t0
= tci_read_r64(&tb_ptr
);
875 t1
= tci_read_r(&tb_ptr
);
876 t2
= tci_read_s32(&tb_ptr
);
877 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
878 *(uint64_t *)(t1
+ t2
) = t0
;
881 /* Arithmetic operations (64 bit). */
883 case INDEX_op_add_i64
:
885 t1
= tci_read_ri64(&tb_ptr
);
886 t2
= tci_read_ri64(&tb_ptr
);
887 tci_write_reg64(t0
, t1
+ t2
);
889 case INDEX_op_sub_i64
:
891 t1
= tci_read_ri64(&tb_ptr
);
892 t2
= tci_read_ri64(&tb_ptr
);
893 tci_write_reg64(t0
, t1
- t2
);
895 case INDEX_op_mul_i64
:
897 t1
= tci_read_ri64(&tb_ptr
);
898 t2
= tci_read_ri64(&tb_ptr
);
899 tci_write_reg64(t0
, t1
* t2
);
901 #if TCG_TARGET_HAS_div_i64
902 case INDEX_op_div_i64
:
903 case INDEX_op_divu_i64
:
904 case INDEX_op_rem_i64
:
905 case INDEX_op_remu_i64
:
908 #elif TCG_TARGET_HAS_div2_i64
909 case INDEX_op_div2_i64
:
910 case INDEX_op_divu2_i64
:
914 case INDEX_op_and_i64
:
916 t1
= tci_read_ri64(&tb_ptr
);
917 t2
= tci_read_ri64(&tb_ptr
);
918 tci_write_reg64(t0
, t1
& t2
);
920 case INDEX_op_or_i64
:
922 t1
= tci_read_ri64(&tb_ptr
);
923 t2
= tci_read_ri64(&tb_ptr
);
924 tci_write_reg64(t0
, t1
| t2
);
926 case INDEX_op_xor_i64
:
928 t1
= tci_read_ri64(&tb_ptr
);
929 t2
= tci_read_ri64(&tb_ptr
);
930 tci_write_reg64(t0
, t1
^ t2
);
933 /* Shift/rotate operations (64 bit). */
935 case INDEX_op_shl_i64
:
937 t1
= tci_read_ri64(&tb_ptr
);
938 t2
= tci_read_ri64(&tb_ptr
);
939 tci_write_reg64(t0
, t1
<< (t2
& 63));
941 case INDEX_op_shr_i64
:
943 t1
= tci_read_ri64(&tb_ptr
);
944 t2
= tci_read_ri64(&tb_ptr
);
945 tci_write_reg64(t0
, t1
>> (t2
& 63));
947 case INDEX_op_sar_i64
:
949 t1
= tci_read_ri64(&tb_ptr
);
950 t2
= tci_read_ri64(&tb_ptr
);
951 tci_write_reg64(t0
, ((int64_t)t1
>> (t2
& 63)));
953 #if TCG_TARGET_HAS_rot_i64
954 case INDEX_op_rotl_i64
:
956 t1
= tci_read_ri64(&tb_ptr
);
957 t2
= tci_read_ri64(&tb_ptr
);
958 tci_write_reg64(t0
, rol64(t1
, t2
& 63));
960 case INDEX_op_rotr_i64
:
962 t1
= tci_read_ri64(&tb_ptr
);
963 t2
= tci_read_ri64(&tb_ptr
);
964 tci_write_reg64(t0
, ror64(t1
, t2
& 63));
967 #if TCG_TARGET_HAS_deposit_i64
968 case INDEX_op_deposit_i64
:
970 t1
= tci_read_r64(&tb_ptr
);
971 t2
= tci_read_r64(&tb_ptr
);
974 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
975 tci_write_reg64(t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
978 case INDEX_op_brcond_i64
:
979 t0
= tci_read_r64(&tb_ptr
);
980 t1
= tci_read_ri64(&tb_ptr
);
981 condition
= *tb_ptr
++;
982 label
= tci_read_label(&tb_ptr
);
983 if (tci_compare64(t0
, t1
, condition
)) {
984 assert(tb_ptr
== old_code_ptr
+ op_size
);
985 tb_ptr
= (uint8_t *)label
;
989 #if TCG_TARGET_HAS_ext8u_i64
990 case INDEX_op_ext8u_i64
:
992 t1
= tci_read_r8(&tb_ptr
);
993 tci_write_reg64(t0
, t1
);
996 #if TCG_TARGET_HAS_ext8s_i64
997 case INDEX_op_ext8s_i64
:
999 t1
= tci_read_r8s(&tb_ptr
);
1000 tci_write_reg64(t0
, t1
);
1003 #if TCG_TARGET_HAS_ext16s_i64
1004 case INDEX_op_ext16s_i64
:
1006 t1
= tci_read_r16s(&tb_ptr
);
1007 tci_write_reg64(t0
, t1
);
1010 #if TCG_TARGET_HAS_ext16u_i64
1011 case INDEX_op_ext16u_i64
:
1013 t1
= tci_read_r16(&tb_ptr
);
1014 tci_write_reg64(t0
, t1
);
1017 #if TCG_TARGET_HAS_ext32s_i64
1018 case INDEX_op_ext32s_i64
:
1020 t1
= tci_read_r32s(&tb_ptr
);
1021 tci_write_reg64(t0
, t1
);
1024 #if TCG_TARGET_HAS_ext32u_i64
1025 case INDEX_op_ext32u_i64
:
1027 t1
= tci_read_r32(&tb_ptr
);
1028 tci_write_reg64(t0
, t1
);
1031 #if TCG_TARGET_HAS_bswap16_i64
1032 case INDEX_op_bswap16_i64
:
1035 t1
= tci_read_r16(&tb_ptr
);
1036 tci_write_reg64(t0
, bswap16(t1
));
1039 #if TCG_TARGET_HAS_bswap32_i64
1040 case INDEX_op_bswap32_i64
:
1042 t1
= tci_read_r32(&tb_ptr
);
1043 tci_write_reg64(t0
, bswap32(t1
));
1046 #if TCG_TARGET_HAS_bswap64_i64
1047 case INDEX_op_bswap64_i64
:
1049 t1
= tci_read_r64(&tb_ptr
);
1050 tci_write_reg64(t0
, bswap64(t1
));
1053 #if TCG_TARGET_HAS_not_i64
1054 case INDEX_op_not_i64
:
1056 t1
= tci_read_r64(&tb_ptr
);
1057 tci_write_reg64(t0
, ~t1
);
1060 #if TCG_TARGET_HAS_neg_i64
1061 case INDEX_op_neg_i64
:
1063 t1
= tci_read_r64(&tb_ptr
);
1064 tci_write_reg64(t0
, -t1
);
1067 #endif /* TCG_TARGET_REG_BITS == 64 */
1069 /* QEMU specific operations. */
1071 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1072 case INDEX_op_debug_insn_start
:
1076 case INDEX_op_debug_insn_start
:
1080 case INDEX_op_exit_tb
:
1081 next_tb
= *(uint64_t *)tb_ptr
;
1084 case INDEX_op_goto_tb
:
1085 t0
= tci_read_i32(&tb_ptr
);
1086 assert(tb_ptr
== old_code_ptr
+ op_size
);
1087 tb_ptr
+= (int32_t)t0
;
1089 case INDEX_op_qemu_ld8u
:
1091 taddr
= tci_read_ulong(&tb_ptr
);
1092 #ifdef CONFIG_SOFTMMU
1093 tmp8
= helper_ldb_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1095 host_addr
= (tcg_target_ulong
)taddr
;
1096 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1098 tci_write_reg8(t0
, tmp8
);
1100 case INDEX_op_qemu_ld8s
:
1102 taddr
= tci_read_ulong(&tb_ptr
);
1103 #ifdef CONFIG_SOFTMMU
1104 tmp8
= helper_ldb_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1106 host_addr
= (tcg_target_ulong
)taddr
;
1107 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1109 tci_write_reg8s(t0
, tmp8
);
1111 case INDEX_op_qemu_ld16u
:
1113 taddr
= tci_read_ulong(&tb_ptr
);
1114 #ifdef CONFIG_SOFTMMU
1115 tmp16
= helper_ldw_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1117 host_addr
= (tcg_target_ulong
)taddr
;
1118 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1120 tci_write_reg16(t0
, tmp16
);
1122 case INDEX_op_qemu_ld16s
:
1124 taddr
= tci_read_ulong(&tb_ptr
);
1125 #ifdef CONFIG_SOFTMMU
1126 tmp16
= helper_ldw_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1128 host_addr
= (tcg_target_ulong
)taddr
;
1129 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1131 tci_write_reg16s(t0
, tmp16
);
1133 #if TCG_TARGET_REG_BITS == 64
1134 case INDEX_op_qemu_ld32u
:
1136 taddr
= tci_read_ulong(&tb_ptr
);
1137 #ifdef CONFIG_SOFTMMU
1138 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1140 host_addr
= (tcg_target_ulong
)taddr
;
1141 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1143 tci_write_reg32(t0
, tmp32
);
1145 case INDEX_op_qemu_ld32s
:
1147 taddr
= tci_read_ulong(&tb_ptr
);
1148 #ifdef CONFIG_SOFTMMU
1149 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1151 host_addr
= (tcg_target_ulong
)taddr
;
1152 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1154 tci_write_reg32s(t0
, tmp32
);
1156 #endif /* TCG_TARGET_REG_BITS == 64 */
1157 case INDEX_op_qemu_ld32
:
1159 taddr
= tci_read_ulong(&tb_ptr
);
1160 #ifdef CONFIG_SOFTMMU
1161 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1163 host_addr
= (tcg_target_ulong
)taddr
;
1164 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1166 tci_write_reg32(t0
, tmp32
);
1168 case INDEX_op_qemu_ld64
:
1170 #if TCG_TARGET_REG_BITS == 32
1173 taddr
= tci_read_ulong(&tb_ptr
);
1174 #ifdef CONFIG_SOFTMMU
1175 tmp64
= helper_ldq_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1177 host_addr
= (tcg_target_ulong
)taddr
;
1178 tmp64
= tswap64(*(uint64_t *)(host_addr
+ GUEST_BASE
));
1180 tci_write_reg(t0
, tmp64
);
1181 #if TCG_TARGET_REG_BITS == 32
1182 tci_write_reg(t1
, tmp64
>> 32);
1185 case INDEX_op_qemu_st8
:
1186 t0
= tci_read_r8(&tb_ptr
);
1187 taddr
= tci_read_ulong(&tb_ptr
);
1188 #ifdef CONFIG_SOFTMMU
1189 t2
= tci_read_i(&tb_ptr
);
1190 helper_stb_mmu(env
, taddr
, t0
, t2
);
1192 host_addr
= (tcg_target_ulong
)taddr
;
1193 *(uint8_t *)(host_addr
+ GUEST_BASE
) = t0
;
1196 case INDEX_op_qemu_st16
:
1197 t0
= tci_read_r16(&tb_ptr
);
1198 taddr
= tci_read_ulong(&tb_ptr
);
1199 #ifdef CONFIG_SOFTMMU
1200 t2
= tci_read_i(&tb_ptr
);
1201 helper_stw_mmu(env
, taddr
, t0
, t2
);
1203 host_addr
= (tcg_target_ulong
)taddr
;
1204 *(uint16_t *)(host_addr
+ GUEST_BASE
) = tswap16(t0
);
1207 case INDEX_op_qemu_st32
:
1208 t0
= tci_read_r32(&tb_ptr
);
1209 taddr
= tci_read_ulong(&tb_ptr
);
1210 #ifdef CONFIG_SOFTMMU
1211 t2
= tci_read_i(&tb_ptr
);
1212 helper_stl_mmu(env
, taddr
, t0
, t2
);
1214 host_addr
= (tcg_target_ulong
)taddr
;
1215 *(uint32_t *)(host_addr
+ GUEST_BASE
) = tswap32(t0
);
1218 case INDEX_op_qemu_st64
:
1219 tmp64
= tci_read_r64(&tb_ptr
);
1220 taddr
= tci_read_ulong(&tb_ptr
);
1221 #ifdef CONFIG_SOFTMMU
1222 t2
= tci_read_i(&tb_ptr
);
1223 helper_stq_mmu(env
, taddr
, tmp64
, t2
);
1225 host_addr
= (tcg_target_ulong
)taddr
;
1226 *(uint64_t *)(host_addr
+ GUEST_BASE
) = tswap64(tmp64
);
1233 assert(tb_ptr
== old_code_ptr
+ op_size
);