From nobody Wed May 15 18:43:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654384359; cv=none; d=zohomail.com; s=zohoarc; b=WVpjFd3RTpGsfuzoqMC0OdIrYBhOrMwonceoZPrJUfNuhOwB6kw0m8RoU39PwIYbXJslEKAquGkhoxf+w6hi6YJ/UZOY5TvWksUoo9Nhw8aYbiKjpI5jo8cFLB/2fTtC2xY8w6PaQOEeBhYtLJn1PNTtQwUfB3H3SNIWbJkX4B0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654384359; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WuXf3mRvUoBgdBHIfYWUJJXxwNA49V6B0JhTPyJnUA4=; b=QSVrayW6KWsRn6XU1qZhhpaZ/1QPb536nDZmokdrsXO5AZEcBGyMTUgOEtkY+gST1Kf+ZJcD8CApReod36D8eoMHoJs4qW/7B6eIqbe5UdO316AHvWP6HwwfvYTmq9tL1+TtP4NAhAnk+nSLWYn8DVG4p9CUWEKEVr7Tr1jUmdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654384359495167.05357839567523; Sat, 4 Jun 2022 16:12:39 -0700 (PDT) Received: from localhost ([::1]:58722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxcwf-0001tv-Ue for importer@patchew.org; Sat, 04 Jun 2022 19:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxcv4-0008KZ-3W for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:58 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:37436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxcuw-0004zj-3W for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:56 -0400 Received: by mail-pg1-x529.google.com with SMTP id h192so3236919pgc.4 for ; Sat, 04 Jun 2022 16:10:07 -0700 (PDT) Received: from bigtime.. ([2602:ae:1547:e101:250:b6ff:fe24:58ae]) by smtp.gmail.com with ESMTPSA id 184-20020a6302c1000000b003fcf1279c84sm5562151pgc.33.2022.06.04.16.10.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 16:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WuXf3mRvUoBgdBHIfYWUJJXxwNA49V6B0JhTPyJnUA4=; b=Wa9FxM1AS4PiwwH6hzszou6dMI7pPJGKNICZXvdEbdo25BL0XugoJWHi/7rQ7Btiw6 xn0vcYvyKVc55hEjU/xSDRtObHcUi4yB4PBqQb4Vm6SBdQT0XsiKxO0OiMqt+uCEoWMN EaotEqZpcdaYI6wBlw3DqBGHIks070z5ff587XYGnUZc+BDVV0yfkKW05Pryd4dnZSdj IzgbLy9xFGgv/UKZik86bgZiKfQqTOLPr5m+IdJwgHWxEbi1LVZ6ThINq6J+NVt8hvtE UjqrVYybI7D3tHBRnPcYDrY6Ws3slCLSeo7PqAogQK5QbSq+ZNlyOC4G0irqiRLZeD0N /vzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WuXf3mRvUoBgdBHIfYWUJJXxwNA49V6B0JhTPyJnUA4=; b=GvebBjDz7dj9gaCnO/o+2Q2RRQzU7+MQEIxTFnkmJ+zN7gIWSqAw4jakigjXv9qHaW 65a79gCAW0wrdIbJTRpAoOOPGY5kx2yDwyOPVvfJASqfzruvWpy9LIRi+1UoX+P1s7nh puaxMjwVA5JvyaPC+YfEpBGn5sW9qsz+3sPfbhzN3RpHN6xDyVpHXQ2sazdvZe6z4ksD ZmGDv1bvL4knEyhWk1vM8EBi+v+gd/zuejO+erZWpVO2TxQTfdu0BZAt+w/njEA5vqiz 3I61g1fxHqGlFTwceQJWWw8Snce2zhYEgzTRI/tx432VkbXfyTPKMsrAy4F1fX3Hvvrs 0iKw== X-Gm-Message-State: AOAM5318czprJYcCARaQd26Hk5d8fSNe2K1wg3BqSupH9ckJUYhgZpC/ F5wyLTd0y93l9yOnjel6fYXQWywztqPlAA== X-Google-Smtp-Source: ABdhPJzZjqaPRCa54zEGpVpkRzxQbSimW9DzbR7LDDEoq4aCd0jnUbfd7XXiU82EnZ4T56hSbbJQbg== X-Received: by 2002:a05:6a00:16cf:b0:51b:5f55:9bc with SMTP id l15-20020a056a0016cf00b0051b5f5509bcmr16703314pfc.7.1654384206711; Sat, 04 Jun 2022 16:10:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/3] target/riscv: Set env->bins in gen_exception_illegal Date: Sat, 4 Jun 2022 23:10:02 +0000 Message-Id: <20220604231004.49990-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604231004.49990-1-richard.henderson@linaro.org> References: <20220604231004.49990-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654384361017100003 Content-Type: text/plain; charset="utf-8" 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 --- 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 55a4713af2..9196aa71db 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -238,6 +238,8 @@ static void generate_exception_mtval(DisasContext *ctx,= int excp) =20 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); } =20 diff --git a/tests/tcg/riscv64/Makefile.softmmu-target b/tests/tcg/riscv64/= Makefile.softmmu-target new file mode 100644 index 0000000000..d51ece7023 --- /dev/null +++ b/tests/tcg/riscv64/Makefile.softmmu-target @@ -0,0 +1,21 @@ +# +# Aarch64 system tests +# + +TEST_SRC =3D $(SRC_PATH)/tests/tcg/riscv64 +VPATH +=3D $(TEST_SRC) + +LINK_SCRIPT =3D $(TEST_SRC)/semihost.ld +LDFLAGS =3D -T $(LINK_SCRIPT) +CFLAGS +=3D -g -Og + +%.o: %.S + $(CC) $(CFLAGS) $< -c -o $@ +%: %.o $(LINK_SCRIPT) + $(LD) $(LDFLAGS) $< -o $@ + +QEMU_OPTS +=3D -M virt -display none -semihosting -device loader,file=3D + +EXTRA_RUNS +=3D 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 */ + . =3D 0x80000000; + .text : { + *(.text) + } + .rodata : { + *(.rodata) + } + /* align r/w section to next 2mb */ + . =3D ALIGN(1 << 21); + .data : { + *(.data) + } + .bss : { + *(.bss) + } +} --=20 2.34.1 From nobody Wed May 15 18:43:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654384452; cv=none; d=zohomail.com; s=zohoarc; b=nmEqSxH9RDx0hALWcTTOaZhl+jjCh8Ztah/Dnaol+K309s48Rx/dXYfbb34HdJe+LCZvF5jhybvtGtQdstDO40sa5LcSR1tuOrJ7ZAA7YEwyILKRk3xV4nt2oAwMKMFm9+yo8KDB8hzOl83YMZwgi0JiFpXKN0RxSlkq4jZZ1MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654384452; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SwpxzSVSdURXSZL6tDOTL8VJqOtYjKYsT4i+YQrSyxQ=; b=cBIHgWohYPkVK6MkhNWAK9QW9AYB5fmuq+e2i6LM3MbpK36AGcN9n41+9Davs4Xc5m1uW7XSLTYU9C4MlH9LkK7FxG8peLE+aS/0FsMIpIUKFGUvJvcmjtdbFb6Qse/qghBdiDiCzw7yJLRuE5+olG56+en+1kU6Ye3S46F51iY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654384452172333.8985885960784; Sat, 4 Jun 2022 16:14:12 -0700 (PDT) Received: from localhost ([::1]:35004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxcyB-0004uQ-4z for importer@patchew.org; Sat, 04 Jun 2022 19:14:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxcv4-0008KX-3B for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:58 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:37438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxcuw-0004zn-2r for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:55 -0400 Received: by mail-pg1-x52b.google.com with SMTP id h192so3236932pgc.4 for ; Sat, 04 Jun 2022 16:10:08 -0700 (PDT) Received: from bigtime.. ([2602:ae:1547:e101:250:b6ff:fe24:58ae]) by smtp.gmail.com with ESMTPSA id 184-20020a6302c1000000b003fcf1279c84sm5562151pgc.33.2022.06.04.16.10.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 16:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SwpxzSVSdURXSZL6tDOTL8VJqOtYjKYsT4i+YQrSyxQ=; b=OTVmxmB2oatkUzmc1/AFsS0kABAwkqbsAQma65vN1fn08zKUmMwAC0x2rjHGQDFsuL 00Ufv7UcL+tyZsNfYQhi1OzTkZ96Gieelx/XDi2cRGW+u4s10hZSwMkeShfPndimHqQU Uge5Hx+kaP6sU1Bkfe+KkU1zk5pN1EQBcGM4f1R70iD9cEdskNfKK21W77pRj6faPs77 Yvg4/jqlpZthHpOqT9t+OL87K7631RNSufOoCPo8slkHTzFUwq9m6G/50dMbcOjTAT8J 08uOQng+SfmUhOIgLDFPSITTz56Gub+OgyLo06R+enJmZBAyp/Q1s7KR+vLyJDJ7ie5i NiYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SwpxzSVSdURXSZL6tDOTL8VJqOtYjKYsT4i+YQrSyxQ=; b=A84qvdECx8rfdNvjC8tAbZzHfUO+bG0/I79WMdKIVScRWdjL1HGGeiROrnK1qBmaY6 9Vu4/P8yjp8jF4LwWruDbvi5tsGNPuLvHsly8RwXgSKKisOfC9D5Nj7DxE7T/5DSLvA3 2vsKQrDTmubJSpInD1PkS9LK5e5Jve5Zvu5ZGyP//DCw7i81RZ7ety4N9vyAU0HyOI6t IAGUAysMxMILSfCaxnTQPtJW3Ivh+gsvCC9bo4+uORqdvLJ26aYmF26HrvomSD2bgZEw 7VMtBX2r0jZY9iPcGaby8C9UKGh7YP/bz6/kD/P0YdcQHq+Go2KkpIbQZmCw4jVW2RCu fIyA== X-Gm-Message-State: AOAM533gws2H1G90rH1aKUeYygo4yk7KzQz/QvzXpD7Cp6h30youfq4W T1VduKpmegZksDChJf56wX5TnRG79U5OHA== X-Google-Smtp-Source: ABdhPJw8ipSFgBm4Yr64bCN/wBxWyQ647KcVVad9uZZbVDP5BAjE+DTuKXk38SqBOWs2wUVsaEUAWA== X-Received: by 2002:a63:8a4c:0:b0:3fc:5c99:a195 with SMTP id y73-20020a638a4c000000b003fc5c99a195mr14498737pgd.29.1654384207422; Sat, 04 Jun 2022 16:10:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/3] target/riscv: Remove generate_exception_mtval Date: Sat, 4 Jun 2022 23:10:03 +0000 Message-Id: <20220604231004.49990-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604231004.49990-1-richard.henderson@linaro.org> References: <20220604231004.49990-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654384453029100001 Content-Type: text/plain; charset="utf-8" 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 --- 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 9196aa71db..6e4bbea1cd 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -228,14 +228,6 @@ static void generate_exception(DisasContext *ctx, int = excp) ctx->base.is_jmp =3D DISAS_NORETURN; } =20 -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 =3D DISAS_NORETURN; -} - static void gen_exception_illegal(DisasContext *ctx) { tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, @@ -245,7 +237,8 @@ static void gen_exception_illegal(DisasContext *ctx) =20 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); } =20 static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) --=20 2.34.1 From nobody Wed May 15 18:43:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654384364; cv=none; d=zohomail.com; s=zohoarc; b=j/2Sf7lVvrrVf7I0aF5ZFcevZlNTnQM91GNt1x9kTPDuYgYzFdbq3APyDsX0VYf9mgxn/ycsGWLL/y0hprabUAGccxv4Xvpt5H2x+B5nz05DtRHizDMh/4wuufj/FqZ7kq9OauG5eykaFwsjogj9oyn10Sj0Sn+bXZO1QEDNR6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654384364; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JEMAlLL3NGuLqFLBWL9oqhqscgsFoPyEqTMfa3vc+S8=; b=clJ0mfAbXMEfJgNo5zr+mD71fChu2WYvxReq1BPiFnNw3HE9tS7NypnpZj3LM+WvAAQqZU8an0b+COOa7UZzaSA2Q47sOrLPm9ePB+vm6laliN0qWHaSo44y8HOAiSqthBT9VEG/1D6ZbjsXfMTee5qWgtGnxqvqwfaSiFH/jLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654384363988647.2562010503008; Sat, 4 Jun 2022 16:12:43 -0700 (PDT) Received: from localhost ([::1]:58886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxcwk-00020B-8Y for importer@patchew.org; Sat, 04 Jun 2022 19:12:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxcv4-0008KT-2S for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:58 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:36541) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxcuw-0004zt-3L for qemu-devel@nongnu.org; Sat, 04 Jun 2022 19:10:56 -0400 Received: by mail-pj1-x102d.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so14919998pju.1 for ; Sat, 04 Jun 2022 16:10:09 -0700 (PDT) Received: from bigtime.. ([2602:ae:1547:e101:250:b6ff:fe24:58ae]) by smtp.gmail.com with ESMTPSA id 184-20020a6302c1000000b003fcf1279c84sm5562151pgc.33.2022.06.04.16.10.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 16:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JEMAlLL3NGuLqFLBWL9oqhqscgsFoPyEqTMfa3vc+S8=; b=Frkdx98CZ1FcgCAuEcGM8FPan83brN4LI40wr4L98tOsknCXdceLM+a3M6FIxorhlV VQ0p7IICyQGHTrNKqKuUkgXfXeYzb0DEZLhguFNcBqvWLf9NwdS3xgrOtxtH5uWD/mXz UNJKRkpRYDxV6fgktP1DjD+29JA+wlsfd+Er0d915SRLACJF0hRCwrHJZeg0Y+ucYrru O0WZbrJHLiSbnvdUrzMNcH9lY27g7ScYfP+WhqSGl5yUQcIh4Dg5/Fv4b9lmWGZU603R NDs/xfKEPWSIWRpnMvXstoupVYeyZ/X6m2BEjKI+ZzOohDNVchcXAklJPKWFT2EAvL1s lEXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JEMAlLL3NGuLqFLBWL9oqhqscgsFoPyEqTMfa3vc+S8=; b=DI/fcSFP0qWkEBG4j3HpIFv21akbXQaFOUpLnsbyEzNJ3kJhjbo8fmQrVMGmVg2FvL z510Xm/qFOSmxVM3ZriHVldZaKoWEFSaF4DquGE0JBEDA6i6rAPDuAVakH50NR40zfRM N6fEWrWmeky5dabcVruGezH+Pq4p457yj9aoUrhPc6HVafj9eI6uDn+an8S3ej7zpygf 5EgeQbmWIgGHMN3zQ8B2y2Uzh2Cso8kH5jJRS74nJ+nnaSB4lsX7fC5Wb1IKvs4ztSkW 1iA0yc/0ctBr+eEU+HhN7B1xrPcZHWEm75P1rdzaYEHl6E4IUG8dwgudKQ+jzx0qYRPz N1jw== X-Gm-Message-State: AOAM532+3e3k1SDOD19CUkI/wOqsiCsb3T8VX3EeFDitTou3MDJgpqAR VrAFouuppCt8A9YIpAT5GgTfCIMLdKlvbg== X-Google-Smtp-Source: ABdhPJxG124SUmYzxT9QXZ1+Sxo8q1Ms9u/L3C19ywLvI9+7Y7Tg/aLk/xnQWkd6pJbKVAquhZEWdg== X-Received: by 2002:a17:902:6505:b0:163:b040:829b with SMTP id b5-20020a170902650500b00163b040829bmr16631470plk.173.1654384208130; Sat, 04 Jun 2022 16:10:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/3] target/riscv: Minimize the calls to decode_save_opc Date: Sat, 4 Jun 2022 23:10:04 +0000 Message-Id: <20220604231004.49990-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604231004.49990-1-richard.henderson@linaro.org> References: <20220604231004.49990-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654384364669100001 Content-Type: text/plain; charset="utf-8" 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 --- 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 6e4bbea1cd..b328a7b2ff 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -204,6 +204,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); } =20 +static void decode_save_opc(DisasContext *ctx) +{ + assert(ctx->insn_start !=3D NULL); + tcg_set_insn_start_param(ctx->insn_start, 1, ctx->opcode); + ctx->insn_start =3D NULL; +} + static void gen_set_pc_imm(DisasContext *ctx, target_ulong dest) { if (get_xl(ctx) =3D=3D MXL_RV32) { @@ -633,6 +640,8 @@ static void gen_set_rm(DisasContext *ctx, int rm) return; } =20 + /* 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)); } =20 @@ -1011,13 +1020,6 @@ static uint32_t opcode_at(DisasContextBase *dcbase, = target_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" =20 -static inline void decode_save_opc(DisasContext *ctx, target_ulong opc) -{ - assert(ctx->insn_start !=3D NULL); - tcg_set_insn_start_param(ctx->insn_start, 1, opc); - ctx->insn_start =3D NULL; -} - static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opc= ode) { /* @@ -1034,7 +1036,6 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx, uint16_t opcode) =20 /* Check for compressed insn */ if (extract16(opcode, 0, 2) !=3D 3) { - decode_save_opc(ctx, opcode); if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { @@ -1049,7 +1050,6 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx, uint16_t opcode) opcode32 =3D deposit32(opcode32, 16, 16, translator_lduw(env, &ctx->base, ctx->base.pc_next + 2)); - decode_save_opc(ctx, opcode32); ctx->opcode =3D opcode32; ctx->pc_succ_insn =3D ctx->base.pc_next + 4; =20 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 =3D 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 =3D 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_tr= ans/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_sf= ence_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_sf= ence_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_tr= ans/trans_rvi.c.inc index f1342f30f8..cf17458022 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -822,6 +822,8 @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_= i *a) =20 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); --=20 2.34.1