From patchwork Tue Aug 22 07:09:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715680 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117354wrp; Tue, 22 Aug 2023 00:10:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEd8dvGL9zboXLZ1L+smZzTQRyhy62ThcMgzLg1vTa3A+GuSC4xvwWZNcIqfAAax5QwLZnk X-Received: by 2002:a05:620a:4493:b0:76d:9b13:a2f3 with SMTP id x19-20020a05620a449300b0076d9b13a2f3mr11160130qkp.13.1692688253525; Tue, 22 Aug 2023 00:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688253; cv=none; d=google.com; s=arc-20160816; b=neMDkHOysQBw2NC9a41bGOvww+4Oj7DAKrbM19W1GZjep0fkHH+27BzlzlgY0U07wd MlnuP/aZvnPtBAYNuTMysdWRkX1CRf1xjRJhSl/XPTrATccVMlyetIngtCg/mxnjF4k5 Fi4jWVUns0ETyOk102bfh5QEwH71hsLKxIa14TxvDARn1o3OSlRAl6w+vwesxAk6oNyf f7Z0tBpvMzxksCFginPkUv0GLpdntrcDo9ua4lymmmk80PgYprz4t7x2mlVjyeWRYdCT pzPp8q4phs075nZsXv02YrhwjMgHmqo9FJ3q3ao2eZYVNdhoi18uP66djrFuJrSuPVqm oUPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=js7oG4DiRv1a4biKMcFP1KhLlrjkX0Ffo4ofKONC+vY=; fh=ll8wP0pkdoX0Mi1LmYRa/p8XYYNe59YpqNAwTi/SoQ4=; b=iomFAwgqHUSA2OMe6KnJ1yQkb+I7JkkNzTDfDw/VNCW6HRiDh6D+X2J36RijBt6/MS arcrfK2yj2KK1/j8+GG7DaZEqkMY+Lz+kEK9eqkdFiAl370A6p7EmE2Ow6PkPkjwZKsQ uBl5iWFxwrEKN68d4fGNrBL2HgdcxV7SbJ/M/eWDnoKKg6AEJ5ImLyFQumEi+hBKU3Iy 0Tb+WdEGHEQ1bfZKhKSBjfiJzq2rkoJr9C8JkUWGVR2IxtL7Z2CCNd9GCK3uvRnJDr0c y0T9Mqkxe7BCbw8P07811QxxQWM2HNi/lrlUFfFzXqeY0SxwG5jkl0AqXfYT3ON8k9nh y6cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LjnsYBOM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q1-20020a05620a0d8100b007682f9ca13fsi5752022qkl.608.2023.08.22.00.10.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LjnsYBOM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLX6-0002A9-OU; Tue, 22 Aug 2023 03:10:32 -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 1qYLX2-00029l-J4 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:28 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLWz-0001xM-9Z for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:28 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fef3c3277bso12895415e9.1 for ; Tue, 22 Aug 2023 00:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688223; x=1693293023; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=js7oG4DiRv1a4biKMcFP1KhLlrjkX0Ffo4ofKONC+vY=; b=LjnsYBOMiD85mxT9wIojt2PRG2gfGgg0kDhaSIFe2lSZ864NGCiqmXy75QbLpJ/kjS TNheR0/2UlpygiFSRiu+aEHg4Bzb1TQBhCCHgrfhcfiHWyfSz/dInQ0YoBwVky0+VHeT Vc5qcqZw3DSvTGfH1j6yMe1RPpJd2HusuMrCPpbIEBV1THQW4Yhswy++I7+Lls6MWHzk mvBzG3GHOUlngF1rN3Wnd4GBLDVeBDF9FrzZhz5UAxF6sPWoz46X4g1MvrlpcZ5lRQvH yo4G//w/F2T3sYZu3tfcXbT5QYkbGjMJZmy4/46w2AgTZNqnFsZ8bx0VEXW2RnKj9rtK YPWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688223; x=1693293023; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=js7oG4DiRv1a4biKMcFP1KhLlrjkX0Ffo4ofKONC+vY=; b=EsNHivSiEIORkVvR4a8pnIgJB0Zh6ink1uEOMg2ApsbOSEbXB4cyhADdZcqnsI02uI pO/KdD6ZONXwGSJ0VlgqYSP77mOnd6q4xJbpl2ZQaBP6OVdMJ4TXeEVzyTrN2xaQxiza CKXgmLhL/Tbd0IH3arsvWr9cD0bH4BgMIxvafzz4rkCNkw0/oLJc1bqUV2DLOhdGS1vI IHtTbCIh/X3lDc0VpwZCZcix3LfZhc1lfyHT8v/U1qWBzSl9g/ZL/j6wfhncmKwaNg3c 5Q/Ccmt/jsSdw9kg5o9RFu2ORQH/lI2R+k62/NsbovSwnlX/rUOxrA7Z40Rvd4lCzQy7 6Y+w== X-Gm-Message-State: AOJu0YwoLuYePCHAA7ufUtv/EtNhW9rddak1ot1e+IpD4QW9LuXx7ilB dHU9evFrvKQ4HRkWJzMWNpni1+Bd2fheEwSxPyN/eg== X-Received: by 2002:a7b:c4c9:0:b0:3fe:2b8c:9f0b with SMTP id g9-20020a7bc4c9000000b003fe2b8c9f0bmr6543968wmk.23.1692688223599; Tue, 22 Aug 2023 00:10:23 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id u1-20020a7bcb01000000b003fefcbe7fa8sm40904wmj.28.2023.08.22.00.10.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson Subject: [PATCH v5 01/19] target/loongarch: Support LoongArch32 TLB entry Date: Tue, 22 Aug 2023 09:09:54 +0200 Message-ID: <20230822071013.34884-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen 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 Signed-off-by: Song Gao Message-ID: <20230822032724.1353391-2-gaosong@loongson.cn> --- 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) #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..cef10e2257 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -48,10 +48,17 @@ static int loongarch_map_tlb_entry(CPULoongArchState *env, hwaddr *physical, tlb_v = FIELD_EX64(tlb_entry, TLBENTRY, V); tlb_d = FIELD_EX64(tlb_entry, TLBENTRY, D); tlb_plv = FIELD_EX64(tlb_entry, TLBENTRY, PLV); - tlb_ppn = FIELD_EX64(tlb_entry, TLBENTRY, PPN); - tlb_nx = FIELD_EX64(tlb_entry, TLBENTRY, NX); - tlb_nr = FIELD_EX64(tlb_entry, TLBENTRY, NR); - tlb_rplv = FIELD_EX64(tlb_entry, TLBENTRY, RPLV); + if (is_la64(env)) { + tlb_ppn = FIELD_EX64(tlb_entry, TLBENTRY_64, PPN); + tlb_nx = FIELD_EX64(tlb_entry, TLBENTRY_64, NX); + tlb_nr = FIELD_EX64(tlb_entry, TLBENTRY_64, NR); + tlb_rplv = FIELD_EX64(tlb_entry, TLBENTRY_64, RPLV); + } else { + tlb_ppn = FIELD_EX64(tlb_entry, TLBENTRY_32, PPN); + tlb_nx = 0; + tlb_nr = 0; + tlb_rplv = 0; + } /* 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 = (tlb_ppn << R_TLBENTRY_PPN_SHIFT) | + *physical = (tlb_ppn << R_TLBENTRY_64_PPN_SHIFT) | (address & MAKE_64BIT_MASK(0, tlb_ps)); *prot = PAGE_READ; if (tlb_d) { From patchwork Tue Aug 22 07:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715679 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117351wrp; Tue, 22 Aug 2023 00:10:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzg1HLgs45uHgwQuEeHXQNUnytouC7TBvEQWrlEUirMd5VIk6Ya64buqq+MtFy+ZRTUneI X-Received: by 2002:ac8:7f47:0:b0:410:9b3c:e828 with SMTP id g7-20020ac87f47000000b004109b3ce828mr5381958qtk.37.1692688253070; Tue, 22 Aug 2023 00:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688253; cv=none; d=google.com; s=arc-20160816; b=v3BBo0yse4V2pEWtacrPcwOIWX7q3sKh0lB/FH6XhOXN2pGHeQKiFZ64vF7W4hBS3J b3fz16iFDaQkNnavG92oGLcS61kNM6oHAz0opvlkyiyEUa31Q2njeqoMi/p8CwLVFJy9 bgHgR4mC7K8dRe5gHEXyMfBTeKb3uG3KX1oCp77Trk6khh5Uadz6MKXPR1blQqrbcbFH eiPHS//9l7QwvbKjsVpjo9i/LeJW3vBWnzCtDMAxpx6kIRGkL8lQcBxqrk8Aghu0kFNc SLvOtdvLQIPwoP1S+QVNBp/kMU3ooSLzHA/MrHkWihSHceD8RSJLeqb12xnkM9w3/NLf nFzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zxHqKmOyuuNOftyTGwcwCJthKGUr1Tn3UywBr6PkJwE=; fh=ll8wP0pkdoX0Mi1LmYRa/p8XYYNe59YpqNAwTi/SoQ4=; b=S0liejKt//OlXRMExeSM4hwe+Ta9Jq9MARcVrmZ2lMu8EXsbWv0UkKltlVnwVEuoah A3MlehrRdMGRfc5biNIYxshdYn6jW4gNmdo6o4kL26cgePO28jOesa/vx+NxGbxtbiyl VD7odWAyk7/EP9rhgnqYQ+HdBLUhb0Qjp4NJm0b8LyIk40Xc1PxkYVnq0QE7/+P41yix e/UKFgX0+K/N6dVIW9smdJzH/12rjTWfGGdoTYxOYuasmQitrQQJfeieqlVX91xnUQM9 PZApP5CHrBy75enhqbwcwvqVhBAcg3kHjwKA+X7SBrPzMYxPHy/yExtZ+jR7wupKlNaO O+QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=krITlh8T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m15-20020a05622a054f00b004032cc7e439si5693075qtx.471.2023.08.22.00.10.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=krITlh8T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLXC-0002D5-Er; Tue, 22 Aug 2023 03:10:38 -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 1qYLX8-0002CB-IB for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:34 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLX6-0002Cn-3m for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:34 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-317c3ac7339so3651833f8f.0 for ; Tue, 22 Aug 2023 00:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688230; x=1693293030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zxHqKmOyuuNOftyTGwcwCJthKGUr1Tn3UywBr6PkJwE=; b=krITlh8T942g2eMS96hHB/szGA6NVhLUhSRHGN2v0bOeNGKsagALclrPPAoRo1gwto 1nrhaSrIOSieU0B7nZWzmIQsCwxadDVNg6/6lnWuU4SHYqZU3vyJTOBaDo/O0P0cdpiU DnI1EGrFRnwgVn0w4ZfpOfm8D4mvQKMDItL7/TrByBRX8A76YSPG4upsffUtBj4JL/SX DbN4cruT7NJuZoJraUF1r+rUP9JAGJwR8Gb2c9RG/kzDJkFUl6gF2p92LipsH9PDYfS9 N332W2xIIVvl3rmwq9xxCyZZe6n25ukhDS6QhA2Z4hpSs5JgxLXTudee74HgqPeANcqg e8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688230; x=1693293030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zxHqKmOyuuNOftyTGwcwCJthKGUr1Tn3UywBr6PkJwE=; b=ex3lI8iYFcf5PMAQxxRjvMcyzvn4ql/W/JT1jsyTmHoyzFhaA2i3Y+Tjhyvg5SDJFi qiW/4hsDVif7yJm0YMQQj2nUuulslxmyVCZDR8yw2ZVPs10Dy+jinJUgVtx4xEcb22JE aJM1zZPVIDdCiN7dnPDG4w1jQxeSgPi3euJDV9gXZX7Yl/1qBu6qbJ1OAE7y/R0RSNv3 LzStx34Qh3zRNMw8Pc+tXQG9yucEAPCniwPCpxozSi6whP8inChb91j3VB0WSFnH3DwB CA6xIMG38oif5FIK9MH8YFG1CsFvxP6RekxZQQhg6bqO7qatuVXJwO/hdEbfYvqMQkeb lIqA== X-Gm-Message-State: AOJu0YzIVwYRajLnbFMsq88iv6s9gkFz0hnytObuW47W9l2tJdIABA1m o+yoVQ9Kt2Mc7e/rDW0cjRuIFIudrctTGVg3EufbiA== X-Received: by 2002:a5d:5910:0:b0:319:7d83:7ace with SMTP id v16-20020a5d5910000000b003197d837acemr6615919wrd.35.1692688229921; Tue, 22 Aug 2023 00:10:29 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id w14-20020adfec4e000000b003180822cf8fsm15095146wrn.1.2023.08.22.00.10.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson Subject: [PATCH v5 02/19] target/loongarch: Support LoongArch32 DMW Date: Tue, 22 Aug 2023 09:09:55 +0200 Message-ID: <20230822071013.34884-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen LA32 uses a different encoding for CSR.DMW and a new direct mapping mechanism. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Signed-off-by: Song Gao Message-ID: <20230822032724.1353391-3-gaosong@loongson.cn> --- target/loongarch/cpu-csr.h | 7 +++---- target/loongarch/tlb_helper.c | 26 +++++++++++++++++++++++--- 2 files changed, 26 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) /* Debug CSRs */ #define LOONGARCH_CSR_DBG 0x500 /* debug config */ diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c index cef10e2257..1f8e7911c7 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -173,6 +173,18 @@ static int loongarch_map_address(CPULoongArchState *env, hwaddr *physical, return TLBRET_NOMATCH; } +static hwaddr dmw_va2pa(CPULoongArchState *env, target_ulong va, + target_ulong dmw) +{ + if (is_la64(env)) { + return va & TARGET_VIRT_MASK; + } else { + uint32_t pseg = 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) @@ -192,12 +204,20 @@ static int get_physical_address(CPULoongArchState *env, hwaddr *physical, } plv = kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT); - base_v = address >> R_CSR_DMW_VSEG_SHIFT; + if (is_la64(env)) { + base_v = address >> R_CSR_DMW_64_VSEG_SHIFT; + } else { + base_v = address >> R_CSR_DMW_32_VSEG_SHIFT; + } /* Check direct map window */ for (int i = 0; i < 4; i++) { - base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG); + if (is_la64(env)) { + base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW_64, VSEG); + } else { + base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW_32, VSEG); + } if ((plv & env->CSR_DMW[i]) && (base_c == base_v)) { - *physical = dmw_va2pa(address); + *physical = dmw_va2pa(env, address, env->CSR_DMW[i]); *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TLBRET_MATCH; } From patchwork Tue Aug 22 07:09:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715684 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117602wrp; Tue, 22 Aug 2023 00:11:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF59QYt+5/mHC9LtSAOHlll3hJH9sXQBwYEWcCZj/E4KXfrM9QDV2V6sqaBWFmKlbSJT402 X-Received: by 2002:a05:620a:4002:b0:765:404b:b91a with SMTP id h2-20020a05620a400200b00765404bb91amr11839854qko.31.1692688297288; Tue, 22 Aug 2023 00:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688297; cv=none; d=google.com; s=arc-20160816; b=typvhEH7UF4G9O3G3KGC2rovi0DwdlsISxfacSEedvQ2NWOpILzTGwtlutajQHnhpD ZNlHIJ9yraLnsBl4TViMPpIuGTD9YouEtBofiFOkkcPE2RdLvrrs0kUBwsPXdlm/dPba sU2X/gEibOQicxqh21rhbzyWT4/ADCbDUoyfR+88l+LRQlY4lR2KU+FO9EWZXcsoW/NS UN/q49dgVnENN0760QLfg3xOQmx8jXaH4fP0PGZ12g67zBQOJjkrcr1Ztu2mxeATCO78 eMuzmOqBTVJIKHS7pvC1nNcZRjVbn3UgqjWjSDIl4s6tR+VIgRaS33De1CWE6nym5p5e pjcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3rrV84vf0KvDLl6SX1WoOdtWUazfK9wKjoL6Oup5qkU=; fh=ll8wP0pkdoX0Mi1LmYRa/p8XYYNe59YpqNAwTi/SoQ4=; b=lXeUR26gMILW9i/0xRKkmaub4meVdMcBSwPb/gW4K0HqykriBnZMfFWKbNdy/BqBIK 4XAYWM7qdZXBZjuL8GWlpGk2wNJ0b98UUNW5losTicn/ctnWFngrQDe50qMJkoryTwhK B58BBgbHfbq3TUP1ONMdld08xR1xlEWf/CE609q1toRy9RCEy+j99or8/h4rW31skZlg pzkBD6sks/nT17GVwMnH7IBoHi4F8uRV19pshlxLH+TDrxeRzwOJWTB9QA5z3ZET0MKY 77zilSGS+NJIvadbTssxjXgtJzDOoh84XZcjLapANjLkwKIhhxu/0i767zvELcf5xBsR +J1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o0DJEZ3Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id qx1-20020a05620a8b8100b0076ce743152esi5500597qkn.710.2023.08.22.00.11.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o0DJEZ3Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLXG-0002ED-Kb; Tue, 22 Aug 2023 03:10:42 -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 1qYLXE-0002E1-CY for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:40 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXC-0002H0-20 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:40 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3159d5e409dso3251458f8f.0 for ; Tue, 22 Aug 2023 00:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688236; x=1693293036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3rrV84vf0KvDLl6SX1WoOdtWUazfK9wKjoL6Oup5qkU=; b=o0DJEZ3ZbcILe/mUyXV8pLMc89CYUZgNN0pVKfss1GbALAGuDWym5TId9QjU1/6apg 0Wt7e0xoBmX1zg3eWbTgDb5lErKwUuOq2ebySYPcrf8/Sg3+iKIdD5i8jSartWLtam0I KVYM0UyhXG5P0hiUJU+zcx1cXinMK8v9aLEjv7ALMk1bR/a6DTzYwpcEH1yvr35byaSV HyUdGHcZlvY5Ler158XU7XMci1m7OxMTQl87uUGdtRtg9n/+7Q8KHw6NC35AZ8is+xhv 3FuXvtiogxx3K4fTXYWudbufew0EKKhXyAJiVR7atUBS+ZWSEDNTb6dh1JviIhTnqCwu q3Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688236; x=1693293036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3rrV84vf0KvDLl6SX1WoOdtWUazfK9wKjoL6Oup5qkU=; b=h0jLOqqpN5z04MBYaW8IN5RAA5KPiKqHi7h1WjD5TEAr0g/vmusrwj0R3TulVTNQw5 +1faT/WVDc8RCsc8UjYnj9Pr44dM6R/l1bhi6+heecTezY+8I3rTITFRphy+4/Ki+Gog DjBdI5LKkb26l7RqVtP2uJ1IB7RsNgKBn1xin3SRh+Sfa39gsS2XljehhGiLfkDmvqRW aYrNiF88vPbWghddKe8WoE6uIABVmVDOYFzaLKDrnSflPlczaGGXHGQSmOJQCvX65lFL O1fNwKA/UAe29RCgRb5F5pz5O4Ad4jwE4oOxlTuflodP3KkqEfI/g0727xxQFczMuddu uE0Q== X-Gm-Message-State: AOJu0YxQJfa1KM3+DAwzm8IAqpxQZ+Jj4QxxNcy1YK4cxN/t6ofsHH5F eiLHAIc1jJDXNVyY1LF87uLLt0RvuxQwq6a0tfLAfQ== X-Received: by 2002:a5d:50cf:0:b0:316:fc03:3c66 with SMTP id f15-20020a5d50cf000000b00316fc033c66mr9299388wrt.3.1692688236252; Tue, 22 Aug 2023 00:10:36 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id r11-20020a5d4e4b000000b00317b063590fsm14876710wrt.55.2023.08.22.00.10.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson Subject: [PATCH v5 03/19] target/loongarch: Support LoongArch32 VPPN Date: Tue, 22 Aug 2023 09:09:56 +0200 Message-ID: <20230822071013.34884-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen VPPN of TLBEHI/TLBREHI is limited to 19 bits in LA32. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Signed-off-by: Song Gao Message-ID: <20230822032724.1353391-4-gaosong@loongson.cn> --- 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..c59d7a9fcb 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) #define LOONGARCH_CSR_TLBEHI 0x11 /* TLB EntryHi */ -FIELD(CSR_TLBEHI, VPPN, 13, 35) +FIELD(CSR_TLBEHI_32, VPPN, 13, 19) +FIELD(CSR_TLBEHI_64, VPPN, 13, 35) #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, 19) +FIELD(CSR_TLBREHI_64, VPPN, 13, 35) #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 1f8e7911c7..c8b8b0497f 100644 --- a/target/loongarch/tlb_helper.c +++ b/target/loongarch/tlb_helper.c @@ -300,8 +300,13 @@ static void raise_mmu_exception(CPULoongArchState *env, target_ulong address, if (tlb_error == TLBRET_NOMATCH) { env->CSR_TLBRBADV = address; - env->CSR_TLBREHI = FIELD_DP64(env->CSR_TLBREHI, CSR_TLBREHI, VPPN, - extract64(address, 13, 35)); + if (is_la64(env)) { + env->CSR_TLBREHI = FIELD_DP64(env->CSR_TLBREHI, CSR_TLBREHI_64, + VPPN, extract64(address, 13, 35)); + } else { + env->CSR_TLBREHI = 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 = address; @@ -366,12 +371,20 @@ static void fill_tlb_entry(CPULoongArchState *env, int index) if (FIELD_EX64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR)) { csr_ps = FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI, PS); - csr_vppn = FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI, VPPN); + if (is_la64(env)) { + csr_vppn = FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI_64, VPPN); + } else { + csr_vppn = FIELD_EX64(env->CSR_TLBREHI, CSR_TLBREHI_32, VPPN); + } lo0 = env->CSR_TLBRELO0; lo1 = env->CSR_TLBRELO1; } else { csr_ps = FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, PS); - csr_vppn = FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI, VPPN); + if (is_la64(env)) { + csr_vppn = FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI_64, VPPN); + } else { + csr_vppn = FIELD_EX64(env->CSR_TLBEHI, CSR_TLBEHI_32, VPPN); + } lo0 = env->CSR_TLBELO0; lo1 = env->CSR_TLBELO1; } @@ -491,7 +504,7 @@ void helper_tlbfill(CPULoongArchState *env) if (pagesize == stlb_ps) { /* Only write into STLB bits [47:13] */ - address = entryhi & ~MAKE_64BIT_MASK(0, R_CSR_TLBEHI_VPPN_SHIFT); + address = entryhi & ~MAKE_64BIT_MASK(0, R_CSR_TLBEHI_64_VPPN_SHIFT); /* Choose one set ramdomly */ set = get_random_tlb(0, 7); From patchwork Tue Aug 22 07:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715687 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117640wrp; Tue, 22 Aug 2023 00:11:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFibwIClIvwCNTlehOzR15osXp/v3AiDY1Gj5KkPyEA5lptuINv4Mmt1OnGwIvlv7UNr2Es X-Received: by 2002:a05:622a:610:b0:410:6ea4:e017 with SMTP id z16-20020a05622a061000b004106ea4e017mr10279145qta.54.1692688307183; Tue, 22 Aug 2023 00:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688307; cv=none; d=google.com; s=arc-20160816; b=kf9yUEUF3dcTd6qwmHKv/UzW4dk+u/htzrJapxexP5aG1pJZBx5qlEpAyvS6VK1XUB JVZrbaCxw9M+GSucWne8Fsz5ukNw/Tk2HX4x9u72KpEuTQop3uHAA4C/8ifwo3UaMeNE QEr0Y5R43TbJuDqqrGvreqi97c6kFaRBNmXvM7JafrAYLZ6V3SXLYRFFtdFqErFH1ubE XpzP5bG4THol1I4HM6QC4AStJM83Hnb85OJM1DHoeM+7s1xdZRZ0QnwZjW01cgeyK0BS l6FFIvFABu8ohh6BGpJB8UX7CWu6roCQDoIY273jootTlE3RmVyqFsEnF93bvysFhuvk 5OyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0lC9gMe2kWPLwbVJidGFgIBdYr23SH/S3e9rEjZW5mo=; fh=ll8wP0pkdoX0Mi1LmYRa/p8XYYNe59YpqNAwTi/SoQ4=; b=YqHWhte5epOIg2g80J5Kf3fkmDVN0ZQ7E1azQD+dSYkqOVkvPjI+4UU7ls77mtxRGP 3tXEP6PbxWsOGGIDSrtSowDsyCmAvZB9M4iF9pJYufIm6IxVo9P8Em4bCd5/BW7B/UNR PBV3US989+VJusvCGI7zBK02pyY/m34djsu3fW+rQnmgQgX2zOrfbOtqSQtdRF0wdnkp aUE5xSMrQV4psUgY067hEcPPuG2AUDazH109PTkeL0CuyEbpxwykTDW8C7mZAlNwCf+n 6cJ6O31CX2/K+vF3PkEX4zkaeDd83vlcic9jxRf+yOYUX9MH/d7D8g0UPOFfwvE2w7Vu NHOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p+kn9Gaf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c1-20020ac87d81000000b004039b1cb698si897182qtd.554.2023.08.22.00.11.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p+kn9Gaf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLXM-0002F6-7m; Tue, 22 Aug 2023 03:10:48 -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 1qYLXK-0002El-VV for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:46 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXI-0002KG-JO for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:46 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31781e15a0cso3748876f8f.3 for ; Tue, 22 Aug 2023 00:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688242; x=1693293042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0lC9gMe2kWPLwbVJidGFgIBdYr23SH/S3e9rEjZW5mo=; b=p+kn9GafdB0xXa1Dw7rRxlicImYgfLyC3uKKpmu0F1cJ2kKYn7xgNXWUGF6dPyk75W rSsjW18lVP/L8haPnegDJofBjPrcKmxXUEiuaJdOrEn5dAH8QD8rJaDN1zNA1UTCK5ZX BNFZeL9hmQVCHHbdatxROkv+pWN50ZlgwZxjG2j2A6DBYG/MQ15aTwvRkrUpT30uCgcp hCIdeTkzxtfl92cR/2Y4nBDlKXZthmOVEvNUxk2zuiCti7S7ObKKw2+SFLCp0jmC5Eaw TT/w2BD0UwA/SBOuB1lteDpVBmv/b3b1KzGzJbB0QBPvts8n5y+fWNI/K/owbcIhYBUL RfUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688242; x=1693293042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0lC9gMe2kWPLwbVJidGFgIBdYr23SH/S3e9rEjZW5mo=; b=abuFSbi2x2vSlqKsn24wKV0eMQPzMfCbYq5BcPVUh2rPfAo0dGd0Shnws9jdO6rawK A15yiEQlSgh8rkGhQd9bH3M4BxnjmYl/1z+eVUgag3hZTn+tXQVJ8hbozB4YuIRf0JB5 Fsz2FoN31YhqPthf4jAq3E/Rn/QZmf8YeO/WGWUobVRuOAKC4udBEWrIjYmFT3u7dMnf aTIfTYwaLk7klvEPIsV1GzO6b5HbPqNqiH6vjCJkmNE71RwyFJpBP5tHFcK7qqoFEKDA /Xf4PUDhMPPEIs0K8vZ9u+Q6awPcz0xN2eY9Hr4rFMLRKjhGIpc8N5htFP7wnHW+ZfTo trIg== X-Gm-Message-State: AOJu0YzqVq3+TxQzeEeYhCj/s/jBY+Bgi+DzRLPc+Se2tcH1TkeUMggp 6oTXaaABAtcD1XODBEkwWbJq7DbPJWh400G4CELi7w== X-Received: by 2002:a5d:4403:0:b0:317:4ef8:1659 with SMTP id z3-20020a5d4403000000b003174ef81659mr5926769wrq.28.1692688242746; Tue, 22 Aug 2023 00:10:42 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id v1-20020a5d6101000000b0031c612146f1sm1305025wrt.100.2023.08.22.00.10.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson Subject: [PATCH v5 04/19] target/loongarch: Add LA64 & VA32 to DisasContext Date: Tue, 22 Aug 2023 09:09:57 +0200 Message-ID: <20230822071013.34884-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=philmd@linaro.org; helo=mail-wr1-x42e.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Add LA64 and VA32(32-bit Virtual Address) to DisasContext to allow the translator to reject doubleword instructions in LA32 mode for example. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Signed-off-by: Song Gao Message-ID: <20230822032724.1353391-5-gaosong@loongson.cn> --- target/loongarch/cpu.h | 13 +++++++++++++ target/loongarch/translate.h | 2 ++ target/loongarch/translate.c | 3 +++ 3 files changed, 18 insertions(+) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index b8af491041..72109095e4 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -432,6 +432,17 @@ static inline bool is_la64(CPULoongArchState *env) return FIELD_EX32(env->cpucfg[1], CPUCFG1, ARCH) == CPUCFG1_ARCH_LA64; } +static inline bool is_va32(CPULoongArchState *env) +{ + /* VA32 if !LA64 or VA32L[1-3] */ + bool va32 = !is_la64(env); + uint64_t plv = FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PLV); + if (plv >= 1 && (FIELD_EX64(env->CSR_MISC, CSR_MISC, VA32) & (1 << plv))) { + va32 = true; + } + return va32; +} + /* * LoongArch CPUs hardware flags. */ @@ -439,6 +450,7 @@ static inline bool is_la64(CPULoongArchState *env) #define HW_FLAGS_CRMD_PG R_CSR_CRMD_PG_MASK /* 0x10 */ #define HW_FLAGS_EUEN_FPE 0x04 #define HW_FLAGS_EUEN_SXE 0x08 +#define HW_FLAGS_VA32 0x20 static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, vaddr *pc, uint64_t *cs_base, uint32_t *flags) @@ -448,6 +460,7 @@ static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, vaddr *pc, *flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK); *flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, FPE) * HW_FLAGS_EUEN_FPE; *flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, SXE) * HW_FLAGS_EUEN_SXE; + *flags |= is_va32(env) * HW_FLAGS_VA32; } void loongarch_cpu_list(void); diff --git a/target/loongarch/translate.h b/target/loongarch/translate.h index 7f60090580..b6fa5df82d 100644 --- a/target/loongarch/translate.h +++ b/target/loongarch/translate.h @@ -33,6 +33,8 @@ typedef struct DisasContext { uint16_t plv; int vl; /* Vector length */ TCGv zero; + bool la64; /* LoongArch64 mode */ + bool va32; /* 32-bit virtual address */ } DisasContext; void generate_exception(DisasContext *ctx, int excp); diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index 3146a2d4ac..ac847745df 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -119,6 +119,9 @@ static void loongarch_tr_init_disas_context(DisasContextBase *dcbase, ctx->vl = LSX_LEN; } + ctx->la64 = is_la64(env); + ctx->va32 = (ctx->base.tb->flags & HW_FLAGS_VA32) != 0; + ctx->zero = tcg_constant_tl(0); } From patchwork Tue Aug 22 07:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715685 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117603wrp; Tue, 22 Aug 2023 00:11:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhILPQzJG65ZQRNpIO+vW/dCzecv1jgDkfxBxwCvVKhMjKvZGlR7SnQAKfMW4FmOCpVD1o X-Received: by 2002:ad4:559b:0:b0:64a:3073:e549 with SMTP id f27-20020ad4559b000000b0064a3073e549mr7650662qvx.59.1692688297288; Tue, 22 Aug 2023 00:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688297; cv=none; d=google.com; s=arc-20160816; b=sVy7VB8MSt0w+rmZHeBYAOgPyYajb1MPYPlMe5rtWNSBY/C1vD/wTv/zd2aq66tzoR tA0+49jDa+HtQOREBwBAHEQkZHJRfJ2gIHQ6NnAw+xChu4ocBx+l6G4dd/trvvXXmZyr Me9jrl2Ez2KNOgKOAhelKIOu9BuRx2hsOo1Otw6w7XGaCiaTR6vdUkXx4eOeATpAifR4 BsFZFXiGSEyryWGYOo0hpEqnHOckklt6sbHGQ8MB8pCWOarU8dui91KAX67Qhzc7wnxu dQ7wOE9B4sRYYNAZQAm5Ggk+2zH0sfzbQv4DlcjEn1CrKUjiconC/XOm2ebkp+psfu5q wvXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V161z4Ei7sDtuZQE5rhbvAPYD0+mOubaYtO5GaVSVj4=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=Hu2hsnsTwTms+zDrMV2m5dgZzdJVRudfIrQo08ZsoteVeB7VajNqkzBxZnYsMLYJnl ZnWT5mSNuWJY1bbsPCzdUeiN1LmNrHZYOXe8ISAh/q5YPchuiOaOaT/eYX4VBMVxTChh SkzvyrmCEuzI+Z3T9pNOp1/ZqRuMfKpRb5I5HKmECm6Wiir9CSxiIUZghh4awHd/UH6o OR3HuDLKKA7q2Hs/FkXvGSRxrjr3Jl5c0pEmTHP3eF2rSVybz/nSAliYBBxcyey9YKCd 1Ukp90isXWo80DB9hC8woCmIQydR2qM2jnu/IVMYho2sLM1s9W9S3J9Yiw3gfVtxqBnt QpLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fOfCWHCp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s4-20020a0ce304000000b0064728ec0f5esi5876262qvl.527.2023.08.22.00.11.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fOfCWHCp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLXT-0002ve-Nw; Tue, 22 Aug 2023 03:10: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 1qYLXR-0002pI-Ke for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:53 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXO-0002Nf-TH for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:53 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fee17aebc8so27873885e9.0 for ; Tue, 22 Aug 2023 00:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688249; x=1693293049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V161z4Ei7sDtuZQE5rhbvAPYD0+mOubaYtO5GaVSVj4=; b=fOfCWHCpsxEKHx0zbI0dYeY07m6DdxH4ZgYfHA6jYzOMrgSQI1Rjg7WxkSmXOQ1foM pFfPzlIXiLl1xCCmxKPIWbPbPOUnX/OBZDZVZ7omdtkQjI5JZpnT9OWn50QK6RLZpMLL NuQaLhXPLDydP/rXQdwHgmKwCwzGWGDyUFpqM9gfE1sLLaviydvKT3/nD9z5MfRU8hDk mFHjyVE71Y3BIp4HufJihhsfngkgmS/FQDi5KJ79ytnN0l/pfwQHwR2Gc188NNTJamsh SFx8wj3XMRVkaZQh0lAB+rRLhBlg7Ht/TPBBoWcUnfttceUvWG/aWI4jKJOScLGdamN6 8aLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688249; x=1693293049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V161z4Ei7sDtuZQE5rhbvAPYD0+mOubaYtO5GaVSVj4=; b=cwcpj5YUaDlOmOsIDnTraCBITTjEN6RR9Krw3bCFH6BY48d9+4gkOvaJaHZzv+NsHJ ntcBCwzBVrQ96es9QpEuzUNc0+YLHNC6vCJqx60jrvuJ11kh706VR0EKjSVU6hL/0Urz ly/Gj/25ohs2PtWHIwAUImShwZlBzpoFCKGb0v/fm0USWvOUE//zUnF3H5NWH1S5ifgl mSUxZk09jNTaWixbSvnrDyyr0tvjbdpJUiL/1iv6VJGSqMxmAjVuU0FIVL2p2k1bCf20 Uh2GsJEzTTVPQnOIXEvSTm+qvsBMmz8ExXcYMWfFseVUuaKqvSGGYNkXy4Z1NKV2UUjB Zpww== X-Gm-Message-State: AOJu0Yxb0sqh5Y5oGCT85aoMWqqAHUabgqQad/dSp2INztJBNnj0agTx np0PSopdm4ha9lM0wtCiKA5/SzafuPy3b3JKRZTazA== X-Received: by 2002:a05:600c:214a:b0:3fc:a8:dc3c with SMTP id v10-20020a05600c214a00b003fc00a8dc3cmr7172541wml.37.1692688249319; Tue, 22 Aug 2023 00:10:49 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id z10-20020a1c4c0a000000b003fef5402d2dsm3081718wmf.8.2023.08.22.00.10.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 05/19] target/loongarch: Extract make_address_x() helper Date: Tue, 22 Aug 2023 09:09:58 +0200 Message-ID: <20230822071013.34884-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Signed-off-by: Jiajie Chen Co-authored-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-6-gaosong@loongson.cn> [PMD: Extract helper from bigger patch] Signed-off-by: Philippe Mathieu-Daudé --- target/loongarch/translate.c | 12 ++++++++++++ .../loongarch/insn_trans/trans_fmemory.c.inc | 18 ++++++------------ target/loongarch/insn_trans/trans_lsx.c.inc | 6 ++---- target/loongarch/insn_trans/trans_memory.c.inc | 6 ++---- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index ac847745df..a68a979a55 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -208,6 +208,18 @@ static void set_fpr(int reg_num, TCGv val) offsetof(CPULoongArchState, fpr[reg_num].vreg.D(0))); } +static TCGv make_address_x(DisasContext *ctx, TCGv base, TCGv addend) +{ + TCGv temp = NULL; + + if (addend) { + temp = tcg_temp_new(); + tcg_gen_add_tl(temp, base, addend); + base = temp; + } + return base; +} + #include "decode-insns.c.inc" #include "insn_trans/trans_arith.c.inc" #include "insn_trans/trans_shift.c.inc" diff --git a/target/loongarch/insn_trans/trans_fmemory.c.inc b/target/loongarch/insn_trans/trans_fmemory.c.inc index 91c09fb6d9..88ad209338 100644 --- a/target/loongarch/insn_trans/trans_fmemory.c.inc +++ b/target/loongarch/insn_trans/trans_fmemory.c.inc @@ -57,8 +57,7 @@ static bool gen_floadx(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); maybe_nanbox_load(dest, mop); set_fpr(a->fd, dest); @@ -75,8 +74,7 @@ static bool gen_fstorex(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_st_tl(src3, addr, ctx->mem_idx, mop); return true; @@ -91,9 +89,8 @@ static bool gen_fload_gt(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); gen_helper_asrtgt_d(cpu_env, src1, src2); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); maybe_nanbox_load(dest, mop); set_fpr(a->fd, dest); @@ -110,9 +107,8 @@ static bool gen_fstore_gt(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); gen_helper_asrtgt_d(cpu_env, src1, src2); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_st_tl(src3, addr, ctx->mem_idx, mop); return true; @@ -127,9 +123,8 @@ static bool gen_fload_le(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); gen_helper_asrtle_d(cpu_env, src1, src2); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); maybe_nanbox_load(dest, mop); set_fpr(a->fd, dest); @@ -146,9 +141,8 @@ static bool gen_fstore_le(DisasContext *ctx, arg_frr *a, MemOp mop) CHECK_FPE; - addr = tcg_temp_new(); gen_helper_asrtle_d(cpu_env, src1, src2); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_st_tl(src3, addr, ctx->mem_idx, mop); return true; diff --git a/target/loongarch/insn_trans/trans_lsx.c.inc b/target/loongarch/insn_trans/trans_lsx.c.inc index 68779daff6..875cb7d51d 100644 --- a/target/loongarch/insn_trans/trans_lsx.c.inc +++ b/target/loongarch/insn_trans/trans_lsx.c.inc @@ -4315,14 +4315,13 @@ static bool trans_vldx(DisasContext *ctx, arg_vrr *a) CHECK_SXE; - addr = tcg_temp_new(); src1 = gpr_src(ctx, a->rj, EXT_NONE); src2 = gpr_src(ctx, a->rk, EXT_NONE); val = tcg_temp_new_i128(); rl = tcg_temp_new_i64(); rh = tcg_temp_new_i64(); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); tcg_gen_qemu_ld_i128(val, addr, ctx->mem_idx, MO_128 | MO_TE); tcg_gen_extr_i128_i64(rl, rh, val); set_vreg64(rh, a->vd, 1); @@ -4339,14 +4338,13 @@ static bool trans_vstx(DisasContext *ctx, arg_vrr *a) CHECK_SXE; - addr = tcg_temp_new(); src1 = gpr_src(ctx, a->rj, EXT_NONE); src2 = gpr_src(ctx, a->rk, EXT_NONE); val = tcg_temp_new_i128(); ah = tcg_temp_new_i64(); al = tcg_temp_new_i64(); - tcg_gen_add_tl(addr, src1, src2); + addr = make_address_x(ctx, src1, src2); get_vreg64(ah, a->vd, 1); get_vreg64(al, a->vd, 0); tcg_gen_concat_i64_i128(val, al, ah); diff --git a/target/loongarch/insn_trans/trans_memory.c.inc b/target/loongarch/insn_trans/trans_memory.c.inc index 75cfdf59ad..ccebd0a4e0 100644 --- a/target/loongarch/insn_trans/trans_memory.c.inc +++ b/target/loongarch/insn_trans/trans_memory.c.inc @@ -39,9 +39,8 @@ static bool gen_loadx(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); - TCGv addr = tcg_temp_new(); + TCGv addr = make_address_x(ctx, src1, src2); - tcg_gen_add_tl(addr, src1, src2); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); @@ -53,9 +52,8 @@ static bool gen_storex(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv data = gpr_src(ctx, a->rd, EXT_NONE); TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); - TCGv addr = tcg_temp_new(); + TCGv addr = make_address_x(ctx, src1, src2); - tcg_gen_add_tl(addr, src1, src2); tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop); return true; From patchwork Tue Aug 22 07:09:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715682 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117582wrp; Tue, 22 Aug 2023 00:11:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfP90i+edGifCKtdBkn013PMIGrEFt/JunowwAwwHJfh8qVwohi52KzXqG67VqG700g/Mk X-Received: by 2002:a05:622a:550:b0:40d:19a4:5fd0 with SMTP id m16-20020a05622a055000b0040d19a45fd0mr8077189qtx.38.1692688294357; Tue, 22 Aug 2023 00:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688294; cv=none; d=google.com; s=arc-20160816; b=lZ7LDyC87cxTJaFE/e2z0ergY/wHYBLP/uY0zZ7q4nkJYm2d2A4HTgfwvVnlNVfIwx qv5QwUfRL+CsCStdFVftq+NKrITv1QDA+ZX/TkHfd+vgYgxD596G+niUZjnvKiaaRFyf x6J9nyQrlIWD67diKpH0KZl8Dxz8ObSv1v8hjH4aOVXmwpHtuu9zTAUQSLvnwYQoa/ze ZjWdYqNFQcv4+AWW0ckSOhHi3fxkdQ4sG0vhsLPr4M83SPwe8EAYZB5DwuawRQVsX6O8 qNThNJCWwR4/AWZbbU0LzXAVzkhXGLuZfFSZJ/4yGXV9Rtm3x/Ty7v7Hkm8KxG6URrxg ZKVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fvQZedijPtJ34ELRwqSS7RfwCk60jvhcOCv1VkYXcvk=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=oROHkXC5osKEtzxH/T1AnMCYT7a4ZthmWIKQ+zLfNQZXACFPLyno+kDXC/f8b/KWhD JY1kAJ7WOGpt1yFK4NcJ1gJCggKy8kG6KdRwUzlsSnvY7BXxz+oW4c7HVDR5203XQXV2 GCjtdMXKA2TkPWiHPwX4wYOV9q9dSFpgtH30IvFtWE83mBA3ZkBg1GhAflTpnNBIVC1V fEsV4sEpSKbgzF6xPv+ELtav2JradLG8UrXrerJc0p2jzvZYhb9mx/8uOmAAGxHb0XqV R+GJ4/RqsKW7UyzWOjR9gsHtjeWql4tVdueNu6Tme5EzxsVduSpLP+d/ZFH252awmGOg w7pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gCTVVogp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k22-20020ac85fd6000000b00403eb431a33si5989936qta.240.2023.08.22.00.11.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gCTVVogp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLXj-0003Bl-RZ; Tue, 22 Aug 2023 03:11:13 -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 1qYLXY-0002zM-84 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:05 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXV-0002Oh-Bd for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:10:59 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3feef504ccbso19123055e9.2 for ; Tue, 22 Aug 2023 00:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688256; x=1693293056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fvQZedijPtJ34ELRwqSS7RfwCk60jvhcOCv1VkYXcvk=; b=gCTVVogpCHk7m/jexss5Prvsk4+BnfVR/S3cPnxREuxQy89Oyg9RioJLZYA80eavwd 1LMq6C6pbilFnNtEHR7gQ0CmeMVQnF+2sNQ7ZXu8eVCUS5n8oj0/DimFl1HLyAgwLoA5 l8nHsfXq/iB3NT4rVOE4hRhQiJNGmBP1zVcOn/Ca1U92q3nbGYO8OfI789S92g3kgg0B AAUhsL1fiPJV0kvLQOLtUrMAy7gN0+dzVk3Od75paCusTG57togM+joildzHnYqmumHy ANAF+vpFJPOW5jN20siU46gtmaeRZN7x3X7t2Gp9NoQ/d6/wv3vb+mOJ26ZijJxcbIty YTXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688256; x=1693293056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fvQZedijPtJ34ELRwqSS7RfwCk60jvhcOCv1VkYXcvk=; b=XsvTj8weR4428Yqk6mW3z6JYChScGdw0KjxsljsNs780dzEmnDCD5q2f3+qdwQAcIr PK0saEsG3H2TCXn/8YJvfOXHREyZt0pyWpdyHItylfAIazZbCqz1DFh6iLRjcFUt2Jiz xCyxyM0CfUqy3n76saE9NuKO2kd5jvtbu1qVzZHjs/R04irjRt9HQI8RucDrGTKx+xx1 0mdQZqi/ln4DQJw8mQa3+QU16a3PI+Y02zChUzREul6MKTmHHnbbOo+BBIOyDWiPVeFp zbLO/xUg3ynOxYeywAedrbNu9MK1Nc/+Er6zfAnSIauDjrKgwcITfdI7HYqra3Zcvmup 7pEw== X-Gm-Message-State: AOJu0YzXO8B2GtAxAbuzMtLd343MMj8Gg+Jux1PNmglC0UsfrCXVHfP8 iRM6tcQ3oeg/nJlB/+kkgvE45vo3bNRXvVrWclBBkQ== X-Received: by 2002:a1c:7907:0:b0:3fe:1bef:4034 with SMTP id l7-20020a1c7907000000b003fe1bef4034mr7305924wme.37.1692688255756; Tue, 22 Aug 2023 00:10:55 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id x20-20020a05600c2a5400b003fef60005b5sm2505947wme.9.2023.08.22.00.10.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:10:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 06/19] target/loongarch: Extract make_address_i() helper Date: Tue, 22 Aug 2023 09:09:59 +0200 Message-ID: <20230822071013.34884-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Signed-off-by: Jiajie Chen Co-authored-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-6-gaosong@loongson.cn> [PMD: Extract helper from bigger patch] Signed-off-by: Philippe Mathieu-Daudé --- target/loongarch/translate.c | 6 ++++ .../loongarch/insn_trans/trans_atomic.c.inc | 5 +-- .../loongarch/insn_trans/trans_branch.c.inc | 3 +- .../loongarch/insn_trans/trans_fmemory.c.inc | 12 ++----- target/loongarch/insn_trans/trans_lsx.c.inc | 32 +++++-------------- .../loongarch/insn_trans/trans_memory.c.inc | 28 +++++----------- 6 files changed, 29 insertions(+), 57 deletions(-) diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index a68a979a55..acc54d7587 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -220,6 +220,12 @@ static TCGv make_address_x(DisasContext *ctx, TCGv base, TCGv addend) return base; } +static TCGv make_address_i(DisasContext *ctx, TCGv base, target_long ofs) +{ + TCGv addend = ofs ? tcg_constant_tl(ofs) : NULL; + return make_address_x(ctx, base, addend); +} + #include "decode-insns.c.inc" #include "insn_trans/trans_arith.c.inc" #include "insn_trans/trans_shift.c.inc" diff --git a/target/loongarch/insn_trans/trans_atomic.c.inc b/target/loongarch/insn_trans/trans_atomic.c.inc index 612709f2a7..fbc081448d 100644 --- a/target/loongarch/insn_trans/trans_atomic.c.inc +++ b/target/loongarch/insn_trans/trans_atomic.c.inc @@ -7,9 +7,8 @@ static bool gen_ll(DisasContext *ctx, arg_rr_i *a, MemOp mop) { TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); - TCGv t0 = tcg_temp_new(); + TCGv t0 = make_address_i(ctx, src1, a->imm); - tcg_gen_addi_tl(t0, src1, a->imm); tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, mop); tcg_gen_st_tl(t0, cpu_env, offsetof(CPULoongArchState, lladdr)); tcg_gen_st_tl(dest, cpu_env, offsetof(CPULoongArchState, llval)); @@ -62,6 +61,8 @@ static bool gen_am(DisasContext *ctx, arg_rrr *a, return false; } + addr = make_address_i(ctx, addr, 0); + func(dest, addr, val, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); diff --git a/target/loongarch/insn_trans/trans_branch.c.inc b/target/loongarch/insn_trans/trans_branch.c.inc index a860f7e733..3ad34bcc05 100644 --- a/target/loongarch/insn_trans/trans_branch.c.inc +++ b/target/loongarch/insn_trans/trans_branch.c.inc @@ -23,7 +23,8 @@ static bool trans_jirl(DisasContext *ctx, arg_jirl *a) TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); - tcg_gen_addi_tl(cpu_pc, src1, a->imm); + TCGv addr = make_address_i(ctx, src1, a->imm); + tcg_gen_mov_tl(cpu_pc, addr); tcg_gen_movi_tl(dest, ctx->base.pc_next + 4); gen_set_gpr(a->rd, dest, EXT_NONE); tcg_gen_lookup_and_goto_ptr(); diff --git a/target/loongarch/insn_trans/trans_fmemory.c.inc b/target/loongarch/insn_trans/trans_fmemory.c.inc index 88ad209338..bd3aba2c49 100644 --- a/target/loongarch/insn_trans/trans_fmemory.c.inc +++ b/target/loongarch/insn_trans/trans_fmemory.c.inc @@ -17,11 +17,7 @@ static bool gen_fload_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) CHECK_FPE; - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); maybe_nanbox_load(dest, mop); @@ -37,11 +33,7 @@ static bool gen_fstore_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) CHECK_FPE; - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_st_tl(src, addr, ctx->mem_idx, mop); diff --git a/target/loongarch/insn_trans/trans_lsx.c.inc b/target/loongarch/insn_trans/trans_lsx.c.inc index 875cb7d51d..50153d6d0b 100644 --- a/target/loongarch/insn_trans/trans_lsx.c.inc +++ b/target/loongarch/insn_trans/trans_lsx.c.inc @@ -4255,7 +4255,7 @@ TRANS(vextrins_d, gen_vv_i, gen_helper_vextrins_d) static bool trans_vld(DisasContext *ctx, arg_vr_i *a) { - TCGv addr, temp; + TCGv addr; TCGv_i64 rl, rh; TCGv_i128 val; @@ -4266,11 +4266,7 @@ static bool trans_vld(DisasContext *ctx, arg_vr_i *a) rl = tcg_temp_new_i64(); rh = tcg_temp_new_i64(); - if (a->imm) { - temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_ld_i128(val, addr, ctx->mem_idx, MO_128 | MO_TE); tcg_gen_extr_i128_i64(rl, rh, val); @@ -4282,7 +4278,7 @@ static bool trans_vld(DisasContext *ctx, arg_vr_i *a) static bool trans_vst(DisasContext *ctx, arg_vr_i *a) { - TCGv addr, temp; + TCGv addr; TCGv_i128 val; TCGv_i64 ah, al; @@ -4293,11 +4289,7 @@ static bool trans_vst(DisasContext *ctx, arg_vr_i *a) ah = tcg_temp_new_i64(); al = tcg_temp_new_i64(); - if (a->imm) { - temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); get_vreg64(ah, a->vd, 1); get_vreg64(al, a->vd, 0); @@ -4356,7 +4348,7 @@ static bool trans_vstx(DisasContext *ctx, arg_vrr *a) #define VLDREPL(NAME, MO) \ static bool trans_## NAME (DisasContext *ctx, arg_vr_i *a) \ { \ - TCGv addr, temp; \ + TCGv addr; \ TCGv_i64 val; \ \ CHECK_SXE; \ @@ -4364,11 +4356,7 @@ static bool trans_## NAME (DisasContext *ctx, arg_vr_i *a) \ addr = gpr_src(ctx, a->rj, EXT_NONE); \ val = tcg_temp_new_i64(); \ \ - if (a->imm) { \ - temp = tcg_temp_new(); \ - tcg_gen_addi_tl(temp, addr, a->imm); \ - addr = temp; \ - } \ + addr = make_address_i(ctx, addr, a->imm); \ \ tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, MO); \ tcg_gen_gvec_dup_i64(MO, vec_full_offset(a->vd), 16, ctx->vl/8, val); \ @@ -4384,7 +4372,7 @@ VLDREPL(vldrepl_d, MO_64) #define VSTELM(NAME, MO, E) \ static bool trans_## NAME (DisasContext *ctx, arg_vr_ii *a) \ { \ - TCGv addr, temp; \ + TCGv addr; \ TCGv_i64 val; \ \ CHECK_SXE; \ @@ -4392,11 +4380,7 @@ static bool trans_## NAME (DisasContext *ctx, arg_vr_ii *a) \ addr = gpr_src(ctx, a->rj, EXT_NONE); \ val = tcg_temp_new_i64(); \ \ - if (a->imm) { \ - temp = tcg_temp_new(); \ - tcg_gen_addi_tl(temp, addr, a->imm); \ - addr = temp; \ - } \ + addr = make_address_i(ctx, addr, a->imm); \ \ tcg_gen_ld_i64(val, cpu_env, \ offsetof(CPULoongArchState, fpr[a->vd].vreg.E(a->imm2))); \ diff --git a/target/loongarch/insn_trans/trans_memory.c.inc b/target/loongarch/insn_trans/trans_memory.c.inc index ccebd0a4e0..88953f0ab0 100644 --- a/target/loongarch/insn_trans/trans_memory.c.inc +++ b/target/loongarch/insn_trans/trans_memory.c.inc @@ -8,11 +8,7 @@ static bool gen_load(DisasContext *ctx, arg_rr_i *a, MemOp mop) TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); @@ -24,11 +20,7 @@ static bool gen_store(DisasContext *ctx, arg_rr_i *a, MemOp mop) TCGv data = gpr_src(ctx, a->rd, EXT_NONE); TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop); return true; @@ -66,6 +58,7 @@ static bool gen_load_gt(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); gen_helper_asrtgt_d(cpu_env, src1, src2); + src1 = make_address_i(ctx, src1, 0); tcg_gen_qemu_ld_tl(dest, src1, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); @@ -79,6 +72,7 @@ static bool gen_load_le(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); gen_helper_asrtle_d(cpu_env, src1, src2); + src1 = make_address_i(ctx, src1, 0); tcg_gen_qemu_ld_tl(dest, src1, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); @@ -92,6 +86,7 @@ static bool gen_store_gt(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); gen_helper_asrtgt_d(cpu_env, src1, src2); + src1 = make_address_i(ctx, src1, 0); tcg_gen_qemu_st_tl(data, src1, ctx->mem_idx, mop); return true; @@ -104,6 +99,7 @@ static bool gen_store_le(DisasContext *ctx, arg_rrr *a, MemOp mop) TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); gen_helper_asrtle_d(cpu_env, src1, src2); + src1 = make_address_i(ctx, src1, 0); tcg_gen_qemu_st_tl(data, src1, ctx->mem_idx, mop); return true; @@ -131,11 +127,7 @@ static bool gen_ldptr(DisasContext *ctx, arg_rr_i *a, MemOp mop) TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop); gen_set_gpr(a->rd, dest, EXT_NONE); @@ -147,11 +139,7 @@ static bool gen_stptr(DisasContext *ctx, arg_rr_i *a, MemOp mop) TCGv data = gpr_src(ctx, a->rd, EXT_NONE); TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); - if (a->imm) { - TCGv temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->imm); - addr = temp; - } + addr = make_address_i(ctx, addr, a->imm); tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop); return true; From patchwork Tue Aug 22 07:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715686 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117613wrp; Tue, 22 Aug 2023 00:11:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVyrTwWNiz3cXD7hZyEpDl3gnfmIxxsiJHskiWMkPtV+84S8TFKsE+33q/NVs7/hOBVO4u X-Received: by 2002:ac8:4e88:0:b0:40f:dd92:5c91 with SMTP id 8-20020ac84e88000000b0040fdd925c91mr10946845qtp.37.1692688299221; Tue, 22 Aug 2023 00:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688299; cv=none; d=google.com; s=arc-20160816; b=UxD6UbD8ZxXSzEtW+nSCOxJ9889IELqAA4vwgY92oMAXSZOfnkuLsdUjSyqOvpmZlG 3w3ZVTwf1V8PHqgAw3OVz/hMeA74TYjsk/kjC1yWYv+NQ9GHtHyNJpy1gpO3o9a45K7F OXF3gbNdIuKBac3TV4wk8aJPooPPfP63+mVFaF4NrqAZ5E+MiMWqhrDk4lwYxJb/HLnS Vv2URLJ3UdLMCG1F4sv+AQ4l20v4aGlyrK8hf3YJyHhGKPdtOucC4wfKClnlD3CKM9gH Af4R+0NEoJkBsxpFd82D9VLuQDHSwOVuZGXIQ4qE1qdPWLVASgr+lgRGa7vdBt6EL2BB A2HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ac7pv2kpb0ajeFGbtJ3onoCTyP2ZNqDH1hhRLbCbPbE=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=Az/NVK6ak6jUZ0dsXZ+R9MXqZaUq3MYsPu07VXCggm1ST8vgPOmcIF3Npe/WONRWkG liUUpxA8RSlB2uaAsZJZbkdehA0PpKQjnIOwdloCajAITvQFm6Rfokbhaxr3eqxXk1z3 sSzOpKyIjiNy4p2GvAsCUVrQ7+8biaPtrVwWkvDVIA9gucDDjYWE7UhLKY9gUMatwnsn Lzus+yUUlZ5JlkANvj5FdMBRpI8ptFCY7yLES1YgN4BdcZeANRy93XbU66H6Sf0rzHWD OExOUF5DMMdKxtkDtBrfb78X7ES58ZrndFo4T99JYDaROy9ZGl1Xwbsw+7WQVBSEI8F4 g0UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rB96EO2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s12-20020a05622a018c00b0040fee175e34si909836qtw.358.2023.08.22.00.11.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rB96EO2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLY1-0003aN-Gv; Tue, 22 Aug 2023 03:11:31 -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 1qYLXe-00036R-Io for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:09 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXb-0002PS-UQ for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:05 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-319559fd67dso3877356f8f.3 for ; Tue, 22 Aug 2023 00:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688262; x=1693293062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ac7pv2kpb0ajeFGbtJ3onoCTyP2ZNqDH1hhRLbCbPbE=; b=rB96EO2v6DcNYHPQOVDRulIp0flmeeOzA70d15VRu4eNNrZidgjDBUi/lQulVSCeJQ lnebTzU2NW+BiG7+wOZsLhtu2VPbdfolJx9H6LFewqyQH+rEIUHq0aJPZczuLryjLyL7 h0XT1z7OXeMkZmz7FZYcNU/UGcWt235z4m3Y4ndIiKH1ZjFqzPFUQ0G42Juj+HGOYVgZ +ZG4l+2QZxu9bvrOyDPT+iiyZbP5OAdGVw7xBpujU2tjmLz0kgPF70jcxehpFR4G3CRH KUZlvYEw5hIgy/VTndMWjC7MV8NbKIC2QYQZrBFMBVTjUfoVwSreXfhg6sEnbcrTVEtv lsDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688262; x=1693293062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ac7pv2kpb0ajeFGbtJ3onoCTyP2ZNqDH1hhRLbCbPbE=; b=GvJmCHIFaop6RggaW9Ei9uFH3E+z7l9D28wJ5JiL+FXHUsozwoTRmYhH/ZAQLHuCyS qu/EaithhsDUwvXfuG0lnbQS0IQ/NqAwz4VIdiNGsvdPpRMi60CNJU+2IB8mLYGiuTEc ltQ4cCU2nhV5JZpT3nIxkbw2rBnKRjWDnN/khlJ2yrtuHVd6nfBypAQ560PNUWCJZSn5 8yq5sUUqA/5CYPuedhmyTt8S1LpCqzAzXfUTfqTpwJ75beaF8KyDX348mumARDyxOEA5 8P99jqIgIUEf+N2YcxztdttTF8HfFnnwhrW3VsnOVSXIsj60XDvMN7zQoVWqdqkqfEjQ gLFA== X-Gm-Message-State: AOJu0Yz7TklTZuXmfqw19a1XqaWIz4Ic+UJTrvcfmLLpUCRcqzqxEEdZ jGTVooPUnBMMKfUYSY/qSL78xdCK9YscUhybz2GnFw== X-Received: by 2002:adf:e412:0:b0:317:3e58:64cb with SMTP id g18-20020adfe412000000b003173e5864cbmr7689768wrm.46.1692688262168; Tue, 22 Aug 2023 00:11:02 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id j7-20020a5d4647000000b0031c4d4be245sm5789358wrs.93.2023.08.22.00.11.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:11:01 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 07/19] target/loongarch: Extract make_address_pc() helper Date: Tue, 22 Aug 2023 09:10:00 +0200 Message-ID: <20230822071013.34884-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-x42f.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-7-gaosong@loongson.cn> [PMD: Extract helper from bigger patch] Signed-off-by: Philippe Mathieu-Daudé --- target/loongarch/translate.c | 5 +++++ target/loongarch/insn_trans/trans_arith.c.inc | 2 +- target/loongarch/insn_trans/trans_branch.c.inc | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index acc54d7587..8b26555a27 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -226,6 +226,11 @@ static TCGv make_address_i(DisasContext *ctx, TCGv base, target_long ofs) return make_address_x(ctx, base, addend); } +static uint64_t make_address_pc(DisasContext *ctx, uint64_t addr) +{ + return addr; +} + #include "decode-insns.c.inc" #include "insn_trans/trans_arith.c.inc" #include "insn_trans/trans_shift.c.inc" diff --git a/target/loongarch/insn_trans/trans_arith.c.inc b/target/loongarch/insn_trans/trans_arith.c.inc index 43d6cf261d..2aea4e41d5 100644 --- a/target/loongarch/insn_trans/trans_arith.c.inc +++ b/target/loongarch/insn_trans/trans_arith.c.inc @@ -72,7 +72,7 @@ static bool gen_pc(DisasContext *ctx, arg_r_i *a, target_ulong (*func)(target_ulong, int)) { TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); - target_ulong addr = func(ctx->base.pc_next, a->imm); + target_ulong addr = make_address_pc(ctx, func(ctx->base.pc_next, a->imm)); tcg_gen_movi_tl(dest, addr); gen_set_gpr(a->rd, dest, EXT_NONE); diff --git a/target/loongarch/insn_trans/trans_branch.c.inc b/target/loongarch/insn_trans/trans_branch.c.inc index 3ad34bcc05..2e35572cea 100644 --- a/target/loongarch/insn_trans/trans_branch.c.inc +++ b/target/loongarch/insn_trans/trans_branch.c.inc @@ -12,7 +12,7 @@ static bool trans_b(DisasContext *ctx, arg_b *a) static bool trans_bl(DisasContext *ctx, arg_bl *a) { - tcg_gen_movi_tl(cpu_gpr[1], ctx->base.pc_next + 4); + tcg_gen_movi_tl(cpu_gpr[1], make_address_pc(ctx, ctx->base.pc_next + 4)); gen_goto_tb(ctx, 0, ctx->base.pc_next + a->offs); ctx->base.is_jmp = DISAS_NORETURN; return true; @@ -25,7 +25,7 @@ static bool trans_jirl(DisasContext *ctx, arg_jirl *a) TCGv addr = make_address_i(ctx, src1, a->imm); tcg_gen_mov_tl(cpu_pc, addr); - tcg_gen_movi_tl(dest, ctx->base.pc_next + 4); + tcg_gen_movi_tl(dest, make_address_pc(ctx, ctx->base.pc_next + 4)); gen_set_gpr(a->rd, dest, EXT_NONE); tcg_gen_lookup_and_goto_ptr(); ctx->base.is_jmp = DISAS_NORETURN; From patchwork Tue Aug 22 07:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715688 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117645wrp; Tue, 22 Aug 2023 00:11:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhD04lJ1065maZLxf6/NOQbPRKdK1GRUx31eJGmH1zJOovAQknjx+va5eaSi2SKFfwJA61 X-Received: by 2002:a05:622a:1487:b0:40c:58a1:cb40 with SMTP id t7-20020a05622a148700b0040c58a1cb40mr11440409qtx.15.1692688309123; Tue, 22 Aug 2023 00:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688309; cv=none; d=google.com; s=arc-20160816; b=p458f4XuXY/VQ7eEKWq58hjHKMleY3TdDEYs87UVppZwEFxuxULHUX+kw3pLczoO7j Y737VPubqroCa6oLJYZJmIjL3PIXcYirWAwdMJ2a4gAyxphRtJUZSG8gdudQx1kwvvZg rQ/Ous3CfpvZda4vehob+xR0WfbP4vgnszqTlvq20O4LaI22wlDUgiHgcOHwzY7fq3eD WhsJIBvlMtBNTLXcqJxAPu/ovRgcMRj2kaI+sUaD64CLdXjlt6mNp93xzpSDOCYWw6Xv 40EWfi0mDr0AzXzr0eu7AH3CpcbyWtz0QPyncjkOl7RWjAH3uhFsBy27zUHU1uHH/A6R cMww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=33DmERFUsYdjL3Dz9aMKxeBhsxHS9Ddy+t/2WnyHXOg=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=xE0LaYz6q4Q/nkrThryaOHxQLi1iGKRDCirLgz/OtBkcrKg/Qvsodp9uM0rP5bMnBA n6TL13XxAm2UsVvt2f8Gfk/BWjs0FuXNXzt3cxc9Wffz6yhqv3QwOJAOAzRFjl1dDsEM SLuYvqHj8yka+ONVVd8TlZ0/W5QeOc2KwWP1j6jtwZRtsGhDo9eBo6dYTACPronkW9oB uR221YcwjIltsYRrhZwZIL4zdc3GBxsL1q/iVndtcIAybrnEVxQmLgz1vxW977+p777t XNwVyCoH2jzVENOQX8esMDRFhISAyNoIhCUgc8NmMY1ZRMfTgqSRQ8+rGRKnkeXKoO8z joKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=slui7MBG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g4-20020ac85804000000b00410a9dd9fe8si40364qtg.173.2023.08.22.00.11.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=slui7MBG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLY3-0003iE-L5; Tue, 22 Aug 2023 03:11:31 -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 1qYLXk-0003CJ-GZ for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:14 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXi-0002QJ-4Q for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:12 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe4a89e8c4so40197155e9.3 for ; Tue, 22 Aug 2023 00:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688268; x=1693293068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=33DmERFUsYdjL3Dz9aMKxeBhsxHS9Ddy+t/2WnyHXOg=; b=slui7MBGB6PaWkSPtX5JXzjaw0snYpLl9iiboCFvBrZNiDmH1bt7rMRaw1edsVwN21 M5uTTzvpcoCLSj7UsL/46Lo753HqfCcbbBYM0n9ARGE+qWd7nyfVR7LW/UfgmflWePtg QGnZxfpcXtSYn/4vrZVNiy3F91Pesx8RYAwfqXycs8etG/BsgXmL+8lTzK9U8EHYyetg 6HnSQ4mOVwjx7/8odUMf17fuLG+V7+ft+edgw6f7r2ESMEX54LRZarbuHuh5aEEhmreH j00E/Pazue90+gVgNb7NzLREBTEsDBDiASqmQTecDcknLm6CygSO27kr4W7hBiGSCrkL UPJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688268; x=1693293068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=33DmERFUsYdjL3Dz9aMKxeBhsxHS9Ddy+t/2WnyHXOg=; b=VT/dn0T2ArvBCDd6FdgWZpDXGKFLNyWKuaNc0YTvWm1Uc9TOjGaV/7EjmDQCqMDn4y jBKXR8VNjPD2t8EwfzI6t7VoFSkxVx+A35AjmINKfZ/yE/fMuG8RZPxFx1YUfuTe2KHE 5mpu73Mlg/arn7BSFieEkghDgnhuwHxWYJWs2S8ZpI5jJcrD/cOy8KfP3PwhK2a4KIyC mA9U/pJL4B05HC2k8Xf6MGH6uIqD5QO+ZNp0AlNz2SfDbEwjOJUD7wp1NgCX39gaPNZ2 j64yR5cDNX+X9V8JHVGeKBJF1vz0hJ9L3V3lqpnicI7tfrrf2akLjTZWc1VTHW6m8yc+ 0yaA== X-Gm-Message-State: AOJu0YwgoApXkmdPXm0QXPtVR8JvJj5XY8Rwb2WIDrYHmBOJAS7cwsc9 ltCWtma7eWdpFt4/E+efXE1FEScVbTkVwKy0w92U0w== X-Received: by 2002:adf:ed87:0:b0:314:2fdd:28ef with SMTP id c7-20020adfed87000000b003142fdd28efmr6746685wro.18.1692688268374; Tue, 22 Aug 2023 00:11:08 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id e11-20020a5d65cb000000b003179d7ed4f3sm14930954wrw.12.2023.08.22.00.11.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:11:08 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 08/19] target/loongarch: Extract set_pc() helper Date: Tue, 22 Aug 2023 09:10:01 +0200 Message-ID: <20230822071013.34884-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Signed-off-by: Jiajie Chen Co-authored-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-6-gaosong@loongson.cn> [PMD: Extract helper from bigger patch] Signed-off-by: Philippe Mathieu-Daudé --- target/loongarch/cpu.h | 5 +++++ target/loongarch/cpu.c | 16 ++++++++-------- target/loongarch/gdbstub.c | 2 +- target/loongarch/op_helper.c | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index 72109095e4..e1562695e8 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -443,6 +443,11 @@ static inline bool is_va32(CPULoongArchState *env) return va32; } +static inline void set_pc(CPULoongArchState *env, uint64_t value) +{ + env->pc = value; +} + /* * LoongArch CPUs hardware flags. */ diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 822f2a72e5..67eb6c3135 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -81,7 +81,7 @@ static void loongarch_cpu_set_pc(CPUState *cs, vaddr value) LoongArchCPU *cpu = LOONGARCH_CPU(cs); CPULoongArchState *env = &cpu->env; - env->pc = value; + set_pc(env, value); } static vaddr loongarch_cpu_get_pc(CPUState *cs) @@ -168,7 +168,7 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) set_DERA: env->CSR_DERA = env->pc; env->CSR_DBG = FIELD_DP64(env->CSR_DBG, CSR_DBG, DST, 1); - env->pc = env->CSR_EENTRY + 0x480; + set_pc(env, env->CSR_EENTRY + 0x480); break; case EXCCODE_INT: if (FIELD_EX64(env->CSR_DBG, CSR_DBG, DST)) { @@ -249,7 +249,8 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) /* Find the highest-priority interrupt. */ vector = 31 - clz32(pending); - env->pc = env->CSR_EENTRY + (EXCCODE_EXTERNAL_INT + vector) * vec_size; + set_pc(env, env->CSR_EENTRY + \ + (EXCCODE_EXTERNAL_INT + vector) * vec_size); qemu_log_mask(CPU_LOG_INT, "%s: PC " TARGET_FMT_lx " ERA " TARGET_FMT_lx " cause %d\n" " A " TARGET_FMT_lx " D " @@ -260,10 +261,9 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) env->CSR_ECFG, env->CSR_ESTAT); } else { if (tlbfill) { - env->pc = env->CSR_TLBRENTRY; + set_pc(env, env->CSR_TLBRENTRY); } else { - env->pc = env->CSR_EENTRY; - env->pc += EXCODE_MCODE(cause) * vec_size; + set_pc(env, env->CSR_EENTRY + EXCODE_MCODE(cause) * vec_size); } qemu_log_mask(CPU_LOG_INT, "%s: PC " TARGET_FMT_lx " ERA " TARGET_FMT_lx @@ -324,7 +324,7 @@ static void loongarch_cpu_synchronize_from_tb(CPUState *cs, CPULoongArchState *env = &cpu->env; tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); - env->pc = tb->pc; + set_pc(env, tb->pc); } static void loongarch_restore_state_to_opc(CPUState *cs, @@ -334,7 +334,7 @@ static void loongarch_restore_state_to_opc(CPUState *cs, LoongArchCPU *cpu = LOONGARCH_CPU(cs); CPULoongArchState *env = &cpu->env; - env->pc = data[0]; + set_pc(env, data[0]); } #endif /* CONFIG_TCG */ diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c index a462e25737..e20b20f99b 100644 --- a/target/loongarch/gdbstub.c +++ b/target/loongarch/gdbstub.c @@ -77,7 +77,7 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) env->gpr[n] = tmp; length = read_length; } else if (n == 33) { - env->pc = tmp; + set_pc(env, tmp); length = read_length; } return length; diff --git a/target/loongarch/op_helper.c b/target/loongarch/op_helper.c index 60335a05e2..cf84f20aba 100644 --- a/target/loongarch/op_helper.c +++ b/target/loongarch/op_helper.c @@ -114,14 +114,14 @@ void helper_ertn(CPULoongArchState *env) env->CSR_TLBRERA = FIELD_DP64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR, 0); env->CSR_CRMD = FIELD_DP64(env->CSR_CRMD, CSR_CRMD, DA, 0); env->CSR_CRMD = FIELD_DP64(env->CSR_CRMD, CSR_CRMD, PG, 1); - env->pc = env->CSR_TLBRERA; + set_pc(env, env->CSR_TLBRERA); qemu_log_mask(CPU_LOG_INT, "%s: TLBRERA " TARGET_FMT_lx "\n", __func__, env->CSR_TLBRERA); } else { csr_pplv = FIELD_EX64(env->CSR_PRMD, CSR_PRMD, PPLV); csr_pie = FIELD_EX64(env->CSR_PRMD, CSR_PRMD, PIE); - env->pc = env->CSR_ERA; + set_pc(env, env->CSR_ERA); qemu_log_mask(CPU_LOG_INT, "%s: ERA " TARGET_FMT_lx "\n", __func__, env->CSR_ERA); } From patchwork Tue Aug 22 07:10:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715683 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117593wrp; Tue, 22 Aug 2023 00:11:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpUKxYYDWZBneX7guswKVvAHJFkT3wUVLAqmgX/NHgoWzYEophDcb24wC3H8fUsIUoAe0t X-Received: by 2002:a05:620a:951:b0:76c:b527:1e37 with SMTP id w17-20020a05620a095100b0076cb5271e37mr7841832qkw.78.1692688296544; Tue, 22 Aug 2023 00:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688296; cv=none; d=google.com; s=arc-20160816; b=lnNiaZp3N3YztGmLv+YOy9k0ytwN1ti22Ns3zAv9X57kWvoY/YKR8aTQk1hsGqiw5p dny4YQo7XdnLNZ1YeJSSoehhLb1NCRI/G+wIB3AAx7ThTKRWA37s5slfje5HgGnGzSVw KLZO0K8l8D7Jo/SxWsQNwnPD+U+hlViQiF7h2yFkxOxwWX+DrbQ9EeEuZcYDrtuqZIMC ADBa3+MWH8pZtJRBs286UQaQoyl6KLeqJCrrHteVa0RVTBfROMzwnmVau39S+/GLDt5o JSLfKzqaguSfRrMhrlS+Zl3zu5GLpLnzTUJRxF+V5pD5Vww0JPvP6+AvSS518SFqzV/m Jo7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=G4X3tz6khmPVI8oYTe6aePTKoWXknBNeCwWeqfMv2Yqk44X8jVJD61rRaYuKaSKolB ndHQat7UyPNehZo4AY+0aQA7fTxGHD1qQ2FggoZ5XAWyUpWvKA0vA6aeRuckepUGfmh3 L2DCxAka4Q0HvzuUzI5g3Dqyq6WoZF28ouuT9ICIkF14lRsvUxIakIxF2P3Os5kB6zlY 1kndOaCe8i7PafgWHJnn8gutvHKXZSv+wVeE5YE6p4qwTFEeGL9MTi9XsER9v9/kFH5p rIxibxGjDbV4obG4TIxdxgQ5eK/6hajlru4v05qzbGq6+G/PQQsIUV/v/FmX/SBxtvjL tH6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PacZu67N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y14-20020a05620a25ce00b00767d04f2884si5962666qko.625.2023.08.22.00.11.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PacZu67N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLY5-0003uC-06; Tue, 22 Aug 2023 03:11:33 -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 1qYLXt-0003LX-K5 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:27 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXo-0002Qt-Ia for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:18 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fe8242fc4dso41086205e9.1 for ; Tue, 22 Aug 2023 00:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688274; x=1693293074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; b=PacZu67Nrm8q5JgiHQhA2mZ2Jbz2tdxzEeHbDXStFgxAoln6IqZHA3rDAvmFlG+fAb k2v8AIASlKiD/Da7V1ncbAl+VCWvfPcL+xkvIeJl83WzqY4m9rfgROVq23VWBqtsKJwE KRTiHXf39Kf+YKcBkaQknTjBlZQnw27+XJoYdfArlvFB7O4qXzndamDJX5vaqSBOrSRJ jG+ceW57SH/McuEzARsl2Jl7HtTuHeNEk91SVgXSZmZl8wcqZ65v+L6LB65o3qJrmnCU vEpOlxBEzWIz8VVV0AMQwsHRvP5nPzKQShAyHtoFO65maXJ1ED6VGiNKWUSnUo6Ah+4Q 3EJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688274; x=1693293074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; b=ND9Q5PsA+TaqjNfCDsNu/V4kyOcomRquyykgp400vnctQ75QKVtBLKFoazPJUkB/Rx x1vichmxVeqMPwDbxcs762mp2/OKIt16gf02PdGAc/09hUsQrtR+Q9jElJ3ti3DunVox AFICZRIe9OtFtwc3gyFHEiVqEq0KyFSWy8cObVC23OhyeoCsJ4QUjp8Lo2pLMWoi5YtH S3bX+1D+65bbsCqsrWlmATTy8vu2yj2v2uytlqcqgsCV+w5Mm9j/474bjvXAjoOfpnC1 UP3JZNdm7OZzCa9WkpFr2MP5tQFKJBjzNcdMOv8XASnoqybqaCqhNMp06X9ikkUaJ2P4 GONQ== X-Gm-Message-State: AOJu0YxJqFZjkM/kpw9ADlxH0Lsw20EFnGIXWn/QGLjJyF3zw+hQl3PT oNqLC+iz+UV75fl9f6PGD9ZbQURLC2opu+BahlplxA== X-Received: by 2002:a1c:4b0e:0:b0:3fe:c7fe:206c with SMTP id y14-20020a1c4b0e000000b003fec7fe206cmr6556451wma.23.1692688274783; Tue, 22 Aug 2023 00:11:14 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id e1-20020adfe7c1000000b0031b2c01f342sm8993223wrn.87.2023.08.22.00.11.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:11:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 09/19] target/loongarch: Truncate high 32 bits of address in VA32 mode Date: Tue, 22 Aug 2023 09:10:02 +0200 Message-ID: <20230822071013.34884-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen When running in VA32 mode(!LA64 or VA32L[1-3] matching PLV), virtual address is truncated to 32 bits before address mapping. Signed-off-by: Jiajie Chen Co-authored-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-6-gaosong@loongson.cn> --- target/loongarch/cpu.h | 6 +++++- target/loongarch/translate.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index e1562695e8..25a0ef7e41 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -445,7 +445,11 @@ static inline bool is_va32(CPULoongArchState *env) static inline void set_pc(CPULoongArchState *env, uint64_t value) { - env->pc = value; + if (is_va32(env)) { + env->pc = (uint32_t)value; + } else { + env->pc = value; + } } /* diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index 8b26555a27..9a23ec786d 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -86,6 +86,10 @@ void generate_exception(DisasContext *ctx, int excp) static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) { + if (ctx->va32) { + dest = (uint32_t) dest; + } + if (translator_use_goto_tb(&ctx->base, dest)) { tcg_gen_goto_tb(n); tcg_gen_movi_tl(cpu_pc, dest); @@ -212,11 +216,17 @@ static TCGv make_address_x(DisasContext *ctx, TCGv base, TCGv addend) { TCGv temp = NULL; - if (addend) { + if (addend || ctx->va32) { temp = tcg_temp_new(); + } + if (addend) { tcg_gen_add_tl(temp, base, addend); base = temp; } + if (ctx->va32) { + tcg_gen_ext32u_tl(temp, base); + base = temp; + } return base; } @@ -262,6 +272,10 @@ static void loongarch_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) } ctx->base.pc_next += 4; + + if (ctx->va32) { + ctx->base.pc_next = (uint32_t)ctx->base.pc_next; + } } static void loongarch_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)