2 * Tiny Code Interpreter for QEMU
4 * Copyright (c) 2009, 2011 Stefan Weil
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 /* Defining NDEBUG disables assertions (which makes the code faster). */
23 #if !defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
27 #include "qemu-common.h"
28 #include "exec/exec-all.h" /* MAX_OPC_PARAM_IARGS */
29 #include "exec/cpu_ldst.h"
32 /* Marker for missing code. */
35 fprintf(stderr, "TODO %s:%u: %s()\n", \
36 __FILE__, __LINE__, __func__); \
40 #if MAX_OPC_PARAM_IARGS != 5
41 # error Fix needed, number of supported input arguments changed!
43 #if TCG_TARGET_REG_BITS == 32
44 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
45 tcg_target_ulong
, tcg_target_ulong
,
46 tcg_target_ulong
, tcg_target_ulong
,
47 tcg_target_ulong
, tcg_target_ulong
,
48 tcg_target_ulong
, tcg_target_ulong
);
50 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
51 tcg_target_ulong
, tcg_target_ulong
,
55 static tcg_target_ulong tci_reg
[TCG_TARGET_NB_REGS
];
57 static tcg_target_ulong
tci_read_reg(TCGReg index
)
59 assert(index
< ARRAY_SIZE(tci_reg
));
60 return tci_reg
[index
];
63 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
64 static int8_t tci_read_reg8s(TCGReg index
)
66 return (int8_t)tci_read_reg(index
);
70 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
71 static int16_t tci_read_reg16s(TCGReg index
)
73 return (int16_t)tci_read_reg(index
);
77 #if TCG_TARGET_REG_BITS == 64
78 static int32_t tci_read_reg32s(TCGReg index
)
80 return (int32_t)tci_read_reg(index
);
84 static uint8_t tci_read_reg8(TCGReg index
)
86 return (uint8_t)tci_read_reg(index
);
89 static uint16_t tci_read_reg16(TCGReg index
)
91 return (uint16_t)tci_read_reg(index
);
94 static uint32_t tci_read_reg32(TCGReg index
)
96 return (uint32_t)tci_read_reg(index
);
99 #if TCG_TARGET_REG_BITS == 64
100 static uint64_t tci_read_reg64(TCGReg index
)
102 return tci_read_reg(index
);
106 static void tci_write_reg(TCGReg index
, tcg_target_ulong value
)
108 assert(index
< ARRAY_SIZE(tci_reg
));
109 assert(index
!= TCG_AREG0
);
110 assert(index
!= TCG_REG_CALL_STACK
);
111 tci_reg
[index
] = value
;
114 #if TCG_TARGET_REG_BITS == 64
115 static void tci_write_reg32s(TCGReg index
, int32_t value
)
117 tci_write_reg(index
, value
);
121 static void tci_write_reg8(TCGReg index
, uint8_t value
)
123 tci_write_reg(index
, value
);
126 static void tci_write_reg32(TCGReg index
, uint32_t value
)
128 tci_write_reg(index
, value
);
131 #if TCG_TARGET_REG_BITS == 32
132 static void tci_write_reg64(uint32_t high_index
, uint32_t low_index
,
135 tci_write_reg(low_index
, value
);
136 tci_write_reg(high_index
, value
>> 32);
138 #elif TCG_TARGET_REG_BITS == 64
139 static void tci_write_reg64(TCGReg index
, uint64_t value
)
141 tci_write_reg(index
, value
);
145 #if TCG_TARGET_REG_BITS == 32
146 /* Create a 64 bit value from two 32 bit values. */
147 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
149 return ((uint64_t)high
<< 32) + low
;
153 /* Read constant (native size) from bytecode. */
154 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
156 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
157 *tb_ptr
+= sizeof(value
);
161 /* Read unsigned constant (32 bit) from bytecode. */
162 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
164 uint32_t value
= *(uint32_t *)(*tb_ptr
);
165 *tb_ptr
+= sizeof(value
);
169 /* Read signed constant (32 bit) from bytecode. */
170 static int32_t tci_read_s32(uint8_t **tb_ptr
)
172 int32_t value
= *(int32_t *)(*tb_ptr
);
173 *tb_ptr
+= sizeof(value
);
177 #if TCG_TARGET_REG_BITS == 64
178 /* Read constant (64 bit) from bytecode. */
179 static uint64_t tci_read_i64(uint8_t **tb_ptr
)
181 uint64_t value
= *(uint64_t *)(*tb_ptr
);
182 *tb_ptr
+= sizeof(value
);
187 /* Read indexed register (native size) from bytecode. */
188 static tcg_target_ulong
tci_read_r(uint8_t **tb_ptr
)
190 tcg_target_ulong value
= tci_read_reg(**tb_ptr
);
195 /* Read indexed register (8 bit) from bytecode. */
196 static uint8_t tci_read_r8(uint8_t **tb_ptr
)
198 uint8_t value
= tci_read_reg8(**tb_ptr
);
203 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
204 /* Read indexed register (8 bit signed) from bytecode. */
205 static int8_t tci_read_r8s(uint8_t **tb_ptr
)
207 int8_t value
= tci_read_reg8s(**tb_ptr
);
213 /* Read indexed register (16 bit) from bytecode. */
214 static uint16_t tci_read_r16(uint8_t **tb_ptr
)
216 uint16_t value
= tci_read_reg16(**tb_ptr
);
221 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
222 /* Read indexed register (16 bit signed) from bytecode. */
223 static int16_t tci_read_r16s(uint8_t **tb_ptr
)
225 int16_t value
= tci_read_reg16s(**tb_ptr
);
231 /* Read indexed register (32 bit) from bytecode. */
232 static uint32_t tci_read_r32(uint8_t **tb_ptr
)
234 uint32_t value
= tci_read_reg32(**tb_ptr
);
239 #if TCG_TARGET_REG_BITS == 32
240 /* Read two indexed registers (2 * 32 bit) from bytecode. */
241 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
243 uint32_t low
= tci_read_r32(tb_ptr
);
244 return tci_uint64(tci_read_r32(tb_ptr
), low
);
246 #elif TCG_TARGET_REG_BITS == 64
247 /* Read indexed register (32 bit signed) from bytecode. */
248 static int32_t tci_read_r32s(uint8_t **tb_ptr
)
250 int32_t value
= tci_read_reg32s(**tb_ptr
);
255 /* Read indexed register (64 bit) from bytecode. */
256 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
258 uint64_t value
= tci_read_reg64(**tb_ptr
);
264 /* Read indexed register(s) with target address from bytecode. */
265 static target_ulong
tci_read_ulong(uint8_t **tb_ptr
)
267 target_ulong taddr
= tci_read_r(tb_ptr
);
268 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
269 taddr
+= (uint64_t)tci_read_r(tb_ptr
) << 32;
274 /* Read indexed register or constant (native size) from bytecode. */
275 static tcg_target_ulong
tci_read_ri(uint8_t **tb_ptr
)
277 tcg_target_ulong value
;
280 if (r
== TCG_CONST
) {
281 value
= tci_read_i(tb_ptr
);
283 value
= tci_read_reg(r
);
288 /* Read indexed register or constant (32 bit) from bytecode. */
289 static uint32_t tci_read_ri32(uint8_t **tb_ptr
)
294 if (r
== TCG_CONST
) {
295 value
= tci_read_i32(tb_ptr
);
297 value
= tci_read_reg32(r
);
302 #if TCG_TARGET_REG_BITS == 32
303 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
304 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
306 uint32_t low
= tci_read_ri32(tb_ptr
);
307 return tci_uint64(tci_read_ri32(tb_ptr
), low
);
309 #elif TCG_TARGET_REG_BITS == 64
310 /* Read indexed register or constant (64 bit) from bytecode. */
311 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
316 if (r
== TCG_CONST
) {
317 value
= tci_read_i64(tb_ptr
);
319 value
= tci_read_reg64(r
);
325 static tcg_target_ulong
tci_read_label(uint8_t **tb_ptr
)
327 tcg_target_ulong label
= tci_read_i(tb_ptr
);
332 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
374 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
416 #ifdef CONFIG_SOFTMMU
417 # define qemu_ld_ub \
418 helper_ret_ldub_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
419 # define qemu_ld_leuw \
420 helper_le_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
421 # define qemu_ld_leul \
422 helper_le_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
423 # define qemu_ld_leq \
424 helper_le_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
425 # define qemu_ld_beuw \
426 helper_be_lduw_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
427 # define qemu_ld_beul \
428 helper_be_ldul_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
429 # define qemu_ld_beq \
430 helper_be_ldq_mmu(env, taddr, oi, (uintptr_t)tb_ptr)
431 # define qemu_st_b(X) \
432 helper_ret_stb_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
433 # define qemu_st_lew(X) \
434 helper_le_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
435 # define qemu_st_lel(X) \
436 helper_le_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
437 # define qemu_st_leq(X) \
438 helper_le_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
439 # define qemu_st_bew(X) \
440 helper_be_stw_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
441 # define qemu_st_bel(X) \
442 helper_be_stl_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
443 # define qemu_st_beq(X) \
444 helper_be_stq_mmu(env, taddr, X, oi, (uintptr_t)tb_ptr)
446 # define qemu_ld_ub ldub_p(g2h(taddr))
447 # define qemu_ld_leuw lduw_le_p(g2h(taddr))
448 # define qemu_ld_leul (uint32_t)ldl_le_p(g2h(taddr))
449 # define qemu_ld_leq ldq_le_p(g2h(taddr))
450 # define qemu_ld_beuw lduw_be_p(g2h(taddr))
451 # define qemu_ld_beul (uint32_t)ldl_be_p(g2h(taddr))
452 # define qemu_ld_beq ldq_be_p(g2h(taddr))
453 # define qemu_st_b(X) stb_p(g2h(taddr), X)
454 # define qemu_st_lew(X) stw_le_p(g2h(taddr), X)
455 # define qemu_st_lel(X) stl_le_p(g2h(taddr), X)
456 # define qemu_st_leq(X) stq_le_p(g2h(taddr), X)
457 # define qemu_st_bew(X) stw_be_p(g2h(taddr), X)
458 # define qemu_st_bel(X) stl_be_p(g2h(taddr), X)
459 # define qemu_st_beq(X) stq_be_p(g2h(taddr), X)
462 /* Interpret pseudo code in tb. */
463 uintptr_t tcg_qemu_tb_exec(CPUArchState
*env
, uint8_t *tb_ptr
)
465 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
466 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
467 uintptr_t next_tb
= 0;
469 tci_reg
[TCG_AREG0
] = (tcg_target_ulong
)env
;
470 tci_reg
[TCG_REG_CALL_STACK
] = sp_value
;
474 TCGOpcode opc
= tb_ptr
[0];
476 uint8_t op_size
= tb_ptr
[1];
477 uint8_t *old_code_ptr
= tb_ptr
;
482 tcg_target_ulong label
;
489 #if TCG_TARGET_REG_BITS == 32
495 tci_tb_ptr
= (uintptr_t)tb_ptr
;
498 /* Skip opcode and size entry. */
503 t0
= tci_read_ri(&tb_ptr
);
504 #if TCG_TARGET_REG_BITS == 32
505 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
506 tci_read_reg(TCG_REG_R1
),
507 tci_read_reg(TCG_REG_R2
),
508 tci_read_reg(TCG_REG_R3
),
509 tci_read_reg(TCG_REG_R5
),
510 tci_read_reg(TCG_REG_R6
),
511 tci_read_reg(TCG_REG_R7
),
512 tci_read_reg(TCG_REG_R8
),
513 tci_read_reg(TCG_REG_R9
),
514 tci_read_reg(TCG_REG_R10
));
515 tci_write_reg(TCG_REG_R0
, tmp64
);
516 tci_write_reg(TCG_REG_R1
, tmp64
>> 32);
518 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
519 tci_read_reg(TCG_REG_R1
),
520 tci_read_reg(TCG_REG_R2
),
521 tci_read_reg(TCG_REG_R3
),
522 tci_read_reg(TCG_REG_R5
));
523 tci_write_reg(TCG_REG_R0
, tmp64
);
527 label
= tci_read_label(&tb_ptr
);
528 assert(tb_ptr
== old_code_ptr
+ op_size
);
529 tb_ptr
= (uint8_t *)label
;
531 case INDEX_op_setcond_i32
:
533 t1
= tci_read_r32(&tb_ptr
);
534 t2
= tci_read_ri32(&tb_ptr
);
535 condition
= *tb_ptr
++;
536 tci_write_reg32(t0
, tci_compare32(t1
, t2
, condition
));
538 #if TCG_TARGET_REG_BITS == 32
539 case INDEX_op_setcond2_i32
:
541 tmp64
= tci_read_r64(&tb_ptr
);
542 v64
= tci_read_ri64(&tb_ptr
);
543 condition
= *tb_ptr
++;
544 tci_write_reg32(t0
, tci_compare64(tmp64
, v64
, condition
));
546 #elif TCG_TARGET_REG_BITS == 64
547 case INDEX_op_setcond_i64
:
549 t1
= tci_read_r64(&tb_ptr
);
550 t2
= tci_read_ri64(&tb_ptr
);
551 condition
= *tb_ptr
++;
552 tci_write_reg64(t0
, tci_compare64(t1
, t2
, condition
));
555 case INDEX_op_mov_i32
:
557 t1
= tci_read_r32(&tb_ptr
);
558 tci_write_reg32(t0
, t1
);
560 case INDEX_op_movi_i32
:
562 t1
= tci_read_i32(&tb_ptr
);
563 tci_write_reg32(t0
, t1
);
566 /* Load/store operations (32 bit). */
568 case INDEX_op_ld8u_i32
:
570 t1
= tci_read_r(&tb_ptr
);
571 t2
= tci_read_s32(&tb_ptr
);
572 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
574 case INDEX_op_ld8s_i32
:
575 case INDEX_op_ld16u_i32
:
578 case INDEX_op_ld16s_i32
:
581 case INDEX_op_ld_i32
:
583 t1
= tci_read_r(&tb_ptr
);
584 t2
= tci_read_s32(&tb_ptr
);
585 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
587 case INDEX_op_st8_i32
:
588 t0
= tci_read_r8(&tb_ptr
);
589 t1
= tci_read_r(&tb_ptr
);
590 t2
= tci_read_s32(&tb_ptr
);
591 *(uint8_t *)(t1
+ t2
) = t0
;
593 case INDEX_op_st16_i32
:
594 t0
= tci_read_r16(&tb_ptr
);
595 t1
= tci_read_r(&tb_ptr
);
596 t2
= tci_read_s32(&tb_ptr
);
597 *(uint16_t *)(t1
+ t2
) = t0
;
599 case INDEX_op_st_i32
:
600 t0
= tci_read_r32(&tb_ptr
);
601 t1
= tci_read_r(&tb_ptr
);
602 t2
= tci_read_s32(&tb_ptr
);
603 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
604 *(uint32_t *)(t1
+ t2
) = t0
;
607 /* Arithmetic operations (32 bit). */
609 case INDEX_op_add_i32
:
611 t1
= tci_read_ri32(&tb_ptr
);
612 t2
= tci_read_ri32(&tb_ptr
);
613 tci_write_reg32(t0
, t1
+ t2
);
615 case INDEX_op_sub_i32
:
617 t1
= tci_read_ri32(&tb_ptr
);
618 t2
= tci_read_ri32(&tb_ptr
);
619 tci_write_reg32(t0
, t1
- t2
);
621 case INDEX_op_mul_i32
:
623 t1
= tci_read_ri32(&tb_ptr
);
624 t2
= tci_read_ri32(&tb_ptr
);
625 tci_write_reg32(t0
, t1
* t2
);
627 #if TCG_TARGET_HAS_div_i32
628 case INDEX_op_div_i32
:
630 t1
= tci_read_ri32(&tb_ptr
);
631 t2
= tci_read_ri32(&tb_ptr
);
632 tci_write_reg32(t0
, (int32_t)t1
/ (int32_t)t2
);
634 case INDEX_op_divu_i32
:
636 t1
= tci_read_ri32(&tb_ptr
);
637 t2
= tci_read_ri32(&tb_ptr
);
638 tci_write_reg32(t0
, t1
/ t2
);
640 case INDEX_op_rem_i32
:
642 t1
= tci_read_ri32(&tb_ptr
);
643 t2
= tci_read_ri32(&tb_ptr
);
644 tci_write_reg32(t0
, (int32_t)t1
% (int32_t)t2
);
646 case INDEX_op_remu_i32
:
648 t1
= tci_read_ri32(&tb_ptr
);
649 t2
= tci_read_ri32(&tb_ptr
);
650 tci_write_reg32(t0
, t1
% t2
);
652 #elif TCG_TARGET_HAS_div2_i32
653 case INDEX_op_div2_i32
:
654 case INDEX_op_divu2_i32
:
658 case INDEX_op_and_i32
:
660 t1
= tci_read_ri32(&tb_ptr
);
661 t2
= tci_read_ri32(&tb_ptr
);
662 tci_write_reg32(t0
, t1
& t2
);
664 case INDEX_op_or_i32
:
666 t1
= tci_read_ri32(&tb_ptr
);
667 t2
= tci_read_ri32(&tb_ptr
);
668 tci_write_reg32(t0
, t1
| t2
);
670 case INDEX_op_xor_i32
:
672 t1
= tci_read_ri32(&tb_ptr
);
673 t2
= tci_read_ri32(&tb_ptr
);
674 tci_write_reg32(t0
, t1
^ t2
);
677 /* Shift/rotate operations (32 bit). */
679 case INDEX_op_shl_i32
:
681 t1
= tci_read_ri32(&tb_ptr
);
682 t2
= tci_read_ri32(&tb_ptr
);
683 tci_write_reg32(t0
, t1
<< (t2
& 31));
685 case INDEX_op_shr_i32
:
687 t1
= tci_read_ri32(&tb_ptr
);
688 t2
= tci_read_ri32(&tb_ptr
);
689 tci_write_reg32(t0
, t1
>> (t2
& 31));
691 case INDEX_op_sar_i32
:
693 t1
= tci_read_ri32(&tb_ptr
);
694 t2
= tci_read_ri32(&tb_ptr
);
695 tci_write_reg32(t0
, ((int32_t)t1
>> (t2
& 31)));
697 #if TCG_TARGET_HAS_rot_i32
698 case INDEX_op_rotl_i32
:
700 t1
= tci_read_ri32(&tb_ptr
);
701 t2
= tci_read_ri32(&tb_ptr
);
702 tci_write_reg32(t0
, rol32(t1
, t2
& 31));
704 case INDEX_op_rotr_i32
:
706 t1
= tci_read_ri32(&tb_ptr
);
707 t2
= tci_read_ri32(&tb_ptr
);
708 tci_write_reg32(t0
, ror32(t1
, t2
& 31));
711 #if TCG_TARGET_HAS_deposit_i32
712 case INDEX_op_deposit_i32
:
714 t1
= tci_read_r32(&tb_ptr
);
715 t2
= tci_read_r32(&tb_ptr
);
718 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
719 tci_write_reg32(t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
722 case INDEX_op_brcond_i32
:
723 t0
= tci_read_r32(&tb_ptr
);
724 t1
= tci_read_ri32(&tb_ptr
);
725 condition
= *tb_ptr
++;
726 label
= tci_read_label(&tb_ptr
);
727 if (tci_compare32(t0
, t1
, condition
)) {
728 assert(tb_ptr
== old_code_ptr
+ op_size
);
729 tb_ptr
= (uint8_t *)label
;
733 #if TCG_TARGET_REG_BITS == 32
734 case INDEX_op_add2_i32
:
737 tmp64
= tci_read_r64(&tb_ptr
);
738 tmp64
+= tci_read_r64(&tb_ptr
);
739 tci_write_reg64(t1
, t0
, tmp64
);
741 case INDEX_op_sub2_i32
:
744 tmp64
= tci_read_r64(&tb_ptr
);
745 tmp64
-= tci_read_r64(&tb_ptr
);
746 tci_write_reg64(t1
, t0
, tmp64
);
748 case INDEX_op_brcond2_i32
:
749 tmp64
= tci_read_r64(&tb_ptr
);
750 v64
= tci_read_ri64(&tb_ptr
);
751 condition
= *tb_ptr
++;
752 label
= tci_read_label(&tb_ptr
);
753 if (tci_compare64(tmp64
, v64
, condition
)) {
754 assert(tb_ptr
== old_code_ptr
+ op_size
);
755 tb_ptr
= (uint8_t *)label
;
759 case INDEX_op_mulu2_i32
:
762 t2
= tci_read_r32(&tb_ptr
);
763 tmp64
= tci_read_r32(&tb_ptr
);
764 tci_write_reg64(t1
, t0
, t2
* tmp64
);
766 #endif /* TCG_TARGET_REG_BITS == 32 */
767 #if TCG_TARGET_HAS_ext8s_i32
768 case INDEX_op_ext8s_i32
:
770 t1
= tci_read_r8s(&tb_ptr
);
771 tci_write_reg32(t0
, t1
);
774 #if TCG_TARGET_HAS_ext16s_i32
775 case INDEX_op_ext16s_i32
:
777 t1
= tci_read_r16s(&tb_ptr
);
778 tci_write_reg32(t0
, t1
);
781 #if TCG_TARGET_HAS_ext8u_i32
782 case INDEX_op_ext8u_i32
:
784 t1
= tci_read_r8(&tb_ptr
);
785 tci_write_reg32(t0
, t1
);
788 #if TCG_TARGET_HAS_ext16u_i32
789 case INDEX_op_ext16u_i32
:
791 t1
= tci_read_r16(&tb_ptr
);
792 tci_write_reg32(t0
, t1
);
795 #if TCG_TARGET_HAS_bswap16_i32
796 case INDEX_op_bswap16_i32
:
798 t1
= tci_read_r16(&tb_ptr
);
799 tci_write_reg32(t0
, bswap16(t1
));
802 #if TCG_TARGET_HAS_bswap32_i32
803 case INDEX_op_bswap32_i32
:
805 t1
= tci_read_r32(&tb_ptr
);
806 tci_write_reg32(t0
, bswap32(t1
));
809 #if TCG_TARGET_HAS_not_i32
810 case INDEX_op_not_i32
:
812 t1
= tci_read_r32(&tb_ptr
);
813 tci_write_reg32(t0
, ~t1
);
816 #if TCG_TARGET_HAS_neg_i32
817 case INDEX_op_neg_i32
:
819 t1
= tci_read_r32(&tb_ptr
);
820 tci_write_reg32(t0
, -t1
);
823 #if TCG_TARGET_REG_BITS == 64
824 case INDEX_op_mov_i64
:
826 t1
= tci_read_r64(&tb_ptr
);
827 tci_write_reg64(t0
, t1
);
829 case INDEX_op_movi_i64
:
831 t1
= tci_read_i64(&tb_ptr
);
832 tci_write_reg64(t0
, t1
);
835 /* Load/store operations (64 bit). */
837 case INDEX_op_ld8u_i64
:
839 t1
= tci_read_r(&tb_ptr
);
840 t2
= tci_read_s32(&tb_ptr
);
841 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
843 case INDEX_op_ld8s_i64
:
844 case INDEX_op_ld16u_i64
:
845 case INDEX_op_ld16s_i64
:
848 case INDEX_op_ld32u_i64
:
850 t1
= tci_read_r(&tb_ptr
);
851 t2
= tci_read_s32(&tb_ptr
);
852 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
854 case INDEX_op_ld32s_i64
:
856 t1
= tci_read_r(&tb_ptr
);
857 t2
= tci_read_s32(&tb_ptr
);
858 tci_write_reg32s(t0
, *(int32_t *)(t1
+ t2
));
860 case INDEX_op_ld_i64
:
862 t1
= tci_read_r(&tb_ptr
);
863 t2
= tci_read_s32(&tb_ptr
);
864 tci_write_reg64(t0
, *(uint64_t *)(t1
+ t2
));
866 case INDEX_op_st8_i64
:
867 t0
= tci_read_r8(&tb_ptr
);
868 t1
= tci_read_r(&tb_ptr
);
869 t2
= tci_read_s32(&tb_ptr
);
870 *(uint8_t *)(t1
+ t2
) = t0
;
872 case INDEX_op_st16_i64
:
873 t0
= tci_read_r16(&tb_ptr
);
874 t1
= tci_read_r(&tb_ptr
);
875 t2
= tci_read_s32(&tb_ptr
);
876 *(uint16_t *)(t1
+ t2
) = t0
;
878 case INDEX_op_st32_i64
:
879 t0
= tci_read_r32(&tb_ptr
);
880 t1
= tci_read_r(&tb_ptr
);
881 t2
= tci_read_s32(&tb_ptr
);
882 *(uint32_t *)(t1
+ t2
) = t0
;
884 case INDEX_op_st_i64
:
885 t0
= tci_read_r64(&tb_ptr
);
886 t1
= tci_read_r(&tb_ptr
);
887 t2
= tci_read_s32(&tb_ptr
);
888 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
889 *(uint64_t *)(t1
+ t2
) = t0
;
892 /* Arithmetic operations (64 bit). */
894 case INDEX_op_add_i64
:
896 t1
= tci_read_ri64(&tb_ptr
);
897 t2
= tci_read_ri64(&tb_ptr
);
898 tci_write_reg64(t0
, t1
+ t2
);
900 case INDEX_op_sub_i64
:
902 t1
= tci_read_ri64(&tb_ptr
);
903 t2
= tci_read_ri64(&tb_ptr
);
904 tci_write_reg64(t0
, t1
- t2
);
906 case INDEX_op_mul_i64
:
908 t1
= tci_read_ri64(&tb_ptr
);
909 t2
= tci_read_ri64(&tb_ptr
);
910 tci_write_reg64(t0
, t1
* t2
);
912 #if TCG_TARGET_HAS_div_i64
913 case INDEX_op_div_i64
:
914 case INDEX_op_divu_i64
:
915 case INDEX_op_rem_i64
:
916 case INDEX_op_remu_i64
:
919 #elif TCG_TARGET_HAS_div2_i64
920 case INDEX_op_div2_i64
:
921 case INDEX_op_divu2_i64
:
925 case INDEX_op_and_i64
:
927 t1
= tci_read_ri64(&tb_ptr
);
928 t2
= tci_read_ri64(&tb_ptr
);
929 tci_write_reg64(t0
, t1
& t2
);
931 case INDEX_op_or_i64
:
933 t1
= tci_read_ri64(&tb_ptr
);
934 t2
= tci_read_ri64(&tb_ptr
);
935 tci_write_reg64(t0
, t1
| t2
);
937 case INDEX_op_xor_i64
:
939 t1
= tci_read_ri64(&tb_ptr
);
940 t2
= tci_read_ri64(&tb_ptr
);
941 tci_write_reg64(t0
, t1
^ t2
);
944 /* Shift/rotate operations (64 bit). */
946 case INDEX_op_shl_i64
:
948 t1
= tci_read_ri64(&tb_ptr
);
949 t2
= tci_read_ri64(&tb_ptr
);
950 tci_write_reg64(t0
, t1
<< (t2
& 63));
952 case INDEX_op_shr_i64
:
954 t1
= tci_read_ri64(&tb_ptr
);
955 t2
= tci_read_ri64(&tb_ptr
);
956 tci_write_reg64(t0
, t1
>> (t2
& 63));
958 case INDEX_op_sar_i64
:
960 t1
= tci_read_ri64(&tb_ptr
);
961 t2
= tci_read_ri64(&tb_ptr
);
962 tci_write_reg64(t0
, ((int64_t)t1
>> (t2
& 63)));
964 #if TCG_TARGET_HAS_rot_i64
965 case INDEX_op_rotl_i64
:
967 t1
= tci_read_ri64(&tb_ptr
);
968 t2
= tci_read_ri64(&tb_ptr
);
969 tci_write_reg64(t0
, rol64(t1
, t2
& 63));
971 case INDEX_op_rotr_i64
:
973 t1
= tci_read_ri64(&tb_ptr
);
974 t2
= tci_read_ri64(&tb_ptr
);
975 tci_write_reg64(t0
, ror64(t1
, t2
& 63));
978 #if TCG_TARGET_HAS_deposit_i64
979 case INDEX_op_deposit_i64
:
981 t1
= tci_read_r64(&tb_ptr
);
982 t2
= tci_read_r64(&tb_ptr
);
985 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
986 tci_write_reg64(t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
989 case INDEX_op_brcond_i64
:
990 t0
= tci_read_r64(&tb_ptr
);
991 t1
= tci_read_ri64(&tb_ptr
);
992 condition
= *tb_ptr
++;
993 label
= tci_read_label(&tb_ptr
);
994 if (tci_compare64(t0
, t1
, condition
)) {
995 assert(tb_ptr
== old_code_ptr
+ op_size
);
996 tb_ptr
= (uint8_t *)label
;
1000 #if TCG_TARGET_HAS_ext8u_i64
1001 case INDEX_op_ext8u_i64
:
1003 t1
= tci_read_r8(&tb_ptr
);
1004 tci_write_reg64(t0
, t1
);
1007 #if TCG_TARGET_HAS_ext8s_i64
1008 case INDEX_op_ext8s_i64
:
1010 t1
= tci_read_r8s(&tb_ptr
);
1011 tci_write_reg64(t0
, t1
);
1014 #if TCG_TARGET_HAS_ext16s_i64
1015 case INDEX_op_ext16s_i64
:
1017 t1
= tci_read_r16s(&tb_ptr
);
1018 tci_write_reg64(t0
, t1
);
1021 #if TCG_TARGET_HAS_ext16u_i64
1022 case INDEX_op_ext16u_i64
:
1024 t1
= tci_read_r16(&tb_ptr
);
1025 tci_write_reg64(t0
, t1
);
1028 #if TCG_TARGET_HAS_ext32s_i64
1029 case INDEX_op_ext32s_i64
:
1031 case INDEX_op_ext_i32_i64
:
1033 t1
= tci_read_r32s(&tb_ptr
);
1034 tci_write_reg64(t0
, t1
);
1036 #if TCG_TARGET_HAS_ext32u_i64
1037 case INDEX_op_ext32u_i64
:
1039 case INDEX_op_extu_i32_i64
:
1041 t1
= tci_read_r32(&tb_ptr
);
1042 tci_write_reg64(t0
, t1
);
1044 #if TCG_TARGET_HAS_bswap16_i64
1045 case INDEX_op_bswap16_i64
:
1048 t1
= tci_read_r16(&tb_ptr
);
1049 tci_write_reg64(t0
, bswap16(t1
));
1052 #if TCG_TARGET_HAS_bswap32_i64
1053 case INDEX_op_bswap32_i64
:
1055 t1
= tci_read_r32(&tb_ptr
);
1056 tci_write_reg64(t0
, bswap32(t1
));
1059 #if TCG_TARGET_HAS_bswap64_i64
1060 case INDEX_op_bswap64_i64
:
1062 t1
= tci_read_r64(&tb_ptr
);
1063 tci_write_reg64(t0
, bswap64(t1
));
1066 #if TCG_TARGET_HAS_not_i64
1067 case INDEX_op_not_i64
:
1069 t1
= tci_read_r64(&tb_ptr
);
1070 tci_write_reg64(t0
, ~t1
);
1073 #if TCG_TARGET_HAS_neg_i64
1074 case INDEX_op_neg_i64
:
1076 t1
= tci_read_r64(&tb_ptr
);
1077 tci_write_reg64(t0
, -t1
);
1080 #endif /* TCG_TARGET_REG_BITS == 64 */
1082 /* QEMU specific operations. */
1084 case INDEX_op_exit_tb
:
1085 next_tb
= *(uint64_t *)tb_ptr
;
1088 case INDEX_op_goto_tb
:
1089 t0
= tci_read_i32(&tb_ptr
);
1090 assert(tb_ptr
== old_code_ptr
+ op_size
);
1091 tb_ptr
+= (int32_t)t0
;
1093 case INDEX_op_qemu_ld_i32
:
1095 taddr
= tci_read_ulong(&tb_ptr
);
1096 oi
= tci_read_i(&tb_ptr
);
1097 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1102 tmp32
= (int8_t)qemu_ld_ub
;
1105 tmp32
= qemu_ld_leuw
;
1108 tmp32
= (int16_t)qemu_ld_leuw
;
1111 tmp32
= qemu_ld_leul
;
1114 tmp32
= qemu_ld_beuw
;
1117 tmp32
= (int16_t)qemu_ld_beuw
;
1120 tmp32
= qemu_ld_beul
;
1125 tci_write_reg(t0
, tmp32
);
1127 case INDEX_op_qemu_ld_i64
:
1129 if (TCG_TARGET_REG_BITS
== 32) {
1132 taddr
= tci_read_ulong(&tb_ptr
);
1133 oi
= tci_read_i(&tb_ptr
);
1134 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
1139 tmp64
= (int8_t)qemu_ld_ub
;
1142 tmp64
= qemu_ld_leuw
;
1145 tmp64
= (int16_t)qemu_ld_leuw
;
1148 tmp64
= qemu_ld_leul
;
1151 tmp64
= (int32_t)qemu_ld_leul
;
1154 tmp64
= qemu_ld_leq
;
1157 tmp64
= qemu_ld_beuw
;
1160 tmp64
= (int16_t)qemu_ld_beuw
;
1163 tmp64
= qemu_ld_beul
;
1166 tmp64
= (int32_t)qemu_ld_beul
;
1169 tmp64
= qemu_ld_beq
;
1174 tci_write_reg(t0
, tmp64
);
1175 if (TCG_TARGET_REG_BITS
== 32) {
1176 tci_write_reg(t1
, tmp64
>> 32);
1179 case INDEX_op_qemu_st_i32
:
1180 t0
= tci_read_r(&tb_ptr
);
1181 taddr
= tci_read_ulong(&tb_ptr
);
1182 oi
= tci_read_i(&tb_ptr
);
1183 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1203 case INDEX_op_qemu_st_i64
:
1204 tmp64
= tci_read_r64(&tb_ptr
);
1205 taddr
= tci_read_ulong(&tb_ptr
);
1206 oi
= tci_read_i(&tb_ptr
);
1207 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
1237 assert(tb_ptr
== old_code_ptr
+ op_size
);