2 * Tiny Code Interpreter for QEMU
4 * Copyright (c) 2009, 2011, 2016 Stefan Weil
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 /* Enable TCI assertions only when debugging TCG (and without NDEBUG defined).
23 * Without assertions, the interpreter runs much faster. */
24 #if defined(CONFIG_DEBUG_TCG)
25 # define tci_assert(cond) assert(cond)
27 # define tci_assert(cond) ((void)0)
30 #include "qemu-common.h"
31 #include "tcg/tcg.h" /* MAX_OPC_PARAM_IARGS */
32 #include "exec/cpu_ldst.h"
33 #include "tcg/tcg-op.h"
34 #include "qemu/compiler.h"
36 #if MAX_OPC_PARAM_IARGS != 6
37 # error Fix needed, number of supported input arguments changed!
39 #if TCG_TARGET_REG_BITS == 32
40 typedef uint64_t (*helper_function
)(tcg_target_ulong
, tcg_target_ulong
,
41 tcg_target_ulong
, tcg_target_ulong
,
42 tcg_target_ulong
, tcg_target_ulong
,
43 tcg_target_ulong
, tcg_target_ulong
,
44 tcg_target_ulong
, tcg_target_ulong
,
45 tcg_target_ulong
, tcg_target_ulong
);
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
);
52 __thread
uintptr_t tci_tb_ptr
;
54 static tcg_target_ulong
tci_read_reg(const tcg_target_ulong
*regs
, TCGReg index
)
56 tci_assert(index
< TCG_TARGET_NB_REGS
);
61 tci_write_reg(tcg_target_ulong
*regs
, TCGReg index
, tcg_target_ulong value
)
63 tci_assert(index
< TCG_TARGET_NB_REGS
);
64 tci_assert(index
!= TCG_AREG0
);
65 tci_assert(index
!= TCG_REG_CALL_STACK
);
69 #if TCG_TARGET_REG_BITS == 32
70 static void tci_write_reg64(tcg_target_ulong
*regs
, uint32_t high_index
,
71 uint32_t low_index
, uint64_t value
)
73 tci_write_reg(regs
, low_index
, value
);
74 tci_write_reg(regs
, high_index
, value
>> 32);
78 #if TCG_TARGET_REG_BITS == 32
79 /* Create a 64 bit value from two 32 bit values. */
80 static uint64_t tci_uint64(uint32_t high
, uint32_t low
)
82 return ((uint64_t)high
<< 32) + low
;
86 /* Read constant (native size) from bytecode. */
87 static tcg_target_ulong
tci_read_i(const uint8_t **tb_ptr
)
89 tcg_target_ulong value
= *(const tcg_target_ulong
*)(*tb_ptr
);
90 *tb_ptr
+= sizeof(value
);
94 /* Read unsigned constant (32 bit) from bytecode. */
95 static uint32_t tci_read_i32(const uint8_t **tb_ptr
)
97 uint32_t value
= *(const uint32_t *)(*tb_ptr
);
98 *tb_ptr
+= sizeof(value
);
102 /* Read signed constant (32 bit) from bytecode. */
103 static int32_t tci_read_s32(const uint8_t **tb_ptr
)
105 int32_t value
= *(const int32_t *)(*tb_ptr
);
106 *tb_ptr
+= sizeof(value
);
110 #if TCG_TARGET_REG_BITS == 64
111 /* Read constant (64 bit) from bytecode. */
112 static uint64_t tci_read_i64(const uint8_t **tb_ptr
)
114 uint64_t value
= *(const uint64_t *)(*tb_ptr
);
115 *tb_ptr
+= sizeof(value
);
120 /* Read indexed register (native size) from bytecode. */
121 static tcg_target_ulong
122 tci_read_r(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
124 tcg_target_ulong value
= tci_read_reg(regs
, **tb_ptr
);
129 #if TCG_TARGET_REG_BITS == 32
130 /* Read two indexed registers (2 * 32 bit) from bytecode. */
131 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
132 const uint8_t **tb_ptr
)
134 uint32_t low
= tci_read_r(regs
, tb_ptr
);
135 return tci_uint64(tci_read_r(regs
, tb_ptr
), low
);
137 #elif TCG_TARGET_REG_BITS == 64
138 /* Read indexed register (64 bit) from bytecode. */
139 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
140 const uint8_t **tb_ptr
)
142 return tci_read_r(regs
, tb_ptr
);
146 /* Read indexed register(s) with target address from bytecode. */
148 tci_read_ulong(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
150 target_ulong taddr
= tci_read_r(regs
, tb_ptr
);
151 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
152 taddr
+= (uint64_t)tci_read_r(regs
, tb_ptr
) << 32;
157 static tcg_target_ulong
tci_read_label(const uint8_t **tb_ptr
)
159 tcg_target_ulong label
= tci_read_i(tb_ptr
);
160 tci_assert(label
!= 0);
164 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
201 g_assert_not_reached();
206 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
243 g_assert_not_reached();
249 cpu_ldub_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
250 #define qemu_ld_leuw \
251 cpu_lduw_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
252 #define qemu_ld_leul \
253 cpu_ldl_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
254 #define qemu_ld_leq \
255 cpu_ldq_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
256 #define qemu_ld_beuw \
257 cpu_lduw_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
258 #define qemu_ld_beul \
259 cpu_ldl_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
260 #define qemu_ld_beq \
261 cpu_ldq_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
262 #define qemu_st_b(X) \
263 cpu_stb_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
264 #define qemu_st_lew(X) \
265 cpu_stw_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
266 #define qemu_st_lel(X) \
267 cpu_stl_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
268 #define qemu_st_leq(X) \
269 cpu_stq_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
270 #define qemu_st_bew(X) \
271 cpu_stw_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
272 #define qemu_st_bel(X) \
273 cpu_stl_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
274 #define qemu_st_beq(X) \
275 cpu_stq_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
277 #if TCG_TARGET_REG_BITS == 64
278 # define CASE_32_64(x) \
279 case glue(glue(INDEX_op_, x), _i64): \
280 case glue(glue(INDEX_op_, x), _i32):
281 # define CASE_64(x) \
282 case glue(glue(INDEX_op_, x), _i64):
284 # define CASE_32_64(x) \
285 case glue(glue(INDEX_op_, x), _i32):
289 /* Interpret pseudo code in tb. */
291 * Disable CFI checks.
292 * One possible operation in the pseudo code is a call to binary code.
293 * Therefore, disable CFI checks in the interpreter function
295 uintptr_t QEMU_DISABLE_CFI
tcg_qemu_tb_exec(CPUArchState
*env
,
296 const void *v_tb_ptr
)
298 const uint8_t *tb_ptr
= v_tb_ptr
;
299 tcg_target_ulong regs
[TCG_TARGET_NB_REGS
];
300 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
301 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
304 regs
[TCG_AREG0
] = (tcg_target_ulong
)env
;
305 regs
[TCG_REG_CALL_STACK
] = sp_value
;
309 TCGOpcode opc
= tb_ptr
[0];
310 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
311 uint8_t op_size
= tb_ptr
[1];
312 const uint8_t *old_code_ptr
= tb_ptr
;
317 tcg_target_ulong label
;
324 #if TCG_TARGET_REG_BITS == 32
329 /* Skip opcode and size entry. */
334 t0
= tci_read_i(&tb_ptr
);
335 tci_tb_ptr
= (uintptr_t)tb_ptr
;
336 #if TCG_TARGET_REG_BITS == 32
337 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
338 tci_read_reg(regs
, TCG_REG_R1
),
339 tci_read_reg(regs
, TCG_REG_R2
),
340 tci_read_reg(regs
, TCG_REG_R3
),
341 tci_read_reg(regs
, TCG_REG_R4
),
342 tci_read_reg(regs
, TCG_REG_R5
),
343 tci_read_reg(regs
, TCG_REG_R6
),
344 tci_read_reg(regs
, TCG_REG_R7
),
345 tci_read_reg(regs
, TCG_REG_R8
),
346 tci_read_reg(regs
, TCG_REG_R9
),
347 tci_read_reg(regs
, TCG_REG_R10
),
348 tci_read_reg(regs
, TCG_REG_R11
));
349 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
350 tci_write_reg(regs
, TCG_REG_R1
, tmp64
>> 32);
352 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
353 tci_read_reg(regs
, TCG_REG_R1
),
354 tci_read_reg(regs
, TCG_REG_R2
),
355 tci_read_reg(regs
, TCG_REG_R3
),
356 tci_read_reg(regs
, TCG_REG_R4
),
357 tci_read_reg(regs
, TCG_REG_R5
));
358 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
362 label
= tci_read_label(&tb_ptr
);
363 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
364 tb_ptr
= (uint8_t *)label
;
366 case INDEX_op_setcond_i32
:
368 t1
= tci_read_r(regs
, &tb_ptr
);
369 t2
= tci_read_r(regs
, &tb_ptr
);
370 condition
= *tb_ptr
++;
371 tci_write_reg(regs
, t0
, tci_compare32(t1
, t2
, condition
));
373 #if TCG_TARGET_REG_BITS == 32
374 case INDEX_op_setcond2_i32
:
376 tmp64
= tci_read_r64(regs
, &tb_ptr
);
377 v64
= tci_read_r64(regs
, &tb_ptr
);
378 condition
= *tb_ptr
++;
379 tci_write_reg(regs
, t0
, tci_compare64(tmp64
, v64
, condition
));
381 #elif TCG_TARGET_REG_BITS == 64
382 case INDEX_op_setcond_i64
:
384 t1
= tci_read_r(regs
, &tb_ptr
);
385 t2
= tci_read_r(regs
, &tb_ptr
);
386 condition
= *tb_ptr
++;
387 tci_write_reg(regs
, t0
, tci_compare64(t1
, t2
, condition
));
392 t1
= tci_read_r(regs
, &tb_ptr
);
393 tci_write_reg(regs
, t0
, t1
);
395 case INDEX_op_tci_movi_i32
:
397 t1
= tci_read_i32(&tb_ptr
);
398 tci_write_reg(regs
, t0
, t1
);
401 /* Load/store operations (32 bit). */
405 t1
= tci_read_r(regs
, &tb_ptr
);
406 t2
= tci_read_s32(&tb_ptr
);
407 tci_write_reg(regs
, t0
, *(uint8_t *)(t1
+ t2
));
411 t1
= tci_read_r(regs
, &tb_ptr
);
412 t2
= tci_read_s32(&tb_ptr
);
413 tci_write_reg(regs
, t0
, *(int8_t *)(t1
+ t2
));
417 t1
= tci_read_r(regs
, &tb_ptr
);
418 t2
= tci_read_s32(&tb_ptr
);
419 tci_write_reg(regs
, t0
, *(uint16_t *)(t1
+ t2
));
423 t1
= tci_read_r(regs
, &tb_ptr
);
424 t2
= tci_read_s32(&tb_ptr
);
425 tci_write_reg(regs
, t0
, *(int16_t *)(t1
+ t2
));
427 case INDEX_op_ld_i32
:
430 t1
= tci_read_r(regs
, &tb_ptr
);
431 t2
= tci_read_s32(&tb_ptr
);
432 tci_write_reg(regs
, t0
, *(uint32_t *)(t1
+ t2
));
435 t0
= tci_read_r(regs
, &tb_ptr
);
436 t1
= tci_read_r(regs
, &tb_ptr
);
437 t2
= tci_read_s32(&tb_ptr
);
438 *(uint8_t *)(t1
+ t2
) = t0
;
441 t0
= tci_read_r(regs
, &tb_ptr
);
442 t1
= tci_read_r(regs
, &tb_ptr
);
443 t2
= tci_read_s32(&tb_ptr
);
444 *(uint16_t *)(t1
+ t2
) = t0
;
446 case INDEX_op_st_i32
:
448 t0
= tci_read_r(regs
, &tb_ptr
);
449 t1
= tci_read_r(regs
, &tb_ptr
);
450 t2
= tci_read_s32(&tb_ptr
);
451 *(uint32_t *)(t1
+ t2
) = t0
;
454 /* Arithmetic operations (mixed 32/64 bit). */
458 t1
= tci_read_r(regs
, &tb_ptr
);
459 t2
= tci_read_r(regs
, &tb_ptr
);
460 tci_write_reg(regs
, t0
, t1
+ t2
);
464 t1
= tci_read_r(regs
, &tb_ptr
);
465 t2
= tci_read_r(regs
, &tb_ptr
);
466 tci_write_reg(regs
, t0
, t1
- t2
);
470 t1
= tci_read_r(regs
, &tb_ptr
);
471 t2
= tci_read_r(regs
, &tb_ptr
);
472 tci_write_reg(regs
, t0
, t1
* t2
);
476 t1
= tci_read_r(regs
, &tb_ptr
);
477 t2
= tci_read_r(regs
, &tb_ptr
);
478 tci_write_reg(regs
, t0
, t1
& t2
);
482 t1
= tci_read_r(regs
, &tb_ptr
);
483 t2
= tci_read_r(regs
, &tb_ptr
);
484 tci_write_reg(regs
, t0
, t1
| t2
);
488 t1
= tci_read_r(regs
, &tb_ptr
);
489 t2
= tci_read_r(regs
, &tb_ptr
);
490 tci_write_reg(regs
, t0
, t1
^ t2
);
493 /* Arithmetic operations (32 bit). */
495 case INDEX_op_div_i32
:
497 t1
= tci_read_r(regs
, &tb_ptr
);
498 t2
= tci_read_r(regs
, &tb_ptr
);
499 tci_write_reg(regs
, t0
, (int32_t)t1
/ (int32_t)t2
);
501 case INDEX_op_divu_i32
:
503 t1
= tci_read_r(regs
, &tb_ptr
);
504 t2
= tci_read_r(regs
, &tb_ptr
);
505 tci_write_reg(regs
, t0
, (uint32_t)t1
/ (uint32_t)t2
);
507 case INDEX_op_rem_i32
:
509 t1
= tci_read_r(regs
, &tb_ptr
);
510 t2
= tci_read_r(regs
, &tb_ptr
);
511 tci_write_reg(regs
, t0
, (int32_t)t1
% (int32_t)t2
);
513 case INDEX_op_remu_i32
:
515 t1
= tci_read_r(regs
, &tb_ptr
);
516 t2
= tci_read_r(regs
, &tb_ptr
);
517 tci_write_reg(regs
, t0
, (uint32_t)t1
% (uint32_t)t2
);
520 /* Shift/rotate operations (32 bit). */
522 case INDEX_op_shl_i32
:
524 t1
= tci_read_r(regs
, &tb_ptr
);
525 t2
= tci_read_r(regs
, &tb_ptr
);
526 tci_write_reg(regs
, t0
, (uint32_t)t1
<< (t2
& 31));
528 case INDEX_op_shr_i32
:
530 t1
= tci_read_r(regs
, &tb_ptr
);
531 t2
= tci_read_r(regs
, &tb_ptr
);
532 tci_write_reg(regs
, t0
, (uint32_t)t1
>> (t2
& 31));
534 case INDEX_op_sar_i32
:
536 t1
= tci_read_r(regs
, &tb_ptr
);
537 t2
= tci_read_r(regs
, &tb_ptr
);
538 tci_write_reg(regs
, t0
, (int32_t)t1
>> (t2
& 31));
540 #if TCG_TARGET_HAS_rot_i32
541 case INDEX_op_rotl_i32
:
543 t1
= tci_read_r(regs
, &tb_ptr
);
544 t2
= tci_read_r(regs
, &tb_ptr
);
545 tci_write_reg(regs
, t0
, rol32(t1
, t2
& 31));
547 case INDEX_op_rotr_i32
:
549 t1
= tci_read_r(regs
, &tb_ptr
);
550 t2
= tci_read_r(regs
, &tb_ptr
);
551 tci_write_reg(regs
, t0
, ror32(t1
, t2
& 31));
554 #if TCG_TARGET_HAS_deposit_i32
555 case INDEX_op_deposit_i32
:
557 t1
= tci_read_r(regs
, &tb_ptr
);
558 t2
= tci_read_r(regs
, &tb_ptr
);
561 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
562 tci_write_reg(regs
, t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
565 case INDEX_op_brcond_i32
:
566 t0
= tci_read_r(regs
, &tb_ptr
);
567 t1
= tci_read_r(regs
, &tb_ptr
);
568 condition
= *tb_ptr
++;
569 label
= tci_read_label(&tb_ptr
);
570 if (tci_compare32(t0
, t1
, condition
)) {
571 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
572 tb_ptr
= (uint8_t *)label
;
576 #if TCG_TARGET_REG_BITS == 32
577 case INDEX_op_add2_i32
:
580 tmp64
= tci_read_r64(regs
, &tb_ptr
);
581 tmp64
+= tci_read_r64(regs
, &tb_ptr
);
582 tci_write_reg64(regs
, t1
, t0
, tmp64
);
584 case INDEX_op_sub2_i32
:
587 tmp64
= tci_read_r64(regs
, &tb_ptr
);
588 tmp64
-= tci_read_r64(regs
, &tb_ptr
);
589 tci_write_reg64(regs
, t1
, t0
, tmp64
);
591 case INDEX_op_brcond2_i32
:
592 tmp64
= tci_read_r64(regs
, &tb_ptr
);
593 v64
= tci_read_r64(regs
, &tb_ptr
);
594 condition
= *tb_ptr
++;
595 label
= tci_read_label(&tb_ptr
);
596 if (tci_compare64(tmp64
, v64
, condition
)) {
597 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
598 tb_ptr
= (uint8_t *)label
;
602 case INDEX_op_mulu2_i32
:
605 t2
= tci_read_r(regs
, &tb_ptr
);
606 tmp64
= (uint32_t)tci_read_r(regs
, &tb_ptr
);
607 tci_write_reg64(regs
, t1
, t0
, (uint32_t)t2
* tmp64
);
609 #endif /* TCG_TARGET_REG_BITS == 32 */
610 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
613 t1
= tci_read_r(regs
, &tb_ptr
);
614 tci_write_reg(regs
, t0
, (int8_t)t1
);
617 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
620 t1
= tci_read_r(regs
, &tb_ptr
);
621 tci_write_reg(regs
, t0
, (int16_t)t1
);
624 #if TCG_TARGET_HAS_ext8u_i32 || TCG_TARGET_HAS_ext8u_i64
627 t1
= tci_read_r(regs
, &tb_ptr
);
628 tci_write_reg(regs
, t0
, (uint8_t)t1
);
631 #if TCG_TARGET_HAS_ext16u_i32 || TCG_TARGET_HAS_ext16u_i64
634 t1
= tci_read_r(regs
, &tb_ptr
);
635 tci_write_reg(regs
, t0
, (uint16_t)t1
);
638 #if TCG_TARGET_HAS_bswap16_i32 || TCG_TARGET_HAS_bswap16_i64
641 t1
= tci_read_r(regs
, &tb_ptr
);
642 tci_write_reg(regs
, t0
, bswap16(t1
));
645 #if TCG_TARGET_HAS_bswap32_i32 || TCG_TARGET_HAS_bswap32_i64
648 t1
= tci_read_r(regs
, &tb_ptr
);
649 tci_write_reg(regs
, t0
, bswap32(t1
));
652 #if TCG_TARGET_HAS_not_i32 || TCG_TARGET_HAS_not_i64
655 t1
= tci_read_r(regs
, &tb_ptr
);
656 tci_write_reg(regs
, t0
, ~t1
);
659 #if TCG_TARGET_HAS_neg_i32 || TCG_TARGET_HAS_neg_i64
662 t1
= tci_read_r(regs
, &tb_ptr
);
663 tci_write_reg(regs
, t0
, -t1
);
666 #if TCG_TARGET_REG_BITS == 64
667 case INDEX_op_tci_movi_i64
:
669 t1
= tci_read_i64(&tb_ptr
);
670 tci_write_reg(regs
, t0
, t1
);
673 /* Load/store operations (64 bit). */
675 case INDEX_op_ld32s_i64
:
677 t1
= tci_read_r(regs
, &tb_ptr
);
678 t2
= tci_read_s32(&tb_ptr
);
679 tci_write_reg(regs
, t0
, *(int32_t *)(t1
+ t2
));
681 case INDEX_op_ld_i64
:
683 t1
= tci_read_r(regs
, &tb_ptr
);
684 t2
= tci_read_s32(&tb_ptr
);
685 tci_write_reg(regs
, t0
, *(uint64_t *)(t1
+ t2
));
687 case INDEX_op_st_i64
:
688 t0
= tci_read_r(regs
, &tb_ptr
);
689 t1
= tci_read_r(regs
, &tb_ptr
);
690 t2
= tci_read_s32(&tb_ptr
);
691 *(uint64_t *)(t1
+ t2
) = t0
;
694 /* Arithmetic operations (64 bit). */
696 case INDEX_op_div_i64
:
698 t1
= tci_read_r(regs
, &tb_ptr
);
699 t2
= tci_read_r(regs
, &tb_ptr
);
700 tci_write_reg(regs
, t0
, (int64_t)t1
/ (int64_t)t2
);
702 case INDEX_op_divu_i64
:
704 t1
= tci_read_r(regs
, &tb_ptr
);
705 t2
= tci_read_r(regs
, &tb_ptr
);
706 tci_write_reg(regs
, t0
, (uint64_t)t1
/ (uint64_t)t2
);
708 case INDEX_op_rem_i64
:
710 t1
= tci_read_r(regs
, &tb_ptr
);
711 t2
= tci_read_r(regs
, &tb_ptr
);
712 tci_write_reg(regs
, t0
, (int64_t)t1
% (int64_t)t2
);
714 case INDEX_op_remu_i64
:
716 t1
= tci_read_r(regs
, &tb_ptr
);
717 t2
= tci_read_r(regs
, &tb_ptr
);
718 tci_write_reg(regs
, t0
, (uint64_t)t1
% (uint64_t)t2
);
721 /* Shift/rotate operations (64 bit). */
723 case INDEX_op_shl_i64
:
725 t1
= tci_read_r(regs
, &tb_ptr
);
726 t2
= tci_read_r(regs
, &tb_ptr
);
727 tci_write_reg(regs
, t0
, t1
<< (t2
& 63));
729 case INDEX_op_shr_i64
:
731 t1
= tci_read_r(regs
, &tb_ptr
);
732 t2
= tci_read_r(regs
, &tb_ptr
);
733 tci_write_reg(regs
, t0
, t1
>> (t2
& 63));
735 case INDEX_op_sar_i64
:
737 t1
= tci_read_r(regs
, &tb_ptr
);
738 t2
= tci_read_r(regs
, &tb_ptr
);
739 tci_write_reg(regs
, t0
, ((int64_t)t1
>> (t2
& 63)));
741 #if TCG_TARGET_HAS_rot_i64
742 case INDEX_op_rotl_i64
:
744 t1
= tci_read_r(regs
, &tb_ptr
);
745 t2
= tci_read_r(regs
, &tb_ptr
);
746 tci_write_reg(regs
, t0
, rol64(t1
, t2
& 63));
748 case INDEX_op_rotr_i64
:
750 t1
= tci_read_r(regs
, &tb_ptr
);
751 t2
= tci_read_r(regs
, &tb_ptr
);
752 tci_write_reg(regs
, t0
, ror64(t1
, t2
& 63));
755 #if TCG_TARGET_HAS_deposit_i64
756 case INDEX_op_deposit_i64
:
758 t1
= tci_read_r(regs
, &tb_ptr
);
759 t2
= tci_read_r(regs
, &tb_ptr
);
762 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
763 tci_write_reg(regs
, t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
766 case INDEX_op_brcond_i64
:
767 t0
= tci_read_r(regs
, &tb_ptr
);
768 t1
= tci_read_r(regs
, &tb_ptr
);
769 condition
= *tb_ptr
++;
770 label
= tci_read_label(&tb_ptr
);
771 if (tci_compare64(t0
, t1
, condition
)) {
772 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
773 tb_ptr
= (uint8_t *)label
;
777 #if TCG_TARGET_HAS_ext32s_i64
778 case INDEX_op_ext32s_i64
:
780 case INDEX_op_ext_i32_i64
:
782 t1
= tci_read_r(regs
, &tb_ptr
);
783 tci_write_reg(regs
, t0
, (int32_t)t1
);
785 #if TCG_TARGET_HAS_ext32u_i64
786 case INDEX_op_ext32u_i64
:
788 case INDEX_op_extu_i32_i64
:
790 t1
= tci_read_r(regs
, &tb_ptr
);
791 tci_write_reg(regs
, t0
, (uint32_t)t1
);
793 #if TCG_TARGET_HAS_bswap64_i64
794 case INDEX_op_bswap64_i64
:
796 t1
= tci_read_r(regs
, &tb_ptr
);
797 tci_write_reg(regs
, t0
, bswap64(t1
));
800 #endif /* TCG_TARGET_REG_BITS == 64 */
802 /* QEMU specific operations. */
804 case INDEX_op_exit_tb
:
805 ret
= *(uint64_t *)tb_ptr
;
808 case INDEX_op_goto_tb
:
809 /* Jump address is aligned */
810 tb_ptr
= QEMU_ALIGN_PTR_UP(tb_ptr
, 4);
811 t0
= qatomic_read((int32_t *)tb_ptr
);
812 tb_ptr
+= sizeof(int32_t);
813 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
814 tb_ptr
+= (int32_t)t0
;
816 case INDEX_op_qemu_ld_i32
:
818 taddr
= tci_read_ulong(regs
, &tb_ptr
);
819 oi
= tci_read_i(&tb_ptr
);
820 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
825 tmp32
= (int8_t)qemu_ld_ub
;
828 tmp32
= qemu_ld_leuw
;
831 tmp32
= (int16_t)qemu_ld_leuw
;
834 tmp32
= qemu_ld_leul
;
837 tmp32
= qemu_ld_beuw
;
840 tmp32
= (int16_t)qemu_ld_beuw
;
843 tmp32
= qemu_ld_beul
;
846 g_assert_not_reached();
848 tci_write_reg(regs
, t0
, tmp32
);
850 case INDEX_op_qemu_ld_i64
:
852 if (TCG_TARGET_REG_BITS
== 32) {
855 taddr
= tci_read_ulong(regs
, &tb_ptr
);
856 oi
= tci_read_i(&tb_ptr
);
857 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
862 tmp64
= (int8_t)qemu_ld_ub
;
865 tmp64
= qemu_ld_leuw
;
868 tmp64
= (int16_t)qemu_ld_leuw
;
871 tmp64
= qemu_ld_leul
;
874 tmp64
= (int32_t)qemu_ld_leul
;
880 tmp64
= qemu_ld_beuw
;
883 tmp64
= (int16_t)qemu_ld_beuw
;
886 tmp64
= qemu_ld_beul
;
889 tmp64
= (int32_t)qemu_ld_beul
;
895 g_assert_not_reached();
897 tci_write_reg(regs
, t0
, tmp64
);
898 if (TCG_TARGET_REG_BITS
== 32) {
899 tci_write_reg(regs
, t1
, tmp64
>> 32);
902 case INDEX_op_qemu_st_i32
:
903 t0
= tci_read_r(regs
, &tb_ptr
);
904 taddr
= tci_read_ulong(regs
, &tb_ptr
);
905 oi
= tci_read_i(&tb_ptr
);
906 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
923 g_assert_not_reached();
926 case INDEX_op_qemu_st_i64
:
927 tmp64
= tci_read_r64(regs
, &tb_ptr
);
928 taddr
= tci_read_ulong(regs
, &tb_ptr
);
929 oi
= tci_read_i(&tb_ptr
);
930 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
953 g_assert_not_reached();
957 /* Ensure ordering for all kinds */
961 g_assert_not_reached();
963 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);