2008-05-20 03:59:38 +04:00
|
|
|
/*
|
|
|
|
* Tiny Code Generator for QEMU
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Andrzej Zaborowski
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2008-10-05 13:59:14 +04:00
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
#if defined(__ARM_ARCH_7__) || \
|
|
|
|
defined(__ARM_ARCH_7A__) || \
|
|
|
|
defined(__ARM_ARCH_7EM__) || \
|
|
|
|
defined(__ARM_ARCH_7M__) || \
|
|
|
|
defined(__ARM_ARCH_7R__)
|
|
|
|
#define USE_ARMV7_INSTRUCTIONS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_ARMV7_INSTRUCTIONS) || \
|
|
|
|
defined(__ARM_ARCH_6J__) || \
|
|
|
|
defined(__ARM_ARCH_6K__) || \
|
|
|
|
defined(__ARM_ARCH_6T2__) || \
|
|
|
|
defined(__ARM_ARCH_6Z__) || \
|
|
|
|
defined(__ARM_ARCH_6ZK__)
|
|
|
|
#define USE_ARMV6_INSTRUCTIONS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_ARMV6_INSTRUCTIONS) || \
|
|
|
|
defined(__ARM_ARCH_5T__) || \
|
|
|
|
defined(__ARM_ARCH_5TE__) || \
|
|
|
|
defined(__ARM_ARCH_5TEJ__)
|
|
|
|
#define USE_ARMV5_INSTRUCTIONS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_ARMV5_INSTRUCTIONS
|
|
|
|
static const int use_armv5_instructions = 1;
|
|
|
|
#else
|
|
|
|
static const int use_armv5_instructions = 0;
|
|
|
|
#endif
|
|
|
|
#undef USE_ARMV5_INSTRUCTIONS
|
|
|
|
|
|
|
|
#ifdef USE_ARMV6_INSTRUCTIONS
|
|
|
|
static const int use_armv6_instructions = 1;
|
|
|
|
#else
|
|
|
|
static const int use_armv6_instructions = 0;
|
|
|
|
#endif
|
|
|
|
#undef USE_ARMV6_INSTRUCTIONS
|
|
|
|
|
|
|
|
#ifdef USE_ARMV7_INSTRUCTIONS
|
|
|
|
static const int use_armv7_instructions = 1;
|
|
|
|
#else
|
|
|
|
static const int use_armv7_instructions = 0;
|
|
|
|
#endif
|
|
|
|
#undef USE_ARMV7_INSTRUCTIONS
|
|
|
|
|
2008-10-05 13:59:14 +04:00
|
|
|
#ifndef NDEBUG
|
|
|
|
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
|
2008-05-20 03:59:38 +04:00
|
|
|
"%r0",
|
|
|
|
"%r1",
|
|
|
|
"%r2",
|
|
|
|
"%r3",
|
|
|
|
"%r4",
|
|
|
|
"%r5",
|
|
|
|
"%r6",
|
|
|
|
"%r7",
|
|
|
|
"%r8",
|
|
|
|
"%r9",
|
|
|
|
"%r10",
|
|
|
|
"%r11",
|
|
|
|
"%r12",
|
|
|
|
"%r13",
|
|
|
|
"%r14",
|
2010-04-09 22:52:48 +04:00
|
|
|
"%pc",
|
2008-05-20 03:59:38 +04:00
|
|
|
};
|
2008-10-05 13:59:14 +04:00
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2008-10-05 13:59:14 +04:00
|
|
|
static const int tcg_target_reg_alloc_order[] = {
|
2008-05-20 03:59:38 +04:00
|
|
|
TCG_REG_R4,
|
|
|
|
TCG_REG_R5,
|
|
|
|
TCG_REG_R6,
|
|
|
|
TCG_REG_R7,
|
|
|
|
TCG_REG_R8,
|
|
|
|
TCG_REG_R9,
|
|
|
|
TCG_REG_R10,
|
|
|
|
TCG_REG_R11,
|
|
|
|
TCG_REG_R13,
|
2010-04-09 22:52:48 +04:00
|
|
|
TCG_REG_R0,
|
|
|
|
TCG_REG_R1,
|
|
|
|
TCG_REG_R2,
|
|
|
|
TCG_REG_R3,
|
|
|
|
TCG_REG_R12,
|
2008-05-20 03:59:38 +04:00
|
|
|
TCG_REG_R14,
|
|
|
|
};
|
|
|
|
|
2008-10-05 13:59:14 +04:00
|
|
|
static const int tcg_target_call_iarg_regs[4] = {
|
2008-05-20 03:59:38 +04:00
|
|
|
TCG_REG_R0, TCG_REG_R1, TCG_REG_R2, TCG_REG_R3
|
|
|
|
};
|
2008-10-05 13:59:14 +04:00
|
|
|
static const int tcg_target_call_oarg_regs[2] = {
|
2008-05-20 03:59:38 +04:00
|
|
|
TCG_REG_R0, TCG_REG_R1
|
|
|
|
};
|
|
|
|
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
static inline void reloc_abs32(void *code_ptr, tcg_target_long target)
|
|
|
|
{
|
|
|
|
*(uint32_t *) code_ptr = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void reloc_pc24(void *code_ptr, tcg_target_long target)
|
|
|
|
{
|
|
|
|
uint32_t offset = ((target - ((tcg_target_long) code_ptr + 8)) >> 2);
|
|
|
|
|
|
|
|
*(uint32_t *) code_ptr = ((*(uint32_t *) code_ptr) & ~0xffffff)
|
|
|
|
| (offset & 0xffffff);
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:26:40 +04:00
|
|
|
static void patch_reloc(uint8_t *code_ptr, int type,
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_target_long value, tcg_target_long addend)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case R_ARM_ABS32:
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
reloc_abs32(code_ptr, value);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case R_ARM_CALL:
|
|
|
|
case R_ARM_JUMP24:
|
|
|
|
default:
|
|
|
|
tcg_abort();
|
|
|
|
|
|
|
|
case R_ARM_PC24:
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
reloc_pc24(code_ptr, value);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 09:36:45 +04:00
|
|
|
#define TCG_CT_CONST_ARM 0x100
|
|
|
|
#define TCG_CT_CONST_INV 0x200
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
/* parse target specific constraints */
|
2008-10-05 13:59:14 +04:00
|
|
|
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
const char *ct_str;
|
|
|
|
|
|
|
|
ct_str = *pct_str;
|
|
|
|
switch (ct_str[0]) {
|
2009-07-18 16:20:30 +04:00
|
|
|
case 'I':
|
2013-03-05 09:36:45 +04:00
|
|
|
ct->ct |= TCG_CT_CONST_ARM;
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
ct->ct |= TCG_CT_CONST_INV;
|
|
|
|
break;
|
2009-07-18 16:20:30 +04:00
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
case 'r':
|
|
|
|
ct->ct |= TCG_CT_REG;
|
|
|
|
tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1);
|
|
|
|
break;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
/* qemu_ld address */
|
|
|
|
case 'l':
|
2008-05-20 03:59:38 +04:00
|
|
|
ct->ct |= TCG_CT_REG;
|
|
|
|
tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1);
|
2010-04-09 22:52:48 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
|
|
|
/* r0 and r1 will be overwritten when reading the tlb entry,
|
|
|
|
so don't use these. */
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0);
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1);
|
2012-09-02 19:28:56 +04:00
|
|
|
#if TARGET_LONG_BITS == 64
|
2012-08-26 17:40:02 +04:00
|
|
|
/* If we're passing env to the helper as r0 and need a regpair
|
|
|
|
* for the address then r2 will be overwritten as we're setting
|
|
|
|
* up the args to the helper.
|
|
|
|
*/
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R2);
|
|
|
|
#endif
|
2010-04-09 22:52:48 +04:00
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
2010-04-09 22:52:48 +04:00
|
|
|
case 'L':
|
2008-05-25 03:12:19 +04:00
|
|
|
ct->ct |= TCG_CT_REG;
|
|
|
|
tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1);
|
2010-04-09 22:52:48 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
|
|
|
/* r1 is still needed to load data_reg or data_reg2,
|
|
|
|
so don't use it. */
|
2008-05-25 03:12:19 +04:00
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1);
|
2010-04-09 22:52:48 +04:00
|
|
|
#endif
|
2008-05-25 03:12:19 +04:00
|
|
|
break;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
/* qemu_st address & data_reg */
|
|
|
|
case 's':
|
2008-05-20 03:59:38 +04:00
|
|
|
ct->ct |= TCG_CT_REG;
|
|
|
|
tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1);
|
2010-04-09 22:52:48 +04:00
|
|
|
/* r0 and r1 will be overwritten when reading the tlb entry
|
|
|
|
(softmmu only) and doing the byte swapping, so don't
|
|
|
|
use these. */
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0);
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1);
|
2012-09-02 19:28:56 +04:00
|
|
|
#if defined(CONFIG_SOFTMMU) && (TARGET_LONG_BITS == 64)
|
2012-08-26 17:40:02 +04:00
|
|
|
/* Avoid clashes with registers being used for helper args */
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R2);
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
|
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
2010-04-09 22:52:48 +04:00
|
|
|
/* qemu_st64 data_reg2 */
|
|
|
|
case 'S':
|
2008-05-20 03:59:38 +04:00
|
|
|
ct->ct |= TCG_CT_REG;
|
|
|
|
tcg_regset_set32(ct->u.regs, 0, (1 << TCG_TARGET_NB_REGS) - 1);
|
2010-04-09 22:52:48 +04:00
|
|
|
/* r0 and r1 will be overwritten when reading the tlb entry
|
|
|
|
(softmmu only) and doing the byte swapping, so don't
|
|
|
|
use these. */
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R0);
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R1);
|
2010-04-09 22:52:48 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
|
|
|
/* r2 is still needed to load data_reg, so don't use it. */
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R2);
|
2012-09-02 19:28:56 +04:00
|
|
|
#if TARGET_LONG_BITS == 64
|
2012-08-26 17:40:02 +04:00
|
|
|
/* Avoid clashes with registers being used for helper args */
|
|
|
|
tcg_regset_reset_reg(ct->u.regs, TCG_REG_R3);
|
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
#endif
|
2010-04-09 22:52:48 +04:00
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ct_str++;
|
|
|
|
*pct_str = ct_str;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-22 16:29:09 +04:00
|
|
|
static inline uint32_t rotl(uint32_t val, int n)
|
|
|
|
{
|
|
|
|
return (val << n) | (val >> (32 - n));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARM immediates for ALU instructions are made of an unsigned 8-bit
|
|
|
|
right-rotated by an even amount between 0 and 30. */
|
|
|
|
static inline int encode_imm(uint32_t imm)
|
|
|
|
{
|
2009-08-25 03:12:25 +04:00
|
|
|
int shift;
|
|
|
|
|
2009-08-22 16:29:09 +04:00
|
|
|
/* simple case, only lower bits */
|
|
|
|
if ((imm & ~0xff) == 0)
|
|
|
|
return 0;
|
|
|
|
/* then try a simple even shift */
|
|
|
|
shift = ctz32(imm) & ~1;
|
|
|
|
if (((imm >> shift) & ~0xff) == 0)
|
|
|
|
return 32 - shift;
|
|
|
|
/* now try harder with rotations */
|
|
|
|
if ((rotl(imm, 2) & ~0xff) == 0)
|
|
|
|
return 2;
|
|
|
|
if ((rotl(imm, 4) & ~0xff) == 0)
|
|
|
|
return 4;
|
|
|
|
if ((rotl(imm, 6) & ~0xff) == 0)
|
|
|
|
return 6;
|
|
|
|
/* imm can't be encoded */
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-18 16:20:30 +04:00
|
|
|
|
|
|
|
static inline int check_fit_imm(uint32_t imm)
|
|
|
|
{
|
2009-08-22 16:29:09 +04:00
|
|
|
return encode_imm(imm) >= 0;
|
2009-07-18 16:20:30 +04:00
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
/* Test if a constant matches the constraint.
|
|
|
|
* TODO: define constraints for:
|
|
|
|
*
|
|
|
|
* ldr/str offset: between -0xfff and 0xfff
|
|
|
|
* ldrh/strh offset: between -0xff and 0xff
|
|
|
|
* mov operand2: values represented with x << (2 * y), x < 0x100
|
|
|
|
* add, sub, eor...: ditto
|
|
|
|
*/
|
|
|
|
static inline int tcg_target_const_match(tcg_target_long val,
|
2013-03-05 09:36:45 +04:00
|
|
|
const TCGArgConstraint *arg_ct)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
int ct;
|
|
|
|
ct = arg_ct->ct;
|
2013-03-05 09:36:45 +04:00
|
|
|
if (ct & TCG_CT_CONST) {
|
2008-05-20 03:59:38 +04:00
|
|
|
return 1;
|
2013-03-05 09:36:45 +04:00
|
|
|
} else if ((ct & TCG_CT_CONST_ARM) && check_fit_imm(val)) {
|
2009-07-18 16:20:30 +04:00
|
|
|
return 1;
|
2013-03-05 09:36:45 +04:00
|
|
|
} else if ((ct & TCG_CT_CONST_INV) && check_fit_imm(~val)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2008-05-20 03:59:38 +04:00
|
|
|
return 0;
|
2013-03-05 09:36:45 +04:00
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
enum arm_data_opc_e {
|
|
|
|
ARITH_AND = 0x0,
|
|
|
|
ARITH_EOR = 0x1,
|
|
|
|
ARITH_SUB = 0x2,
|
|
|
|
ARITH_RSB = 0x3,
|
|
|
|
ARITH_ADD = 0x4,
|
|
|
|
ARITH_ADC = 0x5,
|
|
|
|
ARITH_SBC = 0x6,
|
|
|
|
ARITH_RSC = 0x7,
|
2008-05-25 00:07:07 +04:00
|
|
|
ARITH_TST = 0x8,
|
2008-05-20 03:59:38 +04:00
|
|
|
ARITH_CMP = 0xa,
|
|
|
|
ARITH_CMN = 0xb,
|
|
|
|
ARITH_ORR = 0xc,
|
|
|
|
ARITH_MOV = 0xd,
|
|
|
|
ARITH_BIC = 0xe,
|
|
|
|
ARITH_MVN = 0xf,
|
|
|
|
};
|
|
|
|
|
2008-05-25 00:07:07 +04:00
|
|
|
#define TO_CPSR(opc) \
|
|
|
|
((opc == ARITH_CMP || opc == ARITH_CMN || opc == ARITH_TST) << 20)
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
#define SHIFT_IMM_LSL(im) (((im) << 7) | 0x00)
|
|
|
|
#define SHIFT_IMM_LSR(im) (((im) << 7) | 0x20)
|
|
|
|
#define SHIFT_IMM_ASR(im) (((im) << 7) | 0x40)
|
|
|
|
#define SHIFT_IMM_ROR(im) (((im) << 7) | 0x60)
|
|
|
|
#define SHIFT_REG_LSL(rs) (((rs) << 8) | 0x10)
|
|
|
|
#define SHIFT_REG_LSR(rs) (((rs) << 8) | 0x30)
|
|
|
|
#define SHIFT_REG_ASR(rs) (((rs) << 8) | 0x50)
|
|
|
|
#define SHIFT_REG_ROR(rs) (((rs) << 8) | 0x70)
|
|
|
|
|
|
|
|
enum arm_cond_code_e {
|
|
|
|
COND_EQ = 0x0,
|
|
|
|
COND_NE = 0x1,
|
|
|
|
COND_CS = 0x2, /* Unsigned greater or equal */
|
|
|
|
COND_CC = 0x3, /* Unsigned less than */
|
|
|
|
COND_MI = 0x4, /* Negative */
|
|
|
|
COND_PL = 0x5, /* Zero or greater */
|
|
|
|
COND_VS = 0x6, /* Overflow */
|
|
|
|
COND_VC = 0x7, /* No overflow */
|
|
|
|
COND_HI = 0x8, /* Unsigned greater than */
|
|
|
|
COND_LS = 0x9, /* Unsigned less or equal */
|
|
|
|
COND_GE = 0xa,
|
|
|
|
COND_LT = 0xb,
|
|
|
|
COND_GT = 0xc,
|
|
|
|
COND_LE = 0xd,
|
|
|
|
COND_AL = 0xe,
|
|
|
|
};
|
|
|
|
|
2012-09-25 01:21:40 +04:00
|
|
|
static const uint8_t tcg_cond_to_arm_cond[] = {
|
2008-05-20 03:59:38 +04:00
|
|
|
[TCG_COND_EQ] = COND_EQ,
|
|
|
|
[TCG_COND_NE] = COND_NE,
|
|
|
|
[TCG_COND_LT] = COND_LT,
|
|
|
|
[TCG_COND_GE] = COND_GE,
|
|
|
|
[TCG_COND_LE] = COND_LE,
|
|
|
|
[TCG_COND_GT] = COND_GT,
|
|
|
|
/* unsigned */
|
|
|
|
[TCG_COND_LTU] = COND_CC,
|
|
|
|
[TCG_COND_GEU] = COND_CS,
|
|
|
|
[TCG_COND_LEU] = COND_LS,
|
|
|
|
[TCG_COND_GTU] = COND_HI,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void tcg_out_bx(TCGContext *s, int cond, int rn)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x012fff10 | rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x0a000000 |
|
|
|
|
(((offset - 8) >> 2) & 0x00ffffff));
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:50:44 +04:00
|
|
|
static inline void tcg_out_b_noaddr(TCGContext *s, int cond)
|
|
|
|
{
|
2011-01-10 20:30:05 +03:00
|
|
|
/* We pay attention here to not modify the branch target by skipping
|
|
|
|
the corresponding bytes. This ensure that caches and memory are
|
|
|
|
kept coherent during retranslation. */
|
2009-07-27 18:13:06 +04:00
|
|
|
#ifdef HOST_WORDS_BIGENDIAN
|
2008-05-23 22:50:44 +04:00
|
|
|
tcg_out8(s, (cond << 4) | 0x0a);
|
|
|
|
s->code_ptr += 3;
|
|
|
|
#else
|
|
|
|
s->code_ptr += 3;
|
|
|
|
tcg_out8(s, (cond << 4) | 0x0a);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_bl(TCGContext *s, int cond, int32_t offset)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x0b000000 |
|
|
|
|
(((offset - 8) >> 2) & 0x00ffffff));
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_blx(TCGContext *s, int cond, int rn)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x012fff30 | rn);
|
|
|
|
}
|
|
|
|
|
2011-03-16 18:21:31 +03:00
|
|
|
static inline void tcg_out_blx_imm(TCGContext *s, int32_t offset)
|
|
|
|
{
|
|
|
|
tcg_out32(s, 0xfa000000 | ((offset & 2) << 23) |
|
|
|
|
(((offset - 8) >> 2) & 0x00ffffff));
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_dat_reg(TCGContext *s,
|
|
|
|
int cond, int opc, int rd, int rn, int rm, int shift)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | (0 << 25) | (opc << 21) | TO_CPSR(opc) |
|
|
|
|
(rn << 16) | (rd << 12) | shift | rm);
|
|
|
|
}
|
|
|
|
|
2012-08-26 17:40:02 +04:00
|
|
|
static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm)
|
|
|
|
{
|
|
|
|
/* Simple reg-reg move, optimising out the 'do nothing' case */
|
|
|
|
if (rd != rm) {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV, rd, 0, rm, SHIFT_IMM_LSL(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_dat_reg2(TCGContext *s,
|
|
|
|
int cond, int opc0, int opc1, int rd0, int rd1,
|
|
|
|
int rn0, int rn1, int rm0, int rm1, int shift)
|
|
|
|
{
|
2008-12-01 14:57:21 +03:00
|
|
|
if (rd0 == rn1 || rd0 == rm1) {
|
|
|
|
tcg_out32(s, (cond << 28) | (0 << 25) | (opc0 << 21) | (1 << 20) |
|
|
|
|
(rn0 << 16) | (8 << 12) | shift | rm0);
|
|
|
|
tcg_out32(s, (cond << 28) | (0 << 25) | (opc1 << 21) |
|
|
|
|
(rn1 << 16) | (rd1 << 12) | shift | rm1);
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
rd0, 0, TCG_REG_R8, SHIFT_IMM_LSL(0));
|
|
|
|
} else {
|
|
|
|
tcg_out32(s, (cond << 28) | (0 << 25) | (opc0 << 21) | (1 << 20) |
|
|
|
|
(rn0 << 16) | (rd0 << 12) | shift | rm0);
|
|
|
|
tcg_out32(s, (cond << 28) | (0 << 25) | (opc1 << 21) |
|
|
|
|
(rn1 << 16) | (rd1 << 12) | shift | rm1);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_dat_imm(TCGContext *s,
|
|
|
|
int cond, int opc, int rd, int rn, int im)
|
|
|
|
{
|
2008-05-25 00:07:07 +04:00
|
|
|
tcg_out32(s, (cond << 28) | (1 << 25) | (opc << 21) | TO_CPSR(opc) |
|
2008-05-20 03:59:38 +04:00
|
|
|
(rn << 16) | (rd << 12) | im);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_movi32(TCGContext *s,
|
2011-01-07 00:43:13 +03:00
|
|
|
int cond, int rd, uint32_t arg)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
/* TODO: This is very suboptimal, we can easily have a constant
|
|
|
|
* pool somewhere after all the instructions. */
|
2011-01-07 00:43:13 +03:00
|
|
|
if ((int)arg < 0 && (int)arg >= -0x100) {
|
|
|
|
tcg_out_dat_imm(s, cond, ARITH_MVN, rd, 0, (~arg) & 0xff);
|
|
|
|
} else if (use_armv7_instructions) {
|
2010-04-09 22:52:48 +04:00
|
|
|
/* use movw/movt */
|
|
|
|
/* movw */
|
|
|
|
tcg_out32(s, (cond << 28) | 0x03000000 | (rd << 12)
|
|
|
|
| ((arg << 4) & 0x000f0000) | (arg & 0xfff));
|
2011-01-07 00:43:13 +03:00
|
|
|
if (arg & 0xffff0000) {
|
2010-04-09 22:52:48 +04:00
|
|
|
/* movt */
|
|
|
|
tcg_out32(s, (cond << 28) | 0x03400000 | (rd << 12)
|
|
|
|
| ((arg >> 12) & 0x000f0000) | ((arg >> 16) & 0xfff));
|
|
|
|
}
|
2011-01-07 00:43:13 +03:00
|
|
|
} else {
|
|
|
|
int opc = ARITH_MOV;
|
|
|
|
int rn = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int i, rot;
|
|
|
|
|
|
|
|
i = ctz32(arg) & ~1;
|
|
|
|
rot = ((32 - i) << 7) & 0xf00;
|
|
|
|
tcg_out_dat_imm(s, cond, opc, rd, rn, ((arg >> i) & 0xff) | rot);
|
|
|
|
arg &= ~(0xff << i);
|
|
|
|
|
|
|
|
opc = ARITH_ORR;
|
|
|
|
rn = rd;
|
|
|
|
} while (arg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
|
2012-09-26 22:48:54 +04:00
|
|
|
static inline void tcg_out_dat_rI(TCGContext *s, int cond, int opc, TCGArg dst,
|
|
|
|
TCGArg lhs, TCGArg rhs, int rhs_is_const)
|
|
|
|
{
|
|
|
|
/* Emit either the reg,imm or reg,reg form of a data-processing insn.
|
|
|
|
* rhs must satisfy the "rI" constraint.
|
|
|
|
*/
|
|
|
|
if (rhs_is_const) {
|
|
|
|
int rot = encode_imm(rhs);
|
|
|
|
assert(rot >= 0);
|
|
|
|
tcg_out_dat_imm(s, cond, opc, dst, lhs, rotl(rhs, rot) | (rot << 7));
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, opc, dst, lhs, rhs, SHIFT_IMM_LSL(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 09:36:45 +04:00
|
|
|
static void tcg_out_dat_rIK(TCGContext *s, int cond, int opc, int opinv,
|
|
|
|
TCGReg dst, TCGReg lhs, TCGArg rhs,
|
|
|
|
bool rhs_is_const)
|
|
|
|
{
|
|
|
|
/* Emit either the reg,imm or reg,reg form of a data-processing insn.
|
|
|
|
* rhs must satisfy the "rIK" constraint.
|
|
|
|
*/
|
|
|
|
if (rhs_is_const) {
|
|
|
|
int rot = encode_imm(rhs);
|
|
|
|
if (rot < 0) {
|
|
|
|
rhs = ~rhs;
|
|
|
|
rot = encode_imm(rhs);
|
|
|
|
assert(rot >= 0);
|
|
|
|
opc = opinv;
|
|
|
|
}
|
|
|
|
tcg_out_dat_imm(s, cond, opc, dst, lhs, rotl(rhs, rot) | (rot << 7));
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, opc, dst, lhs, rhs, SHIFT_IMM_LSL(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_mul32(TCGContext *s,
|
|
|
|
int cond, int rd, int rs, int rm)
|
|
|
|
{
|
|
|
|
if (rd != rm)
|
|
|
|
tcg_out32(s, (cond << 28) | (rd << 16) | (0 << 12) |
|
|
|
|
(rs << 8) | 0x90 | rm);
|
|
|
|
else if (rd != rs)
|
|
|
|
tcg_out32(s, (cond << 28) | (rd << 16) | (0 << 12) |
|
|
|
|
(rm << 8) | 0x90 | rs);
|
|
|
|
else {
|
|
|
|
tcg_out32(s, (cond << 28) | ( 8 << 16) | (0 << 12) |
|
|
|
|
(rs << 8) | 0x90 | rm);
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, TCG_REG_R8, SHIFT_IMM_LSL(0));
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_umull32(TCGContext *s,
|
|
|
|
int cond, int rd0, int rd1, int rs, int rm)
|
|
|
|
{
|
|
|
|
if (rd0 != rm && rd1 != rm)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x800090 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rs << 8) | rm);
|
|
|
|
else if (rd0 != rs && rd1 != rs)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x800090 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rm << 8) | rs);
|
|
|
|
else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, rm, SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out32(s, (cond << 28) | 0x800098 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rs << 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_smull32(TCGContext *s,
|
|
|
|
int cond, int rd0, int rd1, int rs, int rm)
|
|
|
|
{
|
|
|
|
if (rd0 != rm && rd1 != rm)
|
|
|
|
tcg_out32(s, (cond << 28) | 0xc00090 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rs << 8) | rm);
|
|
|
|
else if (rd0 != rs && rd1 != rs)
|
|
|
|
tcg_out32(s, (cond << 28) | 0xc00090 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rm << 8) | rs);
|
|
|
|
else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, rm, SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out32(s, (cond << 28) | 0xc00098 |
|
|
|
|
(rd1 << 16) | (rd0 << 12) | (rs << 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_ext8s(TCGContext *s, int cond,
|
|
|
|
int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* sxtb */
|
|
|
|
tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rn, SHIFT_IMM_LSL(24));
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rd, SHIFT_IMM_ASR(24));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_ext8u(TCGContext *s, int cond,
|
|
|
|
int rd, int rn)
|
|
|
|
{
|
|
|
|
tcg_out_dat_imm(s, cond, ARITH_AND, rd, rn, 0xff);
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_ext16s(TCGContext *s, int cond,
|
|
|
|
int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* sxth */
|
|
|
|
tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rn, SHIFT_IMM_LSL(16));
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rd, SHIFT_IMM_ASR(16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ext16u(TCGContext *s, int cond,
|
|
|
|
int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* uxth */
|
|
|
|
tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rn, SHIFT_IMM_LSL(16));
|
2010-04-25 07:46:22 +04:00
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
rd, 0, rd, SHIFT_IMM_LSR(16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_bswap16s(TCGContext *s, int cond, int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* revsh */
|
|
|
|
tcg_out32(s, 0x06ff0fb0 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, rn, SHIFT_IMM_LSL(24));
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, TCG_REG_R8, SHIFT_IMM_ASR(16));
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_ORR,
|
|
|
|
rd, TCG_REG_R8, rn, SHIFT_IMM_LSR(8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_bswap16(TCGContext *s, int cond, int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* rev16 */
|
|
|
|
tcg_out32(s, 0x06bf0fb0 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, rn, SHIFT_IMM_LSL(24));
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, TCG_REG_R8, SHIFT_IMM_LSR(16));
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_ORR,
|
|
|
|
rd, TCG_REG_R8, rn, SHIFT_IMM_LSR(8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 23:53:11 +04:00
|
|
|
/* swap the two low bytes assuming that the two high input bytes and the
|
|
|
|
two high output bit can hold any value. */
|
|
|
|
static inline void tcg_out_bswap16st(TCGContext *s, int cond, int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* rev16 */
|
|
|
|
tcg_out32(s, 0x06bf0fb0 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
TCG_REG_R8, 0, rn, SHIFT_IMM_LSR(8));
|
|
|
|
tcg_out_dat_imm(s, cond, ARITH_AND, TCG_REG_R8, TCG_REG_R8, 0xff);
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_ORR,
|
|
|
|
rd, TCG_REG_R8, rn, SHIFT_IMM_LSL(8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_bswap32(TCGContext *s, int cond, int rd, int rn)
|
|
|
|
{
|
|
|
|
if (use_armv6_instructions) {
|
|
|
|
/* rev */
|
|
|
|
tcg_out32(s, 0x06bf0f30 | (cond << 28) | (rd << 12) | rn);
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_EOR,
|
|
|
|
TCG_REG_R8, rn, rn, SHIFT_IMM_ROR(16));
|
|
|
|
tcg_out_dat_imm(s, cond, ARITH_BIC,
|
|
|
|
TCG_REG_R8, TCG_REG_R8, 0xff | 0x800);
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV,
|
|
|
|
rd, 0, rn, SHIFT_IMM_ROR(8));
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_EOR,
|
|
|
|
rd, rd, TCG_REG_R8, SHIFT_IMM_LSR(8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_ld32_12(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05900000 |
|
|
|
|
(rn << 16) | (rd << 12) | (im & 0xfff));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05100000 |
|
|
|
|
(rn << 16) | (rd << 12) | ((-im) & 0xfff));
|
|
|
|
}
|
|
|
|
|
2012-10-09 23:53:11 +04:00
|
|
|
/* Offset pre-increment with base writeback. */
|
|
|
|
static inline void tcg_out_ld32_12wb(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
/* ldr with writeback and both register equals is UNPREDICTABLE */
|
|
|
|
assert(rd != rn);
|
|
|
|
|
|
|
|
if (im >= 0) {
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05b00000 |
|
|
|
|
(rn << 16) | (rd << 12) | (im & 0xfff));
|
|
|
|
} else {
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05300000 |
|
|
|
|
(rn << 16) | (rd << 12) | ((-im) & 0xfff));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_st32_12(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05800000 |
|
|
|
|
(rn << 16) | (rd << 12) | (im & 0xfff));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05000000 |
|
|
|
|
(rn << 16) | (rd << 12) | ((-im) & 0xfff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld32_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07900000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_st32_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07800000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
2008-05-25 00:07:07 +04:00
|
|
|
/* Register pre-increment with base writeback. */
|
|
|
|
static inline void tcg_out_ld32_rwb(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07b00000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_st32_rwb(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07a00000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_ld16u_8(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x01d000b0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
((im & 0xf0) << 4) | (im & 0xf));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x015000b0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
(((-im) & 0xf0) << 4) | ((-im) & 0xf));
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_st16_8(TCGContext *s, int cond,
|
2008-05-20 03:59:38 +04:00
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x01c000b0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
((im & 0xf0) << 4) | (im & 0xf));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x014000b0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
(((-im) & 0xf0) << 4) | ((-im) & 0xf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld16u_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x019000b0 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_st16_r(TCGContext *s, int cond,
|
2008-05-20 03:59:38 +04:00
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x018000b0 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld16s_8(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x01d000f0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
((im & 0xf0) << 4) | (im & 0xf));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x015000f0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
(((-im) & 0xf0) << 4) | ((-im) & 0xf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld16s_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x019000f0 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8_12(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05d00000 |
|
|
|
|
(rn << 16) | (rd << 12) | (im & 0xfff));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05500000 |
|
|
|
|
(rn << 16) | (rd << 12) | ((-im) & 0xfff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_st8_12(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05c00000 |
|
|
|
|
(rn << 16) | (rd << 12) | (im & 0xfff));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x05400000 |
|
|
|
|
(rn << 16) | (rd << 12) | ((-im) & 0xfff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07d00000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_st8_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
|
|
|
tcg_out32(s, (cond << 28) | 0x07c00000 |
|
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8s_8(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, tcg_target_long im)
|
|
|
|
{
|
|
|
|
if (im >= 0)
|
|
|
|
tcg_out32(s, (cond << 28) | 0x01d000d0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
((im & 0xf0) << 4) | (im & 0xf));
|
|
|
|
else
|
|
|
|
tcg_out32(s, (cond << 28) | 0x015000d0 |
|
|
|
|
(rn << 16) | (rd << 12) |
|
|
|
|
(((-im) & 0xf0) << 4) | ((-im) & 0xf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8s_r(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int rm)
|
|
|
|
{
|
2008-05-20 15:28:35 +04:00
|
|
|
tcg_out32(s, (cond << 28) | 0x019000d0 |
|
2008-05-20 03:59:38 +04:00
|
|
|
(rn << 16) | (rd << 12) | rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld32u(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xfff || offset < -0xfff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_ld32_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_ld32_12(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_st32(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xfff || offset < -0xfff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_st32_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_st32_12(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld16u(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xff || offset < -0xff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_ld16u_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_ld16u_8(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld16s(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xff || offset < -0xff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_ld16s_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_ld16s_8(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_st16(TCGContext *s, int cond,
|
2008-05-20 03:59:38 +04:00
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xff || offset < -0xff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st16_r(s, cond, rd, rn, TCG_REG_R8);
|
2008-05-20 03:59:38 +04:00
|
|
|
} else
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st16_8(s, cond, rd, rn, offset);
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8u(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xfff || offset < -0xfff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_ld8_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_ld8_12(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_ld8s(TCGContext *s, int cond,
|
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xff || offset < -0xff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_ld8s_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_ld8s_8(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_st8(TCGContext *s, int cond,
|
2008-05-20 03:59:38 +04:00
|
|
|
int rd, int rn, int32_t offset)
|
|
|
|
{
|
|
|
|
if (offset > 0xfff || offset < -0xfff) {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, offset);
|
|
|
|
tcg_out_st8_r(s, cond, rd, rn, TCG_REG_R8);
|
|
|
|
} else
|
|
|
|
tcg_out_st8_12(s, cond, rd, rn, offset);
|
|
|
|
}
|
|
|
|
|
2011-12-12 19:37:31 +04:00
|
|
|
/* The _goto case is normally between TBs within the same code buffer,
|
2012-01-08 00:00:25 +04:00
|
|
|
* and with the code buffer limited to 16MB we shouldn't need the long
|
2011-12-12 19:37:31 +04:00
|
|
|
* case.
|
|
|
|
*
|
|
|
|
* .... except to the prologue that is in its own buffer.
|
|
|
|
*/
|
2008-05-20 03:59:38 +04:00
|
|
|
static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr)
|
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
|
2011-03-16 18:21:31 +03:00
|
|
|
if (addr & 1) {
|
|
|
|
/* goto to a Thumb destination isn't supported */
|
|
|
|
tcg_abort();
|
|
|
|
}
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
val = addr - (tcg_target_long) s->code_ptr;
|
|
|
|
if (val - 8 < 0x01fffffd && val - 8 > -0x01fffffd)
|
|
|
|
tcg_out_b(s, cond, val);
|
|
|
|
else {
|
|
|
|
if (cond == COND_AL) {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4);
|
2011-12-12 19:37:31 +04:00
|
|
|
tcg_out32(s, addr);
|
2008-05-20 03:59:38 +04:00
|
|
|
} else {
|
|
|
|
tcg_out_movi32(s, cond, TCG_REG_R8, val - 8);
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_ADD,
|
2010-04-09 22:52:48 +04:00
|
|
|
TCG_REG_PC, TCG_REG_PC,
|
|
|
|
TCG_REG_R8, SHIFT_IMM_LSL(0));
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 19:37:31 +04:00
|
|
|
/* The call case is mostly used for helpers - so it's not unreasonable
|
|
|
|
* for them to be beyond branch range */
|
2011-03-16 18:21:31 +03:00
|
|
|
static inline void tcg_out_call(TCGContext *s, uint32_t addr)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
|
|
|
|
val = addr - (tcg_target_long) s->code_ptr;
|
2011-03-16 18:21:31 +03:00
|
|
|
if (val - 8 < 0x02000000 && val - 8 >= -0x02000000) {
|
|
|
|
if (addr & 1) {
|
|
|
|
/* Use BLX if the target is in Thumb mode */
|
|
|
|
if (!use_armv5_instructions) {
|
|
|
|
tcg_abort();
|
|
|
|
}
|
|
|
|
tcg_out_blx_imm(s, val);
|
|
|
|
} else {
|
|
|
|
tcg_out_bl(s, COND_AL, val);
|
|
|
|
}
|
|
|
|
} else {
|
2011-12-12 19:37:31 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4);
|
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4);
|
|
|
|
tcg_out32(s, addr);
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_callr(TCGContext *s, int cond, int arg)
|
|
|
|
{
|
2010-04-09 22:52:48 +04:00
|
|
|
if (use_armv5_instructions) {
|
|
|
|
tcg_out_blx(s, cond, arg);
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_reg(s, cond, ARITH_MOV, TCG_REG_R14, 0,
|
|
|
|
TCG_REG_PC, SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out_bx(s, cond, arg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_goto_label(TCGContext *s, int cond, int label_index)
|
|
|
|
{
|
|
|
|
TCGLabel *l = &s->labels[label_index];
|
|
|
|
|
|
|
|
if (l->has_value)
|
|
|
|
tcg_out_goto(s, cond, l->u.value);
|
|
|
|
else if (cond == COND_AL) {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4);
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out_reloc(s, s->code_ptr, R_ARM_ABS32, label_index, 31337);
|
|
|
|
s->code_ptr += 4;
|
|
|
|
} else {
|
|
|
|
/* Probably this should be preferred even for COND_AL... */
|
|
|
|
tcg_out_reloc(s, s->code_ptr, R_ARM_PC24, label_index, 31337);
|
2008-05-23 22:50:44 +04:00
|
|
|
tcg_out_b_noaddr(s, cond);
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SOFTMMU
|
2008-08-30 13:51:20 +04:00
|
|
|
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/softmmu_defs.h"
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2011-09-18 18:55:46 +04:00
|
|
|
/* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
|
|
|
|
int mmu_idx) */
|
|
|
|
static const void * const qemu_ld_helpers[4] = {
|
|
|
|
helper_ldb_mmu,
|
|
|
|
helper_ldw_mmu,
|
|
|
|
helper_ldl_mmu,
|
|
|
|
helper_ldq_mmu,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
|
|
|
|
uintxx_t val, int mmu_idx) */
|
|
|
|
static const void * const qemu_st_helpers[4] = {
|
|
|
|
helper_stb_mmu,
|
|
|
|
helper_stw_mmu,
|
|
|
|
helper_stl_mmu,
|
|
|
|
helper_stq_mmu,
|
|
|
|
};
|
2012-08-26 17:40:02 +04:00
|
|
|
|
|
|
|
/* Helper routines for marshalling helper function arguments into
|
|
|
|
* the correct registers and stack.
|
|
|
|
* argreg is where we want to put this argument, arg is the argument itself.
|
|
|
|
* Return value is the updated argreg ready for the next call.
|
|
|
|
* Note that argreg 0..3 is real registers, 4+ on stack.
|
|
|
|
*
|
|
|
|
* We provide routines for arguments which are: immediate, 32 bit
|
|
|
|
* value in register, 16 and 8 bit values in register (which must be zero
|
|
|
|
* extended before use) and 64 bit value in a lo:hi register pair.
|
|
|
|
*/
|
2013-03-13 04:11:40 +04:00
|
|
|
#define DEFINE_TCG_OUT_ARG(NAME, ARGTYPE, MOV_ARG, EXT_ARG) \
|
|
|
|
static TCGReg NAME(TCGContext *s, TCGReg argreg, ARGTYPE arg) \
|
|
|
|
{ \
|
|
|
|
if (argreg < 4) { \
|
|
|
|
MOV_ARG(s, COND_AL, argreg, arg); \
|
|
|
|
} else { \
|
|
|
|
int ofs = (argreg - 4) * 4; \
|
|
|
|
EXT_ARG; \
|
|
|
|
assert(ofs + 4 <= TCG_STATIC_CALL_ARGS_SIZE); \
|
|
|
|
tcg_out_st32_12(s, COND_AL, arg, TCG_REG_CALL_STACK, ofs); \
|
|
|
|
} \
|
|
|
|
return argreg + 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TCG_OUT_ARG(tcg_out_arg_imm32, uint32_t, tcg_out_movi32,
|
|
|
|
(tcg_out_movi32(s, COND_AL, TCG_REG_R8, arg), arg = TCG_REG_R8))
|
|
|
|
DEFINE_TCG_OUT_ARG(tcg_out_arg_reg8, TCGReg, tcg_out_ext8u,
|
|
|
|
(tcg_out_ext8u(s, COND_AL, TCG_REG_R8, arg), arg = TCG_REG_R8))
|
|
|
|
DEFINE_TCG_OUT_ARG(tcg_out_arg_reg16, TCGReg, tcg_out_ext16u,
|
|
|
|
(tcg_out_ext16u(s, COND_AL, TCG_REG_R8, arg), arg = TCG_REG_R8))
|
|
|
|
DEFINE_TCG_OUT_ARG(tcg_out_arg_reg32, TCGReg, tcg_out_mov_reg, )
|
|
|
|
|
|
|
|
static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg,
|
|
|
|
TCGReg arglo, TCGReg arghi)
|
2012-08-26 17:40:02 +04:00
|
|
|
{
|
|
|
|
/* 64 bit arguments must go in even/odd register pairs
|
|
|
|
* and in 8-aligned stack slots.
|
|
|
|
*/
|
|
|
|
if (argreg & 1) {
|
|
|
|
argreg++;
|
|
|
|
}
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, arglo);
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, arghi);
|
|
|
|
return argreg;
|
|
|
|
}
|
2013-03-13 04:11:40 +04:00
|
|
|
#endif /* SOFTMMU */
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2008-05-25 00:07:07 +04:00
|
|
|
#define TLB_SHIFT (CPU_TLB_ENTRY_BITS + CPU_TLB_BITS)
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int opc)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
2010-04-09 22:52:48 +04:00
|
|
|
int addr_reg, data_reg, data_reg2, bswap;
|
2008-05-20 03:59:38 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
2012-10-09 23:53:11 +04:00
|
|
|
int mem_index, s_bits, tlb_offset;
|
2012-08-26 17:40:02 +04:00
|
|
|
TCGReg argreg;
|
2008-05-20 03:59:38 +04:00
|
|
|
# if TARGET_LONG_BITS == 64
|
|
|
|
int addr_reg2;
|
|
|
|
# endif
|
|
|
|
uint32_t *label_ptr;
|
|
|
|
#endif
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
bswap = 1;
|
|
|
|
#else
|
|
|
|
bswap = 0;
|
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
data_reg = *args++;
|
|
|
|
if (opc == 3)
|
|
|
|
data_reg2 = *args++;
|
|
|
|
else
|
2009-09-24 19:53:10 +04:00
|
|
|
data_reg2 = 0; /* suppress warning */
|
2008-05-20 03:59:38 +04:00
|
|
|
addr_reg = *args++;
|
|
|
|
#ifdef CONFIG_SOFTMMU
|
2008-12-08 02:35:47 +03:00
|
|
|
# if TARGET_LONG_BITS == 64
|
|
|
|
addr_reg2 = *args++;
|
|
|
|
# endif
|
2008-05-20 03:59:38 +04:00
|
|
|
mem_index = *args;
|
|
|
|
s_bits = opc & 3;
|
|
|
|
|
2008-05-23 22:51:15 +04:00
|
|
|
/* Should generate something like the following:
|
2008-05-25 00:07:07 +04:00
|
|
|
* shr r8, addr_reg, #TARGET_PAGE_BITS
|
2008-05-23 22:51:15 +04:00
|
|
|
* and r0, r8, #(CPU_TLB_SIZE - 1) @ Assumption: CPU_TLB_BITS <= 8
|
2008-05-25 00:07:07 +04:00
|
|
|
* add r0, env, r0 lsl #CPU_TLB_ENTRY_BITS
|
2008-05-23 22:51:15 +04:00
|
|
|
*/
|
|
|
|
# if CPU_TLB_BITS > 8
|
|
|
|
# error
|
|
|
|
# endif
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_R8,
|
|
|
|
0, addr_reg, SHIFT_IMM_LSR(TARGET_PAGE_BITS));
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_AND,
|
2010-04-09 22:52:48 +04:00
|
|
|
TCG_REG_R0, TCG_REG_R8, CPU_TLB_SIZE - 1);
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_ADD, TCG_REG_R0, TCG_AREG0,
|
|
|
|
TCG_REG_R0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS));
|
2012-10-09 23:53:11 +04:00
|
|
|
/* We assume that the offset is contained within 20 bits. */
|
|
|
|
tlb_offset = offsetof(CPUArchState, tlb_table[mem_index][0].addr_read);
|
2013-01-18 00:04:16 +04:00
|
|
|
assert((tlb_offset & ~0xfffff) == 0);
|
2012-10-09 23:53:11 +04:00
|
|
|
if (tlb_offset > 0xfff) {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R0, TCG_REG_R0,
|
2012-10-09 23:53:11 +04:00
|
|
|
0xa00 | (tlb_offset >> 12));
|
|
|
|
tlb_offset &= 0xfff;
|
|
|
|
}
|
|
|
|
tcg_out_ld32_12wb(s, COND_AL, TCG_REG_R1, TCG_REG_R0, tlb_offset);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0, TCG_REG_R1,
|
|
|
|
TCG_REG_R8, SHIFT_IMM_LSL(TARGET_PAGE_BITS));
|
2008-05-25 00:07:07 +04:00
|
|
|
/* Check alignment. */
|
|
|
|
if (s_bits)
|
|
|
|
tcg_out_dat_imm(s, COND_EQ, ARITH_TST,
|
|
|
|
0, addr_reg, (1 << s_bits) - 1);
|
2008-05-20 03:59:38 +04:00
|
|
|
# if TARGET_LONG_BITS == 64
|
2012-10-09 23:53:11 +04:00
|
|
|
/* XXX: possibly we could use a block data load in the first access. */
|
|
|
|
tcg_out_ld32_12(s, COND_EQ, TCG_REG_R1, TCG_REG_R0, 4);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
|
|
|
TCG_REG_R1, addr_reg2, SHIFT_IMM_LSL(0));
|
2008-05-20 03:59:38 +04:00
|
|
|
# endif
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_EQ, TCG_REG_R1, TCG_REG_R0,
|
2012-10-09 23:53:11 +04:00
|
|
|
offsetof(CPUTLBEntry, addend)
|
|
|
|
- offsetof(CPUTLBEntry, addr_read));
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
switch (opc) {
|
|
|
|
case 0:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld8_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 0 | 4:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld8s_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld16u_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap16(s, COND_EQ, data_reg, data_reg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1 | 4:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_ld16u_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
|
|
|
tcg_out_bswap16s(s, COND_EQ, data_reg, data_reg);
|
|
|
|
} else {
|
|
|
|
tcg_out_ld16s_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
default:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_EQ, data_reg, data_reg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_ld32_rwb(s, COND_EQ, data_reg2, TCG_REG_R1, addr_reg);
|
|
|
|
tcg_out_ld32_12(s, COND_EQ, data_reg, TCG_REG_R1, 4);
|
|
|
|
tcg_out_bswap32(s, COND_EQ, data_reg2, data_reg2);
|
|
|
|
tcg_out_bswap32(s, COND_EQ, data_reg, data_reg);
|
|
|
|
} else {
|
|
|
|
tcg_out_ld32_rwb(s, COND_EQ, data_reg, TCG_REG_R1, addr_reg);
|
|
|
|
tcg_out_ld32_12(s, COND_EQ, data_reg2, TCG_REG_R1, 4);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label_ptr = (void *) s->code_ptr;
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
tcg_out_b_noaddr(s, COND_EQ);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
/* TODO: move this code to where the constants pool will be */
|
2012-08-26 17:40:02 +04:00
|
|
|
/* Note that this code relies on the constraints we set in arm_op_defs[]
|
|
|
|
* to ensure that later arguments are not passed to us in registers we
|
|
|
|
* trash by moving the earlier arguments into them.
|
|
|
|
*/
|
|
|
|
argreg = TCG_REG_R0;
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, TCG_AREG0);
|
|
|
|
#if TARGET_LONG_BITS == 64
|
|
|
|
argreg = tcg_out_arg_reg64(s, argreg, addr_reg, addr_reg2);
|
|
|
|
#else
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, addr_reg);
|
2011-09-18 18:55:46 +04:00
|
|
|
#endif
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_imm32(s, argreg, mem_index);
|
2011-03-16 18:21:31 +03:00
|
|
|
tcg_out_call(s, (tcg_target_long) qemu_ld_helpers[s_bits]);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
switch (opc) {
|
|
|
|
case 0 | 4:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ext8s(s, COND_AL, data_reg, TCG_REG_R0);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1 | 4:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ext16s(s, COND_AL, data_reg, TCG_REG_R0);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
default:
|
2012-09-27 17:55:43 +04:00
|
|
|
tcg_out_mov_reg(s, COND_AL, data_reg, TCG_REG_R0);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-09-27 17:55:43 +04:00
|
|
|
tcg_out_mov_reg(s, COND_AL, data_reg, TCG_REG_R0);
|
|
|
|
tcg_out_mov_reg(s, COND_AL, data_reg2, TCG_REG_R1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
reloc_pc24(label_ptr, (tcg_target_long)s->code_ptr);
|
2009-07-17 15:48:08 +04:00
|
|
|
#else /* !CONFIG_SOFTMMU */
|
|
|
|
if (GUEST_BASE) {
|
|
|
|
uint32_t offset = GUEST_BASE;
|
|
|
|
int i;
|
|
|
|
int rot;
|
|
|
|
|
|
|
|
while (offset) {
|
|
|
|
i = ctz32(offset) & ~1;
|
|
|
|
rot = ((32 - i) << 7) & 0xf00;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R8, addr_reg,
|
2009-07-17 15:48:08 +04:00
|
|
|
((offset >> i) & 0xff) | rot);
|
2010-04-09 22:52:48 +04:00
|
|
|
addr_reg = TCG_REG_R8;
|
2009-07-17 15:48:08 +04:00
|
|
|
offset &= ~(0xff << i);
|
|
|
|
}
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
switch (opc) {
|
|
|
|
case 0:
|
|
|
|
tcg_out_ld8_12(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
break;
|
|
|
|
case 0 | 4:
|
|
|
|
tcg_out_ld8s_8(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
tcg_out_ld16u_8(s, COND_AL, data_reg, addr_reg, 0);
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap16(s, COND_AL, data_reg, data_reg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1 | 4:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_ld16u_8(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
tcg_out_bswap16s(s, COND_AL, data_reg, data_reg);
|
|
|
|
} else {
|
|
|
|
tcg_out_ld16s_8(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_AL, data_reg, data_reg);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-05-25 02:56:51 +04:00
|
|
|
/* TODO: use block load -
|
|
|
|
* check that data_reg2 > data_reg or the other way */
|
tcg-arm: fix qemu_ld64
Emulating fldl on arm doesn't seem to work too well. It's the way
qemu_ld64 is translated to arm instructions.
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, 4);
Consider case where data_reg==0, data_reg2==1, and addr_reg==0. First load
overwrited addr_reg. So let's put an if (data_ref==addr_reg).
(Pablo Virolainen)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6808 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-11 00:43:25 +03:00
|
|
|
if (data_reg == addr_reg) {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, bswap ? 0 : 4);
|
|
|
|
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, bswap ? 4 : 0);
|
tcg-arm: fix qemu_ld64
Emulating fldl on arm doesn't seem to work too well. It's the way
qemu_ld64 is translated to arm instructions.
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, 4);
Consider case where data_reg==0, data_reg2==1, and addr_reg==0. First load
overwrited addr_reg. So let's put an if (data_ref==addr_reg).
(Pablo Virolainen)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6808 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-11 00:43:25 +03:00
|
|
|
} else {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, bswap ? 4 : 0);
|
|
|
|
tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, bswap ? 0 : 4);
|
|
|
|
}
|
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_AL, data_reg, data_reg);
|
|
|
|
tcg_out_bswap32(s, COND_AL, data_reg2, data_reg2);
|
tcg-arm: fix qemu_ld64
Emulating fldl on arm doesn't seem to work too well. It's the way
qemu_ld64 is translated to arm instructions.
tcg_out_ld32_12(s, COND_AL, data_reg, addr_reg, 0);
tcg_out_ld32_12(s, COND_AL, data_reg2, addr_reg, 4);
Consider case where data_reg==0, data_reg2==1, and addr_reg==0. First load
overwrited addr_reg. So let's put an if (data_ref==addr_reg).
(Pablo Virolainen)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6808 c046a42c-6fe2-441c-8c8c-71466251a162
2009-03-11 00:43:25 +03:00
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int opc)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
2010-04-09 22:52:48 +04:00
|
|
|
int addr_reg, data_reg, data_reg2, bswap;
|
2008-05-20 03:59:38 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
2012-10-09 23:53:11 +04:00
|
|
|
int mem_index, s_bits, tlb_offset;
|
2012-08-26 17:40:02 +04:00
|
|
|
TCGReg argreg;
|
2008-05-20 03:59:38 +04:00
|
|
|
# if TARGET_LONG_BITS == 64
|
|
|
|
int addr_reg2;
|
|
|
|
# endif
|
|
|
|
uint32_t *label_ptr;
|
|
|
|
#endif
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
bswap = 1;
|
|
|
|
#else
|
|
|
|
bswap = 0;
|
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
data_reg = *args++;
|
|
|
|
if (opc == 3)
|
|
|
|
data_reg2 = *args++;
|
|
|
|
else
|
2009-09-24 19:53:10 +04:00
|
|
|
data_reg2 = 0; /* suppress warning */
|
2008-05-20 03:59:38 +04:00
|
|
|
addr_reg = *args++;
|
|
|
|
#ifdef CONFIG_SOFTMMU
|
2008-12-08 02:35:47 +03:00
|
|
|
# if TARGET_LONG_BITS == 64
|
|
|
|
addr_reg2 = *args++;
|
|
|
|
# endif
|
2008-05-20 03:59:38 +04:00
|
|
|
mem_index = *args;
|
|
|
|
s_bits = opc & 3;
|
|
|
|
|
2008-05-23 22:51:15 +04:00
|
|
|
/* Should generate something like the following:
|
2008-05-25 00:07:07 +04:00
|
|
|
* shr r8, addr_reg, #TARGET_PAGE_BITS
|
2008-05-23 22:51:15 +04:00
|
|
|
* and r0, r8, #(CPU_TLB_SIZE - 1) @ Assumption: CPU_TLB_BITS <= 8
|
2008-05-25 00:07:07 +04:00
|
|
|
* add r0, env, r0 lsl #CPU_TLB_ENTRY_BITS
|
2008-05-23 22:51:15 +04:00
|
|
|
*/
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV,
|
2010-04-09 22:52:48 +04:00
|
|
|
TCG_REG_R8, 0, addr_reg, SHIFT_IMM_LSR(TARGET_PAGE_BITS));
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_AND,
|
2010-04-09 22:52:48 +04:00
|
|
|
TCG_REG_R0, TCG_REG_R8, CPU_TLB_SIZE - 1);
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_ADD, TCG_REG_R0,
|
|
|
|
TCG_AREG0, TCG_REG_R0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS));
|
2012-10-09 23:53:11 +04:00
|
|
|
/* We assume that the offset is contained within 20 bits. */
|
|
|
|
tlb_offset = offsetof(CPUArchState, tlb_table[mem_index][0].addr_write);
|
2013-01-18 00:04:16 +04:00
|
|
|
assert((tlb_offset & ~0xfffff) == 0);
|
2012-10-09 23:53:11 +04:00
|
|
|
if (tlb_offset > 0xfff) {
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R0, TCG_REG_R0,
|
2012-10-09 23:53:11 +04:00
|
|
|
0xa00 | (tlb_offset >> 12));
|
|
|
|
tlb_offset &= 0xfff;
|
|
|
|
}
|
|
|
|
tcg_out_ld32_12wb(s, COND_AL, TCG_REG_R1, TCG_REG_R0, tlb_offset);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0, TCG_REG_R1,
|
|
|
|
TCG_REG_R8, SHIFT_IMM_LSL(TARGET_PAGE_BITS));
|
2008-05-25 00:07:07 +04:00
|
|
|
/* Check alignment. */
|
|
|
|
if (s_bits)
|
|
|
|
tcg_out_dat_imm(s, COND_EQ, ARITH_TST,
|
|
|
|
0, addr_reg, (1 << s_bits) - 1);
|
2008-05-20 03:59:38 +04:00
|
|
|
# if TARGET_LONG_BITS == 64
|
2012-10-09 23:53:11 +04:00
|
|
|
/* XXX: possibly we could use a block data load in the first access. */
|
|
|
|
tcg_out_ld32_12(s, COND_EQ, TCG_REG_R1, TCG_REG_R0, 4);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
|
|
|
TCG_REG_R1, addr_reg2, SHIFT_IMM_LSL(0));
|
2008-05-20 03:59:38 +04:00
|
|
|
# endif
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_EQ, TCG_REG_R1, TCG_REG_R0,
|
2012-10-09 23:53:11 +04:00
|
|
|
offsetof(CPUTLBEntry, addend)
|
|
|
|
- offsetof(CPUTLBEntry, addr_write));
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
switch (opc) {
|
|
|
|
case 0:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st8_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
2012-10-09 23:53:11 +04:00
|
|
|
tcg_out_bswap16st(s, COND_EQ, TCG_REG_R0, data_reg);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st16_r(s, COND_EQ, TCG_REG_R0, addr_reg, TCG_REG_R1);
|
|
|
|
} else {
|
|
|
|
tcg_out_st16_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
default:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_EQ, TCG_REG_R0, data_reg);
|
|
|
|
tcg_out_st32_r(s, COND_EQ, TCG_REG_R0, addr_reg, TCG_REG_R1);
|
|
|
|
} else {
|
|
|
|
tcg_out_st32_r(s, COND_EQ, data_reg, addr_reg, TCG_REG_R1);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_EQ, TCG_REG_R0, data_reg2);
|
|
|
|
tcg_out_st32_rwb(s, COND_EQ, TCG_REG_R0, TCG_REG_R1, addr_reg);
|
|
|
|
tcg_out_bswap32(s, COND_EQ, TCG_REG_R0, data_reg);
|
2011-01-07 00:43:13 +03:00
|
|
|
tcg_out_st32_12(s, COND_EQ, TCG_REG_R0, TCG_REG_R1, 4);
|
2010-04-09 22:52:48 +04:00
|
|
|
} else {
|
|
|
|
tcg_out_st32_rwb(s, COND_EQ, data_reg, TCG_REG_R1, addr_reg);
|
|
|
|
tcg_out_st32_12(s, COND_EQ, data_reg2, TCG_REG_R1, 4);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label_ptr = (void *) s->code_ptr;
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
tcg_out_b_noaddr(s, COND_EQ);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
/* TODO: move this code to where the constants pool will be */
|
2012-08-26 17:40:02 +04:00
|
|
|
/* Note that this code relies on the constraints we set in arm_op_defs[]
|
|
|
|
* to ensure that later arguments are not passed to us in registers we
|
|
|
|
* trash by moving the earlier arguments into them.
|
|
|
|
*/
|
|
|
|
argreg = TCG_REG_R0;
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, TCG_AREG0);
|
|
|
|
#if TARGET_LONG_BITS == 64
|
|
|
|
argreg = tcg_out_arg_reg64(s, argreg, addr_reg, addr_reg2);
|
|
|
|
#else
|
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, addr_reg);
|
|
|
|
#endif
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
switch (opc) {
|
|
|
|
case 0:
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_reg8(s, argreg, data_reg);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_reg16(s, argreg, data_reg);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_reg32(s, argreg, data_reg);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_reg64(s, argreg, data_reg, data_reg2);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-26 17:40:02 +04:00
|
|
|
argreg = tcg_out_arg_imm32(s, argreg, mem_index);
|
2011-03-16 18:21:31 +03:00
|
|
|
tcg_out_call(s, (tcg_target_long) qemu_st_helpers[s_bits]);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
reloc_pc24(label_ptr, (tcg_target_long)s->code_ptr);
|
2009-07-17 15:48:08 +04:00
|
|
|
#else /* !CONFIG_SOFTMMU */
|
|
|
|
if (GUEST_BASE) {
|
|
|
|
uint32_t offset = GUEST_BASE;
|
|
|
|
int i;
|
|
|
|
int rot;
|
|
|
|
|
|
|
|
while (offset) {
|
|
|
|
i = ctz32(offset) & ~1;
|
|
|
|
rot = ((32 - i) << 7) & 0xf00;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R1, addr_reg,
|
2009-07-17 15:48:08 +04:00
|
|
|
((offset >> i) & 0xff) | rot);
|
2010-04-09 22:52:48 +04:00
|
|
|
addr_reg = TCG_REG_R1;
|
2009-07-17 15:48:08 +04:00
|
|
|
offset &= ~(0xff << i);
|
|
|
|
}
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
switch (opc) {
|
|
|
|
case 0:
|
|
|
|
tcg_out_st8_12(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
2012-10-09 23:53:11 +04:00
|
|
|
tcg_out_bswap16st(s, COND_AL, TCG_REG_R0, data_reg);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st16_8(s, COND_AL, TCG_REG_R0, addr_reg, 0);
|
|
|
|
} else {
|
|
|
|
tcg_out_st16_8(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
default:
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_AL, TCG_REG_R0, data_reg);
|
|
|
|
tcg_out_st32_12(s, COND_AL, TCG_REG_R0, addr_reg, 0);
|
|
|
|
} else {
|
|
|
|
tcg_out_st32_12(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-05-25 02:56:51 +04:00
|
|
|
/* TODO: use block store -
|
|
|
|
* check that data_reg2 > data_reg or the other way */
|
2010-04-09 22:52:48 +04:00
|
|
|
if (bswap) {
|
|
|
|
tcg_out_bswap32(s, COND_AL, TCG_REG_R0, data_reg2);
|
|
|
|
tcg_out_st32_12(s, COND_AL, TCG_REG_R0, addr_reg, 0);
|
|
|
|
tcg_out_bswap32(s, COND_AL, TCG_REG_R0, data_reg);
|
|
|
|
tcg_out_st32_12(s, COND_AL, TCG_REG_R0, addr_reg, 4);
|
|
|
|
} else {
|
|
|
|
tcg_out_st32_12(s, COND_AL, data_reg, addr_reg, 0);
|
|
|
|
tcg_out_st32_12(s, COND_AL, data_reg2, addr_reg, 4);
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t *tb_ret_addr;
|
|
|
|
|
2010-03-19 21:12:29 +03:00
|
|
|
static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
2008-05-20 03:59:38 +04:00
|
|
|
const TCGArg *args, const int *const_args)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
switch (opc) {
|
|
|
|
case INDEX_op_exit_tb:
|
2008-12-01 05:17:12 +03:00
|
|
|
{
|
|
|
|
uint8_t *ld_ptr = s->code_ptr;
|
|
|
|
if (args[0] >> 8)
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, TCG_REG_PC, 0);
|
2008-12-01 05:17:12 +03:00
|
|
|
else
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_MOV, TCG_REG_R0, 0, args[0]);
|
2008-12-01 05:17:12 +03:00
|
|
|
tcg_out_goto(s, COND_AL, (tcg_target_ulong) tb_ret_addr);
|
|
|
|
if (args[0] >> 8) {
|
|
|
|
*ld_ptr = (uint8_t) (s->code_ptr - ld_ptr) - 8;
|
|
|
|
tcg_out32(s, args[0]);
|
|
|
|
}
|
|
|
|
}
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_goto_tb:
|
|
|
|
if (s->tb_jmp_offset) {
|
|
|
|
/* Direct jump method */
|
2008-12-01 05:17:12 +03:00
|
|
|
#if defined(USE_DIRECT_JUMP)
|
2008-05-20 03:59:38 +04:00
|
|
|
s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
|
tcg/arm: fix branch target change during code retranslation
QEMU uses code retranslation to restore the CPU state when an exception
happens. For it to work the retranslation must not modify the generated
code. This is what is currently implemented in ARM TCG.
However on CPU that don't have icache/dcache/memory synchronised like
ARM, this requirement is stronger and code retranslation must not modify
the generated code "atomically", as the cache line might be flushed
at any moment (interrupt, exception, task switching), even if not
triggered by QEMU. The probability for this to happen is very low, and
depends on cache size and associativiy, machine load, interrupts, so the
symptoms are might happen randomly.
This requirement is currently not followed in tcg/arm, for the
load/store code, which basically has the following structure:
1) tlb access code is written
2) conditional fast path code is written
3) branch is written with a temporary target
4) slow path code is written
5) branch target is updated
The cache lines corresponding to the retranslated code is not flushed
after code retranslation as the generated code is supposed to be the
same. However if the cache line corresponding to the branch instruction
is flushed between step 3 and 5, and is not flushed again before the
code is executed again, the branch target is wrong. In the guest, the
symptoms are MMU page fault at a random addresses, which leads to
kernel page fault or segmentation faults.
The patch fixes this issue by avoiding writing the branch target until
it is known, that is by writing only the branch instruction first, and
later only the offset.
This fixes booting linux guests on ARM hosts (tested: arm, i386, mips,
mipsel, sh4, sparc).
Acked-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2011-01-07 00:43:13 +03:00
|
|
|
tcg_out_b_noaddr(s, COND_AL);
|
2008-05-20 03:59:38 +04:00
|
|
|
#else
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4);
|
2008-05-20 03:59:38 +04:00
|
|
|
s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
|
|
|
|
tcg_out32(s, 0);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* Indirect jump method */
|
|
|
|
#if 1
|
|
|
|
c = (int) (s->tb_next + args[0]) - ((int) s->code_ptr + 8);
|
|
|
|
if (c > 0xfff || c < -0xfff) {
|
|
|
|
tcg_out_movi32(s, COND_AL, TCG_REG_R0,
|
|
|
|
(tcg_target_long) (s->tb_next + args[0]));
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_R0, 0);
|
2008-05-20 03:59:38 +04:00
|
|
|
} else
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, c);
|
2008-05-20 03:59:38 +04:00
|
|
|
#else
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_R0, TCG_REG_PC, 0);
|
|
|
|
tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_R0, 0);
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out32(s, (tcg_target_long) (s->tb_next + args[0]));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
|
|
|
|
break;
|
|
|
|
case INDEX_op_call:
|
|
|
|
if (const_args[0])
|
2011-03-16 18:21:31 +03:00
|
|
|
tcg_out_call(s, args[0]);
|
2008-05-20 03:59:38 +04:00
|
|
|
else
|
|
|
|
tcg_out_callr(s, COND_AL, args[0]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_br:
|
|
|
|
tcg_out_goto_label(s, COND_AL, args[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEX_op_ld8u_i32:
|
|
|
|
tcg_out_ld8u(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_ld8s_i32:
|
|
|
|
tcg_out_ld8s(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_ld16u_i32:
|
|
|
|
tcg_out_ld16u(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_ld16s_i32:
|
|
|
|
tcg_out_ld16s(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_ld_i32:
|
|
|
|
tcg_out_ld32u(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_st8_i32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st8(s, COND_AL, args[0], args[1], args[2]);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_st16_i32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_st16(s, COND_AL, args[0], args[1], args[2]);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_st_i32:
|
|
|
|
tcg_out_st32(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEX_op_mov_i32:
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV,
|
|
|
|
args[0], 0, args[1], SHIFT_IMM_LSL(0));
|
|
|
|
break;
|
|
|
|
case INDEX_op_movi_i32:
|
|
|
|
tcg_out_movi32(s, COND_AL, args[0], args[1]);
|
|
|
|
break;
|
2012-09-26 22:48:55 +04:00
|
|
|
case INDEX_op_movcond_i32:
|
|
|
|
/* Constraints mean that v2 is always in the same register as dest,
|
|
|
|
* so we only need to do "if condition passed, move v1 to dest".
|
|
|
|
*/
|
|
|
|
tcg_out_dat_rI(s, COND_AL, ARITH_CMP, 0,
|
|
|
|
args[1], args[2], const_args[2]);
|
|
|
|
tcg_out_dat_rI(s, tcg_cond_to_arm_cond[args[5]],
|
|
|
|
ARITH_MOV, args[0], 0, args[3], const_args[3]);
|
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_add_i32:
|
|
|
|
c = ARITH_ADD;
|
|
|
|
goto gen_arith;
|
|
|
|
case INDEX_op_sub_i32:
|
|
|
|
c = ARITH_SUB;
|
|
|
|
goto gen_arith;
|
|
|
|
case INDEX_op_and_i32:
|
2013-03-05 09:36:45 +04:00
|
|
|
tcg_out_dat_rIK(s, COND_AL, ARITH_AND, ARITH_BIC,
|
|
|
|
args[0], args[1], args[2], const_args[2]);
|
|
|
|
break;
|
2010-03-03 02:13:43 +03:00
|
|
|
case INDEX_op_andc_i32:
|
2013-03-05 09:36:45 +04:00
|
|
|
tcg_out_dat_rIK(s, COND_AL, ARITH_BIC, ARITH_AND,
|
|
|
|
args[0], args[1], args[2], const_args[2]);
|
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_or_i32:
|
|
|
|
c = ARITH_ORR;
|
|
|
|
goto gen_arith;
|
|
|
|
case INDEX_op_xor_i32:
|
|
|
|
c = ARITH_EOR;
|
|
|
|
/* Fall through. */
|
|
|
|
gen_arith:
|
2012-09-26 22:48:54 +04:00
|
|
|
tcg_out_dat_rI(s, COND_AL, c, args[0], args[1], args[2], const_args[2]);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_add2_i32:
|
|
|
|
tcg_out_dat_reg2(s, COND_AL, ARITH_ADD, ARITH_ADC,
|
|
|
|
args[0], args[1], args[2], args[3],
|
|
|
|
args[4], args[5], SHIFT_IMM_LSL(0));
|
|
|
|
break;
|
|
|
|
case INDEX_op_sub2_i32:
|
|
|
|
tcg_out_dat_reg2(s, COND_AL, ARITH_SUB, ARITH_SBC,
|
|
|
|
args[0], args[1], args[2], args[3],
|
|
|
|
args[4], args[5], SHIFT_IMM_LSL(0));
|
|
|
|
break;
|
2008-05-20 15:26:40 +04:00
|
|
|
case INDEX_op_neg_i32:
|
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_RSB, args[0], args[1], 0);
|
|
|
|
break;
|
2009-08-22 15:55:06 +04:00
|
|
|
case INDEX_op_not_i32:
|
|
|
|
tcg_out_dat_reg(s, COND_AL,
|
|
|
|
ARITH_MVN, args[0], 0, args[1], SHIFT_IMM_LSL(0));
|
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_mul_i32:
|
|
|
|
tcg_out_mul32(s, COND_AL, args[0], args[1], args[2]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_mulu2_i32:
|
|
|
|
tcg_out_umull32(s, COND_AL, args[0], args[1], args[2], args[3]);
|
|
|
|
break;
|
2013-02-20 11:51:58 +04:00
|
|
|
case INDEX_op_muls2_i32:
|
|
|
|
tcg_out_smull32(s, COND_AL, args[0], args[1], args[2], args[3]);
|
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
/* XXX: Perhaps args[2] & 0x1f is wrong */
|
|
|
|
case INDEX_op_shl_i32:
|
|
|
|
c = const_args[2] ?
|
|
|
|
SHIFT_IMM_LSL(args[2] & 0x1f) : SHIFT_REG_LSL(args[2]);
|
|
|
|
goto gen_shift32;
|
|
|
|
case INDEX_op_shr_i32:
|
|
|
|
c = const_args[2] ? (args[2] & 0x1f) ? SHIFT_IMM_LSR(args[2] & 0x1f) :
|
|
|
|
SHIFT_IMM_LSL(0) : SHIFT_REG_LSR(args[2]);
|
|
|
|
goto gen_shift32;
|
|
|
|
case INDEX_op_sar_i32:
|
|
|
|
c = const_args[2] ? (args[2] & 0x1f) ? SHIFT_IMM_ASR(args[2] & 0x1f) :
|
|
|
|
SHIFT_IMM_LSL(0) : SHIFT_REG_ASR(args[2]);
|
2010-04-09 22:52:48 +04:00
|
|
|
goto gen_shift32;
|
|
|
|
case INDEX_op_rotr_i32:
|
|
|
|
c = const_args[2] ? (args[2] & 0x1f) ? SHIFT_IMM_ROR(args[2] & 0x1f) :
|
|
|
|
SHIFT_IMM_LSL(0) : SHIFT_REG_ROR(args[2]);
|
2008-05-20 03:59:38 +04:00
|
|
|
/* Fall through. */
|
|
|
|
gen_shift32:
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0, args[1], c);
|
|
|
|
break;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
case INDEX_op_rotl_i32:
|
|
|
|
if (const_args[2]) {
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0, args[1],
|
|
|
|
((0x20 - args[2]) & 0x1f) ?
|
|
|
|
SHIFT_IMM_ROR((0x20 - args[2]) & 0x1f) :
|
|
|
|
SHIFT_IMM_LSL(0));
|
|
|
|
} else {
|
|
|
|
tcg_out_dat_imm(s, COND_AL, ARITH_RSB, TCG_REG_R8, args[1], 0x20);
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0, args[1],
|
|
|
|
SHIFT_REG_ROR(TCG_REG_R8));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_brcond_i32:
|
2012-09-26 22:48:54 +04:00
|
|
|
tcg_out_dat_rI(s, COND_AL, ARITH_CMP, 0,
|
|
|
|
args[0], args[1], const_args[1]);
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[2]], args[3]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_brcond2_i32:
|
|
|
|
/* The resulting conditions are:
|
|
|
|
* TCG_COND_EQ --> a0 == a2 && a1 == a3,
|
|
|
|
* TCG_COND_NE --> (a0 != a2 && a1 == a3) || a1 != a3,
|
|
|
|
* TCG_COND_LT(U) --> (a0 < a2 && a1 == a3) || a1 < a3,
|
|
|
|
* TCG_COND_GE(U) --> (a0 >= a2 && a1 == a3) || (a1 >= a3 && a1 != a3),
|
|
|
|
* TCG_COND_LE(U) --> (a0 <= a2 && a1 == a3) || (a1 <= a3 && a1 != a3),
|
|
|
|
* TCG_COND_GT(U) --> (a0 > a2 && a1 == a3) || a1 > a3,
|
|
|
|
*/
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
|
|
|
args[1], args[3], SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
|
|
|
args[0], args[2], SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[4]], args[5]);
|
|
|
|
break;
|
2010-03-02 00:33:48 +03:00
|
|
|
case INDEX_op_setcond_i32:
|
2012-09-26 22:48:54 +04:00
|
|
|
tcg_out_dat_rI(s, COND_AL, ARITH_CMP, 0,
|
|
|
|
args[1], args[2], const_args[2]);
|
2010-03-02 00:33:48 +03:00
|
|
|
tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[3]],
|
|
|
|
ARITH_MOV, args[0], 0, 1);
|
|
|
|
tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[3])],
|
|
|
|
ARITH_MOV, args[0], 0, 0);
|
|
|
|
break;
|
2010-03-02 00:33:49 +03:00
|
|
|
case INDEX_op_setcond2_i32:
|
|
|
|
/* See brcond2_i32 comment */
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0,
|
|
|
|
args[2], args[4], SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0,
|
|
|
|
args[1], args[3], SHIFT_IMM_LSL(0));
|
|
|
|
tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[5]],
|
|
|
|
ARITH_MOV, args[0], 0, 1);
|
|
|
|
tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[5])],
|
|
|
|
ARITH_MOV, args[0], 0, 0);
|
2010-03-03 00:26:04 +03:00
|
|
|
break;
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
case INDEX_op_qemu_ld8u:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 0);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_ld8s:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 0 | 4);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_ld16u:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_ld16s:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 1 | 4);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
2010-03-19 22:00:26 +03:00
|
|
|
case INDEX_op_qemu_ld32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 2);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_ld64:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_ld(s, args, 3);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
2008-05-20 15:26:40 +04:00
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_qemu_st8:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_st(s, args, 0);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_st16:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_st(s, args, 1);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_st32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_st(s, args, 2);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_qemu_st64:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_qemu_st(s, args, 3);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
case INDEX_op_bswap16_i32:
|
|
|
|
tcg_out_bswap16(s, COND_AL, args[0], args[1]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_bswap32_i32:
|
|
|
|
tcg_out_bswap32(s, COND_AL, args[0], args[1]);
|
|
|
|
break;
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
case INDEX_op_ext8s_i32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ext8s(s, COND_AL, args[0], args[1]);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
case INDEX_op_ext16s_i32:
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_out_ext16s(s, COND_AL, args[0], args[1]);
|
|
|
|
break;
|
|
|
|
case INDEX_op_ext16u_i32:
|
|
|
|
tcg_out_ext16u(s, COND_AL, args[0], args[1]);
|
2008-05-20 03:59:38 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
tcg_abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TCGTargetOpDef arm_op_defs[] = {
|
|
|
|
{ INDEX_op_exit_tb, { } },
|
|
|
|
{ INDEX_op_goto_tb, { } },
|
|
|
|
{ INDEX_op_call, { "ri" } },
|
|
|
|
{ INDEX_op_br, { } },
|
|
|
|
|
|
|
|
{ INDEX_op_mov_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_movi_i32, { "r" } },
|
|
|
|
|
|
|
|
{ INDEX_op_ld8u_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_ld8s_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_ld16u_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_ld16s_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_ld_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_st8_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_st16_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_st_i32, { "r", "r" } },
|
|
|
|
|
|
|
|
/* TODO: "r", "r", "ri" */
|
2009-07-18 16:20:30 +04:00
|
|
|
{ INDEX_op_add_i32, { "r", "r", "rI" } },
|
|
|
|
{ INDEX_op_sub_i32, { "r", "r", "rI" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
{ INDEX_op_mul_i32, { "r", "r", "r" } },
|
|
|
|
{ INDEX_op_mulu2_i32, { "r", "r", "r", "r" } },
|
2013-02-20 11:51:58 +04:00
|
|
|
{ INDEX_op_muls2_i32, { "r", "r", "r", "r" } },
|
2013-03-05 09:36:45 +04:00
|
|
|
{ INDEX_op_and_i32, { "r", "r", "rIK" } },
|
|
|
|
{ INDEX_op_andc_i32, { "r", "r", "rIK" } },
|
2009-07-18 16:20:30 +04:00
|
|
|
{ INDEX_op_or_i32, { "r", "r", "rI" } },
|
|
|
|
{ INDEX_op_xor_i32, { "r", "r", "rI" } },
|
2008-05-20 15:26:40 +04:00
|
|
|
{ INDEX_op_neg_i32, { "r", "r" } },
|
2009-08-22 15:55:06 +04:00
|
|
|
{ INDEX_op_not_i32, { "r", "r" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
{ INDEX_op_shl_i32, { "r", "r", "ri" } },
|
|
|
|
{ INDEX_op_shr_i32, { "r", "r", "ri" } },
|
|
|
|
{ INDEX_op_sar_i32, { "r", "r", "ri" } },
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_rotl_i32, { "r", "r", "ri" } },
|
|
|
|
{ INDEX_op_rotr_i32, { "r", "r", "ri" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2010-03-02 00:33:50 +03:00
|
|
|
{ INDEX_op_brcond_i32, { "r", "rI" } },
|
|
|
|
{ INDEX_op_setcond_i32, { "r", "r", "rI" } },
|
2012-09-26 22:48:55 +04:00
|
|
|
{ INDEX_op_movcond_i32, { "r", "r", "rI", "rI", "0" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
/* TODO: "r", "r", "r", "r", "ri", "ri" */
|
|
|
|
{ INDEX_op_add2_i32, { "r", "r", "r", "r", "r", "r" } },
|
|
|
|
{ INDEX_op_sub2_i32, { "r", "r", "r", "r", "r", "r" } },
|
|
|
|
{ INDEX_op_brcond2_i32, { "r", "r", "r", "r" } },
|
2010-03-02 00:33:49 +03:00
|
|
|
{ INDEX_op_setcond2_i32, { "r", "r", "r", "r", "r" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2010-03-20 14:10:20 +03:00
|
|
|
#if TARGET_LONG_BITS == 32
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_qemu_ld8u, { "r", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld8s, { "r", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld16u, { "r", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld16s, { "r", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld32, { "r", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld64, { "L", "L", "l" } },
|
|
|
|
|
|
|
|
{ INDEX_op_qemu_st8, { "s", "s" } },
|
|
|
|
{ INDEX_op_qemu_st16, { "s", "s" } },
|
|
|
|
{ INDEX_op_qemu_st32, { "s", "s" } },
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_qemu_st64, { "S", "S", "s" } },
|
2010-03-20 14:10:20 +03:00
|
|
|
#else
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_qemu_ld8u, { "r", "l", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld8s, { "r", "l", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld16u, { "r", "l", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld16s, { "r", "l", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld32, { "r", "l", "l" } },
|
|
|
|
{ INDEX_op_qemu_ld64, { "L", "L", "l", "l" } },
|
|
|
|
|
|
|
|
{ INDEX_op_qemu_st8, { "s", "s", "s" } },
|
|
|
|
{ INDEX_op_qemu_st16, { "s", "s", "s" } },
|
|
|
|
{ INDEX_op_qemu_st32, { "s", "s", "s" } },
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_qemu_st64, { "S", "S", "s", "s" } },
|
2010-03-20 14:10:20 +03:00
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_bswap16_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_bswap32_i32, { "r", "r" } },
|
|
|
|
|
2008-05-20 03:59:38 +04:00
|
|
|
{ INDEX_op_ext8s_i32, { "r", "r" } },
|
|
|
|
{ INDEX_op_ext16s_i32, { "r", "r" } },
|
2010-04-09 22:52:48 +04:00
|
|
|
{ INDEX_op_ext16u_i32, { "r", "r" } },
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
{ -1 },
|
|
|
|
};
|
|
|
|
|
2010-06-03 04:26:56 +04:00
|
|
|
static void tcg_target_init(TCGContext *s)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
2010-03-12 19:54:58 +03:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2008-05-20 03:59:38 +04:00
|
|
|
/* fail safe */
|
|
|
|
if ((1 << CPU_TLB_ENTRY_BITS) != sizeof(CPUTLBEntry))
|
|
|
|
tcg_abort();
|
2010-03-12 19:54:58 +03:00
|
|
|
#endif
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffff);
|
2008-05-20 03:59:38 +04:00
|
|
|
tcg_regset_set32(tcg_target_call_clobber_regs, 0,
|
2010-04-09 22:52:48 +04:00
|
|
|
(1 << TCG_REG_R0) |
|
|
|
|
(1 << TCG_REG_R1) |
|
|
|
|
(1 << TCG_REG_R2) |
|
|
|
|
(1 << TCG_REG_R3) |
|
|
|
|
(1 << TCG_REG_R12) |
|
|
|
|
(1 << TCG_REG_R14));
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
tcg_regset_clear(s->reserved_regs);
|
|
|
|
tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK);
|
|
|
|
tcg_regset_set_reg(s->reserved_regs, TCG_REG_R8);
|
2010-04-09 22:52:48 +04:00
|
|
|
tcg_regset_set_reg(s->reserved_regs, TCG_REG_PC);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
|
|
|
tcg_add_target_add_op_defs(arm_op_defs);
|
|
|
|
}
|
|
|
|
|
2011-11-09 12:03:34 +04:00
|
|
|
static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg,
|
|
|
|
TCGReg arg1, tcg_target_long arg2)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
tcg_out_ld32u(s, COND_AL, arg, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
2011-11-09 12:03:34 +04:00
|
|
|
static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg,
|
|
|
|
TCGReg arg1, tcg_target_long arg2)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
tcg_out_st32(s, COND_AL, arg, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
2011-11-09 12:03:34 +04:00
|
|
|
static inline void tcg_out_mov(TCGContext *s, TCGType type,
|
|
|
|
TCGReg ret, TCGReg arg)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
tcg_out_dat_reg(s, COND_AL, ARITH_MOV, ret, 0, arg, SHIFT_IMM_LSL(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tcg_out_movi(TCGContext *s, TCGType type,
|
2011-11-09 12:03:34 +04:00
|
|
|
TCGReg ret, tcg_target_long arg)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
|
|
|
tcg_out_movi32(s, COND_AL, ret, arg);
|
|
|
|
}
|
|
|
|
|
2010-06-03 04:26:56 +04:00
|
|
|
static void tcg_target_qemu_prologue(TCGContext *s)
|
2008-05-20 03:59:38 +04:00
|
|
|
{
|
2013-03-13 04:11:40 +04:00
|
|
|
int frame_size;
|
|
|
|
|
|
|
|
/* Calling convention requires us to save r4-r11 and lr. */
|
|
|
|
/* stmdb sp!, { r4 - r11, lr } */
|
|
|
|
tcg_out32(s, (COND_AL << 28) | 0x092d4ff0);
|
2011-05-15 20:03:25 +04:00
|
|
|
|
2013-03-13 04:11:40 +04:00
|
|
|
/* Allocate the local stack frame. */
|
|
|
|
frame_size = TCG_STATIC_CALL_ARGS_SIZE;
|
|
|
|
frame_size += CPU_TEMP_BUF_NLONGS * sizeof(long);
|
|
|
|
/* We saved an odd number of registers above; keep an 8 aligned stack. */
|
|
|
|
frame_size = ((frame_size + TCG_TARGET_STACK_ALIGN - 1)
|
|
|
|
& -TCG_TARGET_STACK_ALIGN) + 4;
|
|
|
|
|
|
|
|
tcg_out_dat_rI(s, COND_AL, ARITH_SUB, TCG_REG_CALL_STACK,
|
|
|
|
TCG_REG_CALL_STACK, frame_size, 1);
|
|
|
|
tcg_set_frame(s, TCG_REG_CALL_STACK, TCG_STATIC_CALL_ARGS_SIZE,
|
|
|
|
CPU_TEMP_BUF_NLONGS * sizeof(long));
|
2010-03-05 10:35:07 +03:00
|
|
|
|
2011-05-15 20:03:25 +04:00
|
|
|
tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
|
2008-05-20 03:59:38 +04:00
|
|
|
|
2011-05-15 20:03:25 +04:00
|
|
|
tcg_out_bx(s, COND_AL, tcg_target_call_iarg_regs[1]);
|
2008-05-20 03:59:38 +04:00
|
|
|
tb_ret_addr = s->code_ptr;
|
|
|
|
|
2013-03-13 04:11:40 +04:00
|
|
|
/* Epilogue. We branch here via tb_ret_addr. */
|
|
|
|
tcg_out_dat_rI(s, COND_AL, ARITH_ADD, TCG_REG_CALL_STACK,
|
|
|
|
TCG_REG_CALL_STACK, frame_size, 1);
|
|
|
|
|
|
|
|
/* ldmia sp!, { r4 - r11, pc } */
|
|
|
|
tcg_out32(s, (COND_AL << 28) | 0x08bd8ff0);
|
2008-05-20 03:59:38 +04:00
|
|
|
}
|