2020-04-04 00:05:01 +03:00
|
|
|
/*
|
|
|
|
* RISC-V translation routines for the RVXI Base Integer Instruction Set.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Western Digital
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
static void check_access(DisasContext *ctx) {
|
|
|
|
if (!ctx->hlsx) {
|
|
|
|
if (ctx->virt_enabled) {
|
|
|
|
generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT);
|
|
|
|
} else {
|
|
|
|
generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-12 22:13:19 +03:00
|
|
|
static bool trans_hlv_b(DisasContext *ctx, arg_hlv_b *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_SB);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_h(DisasContext *ctx, arg_hlv_h *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TESW);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_w(DisasContext *ctx, arg_hlv_w *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TESL);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_bu(DisasContext *ctx, arg_hlv_bu *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_UB);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_hu(DisasContext *ctx, arg_hlv_hu *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TEUW);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hsv_b(DisasContext *ctx, arg_hsv_b *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv dat = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
gen_get_gpr(dat, a->rs2);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_SB);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(dat);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hsv_h(DisasContext *ctx, arg_hsv_h *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv dat = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
gen_get_gpr(dat, a->rs2);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TESW);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(dat);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hsv_w(DisasContext *ctx, arg_hsv_w *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv dat = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
gen_get_gpr(dat, a->rs2);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TESL);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(dat);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a)
|
|
|
|
{
|
2021-04-24 06:34:12 +03:00
|
|
|
REQUIRE_64BIT(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
REQUIRE_EXT(ctx, RVH);
|
2021-04-24 06:34:12 +03:00
|
|
|
|
2020-08-12 22:13:19 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TEUL);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a)
|
|
|
|
{
|
2021-04-24 06:34:12 +03:00
|
|
|
REQUIRE_64BIT(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
REQUIRE_EXT(ctx, RVH);
|
2021-04-24 06:34:12 +03:00
|
|
|
|
2020-08-12 22:13:19 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TEQ);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a)
|
|
|
|
{
|
2021-04-24 06:34:12 +03:00
|
|
|
REQUIRE_64BIT(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
REQUIRE_EXT(ctx, RVH);
|
2021-04-24 06:34:12 +03:00
|
|
|
|
2020-08-12 22:13:19 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv dat = tcg_temp_new();
|
2020-11-04 07:43:31 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
gen_get_gpr(dat, a->rs2);
|
|
|
|
|
2020-11-04 07:43:31 +03:00
|
|
|
tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK, MO_TEQ);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(dat);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlvx_hu(DisasContext *ctx, arg_hlvx_hu *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:34 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:34 +03:00
|
|
|
gen_helper_hyp_hlvx_hu(t1, cpu_env, t0);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hlvx_wu(DisasContext *ctx, arg_hlvx_wu *a)
|
|
|
|
{
|
|
|
|
REQUIRE_EXT(ctx, RVH);
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
TCGv t0 = tcg_temp_new();
|
|
|
|
TCGv t1 = tcg_temp_new();
|
2020-11-04 07:43:34 +03:00
|
|
|
|
|
|
|
check_access(ctx);
|
2020-08-12 22:13:19 +03:00
|
|
|
|
|
|
|
gen_get_gpr(t0, a->rs1);
|
|
|
|
|
2020-11-04 07:43:34 +03:00
|
|
|
gen_helper_hyp_hlvx_wu(t1, cpu_env, t0);
|
2020-08-12 22:13:19 +03:00
|
|
|
gen_set_gpr(a->rd, t1);
|
|
|
|
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-04 00:05:01 +03:00
|
|
|
static bool trans_hfence_gvma(DisasContext *ctx, arg_sfence_vma *a)
|
|
|
|
{
|
2020-04-04 01:54:59 +03:00
|
|
|
REQUIRE_EXT(ctx, RVH);
|
2020-04-04 00:05:01 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2020-08-12 22:13:49 +03:00
|
|
|
gen_helper_hyp_gvma_tlb_flush(cpu_env);
|
2020-04-04 01:54:59 +03:00
|
|
|
return true;
|
2020-04-04 00:05:01 +03:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool trans_hfence_vvma(DisasContext *ctx, arg_sfence_vma *a)
|
|
|
|
{
|
2020-04-04 01:54:59 +03:00
|
|
|
REQUIRE_EXT(ctx, RVH);
|
2020-04-04 00:05:01 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2020-04-04 01:54:59 +03:00
|
|
|
gen_helper_hyp_tlb_flush(cpu_env);
|
|
|
|
return true;
|
2020-04-04 00:05:01 +03:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|