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/>.
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 */
31 /* Marker for missing code. */
34 fprintf(stderr, "TODO %s:%u: %s()\n", \
35 __FILE__, __LINE__, __func__); \
39 #if MAX_OPC_PARAM_IARGS != 5
40 # error Fix needed, number of supported input arguments changed!
42 #if TCG_TARGET_REG_BITS == 32
43 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
44 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
);
49 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
50 tcg_target_ulong
, tcg_target_ulong
,
54 /* Targets which don't use GETPC also don't need tci_tb_ptr
55 which makes them a little faster. */
60 static tcg_target_ulong tci_reg
[TCG_TARGET_NB_REGS
];
62 static tcg_target_ulong
tci_read_reg(TCGReg index
)
64 assert(index
< ARRAY_SIZE(tci_reg
));
65 return tci_reg
[index
];
68 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
69 static int8_t tci_read_reg8s(TCGReg index
)
71 return (int8_t)tci_read_reg(index
);
75 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
76 static int16_t tci_read_reg16s(TCGReg index
)
78 return (int16_t)tci_read_reg(index
);
82 #if TCG_TARGET_REG_BITS == 64
83 static int32_t tci_read_reg32s(TCGReg index
)
85 return (int32_t)tci_read_reg(index
);
89 static uint8_t tci_read_reg8(TCGReg index
)
91 return (uint8_t)tci_read_reg(index
);
94 static uint16_t tci_read_reg16(TCGReg index
)
96 return (uint16_t)tci_read_reg(index
);
99 static uint32_t tci_read_reg32(TCGReg index
)
101 return (uint32_t)tci_read_reg(index
);
104 #if TCG_TARGET_REG_BITS == 64
105 static uint64_t tci_read_reg64(TCGReg index
)
107 return tci_read_reg(index
);
111 static void tci_write_reg(TCGReg index
, tcg_target_ulong value
)
113 assert(index
< ARRAY_SIZE(tci_reg
));
114 assert(index
!= TCG_AREG0
);
115 assert(index
!= TCG_REG_CALL_STACK
);
116 tci_reg
[index
] = value
;
119 static void tci_write_reg8s(TCGReg index
, int8_t value
)
121 tci_write_reg(index
, value
);
124 static void tci_write_reg16s(TCGReg index
, int16_t value
)
126 tci_write_reg(index
, value
);
129 #if TCG_TARGET_REG_BITS == 64
130 static void tci_write_reg32s(TCGReg index
, int32_t value
)
132 tci_write_reg(index
, value
);
136 static void tci_write_reg8(TCGReg index
, uint8_t value
)
138 tci_write_reg(index
, value
);
141 static void tci_write_reg16(TCGReg index
, uint16_t value
)
143 tci_write_reg(index
, value
);
146 static void tci_write_reg32(TCGReg index
, uint32_t value
)
148 tci_write_reg(index
, value
);
151 #if TCG_TARGET_REG_BITS == 32
152 static void tci_write_reg64(uint32_t high_index
, uint32_t low_index
,
155 tci_write_reg(low_index
, value
);
156 tci_write_reg(high_index
, value
>> 32);
158 #elif TCG_TARGET_REG_BITS == 64
159 static void tci_write_reg64(TCGReg index
, uint64_t value
)
161 tci_write_reg(index
, value
);
165 #if TCG_TARGET_REG_BITS == 32
166 /* Create a 64 bit value from two 32 bit values. */
167 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
169 return ((uint64_t)high
<< 32) + low
;
173 /* Read constant (native size) from bytecode. */
174 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
176 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
177 *tb_ptr
+= sizeof(value
);
181 /* Read unsigned constant (32 bit) from bytecode. */
182 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
184 uint32_t value
= *(uint32_t *)(*tb_ptr
);
185 *tb_ptr
+= sizeof(value
);
189 /* Read signed constant (32 bit) from bytecode. */
190 static int32_t tci_read_s32(uint8_t **tb_ptr
)
192 int32_t value
= *(int32_t *)(*tb_ptr
);
193 *tb_ptr
+= sizeof(value
);
197 #if TCG_TARGET_REG_BITS == 64
198 /* Read constant (64 bit) from bytecode. */
199 static uint64_t tci_read_i64(uint8_t **tb_ptr
)
201 uint64_t value
= *(uint64_t *)(*tb_ptr
);
202 *tb_ptr
+= sizeof(value
);
207 /* Read indexed register (native size) from bytecode. */
208 static tcg_target_ulong
tci_read_r(uint8_t **tb_ptr
)
210 tcg_target_ulong value
= tci_read_reg(**tb_ptr
);
215 /* Read indexed register (8 bit) from bytecode. */
216 static uint8_t tci_read_r8(uint8_t **tb_ptr
)
218 uint8_t value
= tci_read_reg8(**tb_ptr
);
223 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
224 /* Read indexed register (8 bit signed) from bytecode. */
225 static int8_t tci_read_r8s(uint8_t **tb_ptr
)
227 int8_t value
= tci_read_reg8s(**tb_ptr
);
233 /* Read indexed register (16 bit) from bytecode. */
234 static uint16_t tci_read_r16(uint8_t **tb_ptr
)
236 uint16_t value
= tci_read_reg16(**tb_ptr
);
241 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
242 /* Read indexed register (16 bit signed) from bytecode. */
243 static int16_t tci_read_r16s(uint8_t **tb_ptr
)
245 int16_t value
= tci_read_reg16s(**tb_ptr
);
251 /* Read indexed register (32 bit) from bytecode. */
252 static uint32_t tci_read_r32(uint8_t **tb_ptr
)
254 uint32_t value
= tci_read_reg32(**tb_ptr
);
259 #if TCG_TARGET_REG_BITS == 32
260 /* Read two indexed registers (2 * 32 bit) from bytecode. */
261 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
263 uint32_t low
= tci_read_r32(tb_ptr
);
264 return tci_uint64(tci_read_r32(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(uint8_t **tb_ptr
)
270 int32_t value
= tci_read_reg32s(**tb_ptr
);
275 /* Read indexed register (64 bit) from bytecode. */
276 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
278 uint64_t value
= tci_read_reg64(**tb_ptr
);
284 /* Read indexed register(s) with target address from bytecode. */
285 static target_ulong
tci_read_ulong(uint8_t **tb_ptr
)
287 target_ulong taddr
= tci_read_r(tb_ptr
);
288 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
289 taddr
+= (uint64_t)tci_read_r(tb_ptr
) << 32;
294 /* Read indexed register or constant (native size) from bytecode. */
295 static tcg_target_ulong
tci_read_ri(uint8_t **tb_ptr
)
297 tcg_target_ulong value
;
300 if (r
== TCG_CONST
) {
301 value
= tci_read_i(tb_ptr
);
303 value
= tci_read_reg(r
);
308 /* Read indexed register or constant (32 bit) from bytecode. */
309 static uint32_t tci_read_ri32(uint8_t **tb_ptr
)
314 if (r
== TCG_CONST
) {
315 value
= tci_read_i32(tb_ptr
);
317 value
= tci_read_reg32(r
);
322 #if TCG_TARGET_REG_BITS == 32
323 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
324 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
326 uint32_t low
= tci_read_ri32(tb_ptr
);
327 return tci_uint64(tci_read_ri32(tb_ptr
), low
);
329 #elif TCG_TARGET_REG_BITS == 64
330 /* Read indexed register or constant (64 bit) from bytecode. */
331 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
336 if (r
== TCG_CONST
) {
337 value
= tci_read_i64(tb_ptr
);
339 value
= tci_read_reg64(r
);
345 static tcg_target_ulong
tci_read_label(uint8_t **tb_ptr
)
347 tcg_target_ulong label
= tci_read_i(tb_ptr
);
352 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
394 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
436 /* Interpret pseudo code in tb. */
437 uintptr_t tcg_qemu_tb_exec(CPUArchState
*env
, uint8_t *tb_ptr
)
439 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
440 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
441 uintptr_t next_tb
= 0;
443 tci_reg
[TCG_AREG0
] = (tcg_target_ulong
)env
;
444 tci_reg
[TCG_REG_CALL_STACK
] = sp_value
;
448 TCGOpcode opc
= tb_ptr
[0];
450 uint8_t op_size
= tb_ptr
[1];
451 uint8_t *old_code_ptr
= tb_ptr
;
456 tcg_target_ulong label
;
459 #ifndef CONFIG_SOFTMMU
460 tcg_target_ulong host_addr
;
466 #if TCG_TARGET_REG_BITS == 32
471 tci_tb_ptr
= (uintptr_t)tb_ptr
;
474 /* Skip opcode and size entry. */
485 case INDEX_op_discard
:
488 case INDEX_op_set_label
:
492 t0
= tci_read_ri(&tb_ptr
);
493 #if TCG_TARGET_REG_BITS == 32
494 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
495 tci_read_reg(TCG_REG_R1
),
496 tci_read_reg(TCG_REG_R2
),
497 tci_read_reg(TCG_REG_R3
),
498 tci_read_reg(TCG_REG_R5
),
499 tci_read_reg(TCG_REG_R6
),
500 tci_read_reg(TCG_REG_R7
),
501 tci_read_reg(TCG_REG_R8
),
502 tci_read_reg(TCG_REG_R9
),
503 tci_read_reg(TCG_REG_R10
));
504 tci_write_reg(TCG_REG_R0
, tmp64
);
505 tci_write_reg(TCG_REG_R1
, tmp64
>> 32);
507 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
508 tci_read_reg(TCG_REG_R1
),
509 tci_read_reg(TCG_REG_R2
),
510 tci_read_reg(TCG_REG_R3
),
511 tci_read_reg(TCG_REG_R5
));
512 tci_write_reg(TCG_REG_R0
, tmp64
);
516 label
= tci_read_label(&tb_ptr
);
517 assert(tb_ptr
== old_code_ptr
+ op_size
);
518 tb_ptr
= (uint8_t *)label
;
520 case INDEX_op_setcond_i32
:
522 t1
= tci_read_r32(&tb_ptr
);
523 t2
= tci_read_ri32(&tb_ptr
);
524 condition
= *tb_ptr
++;
525 tci_write_reg32(t0
, tci_compare32(t1
, t2
, condition
));
527 #if TCG_TARGET_REG_BITS == 32
528 case INDEX_op_setcond2_i32
:
530 tmp64
= tci_read_r64(&tb_ptr
);
531 v64
= tci_read_ri64(&tb_ptr
);
532 condition
= *tb_ptr
++;
533 tci_write_reg32(t0
, tci_compare64(tmp64
, v64
, condition
));
535 #elif TCG_TARGET_REG_BITS == 64
536 case INDEX_op_setcond_i64
:
538 t1
= tci_read_r64(&tb_ptr
);
539 t2
= tci_read_ri64(&tb_ptr
);
540 condition
= *tb_ptr
++;
541 tci_write_reg64(t0
, tci_compare64(t1
, t2
, condition
));
544 case INDEX_op_mov_i32
:
546 t1
= tci_read_r32(&tb_ptr
);
547 tci_write_reg32(t0
, t1
);
549 case INDEX_op_movi_i32
:
551 t1
= tci_read_i32(&tb_ptr
);
552 tci_write_reg32(t0
, t1
);
555 /* Load/store operations (32 bit). */
557 case INDEX_op_ld8u_i32
:
559 t1
= tci_read_r(&tb_ptr
);
560 t2
= tci_read_s32(&tb_ptr
);
561 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
563 case INDEX_op_ld8s_i32
:
564 case INDEX_op_ld16u_i32
:
567 case INDEX_op_ld16s_i32
:
570 case INDEX_op_ld_i32
:
572 t1
= tci_read_r(&tb_ptr
);
573 t2
= tci_read_s32(&tb_ptr
);
574 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
576 case INDEX_op_st8_i32
:
577 t0
= tci_read_r8(&tb_ptr
);
578 t1
= tci_read_r(&tb_ptr
);
579 t2
= tci_read_s32(&tb_ptr
);
580 *(uint8_t *)(t1
+ t2
) = t0
;
582 case INDEX_op_st16_i32
:
583 t0
= tci_read_r16(&tb_ptr
);
584 t1
= tci_read_r(&tb_ptr
);
585 t2
= tci_read_s32(&tb_ptr
);
586 *(uint16_t *)(t1
+ t2
) = t0
;
588 case INDEX_op_st_i32
:
589 t0
= tci_read_r32(&tb_ptr
);
590 t1
= tci_read_r(&tb_ptr
);
591 t2
= tci_read_s32(&tb_ptr
);
592 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
593 *(uint32_t *)(t1
+ t2
) = t0
;
596 /* Arithmetic operations (32 bit). */
598 case INDEX_op_add_i32
:
600 t1
= tci_read_ri32(&tb_ptr
);
601 t2
= tci_read_ri32(&tb_ptr
);
602 tci_write_reg32(t0
, t1
+ t2
);
604 case INDEX_op_sub_i32
:
606 t1
= tci_read_ri32(&tb_ptr
);
607 t2
= tci_read_ri32(&tb_ptr
);
608 tci_write_reg32(t0
, t1
- t2
);
610 case INDEX_op_mul_i32
:
612 t1
= tci_read_ri32(&tb_ptr
);
613 t2
= tci_read_ri32(&tb_ptr
);
614 tci_write_reg32(t0
, t1
* t2
);
616 #if TCG_TARGET_HAS_div_i32
617 case INDEX_op_div_i32
:
619 t1
= tci_read_ri32(&tb_ptr
);
620 t2
= tci_read_ri32(&tb_ptr
);
621 tci_write_reg32(t0
, (int32_t)t1
/ (int32_t)t2
);
623 case INDEX_op_divu_i32
:
625 t1
= tci_read_ri32(&tb_ptr
);
626 t2
= tci_read_ri32(&tb_ptr
);
627 tci_write_reg32(t0
, t1
/ t2
);
629 case INDEX_op_rem_i32
:
631 t1
= tci_read_ri32(&tb_ptr
);
632 t2
= tci_read_ri32(&tb_ptr
);
633 tci_write_reg32(t0
, (int32_t)t1
% (int32_t)t2
);
635 case INDEX_op_remu_i32
:
637 t1
= tci_read_ri32(&tb_ptr
);
638 t2
= tci_read_ri32(&tb_ptr
);
639 tci_write_reg32(t0
, t1
% t2
);
641 #elif TCG_TARGET_HAS_div2_i32
642 case INDEX_op_div2_i32
:
643 case INDEX_op_divu2_i32
:
647 case INDEX_op_and_i32
:
649 t1
= tci_read_ri32(&tb_ptr
);
650 t2
= tci_read_ri32(&tb_ptr
);
651 tci_write_reg32(t0
, t1
& t2
);
653 case INDEX_op_or_i32
:
655 t1
= tci_read_ri32(&tb_ptr
);
656 t2
= tci_read_ri32(&tb_ptr
);
657 tci_write_reg32(t0
, t1
| t2
);
659 case INDEX_op_xor_i32
:
661 t1
= tci_read_ri32(&tb_ptr
);
662 t2
= tci_read_ri32(&tb_ptr
);
663 tci_write_reg32(t0
, t1
^ t2
);
666 /* Shift/rotate operations (32 bit). */
668 case INDEX_op_shl_i32
:
670 t1
= tci_read_ri32(&tb_ptr
);
671 t2
= tci_read_ri32(&tb_ptr
);
672 tci_write_reg32(t0
, t1
<< t2
);
674 case INDEX_op_shr_i32
:
676 t1
= tci_read_ri32(&tb_ptr
);
677 t2
= tci_read_ri32(&tb_ptr
);
678 tci_write_reg32(t0
, t1
>> t2
);
680 case INDEX_op_sar_i32
:
682 t1
= tci_read_ri32(&tb_ptr
);
683 t2
= tci_read_ri32(&tb_ptr
);
684 tci_write_reg32(t0
, ((int32_t)t1
>> t2
));
686 #if TCG_TARGET_HAS_rot_i32
687 case INDEX_op_rotl_i32
:
689 t1
= tci_read_ri32(&tb_ptr
);
690 t2
= tci_read_ri32(&tb_ptr
);
691 tci_write_reg32(t0
, (t1
<< t2
) | (t1
>> (32 - t2
)));
693 case INDEX_op_rotr_i32
:
695 t1
= tci_read_ri32(&tb_ptr
);
696 t2
= tci_read_ri32(&tb_ptr
);
697 tci_write_reg32(t0
, (t1
>> t2
) | (t1
<< (32 - t2
)));
700 #if TCG_TARGET_HAS_deposit_i32
701 case INDEX_op_deposit_i32
:
703 t1
= tci_read_r32(&tb_ptr
);
704 t2
= tci_read_r32(&tb_ptr
);
707 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
708 tci_write_reg32(t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
711 case INDEX_op_brcond_i32
:
712 t0
= tci_read_r32(&tb_ptr
);
713 t1
= tci_read_ri32(&tb_ptr
);
714 condition
= *tb_ptr
++;
715 label
= tci_read_label(&tb_ptr
);
716 if (tci_compare32(t0
, t1
, condition
)) {
717 assert(tb_ptr
== old_code_ptr
+ op_size
);
718 tb_ptr
= (uint8_t *)label
;
722 #if TCG_TARGET_REG_BITS == 32
723 case INDEX_op_add2_i32
:
726 tmp64
= tci_read_r64(&tb_ptr
);
727 tmp64
+= tci_read_r64(&tb_ptr
);
728 tci_write_reg64(t1
, t0
, tmp64
);
730 case INDEX_op_sub2_i32
:
733 tmp64
= tci_read_r64(&tb_ptr
);
734 tmp64
-= tci_read_r64(&tb_ptr
);
735 tci_write_reg64(t1
, t0
, tmp64
);
737 case INDEX_op_brcond2_i32
:
738 tmp64
= tci_read_r64(&tb_ptr
);
739 v64
= tci_read_ri64(&tb_ptr
);
740 condition
= *tb_ptr
++;
741 label
= tci_read_label(&tb_ptr
);
742 if (tci_compare64(tmp64
, v64
, condition
)) {
743 assert(tb_ptr
== old_code_ptr
+ op_size
);
744 tb_ptr
= (uint8_t *)label
;
748 case INDEX_op_mulu2_i32
:
751 t2
= tci_read_r32(&tb_ptr
);
752 tmp64
= tci_read_r32(&tb_ptr
);
753 tci_write_reg64(t1
, t0
, t2
* tmp64
);
755 #endif /* TCG_TARGET_REG_BITS == 32 */
756 #if TCG_TARGET_HAS_ext8s_i32
757 case INDEX_op_ext8s_i32
:
759 t1
= tci_read_r8s(&tb_ptr
);
760 tci_write_reg32(t0
, t1
);
763 #if TCG_TARGET_HAS_ext16s_i32
764 case INDEX_op_ext16s_i32
:
766 t1
= tci_read_r16s(&tb_ptr
);
767 tci_write_reg32(t0
, t1
);
770 #if TCG_TARGET_HAS_ext8u_i32
771 case INDEX_op_ext8u_i32
:
773 t1
= tci_read_r8(&tb_ptr
);
774 tci_write_reg32(t0
, t1
);
777 #if TCG_TARGET_HAS_ext16u_i32
778 case INDEX_op_ext16u_i32
:
780 t1
= tci_read_r16(&tb_ptr
);
781 tci_write_reg32(t0
, t1
);
784 #if TCG_TARGET_HAS_bswap16_i32
785 case INDEX_op_bswap16_i32
:
787 t1
= tci_read_r16(&tb_ptr
);
788 tci_write_reg32(t0
, bswap16(t1
));
791 #if TCG_TARGET_HAS_bswap32_i32
792 case INDEX_op_bswap32_i32
:
794 t1
= tci_read_r32(&tb_ptr
);
795 tci_write_reg32(t0
, bswap32(t1
));
798 #if TCG_TARGET_HAS_not_i32
799 case INDEX_op_not_i32
:
801 t1
= tci_read_r32(&tb_ptr
);
802 tci_write_reg32(t0
, ~t1
);
805 #if TCG_TARGET_HAS_neg_i32
806 case INDEX_op_neg_i32
:
808 t1
= tci_read_r32(&tb_ptr
);
809 tci_write_reg32(t0
, -t1
);
812 #if TCG_TARGET_REG_BITS == 64
813 case INDEX_op_mov_i64
:
815 t1
= tci_read_r64(&tb_ptr
);
816 tci_write_reg64(t0
, t1
);
818 case INDEX_op_movi_i64
:
820 t1
= tci_read_i64(&tb_ptr
);
821 tci_write_reg64(t0
, t1
);
824 /* Load/store operations (64 bit). */
826 case INDEX_op_ld8u_i64
:
828 t1
= tci_read_r(&tb_ptr
);
829 t2
= tci_read_s32(&tb_ptr
);
830 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
832 case INDEX_op_ld8s_i64
:
833 case INDEX_op_ld16u_i64
:
834 case INDEX_op_ld16s_i64
:
837 case INDEX_op_ld32u_i64
:
839 t1
= tci_read_r(&tb_ptr
);
840 t2
= tci_read_s32(&tb_ptr
);
841 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
843 case INDEX_op_ld32s_i64
:
845 t1
= tci_read_r(&tb_ptr
);
846 t2
= tci_read_s32(&tb_ptr
);
847 tci_write_reg32s(t0
, *(int32_t *)(t1
+ t2
));
849 case INDEX_op_ld_i64
:
851 t1
= tci_read_r(&tb_ptr
);
852 t2
= tci_read_s32(&tb_ptr
);
853 tci_write_reg64(t0
, *(uint64_t *)(t1
+ t2
));
855 case INDEX_op_st8_i64
:
856 t0
= tci_read_r8(&tb_ptr
);
857 t1
= tci_read_r(&tb_ptr
);
858 t2
= tci_read_s32(&tb_ptr
);
859 *(uint8_t *)(t1
+ t2
) = t0
;
861 case INDEX_op_st16_i64
:
862 t0
= tci_read_r16(&tb_ptr
);
863 t1
= tci_read_r(&tb_ptr
);
864 t2
= tci_read_s32(&tb_ptr
);
865 *(uint16_t *)(t1
+ t2
) = t0
;
867 case INDEX_op_st32_i64
:
868 t0
= tci_read_r32(&tb_ptr
);
869 t1
= tci_read_r(&tb_ptr
);
870 t2
= tci_read_s32(&tb_ptr
);
871 *(uint32_t *)(t1
+ t2
) = t0
;
873 case INDEX_op_st_i64
:
874 t0
= tci_read_r64(&tb_ptr
);
875 t1
= tci_read_r(&tb_ptr
);
876 t2
= tci_read_s32(&tb_ptr
);
877 assert(t1
!= sp_value
|| (int32_t)t2
< 0);
878 *(uint64_t *)(t1
+ t2
) = t0
;
881 /* Arithmetic operations (64 bit). */
883 case INDEX_op_add_i64
:
885 t1
= tci_read_ri64(&tb_ptr
);
886 t2
= tci_read_ri64(&tb_ptr
);
887 tci_write_reg64(t0
, t1
+ t2
);
889 case INDEX_op_sub_i64
:
891 t1
= tci_read_ri64(&tb_ptr
);
892 t2
= tci_read_ri64(&tb_ptr
);
893 tci_write_reg64(t0
, t1
- t2
);
895 case INDEX_op_mul_i64
:
897 t1
= tci_read_ri64(&tb_ptr
);
898 t2
= tci_read_ri64(&tb_ptr
);
899 tci_write_reg64(t0
, t1
* t2
);
901 #if TCG_TARGET_HAS_div_i64
902 case INDEX_op_div_i64
:
903 case INDEX_op_divu_i64
:
904 case INDEX_op_rem_i64
:
905 case INDEX_op_remu_i64
:
908 #elif TCG_TARGET_HAS_div2_i64
909 case INDEX_op_div2_i64
:
910 case INDEX_op_divu2_i64
:
914 case INDEX_op_and_i64
:
916 t1
= tci_read_ri64(&tb_ptr
);
917 t2
= tci_read_ri64(&tb_ptr
);
918 tci_write_reg64(t0
, t1
& t2
);
920 case INDEX_op_or_i64
:
922 t1
= tci_read_ri64(&tb_ptr
);
923 t2
= tci_read_ri64(&tb_ptr
);
924 tci_write_reg64(t0
, t1
| t2
);
926 case INDEX_op_xor_i64
:
928 t1
= tci_read_ri64(&tb_ptr
);
929 t2
= tci_read_ri64(&tb_ptr
);
930 tci_write_reg64(t0
, t1
^ t2
);
933 /* Shift/rotate operations (64 bit). */
935 case INDEX_op_shl_i64
:
937 t1
= tci_read_ri64(&tb_ptr
);
938 t2
= tci_read_ri64(&tb_ptr
);
939 tci_write_reg64(t0
, t1
<< t2
);
941 case INDEX_op_shr_i64
:
943 t1
= tci_read_ri64(&tb_ptr
);
944 t2
= tci_read_ri64(&tb_ptr
);
945 tci_write_reg64(t0
, t1
>> t2
);
947 case INDEX_op_sar_i64
:
949 t1
= tci_read_ri64(&tb_ptr
);
950 t2
= tci_read_ri64(&tb_ptr
);
951 tci_write_reg64(t0
, ((int64_t)t1
>> t2
));
953 #if TCG_TARGET_HAS_rot_i64
954 case INDEX_op_rotl_i64
:
955 case INDEX_op_rotr_i64
:
959 #if TCG_TARGET_HAS_deposit_i64
960 case INDEX_op_deposit_i64
:
962 t1
= tci_read_r64(&tb_ptr
);
963 t2
= tci_read_r64(&tb_ptr
);
966 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
967 tci_write_reg64(t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
970 case INDEX_op_brcond_i64
:
971 t0
= tci_read_r64(&tb_ptr
);
972 t1
= tci_read_ri64(&tb_ptr
);
973 condition
= *tb_ptr
++;
974 label
= tci_read_label(&tb_ptr
);
975 if (tci_compare64(t0
, t1
, condition
)) {
976 assert(tb_ptr
== old_code_ptr
+ op_size
);
977 tb_ptr
= (uint8_t *)label
;
981 #if TCG_TARGET_HAS_ext8u_i64
982 case INDEX_op_ext8u_i64
:
984 t1
= tci_read_r8(&tb_ptr
);
985 tci_write_reg64(t0
, t1
);
988 #if TCG_TARGET_HAS_ext8s_i64
989 case INDEX_op_ext8s_i64
:
991 t1
= tci_read_r8s(&tb_ptr
);
992 tci_write_reg64(t0
, t1
);
995 #if TCG_TARGET_HAS_ext16s_i64
996 case INDEX_op_ext16s_i64
:
998 t1
= tci_read_r16s(&tb_ptr
);
999 tci_write_reg64(t0
, t1
);
1002 #if TCG_TARGET_HAS_ext16u_i64
1003 case INDEX_op_ext16u_i64
:
1005 t1
= tci_read_r16(&tb_ptr
);
1006 tci_write_reg64(t0
, t1
);
1009 #if TCG_TARGET_HAS_ext32s_i64
1010 case INDEX_op_ext32s_i64
:
1012 t1
= tci_read_r32s(&tb_ptr
);
1013 tci_write_reg64(t0
, t1
);
1016 #if TCG_TARGET_HAS_ext32u_i64
1017 case INDEX_op_ext32u_i64
:
1019 t1
= tci_read_r32(&tb_ptr
);
1020 tci_write_reg64(t0
, t1
);
1023 #if TCG_TARGET_HAS_bswap16_i64
1024 case INDEX_op_bswap16_i64
:
1027 t1
= tci_read_r16(&tb_ptr
);
1028 tci_write_reg64(t0
, bswap16(t1
));
1031 #if TCG_TARGET_HAS_bswap32_i64
1032 case INDEX_op_bswap32_i64
:
1034 t1
= tci_read_r32(&tb_ptr
);
1035 tci_write_reg64(t0
, bswap32(t1
));
1038 #if TCG_TARGET_HAS_bswap64_i64
1039 case INDEX_op_bswap64_i64
:
1041 t1
= tci_read_r64(&tb_ptr
);
1042 tci_write_reg64(t0
, bswap64(t1
));
1045 #if TCG_TARGET_HAS_not_i64
1046 case INDEX_op_not_i64
:
1048 t1
= tci_read_r64(&tb_ptr
);
1049 tci_write_reg64(t0
, ~t1
);
1052 #if TCG_TARGET_HAS_neg_i64
1053 case INDEX_op_neg_i64
:
1055 t1
= tci_read_r64(&tb_ptr
);
1056 tci_write_reg64(t0
, -t1
);
1059 #endif /* TCG_TARGET_REG_BITS == 64 */
1061 /* QEMU specific operations. */
1063 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1064 case INDEX_op_debug_insn_start
:
1068 case INDEX_op_debug_insn_start
:
1072 case INDEX_op_exit_tb
:
1073 next_tb
= *(uint64_t *)tb_ptr
;
1076 case INDEX_op_goto_tb
:
1077 t0
= tci_read_i32(&tb_ptr
);
1078 assert(tb_ptr
== old_code_ptr
+ op_size
);
1079 tb_ptr
+= (int32_t)t0
;
1081 case INDEX_op_qemu_ld8u
:
1083 taddr
= tci_read_ulong(&tb_ptr
);
1084 #ifdef CONFIG_SOFTMMU
1085 tmp8
= helper_ldb_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1087 host_addr
= (tcg_target_ulong
)taddr
;
1088 assert(taddr
== host_addr
);
1089 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1091 tci_write_reg8(t0
, tmp8
);
1093 case INDEX_op_qemu_ld8s
:
1095 taddr
= tci_read_ulong(&tb_ptr
);
1096 #ifdef CONFIG_SOFTMMU
1097 tmp8
= helper_ldb_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1099 host_addr
= (tcg_target_ulong
)taddr
;
1100 assert(taddr
== host_addr
);
1101 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1103 tci_write_reg8s(t0
, tmp8
);
1105 case INDEX_op_qemu_ld16u
:
1107 taddr
= tci_read_ulong(&tb_ptr
);
1108 #ifdef CONFIG_SOFTMMU
1109 tmp16
= helper_ldw_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1111 host_addr
= (tcg_target_ulong
)taddr
;
1112 assert(taddr
== host_addr
);
1113 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1115 tci_write_reg16(t0
, tmp16
);
1117 case INDEX_op_qemu_ld16s
:
1119 taddr
= tci_read_ulong(&tb_ptr
);
1120 #ifdef CONFIG_SOFTMMU
1121 tmp16
= helper_ldw_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1123 host_addr
= (tcg_target_ulong
)taddr
;
1124 assert(taddr
== host_addr
);
1125 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1127 tci_write_reg16s(t0
, tmp16
);
1129 #if TCG_TARGET_REG_BITS == 64
1130 case INDEX_op_qemu_ld32u
:
1132 taddr
= tci_read_ulong(&tb_ptr
);
1133 #ifdef CONFIG_SOFTMMU
1134 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1136 host_addr
= (tcg_target_ulong
)taddr
;
1137 assert(taddr
== host_addr
);
1138 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1140 tci_write_reg32(t0
, tmp32
);
1142 case INDEX_op_qemu_ld32s
:
1144 taddr
= tci_read_ulong(&tb_ptr
);
1145 #ifdef CONFIG_SOFTMMU
1146 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1148 host_addr
= (tcg_target_ulong
)taddr
;
1149 assert(taddr
== host_addr
);
1150 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1152 tci_write_reg32s(t0
, tmp32
);
1154 #endif /* TCG_TARGET_REG_BITS == 64 */
1155 case INDEX_op_qemu_ld32
:
1157 taddr
= tci_read_ulong(&tb_ptr
);
1158 #ifdef CONFIG_SOFTMMU
1159 tmp32
= helper_ldl_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1161 host_addr
= (tcg_target_ulong
)taddr
;
1162 assert(taddr
== host_addr
);
1163 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1165 tci_write_reg32(t0
, tmp32
);
1167 case INDEX_op_qemu_ld64
:
1169 #if TCG_TARGET_REG_BITS == 32
1172 taddr
= tci_read_ulong(&tb_ptr
);
1173 #ifdef CONFIG_SOFTMMU
1174 tmp64
= helper_ldq_mmu(env
, taddr
, tci_read_i(&tb_ptr
));
1176 host_addr
= (tcg_target_ulong
)taddr
;
1177 assert(taddr
== host_addr
);
1178 tmp64
= tswap64(*(uint64_t *)(host_addr
+ GUEST_BASE
));
1180 tci_write_reg(t0
, tmp64
);
1181 #if TCG_TARGET_REG_BITS == 32
1182 tci_write_reg(t1
, tmp64
>> 32);
1185 case INDEX_op_qemu_st8
:
1186 t0
= tci_read_r8(&tb_ptr
);
1187 taddr
= tci_read_ulong(&tb_ptr
);
1188 #ifdef CONFIG_SOFTMMU
1189 t2
= tci_read_i(&tb_ptr
);
1190 helper_stb_mmu(env
, taddr
, t0
, t2
);
1192 host_addr
= (tcg_target_ulong
)taddr
;
1193 assert(taddr
== host_addr
);
1194 *(uint8_t *)(host_addr
+ GUEST_BASE
) = t0
;
1197 case INDEX_op_qemu_st16
:
1198 t0
= tci_read_r16(&tb_ptr
);
1199 taddr
= tci_read_ulong(&tb_ptr
);
1200 #ifdef CONFIG_SOFTMMU
1201 t2
= tci_read_i(&tb_ptr
);
1202 helper_stw_mmu(env
, taddr
, t0
, t2
);
1204 host_addr
= (tcg_target_ulong
)taddr
;
1205 assert(taddr
== host_addr
);
1206 *(uint16_t *)(host_addr
+ GUEST_BASE
) = tswap16(t0
);
1209 case INDEX_op_qemu_st32
:
1210 t0
= tci_read_r32(&tb_ptr
);
1211 taddr
= tci_read_ulong(&tb_ptr
);
1212 #ifdef CONFIG_SOFTMMU
1213 t2
= tci_read_i(&tb_ptr
);
1214 helper_stl_mmu(env
, taddr
, t0
, t2
);
1216 host_addr
= (tcg_target_ulong
)taddr
;
1217 assert(taddr
== host_addr
);
1218 *(uint32_t *)(host_addr
+ GUEST_BASE
) = tswap32(t0
);
1221 case INDEX_op_qemu_st64
:
1222 tmp64
= tci_read_r64(&tb_ptr
);
1223 taddr
= tci_read_ulong(&tb_ptr
);
1224 #ifdef CONFIG_SOFTMMU
1225 t2
= tci_read_i(&tb_ptr
);
1226 helper_stq_mmu(env
, taddr
, tmp64
, t2
);
1228 host_addr
= (tcg_target_ulong
)taddr
;
1229 assert(taddr
== host_addr
);
1230 *(uint64_t *)(host_addr
+ GUEST_BASE
) = tswap64(tmp64
);
1237 assert(tb_ptr
== old_code_ptr
+ op_size
);