From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401591; cv=none; d=zohomail.com; s=zohoarc; b=BRzSsQx1ijwegr4ZTv4UMe/u5UwYoF7uciA71qiQTW3tTgje1NinjzxBFEyjppUQcJbqx5y37iP9m98nhCqJ0wBlZ96Y7w+ynhAm9Dp2T5aQslDTHLVOhGvwgnsDTBWbheJp9du+cvxk1R7/0DFW+c4JunRrmWHK+jXArROYwVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401591; h=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=QPIfZdK+VITWIvg71jeCebUsOkpaEf7hb7i6NUmM97M=; b=O2kkTKKJ8NPsaBqzJpDhmvPcMTqaFRjTIN8CRj7IFArdnZv+Y5niXef//kftXdeosQmcqpeMOVuktHVuwkIpgYOOPHM/q8oooYtxqzG3KCIEjPuDttjqbdHT4k9AxktPVvUQ6vEavgZMp5DUv42KKfo3FCBM3ZlhqUR9gGcxRic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691401591766318.86591885554344; Mon, 7 Aug 2023 02:46:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoA-0006x7-Uq; Mon, 07 Aug 2023 05:45:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo2-0006r7-5M for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:48 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo0-0002u2-GK for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:41 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id D30DF43B70; Mon, 7 Aug 2023 09:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401537; bh=QPIfZdK+VITWIvg71jeCebUsOkpaEf7hb7i6NUmM97M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u6282+ksaFk/MTvVt/plHNm7MS5+YP90g15RkgFHQo7bCWWVlb1Uzrpty5dMHZzGh YxIAMiCinxvovHmtBtuiGa/rXNO8X0NrAYYebKTm5vWgB2xW5rGfw1jiNElqlzVe4P 3XP7uZ5WEg5T+UvwILPNQ07+6QCMQiPgFkoR2uiM= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Song Gao , Xiaojuan Yang Subject: [PATCH v3 1/6] target/loongarch: Add loongarch32 mode for loongarch64-softmmu Date: Mon, 7 Aug 2023 17:45:00 +0800 Message-Id: <20230807094505.2030603-2-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401592494100001 Content-Type: text/plain; charset="utf-8" This commit adds loongarch32 mode to loongarch64-softmmu. Signed-off-by: Jiajie Chen --- target/loongarch/cpu.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index fa371ca8ba..43c73e6363 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -272,9 +272,16 @@ struct LoongArchTLB { }; typedef struct LoongArchTLB LoongArchTLB; =20 +/* Current LoongArch mode */ +typedef enum LoongArchMode { + LA32 =3D 0, + LA64 =3D 1, +} LoongArchMode; + typedef struct CPUArchState { uint64_t gpr[32]; uint64_t pc; + LoongArchMode mode; =20 fpr_t fpr[32]; float_status fp_status; --=20 2.39.2 From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401593; cv=none; d=zohomail.com; s=zohoarc; b=FQqXZkVNAYO84gM/zxqtUm6zNUZH8nRMItvaUbMgY3Cooif7h3hwaG/2iNR3rKFEvjXmqdoYR5Tkdrc5A+8M/gKAyLhb3VU/DMTBthF3bE6AzyLEjvKAFAuBPTn4YpxrosRc16h0eq1zibwb9CChrsWN6BbsbiFhKFB8Ps1DCsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401593; h=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=C0i+nmBhNDiH0s67+9P3xHZ9nUpjop/vjTD6yVAonDc=; b=RdPFT8wjKA6Y7qGAKos/x564bYx6G8XK2udgArP2WmAg9eIni7eZjZqIjtOqdRTkRFKnxzJ+4UtjVTz3evUyBRygIp5zMLbA7Y+DHcqK4hxIermzEeB7Rfa5mnhKShUpPPNdb+C4ojKRJGoD4fAy2bTyB30/LZ0hNJFp+kjflVw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691401593983955.2057548988083; Mon, 7 Aug 2023 02:46:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoB-0006xR-7t; Mon, 07 Aug 2023 05:45:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo6-0006tm-5J for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:48 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo4-0002uN-Go for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:45 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id B7F6443B9B; Mon, 7 Aug 2023 09:45:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401541; bh=C0i+nmBhNDiH0s67+9P3xHZ9nUpjop/vjTD6yVAonDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kkqfkWJemWELzB+SOAB5jzY1PxukXyW/t5pIwWbg/vLkJarUXYBcohPdGdTVJZIdK S8Pp0HFT+hS1Omzq1FJvYBx46mVo3dS6jFOnKP0T9k/tgWxqAuX2uOtH9XPFR/gjoG TzvRqpGbqWYjqM9/tzhzE0mSXJvRQvTkWChYe+mg= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Xiaojuan Yang , Song Gao Subject: [PATCH v3 2/6] target/loongarch: Add loongarch32 cpu la132 Date: Mon, 7 Aug 2023 17:45:01 +0800 Message-Id: <20230807094505.2030603-3-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401595698100001 Content-Type: text/plain; charset="utf-8" Add la132 as a loongarch32 cpu type and allow virt machine to be used with la132 instead of la464. Signed-off-by: Jiajie Chen --- hw/loongarch/virt.c | 5 ----- target/loongarch/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ target/loongarch/cpu.h | 11 +++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index e19b042ce8..af15bf5aaa 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -798,11 +798,6 @@ static void loongarch_init(MachineState *machine) cpu_model =3D LOONGARCH_CPU_TYPE_NAME("la464"); } =20 - if (!strstr(cpu_model, "la464")) { - error_report("LoongArch/TCG needs cpu type la464"); - exit(1); - } - if (ram_size < 1 * GiB) { error_report("ram_size must be greater than 1G."); exit(1); diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index ad93ecac92..d31efe86da 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -362,6 +362,8 @@ static void loongarch_la464_initfn(Object *obj) CPULoongArchState *env =3D &cpu->env; int i; =20 + env->mode =3D LA64; + for (i =3D 0; i < 21; i++) { env->cpucfg[i] =3D 0x0; } @@ -439,6 +441,20 @@ static void loongarch_la464_initfn(Object *obj) env->CSR_ASID =3D FIELD_DP64(0, CSR_ASID, ASIDBITS, 0xa); } =20 +static void loongarch_la132_initfn(Object *obj) +{ + LoongArchCPU *cpu =3D LOONGARCH_CPU(obj); + CPULoongArchState *env =3D &cpu->env; + + env->mode =3D LA32; + + cpu->dtb_compatible =3D "loongarch,Loongson-3C103"; + + uint32_t data =3D 0; + data =3D FIELD_DP32(data, CPUCFG1, ARCH, 1); /* LA32 */ + env->cpucfg[1] =3D data; +} + static void loongarch_cpu_list_entry(gpointer data, gpointer user_data) { const char *typename =3D object_class_get_name(OBJECT_CLASS(data)); @@ -732,6 +748,10 @@ static void loongarch_cpu_class_init(ObjectClass *c, v= oid *data) #endif } =20 +static void loongarch32_cpu_class_init(ObjectClass *c, void *data) +{ +} + #define DEFINE_LOONGARCH_CPU_TYPE(model, initfn) \ { \ .parent =3D TYPE_LOONGARCH_CPU, \ @@ -754,3 +774,24 @@ static const TypeInfo loongarch_cpu_type_infos[] =3D { }; =20 DEFINE_TYPES(loongarch_cpu_type_infos) + +#define DEFINE_LOONGARCH32_CPU_TYPE(model, initfn) \ + { \ + .parent =3D TYPE_LOONGARCH32_CPU, \ + .instance_init =3D initfn, \ + .name =3D LOONGARCH_CPU_TYPE_NAME(model), \ + } + +static const TypeInfo loongarch32_cpu_type_infos[] =3D { + { + .name =3D TYPE_LOONGARCH32_CPU, + .parent =3D TYPE_LOONGARCH_CPU, + .instance_size =3D sizeof(LoongArchCPU), + + .abstract =3D true, + .class_size =3D sizeof(LoongArchCPUClass), + .class_init =3D loongarch32_cpu_class_init, + }, + DEFINE_LOONGARCH32_CPU_TYPE("la132", loongarch_la132_initfn), +}; +DEFINE_TYPES(loongarch32_cpu_type_infos) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index 43c73e6363..f1907cddc5 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -404,6 +404,17 @@ struct LoongArchCPUClass { ResettablePhases parent_phases; }; =20 +#define TYPE_LOONGARCH32_CPU "loongarch32-cpu" +typedef struct LoongArch32CPUClass LoongArch32CPUClass; +DECLARE_CLASS_CHECKERS(LoongArch32CPUClass, LOONGARCH32_CPU, + TYPE_LOONGARCH32_CPU) + +struct LoongArch32CPUClass { + /*< private >*/ + LoongArchCPUClass parent_class; + /*< public >*/ +}; + /* * LoongArch CPUs has 4 privilege levels. * 0 for kernel mode, 3 for user mode. --=20 2.39.2 From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401580; cv=none; d=zohomail.com; s=zohoarc; b=OFGfZqXS41iFbeut5rtoZ3AUuNDGaYkrkWjg1L6hlXKOFziVAcageln6n1lYkS9DJa9xS8xbI8J5+F1hfoZWmVOop82qIa5qqfDtRtTKb27sXf4uDvHCyeRKu0haSy+jK05TRUwc5NzQkx6fj71b3obHt5i43tvmzrwbwfJKdKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401580; h=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=0aopDn3HiqdrGJxkqGFEjZ9YRCd2L4Dg6StwXOZgbSI=; b=cs2qWX4k5R/ZtvkYXHW099sltLNKR+Yjka4k0qIrYwDJgsNP4KYtLirDfZZMBuGz3kd6d2hFzac00vKq68HJEtvYwv84xB0E46l6dOvzXsJ+P5TzrGemx6jkSGzQ0uLJpUOYC6RsdcNOEcGQtJZLjBCBEHNtZ0bWZfDE/Peof6g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691401580856217.43253232951645; Mon, 7 Aug 2023 02:46:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoF-0006yj-4i; Mon, 07 Aug 2023 05:45:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo9-0006wa-I5 for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:49 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwo7-0002um-HP for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:49 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id 8061D43B70; Mon, 7 Aug 2023 09:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401546; bh=0aopDn3HiqdrGJxkqGFEjZ9YRCd2L4Dg6StwXOZgbSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZmP30NbNQX0cSyZfgwPOniwz2tAHwtYGuVsOBQJx9zw3HYDgiUNHjNYErmjhGfF9E ZHWRHzdGEM57wOutxuaqcB7XdqS/pk6HikGKirtK2qy8k1oY6i23TKsxrYoA5R1bue BIkp1PnFNe6/CZe7BBql6/H59SurTSEG5G7Jjf0A= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Xiaojuan Yang , Song Gao , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 3/6] target/loongarch: Add GDB support for loongarch32 mode Date: Mon, 7 Aug 2023 17:45:02 +0800 Message-Id: <20230807094505.2030603-4-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401581507100002 Content-Type: text/plain; charset="utf-8" GPRs and PC are 32-bit wide in loongarch32 mode. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson --- configs/targets/loongarch64-softmmu.mak | 2 +- gdb-xml/loongarch-base32.xml | 45 +++++++++++++++++++++++++ target/loongarch/cpu.c | 10 +++++- target/loongarch/gdbstub.c | 32 ++++++++++++++---- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 gdb-xml/loongarch-base32.xml diff --git a/configs/targets/loongarch64-softmmu.mak b/configs/targets/loon= garch64-softmmu.mak index 9abc99056f..f23780fdd8 100644 --- a/configs/targets/loongarch64-softmmu.mak +++ b/configs/targets/loongarch64-softmmu.mak @@ -1,5 +1,5 @@ TARGET_ARCH=3Dloongarch64 TARGET_BASE_ARCH=3Dloongarch TARGET_SUPPORTS_MTTCG=3Dy -TARGET_XML_FILES=3D gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml +TARGET_XML_FILES=3D gdb-xml/loongarch-base32.xml gdb-xml/loongarch-base64.= xml gdb-xml/loongarch-fpu.xml TARGET_NEED_FDT=3Dy diff --git a/gdb-xml/loongarch-base32.xml b/gdb-xml/loongarch-base32.xml new file mode 100644 index 0000000000..af47bbd3da --- /dev/null +++ b/gdb-xml/loongarch-base32.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index d31efe86da..ee6d45f1b0 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -710,7 +710,13 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = =3D { =20 static gchar *loongarch_gdb_arch_name(CPUState *cs) { - return g_strdup("loongarch64"); + LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); + CPULoongArchState *env =3D &cpu->env; + if (env->mode =3D=3D LA64) { + return g_strdup("loongarch64"); + } else { + return g_strdup("loongarch32"); + } } =20 static void loongarch_cpu_class_init(ObjectClass *c, void *data) @@ -750,6 +756,8 @@ static void loongarch_cpu_class_init(ObjectClass *c, vo= id *data) =20 static void loongarch32_cpu_class_init(ObjectClass *c, void *data) { + CPUClass *cc =3D CPU_CLASS(c); + cc->gdb_core_xml_file =3D "loongarch-base32.xml"; } =20 #define DEFINE_LOONGARCH_CPU_TYPE(model, initfn) \ diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c index 0752fff924..7c82204e92 100644 --- a/target/loongarch/gdbstub.c +++ b/target/loongarch/gdbstub.c @@ -34,16 +34,25 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByte= Array *mem_buf, int n) { LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); CPULoongArchState *env =3D &cpu->env; + uint64_t val; =20 if (0 <=3D n && n < 32) { - return gdb_get_regl(mem_buf, env->gpr[n]); + val =3D env->gpr[n]; } else if (n =3D=3D 32) { /* orig_a0 */ - return gdb_get_regl(mem_buf, 0); + val =3D 0; } else if (n =3D=3D 33) { - return gdb_get_regl(mem_buf, env->pc); + val =3D env->pc; } else if (n =3D=3D 34) { - return gdb_get_regl(mem_buf, env->CSR_BADV); + val =3D env->CSR_BADV; + } + + if (0 <=3D n && n <=3D 34) { + if (env->mode =3D=3D LA64) { + return gdb_get_reg64(mem_buf, val); + } else { + return gdb_get_reg32(mem_buf, val); + } } return 0; } @@ -52,15 +61,24 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint= 8_t *mem_buf, int n) { LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); CPULoongArchState *env =3D &cpu->env; - target_ulong tmp =3D ldtul_p(mem_buf); + target_ulong tmp; + int read_length; int length =3D 0; =20 + if (env->mode =3D=3D LA64) { + tmp =3D ldq_p(mem_buf); + read_length =3D 8; + } else { + tmp =3D ldl_p(mem_buf); + read_length =3D 4; + } + if (0 <=3D n && n < 32) { env->gpr[n] =3D tmp; - length =3D sizeof(target_ulong); + length =3D read_length; } else if (n =3D=3D 33) { env->pc =3D tmp; - length =3D sizeof(target_ulong); + length =3D read_length; } return length; } --=20 2.39.2 From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401580; cv=none; d=zohomail.com; s=zohoarc; b=Jr9wMYDBnB8gtJomriN4QSmHgb8n+qfvvoc5jrhCWE3nE/W2n7kYNPOokgtJYeCrcFEZPW5VQ4LSAd5xd4nZuwh+C//seOUFTuiKBagxpt56BjGHEdDW+qYFVew8MtF9MxE5ujdsiBD6sIsMX1oxQSVFwWjltLU87AVsN0FW6wY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401580; h=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=p1lcZI1A3JPIuJpDoPDAu2Pb5+W1Uq5NYlZYHLFu6CE=; b=H4GwiNDxtMiqfRy1RJWy1bdHWajiCczfrVNWA/MH/KHauTllJfliQol5qG0sQnIc27yV2B+OH10Ma5rMwhozcWpqxbWW4J01FoiYVpwJ65IHlZ/XjLbMN8DaOTwpx522C0qyWvhVYZfnJsSt13vpwbeoEOfWbIyvnEy+vUf9OU0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169140158074231.720129197115853; Mon, 7 Aug 2023 02:46:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoH-0006zA-5L; Mon, 07 Aug 2023 05:45:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoC-0006xe-18 for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:53 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoA-0002uu-FK for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:51 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id 8BC1E43B72; Mon, 7 Aug 2023 09:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401548; bh=p1lcZI1A3JPIuJpDoPDAu2Pb5+W1Uq5NYlZYHLFu6CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IiPmDxuLIgPE32kEzfKVlAuzEFr5Ih5BfHVMsWQ9cVj4hrY4J2H+0a55F6jxhJ1Sb 1Z1hB623N2FaTI3+oZ1CvQUJPrU7Ty7L8Xlg6rwyoUAWXSH/zlaYxtSpbChOKdTYZG OyW73or0rvkQ3oZNr50iHQnd+QwYv7MMeF/GVey8= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Song Gao , Xiaojuan Yang Subject: [PATCH v3 4/6] target/loongarch: Support LoongArch32 TLB entry Date: Mon, 7 Aug 2023 17:45:03 +0800 Message-Id: <20230807094505.2030603-5-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401581498100001 Content-Type: text/plain; charset="utf-8" The TLB entry of LA32 lacks NR, NX and RPLV and they are hardwired to zero in LoongArch32. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson --- target/loongarch/cpu-csr.h | 9 +++++---- target/loongarch/tlb_helper.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h index f8f24032cb..48ed2e0632 100644 --- a/target/loongarch/cpu-csr.h +++ b/target/loongarch/cpu-csr.h @@ -66,10 +66,11 @@ FIELD(TLBENTRY, D, 1, 1) FIELD(TLBENTRY, PLV, 2, 2) FIELD(TLBENTRY, MAT, 4, 2) FIELD(TLBENTRY, G, 6, 1) -FIELD(TLBENTRY, PPN, 12, 36) -FIELD(TLBENTRY, NR, 61, 1) -FIELD(TLBENTRY, NX, 62, 1) -FIELD(TLBENTRY, RPLV, 63, 1) +FIELD(TLBENTRY_32, PPN, 8, 24) +FIELD(TLBENTRY_64, PPN, 12, 36) +FIELD(TLBENTRY_64, NR, 61, 1) +FIELD(TLBENTRY_64, NX, 62, 1) +FIELD(TLBENTRY_64, RPLV, 63, 1) =20 #define LOONGARCH_CSR_ASID 0x18 /* Address space identifier */ FIELD(CSR_ASID, ASID, 0, 10) diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c index 6e00190547..690c6ef25f 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -48,10 +48,17 @@ static int loongarch_map_tlb_entry(CPULoongArchState *e= nv, hwaddr *physical, tlb_v =3D FIELD_EX64(tlb_entry, TLBENTRY, V); tlb_d =3D FIELD_EX64(tlb_entry, TLBENTRY, D); tlb_plv =3D FIELD_EX64(tlb_entry, TLBENTRY, PLV); - tlb_ppn =3D FIELD_EX64(tlb_entry, TLBENTRY, PPN); - tlb_nx =3D FIELD_EX64(tlb_entry, TLBENTRY, NX); - tlb_nr =3D FIELD_EX64(tlb_entry, TLBENTRY, NR); - tlb_rplv =3D FIELD_EX64(tlb_entry, TLBENTRY, RPLV); + if (env->mode =3D=3D LA64) { + tlb_ppn =3D FIELD_EX64(tlb_entry, TLBENTRY_64, PPN); + tlb_nx =3D FIELD_EX64(tlb_entry, TLBENTRY_64, NX); + tlb_nr =3D FIELD_EX64(tlb_entry, TLBENTRY_64, NR); + tlb_rplv =3D FIELD_EX64(tlb_entry, TLBENTRY_64, RPLV); + } else { + tlb_ppn =3D FIELD_EX64(tlb_entry, TLBENTRY_32, PPN); + tlb_nx =3D 0; + tlb_nr =3D 0; + tlb_rplv =3D 0; + } =20 /* Check access rights */ if (!tlb_v) { @@ -79,7 +86,7 @@ static int loongarch_map_tlb_entry(CPULoongArchState *env= , hwaddr *physical, * tlb_entry contains ppn[47:12] while 16KiB ppn is [47:15] * need adjust. */ - *physical =3D (tlb_ppn << R_TLBENTRY_PPN_SHIFT) | + *physical =3D (tlb_ppn << R_TLBENTRY_64_PPN_SHIFT) | (address & MAKE_64BIT_MASK(0, tlb_ps)); *prot =3D PAGE_READ; if (tlb_d) { --=20 2.39.2 From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401601; cv=none; d=zohomail.com; s=zohoarc; b=awJJYqYzHTqg2PGEmGzNqaae/9Nn2KyDP29zTlVdGuhjztxvRw9W6aP7b5NmME6jiVgRgBCpi4V2KF8pwboFpN0cCmin5S16MbHUfjLt1ASsKTZjNhtZ5aGy8W0me9r7QXfXUxftr+zBtll8EV0hPI+RvLTLnzouuJllh2F1Q6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401601; h=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=xZe46J1Wvo9JiWgG9djX20kdj0wbXvYyt688QvGW8I0=; b=ihPHX7ymUeD6cEKmQUyLl+ONUfGNJdtvHH8AM2OjidkCXcqCjJzFmjCkQwgkmaKFvCKKTT94WYpuRVhyT1sc/SsnSmxOp5EstH/lhNXdQmFpN78w1l5H4x+HbXFVvWZawewEqHwJ37WpS9Y5XHTbVSEBJ0fCruUuBB0iguCzJqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691401601819407.7880285713833; Mon, 7 Aug 2023 02:46:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoL-0006zu-6u; Mon, 07 Aug 2023 05:46:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoF-0006yt-GO for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:55 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoC-0002vW-7K for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:53 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id 31D6E43B9B; Mon, 7 Aug 2023 09:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401551; bh=xZe46J1Wvo9JiWgG9djX20kdj0wbXvYyt688QvGW8I0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mzThe6NEQ+XS8oC/w1Z2EZfco1F4qFs/LXUHLCyMHmNDzUhfI0yWBj+CRoORdGKqu H21EPW+/wXgUJu0dc1vVLsOkPo9Q0eSErTq3R+rTAQ90a8tqgp/qbr2QsdtF+jhbxW EloLprg6+FVzLnhOFag4Hxsd1oJVhhXbYx+yqw+A= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Song Gao , Xiaojuan Yang Subject: [PATCH v3 5/6] target/loongarch: Support LoongArch32 DMW Date: Mon, 7 Aug 2023 17:45:04 +0800 Message-Id: <20230807094505.2030603-6-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401602572100001 Content-Type: text/plain; charset="utf-8" LA32 uses a different encoding for CSR.DMW and a new direct mapping mechanism. Signed-off-by: Jiajie Chen --- target/loongarch/cpu-csr.h | 7 +++---- target/loongarch/tlb_helper.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h index 48ed2e0632..b93f99a9ef 100644 --- a/target/loongarch/cpu-csr.h +++ b/target/loongarch/cpu-csr.h @@ -188,10 +188,9 @@ FIELD(CSR_DMW, PLV1, 1, 1) FIELD(CSR_DMW, PLV2, 2, 1) FIELD(CSR_DMW, PLV3, 3, 1) FIELD(CSR_DMW, MAT, 4, 2) -FIELD(CSR_DMW, VSEG, 60, 4) - -#define dmw_va2pa(va) \ - (va & MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS)) +FIELD(CSR_DMW_32, PSEG, 25, 3) +FIELD(CSR_DMW_32, VSEG, 29, 3) +FIELD(CSR_DMW_64, VSEG, 60, 4) =20 /* Debug CSRs */ #define LOONGARCH_CSR_DBG 0x500 /* debug config */ diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c index 690c6ef25f..cf6f5863f9 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -173,6 +173,18 @@ static int loongarch_map_address(CPULoongArchState *en= v, hwaddr *physical, return TLBRET_NOMATCH; } =20 +static hwaddr dmw_va2pa(CPULoongArchState *env, target_ulong va, + target_ulong dmw) +{ + if (env->mode =3D=3D LA64) { + return va & TARGET_PHYS_MASK; + } else { + uint32_t pseg =3D FIELD_EX32(dmw, CSR_DMW_32, PSEG); + return (va & MAKE_64BIT_MASK(0, R_CSR_DMW_32_VSEG_SHIFT)) | \ + (pseg << R_CSR_DMW_32_VSEG_SHIFT); + } +} + static int get_physical_address(CPULoongArchState *env, hwaddr *physical, int *prot, target_ulong address, MMUAccessType access_type, int mmu_idx) @@ -184,6 +196,11 @@ static int get_physical_address(CPULoongArchState *env= , hwaddr *physical, uint8_t da =3D FIELD_EX64(env->CSR_CRMD, CSR_CRMD, DA); uint8_t pg =3D FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PG); =20 + /* Truncate high 32 bits for LA32 */ + if (env->mode =3D=3D LA32) { + address =3D (uint32_t)address; + } + /* Check PG and DA */ if (da & !pg) { *physical =3D address & TARGET_PHYS_MASK; @@ -192,12 +209,20 @@ static int get_physical_address(CPULoongArchState *en= v, hwaddr *physical, } =20 plv =3D kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT); - base_v =3D address >> R_CSR_DMW_VSEG_SHIFT; + if (env->mode =3D=3D LA64) { + base_v =3D address >> R_CSR_DMW_64_VSEG_SHIFT; + } else { + base_v =3D address >> R_CSR_DMW_32_VSEG_SHIFT; + } /* Check direct map window */ for (int i =3D 0; i < 4; i++) { - base_c =3D FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG); + if (env->mode =3D=3D LA64) { + base_c =3D FIELD_EX64(env->CSR_DMW[i], CSR_DMW_64, VSEG); + } else { + base_c =3D FIELD_EX64(env->CSR_DMW[i], CSR_DMW_32, VSEG); + } if ((plv & env->CSR_DMW[i]) && (base_c =3D=3D base_v)) { - *physical =3D dmw_va2pa(address); + *physical =3D dmw_va2pa(env, address, env->CSR_DMW[i]); *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TLBRET_MATCH; } --=20 2.39.2 From nobody Sun May 19 15:20:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=jia.je ARC-Seal: i=1; a=rsa-sha256; t=1691401654; cv=none; d=zohomail.com; s=zohoarc; b=S0xG9ZoaKkcbrdWwPQ/t2Igccn4bXJ9hKhwB87J11q9/+pdzE2T9wJ4m1KIVmNMVX8k1pfepGGwzzobBe4j62FmXOlssFLdkP4lDgE7W08pzdP24XoVsK5tS2iZRYXuGxWSlz6+MgbGQoYPLTIevZPEs2GfMjnlsGAePN4BpOZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691401654; h=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=j97CmVSXAv1Wmklk7StBxxhzd0v7CMEZFColH1yaWPM=; b=asc3DgXJLujx8U4RuTMrBoPwxNaBK5olQXSBUcSsQTYCIsZLeteMyou3L3b0FUaZMINBRMBDPQiADqjMUO94GYfCRMzYklnbOrIMSiBQCrW58MORTdmBPc8bobTEGuC7FaXOQGdr370ATVCSudU3LkYfX9aNwyjPGfZw3jDoqm0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691401654457975.7029222801023; Mon, 7 Aug 2023 02:47:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSwoM-000710-WD; Mon, 07 Aug 2023 05:46:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoG-0006zB-U9 for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:57 -0400 Received: from hognose1.porkbun.com ([35.82.102.206]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSwoF-0002xL-9H for qemu-devel@nongnu.org; Mon, 07 Aug 2023 05:45:56 -0400 Received: from develop.s.cslab.moe (unknown [166.111.226.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: c@jia.je) by hognose1.porkbun.com (Postfix) with ESMTPSA id CE11E43B70; Mon, 7 Aug 2023 09:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jia.je; s=default; t=1691401553; bh=j97CmVSXAv1Wmklk7StBxxhzd0v7CMEZFColH1yaWPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HyCl5pEIpcEejULekpZjMwzCc03El+gPbL1uPUg/OHaOn/JlEgpWxTkKjAloQ4N9S B5gKz/QYm0DzSIQWgEhvINPqLGvv/yFeR547pxhHpSEGzdEesvnrLh/VqV8p3QtTzV ufEo+eVp+teUEZkwAjuD53rxzQ9xA+50y/zQe0KQ= From: Jiajie Chen To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, yijun@loongson.cn, shenjinyang@loongson.cn, Jiajie Chen , Song Gao , Xiaojuan Yang Subject: [PATCH v3 6/6] target/loongarch: Support LoongArch32 VPPN Date: Mon, 7 Aug 2023 17:45:05 +0800 Message-Id: <20230807094505.2030603-7-c@jia.je> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230807094505.2030603-1-c@jia.je> References: <20230807094505.2030603-1-c@jia.je> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=35.82.102.206; envelope-from=c@jia.je; helo=hognose1.porkbun.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jia.je) X-ZM-MESSAGEID: 1691401657586100001 Content-Type: text/plain; charset="utf-8" VPPN of TLBEHI/TLBREHI is limited to 19 bits in LA32. Signed-off-by: Jiajie Chen --- target/loongarch/cpu-csr.h | 6 ++++-- target/loongarch/tlb_helper.c | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h index b93f99a9ef..9501a969af 100644 --- a/target/loongarch/cpu-csr.h +++ b/target/loongarch/cpu-csr.h @@ -57,7 +57,8 @@ FIELD(CSR_TLBIDX, PS, 24, 6) FIELD(CSR_TLBIDX, NE, 31, 1) =20 #define LOONGARCH_CSR_TLBEHI 0x11 /* TLB EntryHi */ -FIELD(CSR_TLBEHI, VPPN, 13, 35) +FIELD(CSR_TLBEHI_32, VPPN, 13, 35) +FIELD(CSR_TLBEHI_64, VPPN, 13, 19) =20 #define LOONGARCH_CSR_TLBELO0 0x12 /* TLB EntryLo0 */ #define LOONGARCH_CSR_TLBELO1 0x13 /* TLB EntryLo1 */ @@ -164,7 +165,8 @@ FIELD(CSR_TLBRERA, PC, 2, 62) #define LOONGARCH_CSR_TLBRELO1 0x8d /* TLB refill entrylo1 */ #define LOONGARCH_CSR_TLBREHI 0x8e /* TLB refill entryhi */ FIELD(CSR_TLBREHI, PS, 0, 6) -FIELD(CSR_TLBREHI, VPPN, 13, 35) +FIELD(CSR_TLBREHI_32, VPPN, 13, 35) +FIELD(CSR_TLBREHI_64, VPPN, 13, 19) #define LOONGARCH_CSR_TLBRPRMD 0x8f /* TLB refill mode info */ FIELD(CSR_TLBRPRMD, PPLV, 0, 2) FIELD(CSR_TLBRPRMD, PIE, 2, 1) diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c index cf6f5863f9..7926c40252 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -305,8 +305,13 @@ static void raise_mmu_exception(CPULoongArchState *env= , target_ulong address, =20 if (tlb_error =3D=3D TLBRET_NOMATCH) { env->CSR_TLBRBADV =3D address; - env->CSR_TLBREHI =3D FIELD_DP64(env->CSR_TLBREHI, CSR_TLBREHI, VPP= N, - extract64(address, 13, 35)); + if (env->mode =3D=3D LA64) { + env->CSR_TLBREHI =3D FIELD_DP64(env->CSR_TLBREHI, CSR_TLBREHI_= 64, + VPPN, extract64(address, 13, 35)); + } else { + env->CSR_TLBREHI =3D FIELD_DP64(env->CSR_TLBREHI, CSR_TLBREHI_= 32, + VPPN, extract64(address, 13, 19)); + } } else { if (!FIELD_EX64(env->CSR_DBG, CSR_DBG, DST)) { env->CSR_BADV =3D address; @@ -371,12 +376,20 @@ static void fill_tlb_entry(CPULoongArchState *env, in= t index) =20 if (FIELD_EX64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR)) { csr_ps =3D FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI, PS); - csr_vppn =3D FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI, VPPN); + if (env->mode =3D=3D LA64) { + csr_vppn =3D FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI_64, VPPN= ); + } else { + csr_vppn =3D FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI_32, VPPN= ); + } lo0 =3D env->CSR_TLBRELO0; lo1 =3D env->CSR_TLBRELO1; } else { csr_ps =3D FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, PS); - csr_vppn =3D FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI, VPPN); + if (env->mode =3D=3D LA64) { + csr_vppn =3D FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI_64, VPPN); + } else { + csr_vppn =3D FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI_32, VPPN); + } lo0 =3D env->CSR_TLBELO0; lo1 =3D env->CSR_TLBELO1; } @@ -496,7 +509,7 @@ void helper_tlbfill(CPULoongArchState *env) =20 if (pagesize =3D=3D stlb_ps) { /* Only write into STLB bits [47:13] */ - address =3D entryhi & ~MAKE_64BIT_MASK(0, R_CSR_TLBEHI_VPPN_SHIFT); + address =3D entryhi & ~MAKE_64BIT_MASK(0, R_CSR_TLBEHI_64_VPPN_SHI= FT); =20 /* Choose one set ramdomly */ set =3D get_random_tlb(0, 7); --=20 2.39.2