From patchwork Fri Apr 22 16:51:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1620947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=tbqVPiUI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KlLFG0mmfz9s0w for ; Sat, 23 Apr 2022 02:57:54 +1000 (AEST) Received: from localhost ([::1]:58074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhwbQ-0007fy-70 for incoming@patchwork.ozlabs.org; Fri, 22 Apr 2022 12:57:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhwWW-0008Sl-Pg for qemu-devel@nongnu.org; Fri, 22 Apr 2022 12:52:48 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:40787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhwWV-0007Cw-5w for qemu-devel@nongnu.org; Fri, 22 Apr 2022 12:52:48 -0400 Received: by mail-pl1-x62c.google.com with SMTP id k4so544507plk.7 for ; Fri, 22 Apr 2022 09:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=meOXfrn2PD5m0Qh1cBNLkWBSrBP+MRPsiz/DUB3aYZo=; b=tbqVPiUImFnthQK0yo86Pwsk9/imCz2d90C1cP3trX1+76OjpzqOerbEx5INy91u3p ywqaQzbIG2d+dXdLWY6ZAKitIAvFrB/rUInmYG+Xr7b1PjYJPw+MvTLKMuMXtlN9Rk5m 3+Ya7e3bGnTRiO2FlLi7/diAZYklHsUhLigu6XnKEiWIWkni88SJxlqeyykrcvAhkpqu /PoBv9RC7D9k69pS9AtcR20/7HRAlumI4OyGAw72Jg19ZoK3vpTgMdfcvLNvHmhkFKvc Fp+iz7CUumVIv0w2B7opNMf8h7eZAev8lxZuYJDzAS3eCPKOfSPuQqLuVcjRHl5Xq4JU 9q6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=meOXfrn2PD5m0Qh1cBNLkWBSrBP+MRPsiz/DUB3aYZo=; b=5iJDQAAxiL1Prtlwsd1HFMQyif85wzjm9H2xHyAsM3dmYAnI3CFJK8aAxhAp/u4VaX pC9A7iK0Ni0pmQBLRElOSObAoNqNzOUM8ZictjjwpN+WW2ebxt/5uJlwB0U1OjzhW8oP mQqnIc7sI3c50Seu1x4plj8DJYPQHZLT2G1E5GjB8+mw8eVeNrFgkdXwCM8j9feP2Wsn K0VXH0PCH5soqyv+mBjGURFNRf4qsIozCBXIafLN41FVeS8ukmHAyTSacmuMAG3w4FKa h1z+lYKB0gwVoo6Z/NYP4pAoDDZfWdzjVun+OVjG9LAqvBMKs1zbYcDvYye1eXyEx/Mi ytXg== X-Gm-Message-State: AOAM533sIGacSIq4YuLFn3kgDmkA5Elonl4KO+svFitvfw5wzNpLbUXD +YHBY2bzeBHwjN7G9Ix+cyD0g4Oq8waUtxfX X-Google-Smtp-Source: ABdhPJzDHDRwIkaxtfUfCRt3s/GTtmLUT4RszDH04Ud5p8wloTjhczRL4WuBRcE8AQ30fzOvbFJH9A== X-Received: by 2002:a17:90b:3b8f:b0:1d2:86e1:6e4d with SMTP id pc15-20020a17090b3b8f00b001d286e16e4dmr16965403pjb.186.1650646364241; Fri, 22 Apr 2022 09:52:44 -0700 (PDT) Received: from stoup.. ([2607:fb90:27d0:b0f2:934d:3e2:9f8c:dd1]) by smtp.gmail.com with ESMTPSA id 6-20020a17090a030600b001cd4989ff5fsm6835904pje.38.2022.04.22.09.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 09:52:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v8 01/68] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP Date: Fri, 22 Apr 2022 09:51:31 -0700 Message-Id: <20220422165238.1971496-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220422165238.1971496-1-richard.henderson@linaro.org> References: <20220422165238.1971496-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Note that this advance *should* be done by the translator, as that's the pc value that's supposed to be generated by hardware. However, that's a much larger change across sysemu as well. In the meantime, produce the correct PC for any signals raised by the trap instruction. Note the special case of TRAP_BRKPT, which itself is special cased within the kernel. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-Id: <20220421151735.31996-2-richard.henderson@linaro.org> --- linux-user/nios2/cpu_loop.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index 1e93ef34e6..2e9296750d 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -40,6 +40,12 @@ void cpu_loop(CPUNios2State *env) break; case EXCP_TRAP: + /* + * TODO: This advance should be done in the translator, as + * hardware produces an advanced pc as part of all exceptions. + */ + env->regs[R_PC] += 4; + switch (env->error_code) { case 0: qemu_log_mask(CPU_LOG_INT, "\nSyscall\n"); @@ -56,7 +62,6 @@ void cpu_loop(CPUNios2State *env) env->regs[2] = abs(ret); /* Return value is 0..4096 */ env->regs[7] = ret > 0xfffff000u; - env->regs[R_PC] += 4; break; case 1: @@ -69,6 +74,8 @@ void cpu_loop(CPUNios2State *env) break; case 31: qemu_log_mask(CPU_LOG_INT, "\nTrap 31\n"); + /* Match kernel's breakpoint_c(). */ + env->regs[R_PC] -= 4; force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->regs[R_PC]); break; default: @@ -99,7 +106,6 @@ void cpu_loop(CPUNios2State *env) o = env->regs[5]; n = env->regs[6]; env->regs[2] = qatomic_cmpxchg(h, o, n) - o; - env->regs[R_PC] += 4; } break; }