]>
git.proxmox.com Git - mirror_qemu.git/blob - tcg/tci.c
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 byte from bytecode. */
87 static uint8_t tci_read_b(const uint8_t **tb_ptr
)
89 return *(tb_ptr
[0]++);
92 /* Read register number from bytecode. */
93 static TCGReg
tci_read_r(const uint8_t **tb_ptr
)
95 uint8_t regno
= tci_read_b(tb_ptr
);
96 tci_assert(regno
< TCG_TARGET_NB_REGS
);
100 /* Read constant (native size) from bytecode. */
101 static tcg_target_ulong
tci_read_i(const uint8_t **tb_ptr
)
103 tcg_target_ulong value
= *(const tcg_target_ulong
*)(*tb_ptr
);
104 *tb_ptr
+= sizeof(value
);
108 /* Read unsigned constant (32 bit) from bytecode. */
109 static uint32_t tci_read_i32(const uint8_t **tb_ptr
)
111 uint32_t value
= *(const uint32_t *)(*tb_ptr
);
112 *tb_ptr
+= sizeof(value
);
116 /* Read signed constant (32 bit) from bytecode. */
117 static int32_t tci_read_s32(const uint8_t **tb_ptr
)
119 int32_t value
= *(const int32_t *)(*tb_ptr
);
120 *tb_ptr
+= sizeof(value
);
124 #if TCG_TARGET_REG_BITS == 64
125 /* Read constant (64 bit) from bytecode. */
126 static uint64_t tci_read_i64(const uint8_t **tb_ptr
)
128 uint64_t value
= *(const uint64_t *)(*tb_ptr
);
129 *tb_ptr
+= sizeof(value
);
134 /* Read indexed register (native size) from bytecode. */
135 static tcg_target_ulong
136 tci_read_rval(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
138 tcg_target_ulong value
= tci_read_reg(regs
, **tb_ptr
);
143 #if TCG_TARGET_REG_BITS == 32
144 /* Read two indexed registers (2 * 32 bit) from bytecode. */
145 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
146 const uint8_t **tb_ptr
)
148 uint32_t low
= tci_read_rval(regs
, tb_ptr
);
149 return tci_uint64(tci_read_rval(regs
, tb_ptr
), low
);
151 #elif TCG_TARGET_REG_BITS == 64
152 /* Read indexed register (64 bit) from bytecode. */
153 static uint64_t tci_read_r64(const tcg_target_ulong
*regs
,
154 const uint8_t **tb_ptr
)
156 return tci_read_rval(regs
, tb_ptr
);
160 /* Read indexed register(s) with target address from bytecode. */
162 tci_read_ulong(const tcg_target_ulong
*regs
, const uint8_t **tb_ptr
)
164 target_ulong taddr
= tci_read_rval(regs
, tb_ptr
);
165 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
166 taddr
+= (uint64_t)tci_read_rval(regs
, tb_ptr
) << 32;
171 static tcg_target_ulong
tci_read_label(const uint8_t **tb_ptr
)
173 tcg_target_ulong label
= tci_read_i(tb_ptr
);
174 tci_assert(label
!= 0);
179 * Load sets of arguments all at once. The naming convention is:
180 * tci_args_<arguments>
181 * where arguments is a sequence of
183 * c = condition (TCGCond)
184 * l = label or pointer
186 * s = signed ldst offset
189 static void tci_args_l(const uint8_t **tb_ptr
, void **l0
)
191 *l0
= (void *)tci_read_label(tb_ptr
);
194 static void tci_args_rr(const uint8_t **tb_ptr
,
195 TCGReg
*r0
, TCGReg
*r1
)
197 *r0
= tci_read_r(tb_ptr
);
198 *r1
= tci_read_r(tb_ptr
);
201 static void tci_args_rrr(const uint8_t **tb_ptr
,
202 TCGReg
*r0
, TCGReg
*r1
, TCGReg
*r2
)
204 *r0
= tci_read_r(tb_ptr
);
205 *r1
= tci_read_r(tb_ptr
);
206 *r2
= tci_read_r(tb_ptr
);
209 static void tci_args_rrs(const uint8_t **tb_ptr
,
210 TCGReg
*r0
, TCGReg
*r1
, int32_t *i2
)
212 *r0
= tci_read_r(tb_ptr
);
213 *r1
= tci_read_r(tb_ptr
);
214 *i2
= tci_read_s32(tb_ptr
);
217 static void tci_args_rrrc(const uint8_t **tb_ptr
,
218 TCGReg
*r0
, TCGReg
*r1
, TCGReg
*r2
, TCGCond
*c3
)
220 *r0
= tci_read_r(tb_ptr
);
221 *r1
= tci_read_r(tb_ptr
);
222 *r2
= tci_read_r(tb_ptr
);
223 *c3
= tci_read_b(tb_ptr
);
226 static bool tci_compare32(uint32_t u0
, uint32_t u1
, TCGCond condition
)
263 g_assert_not_reached();
268 static bool tci_compare64(uint64_t u0
, uint64_t u1
, TCGCond condition
)
305 g_assert_not_reached();
311 cpu_ldub_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
312 #define qemu_ld_leuw \
313 cpu_lduw_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
314 #define qemu_ld_leul \
315 cpu_ldl_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
316 #define qemu_ld_leq \
317 cpu_ldq_le_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
318 #define qemu_ld_beuw \
319 cpu_lduw_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
320 #define qemu_ld_beul \
321 cpu_ldl_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
322 #define qemu_ld_beq \
323 cpu_ldq_be_mmuidx_ra(env, taddr, get_mmuidx(oi), (uintptr_t)tb_ptr)
324 #define qemu_st_b(X) \
325 cpu_stb_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
326 #define qemu_st_lew(X) \
327 cpu_stw_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
328 #define qemu_st_lel(X) \
329 cpu_stl_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
330 #define qemu_st_leq(X) \
331 cpu_stq_le_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
332 #define qemu_st_bew(X) \
333 cpu_stw_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
334 #define qemu_st_bel(X) \
335 cpu_stl_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
336 #define qemu_st_beq(X) \
337 cpu_stq_be_mmuidx_ra(env, taddr, X, get_mmuidx(oi), (uintptr_t)tb_ptr)
339 #if TCG_TARGET_REG_BITS == 64
340 # define CASE_32_64(x) \
341 case glue(glue(INDEX_op_, x), _i64): \
342 case glue(glue(INDEX_op_, x), _i32):
343 # define CASE_64(x) \
344 case glue(glue(INDEX_op_, x), _i64):
346 # define CASE_32_64(x) \
347 case glue(glue(INDEX_op_, x), _i32):
351 /* Interpret pseudo code in tb. */
353 * Disable CFI checks.
354 * One possible operation in the pseudo code is a call to binary code.
355 * Therefore, disable CFI checks in the interpreter function
357 uintptr_t QEMU_DISABLE_CFI
tcg_qemu_tb_exec(CPUArchState
*env
,
358 const void *v_tb_ptr
)
360 const uint8_t *tb_ptr
= v_tb_ptr
;
361 tcg_target_ulong regs
[TCG_TARGET_NB_REGS
];
362 long tcg_temps
[CPU_TEMP_BUF_NLONGS
];
363 uintptr_t sp_value
= (uintptr_t)(tcg_temps
+ CPU_TEMP_BUF_NLONGS
);
366 regs
[TCG_AREG0
] = (tcg_target_ulong
)env
;
367 regs
[TCG_REG_CALL_STACK
] = sp_value
;
371 TCGOpcode opc
= tb_ptr
[0];
372 #if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
373 uint8_t op_size
= tb_ptr
[1];
374 const uint8_t *old_code_ptr
= tb_ptr
;
380 tcg_target_ulong label
;
387 #if TCG_TARGET_REG_BITS == 32
394 /* Skip opcode and size entry. */
399 t0
= tci_read_i(&tb_ptr
);
400 tci_tb_ptr
= (uintptr_t)tb_ptr
;
401 #if TCG_TARGET_REG_BITS == 32
402 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
403 tci_read_reg(regs
, TCG_REG_R1
),
404 tci_read_reg(regs
, TCG_REG_R2
),
405 tci_read_reg(regs
, TCG_REG_R3
),
406 tci_read_reg(regs
, TCG_REG_R4
),
407 tci_read_reg(regs
, TCG_REG_R5
),
408 tci_read_reg(regs
, TCG_REG_R6
),
409 tci_read_reg(regs
, TCG_REG_R7
),
410 tci_read_reg(regs
, TCG_REG_R8
),
411 tci_read_reg(regs
, TCG_REG_R9
),
412 tci_read_reg(regs
, TCG_REG_R10
),
413 tci_read_reg(regs
, TCG_REG_R11
));
414 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
415 tci_write_reg(regs
, TCG_REG_R1
, tmp64
>> 32);
417 tmp64
= ((helper_function
)t0
)(tci_read_reg(regs
, TCG_REG_R0
),
418 tci_read_reg(regs
, TCG_REG_R1
),
419 tci_read_reg(regs
, TCG_REG_R2
),
420 tci_read_reg(regs
, TCG_REG_R3
),
421 tci_read_reg(regs
, TCG_REG_R4
),
422 tci_read_reg(regs
, TCG_REG_R5
));
423 tci_write_reg(regs
, TCG_REG_R0
, tmp64
);
427 tci_args_l(&tb_ptr
, &ptr
);
428 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
431 case INDEX_op_setcond_i32
:
432 tci_args_rrrc(&tb_ptr
, &r0
, &r1
, &r2
, &condition
);
433 regs
[r0
] = tci_compare32(regs
[r1
], regs
[r2
], condition
);
435 #if TCG_TARGET_REG_BITS == 32
436 case INDEX_op_setcond2_i32
:
438 tmp64
= tci_read_r64(regs
, &tb_ptr
);
439 v64
= tci_read_r64(regs
, &tb_ptr
);
440 condition
= *tb_ptr
++;
441 tci_write_reg(regs
, t0
, tci_compare64(tmp64
, v64
, condition
));
443 #elif TCG_TARGET_REG_BITS == 64
444 case INDEX_op_setcond_i64
:
445 tci_args_rrrc(&tb_ptr
, &r0
, &r1
, &r2
, &condition
);
446 regs
[r0
] = tci_compare64(regs
[r1
], regs
[r2
], condition
);
450 tci_args_rr(&tb_ptr
, &r0
, &r1
);
453 case INDEX_op_tci_movi_i32
:
455 t1
= tci_read_i32(&tb_ptr
);
456 tci_write_reg(regs
, t0
, t1
);
459 /* Load/store operations (32 bit). */
462 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
463 ptr
= (void *)(regs
[r1
] + ofs
);
464 regs
[r0
] = *(uint8_t *)ptr
;
467 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
468 ptr
= (void *)(regs
[r1
] + ofs
);
469 regs
[r0
] = *(int8_t *)ptr
;
472 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
473 ptr
= (void *)(regs
[r1
] + ofs
);
474 regs
[r0
] = *(uint16_t *)ptr
;
477 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
478 ptr
= (void *)(regs
[r1
] + ofs
);
479 regs
[r0
] = *(int16_t *)ptr
;
481 case INDEX_op_ld_i32
:
483 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
484 ptr
= (void *)(regs
[r1
] + ofs
);
485 regs
[r0
] = *(uint32_t *)ptr
;
488 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
489 ptr
= (void *)(regs
[r1
] + ofs
);
490 *(uint8_t *)ptr
= regs
[r0
];
493 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
494 ptr
= (void *)(regs
[r1
] + ofs
);
495 *(uint16_t *)ptr
= regs
[r0
];
497 case INDEX_op_st_i32
:
499 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
500 ptr
= (void *)(regs
[r1
] + ofs
);
501 *(uint32_t *)ptr
= regs
[r0
];
504 /* Arithmetic operations (mixed 32/64 bit). */
507 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
508 regs
[r0
] = regs
[r1
] + regs
[r2
];
511 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
512 regs
[r0
] = regs
[r1
] - regs
[r2
];
515 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
516 regs
[r0
] = regs
[r1
] * regs
[r2
];
519 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
520 regs
[r0
] = regs
[r1
] & regs
[r2
];
523 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
524 regs
[r0
] = regs
[r1
] | regs
[r2
];
527 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
528 regs
[r0
] = regs
[r1
] ^ regs
[r2
];
531 /* Arithmetic operations (32 bit). */
533 case INDEX_op_div_i32
:
534 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
535 regs
[r0
] = (int32_t)regs
[r1
] / (int32_t)regs
[r2
];
537 case INDEX_op_divu_i32
:
538 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
539 regs
[r0
] = (uint32_t)regs
[r1
] / (uint32_t)regs
[r2
];
541 case INDEX_op_rem_i32
:
542 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
543 regs
[r0
] = (int32_t)regs
[r1
] % (int32_t)regs
[r2
];
545 case INDEX_op_remu_i32
:
546 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
547 regs
[r0
] = (uint32_t)regs
[r1
] % (uint32_t)regs
[r2
];
550 /* Shift/rotate operations (32 bit). */
552 case INDEX_op_shl_i32
:
553 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
554 regs
[r0
] = (uint32_t)regs
[r1
] << (regs
[r2
] & 31);
556 case INDEX_op_shr_i32
:
557 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
558 regs
[r0
] = (uint32_t)regs
[r1
] >> (regs
[r2
] & 31);
560 case INDEX_op_sar_i32
:
561 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
562 regs
[r0
] = (int32_t)regs
[r1
] >> (regs
[r2
] & 31);
564 #if TCG_TARGET_HAS_rot_i32
565 case INDEX_op_rotl_i32
:
566 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
567 regs
[r0
] = rol32(regs
[r1
], regs
[r2
] & 31);
569 case INDEX_op_rotr_i32
:
570 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
571 regs
[r0
] = ror32(regs
[r1
], regs
[r2
] & 31);
574 #if TCG_TARGET_HAS_deposit_i32
575 case INDEX_op_deposit_i32
:
577 t1
= tci_read_rval(regs
, &tb_ptr
);
578 t2
= tci_read_rval(regs
, &tb_ptr
);
581 tmp32
= (((1 << tmp8
) - 1) << tmp16
);
582 tci_write_reg(regs
, t0
, (t1
& ~tmp32
) | ((t2
<< tmp16
) & tmp32
));
585 case INDEX_op_brcond_i32
:
586 t0
= tci_read_rval(regs
, &tb_ptr
);
587 t1
= tci_read_rval(regs
, &tb_ptr
);
588 condition
= *tb_ptr
++;
589 label
= tci_read_label(&tb_ptr
);
590 if (tci_compare32(t0
, t1
, condition
)) {
591 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
592 tb_ptr
= (uint8_t *)label
;
596 #if TCG_TARGET_REG_BITS == 32
597 case INDEX_op_add2_i32
:
600 tmp64
= tci_read_r64(regs
, &tb_ptr
);
601 tmp64
+= tci_read_r64(regs
, &tb_ptr
);
602 tci_write_reg64(regs
, t1
, t0
, tmp64
);
604 case INDEX_op_sub2_i32
:
607 tmp64
= tci_read_r64(regs
, &tb_ptr
);
608 tmp64
-= tci_read_r64(regs
, &tb_ptr
);
609 tci_write_reg64(regs
, t1
, t0
, tmp64
);
611 case INDEX_op_brcond2_i32
:
612 tmp64
= tci_read_r64(regs
, &tb_ptr
);
613 v64
= tci_read_r64(regs
, &tb_ptr
);
614 condition
= *tb_ptr
++;
615 label
= tci_read_label(&tb_ptr
);
616 if (tci_compare64(tmp64
, v64
, condition
)) {
617 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
618 tb_ptr
= (uint8_t *)label
;
622 case INDEX_op_mulu2_i32
:
625 t2
= tci_read_rval(regs
, &tb_ptr
);
626 tmp64
= (uint32_t)tci_read_rval(regs
, &tb_ptr
);
627 tci_write_reg64(regs
, t1
, t0
, (uint32_t)t2
* tmp64
);
629 #endif /* TCG_TARGET_REG_BITS == 32 */
630 #if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
632 tci_args_rr(&tb_ptr
, &r0
, &r1
);
633 regs
[r0
] = (int8_t)regs
[r1
];
636 #if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
638 tci_args_rr(&tb_ptr
, &r0
, &r1
);
639 regs
[r0
] = (int16_t)regs
[r1
];
642 #if TCG_TARGET_HAS_ext8u_i32 || TCG_TARGET_HAS_ext8u_i64
644 tci_args_rr(&tb_ptr
, &r0
, &r1
);
645 regs
[r0
] = (uint8_t)regs
[r1
];
648 #if TCG_TARGET_HAS_ext16u_i32 || TCG_TARGET_HAS_ext16u_i64
650 tci_args_rr(&tb_ptr
, &r0
, &r1
);
651 regs
[r0
] = (uint16_t)regs
[r1
];
654 #if TCG_TARGET_HAS_bswap16_i32 || TCG_TARGET_HAS_bswap16_i64
656 tci_args_rr(&tb_ptr
, &r0
, &r1
);
657 regs
[r0
] = bswap16(regs
[r1
]);
660 #if TCG_TARGET_HAS_bswap32_i32 || TCG_TARGET_HAS_bswap32_i64
662 tci_args_rr(&tb_ptr
, &r0
, &r1
);
663 regs
[r0
] = bswap32(regs
[r1
]);
666 #if TCG_TARGET_HAS_not_i32 || TCG_TARGET_HAS_not_i64
668 tci_args_rr(&tb_ptr
, &r0
, &r1
);
669 regs
[r0
] = ~regs
[r1
];
672 #if TCG_TARGET_HAS_neg_i32 || TCG_TARGET_HAS_neg_i64
674 tci_args_rr(&tb_ptr
, &r0
, &r1
);
675 regs
[r0
] = -regs
[r1
];
678 #if TCG_TARGET_REG_BITS == 64
679 case INDEX_op_tci_movi_i64
:
681 t1
= tci_read_i64(&tb_ptr
);
682 tci_write_reg(regs
, t0
, t1
);
685 /* Load/store operations (64 bit). */
687 case INDEX_op_ld32s_i64
:
688 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
689 ptr
= (void *)(regs
[r1
] + ofs
);
690 regs
[r0
] = *(int32_t *)ptr
;
692 case INDEX_op_ld_i64
:
693 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
694 ptr
= (void *)(regs
[r1
] + ofs
);
695 regs
[r0
] = *(uint64_t *)ptr
;
697 case INDEX_op_st_i64
:
698 tci_args_rrs(&tb_ptr
, &r0
, &r1
, &ofs
);
699 ptr
= (void *)(regs
[r1
] + ofs
);
700 *(uint64_t *)ptr
= regs
[r0
];
703 /* Arithmetic operations (64 bit). */
705 case INDEX_op_div_i64
:
706 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
707 regs
[r0
] = (int64_t)regs
[r1
] / (int64_t)regs
[r2
];
709 case INDEX_op_divu_i64
:
710 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
711 regs
[r0
] = (uint64_t)regs
[r1
] / (uint64_t)regs
[r2
];
713 case INDEX_op_rem_i64
:
714 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
715 regs
[r0
] = (int64_t)regs
[r1
] % (int64_t)regs
[r2
];
717 case INDEX_op_remu_i64
:
718 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
719 regs
[r0
] = (uint64_t)regs
[r1
] % (uint64_t)regs
[r2
];
722 /* Shift/rotate operations (64 bit). */
724 case INDEX_op_shl_i64
:
725 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
726 regs
[r0
] = regs
[r1
] << (regs
[r2
] & 63);
728 case INDEX_op_shr_i64
:
729 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
730 regs
[r0
] = regs
[r1
] >> (regs
[r2
] & 63);
732 case INDEX_op_sar_i64
:
733 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
734 regs
[r0
] = (int64_t)regs
[r1
] >> (regs
[r2
] & 63);
736 #if TCG_TARGET_HAS_rot_i64
737 case INDEX_op_rotl_i64
:
738 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
739 regs
[r0
] = rol64(regs
[r1
], regs
[r2
] & 63);
741 case INDEX_op_rotr_i64
:
742 tci_args_rrr(&tb_ptr
, &r0
, &r1
, &r2
);
743 regs
[r0
] = ror64(regs
[r1
], regs
[r2
] & 63);
746 #if TCG_TARGET_HAS_deposit_i64
747 case INDEX_op_deposit_i64
:
749 t1
= tci_read_rval(regs
, &tb_ptr
);
750 t2
= tci_read_rval(regs
, &tb_ptr
);
753 tmp64
= (((1ULL << tmp8
) - 1) << tmp16
);
754 tci_write_reg(regs
, t0
, (t1
& ~tmp64
) | ((t2
<< tmp16
) & tmp64
));
757 case INDEX_op_brcond_i64
:
758 t0
= tci_read_rval(regs
, &tb_ptr
);
759 t1
= tci_read_rval(regs
, &tb_ptr
);
760 condition
= *tb_ptr
++;
761 label
= tci_read_label(&tb_ptr
);
762 if (tci_compare64(t0
, t1
, condition
)) {
763 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
764 tb_ptr
= (uint8_t *)label
;
768 case INDEX_op_ext32s_i64
:
769 case INDEX_op_ext_i32_i64
:
770 tci_args_rr(&tb_ptr
, &r0
, &r1
);
771 regs
[r0
] = (int32_t)regs
[r1
];
773 case INDEX_op_ext32u_i64
:
774 case INDEX_op_extu_i32_i64
:
775 tci_args_rr(&tb_ptr
, &r0
, &r1
);
776 regs
[r0
] = (uint32_t)regs
[r1
];
778 #if TCG_TARGET_HAS_bswap64_i64
779 case INDEX_op_bswap64_i64
:
780 tci_args_rr(&tb_ptr
, &r0
, &r1
);
781 regs
[r0
] = bswap64(regs
[r1
]);
784 #endif /* TCG_TARGET_REG_BITS == 64 */
786 /* QEMU specific operations. */
788 case INDEX_op_exit_tb
:
789 ret
= *(uint64_t *)tb_ptr
;
792 case INDEX_op_goto_tb
:
793 /* Jump address is aligned */
794 tb_ptr
= QEMU_ALIGN_PTR_UP(tb_ptr
, 4);
795 t0
= qatomic_read((int32_t *)tb_ptr
);
796 tb_ptr
+= sizeof(int32_t);
797 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);
798 tb_ptr
+= (int32_t)t0
;
800 case INDEX_op_qemu_ld_i32
:
802 taddr
= tci_read_ulong(regs
, &tb_ptr
);
803 oi
= tci_read_i(&tb_ptr
);
804 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
809 tmp32
= (int8_t)qemu_ld_ub
;
812 tmp32
= qemu_ld_leuw
;
815 tmp32
= (int16_t)qemu_ld_leuw
;
818 tmp32
= qemu_ld_leul
;
821 tmp32
= qemu_ld_beuw
;
824 tmp32
= (int16_t)qemu_ld_beuw
;
827 tmp32
= qemu_ld_beul
;
830 g_assert_not_reached();
832 tci_write_reg(regs
, t0
, tmp32
);
834 case INDEX_op_qemu_ld_i64
:
836 if (TCG_TARGET_REG_BITS
== 32) {
839 taddr
= tci_read_ulong(regs
, &tb_ptr
);
840 oi
= tci_read_i(&tb_ptr
);
841 switch (get_memop(oi
) & (MO_BSWAP
| MO_SSIZE
)) {
846 tmp64
= (int8_t)qemu_ld_ub
;
849 tmp64
= qemu_ld_leuw
;
852 tmp64
= (int16_t)qemu_ld_leuw
;
855 tmp64
= qemu_ld_leul
;
858 tmp64
= (int32_t)qemu_ld_leul
;
864 tmp64
= qemu_ld_beuw
;
867 tmp64
= (int16_t)qemu_ld_beuw
;
870 tmp64
= qemu_ld_beul
;
873 tmp64
= (int32_t)qemu_ld_beul
;
879 g_assert_not_reached();
881 tci_write_reg(regs
, t0
, tmp64
);
882 if (TCG_TARGET_REG_BITS
== 32) {
883 tci_write_reg(regs
, t1
, tmp64
>> 32);
886 case INDEX_op_qemu_st_i32
:
887 t0
= tci_read_rval(regs
, &tb_ptr
);
888 taddr
= tci_read_ulong(regs
, &tb_ptr
);
889 oi
= tci_read_i(&tb_ptr
);
890 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
907 g_assert_not_reached();
910 case INDEX_op_qemu_st_i64
:
911 tmp64
= tci_read_r64(regs
, &tb_ptr
);
912 taddr
= tci_read_ulong(regs
, &tb_ptr
);
913 oi
= tci_read_i(&tb_ptr
);
914 switch (get_memop(oi
) & (MO_BSWAP
| MO_SIZE
)) {
937 g_assert_not_reached();
941 /* Ensure ordering for all kinds */
945 g_assert_not_reached();
947 tci_assert(tb_ptr
== old_code_ptr
+ op_size
);