From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KWSSg-0004Jf-GM for qemu-devel@nongnu.org; Fri, 22 Aug 2008 04:57:38 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KWSSf-0004J9-Dz for qemu-devel@nongnu.org; Fri, 22 Aug 2008 04:57:37 -0400 Received: from [199.232.76.173] (port=51509 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWSSf-0004Iz-9V for qemu-devel@nongnu.org; Fri, 22 Aug 2008 04:57:37 -0400 Received: from savannah.gnu.org ([199.232.41.3]:49173 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KWSSf-0001UD-2G for qemu-devel@nongnu.org; Fri, 22 Aug 2008 04:57:37 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KWSSe-00054g-AP for qemu-devel@nongnu.org; Fri, 22 Aug 2008 08:57:36 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KWSSe-00054W-2l for qemu-devel@nongnu.org; Fri, 22 Aug 2008 08:57:36 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Fri, 22 Aug 2008 08:57:36 +0000 Subject: [Qemu-devel] [5066] [sh4] delay slot bug fix Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5066 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5066 Author: aurel32 Date: 2008-08-22 08:57:35 +0000 (Fri, 22 Aug 2008) Log Message: ----------- [sh4] delay slot bug fix Two bugs about delay slot handlings are fixed. - After an exception occurred in delay slot, the branch instruction before delay slot should be executed again. To judge such re-execution is necessery or not, delay slot status is kept in SH4 CPU data structure. - When a branch instruction is placed at the end of memory segment, the delay slot is placed at the start of next memory segment. It means delay slot comes to the start of a translation block. In such occasion, DELAY_SLOT_CLAREME flag is used to transmit status between translation blocks. When an exception occurs on this kind of delay slot, DELAY_SLOT_CLEARME flag cause a status confusion in exception handling. DELAY_SLOT_CLEARME flag should be cleared on exceptions. And some items are added to CPU status dump. (Shin-ichiro KAWASAKI) Modified Paths: -------------- trunk/target-sh4/helper.c trunk/target-sh4/translate.c Modified: trunk/target-sh4/helper.c =================================================================== --- trunk/target-sh4/helper.c 2008-08-22 08:57:27 UTC (rev 5065) +++ trunk/target-sh4/helper.c 2008-08-22 08:57:35 UTC (rev 5066) @@ -157,6 +157,15 @@ env->sgr = env->gregs[15]; env->sr |= SR_BL | SR_MD | SR_RB; + if (env->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) { + /* Branch instruction should be executed again before delay slot. */ + env->spc -= 2; + /* Clear flags for exception/interrupt routine. */ + env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL | DELAY_SLOT_TRUE); + } + if (env->flags & DELAY_SLOT_CLEARME) + env->flags = 0; + if (do_exp) { env->expevt = env->exception_index; switch (env->exception_index) { Modified: trunk/target-sh4/translate.c =================================================================== --- trunk/target-sh4/translate.c 2008-08-22 08:57:27 UTC (rev 5065) +++ trunk/target-sh4/translate.c 2008-08-22 08:57:35 UTC (rev 5066) @@ -115,6 +115,10 @@ int i; cpu_fprintf(f, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n", env->pc, env->sr, env->pr, env->fpscr); + cpu_fprintf(f, "spc=0x%08x ssr=0x%08x gbr=0x%08x vbr=0x%08x\n", + env->spc, env->ssr, env->gbr, env->vbr); + cpu_fprintf(f, "sgr=0x%08x dbr=0x%08x delayed_pc=0x%08x fpul=0x%08x\n", + env->sgr, env->dbr, env->delayed_pc, env->fpul); for (i = 0; i < 24; i += 4) { cpu_fprintf(f, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n", i, env->gregs[i], i + 1, env->gregs[i + 1], @@ -1188,6 +1192,11 @@ if (old_flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) { if (ctx->flags & DELAY_SLOT_CLEARME) { gen_op_store_flags(0); + } else { + /* go out of the delay slot */ + uint32_t new_flags = ctx->flags; + new_flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL); + gen_op_store_flags(new_flags); } ctx->flags = 0; ctx->bstate = BS_BRANCH; @@ -1198,6 +1207,10 @@ } } + + /* go into a delay slot */ + if (ctx->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) + gen_op_store_flags(ctx->flags); } static inline void