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"
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_read_reg(const tcg_target_ulong
*regs
, TCGReg index
)
60 tci_assert(index
< TCG_TARGET_NB_REGS
);
64 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
65 static int8_t tci_read_reg8s(const tcg_target_ulong
*regs
, TCGReg index
)
67 return (int8_t)tci_read_reg(regs
, index
);
71 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
72 static int16_t tci_read_reg16s(const tcg_target_ulong
*regs
, TCGReg index
)
74 return (int16_t)tci_read_reg(regs
, index
);
78 #if TCG_TARGET_REG_BITS == 64
79 static int32_t tci_read_reg32s(const tcg_target_ulong
*regs
, TCGReg index
)
81 return (int32_t)tci_read_reg(regs
, index
);
85 static uint8_t tci_read_reg8(const tcg_target_ulong
*regs
, TCGReg index
)
87 return (uint8_t)tci_read_reg(regs
, index
);
90 static uint16_t tci_read_reg16(const tcg_target_ulong
*regs
, TCGReg index
)
92 return (uint16_t)tci_read_reg(regs
, index
);
95 static uint32_t tci_read_reg32(const tcg_target_ulong
*regs
, TCGReg index
)
97 return (uint32_t)tci_read_reg(regs
, index
);
100 #if TCG_TARGET_REG_BITS == 64
101 static uint64_t tci_read_reg64(const tcg_target_ulong
*regs
, TCGReg index
)
103 return tci_read_reg(regs
, index
);
108 tci_write_reg(tcg_target_ulong
*regs
, TCGReg index
, tcg_target_ulong value
)
110 tci_assert(index
< TCG_TARGET_NB_REGS
);
111 tci_assert(index
!= TCG_AREG0
);
112 tci_assert(index
!= TCG_REG_CALL_STACK
);
116 #if TCG_TARGET_REG_BITS == 64
118 tci_write_reg32s(tcg_target_ulong
*regs
, TCGReg index
, int32_t value
)
120 tci_write_reg(regs
, index
, value
);
124 static void tci_write_reg8(tcg_target_ulong
*regs
, TCGReg index
, uint8_t value
)
126 tci_write_reg(regs
, index
, value
);
130 tci_write_reg32(tcg_target_ulong
*regs
, TCGReg index
, uint32_t value
)
132 tci_write_reg(regs
, index
, value
);
135 #if TCG_TARGET_REG_BITS == 32
136 static void tci_write_reg64(tcg_target_ulong
*regs
, uint32_t high_index
,
137 uint32_t low_index
, uint64_t value
)
139 tci_write_reg(regs
, low_index
, value
);
140 tci_write_reg(regs
, high_index
, value
>> 32);
142 #elif TCG_TARGET_REG_BITS == 64
144 tci_write_reg64(tcg_target_ulong
*regs
, TCGReg index
, uint64_t value
)
146 tci_write_reg(regs
, index
, value
);
150 #if TCG_TARGET_REG_BITS == 32
151 /* Create a 64 bit value from two 32 bit values. */
152 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
154 return ((uint64_t)high
<< 32) + low
;
158 /* Read constant (native size) from bytecode. */
159 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
161 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
162 *tb_ptr
+= sizeof(value
);
166 /* Read unsigned constant (32 bit) from bytecode. */
167 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
169 uint32_t value
= *(uint32_t *)(*tb_ptr
);
170 *tb_ptr
+= sizeof(value
);
174 /* Read signed constant (32 bit) from bytecode. */
175 static int32_t tci_read_s32(uint8_t **tb_ptr
)
177 int32_t value
= *(int32_t *)(*tb_ptr
);
178 *tb_ptr
+= sizeof(value
);
182 #if TCG_TARGET_REG_BITS == 64
183 /* Read constant (64 bit) from bytecode. */
184 static uint64_t tci_read_i64(uint8_t **tb_ptr
)
186 uint64_t value
= *(uint64_t *)(*tb_ptr
);
187 *tb_ptr
+= sizeof(value
);
192 /* Read indexed register (native size) from bytecode. */
193 static tcg_target_ulong
194 tci_read_r(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
196 tcg_target_ulong value
= tci_read_reg(regs
, **tb_ptr
);
201 /* Read indexed register (8 bit) from bytecode. */
202 static uint8_t tci_read_r8(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
204 uint8_t value
= tci_read_reg8(regs
, **tb_ptr
);
209 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
210 /* Read indexed register (8 bit signed) from bytecode. */
211 static int8_t tci_read_r8s(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
213 int8_t value
= tci_read_reg8s(regs
, **tb_ptr
);
219 /* Read indexed register (16 bit) from bytecode. */
220 static uint16_t tci_read_r16(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
222 uint16_t value
= tci_read_reg16(regs
, **tb_ptr
);
227 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
228 /* Read indexed register (16 bit signed) from bytecode. */
229 static int16_t tci_read_r16s(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
231 int16_t value
= tci_read_reg16s(regs
, **tb_ptr
);
237 /* Read indexed register (32 bit) from bytecode. */
238 static uint32_t tci_read_r32(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
240 uint32_t value
= tci_read_reg32(regs
, **tb_ptr
);
245 #if TCG_TARGET_REG_BITS == 32
246 /* Read two indexed registers (2 * 32 bit) from bytecode. */
247 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
249 uint32_t low
= tci_read_r32(regs
, tb_ptr
);
250 return tci_uint64(tci_read_r32(regs
, tb_ptr
), low
);
252 #elif TCG_TARGET_REG_BITS == 64
253 /* Read indexed register (32 bit signed) from bytecode. */
254 static int32_t tci_read_r32s(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
256 int32_t value
= tci_read_reg32s(regs
, **tb_ptr
);
261 /* Read indexed register (64 bit) from bytecode. */
262 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
264 uint64_t value
= tci_read_reg64(regs
, **tb_ptr
);
270 /* Read indexed register(s) with target address from bytecode. */
272 tci_read_ulong(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
274 target_ulong taddr
= tci_read_r(regs
, tb_ptr
);
275 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
276 taddr
+= (uint64_t)tci_read_r(regs
, tb_ptr
) << 32;
281 /* Read indexed register or constant (native size) from bytecode. */
282 static tcg_target_ulong
283 tci_read_ri(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
285 tcg_target_ulong value
;
288 if (r
== TCG_CONST
) {
289 value
= tci_read_i(tb_ptr
);
291 value
= tci_read_reg(regs
, r
);
296 /* Read indexed register or constant (32 bit) from bytecode. */
297 static uint32_t tci_read_ri32(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
302 if (r
== TCG_CONST
) {
303 value
= tci_read_i32(tb_ptr
);
305 value
= tci_read_reg32(regs
, r
);
310 #if TCG_TARGET_REG_BITS == 32
311 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
312 static uint64_t tci_read_ri64(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
314 uint32_t low
= tci_read_ri32(regs
, tb_ptr
);
315 return tci_uint64(tci_read_ri32(regs
, tb_ptr
), low
);
317 #elif TCG_TARGET_REG_BITS == 64
318 /* Read indexed register or constant (64 bit) from bytecode. */
319 static uint64_t tci_read_ri64(const tcg_target_ulong
*regs
, uint8_t **tb_ptr
)
324 if (r
== TCG_CONST
) {
325 value
= tci_read_i64(tb_ptr
);
327 value
= tci_read_reg64(regs
, r
);
333 static tcg_target_ulong
tci_read_label(uint8_t **tb_ptr
)
335 tcg_target_ulong label
= tci_read_i(tb_ptr
);
336 tci_assert(label
!= 0);
340 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
382 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
424 #ifdef CONFIG_SOFTMMU
425 # define qemu_ld_ub \
426 helper_ret_ldub_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
427 # define qemu_ld_leuw \
428 helper_le_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
429 # define qemu_ld_leul \
430 helper_le_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
431 # define qemu_ld_leq \
432 helper_le_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
433 # define qemu_ld_beuw \
434 helper_be_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
435 # define qemu_ld_beul \
436 helper_be_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
437 # define qemu_ld_beq \
438 helper_be_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
439 # define qemu_st_b(X) \
440 helper_ret_stb_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
441 # define qemu_st_lew(X) \
442 helper_le_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
443 # define qemu_st_lel(X) \
444 helper_le_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
445 # define qemu_st_leq(X) \
446 helper_le_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
447 # define qemu_st_bew(X) \
448 helper_be_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
449 # define qemu_st_bel(X) \
450 helper_be_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
451 # define qemu_st_beq(X) \
452 helper_be_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
454 # define qemu_ld_ub ldub_p(g2h(taddr))
455 # define qemu_ld_leuw lduw_le_p(g2h(taddr))
456 # define qemu_ld_leul (uint32_t)ldl_le_p(g2h(taddr))
457 # define qemu_ld_leq ldq_le_p(g2h(taddr))
458 # define qemu_ld_beuw lduw_be_p(g2h(taddr))
459 # define qemu_ld_beul (uint32_t)ldl_be_p(g2h(taddr))
460 # define qemu_ld_beq ldq_be_p(g2h(taddr))
461 # define qemu_st_b(X) stb_p(g2h(taddr), X)
462 # define qemu_st_lew(X) stw_le_p(g2h(taddr), X)
463 # define qemu_st_lel(X) stl_le_p(g2h(taddr), X)
464 # define qemu_st_leq(X) stq_le_p(g2h(taddr), X)
465 # define qemu_st_bew(X) stw_be_p(g2h(taddr), X)
466 # define qemu_st_bel(X) stl_be_p(g2h(taddr), X)
467 # define qemu_st_beq(X) stq_be_p(g2h(taddr), X)
470 /* Interpret pseudo code in tb. */
471 uintptr_t tcg_qemu_tb_exec(CPUArchState
*env
, uint8_t *tb_ptr
)
473 tcg_target_ulong regs
[TCG_TARGET_NB_REGS
];
474 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
475 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
478 regs
[TCG_AREG0
] = (tcg_target_ulong
)env
;
479 regs
[TCG_REG_CALL_STACK
] = sp_value
;
483 TCGOpcode opc
= tb_ptr
[0];
484 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
485 uint8_t op_size
= tb_ptr
[1];
486 uint8_t *old_code_ptr
= tb_ptr
;
491 tcg_target_ulong label
;
498 #if TCG_TARGET_REG_BITS == 32
504 tci_tb_ptr
= (uintptr_t)tb_ptr
;
507 /* Skip opcode and size entry. */
512 t0
= tci_read_ri(regs
, &tb_ptr
);
513 #if TCG_TARGET_REG_BITS == 32
514 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
515 tci_read_reg(regs
, TCG_REG_R1
),
516 tci_read_reg(regs
, TCG_REG_R2
),
517 tci_read_reg(regs
, TCG_REG_R3
),
518 tci_read_reg(regs
, TCG_REG_R5
),
519 tci_read_reg(regs
, TCG_REG_R6
),
520 tci_read_reg(regs
, TCG_REG_R7
),
521 tci_read_reg(regs
, TCG_REG_R8
),
522 tci_read_reg(regs
, TCG_REG_R9
),
523 tci_read_reg(regs
, TCG_REG_R10
));
524 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
525 tci_write_reg(regs
, TCG_REG_R1
, tmp64
>> 32);
527 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
528 tci_read_reg(regs
, TCG_REG_R1
),
529 tci_read_reg(regs
, TCG_REG_R2
),
530 tci_read_reg(regs
, TCG_REG_R3
),
531 tci_read_reg(regs
, TCG_REG_R5
));
532 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
536 label
= tci_read_label(&tb_ptr
);
537 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
538 tb_ptr
= (uint8_t *)label
;
540 case INDEX_op_setcond_i32
:
542 t1
= tci_read_r32(regs
, &tb_ptr
);
543 t2
= tci_read_ri32(regs
, &tb_ptr
);
544 condition
= *tb_ptr
++;
545 tci_write_reg32(regs
, t0
, tci_compare32(t1
, t2
, condition
));
547 #if TCG_TARGET_REG_BITS == 32
548 case INDEX_op_setcond2_i32
:
550 tmp64
= tci_read_r64(regs
, &tb_ptr
);
551 v64
= tci_read_ri64(regs
, &tb_ptr
);
552 condition
= *tb_ptr
++;
553 tci_write_reg32(regs
, t0
, tci_compare64(tmp64
, v64
, condition
));
555 #elif TCG_TARGET_REG_BITS == 64
556 case INDEX_op_setcond_i64
:
558 t1
= tci_read_r64(regs
, &tb_ptr
);
559 t2
= tci_read_ri64(regs
, &tb_ptr
);
560 condition
= *tb_ptr
++;
561 tci_write_reg64(regs
, t0
, tci_compare64(t1
, t2
, condition
));
564 case INDEX_op_mov_i32
:
566 t1
= tci_read_r32(regs
, &tb_ptr
);
567 tci_write_reg32(regs
, t0
, t1
);
569 case INDEX_op_movi_i32
:
571 t1
= tci_read_i32(&tb_ptr
);
572 tci_write_reg32(regs
, t0
, t1
);
575 /* Load/store operations (32 bit). */
577 case INDEX_op_ld8u_i32
:
579 t1
= tci_read_r(regs
, &tb_ptr
);
580 t2
= tci_read_s32(&tb_ptr
);
581 tci_write_reg8(regs
, t0
, *(uint8_t *)(t1
+ t2
));
583 case INDEX_op_ld8s_i32
:
584 case INDEX_op_ld16u_i32
:
587 case INDEX_op_ld16s_i32
:
590 case INDEX_op_ld_i32
:
592 t1
= tci_read_r(regs
, &tb_ptr
);
593 t2
= tci_read_s32(&tb_ptr
);
594 tci_write_reg32(regs
, t0
, *(uint32_t *)(t1
+ t2
));
596 case INDEX_op_st8_i32
:
597 t0
= tci_read_r8(regs
, &tb_ptr
);
598 t1
= tci_read_r(regs
, &tb_ptr
);
599 t2
= tci_read_s32(&tb_ptr
);
600 *(uint8_t *)(t1
+ t2
) = t0
;
602 case INDEX_op_st16_i32
:
603 t0
= tci_read_r16(regs
, &tb_ptr
);
604 t1
= tci_read_r(regs
, &tb_ptr
);
605 t2
= tci_read_s32(&tb_ptr
);
606 *(uint16_t *)(t1
+ t2
) = t0
;
608 case INDEX_op_st_i32
:
609 t0
= tci_read_r32(regs
, &tb_ptr
);
610 t1
= tci_read_r(regs
, &tb_ptr
);
611 t2
= tci_read_s32(&tb_ptr
);
612 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
613 *(uint32_t *)(t1
+ t2
) = t0
;
616 /* Arithmetic operations (32 bit). */
618 case INDEX_op_add_i32
:
620 t1
= tci_read_ri32(regs
, &tb_ptr
);
621 t2
= tci_read_ri32(regs
, &tb_ptr
);
622 tci_write_reg32(regs
, t0
, t1
+ t2
);
624 case INDEX_op_sub_i32
:
626 t1
= tci_read_ri32(regs
, &tb_ptr
);
627 t2
= tci_read_ri32(regs
, &tb_ptr
);
628 tci_write_reg32(regs
, t0
, t1
- t2
);
630 case INDEX_op_mul_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 #if TCG_TARGET_HAS_div_i32
637 case INDEX_op_div_i32
:
639 t1
= tci_read_ri32(regs
, &tb_ptr
);
640 t2
= tci_read_ri32(regs
, &tb_ptr
);
641 tci_write_reg32(regs
, t0
, (int32_t)t1
/ (int32_t)t2
);
643 case INDEX_op_divu_i32
:
645 t1
= tci_read_ri32(regs
, &tb_ptr
);
646 t2
= tci_read_ri32(regs
, &tb_ptr
);
647 tci_write_reg32(regs
, t0
, t1
/ t2
);
649 case INDEX_op_rem_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_remu_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 #elif TCG_TARGET_HAS_div2_i32
662 case INDEX_op_div2_i32
:
663 case INDEX_op_divu2_i32
:
667 case INDEX_op_and_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 case INDEX_op_or_i32
:
675 t1
= tci_read_ri32(regs
, &tb_ptr
);
676 t2
= tci_read_ri32(regs
, &tb_ptr
);
677 tci_write_reg32(regs
, t0
, t1
| t2
);
679 case INDEX_op_xor_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
);
686 /* Shift/rotate operations (32 bit). */
688 case INDEX_op_shl_i32
:
690 t1
= tci_read_ri32(regs
, &tb_ptr
);
691 t2
= tci_read_ri32(regs
, &tb_ptr
);
692 tci_write_reg32(regs
, t0
, t1
<< (t2
& 31));
694 case INDEX_op_shr_i32
:
696 t1
= tci_read_ri32(regs
, &tb_ptr
);
697 t2
= tci_read_ri32(regs
, &tb_ptr
);
698 tci_write_reg32(regs
, t0
, t1
>> (t2
& 31));
700 case INDEX_op_sar_i32
:
702 t1
= tci_read_ri32(regs
, &tb_ptr
);
703 t2
= tci_read_ri32(regs
, &tb_ptr
);
704 tci_write_reg32(regs
, t0
, ((int32_t)t1
>> (t2
& 31)));
706 #if TCG_TARGET_HAS_rot_i32
707 case INDEX_op_rotl_i32
:
709 t1
= tci_read_ri32(regs
, &tb_ptr
);
710 t2
= tci_read_ri32(regs
, &tb_ptr
);
711 tci_write_reg32(regs
, t0
, rol32(t1
, t2
& 31));
713 case INDEX_op_rotr_i32
:
715 t1
= tci_read_ri32(regs
, &tb_ptr
);
716 t2
= tci_read_ri32(regs
, &tb_ptr
);
717 tci_write_reg32(regs
, t0
, ror32(t1
, t2
& 31));
720 #if TCG_TARGET_HAS_deposit_i32
721 case INDEX_op_deposit_i32
:
723 t1
= tci_read_r32(regs
, &tb_ptr
);
724 t2
= tci_read_r32(regs
, &tb_ptr
);
727 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
728 tci_write_reg32(regs
, t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
731 case INDEX_op_brcond_i32
:
732 t0
= tci_read_r32(regs
, &tb_ptr
);
733 t1
= tci_read_ri32(regs
, &tb_ptr
);
734 condition
= *tb_ptr
++;
735 label
= tci_read_label(&tb_ptr
);
736 if (tci_compare32(t0
, t1
, condition
)) {
737 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
738 tb_ptr
= (uint8_t *)label
;
742 #if TCG_TARGET_REG_BITS == 32
743 case INDEX_op_add2_i32
:
746 tmp64
= tci_read_r64(regs
, &tb_ptr
);
747 tmp64
+= tci_read_r64(regs
, &tb_ptr
);
748 tci_write_reg64(regs
, t1
, t0
, tmp64
);
750 case INDEX_op_sub2_i32
:
753 tmp64
= tci_read_r64(regs
, &tb_ptr
);
754 tmp64
-= tci_read_r64(regs
, &tb_ptr
);
755 tci_write_reg64(regs
, t1
, t0
, tmp64
);
757 case INDEX_op_brcond2_i32
:
758 tmp64
= tci_read_r64(regs
, &tb_ptr
);
759 v64
= tci_read_ri64(regs
, &tb_ptr
);
760 condition
= *tb_ptr
++;
761 label
= tci_read_label(&tb_ptr
);
762 if (tci_compare64(tmp64
, v64
, condition
)) {
763 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
764 tb_ptr
= (uint8_t *)label
;
768 case INDEX_op_mulu2_i32
:
771 t2
= tci_read_r32(regs
, &tb_ptr
);
772 tmp64
= tci_read_r32(regs
, &tb_ptr
);
773 tci_write_reg64(regs
, t1
, t0
, t2
* tmp64
);
775 #endif /* TCG_TARGET_REG_BITS == 32 */
776 #if TCG_TARGET_HAS_ext8s_i32
777 case INDEX_op_ext8s_i32
:
779 t1
= tci_read_r8s(regs
, &tb_ptr
);
780 tci_write_reg32(regs
, t0
, t1
);
783 #if TCG_TARGET_HAS_ext16s_i32
784 case INDEX_op_ext16s_i32
:
786 t1
= tci_read_r16s(regs
, &tb_ptr
);
787 tci_write_reg32(regs
, t0
, t1
);
790 #if TCG_TARGET_HAS_ext8u_i32
791 case INDEX_op_ext8u_i32
:
793 t1
= tci_read_r8(regs
, &tb_ptr
);
794 tci_write_reg32(regs
, t0
, t1
);
797 #if TCG_TARGET_HAS_ext16u_i32
798 case INDEX_op_ext16u_i32
:
800 t1
= tci_read_r16(regs
, &tb_ptr
);
801 tci_write_reg32(regs
, t0
, t1
);
804 #if TCG_TARGET_HAS_bswap16_i32
805 case INDEX_op_bswap16_i32
:
807 t1
= tci_read_r16(regs
, &tb_ptr
);
808 tci_write_reg32(regs
, t0
, bswap16(t1
));
811 #if TCG_TARGET_HAS_bswap32_i32
812 case INDEX_op_bswap32_i32
:
814 t1
= tci_read_r32(regs
, &tb_ptr
);
815 tci_write_reg32(regs
, t0
, bswap32(t1
));
818 #if TCG_TARGET_HAS_not_i32
819 case INDEX_op_not_i32
:
821 t1
= tci_read_r32(regs
, &tb_ptr
);
822 tci_write_reg32(regs
, t0
, ~t1
);
825 #if TCG_TARGET_HAS_neg_i32
826 case INDEX_op_neg_i32
:
828 t1
= tci_read_r32(regs
, &tb_ptr
);
829 tci_write_reg32(regs
, t0
, -t1
);
832 #if TCG_TARGET_REG_BITS == 64
833 case INDEX_op_mov_i64
:
835 t1
= tci_read_r64(regs
, &tb_ptr
);
836 tci_write_reg64(regs
, t0
, t1
);
838 case INDEX_op_movi_i64
:
840 t1
= tci_read_i64(&tb_ptr
);
841 tci_write_reg64(regs
, t0
, t1
);
844 /* Load/store operations (64 bit). */
846 case INDEX_op_ld8u_i64
:
848 t1
= tci_read_r(regs
, &tb_ptr
);
849 t2
= tci_read_s32(&tb_ptr
);
850 tci_write_reg8(regs
, t0
, *(uint8_t *)(t1
+ t2
));
852 case INDEX_op_ld8s_i64
:
853 case INDEX_op_ld16u_i64
:
854 case INDEX_op_ld16s_i64
:
857 case INDEX_op_ld32u_i64
:
859 t1
= tci_read_r(regs
, &tb_ptr
);
860 t2
= tci_read_s32(&tb_ptr
);
861 tci_write_reg32(regs
, t0
, *(uint32_t *)(t1
+ t2
));
863 case INDEX_op_ld32s_i64
:
865 t1
= tci_read_r(regs
, &tb_ptr
);
866 t2
= tci_read_s32(&tb_ptr
);
867 tci_write_reg32s(regs
, t0
, *(int32_t *)(t1
+ t2
));
869 case INDEX_op_ld_i64
:
871 t1
= tci_read_r(regs
, &tb_ptr
);
872 t2
= tci_read_s32(&tb_ptr
);
873 tci_write_reg64(regs
, t0
, *(uint64_t *)(t1
+ t2
));
875 case INDEX_op_st8_i64
:
876 t0
= tci_read_r8(regs
, &tb_ptr
);
877 t1
= tci_read_r(regs
, &tb_ptr
);
878 t2
= tci_read_s32(&tb_ptr
);
879 *(uint8_t *)(t1
+ t2
) = t0
;
881 case INDEX_op_st16_i64
:
882 t0
= tci_read_r16(regs
, &tb_ptr
);
883 t1
= tci_read_r(regs
, &tb_ptr
);
884 t2
= tci_read_s32(&tb_ptr
);
885 *(uint16_t *)(t1
+ t2
) = t0
;
887 case INDEX_op_st32_i64
:
888 t0
= tci_read_r32(regs
, &tb_ptr
);
889 t1
= tci_read_r(regs
, &tb_ptr
);
890 t2
= tci_read_s32(&tb_ptr
);
891 *(uint32_t *)(t1
+ t2
) = t0
;
893 case INDEX_op_st_i64
:
894 t0
= tci_read_r64(regs
, &tb_ptr
);
895 t1
= tci_read_r(regs
, &tb_ptr
);
896 t2
= tci_read_s32(&tb_ptr
);
897 tci_assert(t1
!= sp_value
|| (int32_t)t2
< 0);
898 *(uint64_t *)(t1
+ t2
) = t0
;
901 /* Arithmetic operations (64 bit). */
903 case INDEX_op_add_i64
:
905 t1
= tci_read_ri64(regs
, &tb_ptr
);
906 t2
= tci_read_ri64(regs
, &tb_ptr
);
907 tci_write_reg64(regs
, t0
, t1
+ t2
);
909 case INDEX_op_sub_i64
:
911 t1
= tci_read_ri64(regs
, &tb_ptr
);
912 t2
= tci_read_ri64(regs
, &tb_ptr
);
913 tci_write_reg64(regs
, t0
, t1
- t2
);
915 case INDEX_op_mul_i64
:
917 t1
= tci_read_ri64(regs
, &tb_ptr
);
918 t2
= tci_read_ri64(regs
, &tb_ptr
);
919 tci_write_reg64(regs
, t0
, t1
* t2
);
921 #if TCG_TARGET_HAS_div_i64
922 case INDEX_op_div_i64
:
923 case INDEX_op_divu_i64
:
924 case INDEX_op_rem_i64
:
925 case INDEX_op_remu_i64
:
928 #elif TCG_TARGET_HAS_div2_i64
929 case INDEX_op_div2_i64
:
930 case INDEX_op_divu2_i64
:
934 case INDEX_op_and_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 case INDEX_op_or_i64
:
942 t1
= tci_read_ri64(regs
, &tb_ptr
);
943 t2
= tci_read_ri64(regs
, &tb_ptr
);
944 tci_write_reg64(regs
, t0
, t1
| t2
);
946 case INDEX_op_xor_i64
:
948 t1
= tci_read_ri64(regs
, &tb_ptr
);
949 t2
= tci_read_ri64(regs
, &tb_ptr
);
950 tci_write_reg64(regs
, t0
, t1
^ t2
);
953 /* Shift/rotate operations (64 bit). */
955 case INDEX_op_shl_i64
:
957 t1
= tci_read_ri64(regs
, &tb_ptr
);
958 t2
= tci_read_ri64(regs
, &tb_ptr
);
959 tci_write_reg64(regs
, t0
, t1
<< (t2
& 63));
961 case INDEX_op_shr_i64
:
963 t1
= tci_read_ri64(regs
, &tb_ptr
);
964 t2
= tci_read_ri64(regs
, &tb_ptr
);
965 tci_write_reg64(regs
, t0
, t1
>> (t2
& 63));
967 case INDEX_op_sar_i64
:
969 t1
= tci_read_ri64(regs
, &tb_ptr
);
970 t2
= tci_read_ri64(regs
, &tb_ptr
);
971 tci_write_reg64(regs
, t0
, ((int64_t)t1
>> (t2
& 63)));
973 #if TCG_TARGET_HAS_rot_i64
974 case INDEX_op_rotl_i64
:
976 t1
= tci_read_ri64(regs
, &tb_ptr
);
977 t2
= tci_read_ri64(regs
, &tb_ptr
);
978 tci_write_reg64(regs
, t0
, rol64(t1
, t2
& 63));
980 case INDEX_op_rotr_i64
:
982 t1
= tci_read_ri64(regs
, &tb_ptr
);
983 t2
= tci_read_ri64(regs
, &tb_ptr
);
984 tci_write_reg64(regs
, t0
, ror64(t1
, t2
& 63));
987 #if TCG_TARGET_HAS_deposit_i64
988 case INDEX_op_deposit_i64
:
990 t1
= tci_read_r64(regs
, &tb_ptr
);
991 t2
= tci_read_r64(regs
, &tb_ptr
);
994 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
995 tci_write_reg64(regs
, t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
998 case INDEX_op_brcond_i64
:
999 t0
= tci_read_r64(regs
, &tb_ptr
);
1000 t1
= tci_read_ri64(regs
, &tb_ptr
);
1001 condition
= *tb_ptr
++;
1002 label
= tci_read_label(&tb_ptr
);
1003 if (tci_compare64(t0
, t1
, condition
)) {
1004 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
1005 tb_ptr
= (uint8_t *)label
;
1009 #if TCG_TARGET_HAS_ext8u_i64
1010 case INDEX_op_ext8u_i64
:
1012 t1
= tci_read_r8(regs
, &tb_ptr
);
1013 tci_write_reg64(regs
, t0
, t1
);
1016 #if TCG_TARGET_HAS_ext8s_i64
1017 case INDEX_op_ext8s_i64
:
1019 t1
= tci_read_r8s(regs
, &tb_ptr
);
1020 tci_write_reg64(regs
, t0
, t1
);
1023 #if TCG_TARGET_HAS_ext16s_i64
1024 case INDEX_op_ext16s_i64
:
1026 t1
= tci_read_r16s(regs
, &tb_ptr
);
1027 tci_write_reg64(regs
, t0
, t1
);
1030 #if TCG_TARGET_HAS_ext16u_i64
1031 case INDEX_op_ext16u_i64
:
1033 t1
= tci_read_r16(regs
, &tb_ptr
);
1034 tci_write_reg64(regs
, t0
, t1
);
1037 #if TCG_TARGET_HAS_ext32s_i64
1038 case INDEX_op_ext32s_i64
:
1040 case INDEX_op_ext_i32_i64
:
1042 t1
= tci_read_r32s(regs
, &tb_ptr
);
1043 tci_write_reg64(regs
, t0
, t1
);
1045 #if TCG_TARGET_HAS_ext32u_i64
1046 case INDEX_op_ext32u_i64
:
1048 case INDEX_op_extu_i32_i64
:
1050 t1
= tci_read_r32(regs
, &tb_ptr
);
1051 tci_write_reg64(regs
, t0
, t1
);
1053 #if TCG_TARGET_HAS_bswap16_i64
1054 case INDEX_op_bswap16_i64
:
1056 t1
= tci_read_r16(regs
, &tb_ptr
);
1057 tci_write_reg64(regs
, t0
, bswap16(t1
));
1060 #if TCG_TARGET_HAS_bswap32_i64
1061 case INDEX_op_bswap32_i64
:
1063 t1
= tci_read_r32(regs
, &tb_ptr
);
1064 tci_write_reg64(regs
, t0
, bswap32(t1
));
1067 #if TCG_TARGET_HAS_bswap64_i64
1068 case INDEX_op_bswap64_i64
:
1070 t1
= tci_read_r64(regs
, &tb_ptr
);
1071 tci_write_reg64(regs
, t0
, bswap64(t1
));
1074 #if TCG_TARGET_HAS_not_i64
1075 case INDEX_op_not_i64
:
1077 t1
= tci_read_r64(regs
, &tb_ptr
);
1078 tci_write_reg64(regs
, t0
, ~t1
);
1081 #if TCG_TARGET_HAS_neg_i64
1082 case INDEX_op_neg_i64
:
1084 t1
= tci_read_r64(regs
, &tb_ptr
);
1085 tci_write_reg64(regs
, t0
, -t1
);
1088 #endif /* TCG_TARGET_REG_BITS == 64 */
1090 /* QEMU specific operations. */
1092 case INDEX_op_exit_tb
:
1093 ret
= *(uint64_t *)tb_ptr
;
1096 case INDEX_op_goto_tb
:
1097 /* Jump address is aligned */
1098 tb_ptr
= QEMU_ALIGN_PTR_UP(tb_ptr
, 4);
1099 t0
= atomic_read((int32_t *)tb_ptr
);
1100 tb_ptr
+= sizeof(int32_t);
1101 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
1102 tb_ptr
+= (int32_t)t0
;
1104 case INDEX_op_qemu_ld_i32
:
1106 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1107 oi
= tci_read_i(&tb_ptr
);
1108 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1113 tmp32
= (int8_t)qemu_ld_ub
;
1116 tmp32
= qemu_ld_leuw
;
1119 tmp32
= (int16_t)qemu_ld_leuw
;
1122 tmp32
= qemu_ld_leul
;
1125 tmp32
= qemu_ld_beuw
;
1128 tmp32
= (int16_t)qemu_ld_beuw
;
1131 tmp32
= qemu_ld_beul
;
1136 tci_write_reg(regs
, t0
, tmp32
);
1138 case INDEX_op_qemu_ld_i64
:
1140 if (TCG_TARGET_REG_BITS
== 32) {
1143 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1144 oi
= tci_read_i(&tb_ptr
);
1145 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1150 tmp64
= (int8_t)qemu_ld_ub
;
1153 tmp64
= qemu_ld_leuw
;
1156 tmp64
= (int16_t)qemu_ld_leuw
;
1159 tmp64
= qemu_ld_leul
;
1162 tmp64
= (int32_t)qemu_ld_leul
;
1165 tmp64
= qemu_ld_leq
;
1168 tmp64
= qemu_ld_beuw
;
1171 tmp64
= (int16_t)qemu_ld_beuw
;
1174 tmp64
= qemu_ld_beul
;
1177 tmp64
= (int32_t)qemu_ld_beul
;
1180 tmp64
= qemu_ld_beq
;
1185 tci_write_reg(regs
, t0
, tmp64
);
1186 if (TCG_TARGET_REG_BITS
== 32) {
1187 tci_write_reg(regs
, t1
, tmp64
>> 32);
1190 case INDEX_op_qemu_st_i32
:
1191 t0
= tci_read_r(regs
, &tb_ptr
);
1192 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1193 oi
= tci_read_i(&tb_ptr
);
1194 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1214 case INDEX_op_qemu_st_i64
:
1215 tmp64
= tci_read_r64(regs
, &tb_ptr
);
1216 taddr
= tci_read_ulong(regs
, &tb_ptr
);
1217 oi
= tci_read_i(&tb_ptr
);
1218 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1245 /* Ensure ordering for all kinds */
1252 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);