| 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 | |
| 25 | /* Test if priv level is M or S. */ |
| 26 | #define REQUIRE_PRIV_MS(ctx) do { \ |
| 27 | if (ctx->priv == PRV_U) { \ |
| 28 | return false; \ |
| 29 | } \ |
| 30 | } while (0) |
| 31 | |
| 32 | static bool trans_sinval_vma(DisasContext *ctx, arg_sinval_vma *a) |
| 33 | { |
| 34 | REQUIRE_SVINVAL(ctx); |
| 35 | /* Do the same as sfence.vma currently */ |
| 36 | REQUIRE_EXT(ctx, RVS); |
| 37 | REQUIRE_PRIV_MS(ctx); |
| 38 | #ifndef CONFIG_USER_ONLY |
| 39 | decode_save_opc(ctx, 0); |
| 40 | gen_helper_tlb_flush(tcg_env); |
| 41 | return true; |
| 42 | #endif |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | static bool trans_sfence_w_inval(DisasContext *ctx, arg_sfence_w_inval *a) |
| 47 | { |
| 48 | REQUIRE_SVINVAL(ctx); |
| 49 | REQUIRE_EXT(ctx, RVS); |
| 50 | REQUIRE_PRIV_MS(ctx); |
| 51 | /* Do nothing currently */ |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | static bool trans_sfence_inval_ir(DisasContext *ctx, arg_sfence_inval_ir *a) |
| 56 | { |
| 57 | REQUIRE_SVINVAL(ctx); |
| 58 | REQUIRE_EXT(ctx, RVS); |
| 59 | REQUIRE_PRIV_MS(ctx); |
| 60 | /* Do nothing currently */ |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | static bool trans_hinval_vvma(DisasContext *ctx, arg_hinval_vvma *a) |
| 65 | { |
| 66 | REQUIRE_SVINVAL(ctx); |
| 67 | /* Do the same as hfence.vvma currently */ |
| 68 | REQUIRE_EXT(ctx, RVH); |
| 69 | REQUIRE_PRIV_MS(ctx); |
| 70 | #ifndef CONFIG_USER_ONLY |
| 71 | decode_save_opc(ctx, 0); |
| 72 | gen_helper_hyp_tlb_flush(tcg_env); |
| 73 | return true; |
| 74 | #endif |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | static bool trans_hinval_gvma(DisasContext *ctx, arg_hinval_gvma *a) |
| 79 | { |
| 80 | REQUIRE_SVINVAL(ctx); |
| 81 | /* Do the same as hfence.gvma currently */ |
| 82 | REQUIRE_EXT(ctx, RVH); |
| 83 | REQUIRE_PRIV_MS(ctx); |
| 84 | #ifndef CONFIG_USER_ONLY |
| 85 | decode_save_opc(ctx, 0); |
| 86 | gen_helper_hyp_gvma_tlb_flush(tcg_env); |
| 87 | return true; |
| 88 | #endif |
| 89 | return false; |
| 90 | } |