2 * Tiny Code Interpreter for QEMU
4 * Copyright (c) 2009, 2011, 2016 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/>.
20 #include "qemu/osdep.h"
22 /* Enable TCI assertions only when debugging TCG (and without NDEBUG defined).
23 * Without assertions, the interpreter runs much faster. */
24 #if defined(CONFIG_DEBUG_TCG)
25 # define tci_assert(cond) assert(cond)
27 # define tci_assert(cond) ((void)0)
30 #include "qemu-common.h"
31 #include "tcg/tcg.h" /* MAX_OPC_PARAM_IARGS */
32 #include "exec/cpu_ldst.h"
33 #include "tcg/tcg-op.h"
35 /* Marker for missing code. */
38 fprintf(stderr, "TODO %s:%u: %s()\n", \
39 __FILE__, __LINE__, __func__); \
43 #if MAX_OPC_PARAM_IARGS != 6
44 # error Fix needed, number of supported input arguments changed!
46 #if TCG_TARGET_REG_BITS == 32
47 typedef uint64_t (*helper_function)(tcg_target_ulong, tcg_target_ulong,
48 tcg_target_ulong, tcg_target_ulong,
49 tcg_target_ulong, tcg_target_ulong,
50 tcg_target_ulong, tcg_target_ulong,
51 tcg_target_ulong, tcg_target_ulong,
52 tcg_target_ulong, tcg_target_ulong);
54 typedef uint64_t (*helper_function)(tcg_target_ulong, tcg_target_ulong,
55 tcg_target_ulong, tcg_target_ulong,
56 tcg_target_ulong, tcg_target_ulong);
59 static tcg_target_ulong tci_read_reg(const tcg_target_ulong *regs, TCGReg index)
61 tci_assert(index < TCG_TARGET_NB_REGS);
65 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
66 static int8_t tci_read_reg8s(const tcg_target_ulong *regs, TCGReg index)
68 return (int8_t)tci_read_reg(regs, index);
72 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
73 static int16_t tci_read_reg16s(const tcg_target_ulong *regs, TCGReg index)
75 return (int16_t)tci_read_reg(regs, index);
79 #if TCG_TARGET_REG_BITS == 64
80 static int32_t tci_read_reg32s(const tcg_target_ulong *regs, TCGReg index)
82 return (int32_t)tci_read_reg(regs, index);
86 static uint8_t tci_read_reg8(const tcg_target_ulong *regs, TCGReg index)
88 return (uint8_t)tci_read_reg(regs, index);
91 static uint16_t tci_read_reg16(const tcg_target_ulong *regs, TCGReg index)
93 return (uint16_t)tci_read_reg(regs, index);
96 static uint32_t tci_read_reg32(const tcg_target_ulong *regs, TCGReg index)
98 return (uint32_t)tci_read_reg(regs, index);
101 #if TCG_TARGET_REG_BITS == 64
102 static uint64_t tci_read_reg64(const tcg_target_ulong *regs, TCGReg index)
104 return tci_read_reg(regs, index);
109 tci_write_reg(tcg_target_ulong *regs, TCGReg index, tcg_target_ulong value)
111 tci_assert(index < TCG_TARGET_NB_REGS);
112 tci_assert(index != TCG_AREG0);
113 tci_assert(index != TCG_REG_CALL_STACK);
117 #if TCG_TARGET_REG_BITS == 64
119 tci_write_reg32s(tcg_target_ulong *regs, TCGReg index, int32_t value)
121 tci_write_reg(regs, index, value);
125 static void tci_write_reg8(tcg_target_ulong *regs, TCGReg index, uint8_t value)
127 tci_write_reg(regs, index, value);
131 tci_write_reg16(tcg_target_ulong *regs, TCGReg index, uint16_t value)
133 tci_write_reg(regs, index, value);
137 tci_write_reg32(tcg_target_ulong *regs, TCGReg index, uint32_t value)
139 tci_write_reg(regs, index, value);
142 #if TCG_TARGET_REG_BITS == 32
143 static void tci_write_reg64(tcg_target_ulong *regs, uint32_t high_index,
144 uint32_t low_index, uint64_t value)
146 tci_write_reg(regs, low_index, value);
147 tci_write_reg(regs, high_index, value >> 32);
149 #elif TCG_TARGET_REG_BITS == 64
151 tci_write_reg64(tcg_target_ulong *regs, TCGReg index, uint64_t value)
153 tci_write_reg(regs, index, value);
157 #if TCG_TARGET_REG_BITS == 32
158 /* Create a 64 bit value from two 32 bit values. */
159 static uint64_t tci_uint64(uint32_t high, uint32_t low)
161 return ((uint64_t)high << 32) + low;
165 /* Read constant (native size) from bytecode. */
166 static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
168 tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr);
169 *tb_ptr += sizeof(value);
173 /* Read unsigned constant (32 bit) from bytecode. */
174 static uint32_t tci_read_i32(uint8_t **tb_ptr)
176 uint32_t value = *(uint32_t *)(*tb_ptr);
177 *tb_ptr += sizeof(value);
181 /* Read signed constant (32 bit) from bytecode. */
182 static int32_t tci_read_s32(uint8_t **tb_ptr)
184 int32_t value = *(int32_t *)(*tb_ptr);
185 *tb_ptr += sizeof(value);
189 #if TCG_TARGET_REG_BITS == 64
190 /* Read constant (64 bit) from bytecode. */
191 static uint64_t tci_read_i64(uint8_t **tb_ptr)
193 uint64_t value = *(uint64_t *)(*tb_ptr);
194 *tb_ptr += sizeof(value);
199 /* Read indexed register (native size) from bytecode. */
200 static tcg_target_ulong
201 tci_read_r(const tcg_target_ulong *regs, uint8_t **tb_ptr)
203 tcg_target_ulong value = tci_read_reg(regs, **tb_ptr);
208 /* Read indexed register (8 bit) from bytecode. */
209 static uint8_t tci_read_r8(const tcg_target_ulong *regs, uint8_t **tb_ptr)
211 uint8_t value = tci_read_reg8(regs, **tb_ptr);
216 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
217 /* Read indexed register (8 bit signed) from bytecode. */
218 static int8_t tci_read_r8s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
220 int8_t value = tci_read_reg8s(regs, **tb_ptr);
226 /* Read indexed register (16 bit) from bytecode. */
227 static uint16_t tci_read_r16(const tcg_target_ulong *regs, uint8_t **tb_ptr)
229 uint16_t value = tci_read_reg16(regs, **tb_ptr);
234 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
235 /* Read indexed register (16 bit signed) from bytecode. */
236 static int16_t tci_read_r16s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
238 int16_t value = tci_read_reg16s(regs, **tb_ptr);
244 /* Read indexed register (32 bit) from bytecode. */
245 static uint32_t tci_read_r32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
247 uint32_t value = tci_read_reg32(regs, **tb_ptr);
252 #if TCG_TARGET_REG_BITS == 32
253 /* Read two indexed registers (2 * 32 bit) from bytecode. */
254 static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
256 uint32_t low = tci_read_r32(regs, tb_ptr);
257 return tci_uint64(tci_read_r32(regs, tb_ptr), low);
259 #elif TCG_TARGET_REG_BITS == 64
260 /* Read indexed register (32 bit signed) from bytecode. */
261 static int32_t tci_read_r32s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
263 int32_t value = tci_read_reg32s(regs, **tb_ptr);
268 /* Read indexed register (64 bit) from bytecode. */
269 static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
271 uint64_t value = tci_read_reg64(regs, **tb_ptr);
277 /* Read indexed register(s) with target address from bytecode. */
279 tci_read_ulong(const tcg_target_ulong *regs, uint8_t **tb_ptr)
281 target_ulong taddr = tci_read_r(regs, tb_ptr);
282 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
283 taddr += (uint64_t)tci_read_r(regs, tb_ptr) << 32;
288 /* Read indexed register or constant (native size) from bytecode. */
289 static tcg_target_ulong
290 tci_read_ri(const tcg_target_ulong *regs, uint8_t **tb_ptr)
292 tcg_target_ulong value;
295 if (r == TCG_CONST) {
296 value = tci_read_i(tb_ptr);
298 value = tci_read_reg(regs, r);
303 /* Read indexed register or constant (32 bit) from bytecode. */
304 static uint32_t tci_read_ri32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
309 if (r == TCG_CONST) {
310 value = tci_read_i32(tb_ptr);
312 value = tci_read_reg32(regs, r);
317 #if TCG_TARGET_REG_BITS == 32
318 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
319 static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
321 uint32_t low = tci_read_ri32(regs, tb_ptr);
322 return tci_uint64(tci_read_ri32(regs, tb_ptr), low);
324 #elif TCG_TARGET_REG_BITS == 64
325 /* Read indexed register or constant (64 bit) from bytecode. */
326 static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
331 if (r == TCG_CONST) {
332 value = tci_read_i64(tb_ptr);
334 value = tci_read_reg64(regs, r);
340 static tcg_target_ulong tci_read_label(uint8_t **tb_ptr)
342 tcg_target_ulong label = tci_read_i(tb_ptr);
343 tci_assert(label != 0);
347 static bool tci_compare32(uint32_t u0, uint32_t u1, TCGCond condition)
389 static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
431 #ifdef CONFIG_SOFTMMU
432 # define qemu_ld_ub \
433 helper_ret_ldub_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
434 # define qemu_ld_leuw \
435 helper_le_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
436 # define qemu_ld_leul \
437 helper_le_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
438 # define qemu_ld_leq \
439 helper_le_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
440 # define qemu_ld_beuw \
441 helper_be_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
442 # define qemu_ld_beul \
443 helper_be_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
444 # define qemu_ld_beq \
445 helper_be_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
446 # define qemu_st_b(X) \
447 helper_ret_stb_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
448 # define qemu_st_lew(X) \
449 helper_le_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
450 # define qemu_st_lel(X) \
451 helper_le_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
452 # define qemu_st_leq(X) \
453 helper_le_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
454 # define qemu_st_bew(X) \
455 helper_be_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
456 # define qemu_st_bel(X) \
457 helper_be_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
458 # define qemu_st_beq(X) \
459 helper_be_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
461 # define qemu_ld_ub ldub_p(g2h(taddr))
462 # define qemu_ld_leuw lduw_le_p(g2h(taddr))
463 # define qemu_ld_leul (uint32_t)ldl_le_p(g2h(taddr))
464 # define qemu_ld_leq ldq_le_p(g2h(taddr))
465 # define qemu_ld_beuw lduw_be_p(g2h(taddr))
466 # define qemu_ld_beul (uint32_t)ldl_be_p(g2h(taddr))
467 # define qemu_ld_beq ldq_be_p(g2h(taddr))
468 # define qemu_st_b(X) stb_p(g2h(taddr), X)
469 # define qemu_st_lew(X) stw_le_p(g2h(taddr), X)
470 # define qemu_st_lel(X) stl_le_p(g2h(taddr), X)
471 # define qemu_st_leq(X) stq_le_p(g2h(taddr), X)
472 # define qemu_st_bew(X) stw_be_p(g2h(taddr), X)
473 # define qemu_st_bel(X) stl_be_p(g2h(taddr), X)
474 # define qemu_st_beq(X) stq_be_p(g2h(taddr), X)
477 /* Interpret pseudo code in tb. */
478 uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
480 tcg_target_ulong regs[TCG_TARGET_NB_REGS];
481 long tcg_temps[CPU_TEMP_BUF_NLONGS];
482 uintptr_t sp_value = (uintptr_t)(tcg_temps + CPU_TEMP_BUF_NLONGS);
485 regs[TCG_AREG0] = (tcg_target_ulong)env;
486 regs[TCG_REG_CALL_STACK] = sp_value;
490 TCGOpcode opc = tb_ptr[0];
491 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
492 uint8_t op_size = tb_ptr[1];
493 uint8_t *old_code_ptr = tb_ptr;
498 tcg_target_ulong label;
505 #if TCG_TARGET_REG_BITS == 32
511 tci_tb_ptr = (uintptr_t)tb_ptr;
514 /* Skip opcode and size entry. */
519 t0 = tci_read_ri(regs, &tb_ptr);
520 #if TCG_TARGET_REG_BITS == 32
521 tmp64 = ((helper_function)t0)(tci_read_reg(regs, TCG_REG_R0),
522 tci_read_reg(regs, TCG_REG_R1),
523 tci_read_reg(regs, TCG_REG_R2),
524 tci_read_reg(regs, TCG_REG_R3),
525 tci_read_reg(regs, TCG_REG_R5),
526 tci_read_reg(regs, TCG_REG_R6),
527 tci_read_reg(regs, TCG_REG_R7),
528 tci_read_reg(regs, TCG_REG_R8),
529 tci_read_reg(regs, TCG_REG_R9),
530 tci_read_reg(regs, TCG_REG_R10),
531 tci_read_reg(regs, TCG_REG_R11),
532 tci_read_reg(regs, TCG_REG_R12));
533 tci_write_reg(regs, TCG_REG_R0, tmp64);
534 tci_write_reg(regs, TCG_REG_R1, tmp64 >> 32);
536 tmp64 = ((helper_function)t0)(tci_read_reg(regs, TCG_REG_R0),
537 tci_read_reg(regs, TCG_REG_R1),
538 tci_read_reg(regs, TCG_REG_R2),
539 tci_read_reg(regs, TCG_REG_R3),
540 tci_read_reg(regs, TCG_REG_R5),
541 tci_read_reg(regs, TCG_REG_R6));
542 tci_write_reg(regs, TCG_REG_R0, tmp64);
546 label = tci_read_label(&tb_ptr);
547 tci_assert(tb_ptr == old_code_ptr + op_size);
548 tb_ptr = (uint8_t *)label;
550 case INDEX_op_setcond_i32:
552 t1 = tci_read_r32(regs, &tb_ptr);
553 t2 = tci_read_ri32(regs, &tb_ptr);
554 condition = *tb_ptr++;
555 tci_write_reg32(regs, t0, tci_compare32(t1, t2, condition));
557 #if TCG_TARGET_REG_BITS == 32
558 case INDEX_op_setcond2_i32:
560 tmp64 = tci_read_r64(regs, &tb_ptr);
561 v64 = tci_read_ri64(regs, &tb_ptr);
562 condition = *tb_ptr++;
563 tci_write_reg32(regs, t0, tci_compare64(tmp64, v64, condition));
565 #elif TCG_TARGET_REG_BITS == 64
566 case INDEX_op_setcond_i64:
568 t1 = tci_read_r64(regs, &tb_ptr);
569 t2 = tci_read_ri64(regs, &tb_ptr);
570 condition = *tb_ptr++;
571 tci_write_reg64(regs, t0, tci_compare64(t1, t2, condition));
574 case INDEX_op_mov_i32:
576 t1 = tci_read_r32(regs, &tb_ptr);
577 tci_write_reg32(regs, t0, t1);
579 case INDEX_op_movi_i32:
581 t1 = tci_read_i32(&tb_ptr);
582 tci_write_reg32(regs, t0, t1);
585 /* Load/store operations (32 bit). */
587 case INDEX_op_ld8u_i32:
589 t1 = tci_read_r(regs, &tb_ptr);
590 t2 = tci_read_s32(&tb_ptr);
591 tci_write_reg8(regs, t0, *(uint8_t *)(t1 + t2));
593 case INDEX_op_ld8s_i32:
596 case INDEX_op_ld16u_i32:
599 case INDEX_op_ld16s_i32:
602 case INDEX_op_ld_i32:
604 t1 = tci_read_r(regs, &tb_ptr);
605 t2 = tci_read_s32(&tb_ptr);
606 tci_write_reg32(regs, t0, *(uint32_t *)(t1 + t2));
608 case INDEX_op_st8_i32:
609 t0 = tci_read_r8(regs, &tb_ptr);
610 t1 = tci_read_r(regs, &tb_ptr);
611 t2 = tci_read_s32(&tb_ptr);
612 *(uint8_t *)(t1 + t2) = t0;
614 case INDEX_op_st16_i32:
615 t0 = tci_read_r16(regs, &tb_ptr);
616 t1 = tci_read_r(regs, &tb_ptr);
617 t2 = tci_read_s32(&tb_ptr);
618 *(uint16_t *)(t1 + t2) = t0;
620 case INDEX_op_st_i32:
621 t0 = tci_read_r32(regs, &tb_ptr);
622 t1 = tci_read_r(regs, &tb_ptr);
623 t2 = tci_read_s32(&tb_ptr);
624 tci_assert(t1 != sp_value || (int32_t)t2 < 0);
625 *(uint32_t *)(t1 + t2) = t0;
628 /* Arithmetic operations (32 bit). */
630 case INDEX_op_add_i32:
632 t1 = tci_read_ri32(regs, &tb_ptr);
633 t2 = tci_read_ri32(regs, &tb_ptr);
634 tci_write_reg32(regs, t0, t1 + t2);
636 case INDEX_op_sub_i32:
638 t1 = tci_read_ri32(regs, &tb_ptr);
639 t2 = tci_read_ri32(regs, &tb_ptr);
640 tci_write_reg32(regs, t0, t1 - t2);
642 case INDEX_op_mul_i32:
644 t1 = tci_read_ri32(regs, &tb_ptr);
645 t2 = tci_read_ri32(regs, &tb_ptr);
646 tci_write_reg32(regs, t0, t1 * t2);
648 #if TCG_TARGET_HAS_div_i32
649 case INDEX_op_div_i32:
651 t1 = tci_read_ri32(regs, &tb_ptr);
652 t2 = tci_read_ri32(regs, &tb_ptr);
653 tci_write_reg32(regs, t0, (int32_t)t1 / (int32_t)t2);
655 case INDEX_op_divu_i32:
657 t1 = tci_read_ri32(regs, &tb_ptr);
658 t2 = tci_read_ri32(regs, &tb_ptr);
659 tci_write_reg32(regs, t0, t1 / t2);
661 case INDEX_op_rem_i32:
663 t1 = tci_read_ri32(regs, &tb_ptr);
664 t2 = tci_read_ri32(regs, &tb_ptr);
665 tci_write_reg32(regs, t0, (int32_t)t1 % (int32_t)t2);
667 case INDEX_op_remu_i32:
669 t1 = tci_read_ri32(regs, &tb_ptr);
670 t2 = tci_read_ri32(regs, &tb_ptr);
671 tci_write_reg32(regs, t0, t1 % t2);
673 #elif TCG_TARGET_HAS_div2_i32
674 case INDEX_op_div2_i32:
675 case INDEX_op_divu2_i32:
679 case INDEX_op_and_i32:
681 t1 = tci_read_ri32(regs, &tb_ptr);
682 t2 = tci_read_ri32(regs, &tb_ptr);
683 tci_write_reg32(regs, t0, t1 & t2);
685 case INDEX_op_or_i32:
687 t1 = tci_read_ri32(regs, &tb_ptr);
688 t2 = tci_read_ri32(regs, &tb_ptr);
689 tci_write_reg32(regs, t0, t1 | t2);
691 case INDEX_op_xor_i32:
693 t1 = tci_read_ri32(regs, &tb_ptr);
694 t2 = tci_read_ri32(regs, &tb_ptr);
695 tci_write_reg32(regs, t0, t1 ^ t2);
698 /* Shift/rotate operations (32 bit). */
700 case INDEX_op_shl_i32:
702 t1 = tci_read_ri32(regs, &tb_ptr);
703 t2 = tci_read_ri32(regs, &tb_ptr);
704 tci_write_reg32(regs, t0, t1 << (t2 & 31));
706 case INDEX_op_shr_i32:
708 t1 = tci_read_ri32(regs, &tb_ptr);
709 t2 = tci_read_ri32(regs, &tb_ptr);
710 tci_write_reg32(regs, t0, t1 >> (t2 & 31));
712 case INDEX_op_sar_i32:
714 t1 = tci_read_ri32(regs, &tb_ptr);
715 t2 = tci_read_ri32(regs, &tb_ptr);
716 tci_write_reg32(regs, t0, ((int32_t)t1 >> (t2 & 31)));
718 #if TCG_TARGET_HAS_rot_i32
719 case INDEX_op_rotl_i32:
721 t1 = tci_read_ri32(regs, &tb_ptr);
722 t2 = tci_read_ri32(regs, &tb_ptr);
723 tci_write_reg32(regs, t0, rol32(t1, t2 & 31));
725 case INDEX_op_rotr_i32:
727 t1 = tci_read_ri32(regs, &tb_ptr);
728 t2 = tci_read_ri32(regs, &tb_ptr);
729 tci_write_reg32(regs, t0, ror32(t1, t2 & 31));
732 #if TCG_TARGET_HAS_deposit_i32
733 case INDEX_op_deposit_i32:
735 t1 = tci_read_r32(regs, &tb_ptr);
736 t2 = tci_read_r32(regs, &tb_ptr);
739 tmp32 = (((1 << tmp8) - 1) << tmp16);
740 tci_write_reg32(regs, t0, (t1 & ~tmp32) | ((t2 << tmp16) & tmp32));
743 case INDEX_op_brcond_i32:
744 t0 = tci_read_r32(regs, &tb_ptr);
745 t1 = tci_read_ri32(regs, &tb_ptr);
746 condition = *tb_ptr++;
747 label = tci_read_label(&tb_ptr);
748 if (tci_compare32(t0, t1, condition)) {
749 tci_assert(tb_ptr == old_code_ptr + op_size);
750 tb_ptr = (uint8_t *)label;
754 #if TCG_TARGET_REG_BITS == 32
755 case INDEX_op_add2_i32:
758 tmp64 = tci_read_r64(regs, &tb_ptr);
759 tmp64 += tci_read_r64(regs, &tb_ptr);
760 tci_write_reg64(regs, t1, t0, tmp64);
762 case INDEX_op_sub2_i32:
765 tmp64 = tci_read_r64(regs, &tb_ptr);
766 tmp64 -= tci_read_r64(regs, &tb_ptr);
767 tci_write_reg64(regs, t1, t0, tmp64);
769 case INDEX_op_brcond2_i32:
770 tmp64 = tci_read_r64(regs, &tb_ptr);
771 v64 = tci_read_ri64(regs, &tb_ptr);
772 condition = *tb_ptr++;
773 label = tci_read_label(&tb_ptr);
774 if (tci_compare64(tmp64, v64, condition)) {
775 tci_assert(tb_ptr == old_code_ptr + op_size);
776 tb_ptr = (uint8_t *)label;
780 case INDEX_op_mulu2_i32:
783 t2 = tci_read_r32(regs, &tb_ptr);
784 tmp64 = tci_read_r32(regs, &tb_ptr);
785 tci_write_reg64(regs, t1, t0, t2 * tmp64);
787 #endif /* TCG_TARGET_REG_BITS == 32 */
788 #if TCG_TARGET_HAS_ext8s_i32
789 case INDEX_op_ext8s_i32:
791 t1 = tci_read_r8s(regs, &tb_ptr);
792 tci_write_reg32(regs, t0, t1);
795 #if TCG_TARGET_HAS_ext16s_i32
796 case INDEX_op_ext16s_i32:
798 t1 = tci_read_r16s(regs, &tb_ptr);
799 tci_write_reg32(regs, t0, t1);
802 #if TCG_TARGET_HAS_ext8u_i32
803 case INDEX_op_ext8u_i32:
805 t1 = tci_read_r8(regs, &tb_ptr);
806 tci_write_reg32(regs, t0, t1);
809 #if TCG_TARGET_HAS_ext16u_i32
810 case INDEX_op_ext16u_i32:
812 t1 = tci_read_r16(regs, &tb_ptr);
813 tci_write_reg32(regs, t0, t1);
816 #if TCG_TARGET_HAS_bswap16_i32
817 case INDEX_op_bswap16_i32:
819 t1 = tci_read_r16(regs, &tb_ptr);
820 tci_write_reg32(regs, t0, bswap16(t1));
823 #if TCG_TARGET_HAS_bswap32_i32
824 case INDEX_op_bswap32_i32:
826 t1 = tci_read_r32(regs, &tb_ptr);
827 tci_write_reg32(regs, t0, bswap32(t1));
830 #if TCG_TARGET_HAS_not_i32
831 case INDEX_op_not_i32:
833 t1 = tci_read_r32(regs, &tb_ptr);
834 tci_write_reg32(regs, t0, ~t1);
837 #if TCG_TARGET_HAS_neg_i32
838 case INDEX_op_neg_i32:
840 t1 = tci_read_r32(regs, &tb_ptr);
841 tci_write_reg32(regs, t0, -t1);
844 #if TCG_TARGET_REG_BITS == 64
845 case INDEX_op_mov_i64:
847 t1 = tci_read_r64(regs, &tb_ptr);
848 tci_write_reg64(regs, t0, t1);
850 case INDEX_op_movi_i64:
852 t1 = tci_read_i64(&tb_ptr);
853 tci_write_reg64(regs, t0, t1);
856 /* Load/store operations (64 bit). */
858 case INDEX_op_ld8u_i64:
860 t1 = tci_read_r(regs, &tb_ptr);
861 t2 = tci_read_s32(&tb_ptr);
862 tci_write_reg8(regs, t0, *(uint8_t *)(t1 + t2));
864 case INDEX_op_ld8s_i64:
867 case INDEX_op_ld16u_i64:
869 t1 = tci_read_r(regs, &tb_ptr);
870 t2 = tci_read_s32(&tb_ptr);
871 tci_write_reg16(regs, t0, *(uint16_t *)(t1 + t2));
873 case INDEX_op_ld16s_i64:
876 case INDEX_op_ld32u_i64:
878 t1 = tci_read_r(regs, &tb_ptr);
879 t2 = tci_read_s32(&tb_ptr);
880 tci_write_reg32(regs, t0, *(uint32_t *)(t1 + t2));
882 case INDEX_op_ld32s_i64:
884 t1 = tci_read_r(regs, &tb_ptr);
885 t2 = tci_read_s32(&tb_ptr);
886 tci_write_reg32s(regs, t0, *(int32_t *)(t1 + t2));
888 case INDEX_op_ld_i64:
890 t1 = tci_read_r(regs, &tb_ptr);
891 t2 = tci_read_s32(&tb_ptr);
892 tci_write_reg64(regs, t0, *(uint64_t *)(t1 + t2));
894 case INDEX_op_st8_i64:
895 t0 = tci_read_r8(regs, &tb_ptr);
896 t1 = tci_read_r(regs, &tb_ptr);
897 t2 = tci_read_s32(&tb_ptr);
898 *(uint8_t *)(t1 + t2) = t0;
900 case INDEX_op_st16_i64:
901 t0 = tci_read_r16(regs, &tb_ptr);
902 t1 = tci_read_r(regs, &tb_ptr);
903 t2 = tci_read_s32(&tb_ptr);
904 *(uint16_t *)(t1 + t2) = t0;
906 case INDEX_op_st32_i64:
907 t0 = tci_read_r32(regs, &tb_ptr);
908 t1 = tci_read_r(regs, &tb_ptr);
909 t2 = tci_read_s32(&tb_ptr);
910 *(uint32_t *)(t1 + t2) = t0;
912 case INDEX_op_st_i64:
913 t0 = tci_read_r64(regs, &tb_ptr);
914 t1 = tci_read_r(regs, &tb_ptr);
915 t2 = tci_read_s32(&tb_ptr);
916 tci_assert(t1 != sp_value || (int32_t)t2 < 0);
917 *(uint64_t *)(t1 + t2) = t0;
920 /* Arithmetic operations (64 bit). */
922 case INDEX_op_add_i64:
924 t1 = tci_read_ri64(regs, &tb_ptr);
925 t2 = tci_read_ri64(regs, &tb_ptr);
926 tci_write_reg64(regs, t0, t1 + t2);
928 case INDEX_op_sub_i64:
930 t1 = tci_read_ri64(regs, &tb_ptr);
931 t2 = tci_read_ri64(regs, &tb_ptr);
932 tci_write_reg64(regs, t0, t1 - t2);
934 case INDEX_op_mul_i64:
936 t1 = tci_read_ri64(regs, &tb_ptr);
937 t2 = tci_read_ri64(regs, &tb_ptr);
938 tci_write_reg64(regs, t0, t1 * t2);
940 #if TCG_TARGET_HAS_div_i64
941 case INDEX_op_div_i64:
942 case INDEX_op_divu_i64:
943 case INDEX_op_rem_i64:
944 case INDEX_op_remu_i64:
947 #elif TCG_TARGET_HAS_div2_i64
948 case INDEX_op_div2_i64:
949 case INDEX_op_divu2_i64:
953 case INDEX_op_and_i64:
955 t1 = tci_read_ri64(regs, &tb_ptr);
956 t2 = tci_read_ri64(regs, &tb_ptr);
957 tci_write_reg64(regs, t0, t1 & t2);
959 case INDEX_op_or_i64:
961 t1 = tci_read_ri64(regs, &tb_ptr);
962 t2 = tci_read_ri64(regs, &tb_ptr);
963 tci_write_reg64(regs, t0, t1 | t2);
965 case INDEX_op_xor_i64:
967 t1 = tci_read_ri64(regs, &tb_ptr);
968 t2 = tci_read_ri64(regs, &tb_ptr);
969 tci_write_reg64(regs, t0, t1 ^ t2);
972 /* Shift/rotate operations (64 bit). */
974 case INDEX_op_shl_i64:
976 t1 = tci_read_ri64(regs, &tb_ptr);
977 t2 = tci_read_ri64(regs, &tb_ptr);
978 tci_write_reg64(regs, t0, t1 << (t2 & 63));
980 case INDEX_op_shr_i64:
982 t1 = tci_read_ri64(regs, &tb_ptr);
983 t2 = tci_read_ri64(regs, &tb_ptr);
984 tci_write_reg64(regs, t0, t1 >> (t2 & 63));
986 case INDEX_op_sar_i64:
988 t1 = tci_read_ri64(regs, &tb_ptr);
989 t2 = tci_read_ri64(regs, &tb_ptr);
990 tci_write_reg64(regs, t0, ((int64_t)t1 >> (t2 & 63)));
992 #if TCG_TARGET_HAS_rot_i64
993 case INDEX_op_rotl_i64:
995 t1 = tci_read_ri64(regs, &tb_ptr);
996 t2 = tci_read_ri64(regs, &tb_ptr);
997 tci_write_reg64(regs, t0, rol64(t1, t2 & 63));
999 case INDEX_op_rotr_i64:
1001 t1 = tci_read_ri64(regs, &tb_ptr);
1002 t2 = tci_read_ri64(regs, &tb_ptr);
1003 tci_write_reg64(regs, t0, ror64(t1, t2 & 63));
1006 #if TCG_TARGET_HAS_deposit_i64
1007 case INDEX_op_deposit_i64:
1009 t1 = tci_read_r64(regs, &tb_ptr);
1010 t2 = tci_read_r64(regs, &tb_ptr);
1013 tmp64 = (((1ULL << tmp8) - 1) << tmp16);
1014 tci_write_reg64(regs, t0, (t1 & ~tmp64) | ((t2 << tmp16) & tmp64));
1017 case INDEX_op_brcond_i64:
1018 t0 = tci_read_r64(regs, &tb_ptr);
1019 t1 = tci_read_ri64(regs, &tb_ptr);
1020 condition = *tb_ptr++;
1021 label = tci_read_label(&tb_ptr);
1022 if (tci_compare64(t0, t1, condition)) {
1023 tci_assert(tb_ptr == old_code_ptr + op_size);
1024 tb_ptr = (uint8_t *)label;
1028 #if TCG_TARGET_HAS_ext8u_i64
1029 case INDEX_op_ext8u_i64:
1031 t1 = tci_read_r8(regs, &tb_ptr);
1032 tci_write_reg64(regs, t0, t1);
1035 #if TCG_TARGET_HAS_ext8s_i64
1036 case INDEX_op_ext8s_i64:
1038 t1 = tci_read_r8s(regs, &tb_ptr);
1039 tci_write_reg64(regs, t0, t1);
1042 #if TCG_TARGET_HAS_ext16s_i64
1043 case INDEX_op_ext16s_i64:
1045 t1 = tci_read_r16s(regs, &tb_ptr);
1046 tci_write_reg64(regs, t0, t1);
1049 #if TCG_TARGET_HAS_ext16u_i64
1050 case INDEX_op_ext16u_i64:
1052 t1 = tci_read_r16(regs, &tb_ptr);
1053 tci_write_reg64(regs, t0, t1);
1056 #if TCG_TARGET_HAS_ext32s_i64
1057 case INDEX_op_ext32s_i64:
1059 case INDEX_op_ext_i32_i64:
1061 t1 = tci_read_r32s(regs, &tb_ptr);
1062 tci_write_reg64(regs, t0, t1);
1064 #if TCG_TARGET_HAS_ext32u_i64
1065 case INDEX_op_ext32u_i64:
1067 case INDEX_op_extu_i32_i64:
1069 t1 = tci_read_r32(regs, &tb_ptr);
1070 tci_write_reg64(regs, t0, t1);
1072 #if TCG_TARGET_HAS_bswap16_i64
1073 case INDEX_op_bswap16_i64:
1075 t1 = tci_read_r16(regs, &tb_ptr);
1076 tci_write_reg64(regs, t0, bswap16(t1));
1079 #if TCG_TARGET_HAS_bswap32_i64
1080 case INDEX_op_bswap32_i64:
1082 t1 = tci_read_r32(regs, &tb_ptr);
1083 tci_write_reg64(regs, t0, bswap32(t1));
1086 #if TCG_TARGET_HAS_bswap64_i64
1087 case INDEX_op_bswap64_i64:
1089 t1 = tci_read_r64(regs, &tb_ptr);
1090 tci_write_reg64(regs, t0, bswap64(t1));
1093 #if TCG_TARGET_HAS_not_i64
1094 case INDEX_op_not_i64:
1096 t1 = tci_read_r64(regs, &tb_ptr);
1097 tci_write_reg64(regs, t0, ~t1);
1100 #if TCG_TARGET_HAS_neg_i64
1101 case INDEX_op_neg_i64:
1103 t1 = tci_read_r64(regs, &tb_ptr);
1104 tci_write_reg64(regs, t0, -t1);
1107 #endif /* TCG_TARGET_REG_BITS == 64 */
1109 /* QEMU specific operations. */
1111 case INDEX_op_exit_tb:
1112 ret = *(uint64_t *)tb_ptr;
1115 case INDEX_op_goto_tb:
1116 /* Jump address is aligned */
1117 tb_ptr = QEMU_ALIGN_PTR_UP(tb_ptr, 4);
1118 t0 = atomic_read((int32_t *)tb_ptr);
1119 tb_ptr += sizeof(int32_t);
1120 tci_assert(tb_ptr == old_code_ptr + op_size);
1121 tb_ptr += (int32_t)t0;
1123 case INDEX_op_qemu_ld_i32:
1125 taddr = tci_read_ulong(regs, &tb_ptr);
1126 oi = tci_read_i(&tb_ptr);
1127 switch (get_memop(oi) & (MO_BSWAP | MO_SSIZE)) {
1132 tmp32 = (int8_t)qemu_ld_ub;
1135 tmp32 = qemu_ld_leuw;
1138 tmp32 = (int16_t)qemu_ld_leuw;
1141 tmp32 = qemu_ld_leul;
1144 tmp32 = qemu_ld_beuw;
1147 tmp32 = (int16_t)qemu_ld_beuw;
1150 tmp32 = qemu_ld_beul;
1155 tci_write_reg(regs, t0, tmp32);
1157 case INDEX_op_qemu_ld_i64:
1159 if (TCG_TARGET_REG_BITS == 32) {
1162 taddr = tci_read_ulong(regs, &tb_ptr);
1163 oi = tci_read_i(&tb_ptr);
1164 switch (get_memop(oi) & (MO_BSWAP | MO_SSIZE)) {
1169 tmp64 = (int8_t)qemu_ld_ub;
1172 tmp64 = qemu_ld_leuw;
1175 tmp64 = (int16_t)qemu_ld_leuw;
1178 tmp64 = qemu_ld_leul;
1181 tmp64 = (int32_t)qemu_ld_leul;
1184 tmp64 = qemu_ld_leq;
1187 tmp64 = qemu_ld_beuw;
1190 tmp64 = (int16_t)qemu_ld_beuw;
1193 tmp64 = qemu_ld_beul;
1196 tmp64 = (int32_t)qemu_ld_beul;
1199 tmp64 = qemu_ld_beq;
1204 tci_write_reg(regs, t0, tmp64);
1205 if (TCG_TARGET_REG_BITS == 32) {
1206 tci_write_reg(regs, t1, tmp64 >> 32);
1209 case INDEX_op_qemu_st_i32:
1210 t0 = tci_read_r(regs, &tb_ptr);
1211 taddr = tci_read_ulong(regs, &tb_ptr);
1212 oi = tci_read_i(&tb_ptr);
1213 switch (get_memop(oi) & (MO_BSWAP | MO_SIZE)) {
1233 case INDEX_op_qemu_st_i64:
1234 tmp64 = tci_read_r64(regs, &tb_ptr);
1235 taddr = tci_read_ulong(regs, &tb_ptr);
1236 oi = tci_read_i(&tb_ptr);
1237 switch (get_memop(oi) & (MO_BSWAP | MO_SIZE)) {
1264 /* Ensure ordering for all kinds */
1271 tci_assert(tb_ptr == old_code_ptr + op_size);