tcg/loongarch64: Implement tcg_target_qemu_prologue
Signed-off-by: WANG Xuerui <git@xen0n.name> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20211221054105.178795-25-git@xen0n.name> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
d3a1727c19
commit
697a598059
@ -968,6 +968,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args)
|
||||
* Entry-points
|
||||
*/
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg args[TCG_MAX_OP_ARGS],
|
||||
const int const_args[TCG_MAX_OP_ARGS])
|
||||
@ -1517,3 +1519,69 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op)
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
static const int tcg_target_callee_save_regs[] = {
|
||||
TCG_REG_S0, /* used for the global env (TCG_AREG0) */
|
||||
TCG_REG_S1,
|
||||
TCG_REG_S2,
|
||||
TCG_REG_S3,
|
||||
TCG_REG_S4,
|
||||
TCG_REG_S5,
|
||||
TCG_REG_S6,
|
||||
TCG_REG_S7,
|
||||
TCG_REG_S8,
|
||||
TCG_REG_S9,
|
||||
TCG_REG_RA, /* should be last for ABI compliance */
|
||||
};
|
||||
|
||||
/* Stack frame parameters. */
|
||||
#define REG_SIZE (TCG_TARGET_REG_BITS / 8)
|
||||
#define SAVE_SIZE ((int)ARRAY_SIZE(tcg_target_callee_save_regs) * REG_SIZE)
|
||||
#define TEMP_SIZE (CPU_TEMP_BUF_NLONGS * (int)sizeof(long))
|
||||
#define FRAME_SIZE ((TCG_STATIC_CALL_ARGS_SIZE + TEMP_SIZE + SAVE_SIZE \
|
||||
+ TCG_TARGET_STACK_ALIGN - 1) \
|
||||
& -TCG_TARGET_STACK_ALIGN)
|
||||
#define SAVE_OFS (TCG_STATIC_CALL_ARGS_SIZE + TEMP_SIZE)
|
||||
|
||||
/* We're expecting to be able to use an immediate for frame allocation. */
|
||||
QEMU_BUILD_BUG_ON(FRAME_SIZE > 0x7ff);
|
||||
|
||||
/* Generate global QEMU prologue and epilogue code */
|
||||
static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
tcg_set_frame(s, TCG_REG_SP, TCG_STATIC_CALL_ARGS_SIZE, TEMP_SIZE);
|
||||
|
||||
/* TB prologue */
|
||||
tcg_out_opc_addi_d(s, TCG_REG_SP, TCG_REG_SP, -FRAME_SIZE);
|
||||
for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {
|
||||
tcg_out_st(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i],
|
||||
TCG_REG_SP, SAVE_OFS + i * REG_SIZE);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
if (USE_GUEST_BASE) {
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base);
|
||||
tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Call generated code */
|
||||
tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
|
||||
tcg_out_opc_jirl(s, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0);
|
||||
|
||||
/* Return path for goto_ptr. Set return value to 0 */
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {
|
||||
tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i],
|
||||
TCG_REG_SP, SAVE_OFS + i * REG_SIZE);
|
||||
}
|
||||
|
||||
tcg_out_opc_addi_d(s, TCG_REG_SP, TCG_REG_SP, FRAME_SIZE);
|
||||
tcg_out_opc_jirl(s, TCG_REG_ZERO, TCG_REG_RA, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user