From patchwork Thu Sep 13 06:34:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 183632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 380062C0084 for ; Thu, 13 Sep 2012 23:47:50 +1000 (EST) Received: from localhost ([::1]:53372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC9lk-0002nS-8P for incoming@patchwork.ozlabs.org; Thu, 13 Sep 2012 09:47:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC2yv-0001W8-6Z for qemu-devel@nongnu.org; Thu, 13 Sep 2012 02:32:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TC2yp-0007lL-E6 for qemu-devel@nongnu.org; Thu, 13 Sep 2012 02:32:57 -0400 Received: from dalsmrelay2.nai.com ([205.227.136.216]:17113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC2yp-0007lG-7W for qemu-devel@nongnu.org; Thu, 13 Sep 2012 02:32:51 -0400 Received: from DALEXHT2.corp.nai.org (unknown [10.64.5.52]) by dalsmrelay2.nai.com with smtp id 7ff5_00ec_305d0e80_b1b2_4003_a51f_331d74b8a5a0; Thu, 13 Sep 2012 01:32:50 -0500 Received: from DALEXAMMB3.corp.nai.org (10.64.48.8) by DALEXHT2.corp.nai.org (10.64.5.52) with Microsoft SMTP Server (TLS) id 8.3.279.1; Thu, 13 Sep 2012 01:30:56 -0500 Received: from localhost.localdomain (172.22.196.22) by mail.na.nai.com (10.64.48.8) with Microsoft SMTP Server id 8.3.279.1; Thu, 13 Sep 2012 01:30:55 -0500 From: To: , Date: Thu, 13 Sep 2012 16:34:20 +1000 Message-ID: <1347518060-16798-1-git-send-email-gerg@snapgear.com> X-Mailer: git-send-email 1.5.5.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 205.227.136.216 X-Mailman-Approved-At: Thu, 13 Sep 2012 09:47:32 -0400 Cc: Greg Ungerer Subject: [Qemu-devel] [PATCH] m68k: fix usp processing on interrupt entry and exception exit 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: Greg Ungerer The action to potentially switch sp register is not occurring at the correct point in the interrupt entry or exception exit sequences. For the interrupt entry case the sp on entry is used to create the stack exception frame - but this may well be the user stack pointer, since we haven't done the switch yet. Re-order the flow to switch the sp regs then use the current sp to create the exception frame. For the return from exception case the code is unwinding the sp after switching sp registers. But it should always unwind the supervisor sp first, then carry out any required sp switch. Note that these problems don't effect operation unless the user sp bit is set in the CACR register. Only a single sp is used in the default power up state. Previously Linux only used this single sp mode. But modern versions of Linux use the user sp mode now, so we need correct behavior for Linux to work. Signed-off-by: Greg Ungerer --- target-m68k/op_helper.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/target-m68k/op_helper.c b/target-m68k/op_helper.c index 1971a57..ac1a063 100644 --- a/target-m68k/op_helper.c +++ b/target-m68k/op_helper.c @@ -90,8 +90,8 @@ static void do_rte(void) env->pc = ldl_kernel(sp + 4); sp |= (fmt >> 28) & 3; env->sr = fmt & 0xffff; - m68k_switch_sp(env); env->aregs[7] = sp + 8; + m68k_switch_sp(env); } static void do_interrupt_all(int is_hw) @@ -134,10 +134,7 @@ static void do_interrupt_all(int is_hw) vector = env->exception_index << 2; - sp = env->aregs[7]; - fmt |= 0x40000000; - fmt |= (sp & 3) << 28; fmt |= vector << 16; fmt |= env->sr; @@ -147,6 +144,8 @@ static void do_interrupt_all(int is_hw) env->sr &= ~SR_M; } m68k_switch_sp(env); + sp = env->aregs[7]; + fmt |= (sp & 3) << 28; /* ??? This could cause MMU faults. */ sp &= ~3;