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    gen_helper_tlb_flush(cpu_env);
32    return true;
33#endif
34    return false;
35}
36
37static bool trans_sfence_w_inval(DisasContext *ctx, arg_sfence_w_inval *a)
38{
39    REQUIRE_SVINVAL(ctx);
40    REQUIRE_EXT(ctx, RVS);
41    /* Do nothing currently */
42    return true;
43}
44
45static bool trans_sfence_inval_ir(DisasContext *ctx, arg_sfence_inval_ir *a)
46{
47    REQUIRE_SVINVAL(ctx);
48    REQUIRE_EXT(ctx, RVS);
49    /* Do nothing currently */
50    return true;
51}
52
53static bool trans_hinval_vvma(DisasContext *ctx, arg_hinval_vvma *a)
54{
55    REQUIRE_SVINVAL(ctx);
56    /* Do the same as hfence.vvma currently */
57    REQUIRE_EXT(ctx, RVH);
58#ifndef CONFIG_USER_ONLY
59    gen_helper_hyp_tlb_flush(cpu_env);
60    return true;
61#endif
62    return false;
63}
64
65static bool trans_hinval_gvma(DisasContext *ctx, arg_hinval_gvma *a)
66{
67    REQUIRE_SVINVAL(ctx);
68    /* Do the same as hfence.gvma currently */
69    REQUIRE_EXT(ctx, RVH);
70#ifndef CONFIG_USER_ONLY
71    gen_helper_hyp_gvma_tlb_flush(cpu_env);
72    return true;
73#endif
74    return false;
75}
76