1/*
2 * RISC-V translation routines for the Svinval Standard Instruction Set.
3 *
4 * Copyright (c) 2020-2022 PLCT lab
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#define REQUIRE_SVINVAL(ctx) do {          \
20    if (!ctx->cfg_ptr->ext_svinval) {      \
21        return false;                      \
22    }                                      \
23} while (0)
24
25static bool trans_sinval_vma(DisasContext *ctx, arg_sinval_vma *a)
26{
27    REQUIRE_SVINVAL(ctx);
28    /* Do the same as sfence.vma currently */
29    REQUIRE_EXT(ctx, RVS);
30#ifndef CONFIG_USER_ONLY
31    decode_save_opc(ctx);
32    gen_helper_tlb_flush(tcg_env);
33    return true;
34#endif
35    return false;
36}
37
38static bool trans_sfence_w_inval(DisasContext *ctx, arg_sfence_w_inval *a)
39{
40    REQUIRE_SVINVAL(ctx);
41    REQUIRE_EXT(ctx, RVS);
42    /* Do nothing currently */
43    return true;
44}
45
46static bool trans_sfence_inval_ir(DisasContext *ctx, arg_sfence_inval_ir *a)
47{
48    REQUIRE_SVINVAL(ctx);
49    REQUIRE_EXT(ctx, RVS);
50    /* Do nothing currently */
51    return true;
52}
53
54static bool trans_hinval_vvma(DisasContext *ctx, arg_hinval_vvma *a)
55{
56    REQUIRE_SVINVAL(ctx);
57    /* Do the same as hfence.vvma currently */
58    REQUIRE_EXT(ctx, RVH);
59#ifndef CONFIG_USER_ONLY
60    decode_save_opc(ctx);
61    gen_helper_hyp_tlb_flush(tcg_env);
62    return true;
63#endif
64    return false;
65}
66
67static bool trans_hinval_gvma(DisasContext *ctx, arg_hinval_gvma *a)
68{
69    REQUIRE_SVINVAL(ctx);
70    /* Do the same as hfence.gvma currently */
71    REQUIRE_EXT(ctx, RVH);
72#ifndef CONFIG_USER_ONLY
73    decode_save_opc(ctx);
74    gen_helper_hyp_gvma_tlb_flush(tcg_env);
75    return true;
76#endif
77    return false;
78}
79