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 "exec/exec-all.h" /* MAX_OPC_PARAM_IARGS */
32 #include "exec/cpu_ldst.h"
35 /* Marker for missing code. */
38 fprintf(stderr, "TODO %s:%u: %s()\n", \
39 __FILE__, __LINE__, __func__); \
43 #if MAX_OPC_PARAM_IARGS != 5
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
);
53 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
54 tcg_target_ulong
, tcg_target_ulong
,
58 static tcg_target_ulong tci_reg
[TCG_TARGET_NB_REGS
];
60 static tcg_target_ulong
tci_read_reg(TCGReg index
)
62 tci_assert(index
< ARRAY_SIZE(tci_reg
));
63 return tci_reg
[index
];
66 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
67 static int8_t tci_read_reg8s(TCGReg index
)
69 return (int8_t)tci_read_reg(index
);
73 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
74 static int16_t tci_read_reg16s(TCGReg index
)
76 return (int16_t)tci_read_reg(index
);
80 #if TCG_TARGET_REG_BITS == 64
81 static int32_t tci_read_reg32s(TCGReg index
)
83 return (int32_t)tci_read_reg(index
);
87 static uint8_t tci_read_reg8(TCGReg index
)
89 return (uint8_t)tci_read_reg(index
);
92 static uint16_t tci_read_reg16(TCGReg index
)
94 return (uint16_t)tci_read_reg(index
);
97 static uint32_t tci_read_reg32(TCGReg index
)
99 return (uint32_t)tci_read_reg(index
);
102 #if TCG_TARGET_REG_BITS == 64
103 static uint64_t tci_read_reg64(TCGReg index
)
105 return tci_read_reg(index
);
109 static void tci_write_reg(TCGReg index
, tcg_target_ulong value
)
111 tci_assert(index
< ARRAY_SIZE(tci_reg
));
112 tci_assert(index
!= TCG_AREG0
);
113 tci_assert(index
!= TCG_REG_CALL_STACK
);
114 tci_reg
[index
] = value
;
117 #if TCG_TARGET_REG_BITS == 64
118 static void tci_write_reg32s(TCGReg index
, int32_t value
)
120 tci_write_reg(index
, value
);
124 static void tci_write_reg8(TCGReg index
, uint8_t value
)
126 tci_write_reg(index
, value
);
129 static void tci_write_reg32(TCGReg index
, uint32_t value
)
131 tci_write_reg(index
, value
);
134 #if TCG_TARGET_REG_BITS == 32
135 static void tci_write_reg64(uint32_t high_index
, uint32_t low_index
,
138 tci_write_reg(low_index
, value
);
139 tci_write_reg(high_index
, value
>> 32);
141 #elif TCG_TARGET_REG_BITS == 64
142 static void tci_write_reg64(TCGReg index
, uint64_t value
)
144 tci_write_reg(index
, value
);
148 #if TCG_TARGET_REG_BITS == 32
149 /* Create a 64 bit value from two 32 bit values. */
150 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
152 return ((uint64_t)high
<< 32) + low
;
156 /* Read constant (native size) from bytecode. */
157 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
159 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
160 *tb_ptr
+= sizeof(value
);
164 /* Read unsigned constant (32 bit) from bytecode. */
165 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
167 uint32_t value
= *(uint32_t *)(*tb_ptr
);
168 *tb_ptr
+= sizeof(value
);
172 /* Read signed constant (32 bit) from bytecode. */
173 static int32_t tci_read_s32(uint8_t **tb_ptr
)
175 int32_t value
= *(int32_t *)(*tb_ptr
);
176 *tb_ptr
+= sizeof(value
);
180 #if TCG_TARGET_REG_BITS == 64
181 /* Read constant (64 bit) from bytecode. */
182 static uint64_t tci_read_i64(uint8_t **tb_ptr
)
184 uint64_t value
= *(uint64_t *)(*tb_ptr
);
185 *tb_ptr
+= sizeof(value
);
190 /* Read indexed register (native size) from bytecode. */
191 static tcg_target_ulong
tci_read_r(uint8_t **tb_ptr
)
193 tcg_target_ulong value
= tci_read_reg(**tb_ptr
);
198 /* Read indexed register (8 bit) from bytecode. */
199 static uint8_t tci_read_r8(uint8_t **tb_ptr
)
201 uint8_t value
= tci_read_reg8(**tb_ptr
);
206 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
207 /* Read indexed register (8 bit signed) from bytecode. */
208 static int8_t tci_read_r8s(uint8_t **tb_ptr
)
210 int8_t value
= tci_read_reg8s(**tb_ptr
);
216 /* Read indexed register (16 bit) from bytecode. */
217 static uint16_t tci_read_r16(uint8_t **tb_ptr
)
219 uint16_t value
= tci_read_reg16(**tb_ptr
);
224 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
225 /* Read indexed register (16 bit signed) from bytecode. */
226 static int16_t tci_read_r16s(uint8_t **tb_ptr
)
228 int16_t value
= tci_read_reg16s(**tb_ptr
);
234 /* Read indexed register (32 bit) from bytecode. */
235 static uint32_t tci_read_r32(uint8_t **tb_ptr
)
237 uint32_t value
= tci_read_reg32(**tb_ptr
);
242 #if TCG_TARGET_REG_BITS == 32
243 /* Read two indexed registers (2 * 32 bit) from bytecode. */
244 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
246 uint32_t low
= tci_read_r32(tb_ptr
);
247 return tci_uint64(tci_read_r32(tb_ptr
), low
);
249 #elif TCG_TARGET_REG_BITS == 64
250 /* Read indexed register (32 bit signed) from bytecode. */
251 static int32_t tci_read_r32s(uint8_t **tb_ptr
)
253 int32_t value
= tci_read_reg32s(**tb_ptr
);
258 /* Read indexed register (64 bit) from bytecode. */
259 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
261 uint64_t value
= tci_read_reg64(**tb_ptr
);
267 /* Read indexed register(s) with target address from bytecode. */
268 static target_ulong
tci_read_ulong(uint8_t **tb_ptr
)
270 target_ulong taddr
= tci_read_r(tb_ptr
);
271 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
272 taddr
+= (uint64_t)tci_read_r(tb_ptr
) << 32;
277 /* Read indexed register or constant (native size) from bytecode. */
278 static tcg_target_ulong
tci_read_ri(uint8_t **tb_ptr
)
280 tcg_target_ulong value
;
283 if (r
== TCG_CONST
) {
284 value
= tci_read_i(tb_ptr
);
286 value
= tci_read_reg(r
);
291 /* Read indexed register or constant (32 bit) from bytecode. */
292 static uint32_t tci_read_ri32(uint8_t **tb_ptr
)
297 if (r
== TCG_CONST
) {
298 value
= tci_read_i32(tb_ptr
);
300 value
= tci_read_reg32(r
);
305 #if TCG_TARGET_REG_BITS == 32
306 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
307 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
309 uint32_t low
= tci_read_ri32(tb_ptr
);
310 return tci_uint64(tci_read_ri32(tb_ptr
), low
);
312 #elif TCG_TARGET_REG_BITS == 64
313 /* Read indexed register or constant (64 bit) from bytecode. */
314 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
319 if (r
== TCG_CONST
) {
320 value
= tci_read_i64(tb_ptr
);
322 value
= tci_read_reg64(r
);
328 static tcg_target_ulong
tci_read_label(uint8_t **tb_ptr
)
330 tcg_target_ulong label
= tci_read_i(tb_ptr
);
331 tci_assert(label
!= 0);
335 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
377 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
419 #ifdef CONFIG_SOFTMMU
420 # define qemu_ld_ub \
421 helper_ret_ldub_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
422 # define qemu_ld_leuw \
423 helper_le_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
424 # define qemu_ld_leul \
425 helper_le_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
426 # define qemu_ld_leq \
427 helper_le_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
428 # define qemu_ld_beuw \
429 helper_be_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
430 # define qemu_ld_beul \
431 helper_be_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
432 # define qemu_ld_beq \
433 helper_be_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
434 # define qemu_st_b(X) \
435 helper_ret_stb_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
436 # define qemu_st_lew(X) \
437 helper_le_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
438 # define qemu_st_lel(X) \
439 helper_le_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
440 # define qemu_st_leq(X) \
441 helper_le_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
442 # define qemu_st_bew(X) \
443 helper_be_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
444 # define qemu_st_bel(X) \
445 helper_be_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
446 # define qemu_st_beq(X) \
447 helper_be_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
449 # define qemu_ld_ub ldub_p(g2h(taddr))
450 # define qemu_ld_leuw lduw_le_p(g2h(taddr))
451 # define qemu_ld_leul (uint32_t)ldl_le_p(g2h(taddr))
452 # define qemu_ld_leq ldq_le_p(g2h(taddr))
453 # define qemu_ld_beuw lduw_be_p(g2h(taddr))
454 # define qemu_ld_beul (uint32_t)ldl_be_p(g2h(taddr))
455 # define qemu_ld_beq ldq_be_p(g2h(taddr))
456 # define qemu_st_b(X) stb_p(g2h(taddr), X)
457 # define qemu_st_lew(X) stw_le_p(g2h(taddr), X)
458 # define qemu_st_lel(X) stl_le_p(g2h(taddr), X)
459 # define qemu_st_leq(X) stq_le_p(g2h(taddr), X)
460 # define qemu_st_bew(X) stw_be_p(g2h(taddr), X)
461 # define qemu_st_bel(X) stl_be_p(g2h(taddr), X)
462 # define qemu_st_beq(X) stq_be_p(g2h(taddr), X)
465 /* Interpret pseudo code in tb. */
466 uintptr_t tcg_qemu_tb_exec(CPUArchState
*env
, uint8_t *tb_ptr
)
468 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
469 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
470 uintptr_t next_tb
= 0;
472 tci_reg
[TCG_AREG0
] = (tcg_target_ulong
)env
;
473 tci_reg
[TCG_REG_CALL_STACK
] = sp_value
;
477 TCGOpcode opc
= tb_ptr
[0];
478 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
479 uint8_t op_size
= tb_ptr
[1];
480 uint8_t *old_code_ptr
= tb_ptr
;
485 tcg_target_ulong label
;
492 #if TCG_TARGET_REG_BITS == 32
498 tci_tb_ptr
= (uintptr_t)tb_ptr
;
501 /* Skip opcode and size entry. */
506 t0
= tci_read_ri(&tb_ptr
);
507 #if TCG_TARGET_REG_BITS == 32
508 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
509 tci_read_reg(TCG_REG_R1
),
510 tci_read_reg(TCG_REG_R2
),
511 tci_read_reg(TCG_REG_R3
),
512 tci_read_reg(TCG_REG_R5
),
513 tci_read_reg(TCG_REG_R6
),
514 tci_read_reg(TCG_REG_R7
),
515 tci_read_reg(TCG_REG_R8
),
516 tci_read_reg(TCG_REG_R9
),
517 tci_read_reg(TCG_REG_R10
));
518 tci_write_reg(TCG_REG_R0
, tmp64
);
519 tci_write_reg(TCG_REG_R1
, tmp64
>> 32);
521 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
522 tci_read_reg(TCG_REG_R1
),
523 tci_read_reg(TCG_REG_R2
),
524 tci_read_reg(TCG_REG_R3
),
525 tci_read_reg(TCG_REG_R5
));
526 tci_write_reg(TCG_REG_R0
, tmp64
);
530 label
= tci_read_label(&tb_ptr
);
531 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
532 tb_ptr
= (uint8_t *)label
;
534 case INDEX_op_setcond_i32
:
536 t1
= tci_read_r32(&tb_ptr
);
537 t2
= tci_read_ri32(&tb_ptr
);
538 condition
= *tb_ptr
++;
539 tci_write_reg32(t0
, tci_compare32(t1
, t2
, condition
));
541 #if TCG_TARGET_REG_BITS == 32
542 case INDEX_op_setcond2_i32
:
544 tmp64
= tci_read_r64(&tb_ptr
);
545 v64
= tci_read_ri64(&tb_ptr
);
546 condition
= *tb_ptr
++;
547 tci_write_reg32(t0
, tci_compare64(tmp64
, v64
, condition
));
549 #elif TCG_TARGET_REG_BITS == 64
550 case INDEX_op_setcond_i64
:
552 t1
= tci_read_r64(&tb_ptr
);
553 t2
= tci_read_ri64(&tb_ptr
);
554 condition
= *tb_ptr
++;
555 tci_write_reg64(t0
, tci_compare64(t1
, t2
, condition
));
558 case INDEX_op_mov_i32
:
560 t1
= tci_read_r32(&tb_ptr
);
561 tci_write_reg32(t0
, t1
);
563 case INDEX_op_movi_i32
:
565 t1
= tci_read_i32(&tb_ptr
);
566 tci_write_reg32(t0
, t1
);
569 /* Load/store operations (32 bit). */
571 case INDEX_op_ld8u_i32
:
573 t1
= tci_read_r(&tb_ptr
);
574 t2
= tci_read_s32(&tb_ptr
);
575 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
577 case INDEX_op_ld8s_i32
:
578 case INDEX_op_ld16u_i32
:
581 case INDEX_op_ld16s_i32
:
584 case INDEX_op_ld_i32
:
586 t1
= tci_read_r(&tb_ptr
);
587 t2
= tci_read_s32(&tb_ptr
);
588 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
590 case INDEX_op_st8_i32
:
591 t0
= tci_read_r8(&tb_ptr
);
592 t1
= tci_read_r(&tb_ptr
);
593 t2
= tci_read_s32(&tb_ptr
);
594 *(uint8_t *)(t1
+ t2
) = t0
;
596 case INDEX_op_st16_i32
:
597 t0
= tci_read_r16(&tb_ptr
);
598 t1
= tci_read_r(&tb_ptr
);
599 t2
= tci_read_s32(&tb_ptr
);
600 *(uint16_t *)(t1
+ t2
) = t0
;
602 case INDEX_op_st_i32
:
603 t0
= tci_read_r32(&tb_ptr
);
604 t1
= tci_read_r(&tb_ptr
);
605 t2
= tci_read_s32(&tb_ptr
);
606 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
607 *(uint32_t *)(t1
+ t2
) = t0
;
610 /* Arithmetic operations (32 bit). */
612 case INDEX_op_add_i32
:
614 t1
= tci_read_ri32(&tb_ptr
);
615 t2
= tci_read_ri32(&tb_ptr
);
616 tci_write_reg32(t0
, t1
+ t2
);
618 case INDEX_op_sub_i32
:
620 t1
= tci_read_ri32(&tb_ptr
);
621 t2
= tci_read_ri32(&tb_ptr
);
622 tci_write_reg32(t0
, t1
- t2
);
624 case INDEX_op_mul_i32
:
626 t1
= tci_read_ri32(&tb_ptr
);
627 t2
= tci_read_ri32(&tb_ptr
);
628 tci_write_reg32(t0
, t1
* t2
);
630 #if TCG_TARGET_HAS_div_i32
631 case INDEX_op_div_i32
:
633 t1
= tci_read_ri32(&tb_ptr
);
634 t2
= tci_read_ri32(&tb_ptr
);
635 tci_write_reg32(t0
, (int32_t)t1
/ (int32_t)t2
);
637 case INDEX_op_divu_i32
:
639 t1
= tci_read_ri32(&tb_ptr
);
640 t2
= tci_read_ri32(&tb_ptr
);
641 tci_write_reg32(t0
, t1
/ t2
);
643 case INDEX_op_rem_i32
:
645 t1
= tci_read_ri32(&tb_ptr
);
646 t2
= tci_read_ri32(&tb_ptr
);
647 tci_write_reg32(t0
, (int32_t)t1
% (int32_t)t2
);
649 case INDEX_op_remu_i32
:
651 t1
= tci_read_ri32(&tb_ptr
);
652 t2
= tci_read_ri32(&tb_ptr
);
653 tci_write_reg32(t0
, t1
% t2
);
655 #elif TCG_TARGET_HAS_div2_i32
656 case INDEX_op_div2_i32
:
657 case INDEX_op_divu2_i32
:
661 case INDEX_op_and_i32
:
663 t1
= tci_read_ri32(&tb_ptr
);
664 t2
= tci_read_ri32(&tb_ptr
);
665 tci_write_reg32(t0
, t1
& t2
);
667 case INDEX_op_or_i32
:
669 t1
= tci_read_ri32(&tb_ptr
);
670 t2
= tci_read_ri32(&tb_ptr
);
671 tci_write_reg32(t0
, t1
| t2
);
673 case INDEX_op_xor_i32
:
675 t1
= tci_read_ri32(&tb_ptr
);
676 t2
= tci_read_ri32(&tb_ptr
);
677 tci_write_reg32(t0
, t1
^ t2
);
680 /* Shift/rotate operations (32 bit). */
682 case INDEX_op_shl_i32
:
684 t1
= tci_read_ri32(&tb_ptr
);
685 t2
= tci_read_ri32(&tb_ptr
);
686 tci_write_reg32(t0
, t1
<< (t2
& 31));
688 case INDEX_op_shr_i32
:
690 t1
= tci_read_ri32(&tb_ptr
);
691 t2
= tci_read_ri32(&tb_ptr
);
692 tci_write_reg32(t0
, t1
>> (t2
& 31));
694 case INDEX_op_sar_i32
:
696 t1
= tci_read_ri32(&tb_ptr
);
697 t2
= tci_read_ri32(&tb_ptr
);
698 tci_write_reg32(t0
, ((int32_t)t1
>> (t2
& 31)));
700 #if TCG_TARGET_HAS_rot_i32
701 case INDEX_op_rotl_i32
:
703 t1
= tci_read_ri32(&tb_ptr
);
704 t2
= tci_read_ri32(&tb_ptr
);
705 tci_write_reg32(t0
, rol32(t1
, t2
& 31));
707 case INDEX_op_rotr_i32
:
709 t1
= tci_read_ri32(&tb_ptr
);
710 t2
= tci_read_ri32(&tb_ptr
);
711 tci_write_reg32(t0
, ror32(t1
, t2
& 31));
714 #if TCG_TARGET_HAS_deposit_i32
715 case INDEX_op_deposit_i32
:
717 t1
= tci_read_r32(&tb_ptr
);
718 t2
= tci_read_r32(&tb_ptr
);
721 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
722 tci_write_reg32(t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
725 case INDEX_op_brcond_i32
:
726 t0
= tci_read_r32(&tb_ptr
);
727 t1
= tci_read_ri32(&tb_ptr
);
728 condition
= *tb_ptr
++;
729 label
= tci_read_label(&tb_ptr
);
730 if (tci_compare32(t0
, t1
, condition
)) {
731 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
732 tb_ptr
= (uint8_t *)label
;
736 #if TCG_TARGET_REG_BITS == 32
737 case INDEX_op_add2_i32
:
740 tmp64
= tci_read_r64(&tb_ptr
);
741 tmp64
+= tci_read_r64(&tb_ptr
);
742 tci_write_reg64(t1
, t0
, tmp64
);
744 case INDEX_op_sub2_i32
:
747 tmp64
= tci_read_r64(&tb_ptr
);
748 tmp64
-= tci_read_r64(&tb_ptr
);
749 tci_write_reg64(t1
, t0
, tmp64
);
751 case INDEX_op_brcond2_i32
:
752 tmp64
= tci_read_r64(&tb_ptr
);
753 v64
= tci_read_ri64(&tb_ptr
);
754 condition
= *tb_ptr
++;
755 label
= tci_read_label(&tb_ptr
);
756 if (tci_compare64(tmp64
, v64
, condition
)) {
757 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
758 tb_ptr
= (uint8_t *)label
;
762 case INDEX_op_mulu2_i32
:
765 t2
= tci_read_r32(&tb_ptr
);
766 tmp64
= tci_read_r32(&tb_ptr
);
767 tci_write_reg64(t1
, t0
, t2
* tmp64
);
769 #endif /* TCG_TARGET_REG_BITS == 32 */
770 #if TCG_TARGET_HAS_ext8s_i32
771 case INDEX_op_ext8s_i32
:
773 t1
= tci_read_r8s(&tb_ptr
);
774 tci_write_reg32(t0
, t1
);
777 #if TCG_TARGET_HAS_ext16s_i32
778 case INDEX_op_ext16s_i32
:
780 t1
= tci_read_r16s(&tb_ptr
);
781 tci_write_reg32(t0
, t1
);
784 #if TCG_TARGET_HAS_ext8u_i32
785 case INDEX_op_ext8u_i32
:
787 t1
= tci_read_r8(&tb_ptr
);
788 tci_write_reg32(t0
, t1
);
791 #if TCG_TARGET_HAS_ext16u_i32
792 case INDEX_op_ext16u_i32
:
794 t1
= tci_read_r16(&tb_ptr
);
795 tci_write_reg32(t0
, t1
);
798 #if TCG_TARGET_HAS_bswap16_i32
799 case INDEX_op_bswap16_i32
:
801 t1
= tci_read_r16(&tb_ptr
);
802 tci_write_reg32(t0
, bswap16(t1
));
805 #if TCG_TARGET_HAS_bswap32_i32
806 case INDEX_op_bswap32_i32
:
808 t1
= tci_read_r32(&tb_ptr
);
809 tci_write_reg32(t0
, bswap32(t1
));
812 #if TCG_TARGET_HAS_not_i32
813 case INDEX_op_not_i32
:
815 t1
= tci_read_r32(&tb_ptr
);
816 tci_write_reg32(t0
, ~t1
);
819 #if TCG_TARGET_HAS_neg_i32
820 case INDEX_op_neg_i32
:
822 t1
= tci_read_r32(&tb_ptr
);
823 tci_write_reg32(t0
, -t1
);
826 #if TCG_TARGET_REG_BITS == 64
827 case INDEX_op_mov_i64
:
829 t1
= tci_read_r64(&tb_ptr
);
830 tci_write_reg64(t0
, t1
);
832 case INDEX_op_movi_i64
:
834 t1
= tci_read_i64(&tb_ptr
);
835 tci_write_reg64(t0
, t1
);
838 /* Load/store operations (64 bit). */
840 case INDEX_op_ld8u_i64
:
842 t1
= tci_read_r(&tb_ptr
);
843 t2
= tci_read_s32(&tb_ptr
);
844 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
846 case INDEX_op_ld8s_i64
:
847 case INDEX_op_ld16u_i64
:
848 case INDEX_op_ld16s_i64
:
851 case INDEX_op_ld32u_i64
:
853 t1
= tci_read_r(&tb_ptr
);
854 t2
= tci_read_s32(&tb_ptr
);
855 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
857 case INDEX_op_ld32s_i64
:
859 t1
= tci_read_r(&tb_ptr
);
860 t2
= tci_read_s32(&tb_ptr
);
861 tci_write_reg32s(t0
, *(int32_t *)(t1
+ t2
));
863 case INDEX_op_ld_i64
:
865 t1
= tci_read_r(&tb_ptr
);
866 t2
= tci_read_s32(&tb_ptr
);
867 tci_write_reg64(t0
, *(uint64_t *)(t1
+ t2
));
869 case INDEX_op_st8_i64
:
870 t0
= tci_read_r8(&tb_ptr
);
871 t1
= tci_read_r(&tb_ptr
);
872 t2
= tci_read_s32(&tb_ptr
);
873 *(uint8_t *)(t1
+ t2
) = t0
;
875 case INDEX_op_st16_i64
:
876 t0
= tci_read_r16(&tb_ptr
);
877 t1
= tci_read_r(&tb_ptr
);
878 t2
= tci_read_s32(&tb_ptr
);
879 *(uint16_t *)(t1
+ t2
) = t0
;
881 case INDEX_op_st32_i64
:
882 t0
= tci_read_r32(&tb_ptr
);
883 t1
= tci_read_r(&tb_ptr
);
884 t2
= tci_read_s32(&tb_ptr
);
885 *(uint32_t *)(t1
+ t2
) = t0
;
887 case INDEX_op_st_i64
:
888 t0
= tci_read_r64(&tb_ptr
);
889 t1
= tci_read_r(&tb_ptr
);
890 t2
= tci_read_s32(&tb_ptr
);
891 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
892 *(uint64_t *)(t1
+ t2
) = t0
;
895 /* Arithmetic operations (64 bit). */
897 case INDEX_op_add_i64
:
899 t1
= tci_read_ri64(&tb_ptr
);
900 t2
= tci_read_ri64(&tb_ptr
);
901 tci_write_reg64(t0
, t1
+ t2
);
903 case INDEX_op_sub_i64
:
905 t1
= tci_read_ri64(&tb_ptr
);
906 t2
= tci_read_ri64(&tb_ptr
);
907 tci_write_reg64(t0
, t1
- t2
);
909 case INDEX_op_mul_i64
:
911 t1
= tci_read_ri64(&tb_ptr
);
912 t2
= tci_read_ri64(&tb_ptr
);
913 tci_write_reg64(t0
, t1
* t2
);
915 #if TCG_TARGET_HAS_div_i64
916 case INDEX_op_div_i64
:
917 case INDEX_op_divu_i64
:
918 case INDEX_op_rem_i64
:
919 case INDEX_op_remu_i64
:
922 #elif TCG_TARGET_HAS_div2_i64
923 case INDEX_op_div2_i64
:
924 case INDEX_op_divu2_i64
:
928 case INDEX_op_and_i64
:
930 t1
= tci_read_ri64(&tb_ptr
);
931 t2
= tci_read_ri64(&tb_ptr
);
932 tci_write_reg64(t0
, t1
& t2
);
934 case INDEX_op_or_i64
:
936 t1
= tci_read_ri64(&tb_ptr
);
937 t2
= tci_read_ri64(&tb_ptr
);
938 tci_write_reg64(t0
, t1
| t2
);
940 case INDEX_op_xor_i64
:
942 t1
= tci_read_ri64(&tb_ptr
);
943 t2
= tci_read_ri64(&tb_ptr
);
944 tci_write_reg64(t0
, t1
^ t2
);
947 /* Shift/rotate operations (64 bit). */
949 case INDEX_op_shl_i64
:
951 t1
= tci_read_ri64(&tb_ptr
);
952 t2
= tci_read_ri64(&tb_ptr
);
953 tci_write_reg64(t0
, t1
<< (t2
& 63));
955 case INDEX_op_shr_i64
:
957 t1
= tci_read_ri64(&tb_ptr
);
958 t2
= tci_read_ri64(&tb_ptr
);
959 tci_write_reg64(t0
, t1
>> (t2
& 63));
961 case INDEX_op_sar_i64
:
963 t1
= tci_read_ri64(&tb_ptr
);
964 t2
= tci_read_ri64(&tb_ptr
);
965 tci_write_reg64(t0
, ((int64_t)t1
>> (t2
& 63)));
967 #if TCG_TARGET_HAS_rot_i64
968 case INDEX_op_rotl_i64
:
970 t1
= tci_read_ri64(&tb_ptr
);
971 t2
= tci_read_ri64(&tb_ptr
);
972 tci_write_reg64(t0
, rol64(t1
, t2
& 63));
974 case INDEX_op_rotr_i64
:
976 t1
= tci_read_ri64(&tb_ptr
);
977 t2
= tci_read_ri64(&tb_ptr
);
978 tci_write_reg64(t0
, ror64(t1
, t2
& 63));
981 #if TCG_TARGET_HAS_deposit_i64
982 case INDEX_op_deposit_i64
:
984 t1
= tci_read_r64(&tb_ptr
);
985 t2
= tci_read_r64(&tb_ptr
);
988 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
989 tci_write_reg64(t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
992 case INDEX_op_brcond_i64
:
993 t0
= tci_read_r64(&tb_ptr
);
994 t1
= tci_read_ri64(&tb_ptr
);
995 condition
= *tb_ptr
++;
996 label
= tci_read_label(&tb_ptr
);
997 if (tci_compare64(t0
, t1
, condition
)) {
998 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
999 tb_ptr
= (uint8_t *)label
;
1003 #if TCG_TARGET_HAS_ext8u_i64
1004 case INDEX_op_ext8u_i64
:
1006 t1
= tci_read_r8(&tb_ptr
);
1007 tci_write_reg64(t0
, t1
);
1010 #if TCG_TARGET_HAS_ext8s_i64
1011 case INDEX_op_ext8s_i64
:
1013 t1
= tci_read_r8s(&tb_ptr
);
1014 tci_write_reg64(t0
, t1
);
1017 #if TCG_TARGET_HAS_ext16s_i64
1018 case INDEX_op_ext16s_i64
:
1020 t1
= tci_read_r16s(&tb_ptr
);
1021 tci_write_reg64(t0
, t1
);
1024 #if TCG_TARGET_HAS_ext16u_i64
1025 case INDEX_op_ext16u_i64
:
1027 t1
= tci_read_r16(&tb_ptr
);
1028 tci_write_reg64(t0
, t1
);
1031 #if TCG_TARGET_HAS_ext32s_i64
1032 case INDEX_op_ext32s_i64
:
1034 case INDEX_op_ext_i32_i64
:
1036 t1
= tci_read_r32s(&tb_ptr
);
1037 tci_write_reg64(t0
, t1
);
1039 #if TCG_TARGET_HAS_ext32u_i64
1040 case INDEX_op_ext32u_i64
:
1042 case INDEX_op_extu_i32_i64
:
1044 t1
= tci_read_r32(&tb_ptr
);
1045 tci_write_reg64(t0
, t1
);
1047 #if TCG_TARGET_HAS_bswap16_i64
1048 case INDEX_op_bswap16_i64
:
1051 t1
= tci_read_r16(&tb_ptr
);
1052 tci_write_reg64(t0
, bswap16(t1
));
1055 #if TCG_TARGET_HAS_bswap32_i64
1056 case INDEX_op_bswap32_i64
:
1058 t1
= tci_read_r32(&tb_ptr
);
1059 tci_write_reg64(t0
, bswap32(t1
));
1062 #if TCG_TARGET_HAS_bswap64_i64
1063 case INDEX_op_bswap64_i64
:
1065 t1
= tci_read_r64(&tb_ptr
);
1066 tci_write_reg64(t0
, bswap64(t1
));
1069 #if TCG_TARGET_HAS_not_i64
1070 case INDEX_op_not_i64
:
1072 t1
= tci_read_r64(&tb_ptr
);
1073 tci_write_reg64(t0
, ~t1
);
1076 #if TCG_TARGET_HAS_neg_i64
1077 case INDEX_op_neg_i64
:
1079 t1
= tci_read_r64(&tb_ptr
);
1080 tci_write_reg64(t0
, -t1
);
1083 #endif /* TCG_TARGET_REG_BITS == 64 */
1085 /* QEMU specific operations. */
1087 case INDEX_op_exit_tb
:
1088 next_tb
= *(uint64_t *)tb_ptr
;
1091 case INDEX_op_goto_tb
:
1092 t0
= tci_read_i32(&tb_ptr
);
1093 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
1094 tb_ptr
+= (int32_t)t0
;
1096 case INDEX_op_qemu_ld_i32
:
1098 taddr
= tci_read_ulong(&tb_ptr
);
1099 oi
= tci_read_i(&tb_ptr
);
1100 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1105 tmp32
= (int8_t)qemu_ld_ub
;
1108 tmp32
= qemu_ld_leuw
;
1111 tmp32
= (int16_t)qemu_ld_leuw
;
1114 tmp32
= qemu_ld_leul
;
1117 tmp32
= qemu_ld_beuw
;
1120 tmp32
= (int16_t)qemu_ld_beuw
;
1123 tmp32
= qemu_ld_beul
;
1128 tci_write_reg(t0
, tmp32
);
1130 case INDEX_op_qemu_ld_i64
:
1132 if (TCG_TARGET_REG_BITS
== 32) {
1135 taddr
= tci_read_ulong(&tb_ptr
);
1136 oi
= tci_read_i(&tb_ptr
);
1137 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1142 tmp64
= (int8_t)qemu_ld_ub
;
1145 tmp64
= qemu_ld_leuw
;
1148 tmp64
= (int16_t)qemu_ld_leuw
;
1151 tmp64
= qemu_ld_leul
;
1154 tmp64
= (int32_t)qemu_ld_leul
;
1157 tmp64
= qemu_ld_leq
;
1160 tmp64
= qemu_ld_beuw
;
1163 tmp64
= (int16_t)qemu_ld_beuw
;
1166 tmp64
= qemu_ld_beul
;
1169 tmp64
= (int32_t)qemu_ld_beul
;
1172 tmp64
= qemu_ld_beq
;
1177 tci_write_reg(t0
, tmp64
);
1178 if (TCG_TARGET_REG_BITS
== 32) {
1179 tci_write_reg(t1
, tmp64
>> 32);
1182 case INDEX_op_qemu_st_i32
:
1183 t0
= tci_read_r(&tb_ptr
);
1184 taddr
= tci_read_ulong(&tb_ptr
);
1185 oi
= tci_read_i(&tb_ptr
);
1186 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1206 case INDEX_op_qemu_st_i64
:
1207 tmp64
= tci_read_r64(&tb_ptr
);
1208 taddr
= tci_read_ulong(&tb_ptr
);
1209 oi
= tci_read_i(&tb_ptr
);
1210 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1240 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);