1*68d19b58SWeiwei Li/* 2*68d19b58SWeiwei Li * RISC-V translation routines for the Zk[nd,ne,nh,sed,sh] Standard Extension. 3*68d19b58SWeiwei Li * 4*68d19b58SWeiwei Li * Copyright (c) 2021 Ruibo Lu, luruibo2000@163.com 5*68d19b58SWeiwei Li * Copyright (c) 2021 Zewen Ye, lustrew@foxmail.com 6*68d19b58SWeiwei Li * 7*68d19b58SWeiwei Li * This program is free software; you can redistribute it and/or modify it 8*68d19b58SWeiwei Li * under the terms and conditions of the GNU General Public License, 9*68d19b58SWeiwei Li * version 2 or later, as published by the Free Software Foundation. 10*68d19b58SWeiwei Li * 11*68d19b58SWeiwei Li * This program is distributed in the hope it will be useful, but WITHOUT 12*68d19b58SWeiwei Li * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*68d19b58SWeiwei Li * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14*68d19b58SWeiwei Li * more details. 15*68d19b58SWeiwei Li * 16*68d19b58SWeiwei Li * You should have received a copy of the GNU General Public License along with 17*68d19b58SWeiwei Li * this program. If not, see <http://www.gnu.org/licenses/>. 18*68d19b58SWeiwei Li */ 19*68d19b58SWeiwei Li 20*68d19b58SWeiwei Li#define REQUIRE_ZKND(ctx) do { \ 21*68d19b58SWeiwei Li if (!ctx->cfg_ptr->ext_zknd) { \ 22*68d19b58SWeiwei Li return false; \ 23*68d19b58SWeiwei Li } \ 24*68d19b58SWeiwei Li} while (0) 25*68d19b58SWeiwei Li 26*68d19b58SWeiwei Li#define REQUIRE_ZKNE(ctx) do { \ 27*68d19b58SWeiwei Li if (!ctx->cfg_ptr->ext_zkne) { \ 28*68d19b58SWeiwei Li return false; \ 29*68d19b58SWeiwei Li } \ 30*68d19b58SWeiwei Li} while (0) 31*68d19b58SWeiwei Li 32*68d19b58SWeiwei Listatic bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a, 33*68d19b58SWeiwei Li void (*func)(TCGv, TCGv, TCGv, TCGv)) 34*68d19b58SWeiwei Li{ 35*68d19b58SWeiwei Li TCGv shamt = tcg_constant_tl(a->shamt); 36*68d19b58SWeiwei Li TCGv dest = dest_gpr(ctx, a->rd); 37*68d19b58SWeiwei Li TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); 38*68d19b58SWeiwei Li TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); 39*68d19b58SWeiwei Li 40*68d19b58SWeiwei Li func(dest, src1, src2, shamt); 41*68d19b58SWeiwei Li gen_set_gpr(ctx, a->rd, dest); 42*68d19b58SWeiwei Li return true; 43*68d19b58SWeiwei Li} 44*68d19b58SWeiwei Li 45*68d19b58SWeiwei Listatic bool trans_aes32esmi(DisasContext *ctx, arg_aes32esmi *a) 46*68d19b58SWeiwei Li{ 47*68d19b58SWeiwei Li REQUIRE_32BIT(ctx); 48*68d19b58SWeiwei Li REQUIRE_ZKNE(ctx); 49*68d19b58SWeiwei Li return gen_aes32_sm4(ctx, a, gen_helper_aes32esmi); 50*68d19b58SWeiwei Li} 51*68d19b58SWeiwei Li 52*68d19b58SWeiwei Listatic bool trans_aes32esi(DisasContext *ctx, arg_aes32esi *a) 53*68d19b58SWeiwei Li{ 54*68d19b58SWeiwei Li REQUIRE_32BIT(ctx); 55*68d19b58SWeiwei Li REQUIRE_ZKNE(ctx); 56*68d19b58SWeiwei Li return gen_aes32_sm4(ctx, a, gen_helper_aes32esi); 57*68d19b58SWeiwei Li} 58*68d19b58SWeiwei Li 59*68d19b58SWeiwei Listatic bool trans_aes32dsmi(DisasContext *ctx, arg_aes32dsmi *a) 60*68d19b58SWeiwei Li{ 61*68d19b58SWeiwei Li REQUIRE_32BIT(ctx); 62*68d19b58SWeiwei Li REQUIRE_ZKND(ctx); 63*68d19b58SWeiwei Li return gen_aes32_sm4(ctx, a, gen_helper_aes32dsmi); 64*68d19b58SWeiwei Li} 65*68d19b58SWeiwei Li 66*68d19b58SWeiwei Listatic bool trans_aes32dsi(DisasContext *ctx, arg_aes32dsi *a) 67*68d19b58SWeiwei Li{ 68*68d19b58SWeiwei Li REQUIRE_32BIT(ctx); 69*68d19b58SWeiwei Li REQUIRE_ZKND(ctx); 70*68d19b58SWeiwei Li return gen_aes32_sm4(ctx, a, gen_helper_aes32dsi); 71*68d19b58SWeiwei Li} 72