1/* 2 * RISC-V translation routines for the Zcb Standard Extension. 3 * 4 * Copyright (c) 2021-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_ZCB(ctx) do { \ 20 if (!ctx->cfg_ptr->ext_zcb) \ 21 return false; \ 22} while (0) 23 24static bool trans_c_zext_b(DisasContext *ctx, arg_c_zext_b *a) 25{ 26 REQUIRE_ZCB(ctx); 27 return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext8u_tl); 28} 29 30static bool trans_c_zext_h(DisasContext *ctx, arg_c_zext_h *a) 31{ 32 REQUIRE_ZCB(ctx); 33 REQUIRE_ZBB(ctx); 34 return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl); 35} 36 37static bool trans_c_sext_b(DisasContext *ctx, arg_c_sext_b *a) 38{ 39 REQUIRE_ZCB(ctx); 40 REQUIRE_ZBB(ctx); 41 return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext8s_tl); 42} 43 44static bool trans_c_sext_h(DisasContext *ctx, arg_c_sext_h *a) 45{ 46 REQUIRE_ZCB(ctx); 47 REQUIRE_ZBB(ctx); 48 return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16s_tl); 49} 50 51static bool trans_c_zext_w(DisasContext *ctx, arg_c_zext_w *a) 52{ 53 REQUIRE_64BIT(ctx); 54 REQUIRE_ZCB(ctx); 55 REQUIRE_ZBA(ctx); 56 return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext32u_tl); 57} 58 59static bool trans_c_not(DisasContext *ctx, arg_c_not *a) 60{ 61 REQUIRE_ZCB(ctx); 62 return gen_unary(ctx, a, EXT_NONE, tcg_gen_not_tl); 63} 64 65static bool trans_c_mul(DisasContext *ctx, arg_c_mul *a) 66{ 67 REQUIRE_ZCB(ctx); 68 REQUIRE_M_OR_ZMMUL(ctx); 69 return gen_arith(ctx, a, EXT_NONE, tcg_gen_mul_tl, NULL); 70} 71 72static bool trans_c_lbu(DisasContext *ctx, arg_c_lbu *a) 73{ 74 REQUIRE_ZCB(ctx); 75 return gen_load(ctx, a, MO_UB); 76} 77 78static bool trans_c_lhu(DisasContext *ctx, arg_c_lhu *a) 79{ 80 REQUIRE_ZCB(ctx); 81 return gen_load(ctx, a, MO_UW); 82} 83 84static bool trans_c_lh(DisasContext *ctx, arg_c_lh *a) 85{ 86 REQUIRE_ZCB(ctx); 87 return gen_load(ctx, a, MO_SW); 88} 89 90static bool trans_c_sb(DisasContext *ctx, arg_c_sb *a) 91{ 92 REQUIRE_ZCB(ctx); 93 return gen_store(ctx, a, MO_UB); 94} 95 96static bool trans_c_sh(DisasContext *ctx, arg_c_sh *a) 97{ 98 REQUIRE_ZCB(ctx); 99 return gen_store(ctx, a, MO_UW); 100} 101