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-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 != 4
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);
48 typedef uint64_t (*helper_function)(tcg_target_ulong, tcg_target_ulong,
49 tcg_target_ulong, tcg_target_ulong);
52 /* TCI can optionally use a global register variable for env. */
57 /* Targets which don't use GETPC also don't need tci_tb_ptr
58 which makes them a little faster. */
63 static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS];
65 static tcg_target_ulong tci_read_reg(TCGReg index)
67 assert(index < ARRAY_SIZE(tci_reg));
68 return tci_reg[index];
71 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
72 static int8_t tci_read_reg8s(TCGReg index)
74 return (int8_t)tci_read_reg(index);
78 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
79 static int16_t tci_read_reg16s(TCGReg index)
81 return (int16_t)tci_read_reg(index);
85 #if TCG_TARGET_REG_BITS == 64
86 static int32_t tci_read_reg32s(TCGReg index)
88 return (int32_t)tci_read_reg(index);
92 static uint8_t tci_read_reg8(TCGReg index)
94 return (uint8_t)tci_read_reg(index);
97 static uint16_t tci_read_reg16(TCGReg index)
99 return (uint16_t)tci_read_reg(index);
102 static uint32_t tci_read_reg32(TCGReg index)
104 return (uint32_t)tci_read_reg(index);
107 #if TCG_TARGET_REG_BITS == 64
108 static uint64_t tci_read_reg64(TCGReg index)
110 return tci_read_reg(index);
114 static void tci_write_reg(TCGReg index, tcg_target_ulong value)
116 assert(index < ARRAY_SIZE(tci_reg));
117 assert(index != TCG_AREG0);
118 tci_reg[index] = value;
121 static void tci_write_reg8s(TCGReg index, int8_t value)
123 tci_write_reg(index, value);
126 static void tci_write_reg16s(TCGReg index, int16_t value)
128 tci_write_reg(index, value);
131 #if TCG_TARGET_REG_BITS == 64
132 static void tci_write_reg32s(TCGReg index, int32_t value)
134 tci_write_reg(index, value);
138 static void tci_write_reg8(TCGReg index, uint8_t value)
140 tci_write_reg(index, value);
143 static void tci_write_reg16(TCGReg index, uint16_t value)
145 tci_write_reg(index, value);
148 static void tci_write_reg32(TCGReg index, uint32_t value)
150 tci_write_reg(index, value);
153 #if TCG_TARGET_REG_BITS == 32
154 static void tci_write_reg64(uint32_t high_index, uint32_t low_index,
157 tci_write_reg(low_index, value);
158 tci_write_reg(high_index, value >> 32);
160 #elif TCG_TARGET_REG_BITS == 64
161 static void tci_write_reg64(TCGReg index, uint64_t value)
163 tci_write_reg(index, value);
167 #if TCG_TARGET_REG_BITS == 32
168 /* Create a 64 bit value from two 32 bit values. */
169 static uint64_t tci_uint64(uint32_t high, uint32_t low)
171 return ((uint64_t)high << 32) + low;
175 /* Read constant (native size) from bytecode. */
176 static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
178 tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr);
179 *tb_ptr += sizeof(value);
183 /* Read constant (32 bit) from bytecode. */
184 static uint32_t tci_read_i32(uint8_t **tb_ptr)
186 uint32_t value = *(uint32_t *)(*tb_ptr);
187 *tb_ptr += sizeof(value);
191 #if TCG_TARGET_REG_BITS == 64
192 /* Read constant (64 bit) from bytecode. */
193 static uint64_t tci_read_i64(uint8_t **tb_ptr)
195 uint64_t value = *(uint64_t *)(*tb_ptr);
196 *tb_ptr += sizeof(value);
201 /* Read indexed register (native size) from bytecode. */
202 static tcg_target_ulong tci_read_r(uint8_t **tb_ptr)
204 tcg_target_ulong value = tci_read_reg(**tb_ptr);
209 /* Read indexed register (8 bit) from bytecode. */
210 static uint8_t tci_read_r8(uint8_t **tb_ptr)
212 uint8_t value = tci_read_reg8(**tb_ptr);
217 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
218 /* Read indexed register (8 bit signed) from bytecode. */
219 static int8_t tci_read_r8s(uint8_t **tb_ptr)
221 int8_t value = tci_read_reg8s(**tb_ptr);
227 /* Read indexed register (16 bit) from bytecode. */
228 static uint16_t tci_read_r16(uint8_t **tb_ptr)
230 uint16_t value = tci_read_reg16(**tb_ptr);
235 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
236 /* Read indexed register (16 bit signed) from bytecode. */
237 static int16_t tci_read_r16s(uint8_t **tb_ptr)
239 int16_t value = tci_read_reg16s(**tb_ptr);
245 /* Read indexed register (32 bit) from bytecode. */
246 static uint32_t tci_read_r32(uint8_t **tb_ptr)
248 uint32_t value = tci_read_reg32(**tb_ptr);
253 #if TCG_TARGET_REG_BITS == 32
254 /* Read two indexed registers (2 * 32 bit) from bytecode. */
255 static uint64_t tci_read_r64(uint8_t **tb_ptr)
257 uint32_t low = tci_read_r32(tb_ptr);
258 return tci_uint64(tci_read_r32(tb_ptr), low);
260 #elif TCG_TARGET_REG_BITS == 64
261 /* Read indexed register (32 bit signed) from bytecode. */
262 static int32_t tci_read_r32s(uint8_t **tb_ptr)
264 int32_t value = tci_read_reg32s(**tb_ptr);
269 /* Read indexed register (64 bit) from bytecode. */
270 static uint64_t tci_read_r64(uint8_t **tb_ptr)
272 uint64_t value = tci_read_reg64(**tb_ptr);
278 /* Read indexed register(s) with target address from bytecode. */
279 static target_ulong tci_read_ulong(uint8_t **tb_ptr)
281 target_ulong taddr = tci_read_r(tb_ptr);
282 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
283 taddr += (uint64_t)tci_read_r(tb_ptr) << 32;
288 /* Read indexed register or constant (native size) from bytecode. */
289 static tcg_target_ulong tci_read_ri(uint8_t **tb_ptr)
291 tcg_target_ulong value;
294 if (r == TCG_CONST) {
295 value = tci_read_i(tb_ptr);
297 value = tci_read_reg(r);
302 /* Read indexed register or constant (32 bit) from bytecode. */
303 static uint32_t tci_read_ri32(uint8_t **tb_ptr)
308 if (r == TCG_CONST) {
309 value = tci_read_i32(tb_ptr);
311 value = tci_read_reg32(r);
316 #if TCG_TARGET_REG_BITS == 32
317 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
318 static uint64_t tci_read_ri64(uint8_t **tb_ptr)
320 uint32_t low = tci_read_ri32(tb_ptr);
321 return tci_uint64(tci_read_ri32(tb_ptr), low);
323 #elif TCG_TARGET_REG_BITS == 64
324 /* Read indexed register or constant (64 bit) from bytecode. */
325 static uint64_t tci_read_ri64(uint8_t **tb_ptr)
330 if (r == TCG_CONST) {
331 value = tci_read_i64(tb_ptr);
333 value = tci_read_reg64(r);
339 static target_ulong tci_read_label(uint8_t **tb_ptr)
341 target_ulong label = tci_read_i(tb_ptr);
346 static bool tci_compare32(uint32_t u0, uint32_t u1, TCGCond condition)
388 static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
430 /* Interpret pseudo code in tb. */
431 tcg_target_ulong tcg_qemu_tb_exec(CPUArchState *cpustate, uint8_t *tb_ptr)
433 tcg_target_ulong next_tb = 0;
436 tci_reg[TCG_AREG0] = (tcg_target_ulong)env;
441 tci_tb_ptr = (uintptr_t)tb_ptr;
443 TCGOpcode opc = tb_ptr[0];
445 uint8_t op_size = tb_ptr[1];
446 uint8_t *old_code_ptr = tb_ptr;
451 tcg_target_ulong label;
454 #ifndef CONFIG_SOFTMMU
455 tcg_target_ulong host_addr;
461 #if TCG_TARGET_REG_BITS == 32
465 /* Skip opcode and size entry. */
476 case INDEX_op_discard:
479 case INDEX_op_set_label:
483 t0 = tci_read_ri(&tb_ptr);
484 #if TCG_TARGET_REG_BITS == 32
485 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
486 tci_read_reg(TCG_REG_R1),
487 tci_read_reg(TCG_REG_R2),
488 tci_read_reg(TCG_REG_R3),
489 tci_read_reg(TCG_REG_R5),
490 tci_read_reg(TCG_REG_R6),
491 tci_read_reg(TCG_REG_R7),
492 tci_read_reg(TCG_REG_R8));
493 tci_write_reg(TCG_REG_R0, tmp64);
494 tci_write_reg(TCG_REG_R1, tmp64 >> 32);
496 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
497 tci_read_reg(TCG_REG_R1),
498 tci_read_reg(TCG_REG_R2),
499 tci_read_reg(TCG_REG_R3));
500 tci_write_reg(TCG_REG_R0, tmp64);
505 label = tci_read_label(&tb_ptr);
506 assert(tb_ptr == old_code_ptr + op_size);
507 tb_ptr = (uint8_t *)label;
509 case INDEX_op_setcond_i32:
511 t1 = tci_read_r32(&tb_ptr);
512 t2 = tci_read_ri32(&tb_ptr);
513 condition = *tb_ptr++;
514 tci_write_reg32(t0, tci_compare32(t1, t2, condition));
516 #if TCG_TARGET_REG_BITS == 32
517 case INDEX_op_setcond2_i32:
519 tmp64 = tci_read_r64(&tb_ptr);
520 v64 = tci_read_ri64(&tb_ptr);
521 condition = *tb_ptr++;
522 tci_write_reg32(t0, tci_compare64(tmp64, v64, condition));
524 #elif TCG_TARGET_REG_BITS == 64
525 case INDEX_op_setcond_i64:
527 t1 = tci_read_r64(&tb_ptr);
528 t2 = tci_read_ri64(&tb_ptr);
529 condition = *tb_ptr++;
530 tci_write_reg64(t0, tci_compare64(t1, t2, condition));
533 case INDEX_op_mov_i32:
535 t1 = tci_read_r32(&tb_ptr);
536 tci_write_reg32(t0, t1);
538 case INDEX_op_movi_i32:
540 t1 = tci_read_i32(&tb_ptr);
541 tci_write_reg32(t0, t1);
544 /* Load/store operations (32 bit). */
546 case INDEX_op_ld8u_i32:
548 t1 = tci_read_r(&tb_ptr);
549 t2 = tci_read_i32(&tb_ptr);
550 tci_write_reg8(t0, *(uint8_t *)(t1 + t2));
552 case INDEX_op_ld8s_i32:
553 case INDEX_op_ld16u_i32:
556 case INDEX_op_ld16s_i32:
559 case INDEX_op_ld_i32:
561 t1 = tci_read_r(&tb_ptr);
562 t2 = tci_read_i32(&tb_ptr);
563 tci_write_reg32(t0, *(uint32_t *)(t1 + t2));
565 case INDEX_op_st8_i32:
566 t0 = tci_read_r8(&tb_ptr);
567 t1 = tci_read_r(&tb_ptr);
568 t2 = tci_read_i32(&tb_ptr);
569 *(uint8_t *)(t1 + t2) = t0;
571 case INDEX_op_st16_i32:
572 t0 = tci_read_r16(&tb_ptr);
573 t1 = tci_read_r(&tb_ptr);
574 t2 = tci_read_i32(&tb_ptr);
575 *(uint16_t *)(t1 + t2) = t0;
577 case INDEX_op_st_i32:
578 t0 = tci_read_r32(&tb_ptr);
579 t1 = tci_read_r(&tb_ptr);
580 t2 = tci_read_i32(&tb_ptr);
581 *(uint32_t *)(t1 + t2) = t0;
584 /* Arithmetic operations (32 bit). */
586 case INDEX_op_add_i32:
588 t1 = tci_read_ri32(&tb_ptr);
589 t2 = tci_read_ri32(&tb_ptr);
590 tci_write_reg32(t0, t1 + t2);
592 case INDEX_op_sub_i32:
594 t1 = tci_read_ri32(&tb_ptr);
595 t2 = tci_read_ri32(&tb_ptr);
596 tci_write_reg32(t0, t1 - t2);
598 case INDEX_op_mul_i32:
600 t1 = tci_read_ri32(&tb_ptr);
601 t2 = tci_read_ri32(&tb_ptr);
602 tci_write_reg32(t0, t1 * t2);
604 #if TCG_TARGET_HAS_div_i32
605 case INDEX_op_div_i32:
607 t1 = tci_read_ri32(&tb_ptr);
608 t2 = tci_read_ri32(&tb_ptr);
609 tci_write_reg32(t0, (int32_t)t1 / (int32_t)t2);
611 case INDEX_op_divu_i32:
613 t1 = tci_read_ri32(&tb_ptr);
614 t2 = tci_read_ri32(&tb_ptr);
615 tci_write_reg32(t0, t1 / t2);
617 case INDEX_op_rem_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_remu_i32:
625 t1 = tci_read_ri32(&tb_ptr);
626 t2 = tci_read_ri32(&tb_ptr);
627 tci_write_reg32(t0, t1 % t2);
629 #elif TCG_TARGET_HAS_div2_i32
630 case INDEX_op_div2_i32:
631 case INDEX_op_divu2_i32:
635 case INDEX_op_and_i32:
637 t1 = tci_read_ri32(&tb_ptr);
638 t2 = tci_read_ri32(&tb_ptr);
639 tci_write_reg32(t0, t1 & t2);
641 case INDEX_op_or_i32:
643 t1 = tci_read_ri32(&tb_ptr);
644 t2 = tci_read_ri32(&tb_ptr);
645 tci_write_reg32(t0, t1 | t2);
647 case INDEX_op_xor_i32:
649 t1 = tci_read_ri32(&tb_ptr);
650 t2 = tci_read_ri32(&tb_ptr);
651 tci_write_reg32(t0, t1 ^ t2);
654 /* Shift/rotate operations (32 bit). */
656 case INDEX_op_shl_i32:
658 t1 = tci_read_ri32(&tb_ptr);
659 t2 = tci_read_ri32(&tb_ptr);
660 tci_write_reg32(t0, t1 << t2);
662 case INDEX_op_shr_i32:
664 t1 = tci_read_ri32(&tb_ptr);
665 t2 = tci_read_ri32(&tb_ptr);
666 tci_write_reg32(t0, t1 >> t2);
668 case INDEX_op_sar_i32:
670 t1 = tci_read_ri32(&tb_ptr);
671 t2 = tci_read_ri32(&tb_ptr);
672 tci_write_reg32(t0, ((int32_t)t1 >> t2));
674 #if TCG_TARGET_HAS_rot_i32
675 case INDEX_op_rotl_i32:
677 t1 = tci_read_ri32(&tb_ptr);
678 t2 = tci_read_ri32(&tb_ptr);
679 tci_write_reg32(t0, (t1 << t2) | (t1 >> (32 - t2)));
681 case INDEX_op_rotr_i32:
683 t1 = tci_read_ri32(&tb_ptr);
684 t2 = tci_read_ri32(&tb_ptr);
685 tci_write_reg32(t0, (t1 >> t2) | (t1 << (32 - t2)));
688 case INDEX_op_brcond_i32:
689 t0 = tci_read_r32(&tb_ptr);
690 t1 = tci_read_ri32(&tb_ptr);
691 condition = *tb_ptr++;
692 label = tci_read_label(&tb_ptr);
693 if (tci_compare32(t0, t1, condition)) {
694 assert(tb_ptr == old_code_ptr + op_size);
695 tb_ptr = (uint8_t *)label;
699 #if TCG_TARGET_REG_BITS == 32
700 case INDEX_op_add2_i32:
703 tmp64 = tci_read_r64(&tb_ptr);
704 tmp64 += tci_read_r64(&tb_ptr);
705 tci_write_reg64(t1, t0, tmp64);
707 case INDEX_op_sub2_i32:
710 tmp64 = tci_read_r64(&tb_ptr);
711 tmp64 -= tci_read_r64(&tb_ptr);
712 tci_write_reg64(t1, t0, tmp64);
714 case INDEX_op_brcond2_i32:
715 tmp64 = tci_read_r64(&tb_ptr);
716 v64 = tci_read_ri64(&tb_ptr);
717 condition = *tb_ptr++;
718 label = tci_read_label(&tb_ptr);
719 if (tci_compare64(tmp64, v64, condition)) {
720 assert(tb_ptr == old_code_ptr + op_size);
721 tb_ptr = (uint8_t *)label;
725 case INDEX_op_mulu2_i32:
728 t2 = tci_read_r32(&tb_ptr);
729 tmp64 = tci_read_r32(&tb_ptr);
730 tci_write_reg64(t1, t0, t2 * tmp64);
732 #endif /* TCG_TARGET_REG_BITS == 32 */
733 #if TCG_TARGET_HAS_ext8s_i32
734 case INDEX_op_ext8s_i32:
736 t1 = tci_read_r8s(&tb_ptr);
737 tci_write_reg32(t0, t1);
740 #if TCG_TARGET_HAS_ext16s_i32
741 case INDEX_op_ext16s_i32:
743 t1 = tci_read_r16s(&tb_ptr);
744 tci_write_reg32(t0, t1);
747 #if TCG_TARGET_HAS_ext8u_i32
748 case INDEX_op_ext8u_i32:
750 t1 = tci_read_r8(&tb_ptr);
751 tci_write_reg32(t0, t1);
754 #if TCG_TARGET_HAS_ext16u_i32
755 case INDEX_op_ext16u_i32:
757 t1 = tci_read_r16(&tb_ptr);
758 tci_write_reg32(t0, t1);
761 #if TCG_TARGET_HAS_bswap16_i32
762 case INDEX_op_bswap16_i32:
764 t1 = tci_read_r16(&tb_ptr);
765 tci_write_reg32(t0, bswap16(t1));
768 #if TCG_TARGET_HAS_bswap32_i32
769 case INDEX_op_bswap32_i32:
771 t1 = tci_read_r32(&tb_ptr);
772 tci_write_reg32(t0, bswap32(t1));
775 #if TCG_TARGET_HAS_not_i32
776 case INDEX_op_not_i32:
778 t1 = tci_read_r32(&tb_ptr);
779 tci_write_reg32(t0, ~t1);
782 #if TCG_TARGET_HAS_neg_i32
783 case INDEX_op_neg_i32:
785 t1 = tci_read_r32(&tb_ptr);
786 tci_write_reg32(t0, -t1);
789 #if TCG_TARGET_REG_BITS == 64
790 case INDEX_op_mov_i64:
792 t1 = tci_read_r64(&tb_ptr);
793 tci_write_reg64(t0, t1);
795 case INDEX_op_movi_i64:
797 t1 = tci_read_i64(&tb_ptr);
798 tci_write_reg64(t0, t1);
801 /* Load/store operations (64 bit). */
803 case INDEX_op_ld8u_i64:
805 t1 = tci_read_r(&tb_ptr);
806 t2 = tci_read_i32(&tb_ptr);
807 tci_write_reg8(t0, *(uint8_t *)(t1 + t2));
809 case INDEX_op_ld8s_i64:
810 case INDEX_op_ld16u_i64:
811 case INDEX_op_ld16s_i64:
814 case INDEX_op_ld32u_i64:
816 t1 = tci_read_r(&tb_ptr);
817 t2 = tci_read_i32(&tb_ptr);
818 tci_write_reg32(t0, *(uint32_t *)(t1 + t2));
820 case INDEX_op_ld32s_i64:
822 t1 = tci_read_r(&tb_ptr);
823 t2 = tci_read_i32(&tb_ptr);
824 tci_write_reg32s(t0, *(int32_t *)(t1 + t2));
826 case INDEX_op_ld_i64:
828 t1 = tci_read_r(&tb_ptr);
829 t2 = tci_read_i32(&tb_ptr);
830 tci_write_reg64(t0, *(uint64_t *)(t1 + t2));
832 case INDEX_op_st8_i64:
833 t0 = tci_read_r8(&tb_ptr);
834 t1 = tci_read_r(&tb_ptr);
835 t2 = tci_read_i32(&tb_ptr);
836 *(uint8_t *)(t1 + t2) = t0;
838 case INDEX_op_st16_i64:
839 t0 = tci_read_r16(&tb_ptr);
840 t1 = tci_read_r(&tb_ptr);
841 t2 = tci_read_i32(&tb_ptr);
842 *(uint16_t *)(t1 + t2) = t0;
844 case INDEX_op_st32_i64:
845 t0 = tci_read_r32(&tb_ptr);
846 t1 = tci_read_r(&tb_ptr);
847 t2 = tci_read_i32(&tb_ptr);
848 *(uint32_t *)(t1 + t2) = t0;
850 case INDEX_op_st_i64:
851 t0 = tci_read_r64(&tb_ptr);
852 t1 = tci_read_r(&tb_ptr);
853 t2 = tci_read_i32(&tb_ptr);
854 *(uint64_t *)(t1 + t2) = t0;
857 /* Arithmetic operations (64 bit). */
859 case INDEX_op_add_i64:
861 t1 = tci_read_ri64(&tb_ptr);
862 t2 = tci_read_ri64(&tb_ptr);
863 tci_write_reg64(t0, t1 + t2);
865 case INDEX_op_sub_i64:
867 t1 = tci_read_ri64(&tb_ptr);
868 t2 = tci_read_ri64(&tb_ptr);
869 tci_write_reg64(t0, t1 - t2);
871 case INDEX_op_mul_i64:
873 t1 = tci_read_ri64(&tb_ptr);
874 t2 = tci_read_ri64(&tb_ptr);
875 tci_write_reg64(t0, t1 * t2);
877 #if TCG_TARGET_HAS_div_i64
878 case INDEX_op_div_i64:
879 case INDEX_op_divu_i64:
880 case INDEX_op_rem_i64:
881 case INDEX_op_remu_i64:
884 #elif TCG_TARGET_HAS_div2_i64
885 case INDEX_op_div2_i64:
886 case INDEX_op_divu2_i64:
890 case INDEX_op_and_i64:
892 t1 = tci_read_ri64(&tb_ptr);
893 t2 = tci_read_ri64(&tb_ptr);
894 tci_write_reg64(t0, t1 & t2);
896 case INDEX_op_or_i64:
898 t1 = tci_read_ri64(&tb_ptr);
899 t2 = tci_read_ri64(&tb_ptr);
900 tci_write_reg64(t0, t1 | t2);
902 case INDEX_op_xor_i64:
904 t1 = tci_read_ri64(&tb_ptr);
905 t2 = tci_read_ri64(&tb_ptr);
906 tci_write_reg64(t0, t1 ^ t2);
909 /* Shift/rotate operations (64 bit). */
911 case INDEX_op_shl_i64:
913 t1 = tci_read_ri64(&tb_ptr);
914 t2 = tci_read_ri64(&tb_ptr);
915 tci_write_reg64(t0, t1 << t2);
917 case INDEX_op_shr_i64:
919 t1 = tci_read_ri64(&tb_ptr);
920 t2 = tci_read_ri64(&tb_ptr);
921 tci_write_reg64(t0, t1 >> t2);
923 case INDEX_op_sar_i64:
925 t1 = tci_read_ri64(&tb_ptr);
926 t2 = tci_read_ri64(&tb_ptr);
927 tci_write_reg64(t0, ((int64_t)t1 >> t2));
929 #if TCG_TARGET_HAS_rot_i64
930 case INDEX_op_rotl_i64:
931 case INDEX_op_rotr_i64:
935 case INDEX_op_brcond_i64:
936 t0 = tci_read_r64(&tb_ptr);
937 t1 = tci_read_ri64(&tb_ptr);
938 condition = *tb_ptr++;
939 label = tci_read_label(&tb_ptr);
940 if (tci_compare64(t0, t1, condition)) {
941 assert(tb_ptr == old_code_ptr + op_size);
942 tb_ptr = (uint8_t *)label;
946 #if TCG_TARGET_HAS_ext8u_i64
947 case INDEX_op_ext8u_i64:
949 t1 = tci_read_r8(&tb_ptr);
950 tci_write_reg64(t0, t1);
953 #if TCG_TARGET_HAS_ext8s_i64
954 case INDEX_op_ext8s_i64:
956 t1 = tci_read_r8s(&tb_ptr);
957 tci_write_reg64(t0, t1);
960 #if TCG_TARGET_HAS_ext16s_i64
961 case INDEX_op_ext16s_i64:
963 t1 = tci_read_r16s(&tb_ptr);
964 tci_write_reg64(t0, t1);
967 #if TCG_TARGET_HAS_ext16u_i64
968 case INDEX_op_ext16u_i64:
970 t1 = tci_read_r16(&tb_ptr);
971 tci_write_reg64(t0, t1);
974 #if TCG_TARGET_HAS_ext32s_i64
975 case INDEX_op_ext32s_i64:
977 t1 = tci_read_r32s(&tb_ptr);
978 tci_write_reg64(t0, t1);
981 #if TCG_TARGET_HAS_ext32u_i64
982 case INDEX_op_ext32u_i64:
984 t1 = tci_read_r32(&tb_ptr);
985 tci_write_reg64(t0, t1);
988 #if TCG_TARGET_HAS_bswap16_i64
989 case INDEX_op_bswap16_i64:
992 t1 = tci_read_r16(&tb_ptr);
993 tci_write_reg64(t0, bswap16(t1));
996 #if TCG_TARGET_HAS_bswap32_i64
997 case INDEX_op_bswap32_i64:
999 t1 = tci_read_r32(&tb_ptr);
1000 tci_write_reg64(t0, bswap32(t1));
1003 #if TCG_TARGET_HAS_bswap64_i64
1004 case INDEX_op_bswap64_i64:
1006 t1 = tci_read_r64(&tb_ptr);
1007 tci_write_reg64(t0, bswap64(t1));
1010 #if TCG_TARGET_HAS_not_i64
1011 case INDEX_op_not_i64:
1013 t1 = tci_read_r64(&tb_ptr);
1014 tci_write_reg64(t0, ~t1);
1017 #if TCG_TARGET_HAS_neg_i64
1018 case INDEX_op_neg_i64:
1020 t1 = tci_read_r64(&tb_ptr);
1021 tci_write_reg64(t0, -t1);
1024 #endif /* TCG_TARGET_REG_BITS == 64 */
1026 /* QEMU specific operations. */
1028 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1029 case INDEX_op_debug_insn_start:
1033 case INDEX_op_debug_insn_start:
1037 case INDEX_op_exit_tb:
1038 next_tb = *(uint64_t *)tb_ptr;
1041 case INDEX_op_goto_tb:
1042 t0 = tci_read_i32(&tb_ptr);
1043 assert(tb_ptr == old_code_ptr + op_size);
1044 tb_ptr += (int32_t)t0;
1046 case INDEX_op_qemu_ld8u:
1048 taddr = tci_read_ulong(&tb_ptr);
1049 #ifdef CONFIG_SOFTMMU
1050 tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr));
1052 host_addr = (tcg_target_ulong)taddr;
1053 assert(taddr == host_addr);
1054 tmp8 = *(uint8_t *)(host_addr + GUEST_BASE);
1056 tci_write_reg8(t0, tmp8);
1058 case INDEX_op_qemu_ld8s:
1060 taddr = tci_read_ulong(&tb_ptr);
1061 #ifdef CONFIG_SOFTMMU
1062 tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr));
1064 host_addr = (tcg_target_ulong)taddr;
1065 assert(taddr == host_addr);
1066 tmp8 = *(uint8_t *)(host_addr + GUEST_BASE);
1068 tci_write_reg8s(t0, tmp8);
1070 case INDEX_op_qemu_ld16u:
1072 taddr = tci_read_ulong(&tb_ptr);
1073 #ifdef CONFIG_SOFTMMU
1074 tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr));
1076 host_addr = (tcg_target_ulong)taddr;
1077 assert(taddr == host_addr);
1078 tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE));
1080 tci_write_reg16(t0, tmp16);
1082 case INDEX_op_qemu_ld16s:
1084 taddr = tci_read_ulong(&tb_ptr);
1085 #ifdef CONFIG_SOFTMMU
1086 tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr));
1088 host_addr = (tcg_target_ulong)taddr;
1089 assert(taddr == host_addr);
1090 tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE));
1092 tci_write_reg16s(t0, tmp16);
1094 #if TCG_TARGET_REG_BITS == 64
1095 case INDEX_op_qemu_ld32u:
1097 taddr = tci_read_ulong(&tb_ptr);
1098 #ifdef CONFIG_SOFTMMU
1099 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1101 host_addr = (tcg_target_ulong)taddr;
1102 assert(taddr == host_addr);
1103 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1105 tci_write_reg32(t0, tmp32);
1107 case INDEX_op_qemu_ld32s:
1109 taddr = tci_read_ulong(&tb_ptr);
1110 #ifdef CONFIG_SOFTMMU
1111 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1113 host_addr = (tcg_target_ulong)taddr;
1114 assert(taddr == host_addr);
1115 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1117 tci_write_reg32s(t0, tmp32);
1119 #endif /* TCG_TARGET_REG_BITS == 64 */
1120 case INDEX_op_qemu_ld32:
1122 taddr = tci_read_ulong(&tb_ptr);
1123 #ifdef CONFIG_SOFTMMU
1124 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1126 host_addr = (tcg_target_ulong)taddr;
1127 assert(taddr == host_addr);
1128 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1130 tci_write_reg32(t0, tmp32);
1132 case INDEX_op_qemu_ld64:
1134 #if TCG_TARGET_REG_BITS == 32
1137 taddr = tci_read_ulong(&tb_ptr);
1138 #ifdef CONFIG_SOFTMMU
1139 tmp64 = helper_ldq_mmu(env, taddr, tci_read_i(&tb_ptr));
1141 host_addr = (tcg_target_ulong)taddr;
1142 assert(taddr == host_addr);
1143 tmp64 = tswap64(*(uint64_t *)(host_addr + GUEST_BASE));
1145 tci_write_reg(t0, tmp64);
1146 #if TCG_TARGET_REG_BITS == 32
1147 tci_write_reg(t1, tmp64 >> 32);
1150 case INDEX_op_qemu_st8:
1151 t0 = tci_read_r8(&tb_ptr);
1152 taddr = tci_read_ulong(&tb_ptr);
1153 #ifdef CONFIG_SOFTMMU
1154 t2 = tci_read_i(&tb_ptr);
1155 helper_stb_mmu(env, taddr, t0, t2);
1157 host_addr = (tcg_target_ulong)taddr;
1158 assert(taddr == host_addr);
1159 *(uint8_t *)(host_addr + GUEST_BASE) = t0;
1162 case INDEX_op_qemu_st16:
1163 t0 = tci_read_r16(&tb_ptr);
1164 taddr = tci_read_ulong(&tb_ptr);
1165 #ifdef CONFIG_SOFTMMU
1166 t2 = tci_read_i(&tb_ptr);
1167 helper_stw_mmu(env, taddr, t0, t2);
1169 host_addr = (tcg_target_ulong)taddr;
1170 assert(taddr == host_addr);
1171 *(uint16_t *)(host_addr + GUEST_BASE) = tswap16(t0);
1174 case INDEX_op_qemu_st32:
1175 t0 = tci_read_r32(&tb_ptr);
1176 taddr = tci_read_ulong(&tb_ptr);
1177 #ifdef CONFIG_SOFTMMU
1178 t2 = tci_read_i(&tb_ptr);
1179 helper_stl_mmu(env, taddr, t0, t2);
1181 host_addr = (tcg_target_ulong)taddr;
1182 assert(taddr == host_addr);
1183 *(uint32_t *)(host_addr + GUEST_BASE) = tswap32(t0);
1186 case INDEX_op_qemu_st64:
1187 tmp64 = tci_read_r64(&tb_ptr);
1188 taddr = tci_read_ulong(&tb_ptr);
1189 #ifdef CONFIG_SOFTMMU
1190 t2 = tci_read_i(&tb_ptr);
1191 helper_stq_mmu(env, taddr, tmp64, t2);
1193 host_addr = (tcg_target_ulong)taddr;
1194 assert(taddr == host_addr);
1195 *(uint64_t *)(host_addr + GUEST_BASE) = tswap64(tmp64);
1202 assert(tb_ptr == old_code_ptr + op_size);