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_TCG_DEBUG) && !defined(NDEBUG)
27 #include "qemu-common.h"
28 #include "dyngen-exec.h" /* env */
29 #include "exec-all.h" /* MAX_OPC_PARAM_IARGS */
32 /* Marker for missing code. */
35 fprintf(stderr, "TODO %s:%u: %s()\n", \
36 __FILE__, __LINE__, __func__); \
40 #if MAX_OPC_PARAM_IARGS != 4
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
);
49 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
50 tcg_target_ulong
, tcg_target_ulong
);
53 /* TCI can optionally use a global register variable for env. */
58 /* Targets which don't use GETPC also don't need tci_tb_ptr
59 which makes them a little faster. */
64 static tcg_target_ulong tci_reg
[TCG_TARGET_NB_REGS
];
66 static tcg_target_ulong
tci_read_reg(TCGReg index
)
68 assert(index
< ARRAY_SIZE(tci_reg
));
69 return tci_reg
[index
];
72 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
73 static int8_t tci_read_reg8s(TCGReg index
)
75 return (int8_t)tci_read_reg(index
);
79 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
80 static int16_t tci_read_reg16s(TCGReg index
)
82 return (int16_t)tci_read_reg(index
);
86 #if TCG_TARGET_REG_BITS == 64
87 static int32_t tci_read_reg32s(TCGReg index
)
89 return (int32_t)tci_read_reg(index
);
93 static uint8_t tci_read_reg8(TCGReg index
)
95 return (uint8_t)tci_read_reg(index
);
98 static uint16_t tci_read_reg16(TCGReg index
)
100 return (uint16_t)tci_read_reg(index
);
103 static uint32_t tci_read_reg32(TCGReg index
)
105 return (uint32_t)tci_read_reg(index
);
108 #if TCG_TARGET_REG_BITS == 64
109 static uint64_t tci_read_reg64(TCGReg index
)
111 return tci_read_reg(index
);
115 static void tci_write_reg(TCGReg index
, tcg_target_ulong value
)
117 assert(index
< ARRAY_SIZE(tci_reg
));
118 assert(index
!= TCG_AREG0
);
119 tci_reg
[index
] = value
;
122 static void tci_write_reg8s(TCGReg index
, int8_t value
)
124 tci_write_reg(index
, value
);
127 static void tci_write_reg16s(TCGReg index
, int16_t value
)
129 tci_write_reg(index
, value
);
132 #if TCG_TARGET_REG_BITS == 64
133 static void tci_write_reg32s(TCGReg index
, int32_t value
)
135 tci_write_reg(index
, value
);
139 static void tci_write_reg8(TCGReg index
, uint8_t value
)
141 tci_write_reg(index
, value
);
144 static void tci_write_reg16(TCGReg index
, uint16_t value
)
146 tci_write_reg(index
, value
);
149 static void tci_write_reg32(TCGReg index
, uint32_t value
)
151 tci_write_reg(index
, value
);
154 #if TCG_TARGET_REG_BITS == 32
155 static void tci_write_reg64(uint32_t high_index
, uint32_t low_index
,
158 tci_write_reg(low_index
, value
);
159 tci_write_reg(high_index
, value
>> 32);
161 #elif TCG_TARGET_REG_BITS == 64
162 static void tci_write_reg64(TCGReg index
, uint64_t value
)
164 tci_write_reg(index
, value
);
168 #if TCG_TARGET_REG_BITS == 32
169 /* Create a 64 bit value from two 32 bit values. */
170 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
172 return ((uint64_t)high
<< 32) + low
;
176 /* Read constant (native size) from bytecode. */
177 static tcg_target_ulong
tci_read_i(uint8_t **tb_ptr
)
179 tcg_target_ulong value
= *(tcg_target_ulong
*)(*tb_ptr
);
180 *tb_ptr
+= sizeof(value
);
184 /* Read constant (32 bit) from bytecode. */
185 static uint32_t tci_read_i32(uint8_t **tb_ptr
)
187 uint32_t value
= *(uint32_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(uint8_t **tb_ptr
)
196 uint64_t value
= *(uint64_t *)(*tb_ptr
);
197 *tb_ptr
+= sizeof(value
);
202 /* Read indexed register (native size) from bytecode. */
203 static tcg_target_ulong
tci_read_r(uint8_t **tb_ptr
)
205 tcg_target_ulong value
= tci_read_reg(**tb_ptr
);
210 /* Read indexed register (8 bit) from bytecode. */
211 static uint8_t tci_read_r8(uint8_t **tb_ptr
)
213 uint8_t value
= tci_read_reg8(**tb_ptr
);
218 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
219 /* Read indexed register (8 bit signed) from bytecode. */
220 static int8_t tci_read_r8s(uint8_t **tb_ptr
)
222 int8_t value
= tci_read_reg8s(**tb_ptr
);
228 /* Read indexed register (16 bit) from bytecode. */
229 static uint16_t tci_read_r16(uint8_t **tb_ptr
)
231 uint16_t value
= tci_read_reg16(**tb_ptr
);
236 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
237 /* Read indexed register (16 bit signed) from bytecode. */
238 static int16_t tci_read_r16s(uint8_t **tb_ptr
)
240 int16_t value
= tci_read_reg16s(**tb_ptr
);
246 /* Read indexed register (32 bit) from bytecode. */
247 static uint32_t tci_read_r32(uint8_t **tb_ptr
)
249 uint32_t value
= tci_read_reg32(**tb_ptr
);
254 #if TCG_TARGET_REG_BITS == 32
255 /* Read two indexed registers (2 * 32 bit) from bytecode. */
256 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
258 uint32_t low
= tci_read_r32(tb_ptr
);
259 return tci_uint64(tci_read_r32(tb_ptr
), low
);
261 #elif TCG_TARGET_REG_BITS == 64
262 /* Read indexed register (32 bit signed) from bytecode. */
263 static int32_t tci_read_r32s(uint8_t **tb_ptr
)
265 int32_t value
= tci_read_reg32s(**tb_ptr
);
270 /* Read indexed register (64 bit) from bytecode. */
271 static uint64_t tci_read_r64(uint8_t **tb_ptr
)
273 uint64_t value
= tci_read_reg64(**tb_ptr
);
279 /* Read indexed register(s) with target address from bytecode. */
280 static target_ulong
tci_read_ulong(uint8_t **tb_ptr
)
282 target_ulong taddr
= tci_read_r(tb_ptr
);
283 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
284 taddr
+= (uint64_t)tci_read_r(tb_ptr
) << 32;
289 /* Read indexed register or constant (native size) from bytecode. */
290 static tcg_target_ulong
tci_read_ri(uint8_t **tb_ptr
)
292 tcg_target_ulong value
;
295 if (r
== TCG_CONST
) {
296 value
= tci_read_i(tb_ptr
);
298 value
= tci_read_reg(r
);
303 /* Read indexed register or constant (32 bit) from bytecode. */
304 static uint32_t tci_read_ri32(uint8_t **tb_ptr
)
309 if (r
== TCG_CONST
) {
310 value
= tci_read_i32(tb_ptr
);
312 value
= tci_read_reg32(r
);
317 #if TCG_TARGET_REG_BITS == 32
318 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
319 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
321 uint32_t low
= tci_read_ri32(tb_ptr
);
322 return tci_uint64(tci_read_ri32(tb_ptr
), low
);
324 #elif TCG_TARGET_REG_BITS == 64
325 /* Read indexed register or constant (64 bit) from bytecode. */
326 static uint64_t tci_read_ri64(uint8_t **tb_ptr
)
331 if (r
== TCG_CONST
) {
332 value
= tci_read_i64(tb_ptr
);
334 value
= tci_read_reg64(r
);
340 static target_ulong
tci_read_label(uint8_t **tb_ptr
)
342 target_ulong label
= tci_read_i(tb_ptr
);
347 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
389 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
431 /* Interpret pseudo code in tb. */
432 unsigned long tcg_qemu_tb_exec(CPUState
*cpustate
, uint8_t *tb_ptr
)
434 unsigned long next_tb
= 0;
437 tci_reg
[TCG_AREG0
] = (tcg_target_ulong
)env
;
444 TCGOpcode opc
= tb_ptr
[0];
446 uint8_t op_size
= tb_ptr
[1];
447 uint8_t *old_code_ptr
= tb_ptr
;
452 tcg_target_ulong label
;
455 #ifndef CONFIG_SOFTMMU
456 tcg_target_ulong host_addr
;
462 #if TCG_TARGET_REG_BITS == 32
466 /* Skip opcode and size entry. */
477 case INDEX_op_discard
:
480 case INDEX_op_set_label
:
484 t0
= tci_read_ri(&tb_ptr
);
485 #if TCG_TARGET_REG_BITS == 32
486 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
487 tci_read_reg(TCG_REG_R1
),
488 tci_read_reg(TCG_REG_R2
),
489 tci_read_reg(TCG_REG_R3
),
490 tci_read_reg(TCG_REG_R5
),
491 tci_read_reg(TCG_REG_R6
),
492 tci_read_reg(TCG_REG_R7
),
493 tci_read_reg(TCG_REG_R8
));
494 tci_write_reg(TCG_REG_R0
, tmp64
);
495 tci_write_reg(TCG_REG_R1
, tmp64
>> 32);
497 tmp64
= ((helper_function
)t0
)(tci_read_reg(TCG_REG_R0
),
498 tci_read_reg(TCG_REG_R1
),
499 tci_read_reg(TCG_REG_R2
),
500 tci_read_reg(TCG_REG_R3
));
501 tci_write_reg(TCG_REG_R0
, tmp64
);
506 label
= tci_read_label(&tb_ptr
);
507 assert(tb_ptr
== old_code_ptr
+ op_size
);
508 tb_ptr
= (uint8_t *)label
;
510 case INDEX_op_setcond_i32
:
512 t1
= tci_read_r32(&tb_ptr
);
513 t2
= tci_read_ri32(&tb_ptr
);
514 condition
= *tb_ptr
++;
515 tci_write_reg32(t0
, tci_compare32(t1
, t2
, condition
));
517 #if TCG_TARGET_REG_BITS == 32
518 case INDEX_op_setcond2_i32
:
520 tmp64
= tci_read_r64(&tb_ptr
);
521 v64
= tci_read_ri64(&tb_ptr
);
522 condition
= *tb_ptr
++;
523 tci_write_reg32(t0
, tci_compare64(tmp64
, v64
, condition
));
525 #elif TCG_TARGET_REG_BITS == 64
526 case INDEX_op_setcond_i64
:
528 t1
= tci_read_r64(&tb_ptr
);
529 t2
= tci_read_ri64(&tb_ptr
);
530 condition
= *tb_ptr
++;
531 tci_write_reg64(t0
, tci_compare64(t1
, t2
, condition
));
534 case INDEX_op_mov_i32
:
536 t1
= tci_read_r32(&tb_ptr
);
537 tci_write_reg32(t0
, t1
);
539 case INDEX_op_movi_i32
:
541 t1
= tci_read_i32(&tb_ptr
);
542 tci_write_reg32(t0
, t1
);
545 /* Load/store operations (32 bit). */
547 case INDEX_op_ld8u_i32
:
549 t1
= tci_read_r(&tb_ptr
);
550 t2
= tci_read_i32(&tb_ptr
);
551 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
553 case INDEX_op_ld8s_i32
:
554 case INDEX_op_ld16u_i32
:
557 case INDEX_op_ld16s_i32
:
560 case INDEX_op_ld_i32
:
562 t1
= tci_read_r(&tb_ptr
);
563 t2
= tci_read_i32(&tb_ptr
);
564 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
566 case INDEX_op_st8_i32
:
567 t0
= tci_read_r8(&tb_ptr
);
568 t1
= tci_read_r(&tb_ptr
);
569 t2
= tci_read_i32(&tb_ptr
);
570 *(uint8_t *)(t1
+ t2
) = t0
;
572 case INDEX_op_st16_i32
:
573 t0
= tci_read_r16(&tb_ptr
);
574 t1
= tci_read_r(&tb_ptr
);
575 t2
= tci_read_i32(&tb_ptr
);
576 *(uint16_t *)(t1
+ t2
) = t0
;
578 case INDEX_op_st_i32
:
579 t0
= tci_read_r32(&tb_ptr
);
580 t1
= tci_read_r(&tb_ptr
);
581 t2
= tci_read_i32(&tb_ptr
);
582 *(uint32_t *)(t1
+ t2
) = t0
;
585 /* Arithmetic operations (32 bit). */
587 case INDEX_op_add_i32
:
589 t1
= tci_read_ri32(&tb_ptr
);
590 t2
= tci_read_ri32(&tb_ptr
);
591 tci_write_reg32(t0
, t1
+ t2
);
593 case INDEX_op_sub_i32
:
595 t1
= tci_read_ri32(&tb_ptr
);
596 t2
= tci_read_ri32(&tb_ptr
);
597 tci_write_reg32(t0
, t1
- t2
);
599 case INDEX_op_mul_i32
:
601 t1
= tci_read_ri32(&tb_ptr
);
602 t2
= tci_read_ri32(&tb_ptr
);
603 tci_write_reg32(t0
, t1
* t2
);
605 #if TCG_TARGET_HAS_div_i32
606 case INDEX_op_div_i32
:
608 t1
= tci_read_ri32(&tb_ptr
);
609 t2
= tci_read_ri32(&tb_ptr
);
610 tci_write_reg32(t0
, (int32_t)t1
/ (int32_t)t2
);
612 case INDEX_op_divu_i32
:
614 t1
= tci_read_ri32(&tb_ptr
);
615 t2
= tci_read_ri32(&tb_ptr
);
616 tci_write_reg32(t0
, t1
/ t2
);
618 case INDEX_op_rem_i32
:
620 t1
= tci_read_ri32(&tb_ptr
);
621 t2
= tci_read_ri32(&tb_ptr
);
622 tci_write_reg32(t0
, (int32_t)t1
% (int32_t)t2
);
624 case INDEX_op_remu_i32
:
626 t1
= tci_read_ri32(&tb_ptr
);
627 t2
= tci_read_ri32(&tb_ptr
);
628 tci_write_reg32(t0
, t1
% t2
);
630 #elif TCG_TARGET_HAS_div2_i32
631 case INDEX_op_div2_i32
:
632 case INDEX_op_divu2_i32
:
636 case INDEX_op_and_i32
:
638 t1
= tci_read_ri32(&tb_ptr
);
639 t2
= tci_read_ri32(&tb_ptr
);
640 tci_write_reg32(t0
, t1
& t2
);
642 case INDEX_op_or_i32
:
644 t1
= tci_read_ri32(&tb_ptr
);
645 t2
= tci_read_ri32(&tb_ptr
);
646 tci_write_reg32(t0
, t1
| t2
);
648 case INDEX_op_xor_i32
:
650 t1
= tci_read_ri32(&tb_ptr
);
651 t2
= tci_read_ri32(&tb_ptr
);
652 tci_write_reg32(t0
, t1
^ t2
);
655 /* Shift/rotate operations (32 bit). */
657 case INDEX_op_shl_i32
:
659 t1
= tci_read_ri32(&tb_ptr
);
660 t2
= tci_read_ri32(&tb_ptr
);
661 tci_write_reg32(t0
, t1
<< t2
);
663 case INDEX_op_shr_i32
:
665 t1
= tci_read_ri32(&tb_ptr
);
666 t2
= tci_read_ri32(&tb_ptr
);
667 tci_write_reg32(t0
, t1
>> t2
);
669 case INDEX_op_sar_i32
:
671 t1
= tci_read_ri32(&tb_ptr
);
672 t2
= tci_read_ri32(&tb_ptr
);
673 tci_write_reg32(t0
, ((int32_t)t1
>> t2
));
675 #if TCG_TARGET_HAS_rot_i32
676 case INDEX_op_rotl_i32
:
678 t1
= tci_read_ri32(&tb_ptr
);
679 t2
= tci_read_ri32(&tb_ptr
);
680 tci_write_reg32(t0
, (t1
<< t2
) | (t1
>> (32 - t2
)));
682 case INDEX_op_rotr_i32
:
684 t1
= tci_read_ri32(&tb_ptr
);
685 t2
= tci_read_ri32(&tb_ptr
);
686 tci_write_reg32(t0
, (t1
>> t2
) | (t1
<< (32 - t2
)));
689 case INDEX_op_brcond_i32
:
690 t0
= tci_read_r32(&tb_ptr
);
691 t1
= tci_read_ri32(&tb_ptr
);
692 condition
= *tb_ptr
++;
693 label
= tci_read_label(&tb_ptr
);
694 if (tci_compare32(t0
, t1
, condition
)) {
695 assert(tb_ptr
== old_code_ptr
+ op_size
);
696 tb_ptr
= (uint8_t *)label
;
700 #if TCG_TARGET_REG_BITS == 32
701 case INDEX_op_add2_i32
:
704 tmp64
= tci_read_r64(&tb_ptr
);
705 tmp64
+= tci_read_r64(&tb_ptr
);
706 tci_write_reg64(t1
, t0
, tmp64
);
708 case INDEX_op_sub2_i32
:
711 tmp64
= tci_read_r64(&tb_ptr
);
712 tmp64
-= tci_read_r64(&tb_ptr
);
713 tci_write_reg64(t1
, t0
, tmp64
);
715 case INDEX_op_brcond2_i32
:
716 tmp64
= tci_read_r64(&tb_ptr
);
717 v64
= tci_read_ri64(&tb_ptr
);
718 condition
= *tb_ptr
++;
719 label
= tci_read_label(&tb_ptr
);
720 if (tci_compare64(tmp64
, v64
, condition
)) {
721 assert(tb_ptr
== old_code_ptr
+ op_size
);
722 tb_ptr
= (uint8_t *)label
;
726 case INDEX_op_mulu2_i32
:
729 t2
= tci_read_r32(&tb_ptr
);
730 tmp64
= tci_read_r32(&tb_ptr
);
731 tci_write_reg64(t1
, t0
, t2
* tmp64
);
733 #endif /* TCG_TARGET_REG_BITS == 32 */
734 #if TCG_TARGET_HAS_ext8s_i32
735 case INDEX_op_ext8s_i32
:
737 t1
= tci_read_r8s(&tb_ptr
);
738 tci_write_reg32(t0
, t1
);
741 #if TCG_TARGET_HAS_ext16s_i32
742 case INDEX_op_ext16s_i32
:
744 t1
= tci_read_r16s(&tb_ptr
);
745 tci_write_reg32(t0
, t1
);
748 #if TCG_TARGET_HAS_ext8u_i32
749 case INDEX_op_ext8u_i32
:
751 t1
= tci_read_r8(&tb_ptr
);
752 tci_write_reg32(t0
, t1
);
755 #if TCG_TARGET_HAS_ext16u_i32
756 case INDEX_op_ext16u_i32
:
758 t1
= tci_read_r16(&tb_ptr
);
759 tci_write_reg32(t0
, t1
);
762 #if TCG_TARGET_HAS_bswap16_i32
763 case INDEX_op_bswap16_i32
:
765 t1
= tci_read_r16(&tb_ptr
);
766 tci_write_reg32(t0
, bswap16(t1
));
769 #if TCG_TARGET_HAS_bswap32_i32
770 case INDEX_op_bswap32_i32
:
772 t1
= tci_read_r32(&tb_ptr
);
773 tci_write_reg32(t0
, bswap32(t1
));
776 #if TCG_TARGET_HAS_not_i32
777 case INDEX_op_not_i32
:
779 t1
= tci_read_r32(&tb_ptr
);
780 tci_write_reg32(t0
, ~t1
);
783 #if TCG_TARGET_HAS_neg_i32
784 case INDEX_op_neg_i32
:
786 t1
= tci_read_r32(&tb_ptr
);
787 tci_write_reg32(t0
, -t1
);
790 #if TCG_TARGET_REG_BITS == 64
791 case INDEX_op_mov_i64
:
793 t1
= tci_read_r64(&tb_ptr
);
794 tci_write_reg64(t0
, t1
);
796 case INDEX_op_movi_i64
:
798 t1
= tci_read_i64(&tb_ptr
);
799 tci_write_reg64(t0
, t1
);
802 /* Load/store operations (64 bit). */
804 case INDEX_op_ld8u_i64
:
806 t1
= tci_read_r(&tb_ptr
);
807 t2
= tci_read_i32(&tb_ptr
);
808 tci_write_reg8(t0
, *(uint8_t *)(t1
+ t2
));
810 case INDEX_op_ld8s_i64
:
811 case INDEX_op_ld16u_i64
:
812 case INDEX_op_ld16s_i64
:
815 case INDEX_op_ld32u_i64
:
817 t1
= tci_read_r(&tb_ptr
);
818 t2
= tci_read_i32(&tb_ptr
);
819 tci_write_reg32(t0
, *(uint32_t *)(t1
+ t2
));
821 case INDEX_op_ld32s_i64
:
823 t1
= tci_read_r(&tb_ptr
);
824 t2
= tci_read_i32(&tb_ptr
);
825 tci_write_reg32s(t0
, *(int32_t *)(t1
+ t2
));
827 case INDEX_op_ld_i64
:
829 t1
= tci_read_r(&tb_ptr
);
830 t2
= tci_read_i32(&tb_ptr
);
831 tci_write_reg64(t0
, *(uint64_t *)(t1
+ t2
));
833 case INDEX_op_st8_i64
:
834 t0
= tci_read_r8(&tb_ptr
);
835 t1
= tci_read_r(&tb_ptr
);
836 t2
= tci_read_i32(&tb_ptr
);
837 *(uint8_t *)(t1
+ t2
) = t0
;
839 case INDEX_op_st16_i64
:
840 t0
= tci_read_r16(&tb_ptr
);
841 t1
= tci_read_r(&tb_ptr
);
842 t2
= tci_read_i32(&tb_ptr
);
843 *(uint16_t *)(t1
+ t2
) = t0
;
845 case INDEX_op_st32_i64
:
846 t0
= tci_read_r32(&tb_ptr
);
847 t1
= tci_read_r(&tb_ptr
);
848 t2
= tci_read_i32(&tb_ptr
);
849 *(uint32_t *)(t1
+ t2
) = t0
;
851 case INDEX_op_st_i64
:
852 t0
= tci_read_r64(&tb_ptr
);
853 t1
= tci_read_r(&tb_ptr
);
854 t2
= tci_read_i32(&tb_ptr
);
855 *(uint64_t *)(t1
+ t2
) = t0
;
858 /* Arithmetic operations (64 bit). */
860 case INDEX_op_add_i64
:
862 t1
= tci_read_ri64(&tb_ptr
);
863 t2
= tci_read_ri64(&tb_ptr
);
864 tci_write_reg64(t0
, t1
+ t2
);
866 case INDEX_op_sub_i64
:
868 t1
= tci_read_ri64(&tb_ptr
);
869 t2
= tci_read_ri64(&tb_ptr
);
870 tci_write_reg64(t0
, t1
- t2
);
872 case INDEX_op_mul_i64
:
874 t1
= tci_read_ri64(&tb_ptr
);
875 t2
= tci_read_ri64(&tb_ptr
);
876 tci_write_reg64(t0
, t1
* t2
);
878 #if TCG_TARGET_HAS_div_i64
879 case INDEX_op_div_i64
:
880 case INDEX_op_divu_i64
:
881 case INDEX_op_rem_i64
:
882 case INDEX_op_remu_i64
:
885 #elif TCG_TARGET_HAS_div2_i64
886 case INDEX_op_div2_i64
:
887 case INDEX_op_divu2_i64
:
891 case INDEX_op_and_i64
:
893 t1
= tci_read_ri64(&tb_ptr
);
894 t2
= tci_read_ri64(&tb_ptr
);
895 tci_write_reg64(t0
, t1
& t2
);
897 case INDEX_op_or_i64
:
899 t1
= tci_read_ri64(&tb_ptr
);
900 t2
= tci_read_ri64(&tb_ptr
);
901 tci_write_reg64(t0
, t1
| t2
);
903 case INDEX_op_xor_i64
:
905 t1
= tci_read_ri64(&tb_ptr
);
906 t2
= tci_read_ri64(&tb_ptr
);
907 tci_write_reg64(t0
, t1
^ t2
);
910 /* Shift/rotate operations (64 bit). */
912 case INDEX_op_shl_i64
:
914 t1
= tci_read_ri64(&tb_ptr
);
915 t2
= tci_read_ri64(&tb_ptr
);
916 tci_write_reg64(t0
, t1
<< t2
);
918 case INDEX_op_shr_i64
:
920 t1
= tci_read_ri64(&tb_ptr
);
921 t2
= tci_read_ri64(&tb_ptr
);
922 tci_write_reg64(t0
, t1
>> t2
);
924 case INDEX_op_sar_i64
:
926 t1
= tci_read_ri64(&tb_ptr
);
927 t2
= tci_read_ri64(&tb_ptr
);
928 tci_write_reg64(t0
, ((int64_t)t1
>> t2
));
930 #if TCG_TARGET_HAS_rot_i64
931 case INDEX_op_rotl_i64
:
932 case INDEX_op_rotr_i64
:
936 case INDEX_op_brcond_i64
:
937 t0
= tci_read_r64(&tb_ptr
);
938 t1
= tci_read_ri64(&tb_ptr
);
939 condition
= *tb_ptr
++;
940 label
= tci_read_label(&tb_ptr
);
941 if (tci_compare64(t0
, t1
, condition
)) {
942 assert(tb_ptr
== old_code_ptr
+ op_size
);
943 tb_ptr
= (uint8_t *)label
;
947 #if TCG_TARGET_HAS_ext8u_i64
948 case INDEX_op_ext8u_i64
:
950 t1
= tci_read_r8(&tb_ptr
);
951 tci_write_reg64(t0
, t1
);
954 #if TCG_TARGET_HAS_ext8s_i64
955 case INDEX_op_ext8s_i64
:
957 t1
= tci_read_r8s(&tb_ptr
);
958 tci_write_reg64(t0
, t1
);
961 #if TCG_TARGET_HAS_ext16s_i64
962 case INDEX_op_ext16s_i64
:
964 t1
= tci_read_r16s(&tb_ptr
);
965 tci_write_reg64(t0
, t1
);
968 #if TCG_TARGET_HAS_ext16u_i64
969 case INDEX_op_ext16u_i64
:
971 t1
= tci_read_r16(&tb_ptr
);
972 tci_write_reg64(t0
, t1
);
975 #if TCG_TARGET_HAS_ext32s_i64
976 case INDEX_op_ext32s_i64
:
978 t1
= tci_read_r32s(&tb_ptr
);
979 tci_write_reg64(t0
, t1
);
982 #if TCG_TARGET_HAS_ext32u_i64
983 case INDEX_op_ext32u_i64
:
985 t1
= tci_read_r32(&tb_ptr
);
986 tci_write_reg64(t0
, t1
);
989 #if TCG_TARGET_HAS_bswap16_i64
990 case INDEX_op_bswap16_i64
:
993 t1
= tci_read_r16(&tb_ptr
);
994 tci_write_reg64(t0
, bswap16(t1
));
997 #if TCG_TARGET_HAS_bswap32_i64
998 case INDEX_op_bswap32_i64
:
1000 t1
= tci_read_r32(&tb_ptr
);
1001 tci_write_reg64(t0
, bswap32(t1
));
1004 #if TCG_TARGET_HAS_bswap64_i64
1005 case INDEX_op_bswap64_i64
:
1008 t1
= tci_read_r64(&tb_ptr
);
1009 tci_write_reg64(t0
, bswap64(t1
));
1012 #if TCG_TARGET_HAS_not_i64
1013 case INDEX_op_not_i64
:
1015 t1
= tci_read_r64(&tb_ptr
);
1016 tci_write_reg64(t0
, ~t1
);
1019 #if TCG_TARGET_HAS_neg_i64
1020 case INDEX_op_neg_i64
:
1022 t1
= tci_read_r64(&tb_ptr
);
1023 tci_write_reg64(t0
, -t1
);
1026 #endif /* TCG_TARGET_REG_BITS == 64 */
1028 /* QEMU specific operations. */
1030 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1031 case INDEX_op_debug_insn_start
:
1035 case INDEX_op_debug_insn_start
:
1039 case INDEX_op_exit_tb
:
1040 next_tb
= *(uint64_t *)tb_ptr
;
1043 case INDEX_op_goto_tb
:
1044 t0
= tci_read_i32(&tb_ptr
);
1045 assert(tb_ptr
== old_code_ptr
+ op_size
);
1046 tb_ptr
+= (int32_t)t0
;
1048 case INDEX_op_qemu_ld8u
:
1050 taddr
= tci_read_ulong(&tb_ptr
);
1051 #ifdef CONFIG_SOFTMMU
1052 tmp8
= __ldb_mmu(taddr
, tci_read_i(&tb_ptr
));
1054 host_addr
= (tcg_target_ulong
)taddr
;
1055 assert(taddr
== host_addr
);
1056 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1058 tci_write_reg8(t0
, tmp8
);
1060 case INDEX_op_qemu_ld8s
:
1062 taddr
= tci_read_ulong(&tb_ptr
);
1063 #ifdef CONFIG_SOFTMMU
1064 tmp8
= __ldb_mmu(taddr
, tci_read_i(&tb_ptr
));
1066 host_addr
= (tcg_target_ulong
)taddr
;
1067 assert(taddr
== host_addr
);
1068 tmp8
= *(uint8_t *)(host_addr
+ GUEST_BASE
);
1070 tci_write_reg8s(t0
, tmp8
);
1072 case INDEX_op_qemu_ld16u
:
1074 taddr
= tci_read_ulong(&tb_ptr
);
1075 #ifdef CONFIG_SOFTMMU
1076 tmp16
= __ldw_mmu(taddr
, tci_read_i(&tb_ptr
));
1078 host_addr
= (tcg_target_ulong
)taddr
;
1079 assert(taddr
== host_addr
);
1080 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1082 tci_write_reg16(t0
, tmp16
);
1084 case INDEX_op_qemu_ld16s
:
1086 taddr
= tci_read_ulong(&tb_ptr
);
1087 #ifdef CONFIG_SOFTMMU
1088 tmp16
= __ldw_mmu(taddr
, tci_read_i(&tb_ptr
));
1090 host_addr
= (tcg_target_ulong
)taddr
;
1091 assert(taddr
== host_addr
);
1092 tmp16
= tswap16(*(uint16_t *)(host_addr
+ GUEST_BASE
));
1094 tci_write_reg16s(t0
, tmp16
);
1096 #if TCG_TARGET_REG_BITS == 64
1097 case INDEX_op_qemu_ld32u
:
1099 taddr
= tci_read_ulong(&tb_ptr
);
1100 #ifdef CONFIG_SOFTMMU
1101 tmp32
= __ldl_mmu(taddr
, tci_read_i(&tb_ptr
));
1103 host_addr
= (tcg_target_ulong
)taddr
;
1104 assert(taddr
== host_addr
);
1105 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1107 tci_write_reg32(t0
, tmp32
);
1109 case INDEX_op_qemu_ld32s
:
1111 taddr
= tci_read_ulong(&tb_ptr
);
1112 #ifdef CONFIG_SOFTMMU
1113 tmp32
= __ldl_mmu(taddr
, tci_read_i(&tb_ptr
));
1115 host_addr
= (tcg_target_ulong
)taddr
;
1116 assert(taddr
== host_addr
);
1117 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1119 tci_write_reg32s(t0
, tmp32
);
1121 #endif /* TCG_TARGET_REG_BITS == 64 */
1122 case INDEX_op_qemu_ld32
:
1124 taddr
= tci_read_ulong(&tb_ptr
);
1125 #ifdef CONFIG_SOFTMMU
1126 tmp32
= __ldl_mmu(taddr
, tci_read_i(&tb_ptr
));
1128 host_addr
= (tcg_target_ulong
)taddr
;
1129 assert(taddr
== host_addr
);
1130 tmp32
= tswap32(*(uint32_t *)(host_addr
+ GUEST_BASE
));
1132 tci_write_reg32(t0
, tmp32
);
1134 case INDEX_op_qemu_ld64
:
1136 #if TCG_TARGET_REG_BITS == 32
1139 taddr
= tci_read_ulong(&tb_ptr
);
1140 #ifdef CONFIG_SOFTMMU
1141 tmp64
= __ldq_mmu(taddr
, tci_read_i(&tb_ptr
));
1143 host_addr
= (tcg_target_ulong
)taddr
;
1144 assert(taddr
== host_addr
);
1145 tmp64
= tswap64(*(uint64_t *)(host_addr
+ GUEST_BASE
));
1147 tci_write_reg(t0
, tmp64
);
1148 #if TCG_TARGET_REG_BITS == 32
1149 tci_write_reg(t1
, tmp64
>> 32);
1152 case INDEX_op_qemu_st8
:
1153 t0
= tci_read_r8(&tb_ptr
);
1154 taddr
= tci_read_ulong(&tb_ptr
);
1155 #ifdef CONFIG_SOFTMMU
1156 t2
= tci_read_i(&tb_ptr
);
1157 __stb_mmu(taddr
, t0
, t2
);
1159 host_addr
= (tcg_target_ulong
)taddr
;
1160 assert(taddr
== host_addr
);
1161 *(uint8_t *)(host_addr
+ GUEST_BASE
) = t0
;
1164 case INDEX_op_qemu_st16
:
1165 t0
= tci_read_r16(&tb_ptr
);
1166 taddr
= tci_read_ulong(&tb_ptr
);
1167 #ifdef CONFIG_SOFTMMU
1168 t2
= tci_read_i(&tb_ptr
);
1169 __stw_mmu(taddr
, t0
, t2
);
1171 host_addr
= (tcg_target_ulong
)taddr
;
1172 assert(taddr
== host_addr
);
1173 *(uint16_t *)(host_addr
+ GUEST_BASE
) = tswap16(t0
);
1176 case INDEX_op_qemu_st32
:
1177 t0
= tci_read_r32(&tb_ptr
);
1178 taddr
= tci_read_ulong(&tb_ptr
);
1179 #ifdef CONFIG_SOFTMMU
1180 t2
= tci_read_i(&tb_ptr
);
1181 __stl_mmu(taddr
, t0
, t2
);
1183 host_addr
= (tcg_target_ulong
)taddr
;
1184 assert(taddr
== host_addr
);
1185 *(uint32_t *)(host_addr
+ GUEST_BASE
) = tswap32(t0
);
1188 case INDEX_op_qemu_st64
:
1189 tmp64
= tci_read_r64(&tb_ptr
);
1190 taddr
= tci_read_ulong(&tb_ptr
);
1191 #ifdef CONFIG_SOFTMMU
1192 t2
= tci_read_i(&tb_ptr
);
1193 __stq_mmu(taddr
, tmp64
, t2
);
1195 host_addr
= (tcg_target_ulong
)taddr
;
1196 assert(taddr
== host_addr
);
1197 *(uint64_t *)(host_addr
+ GUEST_BASE
) = tswap64(tmp64
);
1204 assert(tb_ptr
== old_code_ptr
+ op_size
);