From nobody Fri May 3 07:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576836766; cv=none; d=zohomail.com; s=zohoarc; b=dNaM14gglEWC7RQxTsXBwng6rQrkUav8Altigf7GDmsgHe6JDM8uieMxVIWrGLG7dpg/oPfTXr/O/VDdtQPpNnDbbaOMqfYDPr0rxKKrrgqWVAalYRovv6Gu6hmmq423/DBssmuci52/3zV8OegBiXfcPqAj6KzJpHmw7FeKf1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576836766; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E2fvXGKvZIaKw6XNjgGVW8uNWcoIXdiuak3bmNRT/Gs=; b=Ul4+RFCMckmcJ8tp2TOeLQQKeyb0YGfLA7/7Zr9JzPYcRMGH4jyy2aJ8pYvkR1TfVQ6BhQbTE3S/VzwtqQYBJAviw4gjQv0xZGWW65CVd37JrBpjs8+mbZrHlylV/W69ts6FQFFdH6/iDHEx6TBXV8RT3rGYY/t8jMKueOjqOLc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157683676628613.971831987831251; Fri, 20 Dec 2019 02:12:46 -0800 (PST) Received: from localhost ([::1]:52644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFH2-00081G-Rj for importer@patchew.org; Fri, 20 Dec 2019 05:12:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33112) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFDd-0003N6-S1 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiFDb-0006ZK-LP for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:13 -0500 Received: from mx2.rt-rk.com ([89.216.37.149]:33317 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiFDb-0006Sg-Be for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id E4CFE1A2206; Fri, 20 Dec 2019 11:09:08 +0100 (CET) Received: from rtrkw774-lin.domain.local (rtrkw774-lin.domain.local [10.10.14.106]) by mail.rt-rk.com (Postfix) with ESMTPSA id C6A2F1A1E2D; Fri, 20 Dec 2019 11:09:08 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com From: Aleksandar Markovic To: qemu-devel@nongnu.org Subject: [PATCH v2 1/4] target/mips: Rectify documentation on deprecating r4k machine Date: Fri, 20 Dec 2019 11:08:48 +0100 Message-Id: <1576836531-2392-2-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.216.37.149 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aleksandar.rikalo@rt-rk.com, Aleksandar Markovic , aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Aleksandar Markovic Change the documented (in file qemu-deprecated.texi) release since r4k machine is deprecated from 4.2 to 5.0. Fixes: d32dc61421b Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Aleksandar Markovic --- qemu-deprecated.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 62680f7..f71c740 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -254,7 +254,7 @@ The 'scsi-disk' device is deprecated. Users should use = 'scsi-hd' or =20 @section System emulator machines =20 -@subsection mips r4k platform (since 4.2) +@subsection mips r4k platform (since 5.0) =20 This machine type is very old and unmaintained. Users should use the 'malt= a' machine type instead. --=20 2.7.4 From nobody Fri May 3 07:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576836665; cv=none; d=zohomail.com; s=zohoarc; b=ZbT6N+WBEse/cGXRIeTkI+88A7r0TaQynKelAnw9FE/S5CrmMSPZWIrSmUypt3vPZ5tj9O2vFWtQQoi7nkdyO/1xPKfUCDX76m/mr6gf+XTpGDuU73UKjutxA6Wy885yLBZBE5w8v/8gtmZT68668PU/kv9+oQJgXOLqEOGxIzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576836665; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=VhTQECwhbid621c0TWo6jHTqY6s2/b+CuPcB0FB/ILY=; b=jxLbTpTmfTR6NDxaxZvev/tjdtq6wilRmcAYjUf9IrtHSWCVB47HZZglQZ5p+jXgJrfnAVw5x5h55PQPtE6SkfXN8EQZRYP9fN114Tr/HTJcbfxOZ9cOM6QZT9KUxW6LyftAQjueKeDlNpqWnQEotbeHv9Cev1QH55S6Wu9nqGw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576836665047911.4066574701667; Fri, 20 Dec 2019 02:11:05 -0800 (PST) Received: from localhost ([::1]:52618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFFO-00054r-Rf for importer@patchew.org; Fri, 20 Dec 2019 05:11:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33174) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFDe-0003NG-4m for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiFDb-0006aP-TL for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:13 -0500 Received: from mx2.rt-rk.com ([89.216.37.149]:33344 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiFDb-0006Tc-FV for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 0BAB81A21FA; Fri, 20 Dec 2019 11:09:09 +0100 (CET) Received: from rtrkw774-lin.domain.local (rtrkw774-lin.domain.local [10.10.14.106]) by mail.rt-rk.com (Postfix) with ESMTPSA id CF5431A20C7; Fri, 20 Dec 2019 11:09:08 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com From: Aleksandar Markovic To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] target/mips: Add support for MIPS<32|64>R6 CRC32 ISA Date: Fri, 20 Dec 2019 11:08:49 +0100 Message-Id: <1576836531-2392-3-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.216.37.149 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aleksandar.rikalo@rt-rk.com, Aleksandar Markovic , aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Aleksandar Markovic Add support for eight CRC-related MIPS<32|64>R6 instructions. Signed-off-by: Aleksandar Markovic --- disas/mips.c | 8 +++ target/mips/helper.h | 2 + target/mips/op_helper.c | 19 ++++++++ target/mips/translate.c | 127 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 156 insertions(+) diff --git a/disas/mips.c b/disas/mips.c index dfefe5e..75c48b3 100644 --- a/disas/mips.c +++ b/disas/mips.c @@ -1409,6 +1409,14 @@ const struct mips_opcode mips_builtin_opcodes[] =3D {"dvp", "t", 0x41600024, 0xffe0ffff, TRAP|WR_t, 0, I= 32R6}, {"evp", "", 0x41600004, 0xffffffff, TRAP, 0, I= 32R6}, {"evp", "t", 0x41600004, 0xffe0ffff, TRAP|WR_t, 0, I= 32R6}, +{"crc32b", "t,v,t", 0x7c00000f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32h", "t,v,t", 0x7c00004f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32w", "t,v,t", 0x7c00008f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32d", "t,v,t", 0x7c0000cf, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 64R6}, +{"crc32cb", "t,v,t", 0x7c00010f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32ch", "t,v,t", 0x7c00014f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32cw", "t,v,t", 0x7c00018f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, +{"crc32cd", "t,v,t", 0x7c0001cf, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 64R6}, =20 /* MSA */ {"sll.b", "+d,+e,+f", 0x7800000d, 0xffe0003f, WR_VD|RD_VS|RD_VT, 0, MSA= }, diff --git a/target/mips/helper.h b/target/mips/helper.h index 7b8ad74..2095330 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -40,6 +40,8 @@ DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(dbitswap, TCG_CALL_NO_RWG_SE, tl, tl) #endif =20 +DEF_HELPER_3(crc32, tl, tl, tl, i32) +DEF_HELPER_3(crc32c, tl, tl, tl, i32) DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) =20 #ifndef CONFIG_USER_ONLY diff --git a/target/mips/op_helper.c b/target/mips/op_helper.c index 18fcee4..5cd396d 100644 --- a/target/mips/op_helper.c +++ b/target/mips/op_helper.c @@ -27,6 +27,8 @@ #include "exec/memop.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" +#include "qemu/crc32c.h" +#include =20 /*************************************************************************= ****/ /* Exceptions processing helpers */ @@ -350,6 +352,23 @@ target_ulong helper_rotx(target_ulong rs, uint32_t shi= ft, uint32_t shiftx, return (int64_t)(int32_t)(uint32_t)tmp5; } =20 +/* these crc32 functions are based on target/arm/helper-a64.c */ +target_ulong helper_crc32(target_ulong val, target_ulong m, uint32_t sz) +{ + uint8_t buf[8]; + + stq_le_p(buf, m); + return (int32_t) (crc32(val ^ 0xffffffff, buf, sz) ^ 0xffffffff); +} + +target_ulong helper_crc32c(target_ulong val, target_ulong m, uint32_t sz) +{ + uint8_t buf[8]; + + stq_le_p(buf, m); + return (int32_t) (crc32c(val, buf, sz) ^ 0xffffffff); +} + #ifndef CONFIG_USER_ONLY =20 static inline hwaddr do_translate_address(CPUMIPSState *env, diff --git a/target/mips/translate.c b/target/mips/translate.c index 4bff585..1b38356 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -451,6 +451,7 @@ enum { OPC_LWE =3D 0x2F | OPC_SPECIAL3, =20 /* R6 */ + OPC_CRC32 =3D 0x0F | OPC_SPECIAL3, R6_OPC_PREF =3D 0x35 | OPC_SPECIAL3, R6_OPC_CACHE =3D 0x25 | OPC_SPECIAL3, R6_OPC_LL =3D 0x36 | OPC_SPECIAL3, @@ -2547,6 +2548,7 @@ typedef struct DisasContext { bool nan2008; bool abs2008; bool saar; + bool crcp; } DisasContext; =20 #define DISAS_STOP DISAS_TARGET_0 @@ -27117,11 +27119,96 @@ static void decode_opc_special2_legacy(CPUMIPSSta= te *env, DisasContext *ctx) } } =20 +static void gen_crc32(DisasContext *ctx, int rd, int rs, int rt, int sz, + int crc32c) +{ + TCGv t0; + TCGv t1; + TCGv_i32 tsz =3D tcg_const_i32(1 << sz); + uint64_t mask =3D 0; + + if (rd =3D=3D 0) { + /* Treat as NOP. */ + return; + } + t0 =3D tcg_temp_new(); + t1 =3D tcg_temp_new(); + + gen_load_gpr(t0, rt); + gen_load_gpr(t1, rs); + + if (sz !=3D 3) { + switch (sz) { + case 0: + mask =3D 0xFF; + break; + case 1: + mask =3D 0xFFFF; + break; + case 2: + mask =3D 0xFFFFFFFF; + break; + } + tcg_gen_andi_tl(t1, t1, mask); + } + + if (crc32c) { + gen_helper_crc32c(cpu_gpr[rd], t0, t1, tsz); + } else { + gen_helper_crc32(cpu_gpr[rd], t0, t1, tsz); + } + + tcg_temp_free(t0); + tcg_temp_free(t1); + tcg_temp_free_i32(tsz); +} + +static void gen_crc32b(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 0, 0); +} + +static void gen_crc32h(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 1, 0); +} + +static void gen_crc32w(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 2, 0); +} + +static void gen_crc32d(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 3, 0); +} + +static void gen_crc32cb(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 0, 1); +} + +static void gen_crc32ch(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 1, 1); +} + +static void gen_crc32cw(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 2, 1); +} + +static void gen_crc32cd(DisasContext *ctx, int rd, int rs, int rt) +{ + gen_crc32(ctx, rd, rs, rt, 3, 1); +} + static void decode_opc_special3_r6(CPUMIPSState *env, DisasContext *ctx) { int rs, rt, rd, sa; uint32_t op1, op2; int16_t imm; + int sz, crc32c; =20 rs =3D (ctx->opcode >> 21) & 0x1f; rt =3D (ctx->opcode >> 16) & 0x1f; @@ -27131,6 +27218,45 @@ static void decode_opc_special3_r6(CPUMIPSState *e= nv, DisasContext *ctx) =20 op1 =3D MASK_SPECIAL3(ctx->opcode); switch (op1) { + case OPC_CRC32: + sz =3D extract32(ctx->opcode, 6, 2); + crc32c =3D extract32(ctx->opcode, 8, 3); + if (unlikely(!ctx->crcp) || + unlikely((sz =3D=3D 3) && (!(ctx->hflags & MIPS_HFLAG_64))) || + unlikely((crc32c >=3D 2))) { + generate_exception_end(ctx, EXCP_RI); + } + switch (sz) { + case 0: + if (crc32c) { + gen_crc32cb(ctx, rt, rs, rt); + } else { + gen_crc32b(ctx, rt, rs, rt); + } + break; + case 1: + if (crc32c) { + gen_crc32ch(ctx, rt, rs, rt); + } else { + gen_crc32h(ctx, rt, rs, rt); + } + break; + case 2: + if (crc32c) { + gen_crc32cw(ctx, rt, rs, rt); + } else { + gen_crc32w(ctx, rt, rs, rt); + } + break; + case 3: + if (crc32c) { + gen_crc32cd(ctx, rt, rs, rt); + } else { + gen_crc32d(ctx, rt, rs, rt); + } + break; + } + break; case R6_OPC_PREF: if (rt >=3D 24) { /* hint codes 24-31 are reserved and signal RI */ @@ -30727,6 +30853,7 @@ static void mips_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->mrp =3D (env->CP0_Config5 >> CP0C5_MRP) & 1; ctx->nan2008 =3D (env->active_fpu.fcr31 >> FCR31_NAN2008) & 1; ctx->abs2008 =3D (env->active_fpu.fcr31 >> FCR31_ABS2008) & 1; + ctx->crcp =3D (env->CP0_Config5 >> CP0C5_CRCP) & 1; restore_cpu_state(env, ctx); #ifdef CONFIG_USER_ONLY ctx->mem_idx =3D MIPS_HFLAG_UM; --=20 2.7.4 From nobody Fri May 3 07:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576836827; cv=none; d=zohomail.com; s=zohoarc; b=KsIqDGIsC/K3PXDQU1yPxvPgOjkdKF0VN1LhB80yHGWZ3SArI9xPCfEOLqn31HnqULSIc0czwttAlW7z9lTOy/JXmift38NxN05iX7wEb1D4/821U7zdnDe1zaiSd9f9NQNwYZvwii4UrbgCoZzRmI+LZWIapA+SRACp58yMWGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576836827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=aDCTpEKsvko4axFzq2eVlLak+P9n9CvQubaBkLULmck=; b=oLfZTnd+Oos4S4tEbvb3vgy+nXpPQtxSQHEHqCHnPR9IPjsuNxz7CcorQYcyomea3Iyv3IHVvyRSaJGcOAWSp0y7F4sroQuyVWtUogR/Fzl+MnAlkD3l1zBBO+vTO21cXQYQqc3GR2tzwwv0hVA541n0I1Z4H339PF6rBaOPuGE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576836827699658.52805061207; Fri, 20 Dec 2019 02:13:47 -0800 (PST) Received: from localhost ([::1]:52660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFI2-0001DF-AW for importer@patchew.org; Fri, 20 Dec 2019 05:13:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33108) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFDd-0003N4-R9 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiFDb-0006aq-Ur for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:13 -0500 Received: from mx2.rt-rk.com ([89.216.37.149]:33368 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiFDb-0006UC-Id for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 18CC71A1E2D; Fri, 20 Dec 2019 11:09:09 +0100 (CET) Received: from rtrkw774-lin.domain.local (rtrkw774-lin.domain.local [10.10.14.106]) by mail.rt-rk.com (Postfix) with ESMTPSA id D80E91A20CD; Fri, 20 Dec 2019 11:09:08 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com From: Aleksandar Markovic To: qemu-devel@nongnu.org Subject: [PATCH v2 3/4] target/mips: Amend CP0 WatchHi register implementation Date: Fri, 20 Dec 2019 11:08:50 +0100 Message-Id: <1576836531-2392-4-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.216.37.149 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aleksandar.rikalo@rt-rk.com, Yongbok Kim , Aleksandar Markovic , aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yongbok Kim WatchHi is extended by the field MemoryMapID with the GINVT instruction. The field is accessible by MTHC0/MFHC0 in 32-bit architectures and DMTC0/ DMFC0 in 64-bit architectures. Signed-off-by: Yongbok Kim Signed-off-by: Aleksandar Markovic --- target/mips/cpu.h | 2 +- target/mips/helper.h | 3 +++ target/mips/machine.c | 6 +++--- target/mips/op_helper.c | 23 +++++++++++++++++++++-- target/mips/translate.c | 42 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index ca00f41..a7e9857 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -961,7 +961,7 @@ struct CPUMIPSState { /* * CP0 Register 19 */ - int32_t CP0_WatchHi[8]; + uint64_t CP0_WatchHi[8]; #define CP0WH_ASID 16 /* * CP0 Register 20 diff --git a/target/mips/helper.h b/target/mips/helper.h index 2095330..032ea8a 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -80,6 +80,7 @@ DEF_HELPER_1(mfc0_maar, tl, env) DEF_HELPER_1(mfhc0_maar, tl, env) DEF_HELPER_2(mfc0_watchlo, tl, env, i32) DEF_HELPER_2(mfc0_watchhi, tl, env, i32) +DEF_HELPER_2(mfhc0_watchhi, tl, env, i32) DEF_HELPER_1(mfc0_debug, tl, env) DEF_HELPER_1(mftc0_debug, tl, env) #ifdef TARGET_MIPS64 @@ -91,6 +92,7 @@ DEF_HELPER_1(dmfc0_tcschefback, tl, env) DEF_HELPER_1(dmfc0_lladdr, tl, env) DEF_HELPER_1(dmfc0_maar, tl, env) DEF_HELPER_2(dmfc0_watchlo, tl, env, i32) +DEF_HELPER_2(dmfc0_watchhi, tl, env, i32) DEF_HELPER_1(dmfc0_saar, tl, env) #endif /* TARGET_MIPS64 */ =20 @@ -161,6 +163,7 @@ DEF_HELPER_2(mthc0_maar, void, env, tl) DEF_HELPER_2(mtc0_maari, void, env, tl) DEF_HELPER_3(mtc0_watchlo, void, env, tl, i32) DEF_HELPER_3(mtc0_watchhi, void, env, tl, i32) +DEF_HELPER_3(mthc0_watchhi, void, env, tl, i32) DEF_HELPER_2(mtc0_xcontext, void, env, tl) DEF_HELPER_2(mtc0_framemask, void, env, tl) DEF_HELPER_2(mtc0_debug, void, env, tl) diff --git a/target/mips/machine.c b/target/mips/machine.c index c139239..8d5b18b 100644 --- a/target/mips/machine.c +++ b/target/mips/machine.c @@ -212,8 +212,8 @@ const VMStateDescription vmstate_tlb =3D { =20 const VMStateDescription vmstate_mips_cpu =3D { .name =3D "cpu", - .version_id =3D 18, - .minimum_version_id =3D 18, + .version_id =3D 19, + .minimum_version_id =3D 19, .post_load =3D cpu_post_load, .fields =3D (VMStateField[]) { /* Active TC */ @@ -296,7 +296,7 @@ const VMStateDescription vmstate_mips_cpu =3D { VMSTATE_INT32(env.CP0_MAARI, MIPSCPU), VMSTATE_UINTTL(env.lladdr, MIPSCPU), VMSTATE_UINTTL_ARRAY(env.CP0_WatchLo, MIPSCPU, 8), - VMSTATE_INT32_ARRAY(env.CP0_WatchHi, MIPSCPU, 8), + VMSTATE_UINT64_ARRAY(env.CP0_WatchHi, MIPSCPU, 8), VMSTATE_UINTTL(env.CP0_XContext, MIPSCPU), VMSTATE_INT32(env.CP0_Framemask, MIPSCPU), VMSTATE_INT32(env.CP0_Debug, MIPSCPU), diff --git a/target/mips/op_helper.c b/target/mips/op_helper.c index 5cd396d..bcff2f9 100644 --- a/target/mips/op_helper.c +++ b/target/mips/op_helper.c @@ -1026,7 +1026,12 @@ target_ulong helper_mfc0_watchlo(CPUMIPSState *env, = uint32_t sel) =20 target_ulong helper_mfc0_watchhi(CPUMIPSState *env, uint32_t sel) { - return env->CP0_WatchHi[sel]; + return (int32_t) env->CP0_WatchHi[sel]; +} + +target_ulong helper_mfhc0_watchhi(CPUMIPSState *env, uint32_t sel) +{ + return env->CP0_WatchHi[sel] >> 32; } =20 target_ulong helper_mfc0_debug(CPUMIPSState *env) @@ -1104,6 +1109,11 @@ target_ulong helper_dmfc0_saar(CPUMIPSState *env) } return 0; } + +target_ulong helper_dmfc0_watchhi(CPUMIPSState *env, uint32_t sel) +{ + return env->CP0_WatchHi[sel]; +} #endif /* TARGET_MIPS64 */ =20 void helper_mtc0_index(CPUMIPSState *env, target_ulong arg1) @@ -1950,11 +1960,20 @@ void helper_mtc0_watchlo(CPUMIPSState *env, target_= ulong arg1, uint32_t sel) =20 void helper_mtc0_watchhi(CPUMIPSState *env, target_ulong arg1, uint32_t se= l) { - int mask =3D 0x40000FF8 | (env->CP0_EntryHi_ASID_mask << CP0WH_ASID); + uint64_t mask =3D 0x40000FF8 | (env->CP0_EntryHi_ASID_mask << CP0WH_AS= ID); + if ((env->CP0_Config5 >> CP0C5_MI) & 1) { + mask |=3D 0xFFFFFFFF00000000ULL; /* MMID */ + } env->CP0_WatchHi[sel] =3D arg1 & mask; env->CP0_WatchHi[sel] &=3D ~(env->CP0_WatchHi[sel] & arg1 & 0x7); } =20 +void helper_mthc0_watchhi(CPUMIPSState *env, target_ulong arg1, uint32_t s= el) +{ + env->CP0_WatchHi[sel] =3D ((uint64_t) (arg1) << 32) | + (env->CP0_WatchHi[sel] & 0x00000000ffffffffULL= ); +} + void helper_mtc0_xcontext(CPUMIPSState *env, target_ulong arg1) { target_ulong mask =3D (1ULL << (env->SEGBITS - 7)) - 1; diff --git a/target/mips/translate.c b/target/mips/translate.c index 1b38356..7cda5c7 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -2549,6 +2549,7 @@ typedef struct DisasContext { bool abs2008; bool saar; bool crcp; + bool mi; } DisasContext; =20 #define DISAS_STOP DISAS_TARGET_0 @@ -6785,6 +6786,25 @@ static void gen_mfhc0(DisasContext *ctx, TCGv arg, i= nt reg, int sel) goto cp0_unimplemented; } break; + case CP0_REGISTER_19: + switch (sel) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* upper 32 bits are only available when Config5MI !=3D 0 */ + CP0_CHECK(ctx->mi); + gen_mfhc0_load64(arg, offsetof(CPUMIPSState, CP0_WatchHi[sel])= , 0); + register_name =3D "WatchHi"; + break; + default: + goto cp0_unimplemented; + } + break; case CP0_REGISTER_28: switch (sel) { case 0: @@ -6871,6 +6891,25 @@ static void gen_mthc0(DisasContext *ctx, TCGv arg, i= nt reg, int sel) goto cp0_unimplemented; } break; + case CP0_REGISTER_19: + switch (sel) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* upper 32 bits are only available when Config5MI !=3D 0 */ + CP0_CHECK(ctx->mi); + gen_helper_0e1i(mthc0_watchhi, arg, sel); + register_name =3D "WatchHi"; + break; + default: + goto cp0_unimplemented; + } + break; case CP0_REGISTER_28: switch (sel) { case 0: @@ -8924,7 +8963,7 @@ static void gen_dmfc0(DisasContext *ctx, TCGv arg, in= t reg, int sel) case CP0_REG19__WATCHHI6: case CP0_REG19__WATCHHI7: CP0_CHECK(ctx->CP0_Config1 & (1 << CP0C1_WR)); - gen_helper_1e0i(mfc0_watchhi, arg, sel); + gen_helper_1e0i(dmfc0_watchhi, arg, sel); register_name =3D "WatchHi"; break; default: @@ -30854,6 +30893,7 @@ static void mips_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->nan2008 =3D (env->active_fpu.fcr31 >> FCR31_NAN2008) & 1; ctx->abs2008 =3D (env->active_fpu.fcr31 >> FCR31_ABS2008) & 1; ctx->crcp =3D (env->CP0_Config5 >> CP0C5_CRCP) & 1; + ctx->mi =3D (env->CP0_Config5 >> CP0C5_MI) & 1; restore_cpu_state(env, ctx); #ifdef CONFIG_USER_ONLY ctx->mem_idx =3D MIPS_HFLAG_UM; --=20 2.7.4 From nobody Fri May 3 07:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576836901; cv=none; d=zohomail.com; s=zohoarc; b=kUilil+lLAogoMc+bm3r6rhhoQnG6mL9nczMBY30pQapmnnrQ8aXnLz3zqqDryBHRhJU7XZDJPRqSEUjr0W/XqNqepYWepoc93H5MI3PQblyzI9f820BZYV8ReiSBktvlJO6JAp81VTozR9T0/wbo7K/6KEuE051FG3XceO48hE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576836901; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=NbGwqPnFGT6zsC4MljN5h+wnIuzgjvFic/5p6et507E=; b=e5fpRL83oTWxTIiJyJTz9+/tnqvN/40bQB20x0JP7gj1uTOQQa8ea9FhdqG68SQVp5tp2qEAIF5tyAmAfO7hrMPhpaXvu53ikwo9lSXbSXOjJwoouil1r9gaWsnZiF3DUtq865wZvPnB+hYkdDZRVA+L8DXAR2Qr81RSeldfXmo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157683690179033.1694148476347; Fri, 20 Dec 2019 02:15:01 -0800 (PST) Received: from localhost ([::1]:52676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFJE-0002dD-LK for importer@patchew.org; Fri, 20 Dec 2019 05:15:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33930) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiFDi-0003SD-0J for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiFDc-0006bY-7n for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:17 -0500 Received: from mx2.rt-rk.com ([89.216.37.149]:33387 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iiFDb-0006UP-JP for qemu-devel@nongnu.org; Fri, 20 Dec 2019 05:09:12 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 265541A20C7; Fri, 20 Dec 2019 11:09:09 +0100 (CET) Received: from rtrkw774-lin.domain.local (rtrkw774-lin.domain.local [10.10.14.106]) by mail.rt-rk.com (Postfix) with ESMTPSA id E07EA1A211E; Fri, 20 Dec 2019 11:09:08 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com From: Aleksandar Markovic To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] target/mips: Add implementation of GINVT instruction Date: Fri, 20 Dec 2019 11:08:51 +0100 Message-Id: <1576836531-2392-5-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1576836531-2392-1-git-send-email-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.216.37.149 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aleksandar.rikalo@rt-rk.com, Yongbok Kim , Aleksandar Markovic , aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yongbok Kim Implement emulation of GINVT instruction. As QEMU doesn't support caches and virtualization, this implementation covers only GINVT (Global Invalidate TLB) instruction among TLB-related instructions. Signed-off-by: Yongbok Kim Signed-off-by: Aleksandar Markovic --- disas/mips.c | 2 + target/mips/cpu.h | 2 +- target/mips/helper.c | 20 ++++++-- target/mips/helper.h | 2 + target/mips/internal.h | 1 + target/mips/op_helper.c | 129 +++++++++++++++++++++++++++++++++++++++++---= ---- target/mips/translate.c | 46 ++++++++++++++++- 7 files changed, 176 insertions(+), 26 deletions(-) diff --git a/disas/mips.c b/disas/mips.c index 75c48b3..cedfbf8 100644 --- a/disas/mips.c +++ b/disas/mips.c @@ -1417,6 +1417,8 @@ const struct mips_opcode mips_builtin_opcodes[] =3D {"crc32ch", "t,v,t", 0x7c00014f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, {"crc32cw", "t,v,t", 0x7c00018f, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 32R6}, {"crc32cd", "t,v,t", 0x7c0001cf, 0xfc00ff3f, WR_d | RD_s | RD_t, 0, I= 64R6}, +{"ginvi", "v", 0x7c00003d, 0xfc1ffcff, TRAP | INSN_TLB, 0, I= 32R6}, +{"ginvt", "v", 0x7c0000bd, 0xfc1ffcff, TRAP | INSN_TLB, 0, I= 32R6}, =20 /* MSA */ {"sll.b", "+d,+e,+f", 0x7800000d, 0xffe0003f, WR_VD|RD_VS|RD_VT, 0, MSA= }, diff --git a/target/mips/cpu.h b/target/mips/cpu.h index a7e9857..fdab989 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -309,7 +309,7 @@ typedef struct mips_def_t mips_def_t; #define CP0_REG04__USERLOCAL 2 #define CP0_REG04__XCONTEXTCONFIG 3 #define CP0_REG04__DBGCONTEXTID 4 -#define CP0_REG00__MMID 5 +#define CP0_REG04__MMID 5 /* CP0 Register 05 */ #define CP0_REG05__PAGEMASK 0 #define CP0_REG05__PAGEGRAIN 1 diff --git a/target/mips/helper.c b/target/mips/helper.c index 781930a..afd78b1 100644 --- a/target/mips/helper.c +++ b/target/mips/helper.c @@ -72,8 +72,13 @@ int r4k_map_address(CPUMIPSState *env, hwaddr *physical,= int *prot, target_ulong address, int rw, int access_type) { uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); + uint32_t tlb_mmid; int i; =20 + MMID =3D mi ? MMID : (uint32_t) ASID; + for (i =3D 0; i < env->tlb->tlb_in_use; i++) { r4k_tlb_t *tlb =3D &env->tlb->mmu.r4k.tlb[i]; /* 1k pages are not supported. */ @@ -84,8 +89,9 @@ int r4k_map_address(CPUMIPSState *env, hwaddr *physical, = int *prot, tag &=3D env->SEGMask; #endif =20 - /* Check ASID, virtual page number & size */ - if ((tlb->G =3D=3D 1 || tlb->ASID =3D=3D ASID) && VPN =3D=3D tag &= & !tlb->EHINV) { + /* Check ASID/MMID, virtual page number & size */ + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + if ((tlb->G =3D=3D 1 || tlb_mmid =3D=3D MMID) && VPN =3D=3D tag &&= !tlb->EHINV) { /* TLB match */ int n =3D !!(address & mask & ~(mask >> 1)); /* Check access rights */ @@ -1418,14 +1424,20 @@ void r4k_invalidate_tlb(CPUMIPSState *env, int idx,= int use_extra) target_ulong addr; target_ulong end; uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); + uint32_t tlb_mmid; target_ulong mask; =20 + MMID =3D mi ? MMID : (uint32_t) ASID; + tlb =3D &env->tlb->mmu.r4k.tlb[idx]; /* - * The qemu TLB is flushed when the ASID changes, so no need to + * The qemu TLB is flushed when the ASID/MMID changes, so no need to * flush these entries again. */ - if (tlb->G =3D=3D 0 && tlb->ASID !=3D ASID) { + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + if (tlb->G =3D=3D 0 && tlb_mmid !=3D MMID) { return; } =20 diff --git a/target/mips/helper.h b/target/mips/helper.h index 032ea8a..acf7b82 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -122,6 +122,7 @@ DEF_HELPER_2(mtc0_tcschefback, void, env, tl) DEF_HELPER_2(mttc0_tcschefback, void, env, tl) DEF_HELPER_2(mtc0_entrylo1, void, env, tl) DEF_HELPER_2(mtc0_context, void, env, tl) +DEF_HELPER_2(mtc0_memorymapid, void, env, tl) DEF_HELPER_2(mtc0_pagemask, void, env, tl) DEF_HELPER_2(mtc0_pagegrain, void, env, tl) DEF_HELPER_2(mtc0_segctl0, void, env, tl) @@ -378,6 +379,7 @@ DEF_HELPER_1(ei, tl, env) DEF_HELPER_1(eret, void, env) DEF_HELPER_1(eretnc, void, env) DEF_HELPER_1(deret, void, env) +DEF_HELPER_3(ginvt, void, env, tl, i32) #endif /* !CONFIG_USER_ONLY */ DEF_HELPER_1(rdhwr_cpunum, tl, env) DEF_HELPER_1(rdhwr_synci_step, tl, env) diff --git a/target/mips/internal.h b/target/mips/internal.h index 3f435b5..df55f84 100644 --- a/target/mips/internal.h +++ b/target/mips/internal.h @@ -95,6 +95,7 @@ struct r4k_tlb_t { target_ulong VPN; uint32_t PageMask; uint16_t ASID; + uint32_t MMID; unsigned int G:1; unsigned int C0:3; unsigned int C1:3; diff --git a/target/mips/op_helper.c b/target/mips/op_helper.c index bcff2f9..a331d9d 100644 --- a/target/mips/op_helper.c +++ b/target/mips/op_helper.c @@ -1470,6 +1470,17 @@ void helper_mtc0_context(CPUMIPSState *env, target_u= long arg1) env->CP0_Context =3D (env->CP0_Context & 0x007FFFFF) | (arg1 & ~0x007F= FFFF); } =20 +void helper_mtc0_memorymapid(CPUMIPSState *env, target_ulong arg1) +{ + int32_t old; + old =3D env->CP0_MemoryMapID; + env->CP0_MemoryMapID =3D (int32_t) arg1; + /* If the MemoryMapID changes, flush qemu's TLB. */ + if (old !=3D env->CP0_MemoryMapID) { + cpu_mips_tlb_flush(env); + } +} + void update_pagemask(CPUMIPSState *env, target_ulong arg1, int32_t *pagema= sk) { uint64_t mask =3D arg1 >> (TARGET_PAGE_BITS + 1); @@ -1906,6 +1917,8 @@ void helper_mtc0_config5(CPUMIPSState *env, target_ul= ong arg1) { env->CP0_Config5 =3D (env->CP0_Config5 & (~env->CP0_Config5_rw_bitmask= )) | (arg1 & env->CP0_Config5_rw_bitmask); + env->CP0_EntryHi_ASID_mask =3D (env->CP0_Config5 & (1 << CP0C5_MI)) ? + 0x0 : (env->CP0_Config4 & (1 << CP0C4_AE)) ? 0x3ff : 0xff; compute_hflags(env); } =20 @@ -2349,6 +2362,7 @@ static void r4k_fill_tlb(CPUMIPSState *env, int idx) tlb->VPN &=3D env->SEGMask; #endif tlb->ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + tlb->MMID =3D env->CP0_MemoryMapID; tlb->PageMask =3D env->CP0_PageMask; tlb->G =3D env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1; tlb->V0 =3D (env->CP0_EntryLo0 & 2) !=3D 0; @@ -2367,13 +2381,18 @@ static void r4k_fill_tlb(CPUMIPSState *env, int idx) =20 void r4k_helper_tlbinv(CPUMIPSState *env) { - int idx; - r4k_tlb_t *tlb; + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + uint32_t tlb_mmid; + r4k_tlb_t *tlb; + int idx; =20 + MMID =3D mi ? MMID : (uint32_t) ASID; for (idx =3D 0; idx < env->tlb->nb_tlb; idx++) { tlb =3D &env->tlb->mmu.r4k.tlb[idx]; - if (!tlb->G && tlb->ASID =3D=3D ASID) { + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + if (!tlb->G && tlb_mmid =3D=3D MMID) { tlb->EHINV =3D 1; } } @@ -2392,11 +2411,16 @@ void r4k_helper_tlbinvf(CPUMIPSState *env) =20 void r4k_helper_tlbwi(CPUMIPSState *env) { - r4k_tlb_t *tlb; - int idx; + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); target_ulong VPN; - uint16_t ASID; + uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + uint32_t tlb_mmid; bool EHINV, G, V0, D0, V1, D1, XI0, XI1, RI0, RI1; + r4k_tlb_t *tlb; + int idx; + + MMID =3D mi ? MMID : (uint32_t) ASID; =20 idx =3D (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb; tlb =3D &env->tlb->mmu.r4k.tlb[idx]; @@ -2404,7 +2428,6 @@ void r4k_helper_tlbwi(CPUMIPSState *env) #if defined(TARGET_MIPS64) VPN &=3D env->SEGMask; #endif - ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; EHINV =3D (env->CP0_EntryHi & (1 << CP0EnHi_EHINV)) !=3D 0; G =3D env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1; V0 =3D (env->CP0_EntryLo0 & 2) !=3D 0; @@ -2416,11 +2439,12 @@ void r4k_helper_tlbwi(CPUMIPSState *env) XI1 =3D (env->CP0_EntryLo1 >> CP0EnLo_XI) &1; RI1 =3D (env->CP0_EntryLo1 >> CP0EnLo_RI) &1; =20 + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; /* * Discard cached TLB entries, unless tlbwi is just upgrading access * permissions on the current entry. */ - if (tlb->VPN !=3D VPN || tlb->ASID !=3D ASID || tlb->G !=3D G || + if (tlb->VPN !=3D VPN || tlb_mmid !=3D MMID || tlb->G !=3D G || (!tlb->EHINV && EHINV) || (tlb->V0 && !V0) || (tlb->D0 && !D0) || (!tlb->XI0 && XI0) || (!tlb->RI0 && RI0) || @@ -2443,14 +2467,17 @@ void r4k_helper_tlbwr(CPUMIPSState *env) =20 void r4k_helper_tlbp(CPUMIPSState *env) { + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); r4k_tlb_t *tlb; target_ulong mask; target_ulong tag; target_ulong VPN; - uint16_t ASID; + uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + uint32_t tlb_mmid; int i; =20 - ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + MMID =3D mi ? MMID : (uint32_t) ASID; for (i =3D 0; i < env->tlb->nb_tlb; i++) { tlb =3D &env->tlb->mmu.r4k.tlb[i]; /* 1k pages are not supported. */ @@ -2460,8 +2487,9 @@ void r4k_helper_tlbp(CPUMIPSState *env) #if defined(TARGET_MIPS64) tag &=3D env->SEGMask; #endif - /* Check ASID, virtual page number & size */ - if ((tlb->G =3D=3D 1 || tlb->ASID =3D=3D ASID) && VPN =3D=3D tag &= & !tlb->EHINV) { + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + /* Check ASID/MMID, virtual page number & size */ + if ((tlb->G =3D=3D 1 || tlb_mmid =3D=3D MMID) && VPN =3D=3D tag &&= !tlb->EHINV) { /* TLB match */ env->CP0_Index =3D i; break; @@ -2478,8 +2506,9 @@ void r4k_helper_tlbp(CPUMIPSState *env) #if defined(TARGET_MIPS64) tag &=3D env->SEGMask; #endif - /* Check ASID, virtual page number & size */ - if ((tlb->G =3D=3D 1 || tlb->ASID =3D=3D ASID) && VPN =3D=3D t= ag) { + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + /* Check ASID/MMID, virtual page number & size */ + if ((tlb->G =3D=3D 1 || tlb_mmid =3D=3D MMID) && VPN =3D=3D ta= g) { r4k_mips_tlb_flush_extra(env, i); break; } @@ -2501,16 +2530,20 @@ static inline uint64_t get_entrylo_pfn_from_tlb(uin= t64_t tlb_pfn) =20 void r4k_helper_tlbr(CPUMIPSState *env) { + bool mi =3D !!((env->CP0_Config5 >> CP0C5_MI) & 1); + uint16_t ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + uint32_t MMID =3D env->CP0_MemoryMapID; + uint32_t tlb_mmid; r4k_tlb_t *tlb; - uint16_t ASID; int idx; =20 - ASID =3D env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask; + MMID =3D mi ? MMID : (uint32_t) ASID; idx =3D (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb; tlb =3D &env->tlb->mmu.r4k.tlb[idx]; =20 - /* If this will change the current ASID, flush qemu's TLB. */ - if (ASID !=3D tlb->ASID) { + tlb_mmid =3D mi ? tlb->MMID : (uint32_t) tlb->ASID; + /* If this will change the current ASID/MMID, flush qemu's TLB. */ + if (MMID !=3D tlb_mmid) { cpu_mips_tlb_flush(env); } =20 @@ -2522,7 +2555,8 @@ void r4k_helper_tlbr(CPUMIPSState *env) env->CP0_EntryLo0 =3D 0; env->CP0_EntryLo1 =3D 0; } else { - env->CP0_EntryHi =3D tlb->VPN | tlb->ASID; + env->CP0_EntryHi =3D mi ? tlb->VPN : tlb->VPN | tlb->ASID; + env->CP0_MemoryMapID =3D tlb->MMID; env->CP0_PageMask =3D tlb->PageMask; env->CP0_EntryLo0 =3D tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) | ((uint64_t)tlb->RI0 << CP0EnLo_RI) | @@ -2565,6 +2599,63 @@ void helper_tlbinvf(CPUMIPSState *env) env->tlb->helper_tlbinvf(env); } =20 +static void global_invalidate_tlb(CPUMIPSState *env, + uint32_t invMsgVPN2, + uint8_t invMsgR, + uint32_t invMsgMMid, + bool invAll, + bool invVAMMid, + bool invMMid, + bool invVA) +{ + + int idx; + r4k_tlb_t *tlb; + bool VAMatch; + bool MMidMatch; + + for (idx =3D 0; idx < env->tlb->nb_tlb; idx++) { + tlb =3D &env->tlb->mmu.r4k.tlb[idx]; + VAMatch =3D + (((tlb->VPN & ~tlb->PageMask) =3D=3D (invMsgVPN2 & ~tlb->PageM= ask)) +#ifdef TARGET_MIPS64 + && + (extract64(env->CP0_EntryHi, 62, 2) =3D=3D invMsgR) +#endif + ); + MMidMatch =3D tlb->MMID =3D=3D invMsgMMid; + if ((invAll && (idx > env->CP0_Wired)) || + (VAMatch && invVAMMid && (tlb->G || MMidMatch)) || + (VAMatch && invVA) || + (MMidMatch && !(tlb->G) && invMMid)) { + tlb->EHINV =3D 1; + } + } + cpu_mips_tlb_flush(env); +} + +void helper_ginvt(CPUMIPSState *env, target_ulong arg, uint32_t type) +{ + bool invAll =3D type =3D=3D 0; + bool invVA =3D type =3D=3D 1; + bool invMMid =3D type =3D=3D 2; + bool invVAMMid =3D type =3D=3D 3; + uint32_t invMsgVPN2 =3D arg & (TARGET_PAGE_MASK << 1); + uint8_t invMsgR =3D 0; + uint32_t invMsgMMid =3D env->CP0_MemoryMapID; + CPUState *other_cs =3D first_cpu; + +#ifdef TARGET_MIPS64 + invMsgR =3D extract64(arg, 62, 2); +#endif + + CPU_FOREACH(other_cs) { + MIPSCPU *other_cpu =3D MIPS_CPU(other_cs); + global_invalidate_tlb(&other_cpu->env, invMsgVPN2, invMsgR, invMsg= MMid, + invAll, invVAMMid, invMMid, invVA); + } +} + /* Specials */ target_ulong helper_di(CPUMIPSState *env) { diff --git a/target/mips/translate.c b/target/mips/translate.c index 7cda5c7..b3c177f 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -388,6 +388,7 @@ enum { OPC_BSHFL =3D 0x20 | OPC_SPECIAL3, OPC_DBSHFL =3D 0x24 | OPC_SPECIAL3, OPC_RDHWR =3D 0x3B | OPC_SPECIAL3, + OPC_GINV =3D 0x3D | OPC_SPECIAL3, =20 /* Loongson 2E */ OPC_MULT_G_2E =3D 0x18 | OPC_SPECIAL3, @@ -2550,6 +2551,7 @@ typedef struct DisasContext { bool saar; bool crcp; bool mi; + int gi; } DisasContext; =20 #define DISAS_STOP DISAS_TARGET_0 @@ -7133,6 +7135,11 @@ static void gen_mfc0(DisasContext *ctx, TCGv arg, in= t reg, int sel) tcg_gen_ext32s_tl(arg, arg); register_name =3D "UserLocal"; break; + case CP0_REG04__MMID: + CP0_CHECK(ctx->mi); + gen_helper_mtc0_memorymapid(cpu_env, arg); + register_name =3D "MMID"; + break; default: goto cp0_unimplemented; } @@ -7873,6 +7880,11 @@ static void gen_mtc0(DisasContext *ctx, TCGv arg, in= t reg, int sel) offsetof(CPUMIPSState, active_tc.CP0_UserLocal)); register_name =3D "UserLocal"; break; + case CP0_REG04__MMID: + CP0_CHECK(ctx->mi); + gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_MemoryMapID)); + register_name =3D "MMID"; + break; default: goto cp0_unimplemented; } @@ -8631,6 +8643,11 @@ static void gen_dmfc0(DisasContext *ctx, TCGv arg, i= nt reg, int sel) offsetof(CPUMIPSState, active_tc.CP0_UserLocal)); register_name =3D "UserLocal"; break; + case CP0_REG04__MMID: + CP0_CHECK(ctx->mi); + gen_helper_mtc0_memorymapid(cpu_env, arg); + register_name =3D "MMID"; + break; default: goto cp0_unimplemented; } @@ -9353,6 +9370,11 @@ static void gen_dmtc0(DisasContext *ctx, TCGv arg, i= nt reg, int sel) offsetof(CPUMIPSState, active_tc.CP0_UserLocal)); register_name =3D "UserLocal"; break; + case CP0_REG04__MMID: + CP0_CHECK(ctx->mi); + gen_mfc0_load32(arg, offsetof(CPUMIPSState, CP0_MemoryMapID)); + register_name =3D "MMID"; + break; default: goto cp0_unimplemented; } @@ -27335,6 +27357,25 @@ static void decode_opc_special3_r6(CPUMIPSState *e= nv, DisasContext *ctx) } } break; +#ifndef CONFIG_USER_ONLY + case OPC_GINV: + if (unlikely(ctx->gi <=3D 1)) { + generate_exception_end(ctx, EXCP_RI); + } + check_cp0_enabled(ctx); + switch ((ctx->opcode >> 6) & 3) { + case 0: /* GINVI */ + /* Treat as NOP. */ + break; + case 2: /* GINVT */ + gen_helper_0e1i(ginvt, cpu_gpr[rs], extract32(ctx->opcode, 8, = 2)); + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; +#endif #if defined(TARGET_MIPS64) case R6_OPC_SCD: gen_st_cond(ctx, rt, rs, imm, MO_TEQ, false); @@ -30894,6 +30935,7 @@ static void mips_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->abs2008 =3D (env->active_fpu.fcr31 >> FCR31_ABS2008) & 1; ctx->crcp =3D (env->CP0_Config5 >> CP0C5_CRCP) & 1; ctx->mi =3D (env->CP0_Config5 >> CP0C5_MI) & 1; + ctx->gi =3D (env->CP0_Config5 >> CP0C5_GI) & 3; restore_cpu_state(env, ctx); #ifdef CONFIG_USER_ONLY ctx->mem_idx =3D MIPS_HFLAG_UM; @@ -31354,8 +31396,8 @@ void cpu_state_reset(CPUMIPSState *env) if (env->CP0_Config3 & (1 << CP0C3_CMGCR)) { env->CP0_CMGCRBase =3D 0x1fbf8000 >> 4; } - env->CP0_EntryHi_ASID_mask =3D (env->CP0_Config4 & (1 << CP0C4_AE)) ? - 0x3ff : 0xff; + env->CP0_EntryHi_ASID_mask =3D (env->CP0_Config5 & (1 << CP0C5_MI)) ? + 0x0 : (env->CP0_Config4 & (1 << CP0C4_AE)) ? 0x3ff : 0xff; env->CP0_Status =3D (1 << CP0St_BEV) | (1 << CP0St_ERL); /* * Vectored interrupts not implemented, timer on int 7, --=20 2.7.4