[Top] [All Lists]

Re: Unexpected behaviour when catching SIGFPE on FPU-less system

To: "Kevin D. Kissell" <>
Subject: Re: Unexpected behaviour when catching SIGFPE on FPU-less system
From: Shane McDonald <>
Date: Tue, 4 May 2010 06:56:08 -0600
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=haJAor6uk6i7dggpbjKmgukAwtf3Iy9KXCovjQg42ls=; b=V6J6LJ0soxkWKU8gebSGQiGo5LEtR8esPmjyo3Nh102XGxRK22C7DQKNSbxfIg9LYA 8RUq9lcWBReG1sRjOK0UiYfgKU1MH8U7CVRW1MxYplVcAbRQ07c8r8VsND0g+qz/KGJI FsgbR79aaG4Qlih5i9sTOcsfm78J/sDf5x0Ns=
Domainkey-signature: a=rsa-sha1; c=nofws;; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=gZg2gC/jZE5klrKMVd5OhEE8hF6YORKts4BaY5JdWpcD5LbllylGwovYOhBTdZDhdF sAaKdamlqSOZu9v0gXDFdpadyNrMpCa3i/ZHj31P9CaxE+/CnA4EWHI7ncjpoPiRIWpc +CV5t4oAAf+wYkRFUL4aVBZwz4K782VLLCRSA=
In-reply-to: <>
Original-recipient: rfc822;
References: <E1O8lDn-0000Sk-86@localhost> <> <> <> <> <> <> <>
On Tue, May 4, 2010 at 5:16 AM, Kevin D. Kissell <> wrote:
> Shane McDonald wrote:
>> When I'm inside my handler, I see the FCSR register has the value 0x8420,
>> indicating that the Z bit is set in each of the Cause, Enables, and Flags
>> fields.  When longjmp() is called, it tries to write the old FCSR value
>> of 0x400 (just the Z bit of the Enables field).  In the emulation code,
>> at lines 392 - 394 of file cp1emu.c, is the code:
>>     if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
>>             return SIGFPE;
>>     }
>> Given the original FCSR value of 0x8420 and the new value to set
>> of 0x400, the Z bit of the Cause field is still set, and as a result, the
>> above code causes the SIGFPE exception to be thrown.
> That's not how I read the code.  If ctx->fcr31 is 0x400, then the result
> of the AND should be zero.

Sorry, I should have been more clear.

In the following chunk of code from cp1emu.c:

                case ctc_op:{
                        /* copregister rd <- rt */
                        u32 value;

                        if (MIPSInst_RT(ir) == 0)
                                value = 0;
                                value = xcp->regs[MIPSInst_RT(ir)];

                        /* we only have one writable control reg
                        if (MIPSInst_RD(ir) == FPCREG_CSR) {
                                printk("%p gpr[%d]->csr=%08x\n",
                                        (void *) (xcp->cp0_epc),
                                        MIPSInst_RT(ir), value);
                                value &= (FPU_CSR_FLUSH |
                                ctx->fcr31 &= ~(FPU_CSR_FLUSH |
                                /* convert to ieee library modes */
                                ctx->fcr31 |= (value & ~0x3) |
ieee_rm[value & 0x3];
                        if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
                                return SIGFPE;

value gets set to an initial value of 0x400, and ctx->fcr31
comes in with an initial value of 0x8420.
By the time we hit the if statement around the return SIGFPE, ctx->fcr31
has been set to 0x8400, not the 0x400 I implied.

Nevertheless, that's not the problem.  You've given me some good pointers
for where to begin searching for the problem.

If anyone out there has a verification suite they can run on the emulator,
that would be much appreciated!


<Prev in Thread] Current Thread [Next in Thread>