All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Salter <msalter@redhat.com>
To: linux-mips@oss.sgi.com
Subject: another math emulation patch
Date: Sun, 2 Dec 2001 10:26:58 -0500	[thread overview]
Message-ID: <200112021526.fB2FQwF07112@deneb.localdomain> (raw)


I found another math emulation problem. The code that was failing
looked like this:

   bc1f  1f
    nop
   ...
 1:
   jr ra
    move v0,v1

When the bc1f is emulated and the branch is taken, mips_dsemul gets called
to emulate the delay slot insn. Before calling mips_dsemul, the branch
emulation code sets CAUSEF_BD. mips_dsemul checks for nop and bails out
early instead of going through the process of executing the insn. The
loop in fpu_emulator_cop1Handler will call cop1Emulate with the BD flag
set and epc pointing to the "jr ra" insn. cop1Emulate sees the BD flag
and calculates the continue PC based on the jr insn target address.
cop1Emulate then bails out because the move in the jr delay slot is not
a cop1 insn. This results in the program being restarted at the "jr ra"
target address and the move in the jr delay slot being ignored. This
only happens when a nop is in the cop1 branch delay slot because ds_emul
will have the cpu execute other insns and that will clear the BD flag.

The following patch fixes the problem by clearing the BD flag when ds_emul
returns directly in the case of a nop. 

--Mark

Index: cp1emu.c
===================================================================
RCS file: /cvs/linux/arch/mips/math-emu/cp1emu.c,v
retrieving revision 1.13
diff -u -p -5 -c -r1.13 cp1emu.c
cvs server: conflicting specifications of output style
*** cp1emu.c	2001/10/13 12:30:27	1.13
--- cp1emu.c	2001/11/30 23:15:33
*************** mips_dsemul(struct pt_regs *regs, mips_i
*** 788,797 ****
--- 788,798 ----
  	mips_instruction forcetrap;
  	extern asmlinkage void handle_dsemulret(void);
  
  	if (ir == 0) {		/* a nop is easy */
  		regs->cp0_epc = VA_TO_REG(cpc);
+ 		regs->cp0_cause &= ~CAUSEF_BD;
  		return 0;
  	}
  #ifdef DSEMUL_TRACE
  	printk("desemul %p %p\n", REG_TO_VA(regs->cp0_epc), cpc);
  #endif

             reply	other threads:[~2001-12-02 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-02 15:26 Mark Salter [this message]
2001-12-03  5:24 ` another math emulation patch Ralf Baechle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200112021526.fB2FQwF07112@deneb.localdomain \
    --to=msalter@redhat.com \
    --cc=linux-mips@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.