From patchwork Sun Jul 3 00:09:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 586786 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2698788mab; Sat, 2 Jul 2022 17:10:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sNVezFDcoRgZxn9nMrENGV+/eTCRddb2OU+jHCt6Co4cisF+9nah9Od8jeusip69Z/P5/Z X-Received: by 2002:a25:c505:0:b0:66c:93d0:cdab with SMTP id v5-20020a25c505000000b0066c93d0cdabmr23423001ybe.273.1656807058730; Sat, 02 Jul 2022 17:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656807058; cv=none; d=google.com; s=arc-20160816; b=wljeeO7fB46D9DChfN5H9Nx4npjEb3UduSfAlr4KYYeefj5gRDxVGH9/lVMUlw3e2q pHnxqj5IQLZENEEtELPJ8sjlONq/Oo/luk4gZ+wg71jGt0f43CyTnR7o5ygDeUFjbcsq PfVhOCVqoDqOeIWDiIK7Az5K4PM4xu25rkhT4W4TzDEcnAuzCUWbZMF/87asbVIhXLEQ 60qP6Bb6XO6YqaRgXIHsCfS3nk2mQRh0QgEjE2Nhh9s/SWLgpta0/rNfssT/NOQ+cJG7 5BUXxeHo05K6Ps6HSAuvsFDArNgZ69tqA14PwrpZ120A1Elsp3i+x2iGGcugiabcejpx iOjQ== 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:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=D3HuthXmCOSYjNEmAluM6vChJYoD51AL0IrrAWrdcDA=; b=B/DwbX07hppi2Cfw9EnQLUvizY6qFY8MmeMVPwT+tmEQO2kg+/Pcw0dYYOhSq1IaCb SowG2UwBheuVDy4oPXb/2PpzMwxVbidNSG2W1o525KcUNkzY9gSd3zbjMN2x3DUzIw8L uQPQAvuRUkiqEoUJKx8UxG/KLSgc5pZ44eR2kgDWOTAUSKVdQS98b7/2D1+ViLwKDZa1 DYsWpVe2gLHlDWN8uSQZKZpxcsDpRFDOviYA1yrFuFai5wQGYYJitCWaen7gz6PUHvF2 AjpGJTUifeGjRHgnAjLK1oeg9odhWnfTnxh/WaY7648WEf+lb0ZS84HJZ7AbRnUmMmqU CKbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PxH+i20i; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=j+TYVwn9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 185-20020a8111c2000000b0031c874861ccsi1693566ywr.262.2022.07.02.17.10.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Jul 2022 17:10:58 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PxH+i20i; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=j+TYVwn9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Received: from localhost ([::1]:34744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nCU-0001t0-4c for patch@linaro.org; Sat, 02 Jul 2022 20:10:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBT-0001s5-2Z for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:55 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:56111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBP-0000wE-Vg for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656806991; x=1688342991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iFrMNgZb795PtkupPWdOdfi4pfpHCJ8j6NfcibHYPh4=; b=PxH+i20imehQjwAGnFKD1jP00wStjSUJyUNyX0oNXdKFOSpwUQncruRJ 2MYeujXzmaxhql7/0eqLNXqKXs/+K6EjLUh+eGOnnn+43YeOf4Wubbekn OzvjGgSFwfiDhxxswduLrddsMWqRTH5cax5k0kBYNeXOjPrrbVgd7dapg 43ODswAIDzX15xMGGL1SO1HzLs2+EtdzbfLxpX0JOKwdP5UM29jzldnQ0 xEzXID0wSMc1xeEq3gtrzkfIyKt1MhU6DmpWfPwai8BASZOVmak6b5ehx fiMokPSyJBNXBTtIJCIqUVha24Fn0I+VMfx0p8OJbhsohMTUOEyJV13U9 w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="308989614" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:09:50 +0800 IronPort-SDR: o7CxOGtjuveIrf1lzF9AixbPljRAMEIpKlcdok3xpcbMJI7aNaIAuGZMB3kWo64VbBif6cNhig 7wIfvJym30l/9an8sYq8A9Z/0l7jtgerbu7hB5gVnYcDOev/ACedS32ye2qN+MZ0DQfWoYQ5aR daoZucLPUnFmzB7asA5lkSX0mkCGzVO+/0VtIjJ75U+38q/iXxglpRJMfIVhPD2fk29SohLOpr SCghsnZcNscqyOF+QZz2qv8e9mZ9u6a1LkIu1b3JFPAN5lTrAAl3alKxohjdQDBEgs8k6olRx8 oZK78c7ECLmzyyfWyvIEjurw Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:27:12 -0700 IronPort-SDR: 0W/0PQNTvugA8fEOIpHxcgvwRJxG4szJgM/Kn7g7kHEGe/YWU9mPcPS/Oq59rRoTr5Lij7LQE7 rPazdijxLBWexVs5fNwqWBiBZd7nIVCRrOe6yOve5TxV1KaAIdFSiV4Ig18lVU9xz1aBsrCwdY tsPz3rt46fSn4VzpI6k9jsRmZCgME8ddicuNP21AAGGqLniFWzHXFFqb5iWUxmCd1YKyfG5Rjq zqRJvrRhyCHCOO0cyF1fi0YJB67qLOj5v3m1KAiKflChyeAupkHc8cSpLrLdTKfvXBYc/Z07tl 8ug= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:09:50 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8St49Jdz1Rwnx for ; Sat, 2 Jul 2022 17:09:50 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656806989; x=1659398990; bh=iFrMNgZb795PtkupPW dOdfi4pfpHCJ8j6NfcibHYPh4=; b=j+TYVwn9MFmg8z0NZADXS0hgXXJp6X7IUM Cu8/o8HFiP4605k0VMyLpN19q7lNZqyHwcDiGMVzuqt+hobA8raFBkOvLJZU6JLX GLR+FziDSj+T8VuriT/CVAWpk63Xu47GgA4PbnfqzQfsCAbO2CH0h8xVPvi/6Umk vSTP/Prjt2Ahx9Jed2qFpApErB+A+SwV6b8iz7fhvElq0E4Z5dZ/6KfsCt9FHtd0 xxRRTmtp3sDY8gg02zmU1rTrzKBj49CEUemutepK0dfAMASDO/W/fGS07GFkT0OL USyLutrXg+1ev+J3AJrKawg6D9eMRa4OHjeNV8i96DO9assbK3Fg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id csbFcRCuSYUV for ; Sat, 2 Jul 2022 17:09:49 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Sr3p8lz1Rwnm; Sat, 2 Jul 2022 17:09:48 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL 02/19] target/riscv: Set env->bins in gen_exception_illegal Date: Sun, 3 Jul 2022 10:09:21 +1000 Message-Id: <20220703000938.437765-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> References: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Richard Henderson While we set env->bins when unwinding for ILLEGAL_INST, from e.g. csrrw, we weren't setting it for immediately illegal instructions. Add a testcase for mtval via both exception paths. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1060 Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-2-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 2 + tests/tcg/riscv64/Makefile.softmmu-target | 21 +++++++++ tests/tcg/riscv64/issue1060.S | 53 +++++++++++++++++++++++ tests/tcg/riscv64/semihost.ld | 21 +++++++++ 4 files changed, 97 insertions(+) create mode 100644 tests/tcg/riscv64/Makefile.softmmu-target create mode 100644 tests/tcg/riscv64/issue1060.S create mode 100644 tests/tcg/riscv64/semihost.ld diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b151c20674..a10f3f939c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -240,6 +240,8 @@ static void generate_exception_mtval(DisasContext *ctx, int excp) static void gen_exception_illegal(DisasContext *ctx) { + tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, + offsetof(CPURISCVState, bins)); generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST); } diff --git a/tests/tcg/riscv64/Makefile.softmmu-target b/tests/tcg/riscv64/Makefile.softmmu-target new file mode 100644 index 0000000000..e22cdb34c5 --- /dev/null +++ b/tests/tcg/riscv64/Makefile.softmmu-target @@ -0,0 +1,21 @@ +# +# RISC-V system tests +# + +TEST_SRC = $(SRC_PATH)/tests/tcg/riscv64 +VPATH += $(TEST_SRC) + +LINK_SCRIPT = $(TEST_SRC)/semihost.ld +LDFLAGS = -T $(LINK_SCRIPT) +CFLAGS += -g -Og + +%.o: %.S + $(CC) $(CFLAGS) $< -c -o $@ +%: %.o $(LINK_SCRIPT) + $(LD) $(LDFLAGS) $< -o $@ + +QEMU_OPTS += -M virt -display none -semihosting -device loader,file= + +EXTRA_RUNS += run-issue1060 +run-issue1060: issue1060 + $(call run-test, $<, $(QEMU) $(QEMU_OPTS)$<) diff --git a/tests/tcg/riscv64/issue1060.S b/tests/tcg/riscv64/issue1060.S new file mode 100644 index 0000000000..17b7fe1be2 --- /dev/null +++ b/tests/tcg/riscv64/issue1060.S @@ -0,0 +1,53 @@ + .option norvc + + .text + .global _start +_start: + lla t0, trap + csrw mtvec, t0 + + # These are all illegal instructions + csrw time, x0 + .insn i CUSTOM_0, 0, x0, x0, 0x321 + csrw time, x0 + .insn i CUSTOM_0, 0, x0, x0, 0x123 + csrw cycle, x0 + + # Success! + li a0, 0 + j _exit + +trap: + # When an instruction traps, compare it to the insn in memory. + csrr t0, mepc + csrr t1, mtval + lwu t2, 0(t0) + bne t1, t2, fail + + # Skip the insn and continue. + addi t0, t0, 4 + csrw mepc, t0 + mret + +fail: + li a0, 1 + +# Exit code in a0 +_exit: + lla a1, semiargs + li t0, 0x20026 # ADP_Stopped_ApplicationExit + sd t0, 0(a1) + sd a0, 8(a1) + li a0, 0x20 # TARGET_SYS_EXIT_EXTENDED + + # Semihosting call sequence + .balign 16 + slli zero, zero, 0x1f + ebreak + srai zero, zero, 0x7 + j . + + .data + .balign 16 +semiargs: + .space 16 diff --git a/tests/tcg/riscv64/semihost.ld b/tests/tcg/riscv64/semihost.ld new file mode 100644 index 0000000000..a59cc56b28 --- /dev/null +++ b/tests/tcg/riscv64/semihost.ld @@ -0,0 +1,21 @@ +ENTRY(_start) + +SECTIONS +{ + /* virt machine, RAM starts at 2gb */ + . = 0x80000000; + .text : { + *(.text) + } + .rodata : { + *(.rodata) + } + /* align r/w section to next 2mb */ + . = ALIGN(1 << 21); + .data : { + *(.data) + } + .bss : { + *(.bss) + } +} From patchwork Sun Jul 3 00:09:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 586788 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2700003mab; Sat, 2 Jul 2022 17:13:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZwUa83nsYShtW3pDyHULth26LYiD01P9nG2lSa6i49kE+MPM0gLb8/ioC48abMTo1PqH3 X-Received: by 2002:a81:658a:0:b0:31c:7571:7c97 with SMTP id z132-20020a81658a000000b0031c75717c97mr7861163ywb.514.1656807233143; Sat, 02 Jul 2022 17:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656807233; cv=none; d=google.com; s=arc-20160816; b=iQKm9M+Mi47kpKn/yN5uc5TjXZM3FDI1oZ2JZf2H1bz3DtRa/v6GGxQYihlA6n4e2w WinQ2DCKZhv1xkRfVgpGm8ru9fELmlfcQEbSUKY6KKMyC9S7/eqs2lQEZLpIXiWRTf2U aYdkuIWy/YXraFxrhEW+DWgiG8JqF6C8iuM3N4tzF2YRk9wP4xYJ7DAViIFQED1t7YG3 +SrSUtm3SzcXXf2O5En3kNOa5BTDIEvx+ZRu8kv7jZNS+kymQuHeCC0dXMxnio4usteG vM51Y8q+onRh8NQ1nNEEVYfO+AsaqNdYL7SELV2oShGuC4Gl+sIOLu529amfZ/6eSIj2 +zTA== 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:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=foxXdZusDryFqwMtXUjdPue7AebkEcQobI56aA4EfhM=; b=jRsT4FJAZU1n4ds4EzUsZ6SGyfVZHMgWw+pZZXpZKaPDT1SEea9JdH2190zT9Ekq0P +Vl7UEQUx6nuYVzuhqfhIm5dgwldg9pdgyI7E+v8WcBtxdoISh1jbCy18nQPMLnWmTxL MkXRdOIiu3XDiA3q/YL0nISLGHgAZ2fmeCfiknpyIp3xv0HcCW4pwjdsv1M8fwT4sadI pNRyhirjGdw7ualksGjsOKbTDbYywN4x3hmF99DGRbKRxc1I/m4J4tfzMPJ+42vXPDui E+ZEpZh85CjHtzOuVclOnGS905LyLg6kjoW51DT2tmB+hnxAWZdz+ufkufsnoSymgxtk 9lJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=exOOWSFV; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=nnI3qnQ6; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 185-20020a8118c2000000b0031c7aa46da6si4984721ywy.329.2022.07.02.17.13.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Jul 2022 17:13: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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=exOOWSFV; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=nnI3qnQ6; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Received: from localhost ([::1]:43336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nFI-0007cR-LU for patch@linaro.org; Sat, 02 Jul 2022 20:13:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBU-0001sk-Nc for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:56 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:56111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBT-0000wE-4Z for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656806994; x=1688342994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XOGoS+LaSNx9ztfN+554+3MJdJHKkwrfOy2g668jrT8=; b=exOOWSFVG54abgVW+LnB2X9xcnvdpVcoljGnZJePkJuVwGsf/KfWV+RP u+VWk5twfEqLY75US7mvdhbmkPmlrT3SYHAARrD8ebj65/1r37uMRFXLo gAKD9pIvo0Zahsv1TER2ZP+fcT8iTbiQq3cx6UTD0fU808Jx1C/YHZUde H0asBqldLwYErGOsk+E1QsG9yj8MNC/7Jym3HZunqdE4GW2cFj8r28Jh7 oUSH8jMv+GlX2JWH7dTMvHv2PWuk8rSkLVsrTJsMcqvQGtlSkLUnehjxA y5byNoKktpBYK+KTy3MFWdhn9c48dsPIBgvWnSb0vZ7jQc6oVCXVnSWdS Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="308989616" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:09:51 +0800 IronPort-SDR: Nb4TuMjuPh8U9RVwoGlN/L9+6QPR0H0FN6XqT9ZCkwUEdXrgfeBKx0lbpFSpOPuNdNQbG7i0Uf O1CBMwQzizIdTNHgIt0dfTHxLWXO0IpSyDxLO7paSigd2BuaVPy5lDjNL5kSHY4JhxF1FlFbpa cjddFiFsA3lLKgSdUkpPNrscDyLyCTY6AvzKOTMV2DFKK9uY0xiR8rRkvxUX9Eai9F5sv1CF3Q igxbDYjZb4RAZkSJd9XH/8tSc6csBvmAJX84BFw9TQ/WgcHVqcMPbWzUike70eLOBFijIqyZC6 medBBqTmH2Z9gHGP+LuGZUUs Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:27:14 -0700 IronPort-SDR: xAOOH56R4hCcK+6m/r0yDBSA6Kz/80DnbnySOMGy+loGY22bEbcZlDxr6eW9e2duYa1L+ISPhn g32lSENbJljWxC49sGJZk8Fyu1oTukPO8qkxZJeYyIzcLDYfMtKa3RjYA7YrtEs2rLIfYyRCx8 Zixh8/SlooTlQKckECjVr9afI3Fze+i1+viuV+e5VGISiI6FT1eG2RVXprFS0i1HFd5AdPwep3 v1Akeou/GRT3AXRVEXRCaDfBJLdnzH9u8vEAaEQ4E49IvEkRlw0NDq1CROjLBSV9sIrRYuJIZJ 8XM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:09:52 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Sv5SDxz1Rwnl for ; Sat, 2 Jul 2022 17:09:51 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656806991; x=1659398992; bh=XOGoS+LaSNx9ztfN+5 54+3MJdJHKkwrfOy2g668jrT8=; b=nnI3qnQ697vJNOpMtWXx/8bRCfC/NC3sYD pLb29ubCkVNSUTBu+2dRQb0pM0TMUU9k4L4bMnYjfXRcaNOX4TGhyGZxr39sUaCc Qv8q/yzGn+ZFUBjruEC8CHQYBZotibXZE1WTJ06reCfulibkxNo6R/WgIet/Acp0 vTaR+frLy7YIvRkEkLCjASkjpNkW7LS21nquflbG3RbOQKK/yxg6y7NKSnl3fa9N fntyP0QlXfNnGnXOoRR2OCZgre4v+slswiqSsLKzmmOOf2TcRdqFhWztHiGvMSTk /tCsEILUo1nO6OBO69AEUeCdD9NGi0GYQWkpd7tMHkrm02pPiptQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id aRpVCw5szKDe for ; Sat, 2 Jul 2022 17:09:51 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8St23vHz1RtVk; Sat, 2 Jul 2022 17:09:50 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL 03/19] target/riscv: Remove generate_exception_mtval Date: Sun, 3 Jul 2022 10:09:22 +1000 Message-Id: <20220703000938.437765-4-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> References: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Richard Henderson The function doesn't set mtval, it sets badaddr. Move the set of badaddr directly into gen_exception_inst_addr_mis and use generate_exception. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-3-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a10f3f939c..7205a29603 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -230,14 +230,6 @@ static void generate_exception(DisasContext *ctx, int excp) ctx->base.is_jmp = DISAS_NORETURN; } -static void generate_exception_mtval(DisasContext *ctx, int excp) -{ - gen_set_pc_imm(ctx, ctx->base.pc_next); - tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); - gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp)); - ctx->base.is_jmp = DISAS_NORETURN; -} - static void gen_exception_illegal(DisasContext *ctx) { tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, @@ -247,7 +239,8 @@ static void gen_exception_illegal(DisasContext *ctx) static void gen_exception_inst_addr_mis(DisasContext *ctx) { - generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS); + tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); + generate_exception(ctx, RISCV_EXCP_INST_ADDR_MIS); } static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) From patchwork Sun Jul 3 00:09:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 586787 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2698813mab; Sat, 2 Jul 2022 17:11:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vpsgwW5w/Ez1Zz9rI6XWXVXQQt+isTJGl7m5tulu5rEGPR0xc3tuHfOZavPQYMKYkYC22h X-Received: by 2002:a0d:d489:0:b0:31c:7b72:e1e4 with SMTP id w131-20020a0dd489000000b0031c7b72e1e4mr6487158ywd.300.1656807061081; Sat, 02 Jul 2022 17:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656807061; cv=none; d=google.com; s=arc-20160816; b=rj+UB6X3lgKghdZGTSAr1cWKPHRFVq1PhEb5Bd6YH3R3Z/sSIGxbE5IbB83yqgZMxH SaBSFLG01nkCCVkDQngw5l4vWRZX70O1BCGFdiBpPp0uZ9oEnv3on2fA055TGpWQ7tza hnHcRMwlfIXTTpkW2+N5Kkc5U3Or8mpdN3XEnhVe+ttZar89fjspV6fEmuxT1wNuTT3z UjvGrFXvnM2dSoVREUcMk2xsW/5xF0RYsc4wi2F3gN1D6V9brOP7c6jse4ro0vU4E6Di L10rjfPg7U3EhivPzeonbEwUXVYaQdEmBAWwktLbVZhML17QruyjgjrJYww7aEq4le21 ie+w== 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:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=LSFsAoDeoONsgsJfxHokMc3ITKSPM7S2Jw7bcRbBQRM=; b=p+cC1Ez1Uj6UZEeO5houM+PFjKqFazOlfqwhj8ht8Gc4LcA0xgWX1zN2Bkt5UKl7Gc 0DI+Mv6TWzRnC4auO9lqianZ4I3fOH2mLp86MJktvFS7YpbTJdHlYm9B+TkCNtzt5VV/ zfwjcNoByThOMqmIWjFTU+wsPBLdC/Xd3OrBGAPxUsCw0eu9sGjzHMqo4yFOfxiT4JSp O5SLObBSwpg7EkKfFTmyPigbryEkOtnEnE5EhcDh9bJjx+tMAjB6cTayocg5+P9MSZP7 ex7P//DcAZpPevq+Ir7pC3RExbO8MoLCFHrgBVfB6NoNuCZw7WEK6LRuGSt2BQO6kxIT JNSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=gstQbC0P; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=gB7Mnieb; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 129-20020a250087000000b0066d34bc4af4si18835306yba.294.2022.07.02.17.11.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Jul 2022 17:11:01 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=gstQbC0P; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=gB7Mnieb; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Received: from localhost ([::1]:34804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nCW-0001vP-IP for patch@linaro.org; Sat, 02 Jul 2022 20:11:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBV-0001t1-29 for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:57 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:56108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nBT-0000vh-4S for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:09:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656806994; x=1688342994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/hrKk5p20kxaD0zCjNEk9cveWwf20tx/Gzwy08mr1wY=; b=gstQbC0Pd8ONR/r2l1ThPHEftqyXqSxH59LUGkzoaYcMR4ZeULnxcaI0 zhk92KSV34PCQ+JaLZds0/6fhlDfOnnYsiTjBslyfZaY4qQA3cDOFTjas JxkhEfMJcxGvheQmQJHHuLi/siHy8fYxq6BnGcFceaW8AtbN/aEWLLRVI o4+VzyDxtruTnADYDbrKusxP5ikS7DxB41KkLSZM4yXjxzXvhql+t2vrB f0XPkxKUb9IJcA0m5tPIXhUipGvgzYTkIF7BVN9I5S6zazTh3zFJxFDFM hB8KSp6mIKaQWvcpdqRx5+9JANmwUoebAYkrpRh1qnVORTb9gLXKg0Edb w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="308989617" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:09:53 +0800 IronPort-SDR: 2X5vgCX/ZRxLl2N+zyOsYSOAvDTBRL4gzDlOLJVdpfyqopT2iXxJh0VBf//OK8/JSMy39gZpV/ V5qGDFLnzUyOJq6i8ReRjI5Ziq4Oxud1upFOTpoLjAZFfLN55+y4hLxYpiHm/rgB9FOJEDjXcR vf4135rniKWDEXxHWr6greCbdcdcl1vn+fGyjTPQhOobiv7r95P6Wu7ljbwoe+V5oDFEfST3TR W1YYisE0jCQhJjihFsrc3UUcjijRPr+F7Lp4FO5TA5odvsN6WJ60nMfISJcSab5d4gu6T/y6jn ANDL9VzXjEIcTSysMnCTuF7a Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:27:15 -0700 IronPort-SDR: 4GUWQa0Y3nsbmhxChaNr0Cy/ql9K+ucPu/UvO+UTHvWIdsleWk3DzIBOpEe2TJenltmi9y+8sE 0RpPQLhMx5/y6ek8Mk3enkWfehcrSB2RKCoK753MQFX6Pz1Aimq6lXYbHd67GE9ONf7tgcplr1 VTFRaSFvxbmd15x0wiWYx3ZNalBPyCF3MWO7z7lMEtLKa0DPCvzpLn3Dbm0Fu9xY6wckYdvMMx gAw9/dxH3NYBsYN0xUgQyBXg1ZKkRXdocnu5NuACF97/FxaKiZ/zfGL91Ua2KoaooU/CUnLeTc de0= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:09:54 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Sx4GmKz1Rwnx for ; Sat, 2 Jul 2022 17:09:53 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656806992; x=1659398993; bh=/hrKk5p20kxaD0zCjN Ek9cveWwf20tx/Gzwy08mr1wY=; b=gB7Mniebf4zKmlt2AM2S8QIHRe5ND996Ti VX6WcxDn5G+PPURqrajQPWUBonGwDwZ4qXICtLCSotSnwqKyu0GGCt4jV63IP2h9 jYurUVKqa3SfKbRsWenr/4SZ6PTVFF3LAMhF0my7h9gzpA1mKCUyZz1YEWPaGMuG Vic9IQffoF60C+BqldLeo3IdkfOtrNmCot7ht3j6sFk2kfCtB4qXZQFpbuVbpkvW ACnu51onL8C0tM4lpUGWHVaBMGvzE1DhiACnEGof8dixq3jgNUyuW2IBQ/qApBI2 mF04hZEihX/C07Wiq7UPTNjxa8ow8BIaBV2QqUNLygLRZkN8HiZA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id c2dLf0HaOGxl for ; Sat, 2 Jul 2022 17:09:52 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Sv5TP8z1Rwnm; Sat, 2 Jul 2022 17:09:51 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL 04/19] target/riscv: Minimize the calls to decode_save_opc Date: Sun, 3 Jul 2022 10:09:23 +1000 Message-Id: <20220703000938.437765-5-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> References: <20220703000938.437765-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Richard Henderson The set of instructions that require decode_save_opc for unwinding is really fairly small -- only insns that can raise ILLEGAL_INSN at runtime. This includes CSR, anything that uses a *new* fp rounding mode, and many privileged insns. Since unwind info is stored as the difference from the previous insn, storing a 0 for most insns minimizes the size of the unwind info. Booting a debian kernel image to the missing rootfs panic yields - gen code size 22226819/1026886656 + gen code size 21601907/1026886656 on 41k TranslationBlocks, a savings of 610kB or a bit less than 3%. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-4-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 18 +++++++++--------- target/riscv/insn_trans/trans_privileged.c.inc | 4 ++++ target/riscv/insn_trans/trans_rvh.c.inc | 2 ++ target/riscv/insn_trans/trans_rvi.c.inc | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 7205a29603..63b04e8a94 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -206,6 +206,13 @@ static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64 in) tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan); } +static void decode_save_opc(DisasContext *ctx) +{ + assert(ctx->insn_start != NULL); + tcg_set_insn_start_param(ctx->insn_start, 1, ctx->opcode); + ctx->insn_start = NULL; +} + static void gen_set_pc_imm(DisasContext *ctx, target_ulong dest) { if (get_xl(ctx) == MXL_RV32) { @@ -635,6 +642,8 @@ static void gen_set_rm(DisasContext *ctx, int rm) return; } + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ + decode_save_opc(ctx); gen_helper_set_rounding_mode(cpu_env, tcg_constant_i32(rm)); } @@ -1013,13 +1022,6 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" -static inline void decode_save_opc(DisasContext *ctx, target_ulong opc) -{ - assert(ctx->insn_start != NULL); - tcg_set_insn_start_param(ctx->insn_start, 1, opc); - ctx->insn_start = NULL; -} - static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) { /* @@ -1036,7 +1038,6 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) /* Check for compressed insn */ if (extract16(opcode, 0, 2) != 3) { - decode_save_opc(ctx, opcode); if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { @@ -1051,7 +1052,6 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) opcode32 = deposit32(opcode32, 16, 16, translator_lduw(env, &ctx->base, ctx->base.pc_next + 2)); - decode_save_opc(ctx, opcode32); ctx->opcode = opcode32; ctx->pc_succ_insn = ctx->base.pc_next + 4; diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc index 53613682e8..46f96ad74d 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -75,6 +75,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) { #ifndef CONFIG_USER_ONLY if (has_ext(ctx, RVS)) { + decode_save_opc(ctx); gen_helper_sret(cpu_pc, cpu_env); tcg_gen_exit_tb(NULL, 0); /* no chaining */ ctx->base.is_jmp = DISAS_NORETURN; @@ -90,6 +91,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) static bool trans_mret(DisasContext *ctx, arg_mret *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_mret(cpu_pc, cpu_env); tcg_gen_exit_tb(NULL, 0); /* no chaining */ ctx->base.is_jmp = DISAS_NORETURN; @@ -102,6 +104,7 @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) static bool trans_wfi(DisasContext *ctx, arg_wfi *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_set_pc_imm(ctx, ctx->pc_succ_insn); gen_helper_wfi(cpu_env); return true; @@ -113,6 +116,7 @@ static bool trans_wfi(DisasContext *ctx, arg_wfi *a) static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_tlb_flush(cpu_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc index cebcb3f8f6..4f8aecddc7 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -169,6 +169,7 @@ static bool trans_hfence_gvma(DisasContext *ctx, arg_sfence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_hyp_gvma_tlb_flush(cpu_env); return true; #endif @@ -179,6 +180,7 @@ static bool trans_hfence_vvma(DisasContext *ctx, arg_sfence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_hyp_tlb_flush(cpu_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc index c190a59f22..ca8e3d1ea1 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -818,6 +818,8 @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a) static bool do_csr_post(DisasContext *ctx) { + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ + decode_save_opc(ctx); /* We may have changed important cpu state -- exit to main loop. */ gen_set_pc_imm(ctx, ctx->pc_succ_insn); tcg_gen_exit_tb(NULL, 0);