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 != 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 /* TCI can optionally use a global register variable for env. */
59 /* Targets which don't use GETPC also don't need tci_tb_ptr
60 which makes them a little faster. */
65 static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS];
67 static tcg_target_ulong tci_read_reg(TCGReg index)
69 assert(index < ARRAY_SIZE(tci_reg));
70 return tci_reg[index];
73 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
74 static int8_t tci_read_reg8s(TCGReg index)
76 return (int8_t)tci_read_reg(index);
80 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
81 static int16_t tci_read_reg16s(TCGReg index)
83 return (int16_t)tci_read_reg(index);
87 #if TCG_TARGET_REG_BITS == 64
88 static int32_t tci_read_reg32s(TCGReg index)
90 return (int32_t)tci_read_reg(index);
94 static uint8_t tci_read_reg8(TCGReg index)
96 return (uint8_t)tci_read_reg(index);
99 static uint16_t tci_read_reg16(TCGReg index)
101 return (uint16_t)tci_read_reg(index);
104 static uint32_t tci_read_reg32(TCGReg index)
106 return (uint32_t)tci_read_reg(index);
109 #if TCG_TARGET_REG_BITS == 64
110 static uint64_t tci_read_reg64(TCGReg index)
112 return tci_read_reg(index);
116 static void tci_write_reg(TCGReg index, tcg_target_ulong value)
118 assert(index < ARRAY_SIZE(tci_reg));
119 assert(index != TCG_AREG0);
120 tci_reg[index] = value;
123 static void tci_write_reg8s(TCGReg index, int8_t value)
125 tci_write_reg(index, value);
128 static void tci_write_reg16s(TCGReg index, int16_t value)
130 tci_write_reg(index, value);
133 #if TCG_TARGET_REG_BITS == 64
134 static void tci_write_reg32s(TCGReg index, int32_t value)
136 tci_write_reg(index, value);
140 static void tci_write_reg8(TCGReg index, uint8_t value)
142 tci_write_reg(index, value);
145 static void tci_write_reg16(TCGReg index, uint16_t value)
147 tci_write_reg(index, value);
150 static void tci_write_reg32(TCGReg index, uint32_t value)
152 tci_write_reg(index, value);
155 #if TCG_TARGET_REG_BITS == 32
156 static void tci_write_reg64(uint32_t high_index, uint32_t low_index,
159 tci_write_reg(low_index, value);
160 tci_write_reg(high_index, value >> 32);
162 #elif TCG_TARGET_REG_BITS == 64
163 static void tci_write_reg64(TCGReg index, uint64_t value)
165 tci_write_reg(index, value);
169 #if TCG_TARGET_REG_BITS == 32
170 /* Create a 64 bit value from two 32 bit values. */
171 static uint64_t tci_uint64(uint32_t high, uint32_t low)
173 return ((uint64_t)high << 32) + low;
177 /* Read constant (native size) from bytecode. */
178 static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
180 tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr);
181 *tb_ptr += sizeof(value);
185 /* Read constant (32 bit) from bytecode. */
186 static uint32_t tci_read_i32(uint8_t **tb_ptr)
188 uint32_t value = *(uint32_t *)(*tb_ptr);
189 *tb_ptr += sizeof(value);
193 #if TCG_TARGET_REG_BITS == 64
194 /* Read constant (64 bit) from bytecode. */
195 static uint64_t tci_read_i64(uint8_t **tb_ptr)
197 uint64_t value = *(uint64_t *)(*tb_ptr);
198 *tb_ptr += sizeof(value);
203 /* Read indexed register (native size) from bytecode. */
204 static tcg_target_ulong tci_read_r(uint8_t **tb_ptr)
206 tcg_target_ulong value = tci_read_reg(**tb_ptr);
211 /* Read indexed register (8 bit) from bytecode. */
212 static uint8_t tci_read_r8(uint8_t **tb_ptr)
214 uint8_t value = tci_read_reg8(**tb_ptr);
219 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
220 /* Read indexed register (8 bit signed) from bytecode. */
221 static int8_t tci_read_r8s(uint8_t **tb_ptr)
223 int8_t value = tci_read_reg8s(**tb_ptr);
229 /* Read indexed register (16 bit) from bytecode. */
230 static uint16_t tci_read_r16(uint8_t **tb_ptr)
232 uint16_t value = tci_read_reg16(**tb_ptr);
237 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
238 /* Read indexed register (16 bit signed) from bytecode. */
239 static int16_t tci_read_r16s(uint8_t **tb_ptr)
241 int16_t value = tci_read_reg16s(**tb_ptr);
247 /* Read indexed register (32 bit) from bytecode. */
248 static uint32_t tci_read_r32(uint8_t **tb_ptr)
250 uint32_t value = tci_read_reg32(**tb_ptr);
255 #if TCG_TARGET_REG_BITS == 32
256 /* Read two indexed registers (2 * 32 bit) from bytecode. */
257 static uint64_t tci_read_r64(uint8_t **tb_ptr)
259 uint32_t low = tci_read_r32(tb_ptr);
260 return tci_uint64(tci_read_r32(tb_ptr), low);
262 #elif TCG_TARGET_REG_BITS == 64
263 /* Read indexed register (32 bit signed) from bytecode. */
264 static int32_t tci_read_r32s(uint8_t **tb_ptr)
266 int32_t value = tci_read_reg32s(**tb_ptr);
271 /* Read indexed register (64 bit) from bytecode. */
272 static uint64_t tci_read_r64(uint8_t **tb_ptr)
274 uint64_t value = tci_read_reg64(**tb_ptr);
280 /* Read indexed register(s) with target address from bytecode. */
281 static target_ulong tci_read_ulong(uint8_t **tb_ptr)
283 target_ulong taddr = tci_read_r(tb_ptr);
284 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
285 taddr += (uint64_t)tci_read_r(tb_ptr) << 32;
290 /* Read indexed register or constant (native size) from bytecode. */
291 static tcg_target_ulong tci_read_ri(uint8_t **tb_ptr)
293 tcg_target_ulong value;
296 if (r == TCG_CONST) {
297 value = tci_read_i(tb_ptr);
299 value = tci_read_reg(r);
304 /* Read indexed register or constant (32 bit) from bytecode. */
305 static uint32_t tci_read_ri32(uint8_t **tb_ptr)
310 if (r == TCG_CONST) {
311 value = tci_read_i32(tb_ptr);
313 value = tci_read_reg32(r);
318 #if TCG_TARGET_REG_BITS == 32
319 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
320 static uint64_t tci_read_ri64(uint8_t **tb_ptr)
322 uint32_t low = tci_read_ri32(tb_ptr);
323 return tci_uint64(tci_read_ri32(tb_ptr), low);
325 #elif TCG_TARGET_REG_BITS == 64
326 /* Read indexed register or constant (64 bit) from bytecode. */
327 static uint64_t tci_read_ri64(uint8_t **tb_ptr)
332 if (r == TCG_CONST) {
333 value = tci_read_i64(tb_ptr);
335 value = tci_read_reg64(r);
341 static target_ulong tci_read_label(uint8_t **tb_ptr)
343 target_ulong label = tci_read_i(tb_ptr);
348 static bool tci_compare32(uint32_t u0, uint32_t u1, TCGCond condition)
390 static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
432 /* Interpret pseudo code in tb. */
433 tcg_target_ulong tcg_qemu_tb_exec(CPUArchState *cpustate, uint8_t *tb_ptr)
435 tcg_target_ulong next_tb = 0;
438 tci_reg[TCG_AREG0] = (tcg_target_ulong)env;
443 tci_tb_ptr = (uintptr_t)tb_ptr;
445 TCGOpcode opc = tb_ptr[0];
447 uint8_t op_size = tb_ptr[1];
448 uint8_t *old_code_ptr = tb_ptr;
453 tcg_target_ulong label;
456 #ifndef CONFIG_SOFTMMU
457 tcg_target_ulong host_addr;
463 #if TCG_TARGET_REG_BITS == 32
467 /* Skip opcode and size entry. */
478 case INDEX_op_discard:
481 case INDEX_op_set_label:
485 t0 = tci_read_ri(&tb_ptr);
486 #if TCG_TARGET_REG_BITS == 32
487 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
488 tci_read_reg(TCG_REG_R1),
489 tci_read_reg(TCG_REG_R2),
490 tci_read_reg(TCG_REG_R3),
491 tci_read_reg(TCG_REG_R5),
492 tci_read_reg(TCG_REG_R6),
493 tci_read_reg(TCG_REG_R7),
494 tci_read_reg(TCG_REG_R8),
495 tci_read_reg(TCG_REG_R9),
496 tci_read_reg(TCG_REG_R10));
497 tci_write_reg(TCG_REG_R0, tmp64);
498 tci_write_reg(TCG_REG_R1, tmp64 >> 32);
500 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
501 tci_read_reg(TCG_REG_R1),
502 tci_read_reg(TCG_REG_R2),
503 tci_read_reg(TCG_REG_R3),
504 tci_read_reg(TCG_REG_R5));
505 tci_write_reg(TCG_REG_R0, tmp64);
509 label = tci_read_label(&tb_ptr);
510 assert(tb_ptr == old_code_ptr + op_size);
511 tb_ptr = (uint8_t *)label;
513 case INDEX_op_setcond_i32:
515 t1 = tci_read_r32(&tb_ptr);
516 t2 = tci_read_ri32(&tb_ptr);
517 condition = *tb_ptr++;
518 tci_write_reg32(t0, tci_compare32(t1, t2, condition));
520 #if TCG_TARGET_REG_BITS == 32
521 case INDEX_op_setcond2_i32:
523 tmp64 = tci_read_r64(&tb_ptr);
524 v64 = tci_read_ri64(&tb_ptr);
525 condition = *tb_ptr++;
526 tci_write_reg32(t0, tci_compare64(tmp64, v64, condition));
528 #elif TCG_TARGET_REG_BITS == 64
529 case INDEX_op_setcond_i64:
531 t1 = tci_read_r64(&tb_ptr);
532 t2 = tci_read_ri64(&tb_ptr);
533 condition = *tb_ptr++;
534 tci_write_reg64(t0, tci_compare64(t1, t2, condition));
537 case INDEX_op_mov_i32:
539 t1 = tci_read_r32(&tb_ptr);
540 tci_write_reg32(t0, t1);
542 case INDEX_op_movi_i32:
544 t1 = tci_read_i32(&tb_ptr);
545 tci_write_reg32(t0, t1);
548 /* Load/store operations (32 bit). */
550 case INDEX_op_ld8u_i32:
552 t1 = tci_read_r(&tb_ptr);
553 t2 = tci_read_i32(&tb_ptr);
554 tci_write_reg8(t0, *(uint8_t *)(t1 + t2));
556 case INDEX_op_ld8s_i32:
557 case INDEX_op_ld16u_i32:
560 case INDEX_op_ld16s_i32:
563 case INDEX_op_ld_i32:
565 t1 = tci_read_r(&tb_ptr);
566 t2 = tci_read_i32(&tb_ptr);
567 tci_write_reg32(t0, *(uint32_t *)(t1 + t2));
569 case INDEX_op_st8_i32:
570 t0 = tci_read_r8(&tb_ptr);
571 t1 = tci_read_r(&tb_ptr);
572 t2 = tci_read_i32(&tb_ptr);
573 *(uint8_t *)(t1 + t2) = t0;
575 case INDEX_op_st16_i32:
576 t0 = tci_read_r16(&tb_ptr);
577 t1 = tci_read_r(&tb_ptr);
578 t2 = tci_read_i32(&tb_ptr);
579 *(uint16_t *)(t1 + t2) = t0;
581 case INDEX_op_st_i32:
582 t0 = tci_read_r32(&tb_ptr);
583 t1 = tci_read_r(&tb_ptr);
584 t2 = tci_read_i32(&tb_ptr);
585 *(uint32_t *)(t1 + t2) = t0;
588 /* Arithmetic operations (32 bit). */
590 case INDEX_op_add_i32:
592 t1 = tci_read_ri32(&tb_ptr);
593 t2 = tci_read_ri32(&tb_ptr);
594 tci_write_reg32(t0, t1 + t2);
596 case INDEX_op_sub_i32:
598 t1 = tci_read_ri32(&tb_ptr);
599 t2 = tci_read_ri32(&tb_ptr);
600 tci_write_reg32(t0, t1 - t2);
602 case INDEX_op_mul_i32:
604 t1 = tci_read_ri32(&tb_ptr);
605 t2 = tci_read_ri32(&tb_ptr);
606 tci_write_reg32(t0, t1 * t2);
608 #if TCG_TARGET_HAS_div_i32
609 case INDEX_op_div_i32:
611 t1 = tci_read_ri32(&tb_ptr);
612 t2 = tci_read_ri32(&tb_ptr);
613 tci_write_reg32(t0, (int32_t)t1 / (int32_t)t2);
615 case INDEX_op_divu_i32:
617 t1 = tci_read_ri32(&tb_ptr);
618 t2 = tci_read_ri32(&tb_ptr);
619 tci_write_reg32(t0, t1 / t2);
621 case INDEX_op_rem_i32:
623 t1 = tci_read_ri32(&tb_ptr);
624 t2 = tci_read_ri32(&tb_ptr);
625 tci_write_reg32(t0, (int32_t)t1 % (int32_t)t2);
627 case INDEX_op_remu_i32:
629 t1 = tci_read_ri32(&tb_ptr);
630 t2 = tci_read_ri32(&tb_ptr);
631 tci_write_reg32(t0, t1 % t2);
633 #elif TCG_TARGET_HAS_div2_i32
634 case INDEX_op_div2_i32:
635 case INDEX_op_divu2_i32:
639 case INDEX_op_and_i32:
641 t1 = tci_read_ri32(&tb_ptr);
642 t2 = tci_read_ri32(&tb_ptr);
643 tci_write_reg32(t0, t1 & t2);
645 case INDEX_op_or_i32:
647 t1 = tci_read_ri32(&tb_ptr);
648 t2 = tci_read_ri32(&tb_ptr);
649 tci_write_reg32(t0, t1 | t2);
651 case INDEX_op_xor_i32:
653 t1 = tci_read_ri32(&tb_ptr);
654 t2 = tci_read_ri32(&tb_ptr);
655 tci_write_reg32(t0, t1 ^ t2);
658 /* Shift/rotate operations (32 bit). */
660 case INDEX_op_shl_i32:
662 t1 = tci_read_ri32(&tb_ptr);
663 t2 = tci_read_ri32(&tb_ptr);
664 tci_write_reg32(t0, t1 << t2);
666 case INDEX_op_shr_i32:
668 t1 = tci_read_ri32(&tb_ptr);
669 t2 = tci_read_ri32(&tb_ptr);
670 tci_write_reg32(t0, t1 >> t2);
672 case INDEX_op_sar_i32:
674 t1 = tci_read_ri32(&tb_ptr);
675 t2 = tci_read_ri32(&tb_ptr);
676 tci_write_reg32(t0, ((int32_t)t1 >> t2));
678 #if TCG_TARGET_HAS_rot_i32
679 case INDEX_op_rotl_i32:
681 t1 = tci_read_ri32(&tb_ptr);
682 t2 = tci_read_ri32(&tb_ptr);
683 tci_write_reg32(t0, (t1 << t2) | (t1 >> (32 - t2)));
685 case INDEX_op_rotr_i32:
687 t1 = tci_read_ri32(&tb_ptr);
688 t2 = tci_read_ri32(&tb_ptr);
689 tci_write_reg32(t0, (t1 >> t2) | (t1 << (32 - t2)));
692 case INDEX_op_brcond_i32:
693 t0 = tci_read_r32(&tb_ptr);
694 t1 = tci_read_ri32(&tb_ptr);
695 condition = *tb_ptr++;
696 label = tci_read_label(&tb_ptr);
697 if (tci_compare32(t0, t1, condition)) {
698 assert(tb_ptr == old_code_ptr + op_size);
699 tb_ptr = (uint8_t *)label;
703 #if TCG_TARGET_REG_BITS == 32
704 case INDEX_op_add2_i32:
707 tmp64 = tci_read_r64(&tb_ptr);
708 tmp64 += tci_read_r64(&tb_ptr);
709 tci_write_reg64(t1, t0, tmp64);
711 case INDEX_op_sub2_i32:
714 tmp64 = tci_read_r64(&tb_ptr);
715 tmp64 -= tci_read_r64(&tb_ptr);
716 tci_write_reg64(t1, t0, tmp64);
718 case INDEX_op_brcond2_i32:
719 tmp64 = tci_read_r64(&tb_ptr);
720 v64 = tci_read_ri64(&tb_ptr);
721 condition = *tb_ptr++;
722 label = tci_read_label(&tb_ptr);
723 if (tci_compare64(tmp64, v64, condition)) {
724 assert(tb_ptr == old_code_ptr + op_size);
725 tb_ptr = (uint8_t *)label;
729 case INDEX_op_mulu2_i32:
732 t2 = tci_read_r32(&tb_ptr);
733 tmp64 = tci_read_r32(&tb_ptr);
734 tci_write_reg64(t1, t0, t2 * tmp64);
736 #endif /* TCG_TARGET_REG_BITS == 32 */
737 #if TCG_TARGET_HAS_ext8s_i32
738 case INDEX_op_ext8s_i32:
740 t1 = tci_read_r8s(&tb_ptr);
741 tci_write_reg32(t0, t1);
744 #if TCG_TARGET_HAS_ext16s_i32
745 case INDEX_op_ext16s_i32:
747 t1 = tci_read_r16s(&tb_ptr);
748 tci_write_reg32(t0, t1);
751 #if TCG_TARGET_HAS_ext8u_i32
752 case INDEX_op_ext8u_i32:
754 t1 = tci_read_r8(&tb_ptr);
755 tci_write_reg32(t0, t1);
758 #if TCG_TARGET_HAS_ext16u_i32
759 case INDEX_op_ext16u_i32:
761 t1 = tci_read_r16(&tb_ptr);
762 tci_write_reg32(t0, t1);
765 #if TCG_TARGET_HAS_bswap16_i32
766 case INDEX_op_bswap16_i32:
768 t1 = tci_read_r16(&tb_ptr);
769 tci_write_reg32(t0, bswap16(t1));
772 #if TCG_TARGET_HAS_bswap32_i32
773 case INDEX_op_bswap32_i32:
775 t1 = tci_read_r32(&tb_ptr);
776 tci_write_reg32(t0, bswap32(t1));
779 #if TCG_TARGET_HAS_not_i32
780 case INDEX_op_not_i32:
782 t1 = tci_read_r32(&tb_ptr);
783 tci_write_reg32(t0, ~t1);
786 #if TCG_TARGET_HAS_neg_i32
787 case INDEX_op_neg_i32:
789 t1 = tci_read_r32(&tb_ptr);
790 tci_write_reg32(t0, -t1);
793 #if TCG_TARGET_REG_BITS == 64
794 case INDEX_op_mov_i64:
796 t1 = tci_read_r64(&tb_ptr);
797 tci_write_reg64(t0, t1);
799 case INDEX_op_movi_i64:
801 t1 = tci_read_i64(&tb_ptr);
802 tci_write_reg64(t0, t1);
805 /* Load/store operations (64 bit). */
807 case INDEX_op_ld8u_i64:
809 t1 = tci_read_r(&tb_ptr);
810 t2 = tci_read_i32(&tb_ptr);
811 tci_write_reg8(t0, *(uint8_t *)(t1 + t2));
813 case INDEX_op_ld8s_i64:
814 case INDEX_op_ld16u_i64:
815 case INDEX_op_ld16s_i64:
818 case INDEX_op_ld32u_i64:
820 t1 = tci_read_r(&tb_ptr);
821 t2 = tci_read_i32(&tb_ptr);
822 tci_write_reg32(t0, *(uint32_t *)(t1 + t2));
824 case INDEX_op_ld32s_i64:
826 t1 = tci_read_r(&tb_ptr);
827 t2 = tci_read_i32(&tb_ptr);
828 tci_write_reg32s(t0, *(int32_t *)(t1 + t2));
830 case INDEX_op_ld_i64:
832 t1 = tci_read_r(&tb_ptr);
833 t2 = tci_read_i32(&tb_ptr);
834 tci_write_reg64(t0, *(uint64_t *)(t1 + t2));
836 case INDEX_op_st8_i64:
837 t0 = tci_read_r8(&tb_ptr);
838 t1 = tci_read_r(&tb_ptr);
839 t2 = tci_read_i32(&tb_ptr);
840 *(uint8_t *)(t1 + t2) = t0;
842 case INDEX_op_st16_i64:
843 t0 = tci_read_r16(&tb_ptr);
844 t1 = tci_read_r(&tb_ptr);
845 t2 = tci_read_i32(&tb_ptr);
846 *(uint16_t *)(t1 + t2) = t0;
848 case INDEX_op_st32_i64:
849 t0 = tci_read_r32(&tb_ptr);
850 t1 = tci_read_r(&tb_ptr);
851 t2 = tci_read_i32(&tb_ptr);
852 *(uint32_t *)(t1 + t2) = t0;
854 case INDEX_op_st_i64:
855 t0 = tci_read_r64(&tb_ptr);
856 t1 = tci_read_r(&tb_ptr);
857 t2 = tci_read_i32(&tb_ptr);
858 *(uint64_t *)(t1 + t2) = t0;
861 /* Arithmetic operations (64 bit). */
863 case INDEX_op_add_i64:
865 t1 = tci_read_ri64(&tb_ptr);
866 t2 = tci_read_ri64(&tb_ptr);
867 tci_write_reg64(t0, t1 + t2);
869 case INDEX_op_sub_i64:
871 t1 = tci_read_ri64(&tb_ptr);
872 t2 = tci_read_ri64(&tb_ptr);
873 tci_write_reg64(t0, t1 - t2);
875 case INDEX_op_mul_i64:
877 t1 = tci_read_ri64(&tb_ptr);
878 t2 = tci_read_ri64(&tb_ptr);
879 tci_write_reg64(t0, t1 * t2);
881 #if TCG_TARGET_HAS_div_i64
882 case INDEX_op_div_i64:
883 case INDEX_op_divu_i64:
884 case INDEX_op_rem_i64:
885 case INDEX_op_remu_i64:
888 #elif TCG_TARGET_HAS_div2_i64
889 case INDEX_op_div2_i64:
890 case INDEX_op_divu2_i64:
894 case INDEX_op_and_i64:
896 t1 = tci_read_ri64(&tb_ptr);
897 t2 = tci_read_ri64(&tb_ptr);
898 tci_write_reg64(t0, t1 & t2);
900 case INDEX_op_or_i64:
902 t1 = tci_read_ri64(&tb_ptr);
903 t2 = tci_read_ri64(&tb_ptr);
904 tci_write_reg64(t0, t1 | t2);
906 case INDEX_op_xor_i64:
908 t1 = tci_read_ri64(&tb_ptr);
909 t2 = tci_read_ri64(&tb_ptr);
910 tci_write_reg64(t0, t1 ^ t2);
913 /* Shift/rotate operations (64 bit). */
915 case INDEX_op_shl_i64:
917 t1 = tci_read_ri64(&tb_ptr);
918 t2 = tci_read_ri64(&tb_ptr);
919 tci_write_reg64(t0, t1 << t2);
921 case INDEX_op_shr_i64:
923 t1 = tci_read_ri64(&tb_ptr);
924 t2 = tci_read_ri64(&tb_ptr);
925 tci_write_reg64(t0, t1 >> t2);
927 case INDEX_op_sar_i64:
929 t1 = tci_read_ri64(&tb_ptr);
930 t2 = tci_read_ri64(&tb_ptr);
931 tci_write_reg64(t0, ((int64_t)t1 >> t2));
933 #if TCG_TARGET_HAS_rot_i64
934 case INDEX_op_rotl_i64:
935 case INDEX_op_rotr_i64:
939 case INDEX_op_brcond_i64:
940 t0 = tci_read_r64(&tb_ptr);
941 t1 = tci_read_ri64(&tb_ptr);
942 condition = *tb_ptr++;
943 label = tci_read_label(&tb_ptr);
944 if (tci_compare64(t0, t1, condition)) {
945 assert(tb_ptr == old_code_ptr + op_size);
946 tb_ptr = (uint8_t *)label;
950 #if TCG_TARGET_HAS_ext8u_i64
951 case INDEX_op_ext8u_i64:
953 t1 = tci_read_r8(&tb_ptr);
954 tci_write_reg64(t0, t1);
957 #if TCG_TARGET_HAS_ext8s_i64
958 case INDEX_op_ext8s_i64:
960 t1 = tci_read_r8s(&tb_ptr);
961 tci_write_reg64(t0, t1);
964 #if TCG_TARGET_HAS_ext16s_i64
965 case INDEX_op_ext16s_i64:
967 t1 = tci_read_r16s(&tb_ptr);
968 tci_write_reg64(t0, t1);
971 #if TCG_TARGET_HAS_ext16u_i64
972 case INDEX_op_ext16u_i64:
974 t1 = tci_read_r16(&tb_ptr);
975 tci_write_reg64(t0, t1);
978 #if TCG_TARGET_HAS_ext32s_i64
979 case INDEX_op_ext32s_i64:
981 t1 = tci_read_r32s(&tb_ptr);
982 tci_write_reg64(t0, t1);
985 #if TCG_TARGET_HAS_ext32u_i64
986 case INDEX_op_ext32u_i64:
988 t1 = tci_read_r32(&tb_ptr);
989 tci_write_reg64(t0, t1);
992 #if TCG_TARGET_HAS_bswap16_i64
993 case INDEX_op_bswap16_i64:
996 t1 = tci_read_r16(&tb_ptr);
997 tci_write_reg64(t0, bswap16(t1));
1000 #if TCG_TARGET_HAS_bswap32_i64
1001 case INDEX_op_bswap32_i64:
1003 t1 = tci_read_r32(&tb_ptr);
1004 tci_write_reg64(t0, bswap32(t1));
1007 #if TCG_TARGET_HAS_bswap64_i64
1008 case INDEX_op_bswap64_i64:
1010 t1 = tci_read_r64(&tb_ptr);
1011 tci_write_reg64(t0, bswap64(t1));
1014 #if TCG_TARGET_HAS_not_i64
1015 case INDEX_op_not_i64:
1017 t1 = tci_read_r64(&tb_ptr);
1018 tci_write_reg64(t0, ~t1);
1021 #if TCG_TARGET_HAS_neg_i64
1022 case INDEX_op_neg_i64:
1024 t1 = tci_read_r64(&tb_ptr);
1025 tci_write_reg64(t0, -t1);
1028 #endif /* TCG_TARGET_REG_BITS == 64 */
1030 /* QEMU specific operations. */
1032 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1033 case INDEX_op_debug_insn_start:
1037 case INDEX_op_debug_insn_start:
1041 case INDEX_op_exit_tb:
1042 next_tb = *(uint64_t *)tb_ptr;
1045 case INDEX_op_goto_tb:
1046 t0 = tci_read_i32(&tb_ptr);
1047 assert(tb_ptr == old_code_ptr + op_size);
1048 tb_ptr += (int32_t)t0;
1050 case INDEX_op_qemu_ld8u:
1052 taddr = tci_read_ulong(&tb_ptr);
1053 #ifdef CONFIG_SOFTMMU
1054 tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr));
1056 host_addr = (tcg_target_ulong)taddr;
1057 assert(taddr == host_addr);
1058 tmp8 = *(uint8_t *)(host_addr + GUEST_BASE);
1060 tci_write_reg8(t0, tmp8);
1062 case INDEX_op_qemu_ld8s:
1064 taddr = tci_read_ulong(&tb_ptr);
1065 #ifdef CONFIG_SOFTMMU
1066 tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr));
1068 host_addr = (tcg_target_ulong)taddr;
1069 assert(taddr == host_addr);
1070 tmp8 = *(uint8_t *)(host_addr + GUEST_BASE);
1072 tci_write_reg8s(t0, tmp8);
1074 case INDEX_op_qemu_ld16u:
1076 taddr = tci_read_ulong(&tb_ptr);
1077 #ifdef CONFIG_SOFTMMU
1078 tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr));
1080 host_addr = (tcg_target_ulong)taddr;
1081 assert(taddr == host_addr);
1082 tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE));
1084 tci_write_reg16(t0, tmp16);
1086 case INDEX_op_qemu_ld16s:
1088 taddr = tci_read_ulong(&tb_ptr);
1089 #ifdef CONFIG_SOFTMMU
1090 tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr));
1092 host_addr = (tcg_target_ulong)taddr;
1093 assert(taddr == host_addr);
1094 tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE));
1096 tci_write_reg16s(t0, tmp16);
1098 #if TCG_TARGET_REG_BITS == 64
1099 case INDEX_op_qemu_ld32u:
1101 taddr = tci_read_ulong(&tb_ptr);
1102 #ifdef CONFIG_SOFTMMU
1103 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1105 host_addr = (tcg_target_ulong)taddr;
1106 assert(taddr == host_addr);
1107 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1109 tci_write_reg32(t0, tmp32);
1111 case INDEX_op_qemu_ld32s:
1113 taddr = tci_read_ulong(&tb_ptr);
1114 #ifdef CONFIG_SOFTMMU
1115 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1117 host_addr = (tcg_target_ulong)taddr;
1118 assert(taddr == host_addr);
1119 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1121 tci_write_reg32s(t0, tmp32);
1123 #endif /* TCG_TARGET_REG_BITS == 64 */
1124 case INDEX_op_qemu_ld32:
1126 taddr = tci_read_ulong(&tb_ptr);
1127 #ifdef CONFIG_SOFTMMU
1128 tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr));
1130 host_addr = (tcg_target_ulong)taddr;
1131 assert(taddr == host_addr);
1132 tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE));
1134 tci_write_reg32(t0, tmp32);
1136 case INDEX_op_qemu_ld64:
1138 #if TCG_TARGET_REG_BITS == 32
1141 taddr = tci_read_ulong(&tb_ptr);
1142 #ifdef CONFIG_SOFTMMU
1143 tmp64 = helper_ldq_mmu(env, taddr, tci_read_i(&tb_ptr));
1145 host_addr = (tcg_target_ulong)taddr;
1146 assert(taddr == host_addr);
1147 tmp64 = tswap64(*(uint64_t *)(host_addr + GUEST_BASE));
1149 tci_write_reg(t0, tmp64);
1150 #if TCG_TARGET_REG_BITS == 32
1151 tci_write_reg(t1, tmp64 >> 32);
1154 case INDEX_op_qemu_st8:
1155 t0 = tci_read_r8(&tb_ptr);
1156 taddr = tci_read_ulong(&tb_ptr);
1157 #ifdef CONFIG_SOFTMMU
1158 t2 = tci_read_i(&tb_ptr);
1159 helper_stb_mmu(env, taddr, t0, t2);
1161 host_addr = (tcg_target_ulong)taddr;
1162 assert(taddr == host_addr);
1163 *(uint8_t *)(host_addr + GUEST_BASE) = t0;
1166 case INDEX_op_qemu_st16:
1167 t0 = tci_read_r16(&tb_ptr);
1168 taddr = tci_read_ulong(&tb_ptr);
1169 #ifdef CONFIG_SOFTMMU
1170 t2 = tci_read_i(&tb_ptr);
1171 helper_stw_mmu(env, taddr, t0, t2);
1173 host_addr = (tcg_target_ulong)taddr;
1174 assert(taddr == host_addr);
1175 *(uint16_t *)(host_addr + GUEST_BASE) = tswap16(t0);
1178 case INDEX_op_qemu_st32:
1179 t0 = tci_read_r32(&tb_ptr);
1180 taddr = tci_read_ulong(&tb_ptr);
1181 #ifdef CONFIG_SOFTMMU
1182 t2 = tci_read_i(&tb_ptr);
1183 helper_stl_mmu(env, taddr, t0, t2);
1185 host_addr = (tcg_target_ulong)taddr;
1186 assert(taddr == host_addr);
1187 *(uint32_t *)(host_addr + GUEST_BASE) = tswap32(t0);
1190 case INDEX_op_qemu_st64:
1191 tmp64 = tci_read_r64(&tb_ptr);
1192 taddr = tci_read_ulong(&tb_ptr);
1193 #ifdef CONFIG_SOFTMMU
1194 t2 = tci_read_i(&tb_ptr);
1195 helper_stq_mmu(env, taddr, tmp64, t2);
1197 host_addr = (tcg_target_ulong)taddr;
1198 assert(taddr == host_addr);
1199 *(uint64_t *)(host_addr + GUEST_BASE) = tswap64(tmp64);
1206 assert(tb_ptr == old_code_ptr + op_size);