From patchwork Sun Sep 20 20:53:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 520054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D7F9A140772 for ; Mon, 21 Sep 2015 07:15:58 +1000 (AEST) Received: from localhost ([::1]:53665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdleK-0006Mz-Su for incoming@patchwork.ozlabs.org; Sun, 20 Sep 2015 16:55:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdlbx-0004it-Kr for qemu-devel@nongnu.org; Sun, 20 Sep 2015 16:53:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zdlbs-0008Ty-HT for qemu-devel@nongnu.org; Sun, 20 Sep 2015 16:53:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:37797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdlbs-0008TJ-8I; Sun, 20 Sep 2015 16:53:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 283B6ADD8; Sun, 20 Sep 2015 20:53:19 +0000 (UTC) From: Alexander Graf To: qemu-ppc@nongnu.org Date: Sun, 20 Sep 2015 22:53:15 +0200 Message-Id: <1442782398-41762-5-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1442782398-41762-1-git-send-email-agraf@suse.de> References: <1442782398-41762-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: Peter Maydell , qemu-devel@nongnu.org, Anton Blanchard Subject: [Qemu-devel] [PULL 4/7] target-ppc: Fix SRR0 when taking unaligned exceptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Anton Blanchard We are setting SRR0 to the instruction before the one causing the unaligned exception. A quick testcase: . = 0x100 .globl _start _start: /* Cause a 0x600 */ li 3,0x1 stwcx. 3,0,3 1: b 1b . = 0x600 1: b 1b Built into something we can load as a BIOS image: gcc -mbig -c test.S ld -EB -Ttext 0x0 -o test test.o objcopy -O binary test test.bin Run with: qemu-system-ppc64 -nographic -bios test.bin Shows an incorrect SRR0 (points at the li): SRR0 0000000000000100 With the patch we get the correct SRR0: SRR0 0000000000000104 Signed-off-by: Anton Blanchard Signed-off-by: Alexander Graf --- linux-user/main.c | 2 +- target-ppc/excp_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 782037d..25cf875 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -1650,7 +1650,7 @@ void cpu_loop(CPUPPCState *env) info.si_signo = TARGET_SIGBUS; info.si_errno = 0; info.si_code = TARGET_BUS_ADRALN; - info._sifields._sigfault._addr = env->nip - 4; + info._sifields._sigfault._addr = env->nip; queue_signal(env, info.si_signo, &info); break; case POWERPC_EXCP_PROGRAM: /* Program exception */ diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c index b803475..4250106 100644 --- a/target-ppc/excp_helper.c +++ b/target-ppc/excp_helper.c @@ -200,7 +200,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) /* Get rS/rD and rA from faulting opcode */ env->spr[SPR_DSISR] |= (cpu_ldl_code(env, (env->nip - 4)) & 0x03FF0000) >> 16; - goto store_current; + goto store_next; case POWERPC_EXCP_PROGRAM: /* Program exception */ switch (env->error_code & ~0xF) { case POWERPC_EXCP_FP: