Skip to content

Commit efa6937

Browse files
committed
tcg/wasm: Add tcg_target_init function
This commit adds tcg_target_init, aligning it with the Wasm backend's register and stack usage. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
1 parent ee9da47 commit efa6937

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tcg/wasm/tcg-target.c.inc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,3 +2812,32 @@ static int tcg_out_tb_end(TCGContext *s)
28122812

28132813
return 0;
28142814
}
2815+
2816+
static void tcg_target_init(TCGContext *s)
2817+
{
2818+
/* The current code uses uint8_t for tcg operations. */
2819+
tcg_debug_assert(tcg_op_defs_max <= UINT8_MAX);
2820+
2821+
/* Registers available for 32 bit operations. */
2822+
tcg_target_available_regs[TCG_TYPE_I32] = BIT(TCG_TARGET_NB_REGS) - 1;
2823+
/* Registers available for 64 bit operations. */
2824+
tcg_target_available_regs[TCG_TYPE_I64] = BIT(TCG_TARGET_NB_REGS) - 1;
2825+
/*
2826+
* The TCI "registers" are in the local stack frame and
2827+
* cannot be clobbered by the called helper functions. Additionally, Wasm
2828+
* modules for a TB and QEMU itself (i.e. helpers) are separated so also
2829+
* those variables aren't clobbered by the called helper functions.
2830+
* However, the TB assumes a 128-bit return value and assigns to
2831+
* the return value registers.
2832+
*/
2833+
tcg_target_call_clobber_regs =
2834+
MAKE_64BIT_MASK(TCG_REG_R0, 128 / TCG_TARGET_REG_BITS);
2835+
2836+
s->reserved_regs = 0;
2837+
tcg_regset_set_reg(s->reserved_regs, TCG_REG_TMP);
2838+
tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK);
2839+
2840+
/* The call arguments come first, followed by the temp storage. */
2841+
tcg_set_frame(s, TCG_REG_CALL_STACK, TCG_STATIC_CALL_ARGS_SIZE,
2842+
TCG_STATIC_FRAME_SIZE);
2843+
}

0 commit comments

Comments
 (0)