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"
34 #include "qemu/compiler.h"
36 /* Marker for missing code. */
39 fprintf(stderr, "TODO %s:%u: %s()\n", \
40 __FILE__, __LINE__, __func__); \
44 #if MAX_OPC_PARAM_IARGS != 6
45 # error Fix needed, number of supported input arguments changed!
47 #if TCG_TARGET_REG_BITS == 32
48 typedef uint64_t (*helper_function
)(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
,
53 tcg_target_ulong
, tcg_target_ulong
);
55 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
56 tcg_target_ulong
, tcg_target_ulong
,
57 tcg_target_ulong
, tcg_target_ulong
);
60 static tcg_target_ulong
tci_read_reg(const tcg_target_ulong
*regs
, TCGReg index
)
62 tci_assert(index
< TCG_TARGET_NB_REGS
);
66 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
67 static int8_t tci_read_reg8s(const tcg_target_ulong
*regs
, TCGReg index
)
69 return (int8_t)tci_read_reg(regs
, index
);
73 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
74 static int16_t tci_read_reg16s(const tcg_target_ulong
*regs
, TCGReg index
)
76 return (int16_t)tci_read_reg(regs
, index
);
80 #if TCG_TARGET_REG_BITS == 64
81 static int32_t tci_read_reg32s(const tcg_target_ulong
*regs
, TCGReg index
)
83 return (int32_t)tci_read_reg(regs
, index
);
87 static uint8_t tci_read_reg8(const tcg_target_ulong
*regs
, TCGReg index
)
89 return (uint8_t)tci_read_reg(regs
, index
);
92 static uint16_t tci_read_reg16(const tcg_target_ulong
*regs
, TCGReg index
)
94 return (uint16_t)tci_read_reg(regs
, index
);
97 static uint32_t tci_read_reg32(const tcg_target_ulong
*regs
, TCGReg index
)
99 return (uint32_t)tci_read_reg(regs
, index
);
102 #if TCG_TARGET_REG_BITS == 64
103 static uint64_t tci_read_reg64(const tcg_target_ulong
*regs
, TCGReg index
)
105 return tci_read_reg(regs
, index
);
110 tci_write_reg(tcg_target_ulong
*regs
, TCGReg index
, tcg_target_ulong value
)
112 tci_assert(index
< TCG_TARGET_NB_REGS
);
113 tci_assert(index
!= TCG_AREG0
);
114 tci_assert(index
!= TCG_REG_CALL_STACK
);
118 #if TCG_TARGET_REG_BITS == 64
120 tci_write_reg32s(tcg_target_ulong
*regs
, TCGReg index
, int32_t value
)
122 tci_write_reg(regs
, index
, value
);
126 static void tci_write_reg8(tcg_target_ulong
*regs
, TCGReg index
, uint8_t value
)
128 tci_write_reg(regs
, index
, value
);
131 #if TCG_TARGET_REG_BITS == 64
133 tci_write_reg16(tcg_target_ulong
*regs
, TCGReg index
, uint16_t value
)
135 tci_write_reg(regs
, index
, value
);
140 tci_write_reg32(tcg_target_ulong
*regs
, TCGReg index
, uint32_t value
)
142 tci_write_reg(regs
, index
, value
);
145 #if TCG_TARGET_REG_BITS == 32
146 static void tci_write_reg64(tcg_target_ulong
*regs
, uint32_t high_index
,
147 uint32_t low_index
, uint64_t value
)
149 tci_write_reg(regs
, low_index
, value
);
150 tci_write_reg(regs
, high_index
, value
>> 32);
152 #elif TCG_TARGET_REG_BITS == 64
154 tci_write_reg64(tcg_target_ulong
*regs
, TCGReg index
, uint64_t value
)
156 tci_write_reg(regs
, index
, value
);
160 #if TCG_TARGET_REG_BITS == 32
161 /* Create a 64 bit value from two 32 bit values. */
162 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
164 return ((uint64_t)high
<< 32) + low
;
168 /* Read constant (native size) from bytecode. */
169 static tcg_target_ulong
tci_read_i(const uint8_t **tb_ptr
)
171 tcg_target_ulong value
= *(const tcg_target_ulong
*)(*tb_ptr
);
172 *tb_ptr
+= sizeof(value
);
176 /* Read unsigned constant (32 bit) from bytecode. */
177 static uint32_t tci_read_i32(const uint8_t **tb_ptr
)
179 uint32_t value
= *(const uint32_t *)(*tb_ptr
);
180 *tb_ptr
+= sizeof(value
);
184 /* Read signed constant (32 bit) from bytecode. */
185 static int32_t tci_read_s32(const uint8_t **tb_ptr
)
187 int32_t value
= *(const int32_t *)(*tb_ptr
);
188 *tb_ptr
+= sizeof(value
);
192 #if TCG_TARGET_REG_BITS == 64
193 /* Read constant (64 bit) from bytecode. */
194 static uint64_t tci_read_i64(const uint8_t **tb_ptr
)
196 uint64_t value
= *(const uint64_t *)(*tb_ptr
);
197 *tb_ptr
+= sizeof(value
);
202 /* Read indexed register (native size) from bytecode. */
203 static tcg_target_ulong
204 tci_read_r(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
206 tcg_target_ulong value
= tci_read_reg(regs
, **tb_ptr
);
211 /* Read indexed register (8 bit) from bytecode. */
212 static uint8_t tci_read_r8(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
214 uint8_t value
= tci_read_reg8(regs
, **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(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
223 int8_t value
= tci_read_reg8s(regs
, **tb_ptr
);
229 /* Read indexed register (16 bit) from bytecode. */
230 static uint16_t tci_read_r16(const tcg_target_ulong
*regs
,
231 const uint8_t **tb_ptr
)
233 uint16_t value
= tci_read_reg16(regs
, **tb_ptr
);
238 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
239 /* Read indexed register (16 bit signed) from bytecode. */
240 static int16_t tci_read_r16s(const tcg_target_ulong
*regs
,
241 const uint8_t **tb_ptr
)
243 int16_t value
= tci_read_reg16s(regs
, **tb_ptr
);
249 /* Read indexed register (32 bit) from bytecode. */
250 static uint32_t tci_read_r32(const tcg_target_ulong
*regs
,
251 const uint8_t **tb_ptr
)
253 uint32_t value
= tci_read_reg32(regs
, **tb_ptr
);
258 #if TCG_TARGET_REG_BITS == 32
259 /* Read two indexed registers (2 * 32 bit) from bytecode. */
260 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
261 const uint8_t **tb_ptr
)
263 uint32_t low
= tci_read_r32(regs
, tb_ptr
);
264 return tci_uint64(tci_read_r32(regs
, tb_ptr
), low
);
266 #elif TCG_TARGET_REG_BITS == 64
267 /* Read indexed register (32 bit signed) from bytecode. */
268 static int32_t tci_read_r32s(const tcg_target_ulong
*regs
,
269 const uint8_t **tb_ptr
)
271 int32_t value
= tci_read_reg32s(regs
, **tb_ptr
);
276 /* Read indexed register (64 bit) from bytecode. */
277 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
278 const uint8_t **tb_ptr
)
280 uint64_t value
= tci_read_reg64(regs
, **tb_ptr
);
286 /* Read indexed register(s) with target address from bytecode. */
288 tci_read_ulong(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
290 target_ulong taddr
= tci_read_r(regs
, tb_ptr
);
291 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
292 taddr
+= (uint64_t)tci_read_r(regs
, tb_ptr
) << 32;
297 /* Read indexed register or constant (native size) from bytecode. */
298 static tcg_target_ulong
299 tci_read_ri(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
301 tcg_target_ulong value
;
304 if (r
== TCG_CONST
) {
305 value
= tci_read_i(tb_ptr
);
307 value
= tci_read_reg(regs
, r
);
312 /* Read indexed register or constant (32 bit) from bytecode. */
313 static uint32_t tci_read_ri32(const tcg_target_ulong
*regs
,
314 const uint8_t **tb_ptr
)
319 if (r
== TCG_CONST
) {
320 value
= tci_read_i32(tb_ptr
);
322 value
= tci_read_reg32(regs
, r
);
327 #if TCG_TARGET_REG_BITS == 32
328 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
329 static uint64_t tci_read_ri64(const tcg_target_ulong
*regs
,
330 const uint8_t **tb_ptr
)
332 uint32_t low
= tci_read_ri32(regs
, tb_ptr
);
333 return tci_uint64(tci_read_ri32(regs
, tb_ptr
), low
);
335 #elif TCG_TARGET_REG_BITS == 64
336 /* Read indexed register or constant (64 bit) from bytecode. */
337 static uint64_t tci_read_ri64(const tcg_target_ulong
*regs
,
338 const uint8_t **tb_ptr
)
343 if (r
== TCG_CONST
) {
344 value
= tci_read_i64(tb_ptr
);
346 value
= tci_read_reg64(regs
, r
);
352 static tcg_target_ulong
tci_read_label(const uint8_t **tb_ptr
)
354 tcg_target_ulong label
= tci_read_i(tb_ptr
);
355 tci_assert(label
!= 0);
359 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
401 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
443 #ifdef CONFIG_SOFTMMU
444 # define qemu_ld_ub \
445 helper_ret_ldub_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
446 # define qemu_ld_leuw \
447 helper_le_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
448 # define qemu_ld_leul \
449 helper_le_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
450 # define qemu_ld_leq \
451 helper_le_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
452 # define qemu_ld_beuw \
453 helper_be_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
454 # define qemu_ld_beul \
455 helper_be_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
456 # define qemu_ld_beq \
457 helper_be_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
458 # define qemu_st_b(X) \
459 helper_ret_stb_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
460 # define qemu_st_lew(X) \
461 helper_le_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
462 # define qemu_st_lel(X) \
463 helper_le_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
464 # define qemu_st_leq(X) \
465 helper_le_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
466 # define qemu_st_bew(X) \
467 helper_be_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
468 # define qemu_st_bel(X) \
469 helper_be_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
470 # define qemu_st_beq(X) \
471 helper_be_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
473 # define qemu_ld_ub ldub_p(g2h(taddr))
474 # define qemu_ld_leuw lduw_le_p(g2h(taddr))
475 # define qemu_ld_leul (uint32_t)ldl_le_p(g2h(taddr))
476 # define qemu_ld_leq ldq_le_p(g2h(taddr))
477 # define qemu_ld_beuw lduw_be_p(g2h(taddr))
478 # define qemu_ld_beul (uint32_t)ldl_be_p(g2h(taddr))
479 # define qemu_ld_beq ldq_be_p(g2h(taddr))
480 # define qemu_st_b(X) stb_p(g2h(taddr), X)
481 # define qemu_st_lew(X) stw_le_p(g2h(taddr), X)
482 # define qemu_st_lel(X) stl_le_p(g2h(taddr), X)
483 # define qemu_st_leq(X) stq_le_p(g2h(taddr), X)
484 # define qemu_st_bew(X) stw_be_p(g2h(taddr), X)
485 # define qemu_st_bel(X) stl_be_p(g2h(taddr), X)
486 # define qemu_st_beq(X) stq_be_p(g2h(taddr), X)
489 /* Interpret pseudo code in tb. */
491 * Disable CFI checks.
492 * One possible operation in the pseudo code is a call to binary code.
493 * Therefore, disable CFI checks in the interpreter function
495 uintptr_t QEMU_DISABLE_CFI
tcg_qemu_tb_exec(CPUArchState
*env
,
496 const void *v_tb_ptr
)
498 const uint8_t *tb_ptr
= v_tb_ptr
;
499 tcg_target_ulong regs
[TCG_TARGET_NB_REGS
];
500 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
501 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
504 regs
[TCG_AREG0
] = (tcg_target_ulong
)env
;
505 regs
[TCG_REG_CALL_STACK
] = sp_value
;
509 TCGOpcode opc
= tb_ptr
[0];
510 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
511 uint8_t op_size
= tb_ptr
[1];
512 const uint8_t *old_code_ptr
= tb_ptr
;
517 tcg_target_ulong label
;
524 #if TCG_TARGET_REG_BITS == 32
530 tci_tb_ptr
= (uintptr_t)tb_ptr
;
533 /* Skip opcode and size entry. */
538 t0
= tci_read_ri(regs
, &tb_ptr
);
539 #if TCG_TARGET_REG_BITS == 32
540 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
541 tci_read_reg(regs
, TCG_REG_R1
),
542 tci_read_reg(regs
, TCG_REG_R2
),
543 tci_read_reg(regs
, TCG_REG_R3
),
544 tci_read_reg(regs
, TCG_REG_R5
),
545 tci_read_reg(regs
, TCG_REG_R6
),
546 tci_read_reg(regs
, TCG_REG_R7
),
547 tci_read_reg(regs
, TCG_REG_R8
),
548 tci_read_reg(regs
, TCG_REG_R9
),
549 tci_read_reg(regs
, TCG_REG_R10
),
550 tci_read_reg(regs
, TCG_REG_R11
),
551 tci_read_reg(regs
, TCG_REG_R12
));
552 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
553 tci_write_reg(regs
, TCG_REG_R1
, tmp64
>> 32);
555 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
556 tci_read_reg(regs
, TCG_REG_R1
),
557 tci_read_reg(regs
, TCG_REG_R2
),
558 tci_read_reg(regs
, TCG_REG_R3
),
559 tci_read_reg(regs
, TCG_REG_R5
),
560 tci_read_reg(regs
, TCG_REG_R6
));
561 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
565 label
= tci_read_label(&tb_ptr
);
566 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
567 tb_ptr
= (uint8_t *)label
;
569 case INDEX_op_setcond_i32
:
571 t1
= tci_read_r32(regs
, &tb_ptr
);
572 t2
= tci_read_ri32(regs
, &tb_ptr
);
573 condition
= *tb_ptr
++;
574 tci_write_reg32(regs
, t0
, tci_compare32(t1
, t2
, condition
));
576 #if TCG_TARGET_REG_BITS == 32
577 case INDEX_op_setcond2_i32
:
579 tmp64
= tci_read_r64(regs
, &tb_ptr
);
580 v64
= tci_read_ri64(regs
, &tb_ptr
);
581 condition
= *tb_ptr
++;
582 tci_write_reg32(regs
, t0
, tci_compare64(tmp64
, v64
, condition
));
584 #elif TCG_TARGET_REG_BITS == 64
585 case INDEX_op_setcond_i64
:
587 t1
= tci_read_r64(regs
, &tb_ptr
);
588 t2
= tci_read_ri64(regs
, &tb_ptr
);
589 condition
= *tb_ptr
++;
590 tci_write_reg64(regs
, t0
, tci_compare64(t1
, t2
, condition
));
593 case INDEX_op_mov_i32
:
595 t1
= tci_read_r32(regs
, &tb_ptr
);
596 tci_write_reg32(regs
, t0
, t1
);
598 case INDEX_op_tci_movi_i32
:
600 t1
= tci_read_i32(&tb_ptr
);
601 tci_write_reg32(regs
, t0
, t1
);
604 /* Load/store operations (32 bit). */
606 case INDEX_op_ld8u_i32
:
608 t1
= tci_read_r(regs
, &tb_ptr
);
609 t2
= tci_read_s32(&tb_ptr
);
610 tci_write_reg8(regs
, t0
, *(uint8_t *)(t1
+ t2
));
612 case INDEX_op_ld8s_i32
:
615 case INDEX_op_ld16u_i32
:
618 case INDEX_op_ld16s_i32
:
621 case INDEX_op_ld_i32
:
623 t1
= tci_read_r(regs
, &tb_ptr
);
624 t2
= tci_read_s32(&tb_ptr
);
625 tci_write_reg32(regs
, t0
, *(uint32_t *)(t1
+ t2
));
627 case INDEX_op_st8_i32
:
628 t0
= tci_read_r8(regs
, &tb_ptr
);
629 t1
= tci_read_r(regs
, &tb_ptr
);
630 t2
= tci_read_s32(&tb_ptr
);
631 *(uint8_t *)(t1
+ t2
) = t0
;
633 case INDEX_op_st16_i32
:
634 t0
= tci_read_r16(regs
, &tb_ptr
);
635 t1
= tci_read_r(regs
, &tb_ptr
);
636 t2
= tci_read_s32(&tb_ptr
);
637 *(uint16_t *)(t1
+ t2
) = t0
;
639 case INDEX_op_st_i32
:
640 t0
= tci_read_r32(regs
, &tb_ptr
);
641 t1
= tci_read_r(regs
, &tb_ptr
);
642 t2
= tci_read_s32(&tb_ptr
);
643 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
644 *(uint32_t *)(t1
+ t2
) = t0
;
647 /* Arithmetic operations (32 bit). */
649 case INDEX_op_add_i32
:
651 t1
= tci_read_ri32(regs
, &tb_ptr
);
652 t2
= tci_read_ri32(regs
, &tb_ptr
);
653 tci_write_reg32(regs
, t0
, t1
+ t2
);
655 case INDEX_op_sub_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_mul_i32
:
663 t1
= tci_read_ri32(regs
, &tb_ptr
);
664 t2
= tci_read_ri32(regs
, &tb_ptr
);
665 tci_write_reg32(regs
, t0
, t1
* t2
);
667 #if TCG_TARGET_HAS_div_i32
668 case INDEX_op_div_i32
:
670 t1
= tci_read_ri32(regs
, &tb_ptr
);
671 t2
= tci_read_ri32(regs
, &tb_ptr
);
672 tci_write_reg32(regs
, t0
, (int32_t)t1
/ (int32_t)t2
);
674 case INDEX_op_divu_i32
:
676 t1
= tci_read_ri32(regs
, &tb_ptr
);
677 t2
= tci_read_ri32(regs
, &tb_ptr
);
678 tci_write_reg32(regs
, t0
, t1
/ t2
);
680 case INDEX_op_rem_i32
:
682 t1
= tci_read_ri32(regs
, &tb_ptr
);
683 t2
= tci_read_ri32(regs
, &tb_ptr
);
684 tci_write_reg32(regs
, t0
, (int32_t)t1
% (int32_t)t2
);
686 case INDEX_op_remu_i32
:
688 t1
= tci_read_ri32(regs
, &tb_ptr
);
689 t2
= tci_read_ri32(regs
, &tb_ptr
);
690 tci_write_reg32(regs
, t0
, t1
% t2
);
692 #elif TCG_TARGET_HAS_div2_i32
693 case INDEX_op_div2_i32
:
694 case INDEX_op_divu2_i32
:
698 case INDEX_op_and_i32
:
700 t1
= tci_read_ri32(regs
, &tb_ptr
);
701 t2
= tci_read_ri32(regs
, &tb_ptr
);
702 tci_write_reg32(regs
, t0
, t1
& t2
);
704 case INDEX_op_or_i32
:
706 t1
= tci_read_ri32(regs
, &tb_ptr
);
707 t2
= tci_read_ri32(regs
, &tb_ptr
);
708 tci_write_reg32(regs
, t0
, t1
| t2
);
710 case INDEX_op_xor_i32
:
712 t1
= tci_read_ri32(regs
, &tb_ptr
);
713 t2
= tci_read_ri32(regs
, &tb_ptr
);
714 tci_write_reg32(regs
, t0
, t1
^ t2
);
717 /* Shift/rotate operations (32 bit). */
719 case INDEX_op_shl_i32
:
721 t1
= tci_read_ri32(regs
, &tb_ptr
);
722 t2
= tci_read_ri32(regs
, &tb_ptr
);
723 tci_write_reg32(regs
, t0
, t1
<< (t2
& 31));
725 case INDEX_op_shr_i32
:
727 t1
= tci_read_ri32(regs
, &tb_ptr
);
728 t2
= tci_read_ri32(regs
, &tb_ptr
);
729 tci_write_reg32(regs
, t0
, t1
>> (t2
& 31));
731 case INDEX_op_sar_i32
:
733 t1
= tci_read_ri32(regs
, &tb_ptr
);
734 t2
= tci_read_ri32(regs
, &tb_ptr
);
735 tci_write_reg32(regs
, t0
, ((int32_t)t1
>> (t2
& 31)));
737 #if TCG_TARGET_HAS_rot_i32
738 case INDEX_op_rotl_i32
:
740 t1
= tci_read_ri32(regs
, &tb_ptr
);
741 t2
= tci_read_ri32(regs
, &tb_ptr
);
742 tci_write_reg32(regs
, t0
, rol32(t1
, t2
& 31));
744 case INDEX_op_rotr_i32
:
746 t1
= tci_read_ri32(regs
, &tb_ptr
);
747 t2
= tci_read_ri32(regs
, &tb_ptr
);
748 tci_write_reg32(regs
, t0
, ror32(t1
, t2
& 31));
751 #if TCG_TARGET_HAS_deposit_i32
752 case INDEX_op_deposit_i32
:
754 t1
= tci_read_r32(regs
, &tb_ptr
);
755 t2
= tci_read_r32(regs
, &tb_ptr
);
758 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
759 tci_write_reg32(regs
, t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
762 case INDEX_op_brcond_i32
:
763 t0
= tci_read_r32(regs
, &tb_ptr
);
764 t1
= tci_read_ri32(regs
, &tb_ptr
);
765 condition
= *tb_ptr
++;
766 label
= tci_read_label(&tb_ptr
);
767 if (tci_compare32(t0
, t1
, condition
)) {
768 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
769 tb_ptr
= (uint8_t *)label
;
773 #if TCG_TARGET_REG_BITS == 32
774 case INDEX_op_add2_i32
:
777 tmp64
= tci_read_r64(regs
, &tb_ptr
);
778 tmp64
+= tci_read_r64(regs
, &tb_ptr
);
779 tci_write_reg64(regs
, t1
, t0
, tmp64
);
781 case INDEX_op_sub2_i32
:
784 tmp64
= tci_read_r64(regs
, &tb_ptr
);
785 tmp64
-= tci_read_r64(regs
, &tb_ptr
);
786 tci_write_reg64(regs
, t1
, t0
, tmp64
);
788 case INDEX_op_brcond2_i32
:
789 tmp64
= tci_read_r64(regs
, &tb_ptr
);
790 v64
= tci_read_ri64(regs
, &tb_ptr
);
791 condition
= *tb_ptr
++;
792 label
= tci_read_label(&tb_ptr
);
793 if (tci_compare64(tmp64
, v64
, condition
)) {
794 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
795 tb_ptr
= (uint8_t *)label
;
799 case INDEX_op_mulu2_i32
:
802 t2
= tci_read_r32(regs
, &tb_ptr
);
803 tmp64
= tci_read_r32(regs
, &tb_ptr
);
804 tci_write_reg64(regs
, t1
, t0
, t2
* tmp64
);
806 #endif /* TCG_TARGET_REG_BITS == 32 */
807 #if TCG_TARGET_HAS_ext8s_i32
808 case INDEX_op_ext8s_i32
:
810 t1
= tci_read_r8s(regs
, &tb_ptr
);
811 tci_write_reg32(regs
, t0
, t1
);
814 #if TCG_TARGET_HAS_ext16s_i32
815 case INDEX_op_ext16s_i32
:
817 t1
= tci_read_r16s(regs
, &tb_ptr
);
818 tci_write_reg32(regs
, t0
, t1
);
821 #if TCG_TARGET_HAS_ext8u_i32
822 case INDEX_op_ext8u_i32
:
824 t1
= tci_read_r8(regs
, &tb_ptr
);
825 tci_write_reg32(regs
, t0
, t1
);
828 #if TCG_TARGET_HAS_ext16u_i32
829 case INDEX_op_ext16u_i32
:
831 t1
= tci_read_r16(regs
, &tb_ptr
);
832 tci_write_reg32(regs
, t0
, t1
);
835 #if TCG_TARGET_HAS_bswap16_i32
836 case INDEX_op_bswap16_i32
:
838 t1
= tci_read_r16(regs
, &tb_ptr
);
839 tci_write_reg32(regs
, t0
, bswap16(t1
));
842 #if TCG_TARGET_HAS_bswap32_i32
843 case INDEX_op_bswap32_i32
:
845 t1
= tci_read_r32(regs
, &tb_ptr
);
846 tci_write_reg32(regs
, t0
, bswap32(t1
));
849 #if TCG_TARGET_HAS_not_i32
850 case INDEX_op_not_i32
:
852 t1
= tci_read_r32(regs
, &tb_ptr
);
853 tci_write_reg32(regs
, t0
, ~t1
);
856 #if TCG_TARGET_HAS_neg_i32
857 case INDEX_op_neg_i32
:
859 t1
= tci_read_r32(regs
, &tb_ptr
);
860 tci_write_reg32(regs
, t0
, -t1
);
863 #if TCG_TARGET_REG_BITS == 64
864 case INDEX_op_mov_i64
:
866 t1
= tci_read_r64(regs
, &tb_ptr
);
867 tci_write_reg64(regs
, t0
, t1
);
869 case INDEX_op_tci_movi_i64
:
871 t1
= tci_read_i64(&tb_ptr
);
872 tci_write_reg64(regs
, t0
, t1
);
875 /* Load/store operations (64 bit). */
877 case INDEX_op_ld8u_i64
:
879 t1
= tci_read_r(regs
, &tb_ptr
);
880 t2
= tci_read_s32(&tb_ptr
);
881 tci_write_reg8(regs
, t0
, *(uint8_t *)(t1
+ t2
));
883 case INDEX_op_ld8s_i64
:
886 case INDEX_op_ld16u_i64
:
888 t1
= tci_read_r(regs
, &tb_ptr
);
889 t2
= tci_read_s32(&tb_ptr
);
890 tci_write_reg16(regs
, t0
, *(uint16_t *)(t1
+ t2
));
892 case INDEX_op_ld16s_i64
:
895 case INDEX_op_ld32u_i64
:
897 t1
= tci_read_r(regs
, &tb_ptr
);
898 t2
= tci_read_s32(&tb_ptr
);
899 tci_write_reg32(regs
, t0
, *(uint32_t *)(t1
+ t2
));
901 case INDEX_op_ld32s_i64
:
903 t1
= tci_read_r(regs
, &tb_ptr
);
904 t2
= tci_read_s32(&tb_ptr
);
905 tci_write_reg32s(regs
, t0
, *(int32_t *)(t1
+ t2
));
907 case INDEX_op_ld_i64
:
909 t1
= tci_read_r(regs
, &tb_ptr
);
910 t2
= tci_read_s32(&tb_ptr
);
911 tci_write_reg64(regs
, t0
, *(uint64_t *)(t1
+ t2
));
913 case INDEX_op_st8_i64
:
914 t0
= tci_read_r8(regs
, &tb_ptr
);
915 t1
= tci_read_r(regs
, &tb_ptr
);
916 t2
= tci_read_s32(&tb_ptr
);
917 *(uint8_t *)(t1
+ t2
) = t0
;
919 case INDEX_op_st16_i64
:
920 t0
= tci_read_r16(regs
, &tb_ptr
);
921 t1
= tci_read_r(regs
, &tb_ptr
);
922 t2
= tci_read_s32(&tb_ptr
);
923 *(uint16_t *)(t1
+ t2
) = t0
;
925 case INDEX_op_st32_i64
:
926 t0
= tci_read_r32(regs
, &tb_ptr
);
927 t1
= tci_read_r(regs
, &tb_ptr
);
928 t2
= tci_read_s32(&tb_ptr
);
929 *(uint32_t *)(t1
+ t2
) = t0
;
931 case INDEX_op_st_i64
:
932 t0
= tci_read_r64(regs
, &tb_ptr
);
933 t1
= tci_read_r(regs
, &tb_ptr
);
934 t2
= tci_read_s32(&tb_ptr
);
935 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
936 *(uint64_t *)(t1
+ t2
) = t0
;
939 /* Arithmetic operations (64 bit). */
941 case INDEX_op_add_i64
:
943 t1
= tci_read_ri64(regs
, &tb_ptr
);
944 t2
= tci_read_ri64(regs
, &tb_ptr
);
945 tci_write_reg64(regs
, t0
, t1
+ t2
);
947 case INDEX_op_sub_i64
:
949 t1
= tci_read_ri64(regs
, &tb_ptr
);
950 t2
= tci_read_ri64(regs
, &tb_ptr
);
951 tci_write_reg64(regs
, t0
, t1
- t2
);
953 case INDEX_op_mul_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 #if TCG_TARGET_HAS_div_i64
960 case INDEX_op_div_i64
:
961 case INDEX_op_divu_i64
:
962 case INDEX_op_rem_i64
:
963 case INDEX_op_remu_i64
:
966 #elif TCG_TARGET_HAS_div2_i64
967 case INDEX_op_div2_i64
:
968 case INDEX_op_divu2_i64
:
972 case INDEX_op_and_i64
:
974 t1
= tci_read_ri64(regs
, &tb_ptr
);
975 t2
= tci_read_ri64(regs
, &tb_ptr
);
976 tci_write_reg64(regs
, t0
, t1
& t2
);
978 case INDEX_op_or_i64
:
980 t1
= tci_read_ri64(regs
, &tb_ptr
);
981 t2
= tci_read_ri64(regs
, &tb_ptr
);
982 tci_write_reg64(regs
, t0
, t1
| t2
);
984 case INDEX_op_xor_i64
:
986 t1
= tci_read_ri64(regs
, &tb_ptr
);
987 t2
= tci_read_ri64(regs
, &tb_ptr
);
988 tci_write_reg64(regs
, t0
, t1
^ t2
);
991 /* Shift/rotate operations (64 bit). */
993 case INDEX_op_shl_i64
:
995 t1
= tci_read_ri64(regs
, &tb_ptr
);
996 t2
= tci_read_ri64(regs
, &tb_ptr
);
997 tci_write_reg64(regs
, t0
, t1
<< (t2
& 63));
999 case INDEX_op_shr_i64
:
1001 t1
= tci_read_ri64(regs
, &tb_ptr
);
1002 t2
= tci_read_ri64(regs
, &tb_ptr
);
1003 tci_write_reg64(regs
, t0
, t1
>> (t2
& 63));
1005 case INDEX_op_sar_i64
:
1007 t1
= tci_read_ri64(regs
, &tb_ptr
);
1008 t2
= tci_read_ri64(regs
, &tb_ptr
);
1009 tci_write_reg64(regs
, t0
, ((int64_t)t1
>> (t2
& 63)));
1011 #if TCG_TARGET_HAS_rot_i64
1012 case INDEX_op_rotl_i64
:
1014 t1
= tci_read_ri64(regs
, &tb_ptr
);
1015 t2
= tci_read_ri64(regs
, &tb_ptr
);
1016 tci_write_reg64(regs
, t0
, rol64(t1
, t2
& 63));
1018 case INDEX_op_rotr_i64
:
1020 t1
= tci_read_ri64(regs
, &tb_ptr
);
1021 t2
= tci_read_ri64(regs
, &tb_ptr
);
1022 tci_write_reg64(regs
, t0
, ror64(t1
, t2
& 63));
1025 #if TCG_TARGET_HAS_deposit_i64
1026 case INDEX_op_deposit_i64
:
1028 t1
= tci_read_r64(regs
, &tb_ptr
);
1029 t2
= tci_read_r64(regs
, &tb_ptr
);
1032 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
1033 tci_write_reg64(regs
, t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
1036 case INDEX_op_brcond_i64
:
1037 t0
= tci_read_r64(regs
, &tb_ptr
);
1038 t1
= tci_read_ri64(regs
, &tb_ptr
);
1039 condition
= *tb_ptr
++;
1040 label
= tci_read_label(&tb_ptr
);
1041 if (tci_compare64(t0
, t1
, condition
)) {
1042 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
1043 tb_ptr
= (uint8_t *)label
;
1047 #if TCG_TARGET_HAS_ext8u_i64
1048 case INDEX_op_ext8u_i64
:
1050 t1
= tci_read_r8(regs
, &tb_ptr
);
1051 tci_write_reg64(regs
, t0
, t1
);
1054 #if TCG_TARGET_HAS_ext8s_i64
1055 case INDEX_op_ext8s_i64
:
1057 t1
= tci_read_r8s(regs
, &tb_ptr
);
1058 tci_write_reg64(regs
, t0
, t1
);
1061 #if TCG_TARGET_HAS_ext16s_i64
1062 case INDEX_op_ext16s_i64
:
1064 t1
= tci_read_r16s(regs
, &tb_ptr
);
1065 tci_write_reg64(regs
, t0
, t1
);
1068 #if TCG_TARGET_HAS_ext16u_i64
1069 case INDEX_op_ext16u_i64
:
1071 t1
= tci_read_r16(regs
, &tb_ptr
);
1072 tci_write_reg64(regs
, t0
, t1
);
1075 #if TCG_TARGET_HAS_ext32s_i64
1076 case INDEX_op_ext32s_i64
:
1078 case INDEX_op_ext_i32_i64
:
1080 t1
= tci_read_r32s(regs
, &tb_ptr
);
1081 tci_write_reg64(regs
, t0
, t1
);
1083 #if TCG_TARGET_HAS_ext32u_i64
1084 case INDEX_op_ext32u_i64
:
1086 case INDEX_op_extu_i32_i64
:
1088 t1
= tci_read_r32(regs
, &tb_ptr
);
1089 tci_write_reg64(regs
, t0
, t1
);
1091 #if TCG_TARGET_HAS_bswap16_i64
1092 case INDEX_op_bswap16_i64
:
1094 t1
= tci_read_r16(regs
, &tb_ptr
);
1095 tci_write_reg64(regs
, t0
, bswap16(t1
));
1098 #if TCG_TARGET_HAS_bswap32_i64
1099 case INDEX_op_bswap32_i64
:
1101 t1
= tci_read_r32(regs
, &tb_ptr
);
1102 tci_write_reg64(regs
, t0
, bswap32(t1
));
1105 #if TCG_TARGET_HAS_bswap64_i64
1106 case INDEX_op_bswap64_i64
:
1108 t1
= tci_read_r64(regs
, &tb_ptr
);
1109 tci_write_reg64(regs
, t0
, bswap64(t1
));
1112 #if TCG_TARGET_HAS_not_i64
1113 case INDEX_op_not_i64
:
1115 t1
= tci_read_r64(regs
, &tb_ptr
);
1116 tci_write_reg64(regs
, t0
, ~t1
);
1119 #if TCG_TARGET_HAS_neg_i64
1120 case INDEX_op_neg_i64
:
1122 t1
= tci_read_r64(regs
, &tb_ptr
);
1123 tci_write_reg64(regs
, t0
, -t1
);
1126 #endif /* TCG_TARGET_REG_BITS == 64 */
1128 /* QEMU specific operations. */
1130 case INDEX_op_exit_tb
:
1131 ret
= *(uint64_t *)tb_ptr
;
1134 case INDEX_op_goto_tb
:
1135 /* Jump address is aligned */
1136 tb_ptr
= QEMU_ALIGN_PTR_UP(tb_ptr
, 4);
1137 t0
= qatomic_read((int32_t *)tb_ptr
);
1138 tb_ptr
+= sizeof(int32_t);
1139 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
1140 tb_ptr
+= (int32_t)t0
;
1142 case INDEX_op_qemu_ld_i32
:
1144 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1145 oi
= tci_read_i(&tb_ptr
);
1146 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1151 tmp32
= (int8_t)qemu_ld_ub
;
1154 tmp32
= qemu_ld_leuw
;
1157 tmp32
= (int16_t)qemu_ld_leuw
;
1160 tmp32
= qemu_ld_leul
;
1163 tmp32
= qemu_ld_beuw
;
1166 tmp32
= (int16_t)qemu_ld_beuw
;
1169 tmp32
= qemu_ld_beul
;
1174 tci_write_reg(regs
, t0
, tmp32
);
1176 case INDEX_op_qemu_ld_i64
:
1178 if (TCG_TARGET_REG_BITS
== 32) {
1181 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1182 oi
= tci_read_i(&tb_ptr
);
1183 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1188 tmp64
= (int8_t)qemu_ld_ub
;
1191 tmp64
= qemu_ld_leuw
;
1194 tmp64
= (int16_t)qemu_ld_leuw
;
1197 tmp64
= qemu_ld_leul
;
1200 tmp64
= (int32_t)qemu_ld_leul
;
1203 tmp64
= qemu_ld_leq
;
1206 tmp64
= qemu_ld_beuw
;
1209 tmp64
= (int16_t)qemu_ld_beuw
;
1212 tmp64
= qemu_ld_beul
;
1215 tmp64
= (int32_t)qemu_ld_beul
;
1218 tmp64
= qemu_ld_beq
;
1223 tci_write_reg(regs
, t0
, tmp64
);
1224 if (TCG_TARGET_REG_BITS
== 32) {
1225 tci_write_reg(regs
, t1
, tmp64
>> 32);
1228 case INDEX_op_qemu_st_i32
:
1229 t0
= tci_read_r(regs
, &tb_ptr
);
1230 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1231 oi
= tci_read_i(&tb_ptr
);
1232 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1252 case INDEX_op_qemu_st_i64
:
1253 tmp64
= tci_read_r64(regs
, &tb_ptr
);
1254 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1255 oi
= tci_read_i(&tb_ptr
);
1256 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1283 /* Ensure ordering for all kinds */
1290 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);